Newer
Older
dub_jkp / source / dub / generators / sublimetext.d
@Sebastian Wilzbach Sebastian Wilzbach on 23 Feb 2017 3 KB Remove all trailing whitespace
  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-debug",
  74. "release-nobounds",
  75. //"unittest",
  76. "docs",
  77. "ddox",
  78. "profile",
  79. "profile-gc",
  80. "cov",
  81. "unittest-cov",
  82. ];
  83.  
  84. string fileRegex;
  85.  
  86. if (buildPlatform.frontendVersion >= 2066 && buildPlatform.compiler == "dmd")
  87. fileRegex = r"^(.+)\(([0-9]+)\,([0-9]+)\)\:() (.*)$";
  88. else
  89. fileRegex = r"^(.+)\(([0-9]+)\)\:() (.*)$";
  90.  
  91. auto arch = buildPlatform.architecture[0];
  92.  
  93. Json makeBuildSystem(string buildType)
  94. {
  95. return Json([
  96. "name": "DUB build " ~ buildType.Json,
  97. "cmd": ["dub", "build", "--build=" ~ buildType, "--arch=" ~ arch, "--compiler="~buildPlatform.compilerBinary].map!Json.array.Json,
  98. "file_regex": fileRegex.Json,
  99. "working_dir": workingDiretory.Json,
  100. "variants": [
  101. [
  102. "name": "Run".Json,
  103. "cmd": ["dub", "run", "--build=" ~ buildType, "--arch=" ~ arch, "--compiler="~buildPlatform.compilerBinary].map!Json.array.Json,
  104. ].Json
  105. ].array.Json,
  106. ]);
  107. }
  108.  
  109. auto buildSystems = BUILD_TYPES.map!makeBuildSystem.array;
  110.  
  111. buildSystems ~= [
  112. "name": "DUB test".Json,
  113. "cmd": ["dub", "test", "--arch=" ~ arch, "--compiler="~buildPlatform.compilerBinary].map!Json.array.Json,
  114. "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json,
  115. "working_dir": workingDiretory.Json,
  116. ].Json;
  117.  
  118. return buildSystems.array.Json;
  119. }
  120.  
  121. unittest
  122. {
  123. auto buildPlatform = BuildPlatform();
  124. buildPlatform.architecture ~= "x86_64";
  125.  
  126. auto result = buildPlatform.buildSystems.toString;
  127. }