crane/lib/internalCrateNameForCleanSource.nix
2024-08-05 17:42:26 -07:00

26 lines
556 B
Nix

{ internalCrateNameFromCargoToml
}:
src:
let
origSrc =
if src ? _isLibCleanSourceWith
then src.origSrc
else src;
cargoTomlContents =
let
emptyToml = { };
cargoToml = origSrc + "/Cargo.toml";
cargoTomlContents = builtins.readFile cargoToml;
toml = builtins.tryEval (builtins.fromTOML cargoTomlContents);
in
if builtins.pathExists cargoToml
then
if toml.success then toml.value else emptyToml
else
emptyToml;
in
(internalCrateNameFromCargoToml cargoTomlContents).pname or "source"