Reputation: 107
I have a bash script to run my Makefile-based project through Include-What-You-Use (IWYU) which looks as follows:
#!/bin/bash
export MAKEFLAGS="-k CXX=iwyu -Xiwyu --transitive_includes_only -Xiwyu --mapping_file=qt5_4.imp"
build.sh
The build.sh
script sets a couple of environment variables, prepares other parts of the build environment and will then eventually run make
.
At first sight this seems to work and do its job. However closer inspection showed, that only CXX=iwyu
is actually used in the build. The command line options for IWYU get dropped.
I tried various modifications of my call to fix this, however none seemed to solve the problem.
With
export MAKEFLAGS="-k CXX=iwyu\ -Xiwyu\ --transitive_includes_only\ -Xiwyu\ --mapping_file=qt5_4.imp"
the command line options are no longer dropped, but now suddenly -k
seems to get dropped somewhere and my build (because of the missing -k
) is terminated early with failure.
With
export MAKEFLAGS="-k CXX='iwyu -Xiwyu --transitive_includes_only -Xiwyu --mapping_file=qt5_4.imp'"
I'm flooded with /bin/sh: 1: Syntax error: Unterminated quoted string
which looks like the ending '
is somehow dropped.
Are there any other ways I have to escape and/or quote the spaces in my export
to fix this?
Upvotes: 2
Views: 558
Reputation: 754550
You can create a script (once?) to run iwyu
— be careful, single quotes and double quotes are not interchangeable:
echo 'iwyu -Xiwyu --transitive_includes_only -Xiwyu --mapping_file=qt5_4.imp "$@"' > ./run.iwyu
chmod +x ./run.iwyu
and then run:
make -k CXX="$PWD/run.iwyu"
or:
export MAKEFLAGS="-k CXX=$PWD/run.iwyu"
This sidesteps the whole problem of spaces in the arguments. As shown, you specify the full path for the run.iwyu
script just in case your make
process changes directories. If you put the run.iwyu
script in a directory on your PATH
, you don't need to specify the full path to the script. You could prefix the command line in the script with exec
if you like.
Upvotes: 3