return edge;
}
+struct DryRunCommandRunner : public CommandRunner {
+ virtual ~DryRunCommandRunner() {}
+ virtual bool CanRunMore() {
+ return true;
+ }
+ virtual bool StartCommand(Edge* edge) {
+ finished_.push(edge);
+ return true;
+ }
+ virtual void WaitForCommands() {
+ }
+ virtual Edge* NextFinishedCommand(bool* success) {
+ if (finished_.empty())
+ return NULL;
+ *success = true;
+ Edge* edge = finished_.front();
+ finished_.pop();
+ return edge;
+ }
+
+ queue<Edge*> finished_;
+};
+
Builder::Builder(State* state)
: state_(state) {
disk_interface_ = new RealDiskInterface;
log_->verbose_ = verbose;
}
+void Builder::SetDryRun(bool on) {
+ if (on)
+ command_runner_ = new DryRunCommandRunner;
+}
+
Node* Builder::AddTarget(const string& name, string* err) {
Node* node = state_->LookupNode(name);
if (!node) {
Builder(State* state);
void SetVerbose(bool verbose);
+ void SetDryRun(bool on);
Node* AddTarget(const string& name, string* err);
bool Build(string* err);
"options:\n"
" -g output graphviz dot file for targets and exit\n"
" -i FILE specify input build file [default=build.ninja]\n"
+" -n dry run (don't run commands but pretend they succeeded)\n"
" -v show all command lines\n"
);
}
const char* input_file = "build.ninja";
int opt;
- bool graph = false, verbose = false;
- while ((opt = getopt_long(argc, argv, "ghi:v", options, NULL)) != -1) {
+ bool dry_run = false, graph = false, verbose = false;
+ while ((opt = getopt_long(argc, argv, "ghi:nv", options, NULL)) != -1) {
switch (opt) {
case 'g':
graph = true;
case 'i':
input_file = optarg;
break;
+ case 'n':
+ dry_run = true;
+ break;
case 'v':
verbose = true;
break;
Builder builder(&state);
builder.SetVerbose(verbose);
+ builder.SetDryRun(dry_run);
for (int i = 0; i < argc; ++i) {
if (!builder.AddTarget(argv[i], &err)) {
if (!err.empty()) {
or use mtimes on build files?
"explain" mode that shows why we're building a file
"one file" mode that builds only outputs of a single file
-"dry run" mode that shows command lines but doesn't build
adjust to system load dynamically
progress bar rather than printing commands in series