Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninja status format string from argv. #1180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ BuildStatus::BuildStatus(const BuildConfig& config)
if (config_.verbosity != BuildConfig::NORMAL)
printer_.set_smart_terminal(false);

progress_status_format_ = getenv("NINJA_STATUS");
if (config_.status_format) {
// Command line arg overrides env if given.
progress_status_format_ = config_.status_format;
} else {
progress_status_format_ = getenv("NINJA_STATUS");
}
if (!progress_status_format_)
progress_status_format_ = "[%f/%t] ";
}
Expand Down Expand Up @@ -279,7 +284,7 @@ string BuildStatus::FormatProgressStatus(
}

default:
Fatal("unknown placeholder '%%%c' in $NINJA_STATUS", *s);
Fatal("unknown placeholder '%%%c' in the status format string", *s);
return "";
}
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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) {}
failures_allowed(1), max_load_average(-0.0f),
status_format(NULL) {}

enum Verbosity {
NORMAL,
Expand All @@ -173,6 +174,8 @@ struct BuildConfig {
/// The maximum load average we must not exceed. A negative value
/// means that we do not have any limit.
double max_load_average;
/// Status format string.
const char* status_format;
DepfileParserOptions depfile_parser_options;
};

Expand Down
10 changes: 8 additions & 2 deletions src/ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ void Usage(const BuildConfig& config) {
"if targets are unspecified, builds the 'default' target (see manual).\n"
"\n"
"options:\n"
" --version print ninja version (\"%s\")\n"
" -v, --verbose show all command lines while building\n"
" --version print ninja version (\"%s\")\n"
" -v, --verbose show all command lines while building\n"
" -s, --status-format=STATUS specify the status format string\n"
"\n"
" -C DIR change to DIR before doing anything else\n"
" -f FILE specify input build file [default=build.ninja]\n"
Expand Down Expand Up @@ -1190,6 +1191,7 @@ int ReadFlags(int* argc, char*** argv,
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, OPT_VERSION },
{ "verbose", no_argument, NULL, 'v' },
{ "status-format", required_argument, NULL, 's' },
{ NULL, 0, NULL, 0 }
};

Expand Down Expand Up @@ -1239,6 +1241,10 @@ int ReadFlags(int* argc, char*** argv,
case 'n':
config->dry_run = true;
break;
case 's':
// status-format value is in optarg
config->status_format = optarg;
break;
case 't':
options->tool = ChooseTool(optarg);
if (!options->tool)
Expand Down