Use nix-store to query direct deps of command line arguments (closes #4).

This commit is contained in:
Bryan Gardiner 2021-05-03 18:33:54 -07:00
parent 7cdaa6d818
commit 2c2fa1fbc9
No known key found for this signature in database
GPG key ID: 53EFBCA063E6183C
3 changed files with 24 additions and 14 deletions

13
CHANGELOG.md Normal file
View 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.

View file

@ -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
View file

@ -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)