blob: c08cd2b1c59526e5102558105d4df0c6f8281c45 [file] [log] [blame]
// Copyright 2023 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NINJA_BUILD_CONFIG_H_
#define NINJA_BUILD_CONFIG_H_
#include <string>
#include "depfile_parser.h"
/// Options (e.g. verbosity, parallelism) passed to a build.
/// NOTE: This does not include debug flags, stored in global variables :-/
struct BuildConfig {
enum Verbosity {
QUIET, // No output -- used when testing.
NO_STATUS_UPDATE, // just regular output but suppress status update
NORMAL, // regular output and status update
VERBOSE
};
Verbosity verbosity = NORMAL;
bool dry_run = false;
int parallelism = 1;
int failures_allowed = 1;
/// The maximum load average we must not exceed. A negative value
/// means that we do not have any limit.
double max_load_average = -0.0f;
;
DepfileParserOptions depfile_parser_options;
/// Status related options, initialized from the environment.
std::string status_format = "[%f/%t] ";
/// Init some fields from environment variables.
void InitFromEnvironment();
/// Compare two instances.
bool operator==(const BuildConfig& o) const {
return verbosity == o.verbosity && dry_run == o.dry_run &&
parallelism == o.parallelism &&
failures_allowed == o.failures_allowed &&
max_load_average == o.max_load_average &&
depfile_parser_options == o.depfile_parser_options &&
status_format == o.status_format;
}
bool operator!=(const BuildConfig& o) const { return !(*this == o); }
/// Encoding/decoding support for IPC.
static BuildConfig FromEncodedString(const std::string& str,
std::string* error);
std::string ToEncodedString() const;
/// Convert to string for debugging.
std::string ToString() const;
};
#endif // NINJA_BUILD_CONFIG_H_