Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into selections-from-par…
Browse files Browse the repository at this point in the history
…ent-dir

Conflicts:
	source/dub/project.d
  • Loading branch information
kinke committed Jun 12, 2024
2 parents 61e6862 + cb3c523 commit b5a6b8d
Show file tree
Hide file tree
Showing 33 changed files with 995 additions and 451 deletions.
34 changes: 31 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
*.o
*.obj
*.pdb
*~

.dub
.directory
dub.selections.json
# Unknown hidden files
.*
!.gitignore
!/.github
!/.editorconfig
!/.codecov.yml

# Unknown script files
/*.sh
/*.bat
/*.cmd
!/build.cmd
!/build.sh

# dub generation files
dub.selections.json
docs.json
__dummy.html

Expand All @@ -20,7 +33,22 @@ __dummy.html

# Ignore files or directories created by the test suite.
*.exe
*.lib
*.log
/test/*/*
/test/*.*
!/test/*.d
!/test/*.d.min_frontend
!/test/*.sh
!/test/*.sh.min_frontend
!/test/*/.no_*
!/test/*/.min_frontend
!/test/*/.fail_build
!/test/*/dub.json
!/test/*/dub.sdl
!/test/*/dub.settings.json
!/test/*/source/
!/test/*/src/

# Ignore coverage files
cov/
Expand Down
10 changes: 5 additions & 5 deletions build.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Standalone build script for DUB
This script can be called from anywhere, as it deduces absolute paths
based on the script's placement in the repository.
based on the script's location in the source tree.
Invoking it while making use of all the options would like like this:
DMD=ldmd2 DFLAGS="-O -inline" ./build.d my-dub-version
Using an environment variable for the version is also supported:
DMD=dmd DFLAGS="-w -g" GITVER="1.2.3" ./build.d
Invoking it while making use of all the options would look like this:
DMD=ldmd2 GITVER="1.2.3" ./build.d -O -inline
The GITVER environment variable determines the version of
the repository to build against.
Copyright: D Language Foundation
Authors: Mathias 'Geod24' Lang
Expand Down
45 changes: 33 additions & 12 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,11 @@ int runDubCommandLine(string[] args)
import std.uni : toUpper;
foreach (CommandGroup key; handler.commandGroups)
{
foreach (Command command; key.commands)
{
if (levenshteinDistance(command_name, command.name) < 4) {
auto similarCommands = key.commands.filter!(cmd => levenshteinDistance(command_name, cmd.name) < 4).array();
if (similarCommands) {
sort!((a, b) => levenshteinDistance(command_name, a.name) < levenshteinDistance(
command_name, b.name))(similarCommands);
foreach (command; similarCommands) {
logInfo("Did you mean '%s'?", command.name);
}
}
Expand Down Expand Up @@ -563,14 +565,9 @@ struct CommonOptions {
string root_path, recipeFile;
enum Color { automatic, on, off }
Color colorMode = Color.automatic;
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none;
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.default_;
PlacementLocation placementLocation = PlacementLocation.user;

deprecated("Use `Color` instead, the previous naming was a limitation of error message formatting")
alias color = Color;
deprecated("Use `colorMode` instead")
alias color_mode = colorMode;

private void parseColor(string option, string value) @safe
{
// `automatic`, `on`, `off` are there for backwards compatibility
Expand All @@ -589,6 +586,30 @@ struct CommonOptions {
~ "', supported values: --color[=auto], --color=always, --color=never");
}

private void parseSkipRegistry(string option, string value) @safe
{
// We only want to support `none`, `standard`, `configured`, and `all`.
// We use a separate function to prevent getopt from parsing SkipPackageSuppliers.default_.
assert(option == "skip-registry",
"parseSkipRegistry called with unknown option '" ~ option ~ "'");
switch (value) with (SkipPackageSuppliers) {
case "none":
skipRegistry = none;
break;
case "standard":
skipRegistry = standard;
break;
case "configured":
skipRegistry = configured;
break;
case "all":
skipRegistry = all;
break;
default:
throw new GetOptException("skip-registry only accepts 'none', 'standard', 'configured', and 'all', not '" ~ value ~ "'");
}
}

/// Parses all common options and stores the result in the struct instance.
void prepare(CommandArgs args)
{
Expand All @@ -600,7 +621,7 @@ struct CommonOptions {
" DUB: URL to DUB registry (default)",
" Maven: URL to Maven repository + group id containing dub packages as artifacts. E.g. mvn+http://localhost:8040/maven/libs-release/dubpackages",
]);
args.getopt("skip-registry", &skipRegistry, [
args.getopt("skip-registry", &skipRegistry, &parseSkipRegistry, [
"Sets a mode for skipping the search on certain package registry types:",
" none: Search all configured or default registries (default)",
" standard: Don't search the main registry (e.g. "~defaultRegistryURLs[0]~")",
Expand Down Expand Up @@ -852,10 +873,10 @@ class Command {
// should simply retry over all registries instead of using a special
// FallbackPackageSupplier.
auto urls = url.splitter(' ');
PackageSupplier ps = getRegistryPackageSupplier(urls.front);
PackageSupplier ps = _getRegistryPackageSupplier(urls.front);
urls.popFront;
if (!urls.empty)
ps = new FallbackPackageSupplier(ps ~ urls.map!getRegistryPackageSupplier.array);
ps = new FallbackPackageSupplier(ps ~ urls.map!_getRegistryPackageSupplier.array);
return ps;
})
.array;
Expand Down
55 changes: 5 additions & 50 deletions source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,46 +128,14 @@ config /etc/dmd.conf
arch_override
);

/// Replace architecture string in `bp.architecture`
void replaceArch(const string from, const string to)
{
const idx = bp.architecture.countUntil(from);
if (idx != -1)
bp.architecture[idx] = to;
}

// DMD 2.099 changed the default for -m32 from OMF to MsCOFF
const m32IsCoff = bp.frontendVersion >= 2_099;

switch (arch_override) {
default: throw new UnsupportedArchitectureException(arch_override);
case "": break;
case "x86": arch_flags = ["-m32"]; break;
// DMD 2.099 made MsCOFF the default, and DMD v2.109 removed OMF
// support. Default everything to MsCOFF, people wanting to use OMF
// should use an older DMD / dub.
case "x86", "x86_omf", "x86_mscoff": arch_flags = ["-m32"]; break;
case "x86_64": arch_flags = ["-m64"]; break;

case "x86_omf":
if (m32IsCoff)
{
arch_flags = [ "-m32omf" ];
replaceArch("x86_mscoff", "x86_omf"); // Probe used the wrong default
}
else // -m32 is OMF
{
arch_flags = [ "-m32" ];
}
break;

case "x86_mscoff":
if (m32IsCoff)
{
arch_flags = [ "-m32" ];
}
else // -m32 is OMF
{
arch_flags = [ "-m32mscoff" ];
replaceArch("x86_omf", "x86_mscoff"); // Probe used the wrong default
}
break;
}
settings.addDFlags(arch_flags);

Expand All @@ -181,33 +149,22 @@ config /etc/dmd.conf
auto bp = compiler.determinePlatform(settings, "dmd", "x86");
assert(bp.isWindows());
assert(bp.architecture.canFind("x86"));
const defaultOMF = (bp.frontendVersion < 2_099);
assert(bp.architecture.canFind("x86_omf") == defaultOMF);
assert(bp.architecture.canFind("x86_mscoff") != defaultOMF);
settings = BuildSettings.init;
bp = compiler.determinePlatform(settings, "dmd", "x86_omf");
assert(bp.isWindows());
assert(bp.architecture.canFind("x86"));
assert(bp.architecture.canFind("x86_omf"));
assert(!bp.architecture.canFind("x86_mscoff"));
settings = BuildSettings.init;
bp = compiler.determinePlatform(settings, "dmd", "x86_mscoff");
assert(bp.isWindows());
assert(bp.architecture.canFind("x86"));
assert(!bp.architecture.canFind("x86_omf"));
assert(bp.architecture.canFind("x86_mscoff"));
settings = BuildSettings.init;
bp = compiler.determinePlatform(settings, "dmd", "x86_64");
assert(bp.isWindows());
assert(bp.architecture.canFind("x86_64"));
assert(!bp.architecture.canFind("x86"));
assert(!bp.architecture.canFind("x86_omf"));
assert(!bp.architecture.canFind("x86_mscoff"));
settings = BuildSettings.init;
bp = compiler.determinePlatform(settings, "dmd", "");
if (!isWow64.isNull && !isWow64.get) assert(bp.architecture.canFind("x86"));
if (!isWow64.isNull && !isWow64.get) assert(bp.architecture.canFind("x86_mscoff"));
if (!isWow64.isNull && !isWow64.get) assert(!bp.architecture.canFind("x86_omf"));
if (!isWow64.isNull && isWow64.get) assert(bp.architecture.canFind("x86_64"));
}

Expand All @@ -218,11 +175,9 @@ config /etc/dmd.conf
auto compiler = new DMDCompiler;
auto bp = compiler.determinePlatform(settings, "ldmd2", "x86");
assert(bp.architecture.canFind("x86"), bp.architecture.to!string);
assert(!bp.architecture.canFind("x86_omf"), bp.architecture.to!string);
bp = compiler.determinePlatform(settings, "ldmd2", "");
version (X86) assert(bp.architecture.canFind("x86"), bp.architecture.to!string);
version (X86_64) assert(bp.architecture.canFind("x86_64"), bp.architecture.to!string);
assert(!bp.architecture.canFind("x86_omf"), bp.architecture.to!string);
}

void prepareBuildSettings(ref BuildSettings settings, const scope ref BuildPlatform platform,
Expand Down Expand Up @@ -433,7 +388,7 @@ config /etc/dmd.conf
static bool isLinkerDFlag(string arg)
{
switch (arg) {
case "-g", "-gc", "-m32", "-m64", "-shared", "-lib", "-m32omf", "-m32mscoff", "-betterC":
case "-g", "-gc", "-m32", "-m64", "-shared", "-lib", "-betterC":
return true;
default:
return arg.startsWith("-L")
Expand Down
30 changes: 29 additions & 1 deletion source/dub/data/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum SkipPackageSuppliers {
standard, /// Does not use the default package suppliers (`defaultPackageSuppliers`).
configured, /// Does not use default suppliers or suppliers configured in DUB's configuration file
all, /// Uses only manually specified package suppliers.
default_, /// The value wasn't specified. It is provided in order to know when it is safe to ignore it
}

/**
Expand All @@ -39,7 +40,22 @@ package(dub) struct Settings {
@Optional string[] registryUrls;
@Optional NativePath[] customCachePaths;

SetInfo!(SkipPackageSuppliers) skipRegistry;
private struct SkipRegistry {
SkipPackageSuppliers skipRegistry;
static SkipRegistry fromString (string value) {
import std.conv : to;
auto result = value.to!SkipPackageSuppliers;
if (result == SkipPackageSuppliers.default_) {
throw new Exception(
"skipRegistry value `default_` is only meant for interal use."
~ " Instead, use one of `none`, `standard`, `configured`, or `all`."
);
}
return SkipRegistry(result);
}
alias skipRegistry this;
}
SetInfo!(SkipRegistry) skipRegistry;
SetInfo!(string) defaultCompiler;
SetInfo!(string) defaultArchitecture;
SetInfo!(bool) defaultLowMemory;
Expand Down Expand Up @@ -171,3 +187,15 @@ unittest {
auto m3 = Settings.init.merge(c1);
assert(m3 == c1);
}

unittest {
// Test that SkipPackageRegistry.default_ is not allowed

import dub.internal.configy.Read;
import std.exception : assertThrown;

const str1 = `{
"skipRegistry": "all"
`;
assertThrown!Exception(parseConfigString!Settings(str1, "/dev/null"));
}
33 changes: 28 additions & 5 deletions source/dub/dependency.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ struct PackageDependency {
this.spec = s;
}

int opCmp(in typeof(this) other) @safe const {
return name == other.name
? spec.opCmp(other.spec)
: name.opCmp(other.name);
}

/// Name of the referenced package.
PackageName name;

Expand Down Expand Up @@ -723,7 +729,10 @@ unittest {
unittest {
assert(VersionRange.fromString("~>1.0.4").toString() == "~>1.0.4");
assert(VersionRange.fromString("~>1.4").toString() == "~>1.4");
assert(VersionRange.fromString("~>2").toString() == "~>2");
// https://github.com/dlang/dub/issues/2830
assert(VersionRange.fromString("~>2").toString() == "~>2.0");
assert(VersionRange.fromString("~>5.0").toString() == "~>5.0");

assert(VersionRange.fromString("~>1.0.4+1.2.3").toString() == "~>1.0.4");
assert(VersionRange.fromString("^0.1.2").toString() == "^0.1.2");
assert(VersionRange.fromString("^1.2.3").toString() == "^1.2.3");
Expand Down Expand Up @@ -1110,6 +1119,7 @@ public struct VersionRange
string r;

if (this == Invalid) return "no";
if (this.matchesAny()) return "*";
if (this.isExactVersion() && m_inclusiveA && m_inclusiveB) {
// Special "==" case
if (m_versA == Version.masterBranch) return "~master";
Expand All @@ -1125,7 +1135,10 @@ public struct VersionRange
auto parts = va.splitter('.').array;
assert(parts.length == 3, "Version string with a digit group count != 3: "~va);

foreach (i; 0 .. 3) {
// Start at 1 because the notation `~>1` and `^1` are equivalent
// to `~>1.0` and `^1.0`, and the latter are better understood
// and recognized by users. See for example issue 2830.
foreach (i; 1 .. 3) {
auto vp = parts[0 .. i+1].join(".");
auto ve = Version(expandVersion(vp));
auto veb = Version(bumpVersion(vp) ~ "-0");
Expand All @@ -1136,9 +1149,12 @@ public struct VersionRange
}
}

if (m_versA != Version.minRelease) r = (m_inclusiveA ? ">=" : ">") ~ m_versA.toString();
if (m_versB != Version.maxRelease) r ~= (r.length==0 ? "" : " ") ~ (m_inclusiveB ? "<=" : "<") ~ m_versB.toString();
if (this.matchesAny()) r = ">=0.0.0";
if (m_versA != Version.minRelease || !m_inclusiveA)
r = (m_inclusiveA ? ">=" : ">") ~ m_versA.toString();
if (m_versB != Version.maxRelease || !m_inclusiveB)
r ~= (r.length == 0 ? "" : " ") ~ (m_inclusiveB ? "<=" : "<") ~
m_versB.toString();

return r;
}

Expand Down Expand Up @@ -1235,6 +1251,13 @@ unittest {
assert(Version("1.0.0+foo").matches(Version("1.0.0+foo"), VersionMatchMode.strict));
}

// Erased version specification for dependency, converted to "" instead of ">0.0.0"
// https://github.com/dlang/dub/issues/2901
unittest
{
assert(VersionRange.fromString(">0.0.0").toString() == ">0.0.0");
}

/// Determines whether the given string is a Git hash.
bool isGitHash(string hash) @nogc nothrow pure @safe
{
Expand Down
Loading

0 comments on commit b5a6b8d

Please sign in to comment.