1 /** 2 Generator for SublimeText project files 3 4 Copyright: © 2014 Nicholas Londey 5 License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. 6 Authors: Nicholas Londey 7 */ 8 module dub.generators.sublimetext; 9 10 import dub.compilers.compiler; 11 import dub.generators.generator; 12 import dub.internal.vibecompat.core.log; 13 import dub.internal.vibecompat.data.json; 14 import dub.packagemanager; 15 import dub.project; 16 17 import std.algorithm; 18 import std.array; 19 import std.compiler; 20 import std.file; 21 import std.path; 22 import std.range; 23 import std..string; 24 25 26 class SublimeTextGenerator : ProjectGenerator { 27 28 this(Project project) 29 { 30 super(project); 31 } 32 33 override void generateTargets(GeneratorSettings settings, in TargetInfo[string] targets) 34 { 35 auto buildSettings = targets[m_project.name].buildSettings; 36 logDebug("About to generate sublime project for %s.", m_project.rootPackage.name); 37 38 auto root = Json([ 39 "folders": targets.byValue.map!targetFolderJson.array.Json, 40 "build_systems": buildSystems(settings.platform), 41 ]); 42 43 auto jsonString = appender!string(); 44 writePrettyJsonString(jsonString, root); 45 46 write(m_project.name ~ ".sublime-project", jsonString.data); 47 48 logInfo("SublimeText project generated."); 49 } 50 } 51 52 53 Json targetFolderJson(in ProjectGenerator.TargetInfo target) 54 { 55 return [ 56 "name": target.pack.name.Json, 57 "path": target.pack.path.toNativeString.Json, 58 "follow_symlinks": true.Json, 59 "folder_exclude_patterns": [".dub"].map!Json.array.Json, 60 ].Json; 61 } 62 63 64 Json buildSystems(BuildPlatform buildPlatform, string workingDiretory = getcwd()) 65 { 66 enum BUILD_TYPES = [ 67 //"plain", 68 "debug", 69 "release", 70 //"unittest", 71 "docs", 72 "ddox", 73 "profile", 74 "cov", 75 "unittest-cov", 76 ]; 77 78 auto arch = buildPlatform.architecture[0]; 79 80 Json makeBuildSystem(string buildType) 81 { 82 return Json([ 83 "name": "DUB build " ~ buildType.Json, 84 "cmd": ["dub", "build", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json, 85 "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json, 86 "working_dir": workingDiretory.Json, 87 "variants": [ 88 [ 89 "name": "Run".Json, 90 "cmd": ["dub", "run", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json, 91 ].Json 92 ].array.Json, 93 ]); 94 } 95 96 auto buildSystems = BUILD_TYPES.map!makeBuildSystem.array; 97 98 buildSystems ~= [ 99 "name": "DUB test".Json, 100 "cmd": ["dub", "test", "--arch=" ~ arch].map!Json.array.Json, 101 "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json, 102 "working_dir": workingDiretory.Json, 103 ].Json; 104 105 return buildSystems.array.Json; 106 } 107 108 unittest 109 { 110 auto buildPlatform = BuildPlatform(); 111 buildPlatform.architecture ~= "x86_64"; 112 113 auto result = buildPlatform.buildSystems.toString; 114 }