From 8b4f7a4dab2120cf41e7957a28a853f45016bd9d Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 3 Sep 2023 17:33:25 -0700 Subject: [PATCH] various: switch to using runCommand to improve caching (#384) For example, commands which extract a tarball should be cached (i.e should use `runCommand` not `runCommandLocal`) because it allows builds to download the unpacked result instead of having to write both to the store --- CHANGELOG.md | 2 ++ checks/cargoAudit.nix | 4 ++-- lib/downloadCargoPackage.nix | 4 ++-- lib/downloadCargoPackageFromGit.nix | 4 ++-- lib/mkDummySrc.nix | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e74f10a..b0de00d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * `cargoDoc` will now install generated documentation in `$out/share/doc` * Fixed a bug when testing proc macro crates with `cargoNextest` on macOS. ([#376](https://github.com/ipetkov/crane/pull/376)) +* Replaced various internal usages of `runCommandLocal` with `runCommand` for + more optimal behavior when downloading cached artifacts ## [0.13.1] - 2023-08-22 diff --git a/checks/cargoAudit.nix b/checks/cargoAudit.nix index 4be1b568..757875e7 100644 --- a/checks/cargoAudit.nix +++ b/checks/cargoAudit.nix @@ -1,7 +1,7 @@ { cargoAudit , fetchFromGitHub , linkFarmFromDrvs -, runCommandLocal +, runCommand }: let @@ -17,7 +17,7 @@ let simpleWithAuditToml = (auditWith "simple-with-audit-toml" ./simple-with-audit-toml); - containsAuditTomlInSrc = runCommandLocal "containsAuditTomlInSrc" { } '' + containsAuditTomlInSrc = runCommand "containsAuditTomlInSrc" { } '' if [[ -f ${simpleWithAuditToml.src}/.cargo/audit.toml ]]; then touch $out else diff --git a/lib/downloadCargoPackage.nix b/lib/downloadCargoPackage.nix index a90c4ed9..137f845c 100644 --- a/lib/downloadCargoPackage.nix +++ b/lib/downloadCargoPackage.nix @@ -1,6 +1,6 @@ { fetchurl , urlForCargoPackage -, runCommandLocal +, runCommand }: { name @@ -16,7 +16,7 @@ let sha256 = checksum; }); in -runCommandLocal "cargo-package-${name}-${version}" { } '' +runCommand "cargo-package-${name}-${version}" { } '' mkdir -p $out tar -xzf ${tarball} -C $out --strip-components=1 echo '{"files":{}, "package":"${checksum}"}' > $out/.cargo-checksum.json diff --git a/lib/downloadCargoPackageFromGit.nix b/lib/downloadCargoPackageFromGit.nix index fa7e4837..5d9f5b6e 100644 --- a/lib/downloadCargoPackageFromGit.nix +++ b/lib/downloadCargoPackageFromGit.nix @@ -2,7 +2,7 @@ , craneUtils , jq , lib -, runCommandLocal +, runCommand }: { git @@ -26,7 +26,7 @@ let ]; }; in -runCommandLocal "cargo-git" deps '' +runCommand "cargo-git" deps '' mkdir -p $out existing_crates=() while read -r cargoToml; do diff --git a/lib/mkDummySrc.nix b/lib/mkDummySrc.nix index 4d179a3b..ccdccffe 100644 --- a/lib/mkDummySrc.nix +++ b/lib/mkDummySrc.nix @@ -1,7 +1,7 @@ { cleanCargoToml , findCargoFiles , lib -, runCommandLocal +, runCommand , writeText , writeTOML }: @@ -236,7 +236,7 @@ let then "dummy-src" else last nameWithoutHash; in -runCommandLocal sourceName { } '' +runCommand sourceName { } '' mkdir -p $out cp --recursive --no-preserve=mode,ownership ${cleanSrc}/. -t $out ${copyCargoLock}