mirror of
https://github.com/Mic92/nix-update.git
synced 2024-09-19 06:17:14 +03:00
fix updating importCargoLock
when lockFile
is in the nix store
This commit is contained in:
parent
f7eba589cc
commit
927f47a36e
@ -1,7 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
from dataclasses import InitVar, dataclass, field
|
||||
from textwrap import dedent, indent
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
from urllib.parse import ParseResult, urlparse
|
||||
|
||||
from .errors import UpdateError
|
||||
@ -33,7 +34,7 @@ class Package:
|
||||
vendor_hash: Optional[str]
|
||||
vendor_sha256: Optional[str]
|
||||
cargo_deps: Optional[str]
|
||||
cargo_lock: Optional[str]
|
||||
cargo_lock: Optional[str | Literal[False]]
|
||||
npm_deps: Optional[str]
|
||||
tests: List[str]
|
||||
has_update_script: bool
|
||||
@ -112,7 +113,13 @@ in {{
|
||||
cargo_deps = pkg.cargoDeps.outputHash or null;
|
||||
cargo_lock =
|
||||
if pkg ? cargoDeps.lockFile then
|
||||
(sanitizePosition {{ file = pkg.cargoDeps.lockFile; }}).file
|
||||
let
|
||||
inherit (pkg.cargoDeps) lockFile;
|
||||
res = builtins.tryEval (sanitizePosition {{
|
||||
file = lockFile;
|
||||
}});
|
||||
in
|
||||
if res.success then res.value.file else false
|
||||
else
|
||||
null;
|
||||
npm_deps = pkg.npmDeps.outputHash or null;
|
||||
@ -144,5 +151,9 @@ def eval_attr(opts: Options) -> Package:
|
||||
raise UpdateError(
|
||||
f"Nix's builtins.parseDrvName could not parse the version from {package.name}"
|
||||
)
|
||||
if package.cargo_lock and not os.path.realpath(package.cargo_lock).startswith(
|
||||
opts.import_path
|
||||
):
|
||||
package.cargo_lock = False
|
||||
|
||||
return package
|
||||
|
@ -9,7 +9,7 @@ import tomllib
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, Tuple
|
||||
from typing import Dict, Literal, Optional, Tuple
|
||||
|
||||
from .errors import UpdateError
|
||||
from .eval import Package, eval_attr
|
||||
@ -152,7 +152,7 @@ def update_cargo_deps_hash(opts: Options, filename: str, current_hash: str) -> N
|
||||
replace_hash(filename, current_hash, target_hash)
|
||||
|
||||
|
||||
def update_cargo_lock(opts: Options, filename: str, dst: str) -> None:
|
||||
def update_cargo_lock(opts: Options, filename: str, dst: str | Literal[False]) -> None:
|
||||
res = run(
|
||||
[
|
||||
"nix",
|
||||
@ -160,17 +160,30 @@ def update_cargo_lock(opts: Options, filename: str, dst: str) -> None:
|
||||
"--impure",
|
||||
"--print-out-paths",
|
||||
"--expr",
|
||||
f'{get_package(opts)}.overrideAttrs (_: {{ prePatch = "cp -r . $out; exit"; outputs = [ "out" ]; }})',
|
||||
f"""
|
||||
{get_package(opts)}.overrideAttrs (_: {{
|
||||
cargoDeps = null;
|
||||
postUnpack = ''
|
||||
cp -r "$sourceRoot/Cargo.lock" $out
|
||||
exit
|
||||
'';
|
||||
outputs = [ "out" ];
|
||||
}})
|
||||
""",
|
||||
]
|
||||
+ opts.extra_flags,
|
||||
)
|
||||
src = Path(res.stdout.strip()) / "Cargo.lock"
|
||||
src = Path(res.stdout.strip())
|
||||
if not src.is_file():
|
||||
return
|
||||
|
||||
shutil.copyfile(src, dst)
|
||||
with open(src, "rb") as f:
|
||||
if dst:
|
||||
with open(dst, "wb") as fdst:
|
||||
shutil.copyfileobj(f, fdst)
|
||||
f.seek(0)
|
||||
|
||||
hashes = {}
|
||||
with open(dst, "rb") as f:
|
||||
lock = tomllib.load(f)
|
||||
regex = re.compile(r"git\+([^?]+)(\?(rev|tag|branch)=.*)?#(.*)")
|
||||
git_deps = {}
|
||||
@ -326,7 +339,7 @@ def update(opts: Options) -> Package:
|
||||
if package.cargo_deps:
|
||||
update_cargo_deps_hash(opts, package.filename, package.cargo_deps)
|
||||
|
||||
if package.cargo_lock:
|
||||
if package.cargo_lock is not None:
|
||||
update_cargo_lock(opts, package.filename, package.cargo_lock)
|
||||
|
||||
if package.npm_deps:
|
||||
|
@ -39,8 +39,6 @@ def test_main(helpers: conftest.Helpers) -> None:
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
print(diff)
|
||||
assert "Cargo.lock" in diff
|
||||
assert '+source = "git+' in diff
|
||||
assert (
|
||||
"https://github.com/charliermarsh/ruff/compare/v0.0.254...v0.0.255" in diff
|
||||
)
|
||||
|
3263
tests/testpkgs/cargo-lock-update/Cargo.lock
generated
3263
tests/testpkgs/cargo-lock-update/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@ rustPlatform.buildRustPackage rec {
|
||||
};
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
lockFile = src + "/Cargo.lock";
|
||||
outputHashes = {
|
||||
"libcst-0.1.0" = "sha256-jG9jYJP4reACkFLrQBWOYH6nbKniNyFVItD0cTZ+nW0=";
|
||||
"libcst_derive-0.1.0" = "sha256-jG9jYJP4reACkFLrQBWOYH6nbKniNyFVItD0cTZ+nW0=";
|
||||
|
Loading…
Reference in New Issue
Block a user