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!(f => targetFolderJson(f)).array.Json, 40 "build_systems": buildSystems(settings.platform), 41 "settings": [ "include_paths": buildSettings.importPaths.map!Json.array.Json ].Json, 42 ]); 43 44 auto jsonString = appender!string(); 45 writePrettyJsonString(jsonString, root); 46 47 string projectPath = m_project.name ~ ".sublime-project"; 48 49 write(projectPath, jsonString.data); 50 51 logInfo("Project '%s' generated.", projectPath); 52 } 53 } 54 55 56 private Json targetFolderJson(in ProjectGenerator.TargetInfo target) 57 { 58 return [ 59 "name": target.pack.basePackage.name.Json, 60 "path": target.pack.basePackage.path.toNativeString.Json, 61 "follow_symlinks": true.Json, 62 "folder_exclude_patterns": [".dub"].map!Json.array.Json, 63 ].Json; 64 } 65 66 67 private Json buildSystems(BuildPlatform buildPlatform, string workingDiretory = getcwd()) 68 { 69 enum BUILD_TYPES = [ 70 //"plain", 71 "debug", 72 "release", 73 "release-nobounds", 74 //"unittest", 75 "docs", 76 "ddox", 77 "profile", 78 "profile-gc", 79 "cov", 80 "unittest-cov", 81 ]; 82 83 string fileRegex; 84 85 if (buildPlatform.frontendVersion >= 2066 && buildPlatform.compiler == "dmd") 86 fileRegex = r"^(.+)\(([0-9]+)\,([0-9]+)\)\:() (.*)$"; 87 else 88 fileRegex = r"^(.+)\(([0-9]+)\)\:() (.*)$"; 89 90 auto arch = buildPlatform.architecture[0]; 91 92 Json makeBuildSystem(string buildType) 93 { 94 return Json([ 95 "name": "DUB build " ~ buildType.Json, 96 "cmd": ["dub", "build", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json, 97 "file_regex": fileRegex.Json, 98 "working_dir": workingDiretory.Json, 99 "variants": [ 100 [ 101 "name": "Run".Json, 102 "cmd": ["dub", "run", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json, 103 ].Json 104 ].array.Json, 105 ]); 106 } 107 108 auto buildSystems = BUILD_TYPES.map!makeBuildSystem.array; 109 110 buildSystems ~= [ 111 "name": "DUB test".Json, 112 "cmd": ["dub", "test", "--arch=" ~ arch].map!Json.array.Json, 113 "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json, 114 "working_dir": workingDiretory.Json, 115 ].Json; 116 117 return buildSystems.array.Json; 118 } 119 120 unittest 121 { 122 auto buildPlatform = BuildPlatform(); 123 buildPlatform.architecture ~= "x86_64"; 124 125 auto result = buildPlatform.buildSystems.toString; 126 }