Skip to content

Commit

Permalink
fix dub import path generation
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Mar 2, 2024
1 parent 02bb374 commit 2eba59b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
6 changes: 4 additions & 2 deletions test/tc_dub/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ void main()
// if no dependencies are fetched
// or with all dependencies there a lot more
assert(dub.imports.length >= 2, dub.imports.to!string);
assert(dub.stringImports[0].endsWith("views")
|| dub.stringImports[0].endsWith("views/") || dub.stringImports[0].endsWith("views\\"));
assert(dub.stringImports[$ - 1].endsWith("views")
|| dub.stringImports[$ - 1].endsWith("views/")
|| dub.stringImports[$ - 1].endsWith("views\\"),
dub.stringImports.to!string ~ " doesn't end with `views`!");
assert(dub.fileImports.length > 10);
assert(dub.configurations.length == 2);
assert(dub.buildTypes.length);
Expand Down
57 changes: 34 additions & 23 deletions workspace-d/source/workspaced/com/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,9 @@ class DubComponent : ComponentWrapper

try
{
string[] failedPackages = null;
scope (exit)
_failedPackages = failedPackages;
string[string] configs = _dub.project.getPackageConfigs(settings.platform, settings.config);
foreach (pack; _dub.project.getTopologicalPackageList(true, null, configs))
failedPackages ~= pack.name;
failedPackages.sort!"a<b";

auto gen = new TargetDescriptionGenerator(_dub.project);
auto gen = new TargetInfoGenerator(_dub.project);
gen.generate(settings);

auto importPaths = appender!(string[]);
Expand All @@ -242,25 +236,25 @@ class DubComponent : ComponentWrapper
auto versions = appender!(string[]);
auto debugVersions = appender!(string[]);

foreach (target; gen.targetDescriptions)
bool failed;
foreach (pack; _dub.project.getTopologicalPackageList(true, null, configs))
{
// remove resolved dependencies from failedPackages
foreach (name; [target.rootPackage] ~ target.packages)
if (auto target = pack.name in gen.targets)
{
auto match = failedPackages.assumeSorted!"a<b".trisect(name);
foreach (i; 0 .. match[1].length)
failedPackages = failedPackages.remove(match[0].length);
importPaths ~= target.buildSettings.importPaths;
stringImportPaths ~= target.buildSettings.stringImportPaths;
sourceFiles ~= target.buildSettings.sourceFiles;
sourceFiles ~= target.buildSettings.importFiles; // what are these exactly?
versions ~= target.buildSettings.versions;
debugVersions ~= target.buildSettings.debugVersions;
}
else
{
failed = true;
}

importPaths ~= target.buildSettings.importPaths;
stringImportPaths ~= target.buildSettings.stringImportPaths;
sourceFiles ~= target.buildSettings.sourceFiles;
sourceFiles ~= target.buildSettings.importFiles; // what are these exactly?
versions ~= target.buildSettings.versions;
debugVersions ~= target.buildSettings.debugVersions;
}

string[] rootSourcePaths;
/* string[] rootSourcePaths;
if (auto rootTargetIndex = _dub.projectName in gen.targetDescriptionLookup)
{
auto rootTarget = gen.targetDescriptions[*rootTargetIndex];
Expand All @@ -278,14 +272,16 @@ class DubComponent : ComponentWrapper
rootSourcePaths ~= sourcePath;
}
}

_importPaths = rootSourcePaths ~ importPaths.data;
*/

_importPaths = importPaths.data;
_stringImportPaths = stringImportPaths.data;
_importFiles = sourceFiles.data;
_versions = versions.data;
_debugVersions = debugVersions.data;

return failedPackages.length == 0;
return !failed;
}
catch (Exception e)
{
Expand Down Expand Up @@ -1066,3 +1062,18 @@ class ServedDub : Dub
return s;
}
}

class TargetInfoGenerator : ProjectGenerator
{
const(TargetInfo)[string] targets;

this(Project project)
{
super(project);
}

protected override void generateTargets(GeneratorSettings settings, in TargetInfo[string] targets)
{
this.targets = targets.dup;
}
}

0 comments on commit 2eba59b

Please sign in to comment.