From a984d90ea284f2a235950b7341cd709d7c428567 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Mon, 16 Dec 2024 02:07:11 +0000 Subject: [PATCH] cargoTomlContents: ignore context of Cargo.toml file (#762) --- CHANGELOG.md | 3 +++ checks/default.nix | 9 +++++++++ lib/crateNameFromCargoToml.nix | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ee8a17..e9ff398a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed * `mkDummySrc` will deduplicate discovered and declared binary targets when dummifying sources +* `crateNameFromCargoToml` will ignore store contexts when parsing a Cargo.toml + file (avoiding errors like `the string ... is not allowed to refer to a store + path`). ### Meta * Dropped support for publishing releases to https://flakestry.dev/ diff --git a/checks/default.nix b/checks/default.nix index 608df859..90342f9e 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -274,6 +274,15 @@ in }; }; + customDummyWithMkDummySrcNoPname = myLib.buildDepsOnly { + dummySrc = myLib.mkDummySrc { + src = myLib.cleanCargoSource ./simple; + postInstall = '' + touch $out/blah.txt + ''; + }; + }; + # https://github.com/ipetkov/crane/pull/234 nonJsonCargoBuildLog = let diff --git a/lib/crateNameFromCargoToml.nix b/lib/crateNameFromCargoToml.nix index b58bd368..a78aadb0 100644 --- a/lib/crateNameFromCargoToml.nix +++ b/lib/crateNameFromCargoToml.nix @@ -25,7 +25,12 @@ let else throwMsg ); - toml = builtins.fromTOML cargoTomlContents; + # NB: if `src` is derived via `mkDummySrc` the Cargo.toml will contain store paths + # (e.g. build script stubs), which the fromTOML does not like since the context isn't + # threaded through (error is `the string ... is not allowed to refer to a store path`). + # We can work around this by discarding the context before parsing the TOML since we don't + # actually care about any dependency derivations, we just want to parse the name and version + toml = builtins.fromTOML (builtins.unsafeDiscardStringContext cargoTomlContents); debugPath = if args ? cargoTomlContents