diff --git a/build.d b/build.d index 040b502..03038f4 100755 --- a/build.d +++ b/build.d @@ -35,7 +35,11 @@ /// Path to the file containing the files to be built immutable SourceListPath = RootPath.buildPath("build-files.txt"); /// Path at which the newly built `dub` binary will be -immutable DubBinPath = RootPath.buildPath("bin", "dub"); +version (Windows) { + immutable DubBinPath = RootPath.buildPath("bin", "dub.exe"); +} else { + immutable DubBinPath = RootPath.buildPath("bin", "dub"); +} // Flags for DMD immutable OutputFlag = "-of" ~ DubBinPath; diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 058953c..029a482 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -189,7 +189,10 @@ * A `Package` if one was found, `null` if none exists. */ private Package lookup (string name, Version vers) { - if (auto pkg = this.m_internal.lookup(name, vers)) + if (!this.m_initialized) + this.refresh(); + + if (auto pkg = this.m_internal.lookup(name, vers, this)) return pkg; foreach (ref location; this.m_repositories) @@ -493,7 +496,7 @@ Managed packages can be upgraded and removed. */ - bool isManagedPackage(Package pack) + bool isManagedPackage(const(Package) pack) const { auto ppath = pack.basePackage.path; return isManagedPath(ppath); @@ -1356,13 +1359,15 @@ * Returns: * A `Package` if one was found, `null` if none exists. */ - private inout(Package) lookup(string name, Version ver) inout { + private inout(Package) lookup(string name, Version ver, PackageManager mgr) inout { foreach (pkg; this.localPackages) - if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict)) + if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.standard)) return pkg; - foreach (pkg; this.fromPath) - if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict)) + foreach (pkg; this.fromPath) { + auto pvm = mgr.isManagedPackage(pkg) ? VersionMatchMode.strict : VersionMatchMode.standard; + if (pkg.name == name && pkg.version_.matches(ver, pvm)) return pkg; + } return null; } @@ -1383,7 +1388,7 @@ */ private Package load (string name, Version vers, PackageManager mgr) { - if (auto pkg = this.lookup(name, vers)) + if (auto pkg = this.lookup(name, vers, mgr)) return pkg; string versStr = vers.toString(); diff --git a/test/prefer-add-path-packages.sh b/test/prefer-add-path-packages.sh new file mode 100755 index 0000000..af8bc05 --- /dev/null +++ b/test/prefer-add-path-packages.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +. $(dirname ${BASH_SOURCE[0]})/common.sh + +TMPDIR=$CURR_DIR/tmp-add-path + +PACK_PATH="$CURR_DIR"/issue2262-exact-cached-version-match + +# make sure that there are no left-over selections files or temp directory +rm -f $PACK_PATH/dub.selections.json +rm -rf $TMPDIR + +# make sure that there are no cached versions of the dependency +$DUB remove gitcompatibledubpackage@* -n || true + +# build normally, should select 1.0.4 +if ! ${DUB} build --root $PACK_PATH | grep "gitcompatibledubpackage 1\.0\.4:"; then + die $LINENO 'The initial build failed.' +fi + +# clone gitcompatibledubpackage and check out 1.0.4+commit.2.ccb31bf +mkdir $TMPDIR +$DUB add-path $TMPDIR +cd $TMPDIR +git clone https://github.com/dlang-community/gitcompatibledubpackage.git +cd gitcompatibledubpackage +git checkout -q ccb31bf6a655437176ec02e04c2305a8c7c90d67 +cd ../.. + +if ! $DUB list | grep "gitcompatibledubpackage 1\.0\.4+commit.2.gccb31bf"; then + $DUB remove-path $TMPDIR + die $LINENO 'Cloned package was not found in search path' +fi + +# should pick up the cloned package instead of the cached one now +if ! ${DUB} build --root $PACK_PATH | grep "gitcompatibledubpackage 1\.0\.4+commit.2.gccb31bf:"; then + $DUB remove-path $TMPDIR + die $LINENO 'Did not pick up the add-path package.' +fi + +# clean up +$DUB remove-path $TMPDIR +rm -f $PACK_PATH/dub.selections.json +rm -rf $TMPDIR