From f69a53d0b83f6b6448aeacb98442b90e938696f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 29 May 2017 14:05:21 +0200 Subject: Add ability to limit amount of preprocessing done on source The cc.preprocessed variable can be 'none' (not preprocessed), 'includes' (no depends on preprocessor, e.g., #ifdef, etc), and 'all' (the source is fully preprocessed). Note that for 'all' the source can still contain comments and line continuations. --- tests/cc/preprocessed/buildfile | 8 +++ tests/cc/preprocessed/testscript | 125 +++++++++++++++++++++++++++++++++++++++ tests/common.test | 21 +++++++ 3 files changed, 154 insertions(+) create mode 100644 tests/cc/preprocessed/buildfile create mode 100644 tests/cc/preprocessed/testscript (limited to 'tests') diff --git a/tests/cc/preprocessed/buildfile b/tests/cc/preprocessed/buildfile new file mode 100644 index 0000000..d812867 --- /dev/null +++ b/tests/cc/preprocessed/buildfile @@ -0,0 +1,8 @@ +# file : tests/cc/preprocessed/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Test cc.preprocessed logic. +# + +./: test{testscript} $b diff --git a/tests/cc/preprocessed/testscript b/tests/cc/preprocessed/testscript new file mode 100644 index 0000000..cbc179e --- /dev/null +++ b/tests/cc/preprocessed/testscript @@ -0,0 +1,125 @@ +# file : tests/cc/preprocessed/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +crosstest = false +test.arguments = config.cxx="$recall($cxx.path)" update clean #@@ TMP clean + +.include ../../common.test + +# Trace filter. +# +# trace: cxx::compile::extract_(header|modules): target: .../obje{(test).o...} +# +filter = sed -n -e \ + \''s/^trace: cxx::compile::extract_([^:]+): target:[^{]+\{([^.]+).*/\1 \2/p'\' + ++cat <=build/root.build +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +cxx{*}: extension = cxx + +cxx.poptions =+ "-I$src_root" +EOI + +: none +: +: Include a header (makes sure headers are handled) which defines the +: TEST_VALUE macro. Import a non-existent module unless this macro is +: defined (makes sure modules are extracted from preprocessed source). +: Use the macro (makes sure compilation happens on preprocessed source). +: +cat <=test.hxx; + #define TEST_VALUE 0 + EOI +cat <=test.cxx; + #include + + #ifndef TEST_VALUE + import foo; + #endif + + int main () {return TEST_VALUE;} + EOI +$* --verbose 5 <&1 | $filter >>EOO #@@ &test* + exe{test}: cxx{test} + EOI + headers test + modules test + EOO + +: includes +: +cat <=test.cxx; + #ifndef TEST_VALUE + import foo; + #endif + + int main () {return TEST_VALUE;} + EOI +$* --verbose 5 <&1 | $filter >>EOO #@@ &test* + cc.preprocessed = includes + cc.poptions += -DTEST_VALUE=0 + exe{test}: cxx{test} + EOI + modules test + EOO + +: modules +: +: Define and use macro to test that compilation inclused the preprocessor. +: +cat <=test.cxx; + int main () {return TEST_VALUE;} + EOI +$* --verbose 5 <&1 | $filter >>EOO #@@ &test* + cc.preprocessed = modules + cc.poptions += -DTEST_VALUE=0 + exe{test}: cxx{test} + EOI + modules test + EOO + +: modules-extract +: +: Define macro that would have disabled the module import (makes sure +: modules are extracted directly from source). +: +cat <=test.cxx; + #define TEST_VALUE + #ifndef TEST_VALUE + import foo; + #endif + EOI +$* <>EOE != 0 ;#@@ &test* + cc.preprocessed = modules + exe{test}: cxx{test} + EOI + error: module support not yet implemented + EOE +rm -f test.o.d test.exe.obj.d #@@ TMP + +: all +: +: Test handling of comments and line continuations. Define macro on the +: command line that would have affected the result. +: +cat <=test.cxx; + // C++ comment + /* + C comment + */ + + int ma\ + in () {} + EOI +$* --verbose 5 <&1 | $filter >>EOO #@@ &test* + cc.preprocessed = all + cc.poptions += -Dmain=foo + exe{test}: cxx{test} + EOI + modules test + EOO diff --git a/tests/common.test b/tests/common.test index b8d6148..0e8ce52 100644 --- a/tests/common.test +++ b/tests/common.test @@ -5,6 +5,27 @@ # Commonly-used build system test project setup and driver command line. # +# If the includer indicated that no cross-testing should be supported, then +# use the build system driver that is building, not the one being built. +# +# In many cases expecting a cross-compiled driver to perform a native build +# under emulation is pushing things a bit too far. Plus, we have no way of +# knowing the native compiler name/path. +# +# So the idea here is to test cross-compilation with the understanding that +# the build system driver we are testing is not the one being cross-compiled +# but rather the one doing the cross-compilation. +# +if ($null($crosstest)) + crosstest = false +end + +if (!$crosstest && $test.target != $build.host) + test = $recall($build.path) +end + +# Common bootstrap.build. +# +mkdir build +cat <=build/bootstrap.build project = test -- cgit v1.1