Chromium Code Reviews| Index: tools/gn/gn_main.cc |
| diff --git a/tools/gn/gn_main.cc b/tools/gn/gn_main.cc |
| index c0300caff810ffe3b67fd2fd1f3ee1a3dc6adcdd..061f1990dbbb504fbdc1dd99f03eb23db338ad6a 100644 |
| --- a/tools/gn/gn_main.cc |
| +++ b/tools/gn/gn_main.cc |
| @@ -5,21 +5,46 @@ |
| #include "base/at_exit.h" |
| #include "base/command_line.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "build/build_config.h" |
| #include "tools/gn/commands.h" |
| #include "tools/gn/err.h" |
| #include "tools/gn/location.h" |
| +#if defined(OS_WIN) |
| +#include <windows.h> |
| +#include <shellapi.h> |
| +#endif |
| + |
| namespace { |
| std::vector<std::string> GetArgs(const CommandLine& cmdline) { |
| - CommandLine::StringVector in_args = cmdline.GetArgs(); |
| #if defined(OS_WIN) |
| + // On Windows our command line parser treats things starting with slashes as |
| + // switches. This makes it impossible to type label names like "//foo:bar". |
|
scottmg
2013/09/25 17:23:23
seems like it'd be a useful option for CommandLine
|
| + // |
| + // Here, we manually extract the args, looking only for ones beginning with |
| + // hyphens to behave more like Posix. |
| + int num_args = 0; |
| + wchar_t** args = NULL; |
| + args = ::CommandLineToArgvW(::GetCommandLineW(), &num_args); |
| + |
| + bool found_switch_terminator = false; |
| std::vector<std::string> out_args; |
| - for (size_t i = 0; i < in_args.size(); i++) |
| - out_args.push_back(base::WideToUTF8(in_args[i])); |
| + for (int i = 1; i < num_args; i++) { |
| + if (args[i][0] == '-' && args[i][1] == '-' && args[i][2] == 0) { |
| + // Found a bare "--" argument, treat everything following as args. |
| + found_switch_terminator = true; |
| + continue; |
| + } |
| + if (found_switch_terminator || args[i][0] != '-') |
| + out_args.push_back(base::WideToUTF8(args[i])); |
| + } |
| + |
| + ::LocalFree(args); |
| return out_args; |
| + |
| #else |
| - return in_args; |
| + return cmdline.GetArgs(); |
| #endif |
| } |