diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index 19668025c..7d4ce2485 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -12,7 +12,7 @@ import dub.internal.vibecompat.inet.path; import dub.internal.configy.Attributes; import std.array : array; -import std.algorithm : filter, any; +import std.algorithm : filter, any, map; import std.path : globMatch; import std.typecons : BitFlags; import std.algorithm.iteration : uniq; @@ -135,8 +135,8 @@ struct BuildSettings { void removeDFlags(in string[] value...) { remove(dflags, value); } void addLFlags(in string[] value...) { lflags ~= value; } void prependLFlags(in string[] value...) { prepend(lflags, value, false); } - void addLibs(in string[] value...) { add(libs, value); } - void addLinkerFiles(in string[] value...) { add(linkerFiles, value); } + void addLibs(in string[] value...) { addPriortized(libs, value); } + void addLinkerFiles(in string[] value...) { addPriortized(linkerFiles, value); } void addSourceFiles(in string[] value...) { add(sourceFiles, value); } void prependSourceFiles(in string[] value...) { prepend(sourceFiles, value); } void removeSourceFiles(in string[] value...) { removePaths(sourceFiles, value); } @@ -199,7 +199,18 @@ private: foreach (val; vals) arr ~= filterDuplicates(arr, [val], noDuplicates); } - // Append `vals` to `aa` + // Adds new values while removing existing duplicates + // This version keeps the last occurrence of a duplicate in contrast to + // `add(..., true)`, which keeps the first occurrence + static void addPriortized(ref string[] arr, in string[] vals) + { + arr = arr + .filter!(av => !vals.any!(v => v == av)) + .chain(vals) + .map!(s => cast(string)s) + .array; + } + // Append `vals` to AA static void add(ref string[string] aa, in string[string] vals) { // vals might contain duplicated keys, add each val individually @@ -322,6 +333,19 @@ private: BuildSettings.remove(ary, ["root/path1", "foo"]); assert(ary == []); } + + unittest // ensure correct linking order of libs + { + BuildSettings bs_parent; + BuildSettings bs_dep1; + BuildSettings bs_dep2; + + bs_dep1.addLibs(["foo", "c++"]); + bs_dep2.addLibs(["bar", "c++"]); + bs_parent.add(bs_dep1); + bs_parent.add(bs_dep2); + assert(bs_parent.libs == ["foo", "bar", "c++"]); + } } enum BuildSetting { diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 0777f199f..7a8cbf68b 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -1453,7 +1453,7 @@ package struct Location { // Managed structure: $ROOT/$NAME/$VERSION/$NAME // This is the most common code path - else { + else if (mgr.isManagedPath(path)) { // Iterate over versions of a package foreach (versdir; mgr.iterateDirectory(pack_path)) { if (!versdir.isDirectory) continue; diff --git a/test/issue1005-configuration-resolution/a/1.0.0/a/dub.sdl b/test/issue1005-configuration-resolution/a/dub.sdl similarity index 100% rename from test/issue1005-configuration-resolution/a/1.0.0/a/dub.sdl rename to test/issue1005-configuration-resolution/a/dub.sdl diff --git a/test/issue1005-configuration-resolution/b/1.0.0/b/dub.sdl b/test/issue1005-configuration-resolution/b/dub.sdl similarity index 100% rename from test/issue1005-configuration-resolution/b/1.0.0/b/dub.sdl rename to test/issue1005-configuration-resolution/b/dub.sdl diff --git a/test/issue1005-configuration-resolution/b/1.0.0/b/source/b.d b/test/issue1005-configuration-resolution/b/source/b.d similarity index 100% rename from test/issue1005-configuration-resolution/b/1.0.0/b/source/b.d rename to test/issue1005-configuration-resolution/b/source/b.d diff --git a/test/issue1005-configuration-resolution/c/1.0.0/c/dub.sdl b/test/issue1005-configuration-resolution/c/dub.sdl similarity index 100% rename from test/issue1005-configuration-resolution/c/1.0.0/c/dub.sdl rename to test/issue1005-configuration-resolution/c/dub.sdl diff --git a/test/issue1005-configuration-resolution/main/~master/main/dub.sdl b/test/issue1005-configuration-resolution/main/dub.sdl similarity index 100% rename from test/issue1005-configuration-resolution/main/~master/main/dub.sdl rename to test/issue1005-configuration-resolution/main/dub.sdl diff --git a/test/issue1005-configuration-resolution/main/~master/main/source/app.d b/test/issue1005-configuration-resolution/main/source/app.d similarity index 100% rename from test/issue1005-configuration-resolution/main/~master/main/source/app.d rename to test/issue1005-configuration-resolution/main/source/app.d diff --git a/test/issue1024-selective-upgrade.sh b/test/issue1024-selective-upgrade.sh index ef6033348..dc7c00971 100755 --- a/test/issue1024-selective-upgrade.sh +++ b/test/issue1024-selective-upgrade.sh @@ -2,13 +2,13 @@ . $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue1024-selective-upgrade -echo "{\"fileVersion\": 1,\"versions\": {\"a\": \"1.0.0\", \"b\": \"1.0.0\"}}" > main/~master/main/dub.selections.json -$DUB upgrade --bare --root=main/~master/main/ a +echo "{\"fileVersion\": 1,\"versions\": {\"a\": \"1.0.0\", \"b\": \"1.0.0\"}}" > main/dub.selections.json +$DUB upgrade --bare --root=main a -if ! grep -c -e "\"a\": \"1.0.1\"" main/~master/main/dub.selections.json; then +if ! grep -c -e "\"a\": \"1.0.1\"" main/dub.selections.json; then die $LINENO "Specified dependency was not upgraded." fi -if grep -c -e "\"b\": \"1.0.1\"" main/~master/main/dub.selections.json; then +if grep -c -e "\"b\": \"1.0.1\"" main/dub.selections.json; then die $LINENO "Non-specified dependency got upgraded." fi diff --git a/test/issue1024-selective-upgrade/a/1.0.0/a/dub.sdl b/test/issue1024-selective-upgrade/a-1.0.0/dub.sdl similarity index 100% rename from test/issue1024-selective-upgrade/a/1.0.0/a/dub.sdl rename to test/issue1024-selective-upgrade/a-1.0.0/dub.sdl diff --git a/test/issue1024-selective-upgrade/a/1.0.1/a/dub.sdl b/test/issue1024-selective-upgrade/a-1.0.1/dub.sdl similarity index 100% rename from test/issue1024-selective-upgrade/a/1.0.1/a/dub.sdl rename to test/issue1024-selective-upgrade/a-1.0.1/dub.sdl diff --git a/test/issue1024-selective-upgrade/b/1.0.0/b/dub.sdl b/test/issue1024-selective-upgrade/b-1.0.0/dub.sdl similarity index 100% rename from test/issue1024-selective-upgrade/b/1.0.0/b/dub.sdl rename to test/issue1024-selective-upgrade/b-1.0.0/dub.sdl diff --git a/test/issue1024-selective-upgrade/b/1.0.1/b/dub.sdl b/test/issue1024-selective-upgrade/b-1.0.1/dub.sdl similarity index 100% rename from test/issue1024-selective-upgrade/b/1.0.1/b/dub.sdl rename to test/issue1024-selective-upgrade/b-1.0.1/dub.sdl diff --git a/test/issue1024-selective-upgrade/main/~master/main/dub.sdl b/test/issue1024-selective-upgrade/main/dub.sdl similarity index 100% rename from test/issue1024-selective-upgrade/main/~master/main/dub.sdl rename to test/issue1024-selective-upgrade/main/dub.sdl diff --git a/test/issue564-invalid-upgrade-dependency.sh b/test/issue564-invalid-upgrade-dependency.sh index fe1b6a38c..19258cec2 100755 --- a/test/issue564-invalid-upgrade-dependency.sh +++ b/test/issue564-invalid-upgrade-dependency.sh @@ -2,4 +2,7 @@ . $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue564-invalid-upgrade-dependency -${DUB} build -f --bare --compiler=${DC} main +rm -rf a-1.0.0/.dub +rm -rf a-1.1.0/.dub +rm -rf main/.dub +${DUB} build --bare --compiler=${DC} main diff --git a/test/issue564-invalid-upgrade-dependency/a/1.0.0/a/dub.json b/test/issue564-invalid-upgrade-dependency/a-1.0.0/dub.json similarity index 100% rename from test/issue564-invalid-upgrade-dependency/a/1.0.0/a/dub.json rename to test/issue564-invalid-upgrade-dependency/a-1.0.0/dub.json diff --git a/test/issue564-invalid-upgrade-dependency/a/1.0.0/a/source/a.d b/test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d similarity index 100% rename from test/issue564-invalid-upgrade-dependency/a/1.0.0/a/source/a.d rename to test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d diff --git a/test/issue564-invalid-upgrade-dependency/a/1.1.0/a/dub.json b/test/issue564-invalid-upgrade-dependency/a-1.1.0/dub.json similarity index 100% rename from test/issue564-invalid-upgrade-dependency/a/1.1.0/a/dub.json rename to test/issue564-invalid-upgrade-dependency/a-1.1.0/dub.json diff --git a/test/issue564-invalid-upgrade-dependency/a/1.1.0/a/source/a.d b/test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d similarity index 100% rename from test/issue564-invalid-upgrade-dependency/a/1.1.0/a/source/a.d rename to test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d diff --git a/test/issue564-invalid-upgrade-dependency/main/~master/main/dub.json b/test/issue564-invalid-upgrade-dependency/main/dub.json similarity index 100% rename from test/issue564-invalid-upgrade-dependency/main/~master/main/dub.json rename to test/issue564-invalid-upgrade-dependency/main/dub.json diff --git a/test/issue564-invalid-upgrade-dependency/main/dub.selections.json b/test/issue564-invalid-upgrade-dependency/main/dub.selections.json new file mode 100644 index 000000000..e24adfe02 --- /dev/null +++ b/test/issue564-invalid-upgrade-dependency/main/dub.selections.json @@ -0,0 +1,6 @@ +{ + "fileVersion": 1, + "versions": { + "a": "1.0.0" + } +} diff --git a/test/issue564-invalid-upgrade-dependency/main/~master/main/source/app.d b/test/issue564-invalid-upgrade-dependency/main/source/app.d similarity index 100% rename from test/issue564-invalid-upgrade-dependency/main/~master/main/source/app.d rename to test/issue564-invalid-upgrade-dependency/main/source/app.d diff --git a/test/issue813-pure-sub-dependency.sh b/test/issue813-pure-sub-dependency.sh index a76dee836..ec2291ebe 100755 --- a/test/issue813-pure-sub-dependency.sh +++ b/test/issue813-pure-sub-dependency.sh @@ -2,5 +2,8 @@ . $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue813-pure-sub-dependency -rm -f main/~master/main/dub.selections.json -${DUB} build -f --bare --compiler=${DC} main +rm -rf main/.dub +rm -rf sub/.dub +rm -rf sub/sub/.dub +rm -f main/dub.selections.json +${DUB} build --bare --compiler=${DC} main diff --git a/test/issue813-pure-sub-dependency/main/~master/main/dub.sdl b/test/issue813-pure-sub-dependency/main/dub.sdl similarity index 100% rename from test/issue813-pure-sub-dependency/main/~master/main/dub.sdl rename to test/issue813-pure-sub-dependency/main/dub.sdl diff --git a/test/issue813-pure-sub-dependency/main/~master/main/src/app.d b/test/issue813-pure-sub-dependency/main/src/app.d similarity index 100% rename from test/issue813-pure-sub-dependency/main/~master/main/src/app.d rename to test/issue813-pure-sub-dependency/main/src/app.d diff --git a/test/issue813-pure-sub-dependency/sub/~master/sub/dub.sdl b/test/issue813-pure-sub-dependency/sub/dub.sdl similarity index 100% rename from test/issue813-pure-sub-dependency/sub/~master/sub/dub.sdl rename to test/issue813-pure-sub-dependency/sub/dub.sdl diff --git a/test/issue813-pure-sub-dependency/sub/~master/sub/sub/dub.sdl b/test/issue813-pure-sub-dependency/sub/sub/dub.sdl similarity index 100% rename from test/issue813-pure-sub-dependency/sub/~master/sub/sub/dub.sdl rename to test/issue813-pure-sub-dependency/sub/sub/dub.sdl diff --git a/test/issue813-pure-sub-dependency/sub/~master/sub/sub/src/sub/test.d b/test/issue813-pure-sub-dependency/sub/sub/src/sub/test.d similarity index 100% rename from test/issue813-pure-sub-dependency/sub/~master/sub/sub/src/sub/test.d rename to test/issue813-pure-sub-dependency/sub/sub/src/sub/test.d diff --git a/test/issue923-subpackage-deps.sh b/test/issue923-subpackage-deps.sh index 67e137bb4..f3be79c4f 100755 --- a/test/issue923-subpackage-deps.sh +++ b/test/issue923-subpackage-deps.sh @@ -2,10 +2,13 @@ . $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue923-subpackage-deps -rm -f main/~master/main/dub.selections.json -${DUB} build -f --bare --compiler=${DC} main +rm -rf main/.dub +rm -rf a/.dub +rm -rf b/.dub +rm -f main/dub.selections.json +${DUB} build --bare --compiler=${DC} main -if ! grep -c -e \"b\" main/~master/main/dub.selections.json; then +if ! grep -c -e \"b\" main/dub.selections.json; then die $LINENO 'Dependency b not resolved.' fi diff --git a/test/issue923-subpackage-deps/a/1.0.0/a/dub.sdl b/test/issue923-subpackage-deps/a/dub.sdl similarity index 100% rename from test/issue923-subpackage-deps/a/1.0.0/a/dub.sdl rename to test/issue923-subpackage-deps/a/dub.sdl diff --git a/test/issue923-subpackage-deps/b/1.0.0/b/dub.sdl b/test/issue923-subpackage-deps/b/dub.sdl similarity index 100% rename from test/issue923-subpackage-deps/b/1.0.0/b/dub.sdl rename to test/issue923-subpackage-deps/b/dub.sdl diff --git a/test/issue923-subpackage-deps/b/1.0.0/b/source/b.d b/test/issue923-subpackage-deps/b/source/b.d similarity index 100% rename from test/issue923-subpackage-deps/b/1.0.0/b/source/b.d rename to test/issue923-subpackage-deps/b/source/b.d diff --git a/test/issue923-subpackage-deps/main/~master/main/dub.sdl b/test/issue923-subpackage-deps/main/dub.sdl similarity index 100% rename from test/issue923-subpackage-deps/main/~master/main/dub.sdl rename to test/issue923-subpackage-deps/main/dub.sdl diff --git a/test/issue923-subpackage-deps/main/~master/main/source/app.d b/test/issue923-subpackage-deps/main/source/app.d similarity index 100% rename from test/issue923-subpackage-deps/main/~master/main/source/app.d rename to test/issue923-subpackage-deps/main/source/app.d