]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Ignore unknown sloppiness values in configuration files
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Nov 2019 21:51:54 +0000 (22:51 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Nov 2019 21:51:54 +0000 (22:51 +0100)
Similar to 22db9ed893e9: This way legacy ccache versions can still work
with modern ccache configuration keys in the configuration files.

src/confitems.c
unittest/test_conf.c

index d9d14bdd5b724d7e68ed629b69d78e402e1c0cd8..4b70db4ac8eadcd9bf999e55fa528ebd109a1953 100644 (file)
@@ -110,6 +110,8 @@ confitem_format_size(const void *value)
 bool
 confitem_parse_sloppiness(const char *str, void *result, char **errmsg)
 {
+       (void)errmsg;
+
        unsigned *value = (unsigned *)result;
        if (!str) {
                return *value;
@@ -141,11 +143,8 @@ confitem_parse_sloppiness(const char *str, void *result, char **errmsg)
                        *value |= SLOPPY_CLANG_INDEX_STORE;
                } else if (str_eq(word, "locale")) {
                        *value |= SLOPPY_LOCALE;
-               } else {
-                       *errmsg = format("unknown sloppiness: \"%s\"", word);
-                       free(p);
-                       return false;
                }
+               // else: ignore unknown value for forward compatibility
                q = NULL;
        }
        free(p);
index 7dba8571cf6e6dc50ffda16340683b8374194b81..da57bb4a0ca548e813405d9efa40c84f3803bb6b 100644 (file)
@@ -267,15 +267,13 @@ TEST(conf_read_invalid_size)
        conf_free(conf);
 }
 
-TEST(conf_read_invalid_sloppiness)
+TEST(conf_read_unknown_sloppiness)
 {
        struct conf *conf = conf_create();
        char *errmsg;
-       create_file("ccache.conf", "sloppiness = file_macro, foo");
-       CHECK(!conf_read(conf, "ccache.conf", &errmsg));
-       CHECK_INT_EQ(errno, 0);
-       CHECK_STR_EQ_FREE2("ccache.conf:1: unknown sloppiness: \"foo\"",
-                          errmsg);
+       create_file("ccache.conf", "sloppiness = time_macros, foo");
+       CHECK(conf_read(conf, "ccache.conf", &errmsg));
+       CHECK_INT_EQ(conf->sloppiness, SLOPPY_TIME_MACROS);
        conf_free(conf);
 }
 
@@ -405,6 +403,19 @@ TEST(conf_set_unknown_option)
        CHECK_STR_EQ_FREE2("path = chocolate\nstats = chocolate\n", data);
 }
 
+TEST(conf_set_unknown_sloppiness)
+{
+       char *errmsg;
+       char *data;
+
+       create_file("ccache.conf", "path = vanilla\n");
+       CHECK(conf_set_value_in_file("ccache.conf", "sloppiness", "foo", &errmsg));
+
+       data = read_text_file("ccache.conf", 0);
+       CHECK(data);
+       CHECK_STR_EQ_FREE2("path = vanilla\nsloppiness = foo\n", data);
+}
+
 TEST(conf_print_existing_value)
 {
        struct conf *conf = conf_create();