Commit Graph

21 Commits

Author SHA1 Message Date
Seth R. Johnson e4dd555000
Use python3 shebang for all python scripts
The `python` command may not exist on a system with Python 3 installed.
See https://peps.python.org/pep-0394/ for a discussion of the commands
expected to be installed.

Since Python2 was officially sunsetted almost three years ago
(https://www.python.org/doc/sunset-python-2/), IWYU should prefer
compatibility with newer systems over older ones.

Python code in scripts is still Python3/Python2-compatible, but we will no
longer make an effort to preserve Python2 support over time.

Fixes #1096.
2022-12-16 21:03:39 +01:00
Kim Gräsman 3ad4d9b058 [iwyu_tool] Exit with max exit code of IWYU invocations 2022-02-26 12:21:26 +01:00
Kim Gräsman ca9af1e643 [iwyu_tool] Duck-use python3 'getfullargspec'
Using 'inspect.getargspec' in python3 raises a deprecation warning. Prefer
the supported 'inspect.getfullargspec' if it exists.
2022-02-20 16:28:21 +01:00
Kim Gräsman ed1373bf4f [iwyu_tool] Avoid duplicate method def in test
This was most certainly accidental; a new test overwrote an existing test by
using the same name.

Name the test method correctly for better coverage.
2022-02-20 16:28:21 +01:00
Omer Anson a7499e4a2b [iwyu_tool] Notify success/failure via exit code
Modify the exit code of iwyu_tool.py so that it returns 0 only
when include-what-you-use does make any recommendations.

Related: #440
2020-12-07 07:41:37 +01:00
Florian Schmaus a8cd91a62b [iwyu_tool] remove compiler wrappers from the command list
If a compiler wrapper like ccache is used in the compile command
database, then iwyu_tool will only replace the wrapper with
IWYU_EXECUTABLE, while keeping the compiler executable in the
compile_args list. This leads to "error: no such file or directory
'c++'" warnings.

Fixes #789.
2020-05-08 19:56:33 +02:00
Kim Grasman b280c3fd6f [python] Clean up license headers
Apply all changes suggested by iwyu-check-license-header.py to get
strictly conforming license headers.
2019-12-04 21:42:46 +01:00
Kim Grasman 592c21ae3d Make path test independent of host filesystem
FreeBSD has /home linked to /usr/home, so the realpath call in
fixup_compilation_db actually resolved the bogus path to
/usr/home/foobar/Test.cpp and failed the test.

Generate an artifical root dir with uuidgen to reduce/eliminate the risk
of this happening elsewhere.
2019-10-24 21:44:21 +02:00
Kim Grasman 6c5d00886f Reflow long comment in test 2019-10-24 21:43:45 +02:00
Miklos Vajna 38dba88261 [iwyu_tool] Use directory from compilation database if availabl
If the entry looks like this:

    {
        "arguments": [
            ....
        ],
        "directory": "/path/to/test",
        "file": "Test.cpp"
    },

And we invoked iwyu_tool.py in /path/to, then the constructed abs path was
/path/to/Test.cpp, not /path/to/test/Test.cpp, fix this.
2019-10-06 10:46:19 +02:00
Kim Grasman 3776ea410e [iwyu_tool] Add test for compilation db path canonicalization
This drove out a refactor to read the file separately from
canonicalization for easier testing.
2019-09-30 21:58:01 +02:00
Asier Lacasta cd358ea9cf [iwyu_tool] Use extra args verbatim
This is a breaking change.

Originally, the extra arguments after '--' were only intended for IWYU
args, and so '-Xiwyu' was automatically prepended to each of them to
make life easier on users.

But this made it impossible to add additional Clang args, which is also
a useful feature.

The extra arguments are now forwarded as-written to main and users need
to manually add '-Xiwyu' before every IWYU argument.
2019-01-04 23:12:09 +01:00
Kim Grasman 0e03ac1969 [iwyu_tool] Rename iwyu_args -> extra_args
No functional change.
2019-01-04 23:12:09 +01:00
Kim Grasman 6f8c0020f0 [iwyu_tool] Fold consecutive whitespace in command strings
Fix bug where every additional whitespace character would turn into an
empty argument in argument list.
2018-12-22 19:31:55 +01:00
Kim Grasman 1a9eaf13c5 [iwyu_tool] Model blocking more faithfully in tests
No functional change, but the test suite is twice as fast.
2018-12-12 21:50:19 +01:00
Kim Grasman 1d4f2673ce [iwyu_tool] Fix command splitting for Windows
shlex.split does not do the right thing on Windows, not even with the
posix=False flag set.

Work around this with a hand-built win_split function, based on the
more or less official specification:
https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.140)

Add tests.

No behavior change for non-Windows systems.

Fixes #583.
2018-12-11 22:10:57 +01:00
Kim Grasman 8e2b4455f1 [iwyu_tool] Improve MSVC-style driver detection
Match cl.exe without case on Windows to allow for e.g. CL.EXE.

Also match 'clang-cl', which could presumably be used as a cross-tool on
non-Windows systems.

Add tests.
2018-12-11 21:56:39 +01:00
Kim Grasman a7b16c0a88 [iwyu_tool] Case-insensitive path match on Windows
User-provided paths are now matched case-insensitively.

Also fix a bug where /a/b/partial would match partial filenames. The new
implementation is stricter and only matches proper directory prefixes or
the full path name.

Closes bug #582.
2018-12-09 21:02:16 +01:00
Kim Grasman b7438423be [iwyu_tool] Style cleanup
- Two blank lines between module-level entities.
- Imports after doc comment
- Naming in execute
- Collapse IWYUToolTestBase into IWYUToolTests

No functional change.
2018-12-09 19:19:15 +01:00
Philip Pfaffe dbab920114 [iwyu_tool] Drop multiprocessing
Python's multiprocessing module is convenient for task parallelization,
but it is rather weak when it comes to error reporting and handling
KeyboardInterrupt. It was basically impossible to interrupt iwyu_tool
with Ctrl+C.

Also, it seems silly to launch a process just to launch a process --
iwyu_tool.py basically just manages include-what-you-use child
processes.

Remove the use of multiprocessing and handle process scheduling
ourselves.
2018-09-29 15:35:53 +02:00
Philip Pfaffe 2e1e0e16db [iwyu_tool] Refactor for testability and add unit test
- Add execute function to run all invocations (asynchronously)
- Move process invocation to Invocation.run
- Make Invocation.from_compile_command a class method to make it easier
  to stub Invocation.run when under test.

With this in place, add basic test cases for compile command parsing and
execution.
2018-09-08 11:46:53 +02:00