Newer
Older
dub_jkp / source / dub / generators / sublimetext.d
@Nicholas Londey Nicholas Londey on 16 Dec 2014 2 KB Changed to use Package path for folders
  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. auto root = Json([
  38. "folders": targets.byValue.map!targetFolderJson.array.Json,
  39. "build_systems": buildSystems(settings.platform),
  40. ]);
  41.  
  42. auto jsonString = appender!string();
  43. writePrettyJsonString(jsonString, root);
  44.  
  45. write(m_project.name ~ ".sublime-project", jsonString.data);
  46.  
  47. logInfo("SublimeText project generated.");
  48. }
  49. }
  50.  
  51.  
  52. Json targetFolderJson(in ProjectGenerator.TargetInfo target)
  53. {
  54. return [
  55. "name": target.pack.name.Json,
  56. "path": target.pack.path.toNativeString.Json,
  57. "follow_symlinks": true.Json,
  58. "folder_exclude_patterns": [".dub"].map!Json.array.Json,
  59. ].Json;
  60. }
  61.  
  62.  
  63. Json buildSystems(BuildPlatform buildPlatform, string workingDiretory = getcwd())
  64. {
  65. enum BUILD_TYPES = [
  66. //"plain",
  67. "debug",
  68. "release",
  69. //"unittest",
  70. "docs",
  71. "ddox",
  72. "profile",
  73. "cov",
  74. "unittest-cov",
  75. ];
  76.  
  77. auto arch = buildPlatform.architecture[0];
  78.  
  79. Json makeBuildSystem(string buildType)
  80. {
  81. return Json([
  82. "name": "DUB build " ~ buildType.Json,
  83. "cmd": ["dub", "build", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json,
  84. "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json,
  85. "working_dir": workingDiretory.Json,
  86. "variants": [
  87. [
  88. "name": "Run".Json,
  89. "cmd": ["dub", "run", "--build=" ~ buildType, "--arch=" ~ arch].map!Json.array.Json,
  90. ].Json
  91. ].array.Json,
  92. ]);
  93. }
  94.  
  95. auto buildSystems = BUILD_TYPES.map!makeBuildSystem.array;
  96.  
  97. buildSystems ~= [
  98. "name": "DUB test".Json,
  99. "cmd": ["dub", "test", "--arch=" ~ arch].map!Json.array.Json,
  100. "file_regex": r"^(.+)\(([0-9]+)\)\:() (.*)$".Json,
  101. "working_dir": workingDiretory.Json,
  102. ].Json;
  103.  
  104. return buildSystems.array.Json;
  105. }
  106.  
  107. unittest
  108. {
  109. auto buildPlatform = BuildPlatform();
  110. buildPlatform.architecture ~= "x86_64";
  111.  
  112. auto result = buildPlatform.buildSystems.toString;
  113. }