Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2840: Build collision for single-package and FILE_FULL_PATH #2841

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/dub/generators/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class BuildGenerator : ProjectGenerator {
auto cwd = settings.toolWorkingDirectory;
bool generate_binary = !(buildsettings.options & BuildOption.syntaxOnly);

auto build_id = buildsettings.computeBuildID(config, settings);
auto build_id = buildsettings.computeBuildID(pack.path, config, settings);

// make all paths relative to shrink the command line
string makeRelative(string path) { return shrinkPath(NativePath(path), cwd); }
Expand Down
5 changes: 4 additions & 1 deletion source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ package(dub) NativePath targetCacheDir(NativePath cachePath, in Package pkg, str
* library-debug-Z7qINYX4IxM8muBSlyNGrw
* ```
*/
package(dub) string computeBuildID(in BuildSettings buildsettings, string config, GeneratorSettings settings)
package(dub) string computeBuildID(in BuildSettings buildsettings,
in NativePath packagePath, string config, GeneratorSettings settings)
{
import std.conv : to;

Expand All @@ -843,6 +844,8 @@ package(dub) string computeBuildID(in BuildSettings buildsettings, string config
settings.platform.architecture,
[
(cast(uint)(buildsettings.options & ~BuildOption.color)).to!string, // exclude color option from id
// Needed for things such as `__FULL_FILE_PATH__`
packagePath.toNativeString(),
settings.platform.compilerBinary,
settings.platform.compiler,
settings.platform.compilerVersion,
Expand Down
2 changes: 1 addition & 1 deletion source/dub/generators/targetdescription.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TargetDescriptionGenerator : ProjectGenerator {
d.packages = ti.packages.map!(p => p.name).array;
d.rootConfiguration = ti.config;
d.buildSettings = ti.buildSettings.dup;
const buildId = computeBuildID(d.buildSettings, ti.config, settings);
const buildId = computeBuildID(d.buildSettings, ti.pack.path, ti.config, settings);
const filename = settings.compiler.getTargetFileName(d.buildSettings, settings.platform);
d.cacheArtifactPath = (targetCacheDir(settings.cache, ti.pack, buildId) ~ filename).toNativeString();
d.dependencies = ti.dependencies.dup;
Expand Down
14 changes: 14 additions & 0 deletions test/issue2840-build-collision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

. $(dirname "${BASH_SOURCE[0]}")/common.sh

pushd $(dirname "${BASH_SOURCE[0]}")/issue2840-build-collision
# Copy before building, as dub uses timestamp to check for rebuild
rm -rf nested/ && mkdir -p nested/ && cp -v build.d nested/

$DUB ./build.d $(pwd)/build.d
pushd nested
$DUB ./build.d $(pwd)/build.d
popd

popd
Empty file.
16 changes: 16 additions & 0 deletions test/issue2840-build-collision/build.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env dub
/++ dub.json:
{
"name": "build"
}
+/

import std.format;

immutable FullPath = __FILE_FULL_PATH__;

void main (string[] args)
{
assert(args.length == 2, "Expected a single argument");
assert(args[1] == FullPath, format("%s != %s -- %s", args[1], FullPath, args[0]));
}
Loading