summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2018-06-23 19:09:06 +0200
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2018-06-23 19:30:03 +0200
commita4f5f282a3ca686a5344896ca5b9cdcdfac152f1 (patch)
tree78400285dc900ad433508f75447351c4e975269a
parentf60a1d9a8f91289a85585a2bbae67226252369c4 (diff)
downloadccache-a4f5f282a3ca686a5344896ca5b9cdcdfac152f1.tar.gz
Add --hash-file command, for convenience
-rw-r--r--src/ccache.c19
-rw-r--r--test/suites/base.bash14
2 files changed, 32 insertions, 1 deletions
diff --git a/src/ccache.c b/src/ccache.c
index eaa9b308..4fd25505 100644
--- a/src/ccache.c
+++ b/src/ccache.c
@@ -3486,12 +3486,14 @@ static int
ccache_main_options(int argc, char *argv[])
{
enum longopts {
- DUMP_MANIFEST
+ DUMP_MANIFEST,
+ HASH_FILE
};
static const struct option options[] = {
{"cleanup", no_argument, 0, 'c'},
{"clear", no_argument, 0, 'C'},
{"dump-manifest", required_argument, 0, DUMP_MANIFEST},
+ {"hash-file", required_argument, 0, HASH_FILE},
{"help", no_argument, 0, 'h'},
{"max-files", required_argument, 0, 'F'},
{"max-size", required_argument, 0, 'M'},
@@ -3502,6 +3504,8 @@ ccache_main_options(int argc, char *argv[])
{"zero-stats", no_argument, 0, 'z'},
{0, 0, 0, 0}
};
+ struct mdfour md;
+ char *s;
int c;
while ((c = getopt_long(argc, argv, "cChF:M:o:psVz", options, NULL)) != -1) {
@@ -3510,6 +3514,19 @@ ccache_main_options(int argc, char *argv[])
manifest_dump(optarg, stdout);
break;
+ case HASH_FILE:
+ initialize();
+ hash_start(&md);
+ if (str_eq(optarg, "-")) {
+ hash_fd(&md, STDIN_FILENO);
+ } else {
+ hash_file(&md, optarg);
+ }
+ s = hash_result(&md);
+ puts(s);
+ free(s);
+ break;
+
case 'c': // --cleanup
initialize();
clean_up_all(conf);
diff --git a/test/suites/base.bash b/test/suites/base.bash
index 307100e8..e53d40aa 100644
--- a/test/suites/base.bash
+++ b/test/suites/base.bash
@@ -913,6 +913,20 @@ EOF
test_failed "boolean env var '$invalid_val' should be rejected"
fi
done
+
+ # -------------------------------------------------------------------------
+ TEST "--hash-file"
+
+ >empty
+ $CCACHE --hash-file empty > hash.out
+ printf "a" | $CCACHE --hash-file - >> hash.out
+
+ if grep '31d6cfe0d16ae931b73c59d7e0c089c0-0' hash.out >/dev/null 2>&1 && \
+ grep 'bde52cb31de33e46245e05fbdbd6fb24-1' hash.out >/dev/null 2>&1; then
+ : OK
+ else
+ test_failed "Unexpected output of --hash-file"
+ fi
}
# =============================================================================