summaryrefslogtreecommitdiffstats
path: root/src/graph.cc
Commit message (Collapse)AuthorAgeFilesLines
* util: Remove unnecessary CanonicalizePath error handlingBrad King2021-06-041-9/+3
| | | | | | | | | 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.
* dyndep: reconcile dyndep-specified outputs with depfile-specified inputsBrad King2021-03-241-0/+1
| | | | | | | | | When a path loaded from a depfile does not have a node, we create a new node with a phony edge producing it. If we later load a dyndep file that specifies the same node as an output of a known edge, we previously failed with a "multiple rules generate ..." error. Instead, since the conflicting edge was internally generated, replace the node's input edge with the now-known real edge that produces it.
* Revert "Change build log to always log the most recent input mtime"John Drouhard2021-03-241-14/+29
| | | | | | | | | | 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-29/+14
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Refactor depfile loading in preparation for the missingdeps toolTomasz Śniatowski2021-02-221-3/+8
| | | | | Extract an usable helper to load depfile dependencies without adding them to the graph.
* [clang-tidy] add explicit to single argument constructorsRosen Penev2020-12-061-1/+1
| | | | | | Found with google-explicit-constructor Signed-off-by: Rosen Penev <rosenp@gmail.com>
* 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 #1534 from mathstuf/remove-depslog-restrictionJan Niklas Hasse2020-01-041-4/+32
|\ | | | | manifest_parser: remove multi-output depslog restriction
| * depfile_parser: remove restriction on multiple outputsBen Boeckel2019-11-201-4/+32
| |
* | graph.cc: constify DependencyScanKonstantin Kharlamov2019-11-201-2/+2
|/ | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Fix invalid preprocessor #ifMichael Jones2019-11-141-1/+1
|
* Fix crash when using MSVC in debug modeJan Niklas Hasse2019-09-211-0/+4
| | | | | Accessing inputs_[0] when it's empty results in an assert when running in debug. Avoid it by using data() if available.
* Small constifications (#1647)Konstantin Kharlamov2019-09-191-3/+3
| | | | | | | * build: constify EdgeWanted() * build: constify a bit of CommandRunner * graph: constify functions of struct Edge Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Improve const-correctness in compdb related methodsJan Niklas Hasse2019-08-021-17/+11
|
* Fix UB "member call on null pointer of type 'DepsLog'", see #1248Jan Niklas Hasse2019-05-281-1/+1
|
* Teach RecomputeDirty to load dyndep files that are readyBrad King2019-04-181-0/+25
| | | | | | | | | | | The full readiness of a node that has a dyndep binding cannot be known until after the dyndep file is loaded. If a dyndep file is ready while constructing the build plan it can be loaded immediately so full information can be used to decide whether anything needs to be built. If a dyndep file is not ready while constructing the build plan then the edges naming it cannot be ready either because the dyndep file is one of their inputs. In this case we defer loading the dyndep file until the build plan is being executed.
* Teach DependencyScan to load a dyndep fileBrad King2019-04-181-0/+9
| | | | | Add a LoadDyndeps method to load a dyndep file and update the edges that name it in their dyndep binding.
* Add a "dyndep" reserved binding to the manifest formatBrad King2019-04-181-0/+5
| | | | | | Allow rules or build statements to specify one of the build statement inputs in a "dyndep" binding. This will later be used to load dependency information from the specified file.
* Explicitly avoid repeat deps loadingBrad King2019-04-181-6/+10
| | | | | | Track for each Edge whether depfile information has been loaded using an explicit flag. This will allow RecomputeDirty to be repeated for an edge without loading deps again.
* Restore depfile toleration of multiple output paths on distinct linesBrad King2018-11-191-1/+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.
* Make TimeStamp 64-bit.Elliott Sales de Andrade2017-09-161-4/+4
| | | | This prepares it for higher-resolution timestamps.
* Restore tolerance of self-referencing phony build statementsBrad King2017-09-081-0/+15
| | | | | | | | | | | | | | | | | | | | Since commit v1.8.0^2~3^2~1 (Teach RecomputeDirty to detect cycles in the build graph, 2015-11-13) we correctly reject self-referencing phony build statements like build a: phony a as cycles. Unfortunately this breaks support for CMake 2.8.12.x and 3.0.x because those versions incorrectly produce edges of this form (that we used to tolerate). In order to preserve compatibility with those CMake versions we need to restore tolerance of these edges. Add a special case to the manifest parser to filter out self-referencing inputs of phony edges of the form produced by those CMake versions. Warn by default, but add a `-w phonycycle={err,warn}` option to make it an error. Fixes: #1322
* Teach RecomputeDirty to detect cycles in the build graphBrad King2017-06-191-14/+64
| | | | | | | | | | | | | | | | RecomputeDirty is the earliest traversal of the build graph complete with depfile-loaded dependencies. Teach it to detect cycles and fail immediately. This avoids the need to tolerate cycles in RecomputeDirty only to diagnose them later. It also enables future simplification of Plan and Builder logic because they will be able to assume DAG input. When RecomputeDirty detects a cycle, reject it with an error message like that previously produced by Plan::CheckDependencyCycle. Previously we used the stat state of each node to determine whether we reached it earlier in the walk. Retain this approach for leaf nodes, but add an explicit walk state mark for each Edge so that we can have a temporary mark to aid cycle detection.
* Refactor RecomputeDirty to take a node instead of an edgeBrad King2017-06-191-10/+12
| | | | | | 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.
* Fix segfault on edge with no inputsColin Cross2017-06-161-1/+1
| | | | | | | | PR #1281 added a deference of most_recent_input without checking for NULL, which can occur if a build rule has no inputs. Check it for null before dereferencing, and add a test. Fixes #1290.
* Always rebuild on errorsColin Cross2017-05-221-7/+19
| | | | | | | | | | 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.
* Move stat metric to DiskInterfaceColin Cross2017-05-221-1/+0
| | | | | | | Stat is not always used through Node::Stat, it is often used directly through DiskInterface. THe next patches will cause it to be called even more often through DiskInterface, so move the metrics to DiskInterface.
* Merge pull request #1181 from DanielWeber/issue-1161Nico Weber2017-01-241-4/+4
|\ | | | | Allow more path components
| * Use uint64_t for slash_bits consistentlyDaniel Weber2016-09-011-2/+2
| | | | | | | | The VS compiler complained about possible loss of data (and it was right!)
| * Allow more path componentsDaniel Weber2016-08-221-2/+2
| | | | | | | | | | | | | | - 60 instead of 30 path components - 64 instead of 32 backslashes in a path (windows only) Issue: 1161
* | Improve error message when a depfile contains a bad pathTomasz Śniatowski2016-10-121-1/+3
|/ | | | | Debugging "ninja: error: empty path" is not fun, so make the error message mention the depfile name.
* Remove StatIfNecessary call that is never necessaryBrad King2016-02-251-2/+1
| | | | | | | | | | | | | | The call to StatIfNecessary in DependencyScan::RecomputeOutputsDirty was added by commit v1.4.0^2~7^2~1 (Share more code between CleanNode() and RecomputeDirty(), 2013-09-02) while consolidating code paths. However, it was needed only when called from RecomputeDirty because prior to refactoring the CleanNode code path did not call it. Later commit v1.6.0^2~46^2 (Let DependencyScan::RecomputeDirty() work correclty with cyclic graphs, 2014-12-07) added back to RecomputeDirty a loop over outputs that calls StatIfNecessary. Therefore RecomputeOutputsDirty no longer needs to call StatIfNecessary for either of its own callers.
* Merge pull request #989 from bradking/implicit-outputsNico Weber2016-02-031-1/+2
|\ | | | | Add support for build statement implicit outputs
| * Add support for build statement implicit outputsBrad King2016-02-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some build rules produce outputs that are not mentioned on the command line but that should be part of the build graph. Such outputs should not be named in the `$out` variable. Extend the build statement syntax to support specification of implicit outputs using the syntax `| out1 out2` after the explicit outputs and before the `:`. For example, compilation of a Fortran source file `foo.f90` that defines `MODULE FOO` may now be specified as: rule fc command = f95 -c $in -o $out build foo.o | foo.mod: fc foo.f90 The `foo.mod` file is an implicit output generated by the compiler based on the content of the source file and not mentioned on the command line.
* | Expose more details in FileReader::ReadFile signatureBrad King2016-02-031-2/+9
|/ | | | | | Return a status so callers can distinguish a missing file from an empty file. This allows our VirtualFileSystem test infrastructure to report as missing any file for which it has no entry.
* win: print right slashes in 'unknown target' messageNico Weber2015-07-101-3/+4
|
* Add a missing EXPLAIN() call.Nico Weber2015-05-151-1/+7
|
* Let Stat() have an err outparam instead of writing to stderr.Nico Weber2015-03-311-7/+1
| | | | | | | | | Also check for Stat() failure in a few more places. This way, ninja doesn't print two "ninja: error: " lines if stat() fails during a build. It also makes it easier to keep the stat tests quiet. Every caller of Stat() needs to explicitly log the error string if that's desired.
* Recover slowdown for cyclic rule bindings fix.Nico Weber2015-03-211-9/+17
|
* Don't crash on cyclic references between rule bindings.Nico Weber2015-03-211-0/+12
| | | | | | | | | | | | | Fixes #902. This dynamically detects cycles. I like this approach less than detecting them statically when parsing rules [1], but it has the advantage that it doesn't break existing ninja manifest files. It has the disadvantage that it slows down manifest_parser_perftest by 3.9%. 1: https://github.com/martine/ninja/commit/cc6f54d6d436047
* Make failing stat() calls abort the build.Nico Weber2015-03-191-10/+22
| | | | | | | | | | | | | | | | | | | | | | | | Fixes #830, fixes #904. In practice, this either happens with 64-bit inodes and a 32-bit userspace when building without -D_FILE_OFFSET_BITS=64 in CFLAGS, or when a filename is longer than the system file length limit. Since DiskInterface::Stat() returns -1 on error, and Node used -1 on "stat state unknown", not aborting the build lead to ninja stat()ing the same file over and over again, until it finally ran out of stack. That's now fixed. * Change RecomputeOutputsDirty() to return success instead of dirty state (like RecomputeDirty()) and return the dirty state in a bool outparam * Node::Stat()s old return value wasn't used anywhere, change the function to return success instead and add an |err| outparam * Node::StatIfNecessary()'s old return value was used only in one place. Change that place to explicitly check status_known() and make StatIfNecessary() return success and add an |err| outparam * Plan::CleanNode() can now fail, make it return bool and add an |err| outparam
* Env should only be about variables. No behavior change.Nico Weber2015-03-181-5/+0
|
* On unexpected output in a .d file, rebuild instead erroring.Nico Weber2015-03-121-3/+4
| | | | Fixes #417.
* Allow scoping rules through subninjaMohamed Bamakhrama2015-03-011-24/+5
| | | | | | | | Ninja didn't support scoping rules through subninja and assumed a unique rule name in the whole namespace. With this change, this behavior is changed to allow scoping rules. Two rules can have the same name if they belong to two different scopes. However, two rules can NOT have the same name in the same scope.
* Typo fix in graph.cctzik2015-02-061-1/+1
|
* Let DependencyScan::RecomputeDirty() work correclty with cyclic graphs.Nico Weber2014-12-081-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RecomputDirty(edge) currently works roughly like this: RecomputeDirty(edge): LoadDeps(edge) for in in edge.inputs: if in.StatIfNecessary(): RecomputeDirty(in.in_edge) # recurse into inputs for out in edge.outputs: out.StatIfNecessary() # mark outputs as visited It uses the stat state of each node to mark nodes as visited and doesn't traverse across nodes that have been visited already. For cyclic graphs with an edge with multiple outputs on the cycle, nothing prevents an edge to be visited more than once if the cycle is entered through an output that isn't on the cycle. In other words, RecomputeDirty() for the same edge can be on the call stack more than once. This is bad for at least two reasons: 1. Deps are added multiple times, making the graph confusing to reason about. 2. LoadDeps() will insert into the inputs_ of an edge that's iterated over in a callframe higher up. This can invalidate the iterator, which causes a crash when the callframe with the loop over the now-invalidated iterator resumes. To fix this, let RecomputeDirty() mark all outputs of an edge as visited as the first thing it does. This way, even if the edge is on a cycle with several outputs, each output is already marked and no edge will have its deps loaded more than once. Fixes the crashes in #875. (In practice, it turns the crashes into "stuck [this is a bug]" messages for now, due to the example without duplicate rules in #867)
* Rename a few iterators. No behavior change.Nico Weber2014-12-071-9/+9
| | | | | | | | | It confused me that the iterator iterating over `outputs_` was called `i` -- this always made me think of "input", not "iterator". Call iterators over edge outputs "o", iterators over edge inputs "i", iterators over node input edges "oe", and general iterators over edges "e".
* remove two unneeded `explicit`sNico Weber2014-12-071-1/+1
|
* whitespace/comment/wrap fixes, no intended functionality changeScott Graham2014-11-121-1/+1
|
* no need to Decanonicalize on non-WindowsScott Graham2014-11-111-0/+2
|