42 Commits

Author SHA1 Message Date
Jan Niklas Hasse
ce60eb1bce Merge pull request #2774 from jhasse/status-description
Allow to change order of description in --status
2026-06-29 19:27:41 +02:00
Orgad Shaneh
d128826522 Tests: Use context manager for Popen
ResourceWarning: unclosed file <_io.BufferedReader name=3>
2026-06-14 14:45:11 +03:00
Jan Niklas Hasse
23a6827a45 Allow to change order of description in --status
Replacement for #1045.
2026-05-13 22:16:26 +02:00
Jan Niklas Hasse
2a8ddccd35 Merge pull request #2772 from jhasse/status-cmd-line
Add --status flag with Ninja-style variable expansion
2026-05-13 22:12:35 +02:00
Jan Niklas Hasse
0f55557728 Add --status flag with Ninja-style variable expansion
Introduces a `--status FMT` command-line flag that configures the
progress status using Ninja's regular `$var`/`${var}` syntax with
descriptive variable names ($finished, $total, $progress, $elapsed,
etc.) instead of the `%`-escapes used by `NINJA_STATUS`. When passed,
it takes precedence over `NINJA_STATUS`; the env-var path is left
unchanged for backwards compatibility.
2026-05-13 21:06:00 +02:00
Jan Niklas Hasse
28d5408982 Make test_issue_2621 resistence against different ordering
See #2621.
2026-05-09 22:00:37 +02:00
Brad King
bbde7f3d77 Restore "explain" output when a dyndep file is loaded
Since commit 8e6c741a4b ("explain" debug prints just before each command
is run, 2022-01-06, v1.13.0~1^2~56^2~2) the "loading dyndep file '...'"
explanation has not been printed.  Instead the explanation has been
recorded for the dyndep file's node *after* it has been brought
up-to-date, and therefore never printed.

This explanation is generated just before its operation runs, so we can
print it immediately instead of buffering it.

Fixes: #2758
2026-04-03 09:17:16 -04:00
Brad King
b7bbeec9ae Add test for ninja -d explain with dyndep
This was regressed by commit 8e6c741a4b ("explain" debug prints just
before each command is run, 2022-01-06, v1.13.0~1^2~56^2~2).  Add a
test demonstrating the problems, called out by FIXME comments.

Issue: #2758, #2759
2026-04-03 09:17:16 -04:00
Jan Niklas Hasse
3cd2f23945 Merge pull request #2673 from dblsaiko/push-mlnkxqoqmvru
Print an entry in the compilation database for each input file
2026-01-14 01:16:20 +01:00
David 'Digit' Turner
cc0b6ffada Fix Ninja exit code when interrupted.
This fixes ##2681, a regression that was introduced during PR #2540
where Ninja would return a status code of 0 when interrupted.

The problem comes from RealCommandRunner::WaitForCommand() not
updating the result->status field in case of interrupt being
detected in Subprocess::DoWork().

This fixes the issue and adds a regression test for it.

+ Fix the CommandRunner::Result constructor to ensure that
  the `status` field is always initialized, even though it
  should now always be replaced at the end of a command.
2025-11-06 14:39:25 +01:00
Katalin Rebhan
3eeda8fda6 Print an entry in the compilation database for each input file
Targets which use multiple input files only have their first input
file show up in the compilation database. This can cause issues with
tools that build a list of files to inspect from the compilation
database. For example, when using the Swift programming language
together with the SourceKit-LSP language server, only one source file
from each Swift module gets processed correctly by the language server
using the current compilation database output from Ninja, because Swift
modules are compiled with one compiler invocation and therefore one
Ninja target for the whole module.

This changes the compilation database formatter to emit one entry
for each input file of a target instead of just the first input
file, which makes tools able to pick up all the input files used in
the build.

Fixes #1590.
See also https://github.com/mesonbuild/meson/pull/14264.
2025-10-10 11:19:22 +02:00
Jan Niklas Hasse
516a0ddcc4 Add output test for multiple rules + dyndep, fix #2621 2025-07-10 22:32:03 +02:00
Jan Niklas Hasse
89af474419 Add test for multiple console jobs, see #2586 2025-04-12 10:49:18 +02:00
Mikhail f. Shiryaev
9e34d733ec Add tests for pr 2540, improve _test_expected_error 2024-12-30 14:49:06 +01:00
Fredrik Andersson
beabef0987 Add multi-inputs tool
The 'multi-inputs' option will list all <target> + <inputs> for
the given targets.

Run:
ninja -t multi-inputs <target1> <target2> <target3>

Ninja will then output:
<target1> <input_x>
<target1> <input_y>
<target2> <input_x>
<target2> <input_z>
<target3> <input_y>
2024-11-22 13:28:14 +01:00
James Widman
4e4ec4c8ab Introduce new tool: -t compdb-targets
Fixes #1544

Co-authored-by: Linkun Chen <lkchen@google.com>
Co-authored-by: csmoe <csmoe@msn.com>
Co-authored-by: James Widman <james.widman@gmail.com>
2024-10-13 01:31:01 -07:00
David 'Digit' Turner
562cee194c Fix #2499: Status update regression.
PR #2487 introduced a regression, where a completed command without
an output would force a newline, preventing the next status update
to appear on the same line in smart terminals.

This fixes the issue by adding the missing `!outputs.empty()`
condition + adding a proper regression test to catch future
breaks.

Fixed: #2499
2024-09-30 09:24:55 +00:00
Jan Niklas Hasse
41ecb09d36 Merge pull request #2485 from digit-google/fix-inputs-tool
Fix `inputs` tool logic and add new formatting options.
2024-09-19 08:11:23 +02:00
David 'Digit' Turner
2c13023b7e Ensure depfile's parent directory is created before running an action.
For most actions, the depfile will be in the same directory as one
of its outputs, and their  parent directory will be created by Ninja
before running the command. However, this is not always the case.

In particular, the GN build tool is changing its Ninja build plan
generation logic, switching from using stamp files to phony targets,
after issue #478 was fixed in Ninja. For additionnal context
see https://gn-review.googlesource.com/c/gn/+/11380.

The newly generated build plans trigger this condition more frequently,
which results in flaky build failures for large GN-based projects such
as Fuchsia.

This patch ensures the depfile's parent directory is always created
before the command is launched to get rid of the issue entirely.
2024-09-04 12:19:31 +02:00
David 'Digit' Turner
284349311d Add new options to inputs tool.
Add new options to the `inputs` tool in order to change
the format of its output:

- `--no-shell-escape` to avoid shell-escaping the results.

- `--dependency-order` to return results in dependency order,
  instead of sorting them alphabetically.

- `--print0` to use \0 as the list separator in the list,
  useful to process the target paths with `xargs -0` and
  similar tools.
2024-09-02 17:23:05 +02:00
David 'Digit' Turner
5b94d3407f Fix inputs tool implementation.
This uses the InputsCollector class introduced in the
previous patch to implement the tool properly. Results
are still shell-escaped and sorted alphabetically.

Fixed #2482
2024-09-02 17:23:05 +02:00
David Röthlisberger
808fab6cd5 Add test for "-d explain" output
Before #2067, ninja would have printed this instead for the second
`ninja` invocation:

    ninja explain: output .FORCE of phony edge with no inputs doesn't exist
    ninja explain: .FORCE is dirty
    ninja explain: input is dirty
    ninja explain: mid is dirty
    [1/3] [ -e input ] || touch input
2024-05-08 13:44:50 +01:00
David Röthlisberger
37e0870c1c misc/output_test.py: Refactor to allow calling ninja multiple times
So that we're able to test *re* running ninja to test the output of
no-op builds etc.

I'll use this in the next commit to test "-d explain" output.
2024-05-08 13:44:50 +01:00
Thaddeus Crews
977096ad4a Implement type hints in remaining python files 2024-04-09 13:12:05 -05:00
von Heydebrand Julian
878aa468d1 Gracefully handle outdated .ninja_log during '-t recompact'
When we explicitly unlink the file we should return LOAD_NOT_FOUND instead of LOAD_SUCCESS
2024-03-21 09:17:28 +01:00
David 'Digit' Turner
58851eb9eb Minor fix to output_test.py
Do not use os.chdir() to change the current directory inside
the run() function, as doing this prevents the temporary directory
from being removed.

Moreover, this breaks pytest invocations when adding new regression
test scripts in this directory (as done in other forks).

+ Use dict.pop() to undefine environment variables in `default_env`
  dictionary.
2024-03-14 15:32:48 +01:00
Tamino Bauknecht
1111da82ee Add output_test assertion for quiet without 'no work to do' 2023-10-24 18:34:40 +02:00
David 'Digit' Turner
5f8a1fcd33 Allow duplicate rule variable usage.
This fixes #1966 by removing the variable name from the
lookups stack once the recursive lookup call has been performed.
Without this, any previously expanded variable could no longer
be referenced in the command, as Ninja would (incorrectly)
complain about a cyclical dependency.
2023-04-27 18:33:59 +02:00
David 'Digit' Turner
988c847ee7 Make the output of ninja -t inputs deterministic
This sorts the output of `ninja -t inputs` to make it
deterministic and remove duplicates, and adds a regression
test in output_test.py

+ Ensure all inputs are listed, not only explicit ones.
+ Document the `inputs` tool in doc/manual.asciidoc.
2022-03-21 14:44:26 +01:00
Jan Niklas Hasse
cd967ab21e Make output_test.py executable again (mistake thanks to WSL) 2021-06-10 21:30:10 +02:00
Jan Niklas Hasse
0843ae8746 Put Info output back on stdout instead of stderr
See comment in #1899. Also adds two tests to output_test.py which check
this behaviour by relying on Python's suprocess.check_output not piping
stderr.
2021-06-10 21:25:45 +02:00
Eli Ribble
f926cd4503 Add test for status suppression under '--quiet'.
This just tests that the flag works.
2021-05-06 09:31:11 -07:00
Michael Hirsch, Ph.D
e44fcbede9 test: skip non-Windows tests if on Windows 2020-04-27 11:39:48 -04:00
Jan Niklas Hasse
112217185e Add output test for 'no work to do.' 2020-04-24 12:58:20 +02:00
Jan Niklas Hasse
791c887e22 Ignore nonexistent .ninja_log/.ninja_deps for restat and recompact 2019-12-23 14:11:09 +01:00
Jan Niklas Hasse
a67718de4e Run output test in temporary directory 2019-12-23 14:08:59 +01:00
Bernhard M. Wiedemann
07b1cf264a Fix test_issue_1418 to pass on 1-core VM
the previous assert would fail because on a 1-core VM, the 3 outputs
were produced sequentially from top to bottom
2019-09-20 15:48:36 +02:00
Takuto Ikuta
5a78423193 Add OSX build on travis (#1502)
Also make test script works for OSX script command.
2018-11-17 18:23:28 +01:00
Jan Niklas Hasse
bf7107bb86 Allow disabling of escape code stripping, fix #1475
Don't strip colors when CLICOLOR_FORCE is set to a non-zero value. This
environment variable is also used by CMake's Make back-end.
2018-11-13 15:15:43 +01:00
Jan Niklas Hasse
44ed3743af Make output_test.py independent of the environment 2018-11-07 18:20:07 +01:00
Jan Niklas Hasse
3841023a44 Add test for #1418 (edge output should match status) 2018-11-05 18:52:51 +01:00
Jan Niklas Hasse
775c8e89ef Add script to test Ninja's output
First test checks for #1214.
2018-11-05 18:42:31 +01:00