OLD | NEW |
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 "tools/gn/commands.h" | 8 #include "tools/gn/commands.h" |
9 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
10 #include "tools/gn/location.h" | 10 #include "tools/gn/location.h" |
11 #include "tools/gn/standard_out.h" | 11 #include "tools/gn/standard_out.h" |
12 #include "tools/gn/switches.h" | 12 #include "tools/gn/switches.h" |
13 | 13 |
14 // Only the GN-generated build makes this header for now. | 14 // Only the GN-generated build makes this header for now. |
15 // TODO(brettw) consider adding this if we need it in GYP. | 15 // TODO(brettw) consider adding this if we need it in GYP. |
16 #if defined(GN_BUILD) | 16 #if defined(GN_BUILD) |
17 #include "tools/gn/last_commit_position.h" | 17 #include "tools/gn/last_commit_position.h" |
18 #else | 18 #else |
19 #define LAST_COMMIT_POSITION "UNKNOWN" | 19 #define LAST_COMMIT_POSITION "UNKNOWN" |
20 #endif | 20 #endif |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 std::vector<std::string> GetArgs(const CommandLine& cmdline) { | 24 std::vector<std::string> GetArgs(const base::CommandLine& cmdline) { |
25 CommandLine::StringVector in_args = cmdline.GetArgs(); | 25 base::CommandLine::StringVector in_args = cmdline.GetArgs(); |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 std::vector<std::string> out_args; | 27 std::vector<std::string> out_args; |
28 for (const auto& arg : in_args) | 28 for (const auto& arg : in_args) |
29 out_args.push_back(base::WideToUTF8(arg)); | 29 out_args.push_back(base::WideToUTF8(arg)); |
30 return out_args; | 30 return out_args; |
31 #else | 31 #else |
32 return in_args; | 32 return in_args; |
33 #endif | 33 #endif |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 int main(int argc, char** argv) { | 38 int main(int argc, char** argv) { |
39 base::AtExitManager at_exit; | 39 base::AtExitManager at_exit; |
40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
41 CommandLine::set_slash_is_not_a_switch(); | 41 base::CommandLine::set_slash_is_not_a_switch(); |
42 #endif | 42 #endif |
43 CommandLine::Init(argc, argv); | 43 base::CommandLine::Init(argc, argv); |
44 | 44 |
45 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 45 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess(); |
46 std::vector<std::string> args = GetArgs(cmdline); | 46 std::vector<std::string> args = GetArgs(cmdline); |
47 | 47 |
48 std::string command; | 48 std::string command; |
49 if (cmdline.HasSwitch("help") || cmdline.HasSwitch("h")) { | 49 if (cmdline.HasSwitch("help") || cmdline.HasSwitch("h")) { |
50 // Make "-h" and "--help" default to help command. | 50 // Make "-h" and "--help" default to help command. |
51 command = commands::kHelp; | 51 command = commands::kHelp; |
52 } else if (cmdline.HasSwitch(switches::kVersion)) { | 52 } else if (cmdline.HasSwitch(switches::kVersion)) { |
53 // Make "--version" print the version and exit. | 53 // Make "--version" print the version and exit. |
54 OutputString(std::string(LAST_COMMIT_POSITION) + "\n"); | 54 OutputString(std::string(LAST_COMMIT_POSITION) + "\n"); |
55 exit(0); | 55 exit(0); |
(...skipping 17 matching lines...) Expand all Loading... |
73 retval = found_command->second.runner(args); | 73 retval = found_command->second.runner(args); |
74 } else { | 74 } else { |
75 Err(Location(), | 75 Err(Location(), |
76 "Command \"" + command + "\" unknown.").PrintToStdout(); | 76 "Command \"" + command + "\" unknown.").PrintToStdout(); |
77 commands::RunHelp(std::vector<std::string>()); | 77 commands::RunHelp(std::vector<std::string>()); |
78 retval = 1; | 78 retval = 1; |
79 } | 79 } |
80 | 80 |
81 exit(retval); // Don't free memory, it can be really slow! | 81 exit(retval); // Don't free memory, it can be really slow! |
82 } | 82 } |
OLD | NEW |