1 module dlangide.workspace.projectsettings; 2 3 import dlangui.core.settings; 4 import dlangui.core.i18n; 5 6 import dlangide.workspace.idesettings; 7 8 import std..string; 9 import std.array; 10 import std.algorithm : equal; 11 12 const AVAILABLE_TOOLCHAINS = ["default", "dmd", "ldc", "gdc"]; 13 const AVAILABLE_ARCH = ["default", "x86", "x86_64", "arm", "arm64"]; 14 15 /// local settings for project (not supposed to put under source control) 16 class ProjectSettings : SettingsFile { 17 18 this(string filename) { 19 super(filename); 20 } 21 22 /// override to do something after loading - e.g. set defaults 23 override void afterLoad() { 24 } 25 26 override void updateDefaults() { 27 Setting build = buildSettings(); 28 build.setStringDef("toolchain", "default"); 29 build.setStringDef("arch", "default"); 30 build.setBooleanDef("verbose", false); 31 build.setStringDef("dub_additional_params", ""); 32 Setting dbg = debugSettings(); 33 dbg.setBooleanDef("external_console", true); 34 } 35 36 @property Setting buildSettings() { 37 Setting res = _setting.objectByPath("build", true); 38 return res; 39 } 40 41 @property Setting debugSettings() { 42 Setting res = _setting.objectByPath("debug", true); 43 return res; 44 } 45 46 @property bool buildVerbose() { 47 return buildSettings.getBoolean("verbose", false); 48 } 49 50 string getToolchain(IDESettings idesettings) { 51 string cfg = buildSettings.getString("toolchain"); 52 return idesettings.getToolchainCompilerExecutable(cfg); 53 } 54 55 string getDubAdditionalParams(IDESettings idesettings) { 56 string cfg = buildSettings.getString("toolchain"); 57 string globalparams = idesettings.dubAdditionalParams; 58 string globaltoolchainparams = idesettings.getToolchainAdditionalDubParams(cfg); 59 string projectparams = buildSettings.getString("dub_additional_params", ""); 60 string verbosity = buildVerbose ? "-v" : null; 61 return joinParams(globalparams, globaltoolchainparams, projectparams, verbosity); 62 } 63 64 string getArch(IDESettings idesettings) { 65 string cfg = buildSettings.getString("arch"); 66 if (cfg.equal("default")) 67 return null; 68 return cfg; 69 } 70 71 @property bool runInExternalConsole() { 72 return debugSettings.getBoolean("external_console", true); 73 } 74 } 75 76 /// join parameter lists separating with space 77 string joinParams(string[] params...) pure { 78 char[] res; 79 foreach(param; params) { 80 string s = param.strip; 81 if (!s.empty) { 82 if (!res.empty) 83 res ~= " "; 84 res ~= s; 85 } 86 } 87 if (res.empty) 88 return null; 89 return res.dup; 90 }