1 module dud.pkgdescription;
2 
3 import std.typecons : Nullable;
4 
5 public import dud.pkgdescription.path;
6 public import dud.pkgdescription.udas;
7 public import dud.pkgdescription.json;
8 public import dud.pkgdescription.sdl;
9 public import dud.pkgdescription.platform;
10 
11 import dud.semver.semver;
12 import dud.semver.versionrange;
13 
14 @safe pure:
15 
16 enum TargetType {
17 	autodetect,
18 	none,
19 	executable,
20 	library,
21 	sourceLibrary,
22 	dynamicLibrary,
23 	staticLibrary,
24 	object
25 }
26 
27 /**
28 	Describes the build settings and meta data of a single package.
29 
30 	This structure contains the effective build settings and dependencies for
31 	the selected build platform. This structure is most useful for displaying
32 	information about a package in an IDE. Use `TargetDescription` instead when
33 	writing a build-tool.
34 */
35 struct PackageDescription {
36 @safe pure:
37 	@JSON!(jGetString, stringToJ)("")
38 	@SDL!(sGetString, stringToSName)("")
39 	string name; /// Qualified name of the package
40 
41 	//@JSON!(jGetSemVer, semVerToJ)("version")
42 	//@SDL!(sGetSemVer, semVerToS)("version")
43 	//SemVer version_; /// Version of the package
44 
45 	@JSON!(jGetString, stringToJ)("")
46 	@SDL!(sGetString, stringToS)("")
47 	string description;
48 
49 	@JSON!(jGetString, stringToJ)("")
50 	@SDL!(sGetString, stringToS)("")
51 	string homepage;
52 
53 	@JSON!(jGetStrings, stringsToJ)("")
54 	@SDL!(sGetStrings, stringsToS)("")
55 	string[] authors;
56 
57 	@JSON!(jGetString, stringToJ)("")
58 	@SDL!(sGetString, stringToS)("")
59 	string copyright;
60 
61 	@JSON!(jGetString, stringToJ)("")
62 	@SDL!(sGetString, stringToS)("")
63 	string license;
64 
65 	@JSON!(jGetString, stringToJ)("")
66 	@SDL!(sGetString, stringToS)("")
67 	string systemDependencies;
68 
69 	@JSON!(jGetDependencies, dependenciesToJ)("")
70 	@SDL!(sGetDependencies, dependenciesToS)("dependency")
71 	Dependency[] dependencies;
72 
73 	@JSON!(jGetTargetType, targetTypeToJ)("")
74 	@SDL!(sGetTargetType, targetTypeToS)("")
75 	TargetType targetType;
76 
77 	@JSON!(jGetUnprocessedPath, unprocessedPathToJ)("")
78 	@SDL!(sGetUnprocessedPath, unprocessedPathToS)("")
79 	UnprocessedPath targetPath;
80 
81 	@JSON!(jGetString, stringToJ)("")
82 	@SDL!(sGetString, stringToS)("")
83 	string targetName;
84 
85 	@JSON!(jGetUnprocessedPath, unprocessedPathToJ)("")
86 	@SDL!(sGetUnprocessedPath, unprocessedPathToS)("")
87 	UnprocessedPath workingDirectory;
88 
89 	@JSON!(jGetUnprocessedPath, unprocessedPathToJ)("")
90 	@SDL!(sGetUnprocessedPath, unprocessedPathToS)("")
91 	UnprocessedPath mainSourceFile;
92 
93 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
94 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
95 	Strings dflags; /// Flags passed to the D compiler
96 
97 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
98 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
99 	Strings lflags; /// Flags passed to the linker
100 
101 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
102 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
103 	Strings libs; /// Librariy names to link against (typically using "-l<name>")
104 
105 	@JSON!(jGetPaths, pathsToJ)("")
106 	@SDL!(sGetPaths, pathsToS)("")
107 	Paths copyFiles; /// Files to copy to the target directory
108 
109 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
110 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
111 	Strings versions; /// D version identifiers to set
112 
113 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
114 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
115 	Strings debugVersions; /// D debug version identifiers to set
116 
117 	@JSON!(jGetPaths, pathsToJ)("")
118 	@SDL!(sGetPaths, pathsToS)("")
119 	Paths importPaths;
120 
121 	@JSON!(jGetPaths, pathsToJ)("")
122 	@SDL!(sGetPaths, pathsToS)("")
123 	Paths sourcePaths;
124 
125 	@JSON!(jGetPaths, pathsToJ)("")
126 	@SDL!(sGetPaths, pathsToS)("")
127 	Paths sourceFiles;
128 
129 	@JSON!(jGetPaths, pathsToJ)("")
130 	@SDL!(sGetPaths, pathsToS)("")
131 	Paths excludedSourceFiles;
132 
133 	@JSON!(jGetPaths, pathsToJ)("")
134 	@SDL!(sGetPaths, pathsToS)("")
135 	Paths stringImportPaths;
136 
137 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
138 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
139 	Strings preGenerateCommands; /// commands executed before creating the description
140 
141 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
142 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
143 	Strings postGenerateCommands; /// commands executed after creating the description
144 
145 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
146 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
147 	Strings preBuildCommands; /// Commands to execute prior to every build
148 
149 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
150 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
151 	Strings postBuildCommands; /// Commands to execute after every build
152 
153 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
154 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
155 	Strings preRunCommands; /// Commands to execute prior to every run
156 
157 	@JSON!(jGetStringsPlatform, stringsPlatformToJ)("")
158 	@SDL!(sGetStringsPlatform, stringsPlatformToS)("")
159 	Strings postRunCommands; /// Commands to execute after every run
160 
161 	@JSON!(jGetPackageDescriptions, packageDescriptionsToJ)("")
162 	@SDL!(sGetPackageDescriptions, configurationsToS)("configuration")
163 	PackageDescription[string] configurations;
164 
165 	@JSON!(jGetStrings, stringsToJ)("-ddoxFilterArgs")
166 	@SDL!(sGetStrings, stringsToS)("x:ddoxFilterArgs")
167 	string[] ddoxFilterArgs;
168 
169 	@JSON!(jGetStrings, stringsToJ)("")
170 	@SDL!(sGetStrings, stringsToS)("x:debugVersionFilters")
171 	string[] debugVersionFilters;
172 
173 	@JSON!(jGetStringPlatform, stringPlatformToJ)("-ddoxTool")
174 	@SDL!(sGetStringPlatform, stringPlatformToS)("x:ddoxTool")
175 	String ddoxTool;
176 
177 	@JSON!(jGetSubPackages, subPackagesToJ)("")
178 	@SDL!(sGetSubPackage, subPackagesToS)("subPackage")
179 	SubPackage[] subPackages;
180 
181 	@JSON!(jGetBuildRequirements, buildRequirementsToJ)("")
182 	@SDL!(sGetBuildRequirements, buildRequirementsToS)("")
183 	BuildRequirements buildRequirements;
184 
185 	@JSON!(jGetStringAA, stringAAToJ)("")
186 	@SDL!(sGetSubConfig, subConfigsToS)("subConfiguration")
187 	SubConfigs subConfigurations;
188 
189 	@JSON!(jGetStrings, stringsToJ)("")
190 	@SDL!(sGetStrings, stringsToS)("x:versionFilters")
191 	string[] versionFilters;
192 
193 	@JSON!(jGetBuildTypes, buildTypesToJ)("")
194 	@SDL!(sGetBuildTypes, buildTypesToS)("buildType")
195 	BuildType[string] buildTypes;
196 
197 	@JSON!(jGetBuildOptions, buildOptionsToJ)("")
198 	@SDL!(sGetBuildOptions, buildOptionsToS)("")
199 	BuildOptions buildOptions;
200 
201 	@JSON!(jGetPlatforms, platformsToJ)("")
202 	@SDL!(sGetPlatforms, platformsToS)("")
203 	Platform[][] platforms;
204 
205 	@JSON!(jGetToolchainRequirement, toolchainRequirementToJ)("")
206 	@SDL!(sGetToolchainRequirement, toolchainRequirementToS)("")
207 	ToolchainRequirement[Toolchain] toolchainRequirements;
208 
209 	bool opEquals(const PackageDescription other) const {
210 		import dud.pkgdescription.compare : areEqual;
211 		return areEqual(this, other);
212 	}
213 }
214 
215 struct BuildOptions {
216 	BuildOption[][immutable(Platform[])] platforms;
217 	BuildOption[] unspecifiedPlatform;
218 }
219 
220 enum BuildOption {
221 	/// Compile in debug mode (enables contracts) -debug
222 	debugMode,
223 	/// Compile in release mode (disables assertions and bounds checks) -release
224 	releaseMode,
225 	/// Enable code coverage analysis -cov
226 	coverage,
227 	/// Enable symbolic debug information -g
228 	debugInfo,
229 	/// Enable symbolic debug information in C compatible form -gc
230 	debugInfoC,
231 	/// Always generate a stack frame -gs
232 	alwaysStackFrame,
233 	/// Perform stack stomping -gx
234 	stackStomping,
235 	/// Perform function inlining -inline
236 	inline,
237 	/// Disable all bounds checking -boundscheck=off
238 	noBoundsCheck,
239 	/// Enable optimizations -O
240 	optimize,
241 	/// Emit profiling code -profile
242 	profile,
243 	/// Emit GC profiling information -profile=gc
244 	profileGC,
245 	/// Compile unit tests -unittest
246 	unittests,
247 	/// Verbose compiler output -v
248 	verbose,
249 	/// Ignores unknown pragmas during compilation -ignore
250 	ignoreUnknownPragmas,
251 	/// Don't generate object files -o-
252 	syntaxOnly,
253 	/** Enable warnings, enabled by default
254 	(use , buildRequirements,  to control this setting) -wi
255 	*/
256 	warnings,
257 	/** Treat warnings as errors
258 	(use , buildRequirements,  to control this setting) -w
259 	*/
260 	warningsAsErrors,
261 	/** Do not warn about using deprecated features
262 	(use , buildRequirements,  to control this setting) -d
263 	*/
264 	ignoreDeprecations,
265 	/** Warn about using deprecated features, enabled by default
266 	(use , buildRequirements,  to control this setting) -dw
267 	*/
268 	deprecationWarnings,
269 	/** Stop compilation upon usage of deprecated features
270 	(use , buildRequirements,  to control this setting) -de
271 	*/
272 	deprecationErrors,
273 	/// Enforce property syntax - deprecated -property
274 	property,
275 	/// Compile in betterC mode -betterC
276 	betterC,
277 }
278 
279 struct SubConfigs {
280 	string[string][immutable(Platform[])] configs;
281 	string[string] unspecifiedPlatform;
282 }
283 
284 struct BuildType {
285 	string name;
286 	PackageDescription pkg;
287 }
288 
289 enum BuildRequirement {
290 	allowWarnings,
291 	silenceWarnings,
292 	disallowDeprecations,
293 	silenceDeprecations,
294 	disallowInlining,
295 	disallowOptimization,
296 	requireBoundsCheck,
297 	requireContracts,
298 	relaxProperties,
299 	noDefaultFlags,
300 }
301 
302 struct BuildRequirements {
303 	BuildRequirementPlatform[] platforms;
304 }
305 
306 struct BuildRequirementPlatform {
307 	BuildRequirement[] requirements;
308 	Platform[] platforms;
309 }
310 
311 struct SubPackage {
312 	Path path;
313 	Nullable!PackageDescription inlinePkg;
314 }
315 
316 struct Dependency {
317 @safe pure:
318 	import std.typecons : Nullable;
319 	string name;
320 	Nullable!VersionRange version_;
321 	UnprocessedPath path;
322 	Nullable!bool optional;
323 	Nullable!bool default_;
324 	Platform[] platforms;
325 
326 	bool opEqual()(auto ref const Dependency other) const {
327 		return areEqual(this, other);
328 	}
329 }
330 
331 struct StringPlatform {
332 	string str;
333 	Platform[] platforms;
334 }
335 
336 struct String {
337 @safe pure:
338 	StringPlatform[] platforms;
339 }
340 
341 struct StringsPlatform {
342 	string[] strs;
343 	Platform[] platforms;
344 }
345 
346 struct Strings {
347 	StringsPlatform[] platforms;
348 }
349 
350 enum Toolchain {
351 	dub,
352 	dud,
353 	frontend,
354 	dmd,
355 	ldc,
356 	gdc
357 }
358 
359 struct ToolchainRequirement {
360 	bool no;
361 	VersionRange version_;
362 }