diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a3a2f3..e6490ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,6 +63,8 @@ # The value doesn't matter as long as it's > 2.087 FRONTEND: 2.093.0 run: | + dub build --compiler=${{ env.DC }} + dub run --compiler=${{ env.DC }} --single test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d ./scripts/ci/travis.sh - name: '[Windows] Test' @@ -72,3 +74,4 @@ run: | dub build --compiler=${{ env.DC }} dub test --compiler=${{ env.DC }} + dub run --compiler=${{ env.DC }} --single test\issue_2051_running_unittests_from_dub_single_file_packages_fails.d diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f2b5a9d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,114 +0,0 @@ -language: d -dist: bionic - -addons: - apt: - packages: - - libevent-dev - -script: - - ./scripts/ci/travis.sh - -jobs: - allow_failures: - - d: gdc - include: - - stage: test - d: dmd-2.093.0 - env: [FRONTEND=2.093, COVERAGE=true] - - d: dmd-2.089.1,dub - env: [FRONTEND=2.089] - - d: dmd-2.083.1,dub - env: [FRONTEND=2.083] - - d: ldc-1.22.0 - env: [FRONTEND=2.092] - - d: ldc-1.20.0,dub - env: [FRONTEND=2.090] - - stage: deploy - d: ldc-1.22.0,dub - os: osx - addons: - homebrew: - packages: - - gnu-tar - update: true - script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh - deploy: - - provider: releases - file_glob: true - file: bin/dub-*.tar.gz - skip_cleanup: true - api_key: $GH_REPO_TOKEN - on: - tags: true - - d: ldc-1.22.0,dub - script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh - env: [ARCH=32] - addons: - apt: - packages: - - g++-multilib - - libcurl4-openssl-dev:i386 - deploy: - - provider: releases - file_glob: true - file: bin/dub-*.tar.gz - skip_cleanup: true - api_key: $GH_REPO_TOKEN - on: - tags: true - - d: ldc-1.22.0,dub - script: echo "Deploying to GitHub releases ..." && ./scripts/ci/release.sh - deploy: - - provider: releases - file_glob: true - file: bin/dub-*.tar.gz - skip_cleanup: true - api_key: $GH_REPO_TOKEN - on: - tags: true - - d: ldc-1.22.0,dub - script: echo "Deploying to GitHub releases (win32) ..." && ./scripts/ci/release-windows.sh - addons: - apt: - packages: - - p7zip-full - deploy: - - provider: releases - file_glob: true - file: bin/dub-*.zip - skip_cleanup: true - api_key: $GH_REPO_TOKEN - on: - tags: true - - d: ldc-1.22.0,dub - script: echo "Deploying to GitHub releases (win64) ..." && ARCH=64 ./scripts/ci/release-windows.sh - addons: - apt: - packages: - - p7zip-full - deploy: - - provider: releases - file_glob: true - file: bin/dub-*.zip - skip_cleanup: true - api_key: $GH_REPO_TOKEN - on: - tags: true - - stage: update-latest - script: echo "Deploying to GitHub pages ..." && mkdir -p docs && git describe --abbrev=0 --tags > docs/LATEST - deploy: - - provider: pages - skip_cleanup: true - local_dir: docs - github_token: $GH_REPO_TOKEN - on: - tags: true -stages: - - name: test - if: type = pull_request or (type = push and branch = master) - # Until deployment of the release binaries is fixed, always build them - #- name: deploy - #if: type = push and tag =~ ^v\d+\.\d+\.\d+[^-]*\$ # not a pre-release tag - - name: update-latest - if: type = push and tag =~ ^v\d+\.\d+\.\d+[^-]*\$ # not a pre-release tag diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 9d5e983..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,123 +0,0 @@ -platform: x64 -environment: - matrix: - #- DC: dmd - # DVersion: nightly - # arch: x64 - #- DC: dmd - # DVersion: nightly - # arch: x86 - - DC: dmd - DVersion: beta - arch: x64 - - DC: dmd - DVersion: beta - arch: x86 - - DC: dmd - DVersion: stable - arch: x64 - - DC: dmd - DVersion: 2.086.0 - arch: x86 - - DC: dmd - DVersion: 2.086.0 - arch: x64 - - DC: dmd - DVersion: stable - arch: x86 - - DC: ldc - DVersion: stable - arch: x64 - - DC: ldc - DVersion: 1.15.0 - arch: x64 - -skip_tags: false -branches: - only: - - master - - stable - -install: - - ps: function ResolveLatestDMD - { - $version = $env:DVersion; - if($version -eq "stable") { - $latest = (Invoke-WebRequest "http://downloads.dlang.org/releases/LATEST").toString(); - $url = "http://downloads.dlang.org/releases/2.x/$($latest)/dmd.$($latest).windows.7z"; - }elseif($version -eq "beta") { - $latest = (Invoke-WebRequest "http://downloads.dlang.org/pre-releases/LATEST").toString(); - $latestVersion = $latest.split("-")[0].split("~")[0]; - $url = "http://downloads.dlang.org/pre-releases/2.x/$($latestVersion)/dmd.$($latest).windows.7z"; - }elseif($version -eq "nightly") { - $url = "http://nightlies.dlang.org/dmd-master-2017-05-20/dmd.master.windows.7z" - }else { - $url = "http://downloads.dlang.org/releases/2.x/$($version)/dmd.$($version).windows.7z"; - } - $env:PATH += ";C:\dmd2\windows\bin;"; - return $url; - } - - ps: function ResolveLatestLDC - { - $version = $env:DVersion; - $arch = $env:arch; - if($version -eq "stable") { - $latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST").toString().replace("`n","").replace("`r",""); - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-windows-$($arch).7z"; - }elseif($version -eq "beta") { - $latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST_BETA").toString().replace("`n","").replace("`r",""); - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-windows-$($arch).7z"; - } else { - $latest = $version; - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($version)/ldc2-$($version)-windows-$($arch).7z"; - } - $env:PATH += ";C:\ldc2-$($latest)-windows-$($arch)\bin"; - $env:DC = "ldc2"; - return $url; - } - - ps: function SetUpDCompiler - { - $env:toolchain = "msvc"; - if($env:DC -eq "dmd"){ - echo "downloading ..."; - $url = ResolveLatestDMD; - echo $url; - Invoke-WebRequest $url -OutFile "c:\dmd.7z"; - echo "finished."; - pushd c:\\; - 7z x dmd.7z > $null; - popd; - } - elseif($env:DC -eq "ldc"){ - echo "downloading ..."; - $url = ResolveLatestLDC; - echo $url; - Invoke-WebRequest $url -OutFile "c:\ldc.zip"; - echo "finished."; - pushd c:\\; - 7z x ldc.zip > $null; - popd; - } - } - - ps: SetUpDCompiler - -build_script: - - ps: if($env:arch -eq "x86"){ - $env:compilersetupargs = "x86"; - $env:Darch = "x86"; - $env:DConf = "m32"; - }elseif($env:arch -eq "x64"){ - $env:compilersetupargs = "amd64"; - $env:Darch = "x86_64"; - $env:DConf = "m64"; - } - - ps: $env:compilersetup = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall"; - - '"%compilersetup%" %compilersetupargs%' - -test_script: - - echo %PLATFORM% - - echo %Darch% - - echo %DC% - - echo %PATH% - - '%DC% --version' - - dub test --arch=%Darch% --compiler=%DC% diff --git a/build-gdc.sh b/build-gdc.sh deleted file mode 100755 index df0e5ce..0000000 --- a/build-gdc.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -set -e - -if [ "$GDC" = "" ]; then - GDC=gdc -fi - -# link against libcurl -LIBS=`pkg-config --libs libcurl 2>/dev/null || echo "-lcurl"` - -# adjust linker flags for gdc command line -LIBS=`echo "$LIBS" | sed 's/^-L/-L-L/; s/ -L/ -L-L/g; s/^-l/-L-l/; s/ -l/ -L-l/g'` - -echo Generating version file... -GITVER=$(git describe) || GITVER=unknown -echo "module dub.version_;" > source/dub/version_.d -echo "enum dubVersion = \"$GITVER\";" >> source/dub/version_.d - -echo Running $GDC... -$GDC -obin/dub -lcurl -w -fversion=DubUseCurl -fversion=DubApplication -Isource $* $LIBS @build-files.txt -echo DUB has been built as bin/dub. -echo -echo You may want to run -echo sudo ln -s $(pwd)/bin/dub /usr/local/bin -echo now. diff --git a/changelog/add-ability-for-specify-version-range-for-commandline-commands.dd b/changelog/add-ability-for-specify-version-range-for-commandline-commands.dd new file mode 100644 index 0000000..72ca62a --- /dev/null +++ b/changelog/add-ability-for-specify-version-range-for-commandline-commands.dd @@ -0,0 +1,10 @@ +All commands now accept a version specification + +Before this release dub could only get an exact version for some commands +(`describe`, `generate`, `fetch`, etc...). All commands now accept a version specification, +such as can be found in `dub.json` / `dub.sdl`: + + dub fetch 'foo@>0.2.0' + dub describe foo@'>=0.3.0 <1.0.0' + +Note that commands such as `describe` will still not fetch from the network. diff --git a/changelog/dependency-build-settings.dd b/changelog/dependency-build-settings.dd new file mode 100644 index 0000000..8859018 --- /dev/null +++ b/changelog/dependency-build-settings.dd @@ -0,0 +1,15 @@ +Allow custom build settings to be defined for dependencies + +For example: +--- +{ + "name": "example", + "dependencies": { + "vibe-d": { "version" : "~>0.9.2", "dflags" : ["-preview=in"] } + } +} +--- + +In this example, `-preview=in` will be applied to `vibe-d` and all of its dependencies. +Any $(LINK2 build settings, https://dub.pm/package-format-json.html#build-settings) field will be parsed, +however only `dflags` is taken into account when compiling for now. diff --git a/changelog/dont-propagate-flags.dd b/changelog/dont-propagate-flags.dd new file mode 100644 index 0000000..dd5a3fa --- /dev/null +++ b/changelog/dont-propagate-flags.dd @@ -0,0 +1,10 @@ +`DFLAGS` and `LFLAGS` no longer propagate to nested `dub` invocations + +`DFLAGS` and `LFLAGS` will no longer be exported as environment variables by default +when invoking pre-generate, pre-build, pre-run, post-generate, post-build, or post-run commands. + +If the previous behavior is still desired, they can be accessed using `$DFLAGS` and `$LFLAGS` in dub.json +E.g.: +`preGenerateCommands : ["DFLAGS=$DFLAGS env | grep DFLAGS"]` + +will output DFLAGS environment variable with all the dflags used. diff --git a/changelog/env-d-compiler.dd b/changelog/env-d-compiler.dd new file mode 100644 index 0000000..8769cea --- /dev/null +++ b/changelog/env-d-compiler.dd @@ -0,0 +1,6 @@ +Use DC environment variable as default D compiler + +dub now respects the `DC` environment variable, meaning that `DC=ldc2 dub build` will behave as `dub build --compiler=ldc2`. +In case both are supplied, the `--compiler` switch still has priority. +Note that when DUB recursively invokes itself, for example in `preGenerateCommands`, +it sets the `DC` variable to the compiler it is using, meaning that nested dub invocation will now use the same compiler. diff --git a/changelog/fix-2051.dd b/changelog/fix-2051.dd new file mode 100644 index 0000000..497d7ae --- /dev/null +++ b/changelog/fix-2051.dd @@ -0,0 +1,3 @@ +Fix #2051 "Running unit tests from DUB single file packages fails" + +Now dub is capable run test command in single mode like: `dub test --single yoursinglefile.d` \ No newline at end of file diff --git a/changelog/improved-ldc-cross-compile.dd b/changelog/improved-ldc-cross-compile.dd new file mode 100644 index 0000000..1ddaf22 --- /dev/null +++ b/changelog/improved-ldc-cross-compile.dd @@ -0,0 +1,3 @@ +Improve ldc cross compilation + +Enables co-existence and parallel compilation of the same project with different settings (e.g. cross compilation) by moving `.dub/obj` to `$DUB_TARGET_PATH/obj`. \ No newline at end of file diff --git a/changelog/improved-list-command.dd b/changelog/improved-list-command.dd new file mode 100644 index 0000000..c52a061 --- /dev/null +++ b/changelog/improved-list-command.dd @@ -0,0 +1,6 @@ +Filter ability for list command + +For list command added optional filtration by name and version specification: + + dub list foo + dub list foo@'>=0.1.0 <1.0.0' diff --git a/semaphore-ci.sh b/semaphore-ci.sh deleted file mode 100755 index c942ed9..0000000 --- a/semaphore-ci.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -set -euo pipefail -set -x - -if [ "${D_VERSION:-dmd}" == "gdc" ] ; then - echo "GDC unrelated test failures to be fixed" - exit 0 - - # Use the dub-updating fork of the installer script until https://github.com/dlang/installer/pull/301 is merged - wget https://raw.githubusercontent.com/wilzbach/installer-dub/master/script/install.sh -O install.dub.sh - bash install.dub.sh -a dub - dub_path_activate="$(find $HOME/dlang/*/activate | head -1)" - rm "${dub_path_activate}" - dub_path="$(dirname "$dub_path_activate")" - sudo ln -s "${dub_path}/dub" /usr/bin/dub - - export DMD=gdmd - export DC=gdc - # It's technically ~"2.076", but Ternary doesn't seem to have been ported and Vibe.d seems to depend on this. - # Ternary was added in 2.072: https://dlang.org/phobos/std_typecons.html#.Ternary - # However, the nonet tests is done only for > 2.072 - export FRONTEND=2.072 - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install -y gdc-9 - # fetch the dmd-like wrapper - sudo wget https://raw.githubusercontent.com/D-Programming-GDC/GDMD/master/dmd-script -O /usr/bin/gdmd - sudo chmod +x /usr/bin/gdmd - # DUB requires gdmd - sudo ln -s /usr/bin/gdc-9 /usr/bin/gdc - # fake install script and create a fake 'activate' script - mkdir -p ~/dlang/gdc-9 - echo "deactivate(){ echo;}" > ~/dlang/gdc-9/activate - -else - . $(curl --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 --retry-max-time 60 https://dlang.org/install.sh | bash -s "$D_VERSION" -a) -fi - -./scripts/ci/travis.sh diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 4e0932c..04f5d69 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -991,11 +991,10 @@ protected void setupVersionPackage(Dub dub, string str_package_info, string default_build_type = "debug") { PackageAndVersion package_info = splitPackageName(str_package_info); - Version ver = package_info.version_.length ? Version(package_info.version_) : Version.unknown; - setupPackage(dub, package_info.name, default_build_type, ver); + setupPackage(dub, package_info.name, default_build_type, package_info.version_); } - protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", Version ver = Version.unknown) + protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", string ver = "") { if (!m_compilerName.length) m_compilerName = dub.defaultCompiler; if (!m_arch.length) m_arch = dub.defaultArchitecture; @@ -1039,7 +1038,7 @@ } } - private bool loadSpecificPackage(Dub dub, string package_name, Version ver) + private bool loadSpecificPackage(Dub dub, string package_name, string ver) { if (m_single) { enforce(package_name.length, "Missing file name of single-file package."); @@ -1061,12 +1060,12 @@ enforce(package_name.length, "No valid root package found - aborting."); - auto pack = ver.isUnknown + auto pack = ver == "" ? dub.packageManager.getLatestPackage(package_name) - : dub.packageManager.getPackage(package_name, ver); + : dub.packageManager.getBestPackage(package_name, ver); enforce(pack, format!"Failed to find a package named '%s%s' locally."(package_name, - ver.isUnknown ? "" : "@" ~ ver.toString() + ver == "" ? "" : ("@" ~ ver) )); logInfo("Building package %s in %s", pack.name, pack.path.toNativeString()); dub.loadPackage(pack); @@ -2062,20 +2061,28 @@ this() @safe pure nothrow { this.name = "list"; - this.argumentsPattern = ""; - this.description = "Prints a list of all local packages dub is aware of"; + this.argumentsPattern = "[[@]]"; + this.description = "Prints a list of all or selected local packages dub is aware of"; this.helpText = [ - "Prints a list of all local packages. This includes all cached packages (user or system wide), all packages in the package search paths (\"dub add-path\") and all manually registered packages (\"dub add-local\")." + "Prints a list of all or selected local packages. This includes all cached "~ + "packages (user or system wide), all packages in the package search paths "~ + "(\"dub add-path\") and all manually registered packages (\"dub add-local\"). "~ + "If package specified output filtered by package spec." ]; } override void prepare(scope CommandArgs args) {} override int execute(Dub dub, string[] free_args, string[] app_args) { - enforceUsage(free_args.length == 0, "Expecting no extra arguments."); + enforceUsage(free_args.length <= 1, "Expecting zero or one extra arguments."); + const pinfo = free_args.length ? splitPackageName(free_args[0]) : PackageAndVersion("","*"); + const pname = pinfo.name; + const pvlim = Dependency(pinfo.version_ == "" ? "*" : pinfo.version_); enforceUsage(app_args.length == 0, "The list command supports no application arguments."); logInfo("Packages present in the system and known to dub:"); - foreach (p; dub.packageManager.getPackageIterator()) - logInfo(" %s %s: %s", p.name, p.version_, p.path.toNativeString()); + foreach (p; dub.packageManager.getPackageIterator()) { + if ((pname == "" || pname == p.name) && pvlim.matches(p.version_)) + logInfo(" %s %s: %s", p.name, p.version_, p.path.toNativeString()); + } logInfo(""); return 0; } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 232c44a..2fbe362 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -104,6 +104,7 @@ void prepareBuildSettings(ref BuildSettings settings, const scope ref BuildPlatform platform, BuildSetting fields = BuildSetting.all) const { + import std.format : format; enforceBuildRequirements(settings); if (!(fields & BuildSetting.options)) { @@ -113,7 +114,7 @@ } // since LDC always outputs multiple object files, avoid conflicts by default - settings.addDFlags("--oq", "-od=.dub/obj"); + settings.addDFlags("--oq", format("-od=%s/obj", settings.targetPath)); if (!(fields & BuildSetting.versions)) { settings.addDFlags(settings.versions.map!(s => "-d-version="~s)().array()); diff --git a/source/dub/dub.d b/source/dub/dub.d index 3d05126..e88ece2 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -663,7 +663,10 @@ foreach (file; lbuildsettings.sourceFiles) { if (file.endsWith(".d")) { auto fname = NativePath(file).head.name; - if (NativePath(file).relativeTo(m_project.rootPackage.path) == NativePath(mainfil)) { + NativePath msf = NativePath(mainfil); + if (msf.absolute) + msf = msf.relativeTo(m_project.rootPackage.path); + if (NativePath(file).relativeTo(m_project.rootPackage.path) == msf) { logWarn("Excluding main source file %s from test.", mainfil); tcinfo.excludedSourceFiles[""] ~= mainfil; continue; @@ -817,7 +820,6 @@ // TODO: clear target files and copy files if (existsFile(path ~ ".dub/build")) rmdirRecurse((path ~ ".dub/build").toNativeString()); - if (existsFile(path ~ ".dub/obj")) rmdirRecurse((path ~ ".dub/obj").toNativeString()); if (existsFile(path ~ ".dub/metadata_cache.json")) std.file.remove((path ~ ".dub/metadata_cache.json").toNativeString()); auto p = Package.load(path); @@ -1380,7 +1382,11 @@ import std.process : environment; import std.range : front; - m_defaultCompiler = m_config.defaultCompiler.expandTilde; + // Env takes precedence + if (auto envCompiler = environment.get("DC")) + m_defaultCompiler = envCompiler; + else + m_defaultCompiler = m_config.defaultCompiler.expandTilde; if (m_defaultCompiler.length && m_defaultCompiler.isAbsolute) return; diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index cf47fd8..9ab99e7 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -314,20 +314,45 @@ visited.clear(); // 1. downwards inherits versions, debugVersions, and inheritable build settings - static void configureDependencies(const scope ref TargetInfo ti, TargetInfo[string] targets, size_t level = 0) + static void configureDependencies(const scope ref TargetInfo ti, TargetInfo[string] targets, + BuildSettings[string] dependBS, size_t level = 0) { + + static void applyForcedSettings(const scope ref BuildSettings forced, ref BuildSettings child) { + child.addDFlags(forced.dflags); + } + // do not use `visited` here as dependencies must inherit // configurations from *all* of their parents logDebug("%sConfigure dependencies of %s, deps:%(%s, %)", ' '.repeat(2 * level), ti.pack.name, ti.dependencies); foreach (depname; ti.dependencies) { + BuildSettings forcedSettings; auto pti = &targets[depname]; mergeFromDependent(ti.buildSettings, pti.buildSettings); - configureDependencies(*pti, targets, level + 1); + + if (auto matchedSettings = depname in dependBS) + forcedSettings = *matchedSettings; + else if (auto matchedSettings = "*" in dependBS) + forcedSettings = *matchedSettings; + + applyForcedSettings(forcedSettings, pti.buildSettings); + configureDependencies(*pti, targets, ["*" : forcedSettings], level + 1); } } - configureDependencies(*roottarget, targets); + BuildSettings[string] dependencyBuildSettings; + foreach (key, value; rootPackage.recipe.buildSettings.dependencyBuildSettings) + { + BuildSettings buildSettings; + if (auto target = key in targets) + { + value.getPlatformSettings(buildSettings, genSettings.platform, target.pack.path); + buildSettings.processVars(m_project, target.pack, buildSettings, genSettings, true); + dependencyBuildSettings[key] = buildSettings; + } + } + configureDependencies(*roottarget, targets, dependencyBuildSettings); // 2. add Have_dependency_xyz for all direct dependencies of a target // (includes incorporated non-target dependencies and their dependencies) @@ -776,8 +801,6 @@ string[string] env = environment.toAA(); // TODO: do more elaborate things here // TODO: escape/quote individual items appropriately - env["DFLAGS"] = join(cast(string[])build_settings.dflags, " "); - env["LFLAGS"] = join(cast(string[])build_settings.lflags," "); env["VERSIONS"] = join(cast(string[])build_settings.versions," "); env["LIBS"] = join(cast(string[])build_settings.libs," "); env["SOURCE_FILES"] = join(cast(string[])build_settings.sourceFiles," "); diff --git a/source/dub/internal/libInputVisitor.d b/source/dub/internal/libInputVisitor.d index d388b78..4961549 100644 --- a/source/dub/internal/libInputVisitor.d +++ b/source/dub/internal/libInputVisitor.d @@ -1,4 +1,4 @@ -module dub.internal.libInputVisitor; +module dub.internal.libInputVisitor; version (Have_libInputVisitor) public import libInputVisitor; else: diff --git a/source/dub/internal/sdlang/parser.d b/source/dub/internal/sdlang/parser.d index 8ccf119..023dffc 100644 --- a/source/dub/internal/sdlang/parser.d +++ b/source/dub/internal/sdlang/parser.d @@ -1,4 +1,4 @@ -// SDLang-D +// SDLang-D // Written in the D programming language. module dub.internal.sdlang.parser; diff --git a/source/dub/project.d b/source/dub/project.d index edfd20b..2f96a8e 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1396,6 +1396,15 @@ if (name == "BUILD_TYPE") return gsettings.buildType; + if (name == "DFLAGS" || name == "LFLAGS") + { + auto buildSettings = pack.getBuildSettings(gsettings.platform, gsettings.config); + if (name == "DFLAGS") + return join(buildSettings.dflags," "); + else if (name == "LFLAGS") + return join(buildSettings.lflags," "); + } + auto envvar = environment.get(name); if (envvar !is null) return envvar; @@ -1419,6 +1428,10 @@ } string name; NativePath path; + BuildSettings getBuildSettings(in BuildPlatform platform, string config) const + { + return BuildSettings(); + } } static struct MockProject diff --git a/source/dub/recipe/json.d b/source/dub/recipe/json.d index 54486c7..60e7626 100644 --- a/source/dub/recipe/json.d +++ b/source/dub/recipe/json.d @@ -177,7 +177,13 @@ pkg = package_name ~ pkg; } enforce(pkg !in bs.dependencies, "The dependency '"~pkg~"' is specified more than once." ); - bs.dependencies[pkg] = deserializeJson!Dependency(verspec); + bs.dependencies[pkg] = Dependency.fromJson(verspec); + if (verspec.type == Json.Type.object) + { + BuildSettingsTemplate dbs; + dbs.parseJson(verspec, package_name); + bs.dependencyBuildSettings[pkg] = dbs; + } } break; case "systemDependencies": @@ -251,7 +257,7 @@ if( bs.dependencies !is null ){ auto deps = Json.emptyObject; foreach( pack, d; bs.dependencies ) - deps[pack] = serializeToJson(d); + deps[pack] = d.toJson(); ret["dependencies"] = deps; } if (bs.systemDependencies !is null) ret["systemDependencies"] = bs.systemDependencies; diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index e03fa92..f03a943 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -176,6 +176,7 @@ /// a certain BuildPlatform. struct BuildSettingsTemplate { Dependency[string] dependencies; + BuildSettingsTemplate[string] dependencyBuildSettings; string systemDependencies; TargetType targetType = TargetType.autodetect; string targetPath; diff --git a/test/.gitignore b/test/.gitignore index e8ce8bd..6b02e75 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -17,3 +17,4 @@ version-spec/**/foo /test_registry +/issue_2051_running_unittests_from_dub_single_file_packages_fails diff --git a/test/dc-env.sh b/test/dc-env.sh new file mode 100755 index 0000000..e5ea3bc --- /dev/null +++ b/test/dc-env.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh +cd ${CURR_DIR}/issue2012-dc-env + +$DUB app.d ${DC} diff --git a/test/depen-build-settings/.gitignore b/test/depen-build-settings/.gitignore new file mode 100644 index 0000000..3dfd42f --- /dev/null +++ b/test/depen-build-settings/.gitignore @@ -0,0 +1,4 @@ +depend.json +depend2.json +depen-build-settings.json +depen-build-settings diff --git a/test/depen-build-settings/.no_test b/test/depen-build-settings/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/depen-build-settings/.no_test diff --git a/test/depen-build-settings/depend/depend2/dub.json b/test/depen-build-settings/depend/depend2/dub.json new file mode 100644 index 0000000..b3ac9ae --- /dev/null +++ b/test/depen-build-settings/depend/depend2/dub.json @@ -0,0 +1,5 @@ +{ + "targetType": "library", + "description": "A minimal D application.", + "name": "depend2" +} diff --git a/test/depen-build-settings/depend/depend2/source/depend2.d b/test/depen-build-settings/depend/depend2/source/depend2.d new file mode 100644 index 0000000..31b6367 --- /dev/null +++ b/test/depen-build-settings/depend/depend2/source/depend2.d @@ -0,0 +1,6 @@ +import std.stdio; + +extern (C) void depend2_func() +{ + writeln("depend2_func"); +} diff --git a/test/depen-build-settings/depend/dub.json b/test/depen-build-settings/depend/dub.json new file mode 100644 index 0000000..4d7ad5a --- /dev/null +++ b/test/depen-build-settings/depend/dub.json @@ -0,0 +1,9 @@ +{ + "targetType": "library", + "description": "A minimal D application.", + "name": "depend1", + + "dependencies": { + "depend2": { "version" : "*" } + } +} diff --git a/test/depen-build-settings/depend/source/depend.d b/test/depen-build-settings/depend/source/depend.d new file mode 100644 index 0000000..d9bb981 --- /dev/null +++ b/test/depen-build-settings/depend/source/depend.d @@ -0,0 +1,9 @@ +import std.stdio; + +extern (C) void depend2_func(); + +extern (C) void depend1_func() +{ + writeln("depend1_func"); + depend2_func(); +} diff --git a/test/depen-build-settings/dub.json b/test/depen-build-settings/dub.json new file mode 100644 index 0000000..1769ac1 --- /dev/null +++ b/test/depen-build-settings/dub.json @@ -0,0 +1,8 @@ +{ + "description": "A minimal D application.", + "name": "depen-build-settings", + + "dependencies": { + "depend1": { "version" : "*", "dflags" : ["-X"] } + } +} diff --git a/test/depen-build-settings/dub.selections.json b/test/depen-build-settings/dub.selections.json new file mode 100644 index 0000000..584b513 --- /dev/null +++ b/test/depen-build-settings/dub.selections.json @@ -0,0 +1,7 @@ +{ + "fileVersion": 1, + "versions": { + "depend1": {"path":"depend/"}, + "depend2": {"path":"depend/depend2/"} + } +} diff --git a/test/depen-build-settings/source/app.d b/test/depen-build-settings/source/app.d new file mode 100644 index 0000000..8893119 --- /dev/null +++ b/test/depen-build-settings/source/app.d @@ -0,0 +1,12 @@ +import std.stdio; +import std.file; + +extern (C) void depend1_func(); + +void main() +{ + writeln("Edit source/app.d to start your project."); + depend1_func(); + assert(exists("depend2.json")); + assert(exists("depend.json")); +} diff --git a/test/issue2012-dc-env/.no_build b/test/issue2012-dc-env/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue2012-dc-env/.no_build diff --git a/test/issue2012-dc-env/app.d b/test/issue2012-dc-env/app.d new file mode 100644 index 0000000..4b1f4d1 --- /dev/null +++ b/test/issue2012-dc-env/app.d @@ -0,0 +1,18 @@ +#!/usr/bin/env dub +/+ dub.sdl: + name "app" ++/ + +import std.format; + +void main(string[] args) +{ + version (LDC) + immutable expected = "ldc2"; + version (DigitalMars) + immutable expected = "dmd"; + version (GNU) + immutable expected = "gdc"; + + assert(expected == args[1], format!"Expected '%s' but got '%s'"(expected, args[1])); +} diff --git a/test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d b/test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d index b430cbc..45d8a32 100644 --- a/test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d +++ b/test/issue564-invalid-upgrade-dependency/a-1.0.0/source/a.d @@ -1,3 +1,3 @@ -void test() -{ -} \ No newline at end of file +void test() +{ +} diff --git a/test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d b/test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d index b430cbc..45d8a32 100644 --- a/test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d +++ b/test/issue564-invalid-upgrade-dependency/a-1.1.0/source/a.d @@ -1,3 +1,3 @@ -void test() -{ -} \ No newline at end of file +void test() +{ +} diff --git a/test/issue564-invalid-upgrade-dependency/main/source/app.d b/test/issue564-invalid-upgrade-dependency/main/source/app.d index c0b76f0..b248b89 100644 --- a/test/issue564-invalid-upgrade-dependency/main/source/app.d +++ b/test/issue564-invalid-upgrade-dependency/main/source/app.d @@ -1,6 +1,6 @@ -import a; - -void main() -{ - test(); -} +import a; + +void main() +{ + test(); +} diff --git a/test/issue895-local-configuration.sh b/test/issue895-local-configuration.sh index 9799288..8593c00 100755 --- a/test/issue895-local-configuration.sh +++ b/test/issue895-local-configuration.sh @@ -20,6 +20,8 @@ trap cleanup EXIT +unset DC + if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: $(dirname $CURR_DIR)/bin/foo"; then rm ../bin/foo die $LINENO 'DUB did not find the local configuration with an adjacent compiler.' diff --git a/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d b/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d new file mode 100644 index 0000000..08a45ad --- /dev/null +++ b/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d @@ -0,0 +1,76 @@ +/+ dub.sdl: + name "issue_2051_running_unittests_from_dub_single_file_packages_fails" + +/ + +import std.algorithm : any; +import std.conv : text; +import std.file : tempDir; +import std.stdio : File, writeln; +import std.string : lineSplitter; +import std.path : buildPath; +import std.process : environment, executeShell; + +auto executeCommand(string command) +{ + import std.exception : enforce; + + auto dub = executeShell(command); + writeln("--- dub output:"); + foreach(line; dub.output.lineSplitter) + writeln("\t", line); + writeln("--- end of dub output"); + + enforce(dub.status == 0, "couldn't build the project, see above"); + + return dub.output; +} + +/// check dub output to determine rebuild has not been triggered +auto checkUnittestsResult(string output) +{ + if (output.lineSplitter.any!(a=> a == "All unit tests have been run successfully.")) + { + writeln("\nOk. Unittest passed."); + return 0; + } + else + { + writeln("\nError. Unittests failed."); + return 1; + } +} + +int main() +{ + auto dub = environment.get("DUB"); + if (!dub.length) + dub = buildPath(".", "bin", "dub"); + + string filename; + // create test_project + { + filename = tempDir.buildPath("issue_2051.d"); + auto f = File(filename, "w"); + f.write( +`#!/usr/bin/env dub +/+ dub.sdl: + name "issue2051" ++/ + +version(unittest) {} +else void main() +{ +} + +unittest +{ + auto input = [1721]; + assert(input[0] == 1721); +} +` ); + } + + return text(dub, " test --single ", filename) + .executeCommand + .checkUnittestsResult; +} \ No newline at end of file diff --git a/test/removed-dub-obj.sh b/test/removed-dub-obj.sh new file mode 100755 index 0000000..3686c61 --- /dev/null +++ b/test/removed-dub-obj.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh +cd ${CURR_DIR}/removed-dub-obj +rm -rf .dub + +${DUB} build --compiler=${DC} + +[ -d ".dub/obj" ] && die $LINENO '.dub/obj was found' + +if [[ ${DC} == *"ldc"* ]]; then + [ -f .dub/build/library-*ldc*/obj/test.o* ] || die $LINENO '.dub/build/library-*ldc*/obj/test.o* was not found' +fi + +exit 0 \ No newline at end of file diff --git a/test/removed-dub-obj/.no_build b/test/removed-dub-obj/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_build diff --git a/test/removed-dub-obj/.no_run b/test/removed-dub-obj/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_run diff --git a/test/removed-dub-obj/.no_test b/test/removed-dub-obj/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/removed-dub-obj/.no_test diff --git a/test/removed-dub-obj/dub.sdl b/test/removed-dub-obj/dub.sdl new file mode 100644 index 0000000..86660c8 --- /dev/null +++ b/test/removed-dub-obj/dub.sdl @@ -0,0 +1,3 @@ +name "removed-dub-obj" + +targetType "staticLibrary" \ No newline at end of file diff --git a/test/removed-dub-obj/source/test.d b/test/removed-dub-obj/source/test.d new file mode 100644 index 0000000..c6e2276 --- /dev/null +++ b/test/removed-dub-obj/source/test.d @@ -0,0 +1,6 @@ +module test; + +unittest +{ + assert(true); +} \ No newline at end of file diff --git a/test/version-spec.sh b/test/version-spec.sh index 76b54b8..8d0677f 100755 --- a/test/version-spec.sh +++ b/test/version-spec.sh @@ -9,6 +9,13 @@ [[ $($DUB describe foo@1.0.0 | grep path | head -n 1) == *"/newfoo/"* ]] [[ $($DUB describe foo@0.1.0 | grep path | head -n 1) == *"/oldfoo/"* ]] +[[ $($DUB describe foo@'<1.0.0' | grep path | head -n 1) == *"/oldfoo/"* ]] +[[ $($DUB describe foo@'>0.1.0' | grep path | head -n 1) == *"/newfoo/"* ]] +[[ $($DUB describe foo@'>0.2.0' | grep path | head -n 1) == *"/newfoo/"* ]] +[[ $($DUB describe foo@'<=0.2.0' | grep path | head -n 1) == *"/oldfoo/"* ]] +[[ $($DUB describe foo@'*' | grep path | head -n 1) == *"/newfoo/"* ]] +[[ $($DUB describe foo@'>0.0.1 <2.0.0' | grep path | head -n 1) == *"/newfoo/"* ]] + [[ $($DUB test foo | head -n 1) == *"/newfoo/" ]] [[ $($DUB test foo@1.0.0 | head -n 1) == *"/newfoo/" ]] [[ $($DUB test foo@0.1.0 | head -n 1) == *"/oldfoo/" ]] @@ -29,6 +36,10 @@ [[ $($DUB run -n foo@1.0.0 | tail -n 1) == 'new-foo' ]] [[ $($DUB run -n foo@0.1.0 | tail -n 1) == 'old-foo' ]] +[[ $($DUB list foo | wc -l) == '4' ]] +[[ $($DUB list foo@0.1.0 | wc -l) == '3' ]] +[[ $($DUB list foo@'>0.1.0' | head -n 2 | tail -n 1) == *"/newfoo"* ]] + $DUB remove-local "$CURR_DIR/version-spec/newfoo" $DUB remove-local "$CURR_DIR/version-spec/oldfoo"