From 62e5e2e35380e46ccbff2c2ed118f8bb5c01755b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 29 Apr 2023 16:06:52 +0200 Subject: [PATCH] iwyu_test_util: add support for EXTRA_IWYU_ARGS env variable When running the tests as part of Gentoo's emerge process (in src_test()) the tests fail due clang's include directory missing. The emerge phase that runs the tests is performed with the application under test still in the build directory. And this is what breaks the IWYU tests there. The include-what-you-use binary seems to have, amongst other, the following default include path (as per "include-what-you-use-0.19_build/bin/include-what-you-use -E -x c++ - -v < /dev/null"): ignoring nonexistent directory "/var/tmp/portage/dev-util/include-what-you-use-0.19/work/include-what-you-use-0.19_build/bin/../../../../lib/clang/15.0.7/include" Here, /var/tmp/portage/dev-util/include-what-you-use-0.19/work/include-what-you-use-0.19_build/ is the build directory. Unfortunately, the whole path to the clang include is invalid (non-existent). It will become correct once IWYU is merged into the live filesystem. As workaround I added EXTRA_IWYU_ARGS to the run_iwyu_tests.py script, to be able to provide the correct include path by invoking run_iwyu_test.py basically like: EXTRA_IWYU_ARGS="-I /usr/lib/clang/15.0.7/include" \ run_iwyu_tests.py \ -- ${BUILD_DIR}/bin/include-what-you-use Related Gentoo bug: https://bugs.gentoo.org/905214 --- iwyu_test_util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iwyu_test_util.py b/iwyu_test_util.py index d748cf2e..9223d904 100755 --- a/iwyu_test_util.py +++ b/iwyu_test_util.py @@ -439,8 +439,14 @@ def TestIwyuOnRelativeFile(cc_file, cpp_files_to_check, verbose=False): if env_verbose_level: verbosity_flags = ['-Xiwyu', '--verbose=' + env_verbose_level] + iwyu_command = _ShellQuote(_GetIwyuPath()) + + env_extra_iwyu_args = os.getenv('EXTRA_IWYU_ARGS') + if env_extra_iwyu_args: + iwyu_command += f" {env_extra_iwyu_args}" + cmd = '%s %s %s %s %s' % ( - _ShellQuote(_GetIwyuPath()), + iwyu_command, # Require verbose level 3 so that we can verify the individual diagnostics. # We allow the level to be overriden by # * IWYU_ARGS comment in a test file;