1 /**
2 	Pseudo generator to output build descriptions.
3 
4 	Copyright: © 2015 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.generators.targetdescription;
9 
10 import dub.compilers.buildsettings;
11 import dub.compilers.compiler;
12 import dub.description;
13 import dub.generators.generator;
14 import dub.internal.vibecompat.inet.path;
15 import dub.project;
16 
17 class TargetDescriptionGenerator : ProjectGenerator {
18 	TargetDescription[] targetDescriptions;
19 	size_t[string] targetDescriptionLookup;
20 
21 	this(Project project)
22 	{
23 		super(project);
24 	}
25 
26 	protected override void generateTargets(GeneratorSettings settings, in TargetInfo[string] targets)
27 	{
28 		import std.algorithm : map;
29 		import std.array : array;
30 
31 		auto configs = m_project.getPackageConfigs(settings.platform, settings.config);
32 		targetDescriptions.length = targets.length;
33 		size_t i = 0;
34 
35 		bool[string] visited;
36 		void visitTargetRec(string target)
37 		{
38 			if (target in visited) return;
39 			visited[target] = true;
40 
41 			auto ti = targets[target];
42 
43 			TargetDescription d;
44 			d.rootPackage = ti.pack.name;
45 			d.packages = ti.packages.map!(p => p.name).array;
46 			d.rootConfiguration = ti.config;
47 			d.buildSettings = ti.buildSettings.dup;
48 			d.dependencies = ti.dependencies.dup;
49 			d.linkDependencies = ti.linkDependencies.dup;
50 
51 			// Add static library dependencies
52 			foreach (ld; ti.linkDependencies) {
53 				auto ltarget = targets[ld];
54 				auto ltbs = ltarget.buildSettings;
55 				auto targetfil = (NativePath(ltbs.targetPath) ~ settings.compiler.getTargetFileName(ltbs, settings.platform)).toNativeString();
56 				d.buildSettings.addLinkerFiles(targetfil);
57 			}
58 
59 			targetDescriptionLookup[d.rootPackage] = i;
60 			targetDescriptions[i++] = d;
61 
62 			foreach (dep; ti.dependencies)
63 				visitTargetRec(dep);
64 		}
65 		visitTargetRec(m_project.rootPackage.name);
66 	}
67 }