Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make updating cargo.lock more robust #268

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import sys
import tempfile
import textwrap
import tomllib
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
Expand Down Expand Up @@ -258,15 +259,36 @@ def disable_copystat():
finally:
shutil.copystat = _orig

getSrcAndCargo = textwrap.dedent(f"""
{get_package(opts)}.overrideAttrs (old: {{
cargoDeps = null;
cargoVendorDir = ".";
postUnpack = ''
cp -pr --reflink=auto -- $sourceRoot $out
mkdir -p "$out/nix-support"
command -v cargo > $out/nix-support/cargo-bin || {{
echo "no cargo executable found in native build inputs" >&2
exit 1
}}
exit
'';
outputs = [ "out" ];
separateDebugInfo = false;
}})
""")

res = run(
[
"nix",
"--extra-experimental-features",
"flakes nix-command",
"build",
"-L",
"--no-link",
"--impure",
"--print-out-paths",
"--expr",
f"{get_package(opts)}.src",
getSrcAndCargo,
]
+ opts.extra_flags,
)
Expand All @@ -276,12 +298,11 @@ def disable_copystat():
with disable_copystat():
shutil.copytree(src, tempdir, dirs_exist_ok=True, copy_function=shutil.copy)

cargo_bin = (src / "nix-support" / "cargo-bin").read_text().rstrip("\n")

run(
[
"nix",
"run",
"nixpkgs#cargo",
"--",
cargo_bin,
"generate-lockfile",
"--manifest-path",
f"{opts.lockfile_metadata_path}/Cargo.toml",
Expand Down
6 changes: 5 additions & 1 deletion tests/testpkgs/cargo-lock-generate/simple/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
,
}:

python3Packages.buildPythonPackage rec {
Expand All @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec {
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
,
}:

python3Packages.buildPythonPackage rec {
Expand All @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec {
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
}