]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
config: Add -p/--print-config option
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Jul 2011 20:10:31 +0000 (22:10 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 29 Jul 2011 15:16:58 +0000 (17:16 +0200)
ccache.c
conf.c
test/test_conf.c

index 386c7d4c8826acbfe43c0f39ceed44f8466f27e6..920a7d97a7928a71834fbfce375bcd59a8f60210 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -62,6 +62,7 @@ static const char USAGE_TEXT[] =
 "                          limit; available suffixes: G, M and K; default\n"
 "                          suffix: G)\n"
 "    -o, --set-option=K=V  set configuration option K to V\n"
+"    -p, --print-config    print current configuration options\n"
 "    -s, --show-stats      show statistics summary\n"
 "    -z, --zero-stats      zero statistics counters\n"
 "\n"
@@ -2081,6 +2082,16 @@ ccache(int argc, char *argv[])
        failed();
 }
 
+static void
+conf_printer(const char *s, void *context)
+{
+       if (context == NULL) {
+               cc_log("%s\n", s);
+       } else {
+               fprintf(context, "%s\n", s);
+       }
+}
+
 /* the main program when not doing a compile */
 static int
 ccache_main_options(int argc, char *argv[])
@@ -2099,13 +2110,14 @@ ccache_main_options(int argc, char *argv[])
                {"max-files",     required_argument, 0, 'F'},
                {"max-size",      required_argument, 0, 'M'},
                {"set-option",    required_argument, 0, 'o'},
+               {"print-config",  no_argument,       0, 'p'},
                {"show-stats",    no_argument,       0, 's'},
                {"version",       no_argument,       0, 'V'},
                {"zero-stats",    no_argument,       0, 'z'},
                {0, 0, 0, 0}
        };
 
-       while ((c = getopt_long(argc, argv, "cChF:M:o:sVz", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "cChF:M:o:psVz", options, NULL)) != -1) {
                switch (c) {
                case DUMP_MANIFEST:
                        manifest_dump(optarg, stdout);
@@ -2184,6 +2196,11 @@ ccache_main_options(int argc, char *argv[])
                        }
                        break;
 
+               case 'p': /* --print-config */
+                       initialize();
+                       conf_print_items(conf, conf_printer, stdout);
+                       break;
+
                case 's': /* --show-stats */
                        initialize();
                        stats_summary(conf);
diff --git a/conf.c b/conf.c
index 5cd73928a5f104b8dc782fc6831d82d8a66eac7e..a79001bb07c7578ef653ddb3772f1930bd097e6e 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -60,21 +60,6 @@ parse_env_string(const char *str, void *result, char **errmsg)
        return *value;
 }
 
-static bool
-parse_octal(const char *str, void *result, char **errmsg)
-{
-       unsigned *value = (unsigned *)result;
-       char *endptr;
-       errno = 0;
-       *value = strtoul(str, &endptr, 8);
-       if (errno == 0 && *str != '\0' && *endptr == '\0') {
-               return true;
-       } else {
-               *errmsg = format("not an octal integer: \"%s\"", str);
-               return false;
-       }
-}
-
 static bool
 parse_size(const char *str, void *result, char **errmsg)
 {
@@ -129,6 +114,25 @@ parse_string(const char *str, void *result, char **errmsg)
        return true;
 }
 
+static bool
+parse_umask(const char *str, void *result, char **errmsg)
+{
+       unsigned *value = (unsigned *)result;
+       char *endptr;
+       if (str_eq(str, "")) {
+               *value = UINT_MAX;
+               return true;
+       }
+       errno = 0;
+       *value = strtoul(str, &endptr, 8);
+       if (errno == 0 && *str != '\0' && *endptr == '\0') {
+               return true;
+       } else {
+               *errmsg = format("not an octal integer: \"%s\"", str);
+               return false;
+       }
+}
+
 static bool
 parse_unsigned(const char *str, void *result, char **errmsg)
 {
@@ -206,7 +210,7 @@ static const struct conf_item conf_items[] = {
        ITEM(sloppiness, sloppiness),
        ITEM(stats, bool),
        ITEM(temporary_dir, env_string),
-       ITEM(umask, octal),
+       ITEM(umask, umask),
        ITEM(unify, bool)
 };
 
@@ -710,8 +714,12 @@ bool conf_print_items(struct conf *conf,
        reformat(&s, "temporary_dir = %s", conf->temporary_dir);
        printer(s, context);
 
-       reformat(&s, "umask = %03o", conf->umask);
-       printer(s, context);
+       if (conf->umask == UINT_MAX) {
+               printer("umask = ", context);
+       } else {
+               reformat(&s, "umask = %03o", conf->umask);
+               printer(s, context);
+       }
 
        reformat(&s, "unify = %s", conf->unify ? "true" : "false");
        printer(s, context);
index 2ad6d80b78463f380c38c6a658753ca4dbdc47a6..f2f4e5ae740c1e70f3e70b5887d24f992b1ad25c 100644 (file)
@@ -210,14 +210,13 @@ TEST(conf_read_invalid_env_string)
        conf_free(conf);
 }
 
-TEST(conf_read_invalid_octal)
+TEST(conf_read_empty_umask)
 {
        struct conf *conf = conf_create();
        char *errmsg;
-       create_file("ccache.conf", "umask = 890x");
-       CHECK(!conf_read(conf, "ccache.conf", &errmsg));
-       CHECK_STR_EQ_FREE2("ccache.conf:1: not an octal integer: \"890x\"",
-                          errmsg);
+       create_file("ccache.conf", "umask = ");
+       CHECK(conf_read(conf, "ccache.conf", &errmsg));
+       CHECK_INT_EQ(conf->umask, UINT_MAX);
        conf_free(conf);
 }