1 module reggae.types; 2 3 import reggae.rules.common: exeExt; 4 import std.path: baseName, stripExtension, defaultExtension; 5 6 //Wrapper structs to ensure type-safety and readability 7 8 @safe: 9 10 struct SourceFileName { 11 string value; 12 } 13 14 struct BinaryFileName { 15 string value; 16 } 17 18 struct App { 19 SourceFileName srcFileName; 20 BinaryFileName exeFileName; 21 22 this(SourceFileName srcFileName) pure { 23 immutable stripped = srcFileName.value.baseName.stripExtension; 24 immutable exeFileName = BinaryFileName(exeExt == "" ? stripped : stripped.defaultExtension(exeExt)); 25 26 this(srcFileName, exeFileName); 27 } 28 29 this(SourceFileName srcFileName, BinaryFileName exeFileName) @safe pure nothrow { 30 this.srcFileName = srcFileName; 31 this.exeFileName = exeFileName; 32 } 33 } 34 35 36 struct Flags { 37 string value; 38 } 39 40 struct CompilerFlags { 41 string value; 42 43 this(string value) { this.value = value; } 44 this(string[] value) { 45 import std.string: join; 46 this.value = value.join(" "); 47 } 48 } 49 50 struct LinkerFlags { 51 string value; 52 } 53 54 struct ImportPaths { 55 string[] value; 56 57 this(inout(string)[] value) inout pure { 58 this.value = value; 59 } 60 61 this(inout(string) value) inout pure { 62 this([value]); 63 } 64 65 } 66 67 alias IncludePaths = ImportPaths; 68 69 struct StringImportPaths { 70 string[] value; 71 72 this(inout(string)[] value) inout pure { 73 this.value = value; 74 } 75 76 this(inout(string) value) inout pure { 77 this([value]); 78 } 79 80 } 81 82 struct SrcDirs { 83 string[] value; 84 85 this(inout(string)[] value) inout pure { 86 this.value = value; 87 } 88 89 this(inout(string) value) inout pure { 90 this([value]); 91 } 92 93 } 94 95 struct SrcFiles { 96 string[] value; 97 98 this(inout(string)[] value) inout pure { 99 this.value = value; 100 } 101 102 this(inout(string) value) inout pure { 103 this([value]); 104 } 105 106 } 107 108 struct ExcludeFiles { 109 string[] value; 110 111 this(inout(string)[] value) inout pure { 112 this.value = value; 113 } 114 115 this(inout(string) value) inout pure { 116 this([value]); 117 } 118 119 } 120 121 struct ExeName { 122 string value; 123 } 124 125 struct TargetName { 126 string value; 127 } 128 129 struct Configuration { 130 string value = "default"; 131 } 132 133 enum Backend { 134 none, 135 make, 136 ninja, 137 tup, 138 binary, 139 } 140 141 142 struct Dirs { 143 string[] value = ["."]; 144 145 this(inout(string)[] value) inout pure { 146 this.value = value; 147 } 148 149 this(inout(string) value) inout pure { 150 this([value]); 151 } 152 } 153 154 struct Files { 155 string[] value; 156 157 this(inout(string)[] value) inout pure { 158 this.value = value; 159 } 160 161 this(inout(string) value) inout pure { 162 this([value]); 163 } 164 } 165 166 struct Filter(alias F) { 167 alias func = F; 168 } 169 170 struct SourcesImpl(alias F) { 171 Dirs dirs; 172 Files files; 173 Filter!F filter; 174 175 alias filterFunc = F; 176 } 177 178 auto Sources(Dirs dirs = Dirs(), Files files = Files(), F = Filter!(a => true))() { 179 return SourcesImpl!(F.func)(dirs, files); 180 } 181 182 auto Sources(string[] dirs, Files files = Files(), F = Filter!(a => true))() { 183 return Sources!(Dirs(dirs), files, F)(); 184 } 185 186 auto Sources(string dir, Files files = Files(), F = Filter!(a => true))() { 187 return Sources!([dir], files, F)(); 188 } 189 190 struct SourceFile { 191 string value; 192 }