Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: tools/gn/gn_main.cc

Issue 24613003: Allow typing label names on Windows by not treating things that start with slashes as arguments rat… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/command_desc.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
}
« no previous file with comments | « tools/gn/command_desc.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698