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 44 struct LinkerFlags { 45 string value; 46 } 47 48 struct ImportPaths { 49 string[] value; 50 51 this(inout(string)[] value) inout pure { 52 this.value = value; 53 } 54 55 this(inout(string) value) inout pure { 56 this([value]); 57 } 58 59 } 60 61 alias IncludePaths = ImportPaths; 62 63 struct StringImportPaths { 64 string[] value; 65 66 this(inout(string)[] value) inout pure { 67 this.value = value; 68 } 69 70 this(inout(string) value) inout pure { 71 this([value]); 72 } 73 74 } 75 76 struct SrcDirs { 77 string[] value; 78 79 this(inout(string)[] value) inout pure { 80 this.value = value; 81 } 82 83 this(inout(string) value) inout pure { 84 this([value]); 85 } 86 87 } 88 89 struct SrcFiles { 90 string[] value; 91 92 this(inout(string)[] value) inout pure { 93 this.value = value; 94 } 95 96 this(inout(string) value) inout pure { 97 this([value]); 98 } 99 100 } 101 102 struct ExcludeFiles { 103 string[] value; 104 105 this(inout(string)[] value) inout pure { 106 this.value = value; 107 } 108 109 this(inout(string) value) inout pure { 110 this([value]); 111 } 112 113 } 114 115 struct ExeName { 116 string value; 117 } 118 119 struct TargetName { 120 string value; 121 } 122 123 struct Configuration { 124 string value = "default"; 125 } 126 127 enum Backend { 128 none, 129 make, 130 ninja, 131 tup, 132 binary, 133 } 134 135 136 struct Dirs { 137 string[] value = ["."]; 138 139 this(inout(string)[] value) inout pure { 140 this.value = value; 141 } 142 143 this(inout(string) value) inout pure { 144 this([value]); 145 } 146 } 147 148 struct Files { 149 string[] value; 150 151 this(inout(string)[] value) inout pure { 152 this.value = value; 153 } 154 155 this(inout(string) value) inout pure { 156 this([value]); 157 } 158 } 159 160 struct Filter(alias F) { 161 alias func = F; 162 } 163 164 struct SourcesImpl(alias F) { 165 Dirs dirs; 166 Files files; 167 Filter!F filter; 168 169 alias filterFunc = F; 170 } 171 172 auto Sources(Dirs dirs = Dirs(), Files files = Files(), F = Filter!(a => true))() { 173 return SourcesImpl!(F.func)(dirs, files); 174 } 175 176 auto Sources(string[] dirs, Files files = Files(), F = Filter!(a => true))() { 177 return Sources!(Dirs(dirs), files, F)(); 178 } 179 180 auto Sources(string dir, Files files = Files(), F = Filter!(a => true))() { 181 return Sources!([dir], files, F)(); 182 } 183 184 struct SourceFile { 185 string value; 186 }