Skip to content

Commit

Permalink
Revert "Fix #2691: Use same structure for managed and unmanaged path"
Browse files Browse the repository at this point in the history
This reverts commit 1a53049.
  • Loading branch information
s-ludwig committed Feb 16, 2024
1 parent 85a78c0 commit 724cab7
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 15 deletions.
32 changes: 28 additions & 4 deletions source/dub/compilers/buildsettings.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/issue1024-selective-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion test/issue564-invalid-upgrade-dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fileVersion": 1,
"versions": {
"a": "1.0.0"
}
}
7 changes: 5 additions & 2 deletions test/issue813-pure-sub-dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions test/issue923-subpackage-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 724cab7

Please sign in to comment.