From 543c22cb6337041bde98064cbdbe890d4db6bec3 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Fri, 15 Jun 2018 10:53:32 +0200 Subject: [PATCH 1/4] add ccache completion --- src/_ccache | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/_ccache diff --git a/src/_ccache b/src/_ccache new file mode 100644 index 0000000..a9dc010 --- /dev/null +++ b/src/_ccache @@ -0,0 +1,66 @@ +#compdef ccache +# zsh completion script for ccache + +# Copyright 2018 CERN for the benefit of the LHCb Collaboration. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# In applying this licence, CERN does not waive the privileges and immunities +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. + +# allow users to define their better compilers +# inspired by _cmake_compilers +# users could override with +# +# _ccache_compilers() { +# local -a _ccache_compilers +# _ccache_compilers=(gcc g++ clang clang++) +# _wanted compilers expl "compiler" compadd -- $_ccache_compilers +# } +(( $+functions[_ccache_compilers] )) || +_ccache_compilers() { + _command_names -e +} + +if [[ $words[2] == -* ]]; then + # if the first argument starts with -, we are in configure-ccache mode + # for this, _gnu_generic is okayish: + # * ccache --set-config=key=value won't complete beyond the first = + # * ccache --set-config=foo=bar -- won't suggest "set-config" another time + if [[ $words[$CURRENT] == -* ]]; then + # only call _gnu_generic without hyphen (files are not useful) + _gnu_generic + fi +elif [[ $CURRENT -eq 2 ]]; then + _ccache_compilers +else + # the command line already looks like 'ccache ...' + # forward to the completion function of the compiler + (( CURRENT-- )) + shift words + _normal +fi From 66f1f211b9433401c088d651bdb12ca8a1a649d6 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Sun, 17 Jun 2018 15:18:08 +0200 Subject: [PATCH 2/4] start environment variable completion --- src/_ccache | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/src/_ccache b/src/_ccache index a9dc010..504deb9 100644 --- a/src/_ccache +++ b/src/_ccache @@ -1,4 +1,5 @@ -#compdef ccache +#compdef ccache -P -value-,CCACHE_*,-default- + # zsh completion script for ccache # Copyright 2018 CERN for the benefit of the LHCb Collaboration. @@ -46,6 +47,129 @@ _ccache_compilers() { _command_names -e } +_ccache_booleans() { + _message 'There are no "false" values, unset variable to disable' + local description; description=${1:-boolean} + local booleans; booleans=( + 'true' + 'yes' + ) + _describe -t booeans "$description" booleans +} + +if [[ "$service" = -value-* ]]; then + case $service in + *CCACHE_*DIR*) + # CCACHE_BASEDIR: relative to which top level paths are hashed + # CCACHE_DIR: where the cache and config are kept + # CCACHE_TEMPDIR: where temporary files are kept + # all: a single path + _path_files -/ + ;; + *CCACHE_NLEVELS*) + local -a one_eight + one_eight=(1 2 3 4 5 6 7 8) + _describe -t onetoeight "directory levels in the cache directory" one_eight + ;; + *CCACHE_CC*) + _ccache_compilers + ;; + *CCACHE_COMPILERCHECK*) + local -a compiler_check_values + compiler_check_values=( + 'content: the actual compiler binary' + 'mtime: mtime and size of the compiler' + 'none: ignore compiler for hashing' + 'string\:: any hard coded string (pre-computed version)' + '%compiler%\ -v:any compiler invocation output' + ) + _describe -t compilerchecks "compiler information included in the hash" compiler_check_values + ;; + *CCACHE_*COMPRESS*) + _ccache_booleans "write compressed cache" + ;; + *CCACHE_COMPRESSLEVEL*) + local -a one_nine + one_nine=(1 2 3 4 5 6 7 8 9) + _describe -t onetonine "compression level (if using compression)" one_nine + ;; + *CCACHE_EXTENSION*) + # FIXME + ;; + *CCACHE_*DIRECT*) + _ccache_booleans "use direct mode" + ;; + *CCACHE_*DISABLE*) + _ccache_booleans "disable cache usage" + ;; + *CCACHE_EXTRAFILES*) + local sep=: + compset -P "*${sep}" + compset -S "${sep}*" || suf="$sep" + + _files "" -r "${sep}"' /\t\t\-' "$@" + ;; + *CCACHE_*HARDLINK*) + _ccache_booleans "create hard links rather than copies" + ;; + *CCACHE_*HASHDIR*) + _ccache_booleans "include the cwd in the hash" + ;; + *CCACHE_IGNOREHEADERS*) + _dir_list + ;; + *CCACHE_*COMMENTS*) + _ccache_booleans "consider comments in hashing" + ;; + *CCACHE_LIMIT_MULTIPLE*) + _alternative ":clean up down to level (e.g. 0.8): " + ;; + *CCACHE_LOGFILE*) + _path_files -g "*(/) *.log" + ;; + *CCACHE_MAXFILES*) + _alternative ":maximum number of files in the cache (0= no limit): " + ;; + *CCACHE_MAXSIZE*) + ;; + *CCACHE_PATH*) + _alternative ':PATH for compiler lookup (instead of $PATH):_dir_list' + ;; + *CCACHE_PREFIX*) + # FIXME + ;; + *CCACHE_PREFIX_CPP*) + # FIXME + ;; + *CCACHE_*READONLY*) + _ccache_booleans "treat cache as read-only" + ;; + *CCACHE_*READONLY_DIRECT*) + _ccache_booleans "retrieve from read-only cache in direct mode" + ;; + *CCACHE_*RECACHE*) + _ccache_booleans "use cache in write-only mode" + ;; + *CCACHE_*CPP2*) + _ccache_booleans "pass originial rather than preprocessed source code to compiler" + ;; + *CCACHE_SLOPPINESS*) + # FIXME + ;; + *CCACHE_*STATS*) + _ccache_booleans "update statistics counters" + ;; + *CCACHE_UMASK*) + # FIXME + ;; + *CCACHE_*UNIFY*) + _ccache_booleans "normalise sources prior to processing" + ;; + esac + + return +fi + if [[ $words[2] == -* ]]; then # if the first argument starts with -, we are in configure-ccache mode # for this, _gnu_generic is okayish: From 0b151f17495c92be278bb074628b4b43f01c80bc Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Mon, 18 Jun 2018 13:40:58 +0200 Subject: [PATCH 3/4] add actual arguments for ccache completion --- src/_ccache | 168 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 145 insertions(+), 23 deletions(-) diff --git a/src/_ccache b/src/_ccache index 504deb9..5f6ffa3 100644 --- a/src/_ccache +++ b/src/_ccache @@ -57,6 +57,33 @@ _ccache_booleans() { _describe -t booeans "$description" booleans } +(( $+functions[_ccache_compressionlevels] )) || +_ccache_compressionlevels() { + local -a one_nine + one_nine=(1 2 3 4 5 6 7 8 9) + _describe -t onetonine "compression level (if using compression)" one_nine +} + +(( $+functions[_ccache_compilerchecks] )) || +_ccache_compilerchecks() { + local -a compiler_check_values + compiler_check_values=( + 'content: the actual compiler binary' + 'mtime: mtime and size of the compiler' + 'none: ignore compiler for hashing' + 'string\:: any hard coded string (pre-computed version)' + '%compiler%\ -v:any compiler invocation output' + ) + _describe -t compilerchecks "compiler information included in the hash" compiler_check_values +} + +(( $+functions[_ccache_dirlevels] )) || +_ccache_dirlevels() { + local -a one_eight + one_eight=(1 2 3 4 5 6 7 8) + _describe -t onetoeight "directory levels in the cache directory" one_eight +} + if [[ "$service" = -value-* ]]; then case $service in *CCACHE_*DIR*) @@ -67,31 +94,19 @@ if [[ "$service" = -value-* ]]; then _path_files -/ ;; *CCACHE_NLEVELS*) - local -a one_eight - one_eight=(1 2 3 4 5 6 7 8) - _describe -t onetoeight "directory levels in the cache directory" one_eight + _ccache_dirlevels ;; *CCACHE_CC*) _ccache_compilers ;; *CCACHE_COMPILERCHECK*) - local -a compiler_check_values - compiler_check_values=( - 'content: the actual compiler binary' - 'mtime: mtime and size of the compiler' - 'none: ignore compiler for hashing' - 'string\:: any hard coded string (pre-computed version)' - '%compiler%\ -v:any compiler invocation output' - ) - _describe -t compilerchecks "compiler information included in the hash" compiler_check_values + _ccache_compilerchecks ;; *CCACHE_*COMPRESS*) _ccache_booleans "write compressed cache" ;; *CCACHE_COMPRESSLEVEL*) - local -a one_nine - one_nine=(1 2 3 4 5 6 7 8 9) - _describe -t onetonine "compression level (if using compression)" one_nine + _ccache_compressionlevels ;; *CCACHE_EXTENSION*) # FIXME @@ -170,15 +185,122 @@ if [[ "$service" = -value-* ]]; then return fi -if [[ $words[2] == -* ]]; then +__ccache_config_keys() { + local -a keys + keys=( + 'compression' + 'direct_mode' + 'disable' + 'hard_link' + 'hash_dir' + 'keep_comments_cpp' + 'read_only' + 'read_only_direct' + 'recache' + 'run_second_cpp' + 'stats' + 'unify' + 'base_dir' + 'temporary_dir' + 'cache_dir' + 'compiler' + 'cache_dir_levels' + 'compiler_check' + 'compression_level' + 'cpp_extension' + 'extra_files_to_hash' + 'ignore_headers_in_manifest' + 'limit_multiple' + 'log_file' + 'max_files' + 'max_size' + 'path' + 'prefix_command' + 'prefix_command_cpp' + 'sloppiness' + 'umask' + ) + _describe -t configkeys "configuration keys" keys -S '=' +} + +if compset -P '--set-config=*='; then + case $IPREFIX in + *=compression= | *=direct_mode= | *=disable= | *=hard_link= | *=hash_dir= | *=keep_comments_cpp= | *=read_only= | *=read_only_direct= | *=recache= | *=run_second_cpp= | *=stats= | *=unify= ) + local booleans; booleans=( + 'true' + 'false' + ) + _describe -t booleans 'boolean' booleans + ;; + *=base_dir= | *=temporary_dir= | *=cache_dir=) + _path_files -/ + ;; + *=compiler=) + _ccache_compilers + ;; + *=cache_dir_levels=) + _ccache_dirlevels + ;; + *=compiler_check=) + _ccache_compilerchecks + ;; + *=compression_level=) + _ccache_compressionlevels + ;; + *=cpp_extension=) + # FIXME + ;; + *=extra_files_to_hash=) + local sep=: + compset -P "*${sep}" + compset -S "${sep}*" || suf="$sep" + + _files "" -r "${sep}"' /\t\t\-' "$@" + ;; + *=ignore_headers_in_manifest=) + _dir_list + ;; + *=limit_multiple=) + _alternative ":clean up down to level (e.g. 0.8): " + ;; + *=log_file=) + _path_files -g "*(/) *.log" + ;; + *=max_files=) + _alternative ":maximum number of files in the cache (0= no limit): " + ;; + *=max_size=) + # FIXME + ;; + *=path=) + _alternative ':PATH for compiler lookup (instead of $PATH):_dir_list' + ;; + *=prefix_command=) + # FIXME + ;; + *=prefix_command_cpp=) + # FIXME + ;; + *=sloppiness=) + # FIXME + ;; + *=umask=) + # FIXME + ;; + esac +elif [[ $words[2] == -* ]]; then # if the first argument starts with -, we are in configure-ccache mode - # for this, _gnu_generic is okayish: - # * ccache --set-config=key=value won't complete beyond the first = - # * ccache --set-config=foo=bar -- won't suggest "set-config" another time - if [[ $words[$CURRENT] == -* ]]; then - # only call _gnu_generic without hyphen (files are not useful) - _gnu_generic - fi + _arguments \ + '*'{-o,--set-config=}"[set configuration key]:keys:__ccache_config_keys" \ + '(: -)'{-h,--help}'[show help message]' \ + '(: -)'{-V,--version}'[print version and copyright information]' \ + '(-z --zero-stats)'{-z,--zero-stats}'[zero statistics counters]' \ + '(-c --cleanup)'{-c,--cleanup}'[delete old files and recalculate size counters]' \ + '(-C --clear)'{-C,--clear}'[clear the cache completely (except configuration)]' \ + '(-p --print-config)'{-p,--print-config}'[print current configuration options]' \ + '(-s --show-stats)'{-s,--show-stats}'[show statistics summary]' \ + '(-F --max-files=)'{-F,--max-files=}'[set maximum number of files in cache]:number of files in cache: ' \ + '(-M --max-size=)'{-M,--max-size=}'[set maximum size of cache]:cache size: ' elif [[ $CURRENT -eq 2 ]]; then _ccache_compilers else From 9f5c2796d7700491a3b2d70943c0272e73fda520 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Tue, 19 Jun 2018 16:40:05 +0200 Subject: [PATCH 4/4] last bit of ccache --- src/_ccache | 97 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/src/_ccache b/src/_ccache index 5f6ffa3..8bb33a2 100644 --- a/src/_ccache +++ b/src/_ccache @@ -64,6 +64,18 @@ _ccache_compressionlevels() { _describe -t onetonine "compression level (if using compression)" one_nine } +(( $+functions[_ccache_sloppiness] )) || +_ccache_sloppiness() { + _values -s ',' \ + "file_macro[ignore __FILE__]" \ + "file_stat_matches[rely on mtimes and ctimes]" \ + "include_file_ctime[ignore headers' ctime too new]" \ + "include_file_mtime[ignore headers' mtime too new]" \ + "no_system_headers[exclude system headers from cache]" \ + "pch_defines[be sloppy about #defines in pch]" \ + "time_macros[ignore __date__ and __time__]" +} + (( $+functions[_ccache_compilerchecks] )) || _ccache_compilerchecks() { local -a compiler_check_values @@ -109,7 +121,7 @@ if [[ "$service" = -value-* ]]; then _ccache_compressionlevels ;; *CCACHE_EXTENSION*) - # FIXME + _alternative ':set extension for intermediate files: ' ;; *CCACHE_*DIRECT*) _ccache_booleans "use direct mode" @@ -146,15 +158,16 @@ if [[ "$service" = -value-* ]]; then _alternative ":maximum number of files in the cache (0= no limit): " ;; *CCACHE_MAXSIZE*) + _alternative ':maximum cache size (0= no limit) with suffix k,M,G,T or Ki,Mi,Gi,Ti: ' ;; *CCACHE_PATH*) _alternative ':PATH for compiler lookup (instead of $PATH):_dir_list' ;; *CCACHE_PREFIX*) - # FIXME + _alternative ':prefixes for compiler invokation: ' ;; *CCACHE_PREFIX_CPP*) - # FIXME + _alternative ':prefixes for preprocessor invokation: ' ;; *CCACHE_*READONLY*) _ccache_booleans "treat cache as read-only" @@ -169,13 +182,13 @@ if [[ "$service" = -value-* ]]; then _ccache_booleans "pass originial rather than preprocessed source code to compiler" ;; *CCACHE_SLOPPINESS*) - # FIXME + _ccache_sloppiness ;; *CCACHE_*STATS*) _ccache_booleans "update statistics counters" ;; *CCACHE_UMASK*) - # FIXME + _alternative ":umask value (octal): " ;; *CCACHE_*UNIFY*) _ccache_booleans "normalise sources prior to processing" @@ -188,37 +201,37 @@ fi __ccache_config_keys() { local -a keys keys=( - 'compression' - 'direct_mode' - 'disable' - 'hard_link' - 'hash_dir' - 'keep_comments_cpp' - 'read_only' - 'read_only_direct' - 'recache' - 'run_second_cpp' - 'stats' - 'unify' - 'base_dir' - 'temporary_dir' - 'cache_dir' - 'compiler' - 'cache_dir_levels' - 'compiler_check' - 'compression_level' - 'cpp_extension' - 'extra_files_to_hash' - 'ignore_headers_in_manifest' - 'limit_multiple' - 'log_file' - 'max_files' - 'max_size' - 'path' - 'prefix_command' - 'prefix_command_cpp' - 'sloppiness' - 'umask' + 'compression:write compressed cache' + 'direct_mode:use direct mode' + 'disable:disable cache usage' + 'hard_link:create hard links rather than copies' + 'hash_dir:include the cwd in the hash' + 'keep_comments_cpp:consider comments in hashing' + 'read_only:treat cache as read-only' + 'read_only_direct:retrieve from read-only cache in direct mode' + 'recache:use cache in write-only mode' + 'run_second_cpp:pass originial rather than preprocessed source code to compiler' + 'stats:update statistics counters' + 'unify:normalise sources prior to processing' + 'base_dir:specify relative to which top level paths are hashed' + 'temporary_dir:specify where temporary files are kept' + 'cache_dir:specify where the cache is kept' + 'compiler:specify compiler' + 'cache_dir_levels:directory levels in the cache directory' + 'compiler_check:compiler information included in the hash' + 'compression_level:cache compression level' + 'cpp_extension:set extensions for intermediate files' + 'extra_files_to_hash:additional files to consider in hashing' + 'ignore_headers_in_manifest:set paths to headers to ignore in hashing' + 'limit_multiple:cleanup level' + 'log_file:specify a log file' + 'max_files:maximum number of files in the cache' + 'max_size:maximum size of the cache' + 'path:PATH for compiler lookup (instead of $PATH)' + 'prefix_command:prefixes for compiler invokation' + 'prefix_command_cpp:prefixes for preprocessor invokation' + 'sloppiness:hash files sloppy' + 'umask:set umask for ccache and child processes (e.g. for sharing cache)' ) _describe -t configkeys "configuration keys" keys -S '=' } @@ -248,7 +261,7 @@ if compset -P '--set-config=*='; then _ccache_compressionlevels ;; *=cpp_extension=) - # FIXME + _alternative ':set extension for intermediate files: ' ;; *=extra_files_to_hash=) local sep=: @@ -270,22 +283,22 @@ if compset -P '--set-config=*='; then _alternative ":maximum number of files in the cache (0= no limit): " ;; *=max_size=) - # FIXME + _alternative ':maximum cache size (0= no limit) with suffix k,M,G,T or Ki,Mi,Gi,Ti: ' ;; *=path=) _alternative ':PATH for compiler lookup (instead of $PATH):_dir_list' ;; *=prefix_command=) - # FIXME + _alternative ':prefixes for compiler invokation: ' ;; *=prefix_command_cpp=) - # FIXME + _alternative ':prefixes for preprocessor invokation: ' ;; *=sloppiness=) - # FIXME + _ccache_sloppiness ;; *=umask=) - # FIXME + _alternative ":umask value (octal): " ;; esac elif [[ $words[2] == -* ]]; then