Skip to content

Commit

Permalink
Make callers of CommandLine use it via the base:: namespace.
Browse files Browse the repository at this point in the history
Covers testing/, tools/, ui/, and win8/.

BUG=422426
TEST=none
TBR=ben@chromium.org

Review URL: https://codereview.chromium.org/819223002

Cr-Commit-Position: refs/heads/master@{#309538}
  • Loading branch information
avi authored and Commit bot committed Dec 23, 2014
1 parent b126eb8 commit 6b10fd0
Show file tree
Hide file tree
Showing 84 changed files with 231 additions and 200 deletions.
9 changes: 5 additions & 4 deletions testing/android/native_test_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void RunTests(JNIEnv* env,

// Command line initialized basically, will be fully initialized later.
static const char* const kInitialArgv[] = { "ChromeTestActivity" };
CommandLine::Init(arraysize(kInitialArgv), kInitialArgv);
base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv);

// Set the application context in base.
base::android::ScopedJavaLocalRef<jobject> scoped_context(
Expand All @@ -151,9 +151,10 @@ static void RunTests(JNIEnv* env,
int argc = ArgsToArgv(args, &argv);

// Fully initialize command line with arguments.
CommandLine::ForCurrentProcess()->AppendArguments(
CommandLine(argc, &argv[0]), false);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
base::CommandLine::ForCurrentProcess()->AppendArguments(
base::CommandLine(argc, &argv[0]), false);
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();

base::FilePath files_dir(
base::android::ConvertJavaStringToUTF8(env, jfiles_dir));
Expand Down
4 changes: 2 additions & 2 deletions tools/android/common/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ void CloseFileDescriptor(int fd) {

namespace tools {

bool HasHelpSwitch(const CommandLine& command_line) {
bool HasHelpSwitch(const base::CommandLine& command_line) {
return command_line.HasSwitch("h") || command_line.HasSwitch("help");
}

bool HasNoSpawnDaemonSwitch(const CommandLine& command_line) {
bool HasNoSpawnDaemonSwitch(const base::CommandLine& command_line) {
return command_line.HasSwitch(kNoSpawnDaemon);
}

Expand Down
4 changes: 2 additions & 2 deletions tools/android/forwarder/forwarder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ int main(int argc, char** argv) {
printf("Android device to host TCP forwarder\n");
printf("Like 'adb forward' but in the reverse direction\n");

CommandLine command_line(argc, argv);
CommandLine::StringVector server_args = command_line.GetArgs();
base::CommandLine command_line(argc, argv);
base::CommandLine::StringVector server_args = command_line.GetArgs();
if (tools::HasHelpSwitch(command_line) || server_args.empty()) {
tools::ShowHelp(
argv[0],
Expand Down
6 changes: 3 additions & 3 deletions tools/android/forwarder2/device_forwarder_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class ClientDelegate : public Daemon::ClientDelegate {
};

int RunDeviceForwarder(int argc, char** argv) {
CommandLine::Init(argc, argv); // Needed by logging.
const bool kill_server = CommandLine::ForCurrentProcess()->HasSwitch(
"kill-server");
base::CommandLine::Init(argc, argv); // Needed by logging.
const bool kill_server =
base::CommandLine::ForCurrentProcess()->HasSwitch("kill-server");
if ((kill_server && argc != 2) || (!kill_server && argc != 1)) {
std::cerr << "Usage: device_forwarder [--kill-server]" << std::endl;
return 1;
Expand Down
4 changes: 2 additions & 2 deletions tools/android/forwarder2/host_forwarder_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ int PortToInt(const std::string& s) {
}

int RunHostForwarder(int argc, char** argv) {
CommandLine::Init(argc, argv);
const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
base::CommandLine::Init(argc, argv);
const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
bool kill_server = false;

Pickle pickle;
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/command_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int RunCheck(const std::vector<std::string>& args) {
}
}

const CommandLine* cmdline = CommandLine::ForCurrentProcess();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
bool force = cmdline->HasSwitch("force");

if (!CheckPublicHeaders(&setup->build_settings(), all_targets,
Expand Down
5 changes: 3 additions & 2 deletions tools/gn/command_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void RecursivePrintDeps(const Target* target,
}

void PrintDeps(const Target* target, bool display_header) {
const CommandLine* cmdline = CommandLine::ForCurrentProcess();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
Label toolchain_label = target->label().GetToolchainLabel();

// Tree mode is separate.
Expand Down Expand Up @@ -407,7 +407,8 @@ template<typename T> void OutputRecursiveTargetConfig(
const Target* target,
const char* header_name,
const std::vector<T>& (ConfigValues::* getter)() const) {
bool display_blame = CommandLine::ForCurrentProcess()->HasSwitch("blame");
bool display_blame =
base::CommandLine::ForCurrentProcess()->HasSwitch("blame");

DescValueWriter<T> writer;
std::ostringstream out;
Expand Down
4 changes: 2 additions & 2 deletions tools/gn/command_gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int RunGen(const std::vector<std::string>& args) {
if (!setup->DoSetup(args[0], true))
return 1;

if (CommandLine::ForCurrentProcess()->HasSwitch(kSwitchCheck))
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchCheck))
setup->set_check_public_headers(true);

// Cause the load to also generate the ninja files for each target. We wrap
Expand All @@ -103,7 +103,7 @@ int RunGen(const std::vector<std::string>& args) {

base::TimeDelta elapsed_time = timer.Elapsed();

if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) {
OutputString("Done. ", DECORATION_GREEN);

std::string stats = "Wrote " +
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/command_help.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int RunHelp(const std::vector<std::string>& args) {
// If no argument is specified, check for switches to allow things like
// "gn help --args" for help on the args switch.
const base::CommandLine::SwitchMap& switches =
CommandLine::ForCurrentProcess()->GetSwitches();
base::CommandLine::ForCurrentProcess()->GetSwitches();
if (switches.empty()) {
// Still nothing, show help overview.
PrintToplevelHelp();
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/command_ls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int RunLs(const std::vector<std::string>& args) {
if (!setup->DoSetup(args[0], false) || !setup->Run())
return 1;

const CommandLine* cmdline = CommandLine::ForCurrentProcess();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
bool all_toolchains = cmdline->HasSwitch("all-toolchains");

// Find matching targets.
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/command_refs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ int RunRefs(const std::vector<std::string>& args) {
return 1;
}

const CommandLine* cmdline = CommandLine::ForCurrentProcess();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
bool tree = cmdline->HasSwitch("tree");
bool all = cmdline->HasSwitch("all");
bool all_toolchains = cmdline->HasSwitch("all-toolchains");
Expand Down
4 changes: 2 additions & 2 deletions tools/gn/exec_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace internal {

#if defined(OS_WIN)
bool ExecProcess(const CommandLine& cmdline,
bool ExecProcess(const base::CommandLine& cmdline,
const base::FilePath& startup_dir,
std::string* std_out,
std::string* std_err,
Expand Down Expand Up @@ -138,7 +138,7 @@ bool ReadFromPipe(int fd, std::string* output) {
return true;
}

bool ExecProcess(const CommandLine& cmdline,
bool ExecProcess(const base::CommandLine& cmdline,
const base::FilePath& startup_dir,
std::string* std_out,
std::string* std_err,
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/function_exec_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Value RunExecScript(Scope* scope,

// Make the command line.
const base::FilePath& python_path = build_settings->python_path();
CommandLine cmdline(python_path);
base::CommandLine cmdline(python_path);
cmdline.AppendArgPath(script_path);

if (args.size() >= 2) {
Expand Down
10 changes: 5 additions & 5 deletions tools/gn/gn_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace {

std::vector<std::string> GetArgs(const CommandLine& cmdline) {
CommandLine::StringVector in_args = cmdline.GetArgs();
std::vector<std::string> GetArgs(const base::CommandLine& cmdline) {
base::CommandLine::StringVector in_args = cmdline.GetArgs();
#if defined(OS_WIN)
std::vector<std::string> out_args;
for (const auto& arg : in_args)
Expand All @@ -38,11 +38,11 @@ std::vector<std::string> GetArgs(const CommandLine& cmdline) {
int main(int argc, char** argv) {
base::AtExitManager at_exit;
#if defined(OS_WIN)
CommandLine::set_slash_is_not_a_switch();
base::CommandLine::set_slash_is_not_a_switch();
#endif
CommandLine::Init(argc, argv);
base::CommandLine::Init(argc, argv);

const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
std::vector<std::string> args = GetArgs(cmdline);

std::string command;
Expand Down
9 changes: 5 additions & 4 deletions tools/gn/ninja_build_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::string GetSelfInvocationCommand(const BuildSettings* build_settings) {
base::FilePath executable;
PathService::Get(base::FILE_EXE, &executable);

CommandLine cmdline(executable.NormalizePathSeparatorsTo('/'));
base::CommandLine cmdline(executable.NormalizePathSeparatorsTo('/'));
cmdline.AppendArg("gen");
cmdline.AppendArg(build_settings->build_dir().value());
cmdline.AppendSwitchPath(std::string("--") + switches::kRoot,
Expand All @@ -52,9 +52,10 @@ std::string GetSelfInvocationCommand(const BuildSettings* build_settings) {
escape_shell.inhibit_quoting = true;
#endif

const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess();
const CommandLine::SwitchMap& switches = our_cmdline.GetSwitches();
for (CommandLine::SwitchMap::const_iterator i = switches.begin();
const base::CommandLine& our_cmdline =
*base::CommandLine::ForCurrentProcess();
const base::CommandLine::SwitchMap& switches = our_cmdline.GetSwitches();
for (base::CommandLine::SwitchMap::const_iterator i = switches.begin();
i != switches.end(); ++i) {
// Only write arguments we haven't already written. Always skip "args"
// since those will have been written to the file and will be used
Expand Down
3 changes: 2 additions & 1 deletion tools/gn/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace {

int GetThreadCount() {
std::string thread_count =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kThreads);
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kThreads);

int result;
if (thread_count.empty() || !base::StringToInt(thread_count, &result))
Expand Down
10 changes: 5 additions & 5 deletions tools/gn/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool CommonSetup::RunPostMessageLoop() {
}

// Write out tracing and timing if requested.
const CommandLine* cmdline = CommandLine::ForCurrentProcess();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(switches::kTime))
PrintLongHelp(SummarizeTraces());
if (cmdline->HasSwitch(switches::kTracelog))
Expand Down Expand Up @@ -231,7 +231,7 @@ Setup::~Setup() {
}

bool Setup::DoSetup(const std::string& build_dir, bool force_create) {
CommandLine* cmdline = CommandLine::ForCurrentProcess();
base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();

scheduler_.set_verbose_logging(cmdline->HasSwitch(switches::kVerbose));
if (cmdline->HasSwitch(switches::kTime) ||
Expand Down Expand Up @@ -282,7 +282,7 @@ SourceFile Setup::GetBuildArgFile() const {
return SourceFile(build_settings_.build_dir().value() + kBuildArgFileName);
}

bool Setup::FillArguments(const CommandLine& cmdline) {
bool Setup::FillArguments(const base::CommandLine& cmdline) {
// Use the args on the command line if specified, and save them. Do this even
// if the list is empty (this means clear any defaults).
if (cmdline.HasSwitch(switches::kArgs)) {
Expand Down Expand Up @@ -397,7 +397,7 @@ bool Setup::SaveArgsToFile() {
return true;
}

bool Setup::FillSourceDir(const CommandLine& cmdline) {
bool Setup::FillSourceDir(const base::CommandLine& cmdline) {
// Find the .gn file.
base::FilePath root_path;

Expand Down Expand Up @@ -542,7 +542,7 @@ bool Setup::RunConfigFile() {
return true;
}

bool Setup::FillOtherConfig(const CommandLine& cmdline) {
bool Setup::FillOtherConfig(const base::CommandLine& cmdline) {
Err err;

// Secondary source path, read from the config file if present.
Expand Down
2 changes: 1 addition & 1 deletion tools/gn/trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void ScopedTrace::SetToolchain(const Label& label) {
item_->set_toolchain(label.GetUserVisibleName(false));
}

void ScopedTrace::SetCommandLine(const CommandLine& cmdline) {
void ScopedTrace::SetCommandLine(const base::CommandLine& cmdline) {
if (item_)
item_->set_cmdline(FilePathToUTF8(cmdline.GetArgumentsString()));
}
Expand Down
7 changes: 4 additions & 3 deletions tools/imagediff/image_diff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ base::FilePath FilePathFromASCII(const std::string& str) {

int main(int argc, const char* argv[]) {
base::EnableTerminationOnHeapCorruption();
CommandLine::Init(argc, argv);
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
base::CommandLine::Init(argc, argv);
const base::CommandLine& parsed_command_line =
*base::CommandLine::ForCurrentProcess();
bool histograms = parsed_command_line.HasSwitch(kOptionCompareHistograms);
if (parsed_command_line.HasSwitch(kOptionPollStdin)) {
// Watch stdin for filenames.
Expand All @@ -432,7 +433,7 @@ int main(int argc, const char* argv[]) {
return 0;
}

const CommandLine::StringVector& args = parsed_command_line.GetArgs();
const base::CommandLine::StringVector& args = parsed_command_line.GetArgs();
if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) {
if (args.size() == 3) {
return DiffImages(base::FilePath(args[0]),
Expand Down
6 changes: 3 additions & 3 deletions tools/ipc_fuzzer/mutate/generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1285,9 +1285,9 @@ static const char kCountSwitch[] = "count";
static const char kHelpSwitch[] = "help";

int GenerateMain(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cmd = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = cmd->GetArgs();
base::CommandLine::Init(argc, argv);
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = cmd->GetArgs();

if (args.size() != 1 || cmd->HasSwitch(kHelpSwitch)) {
std::cerr << "Usage: ipc_fuzzer_generate [--help] [--count=n] outfile\n";
Expand Down
6 changes: 3 additions & 3 deletions tools/ipc_fuzzer/mutate/message_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ bool MessageMatches(const IPC::Message* msg, const RE2& pattern) {
} // namespace

int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cmd = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = cmd->GetArgs();
base::CommandLine::Init(argc, argv);
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = cmd->GetArgs();

if (args.size() < 1 || args.size() > 2 || cmd->HasSwitch(kHelpSwitch)) {
usage();
Expand Down
6 changes: 3 additions & 3 deletions tools/ipc_fuzzer/mutate/mutate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ void usage() {
} // namespace

int MutateMain(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cmd = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = cmd->GetArgs();
base::CommandLine::Init(argc, argv);
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = cmd->GetArgs();

if (args.size() != 2 || cmd->HasSwitch(kHelpSwitch)) {
usage();
Expand Down
13 changes: 7 additions & 6 deletions tools/ipc_fuzzer/replay/replay_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ ReplayProcess::~ReplayProcess() {
}

bool ReplayProcess::Initialize(int argc, const char** argv) {
CommandLine::Init(argc, argv);
base::CommandLine::Init(argc, argv);

if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kIpcFuzzerTestcase)) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kIpcFuzzerTestcase)) {
LOG(ERROR) << "This binary shouldn't be executed directly, "
<< "please use tools/ipc_fuzzer/play_testcase.py";
return false;
Expand All @@ -52,7 +52,7 @@ bool ReplayProcess::Initialize(int argc, const char** argv) {

void ReplayProcess::OpenChannel() {
std::string channel_name =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);

channel_ = IPC::ChannelProxy::Create(channel_name,
Expand All @@ -62,8 +62,9 @@ void ReplayProcess::OpenChannel() {
}

bool ReplayProcess::OpenTestcase() {
base::FilePath path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kIpcFuzzerTestcase);
base::FilePath path =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kIpcFuzzerTestcase);
return MessageFile::Read(path, &messages_);
}

Expand Down
7 changes: 4 additions & 3 deletions tools/perf/clear_system_cache/clear_system_cache_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ void ClearCacheForFile(const base::FilePath& path) {
}

int main(int argc, const char* argv[]) {
CommandLine::Init(argc, argv);
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
base::CommandLine::Init(argc, argv);
const base::CommandLine& parsed_command_line =
*base::CommandLine::ForCurrentProcess();
bool should_recurse = parsed_command_line.HasSwitch("recurse");
const CommandLine::StringVector& args = parsed_command_line.GetArgs();
const base::CommandLine::StringVector& args = parsed_command_line.GetArgs();

if (args.size() < 1) {
printf("USAGE: %s [--recurse] <files or directories>\n", argv[0]);
Expand Down
Loading

0 comments on commit 6b10fd0

Please sign in to comment.