diff options
-rw-r--r-- | base/command_line.cc | 16 | ||||
-rw-r--r-- | base/command_line.h | 11 | ||||
-rw-r--r-- | tools/gn/command_desc.cc | 2 | ||||
-rw-r--r-- | tools/gn/gn_main.cc | 3 |
4 files changed, 30 insertions, 2 deletions
diff --git a/base/command_line.cc b/base/command_line.cc index 36ac88f..7050242 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -27,17 +27,22 @@ CommandLine* CommandLine::current_process_commandline_ = NULL; namespace { const CommandLine::CharType kSwitchTerminator[] = FILE_PATH_LITERAL("--"); const CommandLine::CharType kSwitchValueSeparator[] = FILE_PATH_LITERAL("="); + // Since we use a lazy match, make sure that longer versions (like "--") are // listed before shorter versions (like "-") of similar prefixes. #if defined(OS_WIN) +// By putting slash last, we can control whether it is treaded as a switch +// value by changing the value of switch_prefix_count to be one less than +// the array size. const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"}; #elif defined(OS_POSIX) // Unixes don't use slash as a switch. const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"}; #endif +size_t switch_prefix_count = arraysize(kSwitchPrefixes); size_t GetSwitchPrefixLength(const CommandLine::StringType& string) { - for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) { + for (size_t i = 0; i < switch_prefix_count; ++i) { CommandLine::StringType prefix(kSwitchPrefixes[i]); if (string.compare(0, prefix.length(), prefix) == 0) return prefix.length(); @@ -169,6 +174,15 @@ CommandLine::CommandLine(const StringVector& argv) CommandLine::~CommandLine() { } +#if defined(OS_WIN) +// static +void CommandLine::set_slash_is_not_a_switch() { + // The last switch prefix should be slash, so adjust the size to skip it. + DCHECK(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/") == 0); + switch_prefix_count = arraysize(kSwitchPrefixes) - 1; +} +#endif + // static bool CommandLine::Init(int argc, const char* const* argv) { if (current_process_commandline_) { diff --git a/base/command_line.h b/base/command_line.h index ed46c4f..81bd4b7 100644 --- a/base/command_line.h +++ b/base/command_line.h @@ -53,6 +53,17 @@ class BASE_EXPORT CommandLine { ~CommandLine(); +#if defined(OS_WIN) + // By default this class will treat command-line arguments beginning with + // slashes as switches on Windows, but not other platforms. + // + // If this behavior is inappropriate for your application, you can call this + // function BEFORE initializing the current process' global command line + // object and the behavior will be the same as Posix systems (only hyphens + // begin switches, everything else will be an arg). + static void set_slash_is_not_a_switch(); +#endif + // Initialize the current process CommandLine singleton. On Windows, ignores // its arguments (we instead parse GetCommandLineW() directly) because we // don't trust the CRT's parsing of the command line, but it still must be diff --git a/tools/gn/command_desc.cc b/tools/gn/command_desc.cc index 2f02689..fbcf97d 100644 --- a/tools/gn/command_desc.cc +++ b/tools/gn/command_desc.cc @@ -212,11 +212,11 @@ template<typename T> void OutputRecursiveTargetConfig( if (config) { // Source of this value is a config. out << " From " << config->label().GetUserVisibleName(false) << "\n"; + OutputSourceOfDep(target, config->label(), out); } else { // Source of this value is the target itself. out << " From " << target->label().GetUserVisibleName(false) << "\n"; } - OutputSourceOfDep(target, config->label(), out); } // Actual values. diff --git a/tools/gn/gn_main.cc b/tools/gn/gn_main.cc index c0300ca..9c86ab5 100644 --- a/tools/gn/gn_main.cc +++ b/tools/gn/gn_main.cc @@ -27,6 +27,9 @@ 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(); +#endif CommandLine::Init(argc, argv); const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |