mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-26 09:08:57 +03:00
Update crateNameFromCargoToml with better fallback error messages
* If a derivation is created without a name *and* we cannot infer a name from a Cargo.toml file, we'll throw a descriptive error message which hints towards the remediation * Otherwise nix can throw a pretty obtuse "derivation has no name" error with no error trace
This commit is contained in:
parent
0aadea3b08
commit
2a14c2d53b
@ -2,15 +2,27 @@
|
||||
|
||||
{ src ? null
|
||||
, cargoToml ? src + /Cargo.toml
|
||||
, cargoTomlContents ? builtins.readFile cargoToml
|
||||
, cargoTomlContents ? null
|
||||
, ...
|
||||
}:
|
||||
|
||||
let
|
||||
toml = fromTOML cargoTomlContents;
|
||||
p = toml.package;
|
||||
in
|
||||
{
|
||||
inherit (p) version;
|
||||
pname = p.name;
|
||||
}
|
||||
if cargoTomlContents == null && (src == null || !builtins.pathExists cargoToml)
|
||||
then
|
||||
throw ''
|
||||
unable to infer crate name and version. Please make sure the src directory
|
||||
contains a valid Cargo.toml file, or consider setting a derivation name explicitly
|
||||
''
|
||||
else
|
||||
let
|
||||
cargoTomlRealContents =
|
||||
if cargoTomlContents != null
|
||||
then cargoTomlContents
|
||||
else builtins.readFile cargoToml;
|
||||
|
||||
toml = fromTOML cargoTomlRealContents;
|
||||
p = toml.package;
|
||||
in
|
||||
{
|
||||
inherit (p) version;
|
||||
pname = p.name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user