From 79f26d973573cd9ee344afa38c4c860b11bda79b Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 30 Jan 2018 21:51:17 +0100 Subject: [PATCH] Improve docs and clean up --- MANUAL.txt | 11 ++++++----- ccache.c | 6 +++--- test/suites/cpp1.bash | 16 ++++++++-------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/MANUAL.txt b/MANUAL.txt index 8bcc9a037..0d37a42e2 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -486,11 +486,12 @@ source code only has to be preprocessed once. The downside is that some compilers won't produce the same result (for instance diagnostics warnings) when compiling preprocessed source code. + -An alternative to *run_second_cpp* is to use *-fdirectives-only* (for GCC) or -*-frewrite-includes* (for Clang). This will cause the compiler to leave the -macros and other preprocessor information, and only process the *#include* -directives. When run in this way, the preprocessor arguments will be passed -to the compiler since it still has to do _some_ preprocessing (like macros). +A solution to the above mentioned downside is to set *run_second_cpp* to false +and pass *-fdirectives-only* (for GCC) or *-frewrite-includes* (for Clang) to +the compiler. This will cause the compiler to leave the macros and other +preprocessor information, and only process the *#include* directives. When run +in this way, the preprocessor arguments will be passed to the compiler since it +still has to do _some_ preprocessing (like macros). *sloppiness* (*CCACHE_SLOPPINESS*):: diff --git a/ccache.c b/ccache.c index 8b8746cac..5ed903186 100644 --- a/ccache.c +++ b/ccache.c @@ -2955,17 +2955,17 @@ cc_process_args(struct args *args, struct args **preprocessor_args, if (conf->run_second_cpp) { args_extend(*compiler_args, cpp_args); } else if (found_directives_only || found_rewrite_includes) { - // Need to pass the macros and any other preprocessor directives again + // Need to pass the macros and any other preprocessor directives again. args_extend(*compiler_args, cpp_args); if (found_directives_only) { args_add(cpp_args, "-fdirectives-only"); - // The preprocessed source code still needs some more preprocessing + // The preprocessed source code still needs some more preprocessing. args_add(*compiler_args, "-fpreprocessed"); args_add(*compiler_args, "-fdirectives-only"); } if (found_rewrite_includes) { args_add(cpp_args, "-frewrite-includes"); - // The preprocessed source code still needs some more preprocessing + // The preprocessed source code still needs some more preprocessing. args_add(*compiler_args, "-x"); args_add(*compiler_args, actual_language); } diff --git a/test/suites/cpp1.bash b/test/suites/cpp1.bash index eefa1f41d..6d07dcb02 100644 --- a/test/suites/cpp1.bash +++ b/test/suites/cpp1.bash @@ -1,12 +1,12 @@ SUITE_cpp1_PROBE() { touch test.c if $COMPILER_TYPE_GCC; then - if ! $UNCACHED_COMPILE -E -fdirectives-only test.c >/dev/null 2>&1; then + if ! $UNCACHED_COMPILE -E -fdirectives-only test.c >&/dev/null; then echo "-fdirectives-only not supported by compiler" return fi elif $COMPILER_TYPE_CLANG; then - if ! $UNCACHED_COMPILE -E -frewrite-includes test.c >/dev/null 2>&1; then + if ! $UNCACHED_COMPILE -E -frewrite-includes test.c >&/dev/null; then echo "-frewrite-includes not supported by compiler" return fi @@ -20,11 +20,11 @@ SUITE_cpp1_SETUP() { export CCACHE_NOCPP2=1 echo "#define FOO 1" >test1.h backdate test1.h - echo "#include \"test1.h\"" >test1.c - echo "#define BAR 2" >>test1.c - echo "int foo(int x) { return FOO; }" >>test1.c - echo "int bar(int x) { return BAR; }" >>test1.c - echo "int baz(int x) { return BAZ; }" >>test1.c + echo '#include "test1.h"' >test1.c + echo '#define BAR 2' >>test1.c + echo 'int foo(int x) { return FOO; }' >>test1.c + echo 'int bar(int x) { return BAR; }' >>test1.c + echo 'int baz(int x) { return BAZ; }' >>test1.c } SUITE_cpp1() { @@ -33,7 +33,7 @@ SUITE_cpp1() { elif $COMPILER_TYPE_CLANG; then cpp_flag="-frewrite-includes" fi - cpp_flag="$cpp_flag -DBAZ=3" + cpp_flag+=" -DBAZ=3" # ------------------------------------------------------------------------- TEST "Base case" -- 2.47.2