mirror of
https://gitlab.com/khumba/nvd.git
synced 2024-11-23 13:21:46 +01:00
Use nix-store to query direct deps of command line arguments (closes #4).
This commit is contained in:
parent
7cdaa6d818
commit
2c2fa1fbc9
3 changed files with 24 additions and 14 deletions
13
CHANGELOG.md
Normal file
13
CHANGELOG.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# nvd changelog
|
||||
|
||||
## 0.1.0
|
||||
|
||||
- Optimized first level dependency calculation to read depenencies from
|
||||
`nix-store` rather than walking a directory tree manually (issue #4). This
|
||||
also fixes nvd's support for things other than simple `buildEnv`s, e.g. file
|
||||
entries at the top level of the store, derivations, and references in files
|
||||
other than symlinks.
|
||||
|
||||
## 0.0.1
|
||||
|
||||
Initial release.
|
|
@ -4,7 +4,7 @@ let
|
|||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "nvd";
|
||||
version = "0.0.1";
|
||||
version = "0.1.0";
|
||||
|
||||
src = nix-gitignore.gitignoreSourcePure [ ./.gitignore ] ./src;
|
||||
|
||||
|
|
23
src/nvd
23
src/nvd
|
@ -237,22 +237,19 @@ class PackageManifest:
|
|||
|
||||
@staticmethod
|
||||
def parse_tree(root: Path) -> "PackageManifest":
|
||||
assert isinstance(root, Path), f"Not a Path: {root!r}"
|
||||
|
||||
store_paths = set()
|
||||
for curdir, dirs, files in os.walk(root, onerror=raise_arg):
|
||||
for filename in files:
|
||||
path_str = os.path.join(curdir, filename)
|
||||
if os.path.islink(path_str):
|
||||
store_paths.add(StorePath(os.readlink(path_str)).to_base_path())
|
||||
direct_deps: List[str] = subprocess.run(
|
||||
["nix-store", "--query", "--references", str(root)],
|
||||
stdout=PIPE,
|
||||
text=True
|
||||
).stdout.rstrip("\n").split("\n")
|
||||
|
||||
packages = []
|
||||
for store_path in store_paths:
|
||||
pname, version = parse_pname_version(str(store_path.path()))
|
||||
for dep_path in direct_deps:
|
||||
pname, version = parse_pname_version(dep_path)
|
||||
packages.append(Package(
|
||||
pname=pname,
|
||||
version=Version(version),
|
||||
store_path=store_path,
|
||||
store_path=StorePath(dep_path),
|
||||
))
|
||||
|
||||
return PackageManifest(packages)
|
||||
|
@ -455,8 +452,8 @@ def main():
|
|||
right_manifest: Optional[PackageManifest] = None
|
||||
|
||||
if (left_resolved / "sw").is_dir() and (right_resolved / "sw").is_dir():
|
||||
left_manifest = PackageManifest.parse_tree(left_resolved / "sw")
|
||||
right_manifest = PackageManifest.parse_tree(right_resolved / "sw")
|
||||
left_manifest = PackageManifest.parse_tree((left_resolved / "sw").resolve())
|
||||
right_manifest = PackageManifest.parse_tree((right_resolved / "sw").resolve())
|
||||
else:
|
||||
left_manifest = PackageManifest.parse_tree(left_resolved)
|
||||
right_manifest = PackageManifest.parse_tree(right_resolved)
|
||||
|
|
Loading…
Reference in a new issue