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