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 const buildId = computeBuildID(d.buildSettings, ti.pack.path, ti.config, settings); 49 const filename = settings.compiler.getTargetFileName(d.buildSettings, settings.platform); 50 d.cacheArtifactPath = (targetCacheDir(settings.cache, ti.pack, buildId) ~ filename).toNativeString(); 51 d.dependencies = ti.dependencies.dup; 52 d.linkDependencies = ti.linkDependencies.dup; 53 54 // Add static library dependencies 55 foreach (ld; ti.linkDependencies) { 56 auto ltarget = targets[ld]; 57 auto ltbs = ltarget.buildSettings; 58 auto targetfil = (NativePath(ltbs.targetPath) ~ settings.compiler.getTargetFileName(ltbs, settings.platform)).toNativeString(); 59 d.buildSettings.addLinkerFiles(targetfil); 60 } 61 62 targetDescriptionLookup[d.rootPackage] = i; 63 targetDescriptions[i++] = d; 64 65 foreach (dep; ti.dependencies) 66 visitTargetRec(dep); 67 } 68 visitTargetRec(m_project.rootPackage.name); 69 } 70 }