fix(rust-cargo-lock): handle workspace = true for license, description and homepage package attributes (#787)

This commit is contained in:
Yusuf Bera Ertan 2023-11-08 17:11:56 +03:00 committed by GitHub
parent 7cb0fded82
commit f1a9f36bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,10 +31,14 @@
value = projectTree.files."Cargo.toml".tomlContent;
};
workspacePackage = rootToml.value.workspace.package or null;
getVersion = package:
if package.version.workspace or false
then workspacePackage.version or (l.warn "no workspace version found in root Cargo.toml for ${package.name}, defaulting to unknown" "unknown")
else package.version or (l.warn "no version found in Cargo.toml for ${package.name}, defaulting to unknown" "unknown");
# get a package attribute, handles `attr.workspace = true`
# where the attribute is instead defined in workspace metadata
getPackageAttribute = package: attr:
if package.${attr}.workspace or false
then workspacePackage.${attr} or (l.warn "no workspace ${attr} found in root Cargo.toml for ${package.name}" null)
else package.${attr} or (l.warn "no ${attr} found in Cargo.toml for ${package.name}" null);
getVersion = package: getPackageAttribute package "version";
getLicense = package: getPackageAttribute package "license";
# find all the workspace members if we are in a workspace
# this is used to figure out what packages we can build
@ -310,13 +314,22 @@
(
package: let
pkg = package.value.package;
_licenseRaw = getLicense pkg;
licenseRaw =
if _licenseRaw == null
then ""
else _licenseRaw;
in {
${pkg.name}.${getVersion pkg} =
{license = parseSpdxId (pkg.license or "");}
{license = parseSpdxId licenseRaw;}
// (
l.filterAttrs
(n: v: l.any (on: n == on) ["description" "homepage"])
pkg
l.mapAttrs
(name: _: getPackageAttribute pkg name)
(
l.filterAttrs
(n: v: l.any (on: n == on) ["description" "homepage"])
pkg
)
);
}
)