Skip to content

Commit

Permalink
Add an '-m' option to enable 'modified output is considered dirty'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragnalith committed Apr 15, 2021
1 parent 6ef944e commit f3c6ed7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/build.cc
Expand Up @@ -504,7 +504,8 @@ Builder::Builder(State* state, const BuildConfig& config,
: state_(state), config_(config), plan_(this), status_(status),
start_time_millis_(start_time_millis), disk_interface_(disk_interface),
scan_(state, build_log, deps_log, disk_interface,
&config_.depfile_parser_options) {
&config_.depfile_parser_options,
config.modified_output_is_dirty) {
}

Builder::~Builder() {
Expand Down
5 changes: 3 additions & 2 deletions src/build.h
Expand Up @@ -155,8 +155,8 @@ struct CommandRunner {

/// Options (e.g. verbosity, parallelism) passed to a build.
struct BuildConfig {
BuildConfig() : verbosity(NORMAL), dry_run(false), parallelism(1),
failures_allowed(1), max_load_average(-0.0f) {}
BuildConfig() : verbosity(NORMAL), dry_run(false), modified_output_is_dirty(false),
parallelism(1), failures_allowed(1), max_load_average(-0.0f) {}

enum Verbosity {
NORMAL,
Expand All @@ -165,6 +165,7 @@ struct BuildConfig {
};
Verbosity verbosity;
bool dry_run;
bool modified_output_is_dirty;
int parallelism;
int failures_allowed;
/// The maximum load average we must not exceed. A negative value
Expand Down
25 changes: 24 additions & 1 deletion src/build_test.cc
Expand Up @@ -494,6 +494,10 @@ struct BuildTest : public StateTestWithBuiltinRules, public BuildLogUser {
: config_(MakeConfig()), command_runner_(&fs_), status_(config_),
builder_(&state_, config_, NULL, log, &fs_, &status_, 0) {}

explicit BuildTest(const BuildConfig& config)
: config_(config), command_runner_(&fs_), status_(config_),
builder_(&state_, config_, NULL, NULL, &fs_, &status_, 0) {}

virtual void SetUp() {
StateTestWithBuiltinRules::SetUp();

Expand Down Expand Up @@ -1292,6 +1296,12 @@ struct BuildWithLogTest : public BuildTest {
BuildWithLogTest() {
builder_.SetBuildLog(&build_log_);
}

explicit BuildWithLogTest(const BuildConfig& config)
: BuildTest(config)
{
builder_.SetBuildLog(&build_log_);
}

BuildLog build_log_;
};
Expand Down Expand Up @@ -1446,7 +1456,19 @@ TEST_F(BuildWithLogTest, RebuildWithNoInputs) {
EXPECT_EQ(1u, command_runner_.commands_ran_.size());
}

TEST_F(BuildWithLogTest, RebuildIfOutputIsModified) {
struct BuildWithModifiedOutputDirtyAndLogTest : public BuildWithLogTest {
BuildWithModifiedOutputDirtyAndLogTest() : BuildWithLogTest(MakeConfig()) {
}

BuildConfig MakeConfig() {
BuildConfig config;
config.verbosity = BuildConfig::QUIET;
config.modified_output_is_dirty = true;
return config;
}
};

TEST_F(BuildWithModifiedOutputDirtyAndLogTest, RebuildIfOutputIsModified) {
ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
"build out: cat in\n"));

Expand Down Expand Up @@ -1567,6 +1589,7 @@ TEST_F(BuildWithLogTest, RestatMissingFile) {

fs_.Tick();
fs_.Create("in", "");
fs_.Create("out2", "");

// Run a build, expect only the first command to run.
// It doesn't touch its output (due to being the "true" command), so
Expand Down
2 changes: 1 addition & 1 deletion src/disk_interface_test.cc
Expand Up @@ -221,7 +221,7 @@ TEST_F(DiskInterfaceTest, RemoveFile) {

struct StatTest : public StateTestWithBuiltinRules,
public DiskInterface {
StatTest() : scan_(&state_, NULL, NULL, this, NULL) {}
StatTest() : scan_(&state_, NULL, NULL, this, NULL, false) {}

// DiskInterface implementation.
virtual TimeStamp Stat(const string& path, string* err) const;
Expand Down
2 changes: 1 addition & 1 deletion src/graph.cc
Expand Up @@ -276,7 +276,7 @@ bool DependencyScan::RecomputeOutputDirty(const Edge* edge,
if (build_log()) {
bool generator = edge->GetBindingBool("generator");
if (entry || (entry = build_log()->LookupByOutput(output->path()))) {
if (output->mtime() > entry->mtime) {
if (modified_output_is_dirty_ && output->mtime() > entry->mtime) {
// May also be dirty due to the mtime in the log being older from the
// actual mtime of the output. This can occur if the output has been
// modified from a process unrelated to the build system. In that case the
Expand Down
7 changes: 5 additions & 2 deletions src/graph.h
Expand Up @@ -284,11 +284,13 @@ struct ImplicitDepLoader {
struct DependencyScan {
DependencyScan(State* state, BuildLog* build_log, DepsLog* deps_log,
DiskInterface* disk_interface,
DepfileParserOptions const* depfile_parser_options)
DepfileParserOptions const* depfile_parser_options,
bool modified_output_is_dirty)
: build_log_(build_log),
disk_interface_(disk_interface),
dep_loader_(state, deps_log, disk_interface, depfile_parser_options),
dyndep_loader_(state, disk_interface) {}
dyndep_loader_(state, disk_interface),
modified_output_is_dirty_(modified_output_is_dirty) {}

/// Update the |dirty_| state of the given node by inspecting its input edge.
/// Examine inputs, outputs, and command lines to judge whether an edge
Expand Down Expand Up @@ -333,6 +335,7 @@ struct DependencyScan {
DiskInterface* disk_interface_;
ImplicitDepLoader dep_loader_;
DyndepLoader dyndep_loader_;
bool modified_output_is_dirty_;
};

#endif // NINJA_GRAPH_H_
2 changes: 1 addition & 1 deletion src/graph_test.cc
Expand Up @@ -20,7 +20,7 @@
using namespace std;

struct GraphTest : public StateTestWithBuiltinRules {
GraphTest() : scan_(&state_, NULL, NULL, &fs_, NULL) {}
GraphTest() : scan_(&state_, NULL, NULL, &fs_, NULL, false) {}

VirtualFileSystem fs_;
DependencyScan scan_;
Expand Down
7 changes: 6 additions & 1 deletion src/ninja.cc
Expand Up @@ -224,6 +224,7 @@ void Usage(const BuildConfig& config) {
" -j N run N jobs in parallel (0 means infinity) [default=%d on this system]\n"
" -k N keep going until N jobs fail (0 means infinity) [default=1]\n"
" -l N do not start new jobs if the load average is greater than N\n"
" -m considered modified output as dirty\n"
" -n dry run (don't run commands but act like they succeeded)\n"
"\n"
" -d MODE enable debugging (use '-d list' to list modes)\n"
Expand Down Expand Up @@ -1317,7 +1318,7 @@ int ReadFlags(int* argc, char*** argv,

int opt;
while (!options->tool &&
(opt = getopt_long(*argc, *argv, "d:f:j:k:l:nt:vw:C:h", kLongOptions,
(opt = getopt_long(*argc, *argv, "d:f:j:k:l:mnt:vw:C:h", kLongOptions,
NULL)) != -1) {
switch (opt) {
case 'd':
Expand Down Expand Up @@ -1358,6 +1359,10 @@ int ReadFlags(int* argc, char*** argv,
config->max_load_average = value;
break;
}
case 'm': {
config->modified_output_is_dirty = true;
break;
}
case 'n':
config->dry_run = true;
break;
Expand Down

0 comments on commit f3c6ed7

Please sign in to comment.