summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
6 daysMerge changes I3ced97c9,I68a8649e,I5e7c195e,I79432cda,I2dd9e5da into mainmainCole Faust
* changes: lstat generated files Shell-escape $in and $out Disallow missing depfiles Implement --frontend-file Add multithreaded parsing
12 daysIncrease the sleep before/after running commandsCole Faust
Adding this sleep did seem to drastically reduce the flakiness, but we recently got another flake. Increase the length of the sleep to hopefully hammer out the last bit of flakeyness. Test: Cargo test Change-Id: I3b0ef31efc92357f90e49d04876f17397fa507e5
2024-05-13lstat generated filesCole Faust
This is to match a patch that we added to the android fork of ninja, where generated files are lstat'd instead of stat'd. Without this, n2 always reruns rules that generate dangling symlinks, because it thinks those files don't exist. Bug: 318434287 Test: Manually Change-Id: I3ced97c9195adb3b8d94e3103940f197097c278c
2024-05-10Shell-escape $in and $outCole Faust
Excape in cases where they need to be read by n2 directly. E.g. `rspfile = $in` is not escaped because n2 will just open the file directly, but `rspfile_content = $in` will be escaped because rspfiles are often treated as command line arguments. Bug: 318434287 Test: cargo test Change-Id: I68a8649eabbf3b0ca459e0cac28160a834eebd62
2024-05-10Disallow missing depfilesCole Faust
We always run ninja with -w missingdepfile=err. N2 doesn't have that flag, but we can just make it always enforce that dep files exist. Bug: 318434287 Test: cargo test Change-Id: I5e7c195efca6779db631e65017f14a10d3f48d15
2024-05-10Implement --frontend-fileCole Faust
This is what soong uses to take control of ninja's output. Ninja will just be quiet but write protobuf-encoded status messages to a file that soong_ui reads. Not all fields of the protobuf are implemented in this cl, but it's enough to display a functional UI in an android build. Missing things include: - A bunch of fields related to how much time/memory an action took - A critical path time estimate used in displaying an ETA, but that requires the infrastructure about the time of prior builds used to schedule slower actions with higher priority in regular ninja - The inputs that changed that caused an action to rerun, used in some telemetry Bug: 318434287 Test: cargo test Change-Id: I79432cdab965ff5fc7e0d5b42c645488b2e9093b
2024-05-07Loosen bound on mtime diff in stat_mtime_resolutionCole Faust
This check seems to flake sometimes, make it more lenient. Bug: 318434287 Test: cargo test Change-Id: I21c46360ae60c9f1a1e0ba488f5f674bc4691615
2024-05-02Add multithreaded parsingCole Faust
This PR ports over most of the enhancements that are in Android's fork of ninja to n2. N2 goes from taking ~16 seconds to parse the AOSP ninja files, to ~1 second. (at least on my work computer where available_parallelism returns 128) It still seems to be about ~0.1 seconds slower than the android fork of ninja, but it's at least in the range where it's a little difficult to measure. A general list of the changes in this PR: - Add support for subninja, with scoped variables. - mmap input files instead of reading them into memory. - Remove the FileIds and the Vec of files, replacing them with Arc. Having to maintain a separate vec mapping FileIds to files is too expensive. - Use the DashMap crate to map from filename to File object, so that id_from_canonical can be called in parallel. - Use rayon for multithreading. - Split input files into chunks and parse the chunks in parallel - Parse subninjas in parallel. Subninja support was implemented because regular includes cannot be processed in parallel. - Revamp the evaluation of variable assignments. Now, every statement in the ninja file gets a "scope position". When evaluating global variables, they are evaluated relative to a certain scope position, so you can evaluate the variable at a particular point in the file, even if it is reassigned later. - Introduce "clumps" of parse results, as returning all the parsed statements in a flat vector causes too many large vector concatenations. - Box Build objects, as they are quite large, and Vecs of unboxed builds are too large and slow to concatenate. - Don't evaluate all the build bindings at load time. Only evaluate the input/output files, and defer evaluation of other bindings until the build is actually run. - Evalstrings are now just regular strings instead of Vecs of strings. This means when they're evaluated they're re-parsed. Doing it this way saves of the Vec allocations, and in the case of owned evalstrings, does one big string allocation instead of a bunch of little ones. There are a lot more owned evalstrings now due to deferred evaluation of build bindings, so it makes a bit of a difference. One thing that the android fork has that I didn't include was precomputed hashes. The android fork has a HashedString and HashedStrView type that it uses to ensure hashes aren't recalculated. This is somewhat difficult to do in rust, you have to either make concessions about being able to look up map values by their borrowed representation, use the raw entry map apis on nightly rust, or use hashbrown's RawTable. And even when I was experimenting with RawTable it didn't seem to provide a noticeable speedup. Some of these optimizations are memory optimizations. This turned out to be necessary because apparently the exit_group syscall that quits the process spends time cleaning up memory. The exit_group syscall was taking over a second to run before some of these optimizations. Bug: 318434287 Test: OUT_DIR=out prebuilts/build-tools/build-prebuilts.sh Change-Id: I2dd9e5dae37c2904ecf01db2cd771857e5f7aae8
2024-05-02Attempt to fix test flakesCole Faust
Sleep before/after running n2, because it seems like occasionally n2 is not seeing updating timestamps. Maybe the tests run too quickly and the timestamps are the same? Bug: 338259955 Test: Presubmits Change-Id: Ib695815317499c95514ccf0653c55ed19e2fbb96
2024-05-01Disable dep_on_current_directory testCole Faust
This test is flakey, disable it until we can do a proper fix. Bug: 338259955 Test: Presubmits Change-Id: I8218fb08524f17c2332738e353da2a744e08f762
2024-04-30Add build rules for n2 testsCole Faust
Bug: 318434287 Test: OUT_DIR=out prebuilts/build-tools/build-prebuilts.sh Change-Id: I8cad9c5951d71b719e5a87907a5099be4b73468b
2024-03-28Merge remote-tracking branch 'origin/upstream'Inna Palant
Import b/328273370
2024-03-21Import n2 to androidupstreamCole Faust
Test: m n2 Third-Party Import of: https://github.com/evmar/n2 Request Document: go/android3p For CL Reviewers: go/android3p#reviewing-a-cl For Build Team: go/ab-third-party-imports Bug: http://b/328273370 Original import of the code can be found at: https://googleplex-android.googlesource.com/platform/external/n2/+/refs/heads/third-party-review. Security Questionnaire: http://b/328273370#comment1 Change-Id: Iab199b146d606cb1e8212f5c38d8612a5845b6bf
2024-03-13Initial empty repositoryrassb@google.com
2024-03-05Parse depfiles with multiple targetsCole Faust
This is needed for android. It just treats all the deps of all targets in the depfile as deps for the Build. In task.rs there is a TODO to verify that the targets refer to the outputs of the Build, but adding that verification breaks the android build. In android's case, there are some depfiles that contain `foo.o: path/to/some/dep.asm` where it should instead be `path/to/foo.o: path/to/some/dep.asm`.
2024-01-25Switch some HashMaps to FxHashMapsCole Faust
FxHashMap has a faster hashing algorithm, at the expense of not being resistent to DOS attacks.
2024-01-25Only hash strings once in id_from_canonicalCole Faust
Use HashMap.entry() instead of a lookup + insert.
2024-01-25Precalcuate length of evaluated stringsCole Faust
So that we can do one memory allocation for them.
2024-01-25Pass owned paths to id_from_canonicalCole Faust
id_from_canonical ideally takes owned strings instead of references to avoid a copy.
2024-01-19avoid clown shoes allocation of input filesEvan Martin
Scanner expects its input to be nul terminated, which I implemented as buf = std::fs::read(file) buf.push(0) However, std::fs::read carefully sizes its buffer to be exactly the file's size, which means the push() must grow the buffer. This means for e.g. a 40mb input file, we'd read it into a 40mb buffer, then grow the buffer, copying it into an 80mb buffer, just to add one byte! Fix this by using a buffer of the appropriate size. I attempted to measure the perf impact here and it wasn't measureable. Possibly this buffer growth really is that fast? It seems it will at least have memory impact at least.
2024-01-18Evaluate build paths in the context of the build's bindingsCole Faust
This fixes an incompatibility with ninja. I've also moved a bunch of variable evaluations out of the parser and into the loader, in preparation for parsing the build file in multiple threads, and then only doing the evaluations after all the chunks of the file have been parsed. Fixes #91 and #39.
2024-01-18Add benchmark test for the loaderCole Faust
I'm making some changes that affect the performance of the parser and the loader, and would like to benchmark them together. Unfortunately this required making a bunch of things public (#[cfg(test)] doesn't seem to apply for benchmarks), which isn't great.
2024-01-18Enforce only valid rule variables are usedCole Faust
Regular ninja also has this validation.
2024-01-10drop git lfsEvan Martin
It's a needless burden for people who don't care about this snapshot. I switched to Google Drive for now, shruggie. Fixes #105.
2024-01-08Wait for out instead of regular_inputCole Faust
The test is supposed to ensure that out builds before validation_input.
2024-01-08improve test for validation execution orderEvan Martin
The test wanted to verify that in a file containing build foo: ... |@ bar it's possible for foo to finish before bar does. This changes to the test to make the bar step wait (at runtime) for the foo step to finish, enforcing that that ordering is possible. Fixes #102.
2024-01-08stat outputs of phony rulesEvan Martin
CMake has files that are outputs of a phony rule but still used as inputs. build ...: ... some_file build some_file: phony ... Before this change, n2 would just mark all phony outputs as missing, which breaks the above. This change instead makes phony a little closer to how non-phony rules work which fixes #40 and which I hope is a benefit in general. Fixes #40.
2024-01-08mention empty depfiles in design notesEvan Martin
2024-01-08update README to show current outputEvan Martin
2024-01-08allow windows drive letters in depfilesEvan Martin
See bug report context in #98. From a patch from Tobias Hieta <tobias.hieta@ubisoft.com>.
2024-01-08Treat missing depfile as a empty list of dependencies.Tobias Hieta
CMake can sometimes write depfile directives to build.ninja even when no depfile is generated. This was handled by "ninja" by just ignoring the missing file and going on with the build, see the code here: https://github.com/ninja-build/ninja/blob/master/src/build.cc#L894 This fixes #80
2024-01-08another pass at documenting variable scopeEvan Martin
2024-01-04design notes on variable scopeEvan Martin
2024-01-04snapshots of llvm build artifactsEvan Martin
2024-01-03Canonicalize paths to '.' instead of an empty stringCole Faust
It's possible to have a ninja dep on '.', meaning the directory that ninja was run from. Previously, canon_path_fast would canonicalize this to an empty string, which would cause stats and other opterations to fail. This was found when running the android codebase with n2.
2023-12-30attempt to deflake write_to_input testEvan Martin
2023-12-30ci: show backtraces on test failureEvan Martin
2023-12-30support external build.ninja files under `cargo bench`Evan Martin
Add docs for how to use it too.
2023-12-30disable bench for lib/bin, because it lives under benches/Evan Martin
This is in the Criterion FAQ.
2023-12-30restore criterion benchmarkingEvan Martin
2023-12-26move around nul-termination of input filesEvan Martin
2023-12-26use a growing Vec<u8> for buffering record writesEvan Martin
I had been too clever here with a statically-sized buffer, when really I ought to profile first and optimize second. I think it's still correct (without profiling) to avoid calling the underlying write() syscall too many times, so buffering at least a record at a time still makes sense. Fixes #92.
2023-12-21win: ensure thread attributes live long enoughEvan Martin
The pointers passed in a PROC_THREAD_ATTRIBUTE_LIST must outlive the struct, so add some lifetime hackery.
2023-12-21fix a test failing on windowsEvan Martin
2023-12-21Add validation inputsCole Faust
These were added to regular ninja in: https://github.com/ninja-build/ninja/commit/04c410b15b70fb321928ffba19d697db15cb0121 Android uses them, so they're needed to port android to n2. (which is something I'm exploring but not committing to)
2023-12-20obey builddir for placing .n2_dbEvan Martin
2023-11-28allow $\n in most contexts when parsingEvan Martin
The Ninja rules here aren't super clear, like I think this might be legal build $ foo$ :$ bar baz$ =$ blah and at least that kind of thing appears to be possible output of ninja_syntax.py. Fixes #89.
2023-11-05drop log to fix testEvan Martin
2023-11-04build all files if none specifiedEvan Martin
I'm ambivalent about this behavior, but it's come up twice so I think people depend on it. Fixes #88 and #53.
2023-10-10Run clippy --fixDamien Elmes