From 7952a8053c474e771d6ee14e3ab6dc15c9ddd895 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 6 Jul 2003 15:11:02 +0000 Subject: [PATCH] * A utility `nix-hash' to compute Nix path hashes. --- src/Makefile.am | 5 ++++- src/fix.cc | 4 +--- src/nix-hash.cc | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/nix-hash.cc diff --git a/src/Makefile.am b/src/Makefile.am index 7d12719ac..22b27d88a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = nix fix +bin_PROGRAMS = nix nix-hash fix check_PROGRAMS = test AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall -I.. @@ -6,6 +6,9 @@ AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall -I.. nix_SOURCES = nix.cc shared.cc nix_LDADD = libnix.a -ldb_cxx-4 -lATerm +nix_hash_SOURCES = nix-hash.cc shared.cc +nix_hash_LDADD = libnix.a -ldb_cxx-4 -lATerm + fix_SOURCES = fix.cc shared.cc fix_LDADD = libnix.a -ldb_cxx-4 -lATerm diff --git a/src/fix.cc b/src/fix.cc index cb42aca6b..33bcdd9a1 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -186,7 +186,6 @@ static Expr evalExpr(Expr e) /* Hash the normal form to produce a unique but deterministic path name for this package. */ ATerm nf = ATmake("Package()", ATreverse(bnds)); - debug(printTerm(nf)); Hash hash = hashTerm(nf); if (builder == "") @@ -202,7 +201,6 @@ static Expr evalExpr(Expr e) /* Construct the result. */ e = ATmake("Derive(, , , , )", SYSTEM, builder.c_str(), ins, out.c_str(), env); - debug(printTerm(e)); /* Write the resulting term into the Nix store directory. */ Hash eHash = writeTerm(e); @@ -257,7 +255,7 @@ void run(Strings args) char * s; if (ATmatch(e, "Include()", &s)) { cout << format("%1%\n") % s; - } + } else throw badTerm("top level is not a package", e); } } diff --git a/src/nix-hash.cc b/src/nix-hash.cc new file mode 100644 index 000000000..e35d0a1fe --- /dev/null +++ b/src/nix-hash.cc @@ -0,0 +1,16 @@ +#include + +#include "hash.hh" +#include "shared.hh" + + +void run(Strings args) +{ + for (Strings::iterator it = args.begin(); + it != args.end(); it++) + cout << format("%1%\n") % (string) hashPath(*it); +} + + +string programId = "nix-hash"; +