Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt dub.recipe.json to PackageName API #2814

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions source/dub/recipe/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void parseJson(ref PackageRecipe recipe, Json json, in PackageName parent = Pack
case "buildTypes":
foreach (string name, settings; value) {
BuildSettingsTemplate bs;
bs.parseJson(settings, null);
bs.parseJson(settings, PackageName.init);
recipe.buildTypes[name] = bs;
}
break;
Expand All @@ -57,8 +57,8 @@ void parseJson(ref PackageRecipe recipe, Json json, in PackageName parent = Pack

enforce(recipe.name.length > 0, "The package \"name\" field is missing or empty.");

auto fullname = parent.length
? PackageName(parent ~ ":" ~ recipe.name)
const fullname = parent.toString().length
? PackageName(parent.toString() ~ ":" ~ recipe.name)
: PackageName(recipe.name);

// parse build settings
Expand All @@ -67,7 +67,7 @@ void parseJson(ref PackageRecipe recipe, Json json, in PackageName parent = Pack
if (auto pv = "configurations" in json) {
foreach (settings; *pv) {
ConfigurationInfo ci;
ci.parseJson(settings, recipe.name);
ci.parseJson(settings, fullname);
recipe.configurations ~= ci;
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private void parseSubPackages(ref PackageRecipe recipe, in PackageName parent, J
}
}

private void parseJson(ref ConfigurationInfo config, Json json, string package_name)
private void parseJson(ref ConfigurationInfo config, Json json, in PackageName pname)
{
foreach (string name, value; json) {
switch (name) {
Expand All @@ -151,7 +151,7 @@ private void parseJson(ref ConfigurationInfo config, Json json, string package_n
}

enforce(!config.name.empty, "Configuration is missing a name.");
config.buildSettings.parseJson(json, package_name);
config.buildSettings.parseJson(json, pname);
}

private Json toJson(const scope ref ConfigurationInfo config)
Expand All @@ -162,7 +162,7 @@ private Json toJson(const scope ref ConfigurationInfo config)
return ret;
}

private void parseJson(ref BuildSettingsTemplate bs, Json json, string package_name)
private void parseJson(ref BuildSettingsTemplate bs, Json json, in PackageName pname)
{
foreach(string name, value; json)
{
Expand All @@ -175,13 +175,15 @@ private void parseJson(ref BuildSettingsTemplate bs, Json json, string package_n
case "dependencies":
foreach (string pkg, verspec; value) {
if (pkg.startsWith(":")) {
enforce(!package_name.canFind(':'), format("Short-hand packages syntax not allowed within sub packages: %s -> %s", package_name, pkg));
pkg = package_name ~ pkg;
enforce(!pname.sub.length,
"Short-hand packages syntax not allowed within " ~
"sub packages: %s -> %s".format(pname, pkg));
pkg = pname.toString() ~ pkg;
}
enforce(pkg !in bs.dependencies, "The dependency '"~pkg~"' is specified more than once." );
bs.dependencies[pkg] = Dependency.fromJson(verspec);
if (verspec.type == Json.Type.object)
bs.dependencies[pkg].settings.parseJson(verspec, package_name);
bs.dependencies[pkg].settings.parseJson(verspec, pname);
}
break;
case "systemDependencies":
Expand Down
Loading