summaryrefslogtreecommitdiffstats
path: root/src/build.cc
Commit message (Collapse)AuthorAgeFilesLines
* Add validation nodes to ninjaColin Cross2021-10-121-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common problem in the Android build is inserting rules that perform some sort of error checking that doesn't produce any artifacts needed by the build, for example static analysis tools. There are a few patterns currently used, both of which have downsides. The first is to have a rule that depends on all of the static analysis results. This ensures they run, but requires running static analysis over everything, and not just the active parts of the build graph. The second is to insert the static analysis rule into the build graph between the artifact producing rule and anything that depends on it, often copying the artifact as the output of the static analysis rule. This increases the critical path of the build, often reducing parallelism. In the case of copying the artifact, it also wastes disk space. This patch adds "validation nodes" to edges in Ninja. A build statement can specify validation nodes using "|@" in the edge inputs. The validation nodes are not used as an input to the edge (the edge can run before the validation node is ready), but are added to the initial nodes of the build graph whenever the edge is part of the build graph. The edge that outputs the validation node can depend on the output of the edge that is being validated if desired. Test: ninja_test Change-Id: Ife27086c50c1b257a26509373199664680b2b247
* Remove early return from Builder::AddTargetColin Cross2021-10-121-5/+5
| | | | | | | | Refactor Builder::AddTarget to remove an early return in a non-error case. The next CL will add code that needs to be executed even if the node is clean. Change-Id: I953dc54b60b635dd75d75f8f3931970faefc5ecf
* util: Remove unnecessary CanonicalizePath error handlingBrad King2021-06-041-3/+1
| | | | | | | | | Since commit 86f606fe (Remove path component limit from input of CanonicalizePath in windows, 2017-08-30, v1.8.0^2~2^2), the only failure case in the `CanonicalizePath` implementation is the "empty path" error. All call sites have been updated to ensure `CanonicalizePath` is never called with an empty path. Remove error handling from the signature to simplify call sites.
* Revert "Change build log to always log the most recent input mtime"John Drouhard2021-03-241-40/+35
| | | | | | | | | | This reverts commit 67fbbeeec91ec171da7d4e297b8f9b319f3424c8. There were a few missing test cases exposed by CMake's test suite that need slight adjustments. Better to revert the original attempt, add the test cases, and then re-land the change with the fixes. Fixes #1932
* Change build log to always log the most recent input mtimeJohn Drouhard2021-03-161-35/+40
| | | | | | | | | | | | | | | | | | | | | | | | If an edge's output files' mtimes are compared to the most recent input's mtime, edges might be calculated as clean even if they are actually dirty. While an edge's command is running its rule to produce its outputs and an input to the edge is updated before the outputs are written to disk, then subsequent runs will think that the outputs are newer than the inputs, even though the inputs have actually been updated and may be different than what were used to produce those outputs. Ninja will now restat all inputs just prior to running an edge's command and remember the most recent input mtime. When the command completes, it will stat any discovered dependencies from dep files (if necessary), recalculate the most recent input mtime, and log it to the build log file. On subsequent runs, ninja will use this value to compare to the edge's most recent input's mtime to determine whether the outputs are dirty. This extends the methodology used by restat rules to work in all cases. Restat rules are still unique in that they will clean the edge's output nodes recursively if the edge's command did not change the output, but in all cases, the mtime recorded in the log file is now the most recent input mtime. See the new tests for more clarification.
* Put builder output through status interfaceColin Cross2021-02-051-1/+1
| | | | | | Send all output after manifest parsing is finished to the Status interface, so that when status frontends are added they can handle build messages.
* Turn BuildStatus into an interfaceColin Cross2020-12-181-227/+4
| | | | | | Make BuildStatus an abstract interface, and move the current implementation to StatusPrinter, to make way for a serialized Status output.
* Simplify running edges statusColin Cross2020-12-181-11/+15
| | | | | | | Store the number of running edges instead of trying to compute it from the started and finshed edge counts, which may be different for starting and ending status messages. Allows removing the status parameter to PrintStatus and the EdgeStatus enum.
* Move edge time from Status to BuilderColin Cross2020-12-181-41/+38
| | | | | | | | The times that end up in the build log currently originate in the status printer, and are propagated back out to the Builder. Move the edge times into the Builder instead, and move the overall start time into NinjaMain so it doesn't get reset during manifest rebuilds.
* Merge pull request #1866 from jhasse/unique-edge-idsJan Niklas Hasse2020-12-031-1/+1
|\ | | | | Add unique IDs to edges
| * Add unique IDs to edgesColin Cross2020-10-301-1/+1
| | | | | | | | | | | | | | | | Edges are nominally ordered by order in the build manifest, but in fact are ordered by memory address. In most cases the memory address will be monontonically increasing. Since serialized build output will need unique IDs, add a monotonically increasing ID to edges, and use that for sorting instead of memory address.
* | [clang-tidy] fix inconsistent declarationsRosen Penev2020-12-021-6/+6
| | | | | | | | | | | | Found with readability-inconsistent-declaration-parameter-name Signed-off-by: Rosen Penev <rosenp@gmail.com>
* | Merge pull request #1834 from jhasse/close-during-generatorJan Niklas Hasse2020-11-021-0/+4
|\ \ | |/ |/| Close BuildLog while running generators, fix #1724
| * Close BuildLog while running generators, fix #1724Jan Niklas Hasse2020-08-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | While #1780 delayed opening .ninja_log until the first write, this this didn't fully fix the issue on Windows: There might be build statements which run before the generator resulting in an actual write to .ninja_log. To fix this once and for all the BuildLog now gets closed before running the generator. BuildLog::log_file_path_ won't be cleared so that it can be opened again after the generator finished.
* | Add 'using namespace std;' to all cc files to prepare for removing it from ↵Michael Jones2020-09-301-0/+2
| | | | | | | | header files
* | Merge pull request #1789 from neheb/ifJan Niklas Hasse2020-09-101-2/+1
|\ \ | | | | | | [clang-tidy] fix small false positive
| * | [clang-tidy] fix small false positiveRosen Penev2020-06-181-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | else if has to be on the same line it seems. Found with readability-misleading-indentation Signed-off-by: Rosen Penev <rosenp@gmail.com>
* | | Merge pull request #1786 from neheb/membJan Niklas Hasse2020-09-101-6/+3
|\ \ \ | |_|/ |/| | [clang-tidy] remove redundant member init
| * | [clang-tidy] remove redundant member initRosen Penev2020-06-181-6/+3
| |/ | | | | | | | | | | Found with readability-redundant-member-init Signed-off-by: Rosen Penev <rosenp@gmail.com>
* | Fix typosDimitris Apostolou2020-07-071-1/+1
|/
* [clang-tidy] check empty instead of size (#1784)Rosen Penev2020-06-041-1/+1
| | | | | Found with readability-container-size-empty Signed-off-by: Rosen Penev <rosenp@gmail.com>
* Merge pull request #1534 from mathstuf/remove-depslog-restrictionJan Niklas Hasse2020-01-041-8/+10
|\ | | | | manifest_parser: remove multi-output depslog restriction
| * depfile_parser: remove restriction on multiple outputsBen Boeckel2019-11-201-1/+1
| |
| * build: add to deps log for each edge outputBen Boeckel2019-11-201-7/+9
| |
* | build.cc: constify BuildStatusKonstantin Kharlamov2019-11-201-2/+2
| | | | | | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* | build.cc: constify a few Plan functionsKonstantin Kharlamov2019-11-201-7/+7
| | | | | | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* | build.cc: constify a map key in RealCommandRunnerKonstantin Kharlamov2019-11-201-3/+3
|/ | | | | | Modifying a key in C++ associative containers is UB. Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Small constifications (#1647)Konstantin Kharlamov2019-09-191-5/+5
| | | | | | | * build: constify EdgeWanted() * build: constify a bit of CommandRunner * graph: constify functions of struct Edge Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Merge pull request #1508 from mqudsi/colored_failJan Niklas Hasse2019-08-021-1/+5
|\ | | | | Emit "FAILED: " in red if terminal supports ANSI color output
| * Add braces to clarify conditional scopeMahmoud Al-Qudsi2019-02-041-2/+3
| |
| * Emit "FAILED: " in red if terminal supports ANSI color outputMahmoud Al-Qudsi2018-12-051-1/+4
| |
* | Teach builder to load dyndep files when they are readyBrad King2019-04-181-4/+173
| | | | | | | | | | | | | | | | After finishing an edge that produces a dyndep file, load the file and update the build graph structure. Recompute the dirty state of all its dependents and of newly reachable portions of the graph. Add edges to the build plan that are discovered to be wanted. Finally, schedule edges that are wanted and now ready to build.
* | Make a Builder optionally available to PlanBrad King2019-04-181-2/+7
| | | | | | | | | | | | | | In order to later support dynamic updates to the build plan while building, the Plan will need access to its Builder. Since this access will be needed only for specific features we can avoid updating all Plan constructions in the test suite by making this access optional.
* | Factor out output edge ready check from Plan::NodeFinishedBrad King2019-04-181-9/+16
| | | | | | | | | | Move the logic to a new Plan::EdgeMaybeReady method so it can be re-used elsewhere.
* | Factor out edge marking logic from Plan::AddSubTargetBrad King2019-04-181-3/+7
| | | | | | | | | | Move the logic to mark edges as wanted over to a Plan::EdgeWanted method so it can be re-used elsewhere later.
* | Allow EdgeFinished and NodeFinished to fail with errorsBrad King2019-04-181-9/+17
| | | | | | | | | | | | | | Add an 'err' string argument and return a boolean for success. Update call sites to pass an 'err' string argument and check the return value. This will be useful later for adding logic to these methods that may fail.
* | Assert precondition in BuildStatus::BuildEdgeStartedBrad King2019-04-181-0/+1
|/ | | | | This method should be called only with edges that have not already been started.
* Restore depfile toleration of multiple output paths on distinct linesBrad King2018-11-191-2/+3
| | | | | | | | | | | | | | | | Prior to introduction of depfile parser handling of multiple rules, ninja silently accepted a depfile of the form: out: in1 in2 in3 other: otherIn1 otherIn2 otherIn3 and incorrectly treated `other` and `otherIn*` as additional inputs to `out`. Now we prefer to reject this just as we already do for a depfile specifying multiple outputs on one line. However, this can break existing cases where such a depfile was silently tolerated. Add a `-w depfilemulti={err,warn}` option to control this behavior, and make it just a warning by default.
* Allow disabling of escape code stripping, fix #1475Jan Niklas Hasse2018-11-131-1/+0
| | | | | 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.
* Revert "Fix confusing smart console output from concurrent builds"Jan Niklas Hasse2018-11-051-13/+0
| | | | | | This reverts commit 52c1d0c8f8545231581c4d51cb0a85f50564c415. Fixes #1418.
* Do not always strip colored output in verbose mode, fix #1214Jan Niklas Hasse2018-11-051-1/+1
|
* Fix confusing smart console output from concurrent buildsNico Weber2018-04-051-0/+13
| | | | | | | | | | | Developers tend to blame the last printed line when a build takes too long. Unfortunately, when building concurrently, the last printed line may have actually finished a long time ago. Under the current system, ninja does not update the status line to reflect what jobs are still running. This change makes ninja always print the oldest still running job instead. In other words, the likely build bottlenecks. Patch from David Zarzycki, originally uploaded at #1320.
* Merge pull request #1294 from bradking/plan-track-schedulingNico Weber2018-04-051-21/+23
|\ | | | | Track in Plan whether wanted edges have been scheduled
| * Track in Plan whether wanted edges have been scheduledBrad King2017-09-141-21/+23
| | | | | | | | | | | | | | | | Refactor the `want_` map to track for wanted edges whether they have been scheduled or not. This gives `ScheduleWork` a direct place to keep this information, making the logic more robust and easier to follow. It also future-proofs `ScheduleWork` to avoid repeat scheduling if it is called after an edge has been removed from `ready_` by `FindWork`.
* | make ninja build with -std=c++17Nico Weber2018-04-051-1/+6
|/ | | | | | Ninja is supposed to be able to build as C++98 so it can run on old systems, but it should also be possible to optionally build it with newer dialects.
* Drop unnecessary cycle detection in Plan::AddTargetBrad King2017-06-191-44/+5
| | | | | We now detect and reject cycles in DependencyScan::RecomputeDirty before Plan::AddTarget is called so we can assume DAG input to the Plan.
* Refactor RecomputeDirty to take a node instead of an edgeBrad King2017-06-191-2/+3
| | | | | | All call sites have a node on which they call `in_edge()` to call RecomputeDirty. Simplify call sites by taking the node directly and calling `in_edge()` internally.
* Merge pull request #1156 from cdbennett/windows-binary-mode-outputNico Weber2017-06-141-0/+15
|\ | | | | Write subprocess output to stdout in binary mode
| * Write subprocess output to stdout in binary modeColin D Bennett2016-05-121-0/+15
| | | | | | | | | | | | | | | | Set stdout to binary mode while writing subprocess output, so that the CR in a CR LF sequence is not replaced with CR LF itself, which would result in CR CR LF. Based on patch posted by nico in issue #773 comment.
* | Always rebuild on errorsColin Cross2017-05-221-5/+11
| | | | | | | | | | | | | | | | | | | | https://groups.google.com/forum/#!msg/ninja-build/YQuGNrECI-4/ti-lAs9SPv8J discusses a case where an rule updates its output file and then fails. The next run of ninja considers the ouptut file clean and doesn't rebuild it. Always stat output files after they are built, and write the mtime into .ninja_log. Consider output files dirty if the recorded mtime is older than the most recent input file.