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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/command_desc.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "build/build_config.h"
8 #include "tools/gn/commands.h" 9 #include "tools/gn/commands.h"
9 #include "tools/gn/err.h" 10 #include "tools/gn/err.h"
10 #include "tools/gn/location.h" 11 #include "tools/gn/location.h"
11 12
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #include <shellapi.h>
16 #endif
17
12 namespace { 18 namespace {
13 19
14 std::vector<std::string> GetArgs(const CommandLine& cmdline) { 20 std::vector<std::string> GetArgs(const CommandLine& cmdline) {
15 CommandLine::StringVector in_args = cmdline.GetArgs();
16 #if defined(OS_WIN) 21 #if defined(OS_WIN)
22 // On Windows our command line parser treats things starting with slashes as
23 // 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
24 //
25 // Here, we manually extract the args, looking only for ones beginning with
26 // hyphens to behave more like Posix.
27 int num_args = 0;
28 wchar_t** args = NULL;
29 args = ::CommandLineToArgvW(::GetCommandLineW(), &num_args);
30
31 bool found_switch_terminator = false;
17 std::vector<std::string> out_args; 32 std::vector<std::string> out_args;
18 for (size_t i = 0; i < in_args.size(); i++) 33 for (int i = 1; i < num_args; i++) {
19 out_args.push_back(base::WideToUTF8(in_args[i])); 34 if (args[i][0] == '-' && args[i][1] == '-' && args[i][2] == 0) {
35 // Found a bare "--" argument, treat everything following as args.
36 found_switch_terminator = true;
37 continue;
38 }
39 if (found_switch_terminator || args[i][0] != '-')
40 out_args.push_back(base::WideToUTF8(args[i]));
41 }
42
43 ::LocalFree(args);
20 return out_args; 44 return out_args;
45
21 #else 46 #else
22 return in_args; 47 return cmdline.GetArgs();
23 #endif 48 #endif
24 } 49 }
25 50
26 } // namespace 51 } // namespace
27 52
28 int main(int argc, char** argv) { 53 int main(int argc, char** argv) {
29 base::AtExitManager at_exit; 54 base::AtExitManager at_exit;
30 CommandLine::Init(argc, argv); 55 CommandLine::Init(argc, argv);
31 56
32 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); 57 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
(...skipping 20 matching lines...) Expand all
53 } else { 78 } else {
54 Err(Location(), 79 Err(Location(),
55 "Command \"" + command + "\" unknown.").PrintToStdout(); 80 "Command \"" + command + "\" unknown.").PrintToStdout();
56 commands::RunHelp(std::vector<std::string>()); 81 commands::RunHelp(std::vector<std::string>());
57 retval = 1; 82 retval = 1;
58 } 83 }
59 84
60 exit(retval); // Don't free memory, it can be really slow! 85 exit(retval); // Don't free memory, it can be really slow!
61 return retval; 86 return retval;
62 } 87 }
OLDNEW
« 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