Hi,

I would like to improve ccache's configurability. As you know, configuration of
ccache is today done by setting a bunch of environment variables, but that's
becoming increasingly messy; there are currently 24 CCACHE_* variables in the
development version of ccache. I think it's time to move settings to a
configuration file while keeping the ability to override configuration by
setting environment variables.

I actually envision two configuration files:

- <sysconfdir>/ccache.conf (typically /etc/ccache.conf)
- <ccachedir>/ccache.conf (typically $HOME/.ccache/ccache.conf)

ccache reads both (if they exist) each time it's run. Settings then have the
following priority:

1. Environment variables.
2. <ccachedir>/ccache.conf
3. <sysconfdir>/ccache.conf
4. Compile-time defaults.

This means that:

- The administrator can choose default settings for the system by editing
  <sysconfdir>/ccache.conf.
- The user can override the system settings with his/her own default settings
  by editing <ccachedir>/ccache.conf. (If <ccachedir> is shared by several
  users, the settings are of course also shared.)
- The user can override the default settings temporarily by setting environment
  variables.
- It's backwards compatible with the existing environment variables.

I expect that the overhead of reading the configuration file(s) will be
negligible.

The "max files" and "max size" settings (set by command-line options
-F/--max-files and -M/--max-size) are today stored in the "stats" files in the
cache, but these will find a much better place in <ccachedir>/ccache.conf.

I think the configuration file syntax should be a simple text format like this:

    # A comment.
    key = value

No quotes around strings (at least not mandatory). Whitespace is trimmed at the
beginning and end of values.

Mapping between environment variables and keys in the configuration files:

    Environment variable   Config key           Type     Default       Note
    -----------------------------------------------------------------------
    CCACHE_BASEDIR         base_dir             string   ""            [1]
    CCACHE_CC              compiler             string   ""            [2]
    CCACHE_COMPILERCHECK   compiler_check       string   mtime
    CCACHE_COMPRESS        compression          boolean  false
    CCACHE_CPP2            run_second_cpp       boolean  false
    CCACHE_DETECT_SHEBANG  detect_shebang       boolean  false
    CCACHE_DIR             cache_dir            string   $HOME/.ccache
    CCACHE_DIRECT          direct_mode          boolean  true
    CCACHE_DISABLE         disable              boolean  false
    CCACHE_EXTENSION       cpp_extension        string   ""            [3]
    CCACHE_EXTRAFILES      extra_files_to_hash  string   ""
    CCACHE_HARDLINK        hard_link            boolean  false
    CCACHE_HASHDIR         hash_dir             boolean  false
    CCACHE_LOGFILE         log_file             string   ""            [4]
NEW CCACHE_MAXFILES        max_files            integer  0             [5]
NEW CCACHE_MAXSIZE         max_size             integer  1G            [6]
    CCACHE_NLEVELS         cache_dir_levels     integer  2
    CCACHE_PATH            path                 string   ""            [7]
    CCACHE_PREFIX          prefix_command       string   ""            [8]
    CCACHE_READONLY        read_only            boolean  false
    CCACHE_RECACHE         recache              boolean  false
    CCACHE_SLOPPINESS      sloppiness           string   ""
    CCACHE_STATS           stats                boolean  true
    CCACHE_TEMPDIR         temporary_dir        string   ""            [9]
    CCACHE_UMASK           umask                integer  -             [10]
    CCACHE_UNIFY           unify                boolean  false

String and integer settings are handled in a straight-forward manner, but
boolean settings are a bit special for backward-compatibility reasons:

  - A boolean CCACHE_FOO set to any value (even the empty string) means true;
    unset means false.
  - For each boolean CCACHE_FOO, there is also a CCACHE_NOFOO with the inverse
    logic. CCACHE_FOO (if set) has higher priority than CCACHE_NOFOO. (Some
    settings are quite silly in their NO variant, but I think it's worth it for
    consistency.)
  - The possible values of a boolean setting in the configuration file are
    spelled "true" and "false".

$VARIABLE and ${VARIABLE} references will be expanded as expected in variables
that specify paths.

Notes:

[1] The empty string means "don't rewrite absolute paths".
[2] The empty string means find compiler from the command line.
[3] The empty string means auto-detect.
[4] The empty string means no logging.
[5] New setting corresponding to the old -F command-line option. 0 means
    unlimited.
[6] New setting corresponding to the old -M command-line option. 0 means
    unlimited. Suffix G, M or K may be used; default suffix: G.
[7] The empty string means use the normal PATH.
[8] The empty string means no prefix.
[9] The empty string means "use <cache_dir>/tmp".
[10] Not set means "don't change the umask". The integer is interpreted as an
     octal number.

New command-line options to ccache:

  -o, --set-option=K=V     set configuration setting K to V
  -p, --print-config       print current configuration settings

The -F and -M command-line options will update the configuration file instead
of the stats file (and those entries in the stats files will become obsolete).

What do you think? Comments are welcome!

-- Joel
_______________________________________________
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache

Reply via email to