mirror of
https://gitlab.com/khumba/nvd.git
synced 2024-11-13 00:19:28 +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
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "nvd";
|
pname = "nvd";
|
||||||
version = "0.0.1";
|
version = "0.1.0";
|
||||||
|
|
||||||
src = nix-gitignore.gitignoreSourcePure [ ./.gitignore ] ./src;
|
src = nix-gitignore.gitignoreSourcePure [ ./.gitignore ] ./src;
|
||||||
|
|
||||||
|
|
23
src/nvd
23
src/nvd
|
@ -237,22 +237,19 @@ class PackageManifest:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_tree(root: Path) -> "PackageManifest":
|
def parse_tree(root: Path) -> "PackageManifest":
|
||||||
assert isinstance(root, Path), f"Not a Path: {root!r}"
|
direct_deps: List[str] = subprocess.run(
|
||||||
|
["nix-store", "--query", "--references", str(root)],
|
||||||
store_paths = set()
|
stdout=PIPE,
|
||||||
for curdir, dirs, files in os.walk(root, onerror=raise_arg):
|
text=True
|
||||||
for filename in files:
|
).stdout.rstrip("\n").split("\n")
|
||||||
path_str = os.path.join(curdir, filename)
|
|
||||||
if os.path.islink(path_str):
|
|
||||||
store_paths.add(StorePath(os.readlink(path_str)).to_base_path())
|
|
||||||
|
|
||||||
packages = []
|
packages = []
|
||||||
for store_path in store_paths:
|
for dep_path in direct_deps:
|
||||||
pname, version = parse_pname_version(str(store_path.path()))
|
pname, version = parse_pname_version(dep_path)
|
||||||
packages.append(Package(
|
packages.append(Package(
|
||||||
pname=pname,
|
pname=pname,
|
||||||
version=Version(version),
|
version=Version(version),
|
||||||
store_path=store_path,
|
store_path=StorePath(dep_path),
|
||||||
))
|
))
|
||||||
|
|
||||||
return PackageManifest(packages)
|
return PackageManifest(packages)
|
||||||
|
@ -455,8 +452,8 @@ def main():
|
||||||
right_manifest: Optional[PackageManifest] = None
|
right_manifest: Optional[PackageManifest] = None
|
||||||
|
|
||||||
if (left_resolved / "sw").is_dir() and (right_resolved / "sw").is_dir():
|
if (left_resolved / "sw").is_dir() and (right_resolved / "sw").is_dir():
|
||||||
left_manifest = PackageManifest.parse_tree(left_resolved / "sw")
|
left_manifest = PackageManifest.parse_tree((left_resolved / "sw").resolve())
|
||||||
right_manifest = PackageManifest.parse_tree(right_resolved / "sw")
|
right_manifest = PackageManifest.parse_tree((right_resolved / "sw").resolve())
|
||||||
else:
|
else:
|
||||||
left_manifest = PackageManifest.parse_tree(left_resolved)
|
left_manifest = PackageManifest.parse_tree(left_resolved)
|
||||||
right_manifest = PackageManifest.parse_tree(right_resolved)
|
right_manifest = PackageManifest.parse_tree(right_resolved)
|
||||||
|
|
Loading…
Reference in a new issue