215 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
Jan Niklas Hasse
a830ae5b15 Merge pull request #2726 from jamesl-10/ninja-parallelism
Make full use of parallelism in jobserver mode
2026-04-28 07:51:10 +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
jamesl-10
1a7da2b33a Added regression test for jobserver token availability 2026-03-16 21:02:25 -04:00
haosenwang1018
e7fcd46340 fix: replace 2 bare except clauses with except Exception 2026-02-26 05:33:09 +00: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
David 'Digit' Turner
d4a4f3694c Support jobserver client mode automatically.
Detect that the environment variable MAKEFLAGS specifies a
jobserver pool to use, and automatically use it to control
build parallelism when this is the case.

NOTE: On Posix, the pipe-based protocol is not supported and
will be detected. Ninja will print a warning on startup then
ignore the content of MAKEFLAGS (there is a regression test
for this).

This is disabled is `--dry-run` or an explicit `-j<COUNT>`
is passed on the command-line. Note that the `-l` option
used to limit dispatch based on the overall load factor
will still be in effect if used.

+ Use default member initialization for BuildConfig struct.

+ Add a new regression test suite that uses the
  misc/jobserver_pool.py script that was introduced in
  a previous commit, to verify that everything works
  properly.
2025-04-22 14:14:45 +02:00
David 'Digit' Turner
6adbd5cbda Add misc/jobserver_pool.py
This implements a GNU jobserver token pool that will be used
for testing the upcoming jobserver Ninja client implementation.

Note that the implementation is basic and doesn't try to deal
with broken protocol clients (which release more tokens than
they acquired). Supporting them would require something vastly
more complex that would monitor the state of the pipe/fifo
at all times.
2025-04-22 14:14:44 +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
Jan Niklas Hasse
a3fda2b06c Merge pull request #2497 from JamesWidman/compdb-target
Introduce a new tool: `ninja -t compdb-targets`
2024-11-12 17:25:13 +01:00
Jan Niklas Hasse
23350f1cc7 Move Emacs file to https://github.com/ninja-build/ninja-emacs, see #2213 2024-11-11 21:26:20 +01:00
musvaage
37a97ea89b end-of-line, comment, and point-max 2024-10-30 15:25:47 -05: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
Peter Oliver
7744530eaf Add Emacs package attributes, “Keywords” and “URL” 2024-05-20 16:54:52 +01: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
Jan Niklas Hasse
210e6f2e58 GitHub Actions doesn't seem to have a valid Git repo, fallback to hard-coded ignore list 2024-04-27 17:47:24 +02:00
Jan Niklas Hasse
f5b04af0d4 misc/ci.py: To make local dev easier, ignore files from .gitignore 2024-04-27 17:30:47 +02:00
Jan Niklas Hasse
b914a67b7c Remove trailing whitespace 2024-04-27 15:49:40 +02:00
Thaddeus Crews
977096ad4a Implement type hints in remaining python files 2024-04-09 13:12:05 -05:00
Thaddeus Crews
9cabe6a3f3 Implement type hints in ninja_syntax.py 2024-04-06 12:31:52 -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
Konstantin Kharlamov
74642c5a6f ninja-mode.el: add support for indentation
We default `ninja-indent-offset` to `2` because Meson and CMake use `1`
and `2` values accordingly, but `1` seems like too little, so use `2`.

The correctness was tested in particular on two `build.ninja` files,
one generated by Meson (1790 lines), and another by CMake (7777
lines). After setting `ninja-indent-offset` to the expected by the
file value and re-indenting whole file the buffer was left unchanged,
i.e. the calculated offset matched the ones already used.
2023-03-28 18:52:26 +03:00
Konstantin Kharlamov
da6645e7d7 ninja-mode.el: fix variables highlighting
The code previously did not take into account that between the name
and assignment may be any number of space including no space at all.

It was also incorrectly highlighting in a code like

   foo = bar = buzz

the `bar` as a variable, even though the `bar = buzz` is just a text
that gets assigned to `foo`, i.e. `bar` is not a variable. Fix that.
2023-03-28 18:46:05 +03:00
Nico Weber
6a17e84370 Use python3 in all run lines
We already did this in some, this converts the rest.
Also chmod +x on write_fake_manifests.py while here.
2023-01-10 10:46:45 -05:00
Paul Seyfert
184bfeb5cc Add --quiet flag to zsh completion 2022-09-04 11:35:49 +02:00
Eisuke Kawashima
c136c2e1df improve zsh-completion
- add `ninja` prefix to functions
- improve completion of `-d` and `-t`
- stop completion if `-h`, `--help`, or `--version` is supplied
- add missing `--verbose` options
2022-06-13 14:43:33 +09: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
Christian Clauss
2dab655765 xrange() was removed in Python 3 in favor of range() (#2036)
https://portingguide.readthedocs.io
2021-11-11 09:53:53 +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