mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-22 23:17:15 +03:00
crateNameFromCargoToml: warn when values can't be found (#237)
This commit is contained in:
parent
c6b5c57cfb
commit
6fb400ec63
@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
* A warning will now be emitted if a derivation's `pname` or `version`
|
||||
attributes are not set and the value cannot be loaded from the derivation's
|
||||
root `Cargo.toml`. To resolve it consider setting `pname = "...";` or `version
|
||||
= "...";` explicitly on the derivation.
|
||||
|
||||
## [0.11.2] - 2023-02-11
|
||||
|
||||
### Fixed
|
||||
|
@ -380,11 +380,13 @@ in
|
||||
workspace = myLib.buildPackage {
|
||||
src = myLib.cleanCargoSource ./workspace;
|
||||
pname = "workspace";
|
||||
version = "0.0.1";
|
||||
};
|
||||
|
||||
workspaceHack = myLib.buildPackage {
|
||||
src = myLib.cleanCargoSource ./workspace-hack;
|
||||
pname = "workspace-hack";
|
||||
version = "0.0.1";
|
||||
};
|
||||
|
||||
workspaceInheritance = myLib.buildPackage {
|
||||
@ -394,6 +396,8 @@ in
|
||||
|
||||
# https://github.com/ipetkov/crane/issues/209
|
||||
workspaceRootNotAtSourceRoot = myLib.buildPackage {
|
||||
pname = "workspaceRootNotAtSourceRoot";
|
||||
version = "0.0.1";
|
||||
src = myLib.cleanCargoSource ./workspace-not-at-root;
|
||||
postUnpack = ''
|
||||
cd $sourceRoot/workspace
|
||||
@ -411,6 +415,7 @@ in
|
||||
workspaceGit = myLib.buildPackage {
|
||||
src = myLib.cleanCargoSource ./workspace-git;
|
||||
pname = "workspace-git";
|
||||
version = "0.0.1";
|
||||
};
|
||||
})
|
||||
)
|
||||
|
@ -605,8 +605,10 @@ raised during evaluation.
|
||||
Extract a crate's name and version from its Cargo.toml file.
|
||||
|
||||
The resulting `pname` attribute will be populated with the value of the
|
||||
Cargo.toml's `package.name` attribute, if present. Otherwise a placeholder value
|
||||
will be used.
|
||||
Cargo.toml's (top-level) `package.name` attribute, if present and if the
|
||||
value is a string. Otherwise `workspace.package.name` will be used if it is
|
||||
present _and_ the value is a string. Otherwise a placeholder version field will
|
||||
be used.
|
||||
|
||||
The resulting `version` attribute will be populated with the value of the
|
||||
Cargo.toml's (top-level) `package.version` attribute, if present and if the
|
||||
|
@ -20,9 +20,31 @@ let
|
||||
);
|
||||
|
||||
toml = builtins.fromTOML cargoTomlContents;
|
||||
|
||||
debugPath =
|
||||
if args ? cargoTomlContents
|
||||
then "provided Cargo.toml contents"
|
||||
else cargoToml;
|
||||
|
||||
traceMsg = tomlName: drvName: placeholder: lib.trivial.warn
|
||||
"crane cannot find ${tomlName} attribute in ${debugPath}, consider setting `${drvName} = \"...\";` explicitly"
|
||||
placeholder;
|
||||
in
|
||||
{
|
||||
pname = toml.package.name or "cargo-package";
|
||||
# Now that cargo supports workspace inheritance we attempt to select a name
|
||||
# with the following priorities:
|
||||
# - choose `[package.name]` if the value is present and a string
|
||||
# (i.e. it isn't `[package.name] = { workspace = "true" }`)
|
||||
# - choose `[workspace.package.name]` if it is present (and a string for good measure)
|
||||
# - otherwise, fall back to a placeholder
|
||||
pname =
|
||||
let
|
||||
packageName = toml.package.name or null;
|
||||
workspacePackageName = toml.workspace.package.name or null;
|
||||
in
|
||||
if lib.isString packageName then packageName
|
||||
else if lib.isString workspacePackageName then workspacePackageName
|
||||
else traceMsg "name" "pname" "cargo-package";
|
||||
|
||||
# Now that cargo supports workspace inheritance we attempt to select a version
|
||||
# string with the following priorities:
|
||||
@ -37,5 +59,5 @@ in
|
||||
in
|
||||
if lib.isString packageVersion then packageVersion
|
||||
else if lib.isString workspacePackageVersion then workspacePackageVersion
|
||||
else "0.0.1";
|
||||
else traceMsg "version" "version" "0.0.1";
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
, crateNameFromCargoToml
|
||||
, inheritCargoArtifactsHook
|
||||
, installCargoArtifactsHook
|
||||
, lib
|
||||
, stdenv
|
||||
, vendorCargoDeps
|
||||
, zstd
|
||||
|
Loading…
Reference in New Issue
Block a user