1 /**
2 	Types for project descriptions (dub describe).
3 
4 	Copyright: © 2015-2016 rejectedsoftware e.K.
5 	License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
6 	Authors: Sönke Ludwig
7 */
8 module dub.description;
9 
10 import dub.compilers.buildsettings;
11 import dub.dependency;
12 import dub.internal.vibecompat.data.serialization;
13 
14 
15 /**
16 	Describes a complete project for use in IDEs or build tools.
17 
18 	The build settings will be specific to the compiler, platform
19 	and configuration that has been selected.
20 */
21 struct ProjectDescription {
22 	string rootPackage; /// Name of the root package being built
23 	string configuration; /// Name of the selected build configuration
24 	string buildType; /// Name of the selected build type
25 	string compiler; /// Canonical name of the compiler used (e.g. "dmd", "gdc" or "ldc")
26 	string[] architecture; /// Architecture constants for the selected platform (e.g. `["x86_64"]`)
27 	string[] platform; /// Platform constants for the selected platform (e.g. `["posix", "osx"]`)
28 	PackageDescription[] packages; /// All packages in the dependency tree
29 	TargetDescription[] targets; /// Build targets
30 	@ignore size_t[string] targetLookup; /// Target index by package name name
31 
32 	/// Targets by name
33 	ref inout(TargetDescription) lookupTarget(string name) inout
34 	{
35 		import std.exception : enforce;
36 		auto pti = name in targetLookup;
37 		enforce(pti !is null, "Target '"~name~"' doesn't exist. Is the target type set to \"none\" in the package recipe?");
38 		return targets[*pti];
39 	}
40 
41 	/// Projects by name
42 	ref inout(PackageDescription) lookupPackage(string name) inout
43 	{
44 		foreach (ref p; packages)
45 			if (p.name == name)
46 			{
47 				return p;
48 			}
49 		throw new Exception("Package '"~name~"' not found in dependency tree.");
50 	}
51 
52 	/// Root package
53 	ref inout(PackageDescription) lookupRootPackage() inout { return lookupPackage(rootPackage); }
54 }
55 
56 
57 /**
58 	Describes the build settings and meta data of a single package.
59 
60 	This structure contains the effective build settings and dependencies for
61 	the selected build platform. This structure is most useful for displaying
62 	information about a package in an IDE. Use `TargetDescription` instead when
63 	writing a build-tool.
64 */
65 struct PackageDescription {
66 	string path; /// Path to the package
67 	string name; /// Qualified name of the package
68 	Version version_; /// Version of the package
69 	string description;
70 	string homepage;
71 	string[] authors;
72 	string copyright;
73 	string license;
74 	string[] dependencies;
75 
76 	bool active; /// Does this package take part in the build?
77 	string configuration; /// The configuration that is built
78 	@byName TargetType targetType;
79 	string targetPath;
80 	string targetName;
81 	string targetFileName;
82 	string workingDirectory;
83 	string mainSourceFile;
84 	string[] dflags; /// Flags passed to the D compiler
85 	string[] lflags; /// Flags passed to the linker
86 	string[] libs; /// Library names to link against (typically using "-l<name>")
87 	string[] injectSourceFiles; /// Files that should be injected when this package is dependent upon by a binary image.
88 	string[] copyFiles; /// Files to copy to the target directory
89 	string[] extraDependencyFiles; /// Files to check for rebuild dub project
90 	string[] versions; /// D version identifiers to set
91 	string[] debugVersions; /// D debug version identifiers to set
92 	string[] importPaths;
93 	string[] stringImportPaths;
94 	string[] preGenerateCommands; /// Commands executed before creating the description, with variables not substituted.
95 	string[] postGenerateCommands; /// Commands executed after creating the description, with variables not substituted.
96 	string[] preBuildCommands; /// Commands to execute prior to every build, with variables not substituted.
97 	string[] postBuildCommands; /// Commands to execute after every build, with variables not substituted.
98 	string[] preRunCommands; /// Commands to execute prior to every run, with variables not substituted.
99 	string[] postRunCommands; /// Commands to execute after every run, with variables not substituted.
100 	string[string] environments;
101 	string[string] buildEnvironments;
102 	string[string] runEnvironments;
103 	string[string] preGenerateEnvironments;
104 	string[string] postGenerateEnvironments;
105 	string[string] preBuildEnvironments;
106 	string[string] postBuildEnvironments;
107 	string[string] preRunEnvironments;
108 	string[string] postRunEnvironments;
109 	@byName BuildRequirement[] buildRequirements;
110 	@byName BuildOption[] options;
111 	SourceFileDescription[] files; /// A list of all source/import files possibly used by the package
112 }
113 
114 
115 /**
116 	Describes the settings necessary to build a certain binary target.
117 */
118 struct TargetDescription {
119 	string rootPackage; /// Main package associated with this target, this is also the name of the target.
120 	string[] packages; /// All packages contained in this target (e.g. for target type "sourceLibrary")
121 	string rootConfiguration; /// Build configuration of the target's root package used for building
122 	BuildSettings buildSettings; /// Final build settings to use when building the target
123 	string[] dependencies; /// List of all dependencies of this target (package names)
124 	string[] linkDependencies; /// List of all link-dependencies of this target (target names)
125 }
126 
127 /**
128 	Description for a single source file known to the package.
129 */
130 struct SourceFileDescription {
131 	@byName SourceFileRole role; /// Main role this file plays in the build process
132 	string path; /// Full path to the file
133 }
134 
135 /**
136 	Determines the role that a file plays in the build process.
137 
138 	If a file has multiple roles, higher enum values will have precedence, i.e.
139 	if a file is used both, as a source file and as an import file, it will
140 	be classified as a source file.
141 */
142 enum SourceFileRole {
143 	unusedStringImport, /// Used as a string import for another configuration/platform
144 	unusedImport,       /// Used as an import for another configuration/platform
145 	unusedSource,       /// Used as a source file for another configuration/platform
146 	stringImport,       /// Used as a string import file
147 	import_,            /// Used as an import file
148 	source              /// Used as a source file
149 }