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

Side by Side Diff: tools/gn/gn_main.cc

Issue 46003002: Add a target in GN that generates a last_change.h file for the SVN revision. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
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 "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"
12
13 // Only the GN-generated build makes this header for now.
viettrungluu 2013/11/06 18:39:22 Is this a TODO?
14 #if defined(GN_BUILD)
15 #include "build/util/last_change.h"
16 #else
17 #define LAST_CHANGE "UNKNOWN"
18 #endif
11 19
12 namespace { 20 namespace {
13 21
14 std::vector<std::string> GetArgs(const CommandLine& cmdline) { 22 std::vector<std::string> GetArgs(const CommandLine& cmdline) {
15 CommandLine::StringVector in_args = cmdline.GetArgs(); 23 CommandLine::StringVector in_args = cmdline.GetArgs();
16 #if defined(OS_WIN) 24 #if defined(OS_WIN)
17 std::vector<std::string> out_args; 25 std::vector<std::string> out_args;
18 for (size_t i = 0; i < in_args.size(); i++) 26 for (size_t i = 0; i < in_args.size(); i++)
19 out_args.push_back(base::WideToUTF8(in_args[i])); 27 out_args.push_back(base::WideToUTF8(in_args[i]));
20 return out_args; 28 return out_args;
(...skipping 11 matching lines...) Expand all
32 #endif 40 #endif
33 CommandLine::Init(argc, argv); 41 CommandLine::Init(argc, argv);
34 42
35 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); 43 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
36 std::vector<std::string> args = GetArgs(cmdline); 44 std::vector<std::string> args = GetArgs(cmdline);
37 45
38 std::string command; 46 std::string command;
39 if (cmdline.HasSwitch("help")) { 47 if (cmdline.HasSwitch("help")) {
40 // Make "--help" default to help command. 48 // Make "--help" default to help command.
41 command = commands::kHelp; 49 command = commands::kHelp;
50 } else if (cmdline.HasSwitch("version")) {
51 // Make "--version" print the version and exit.
52 OutputString(std::string(LAST_CHANGE) + "\n");
53 exit(0);
42 } else if (args.empty()) { 54 } else if (args.empty()) {
43 command = commands::kGen; 55 command = commands::kGen;
44 } else { 56 } else {
45 command = args[0]; 57 command = args[0];
46 args.erase(args.begin()); 58 args.erase(args.begin());
47 } 59 }
48 60
49 const commands::CommandInfoMap& command_map = commands::GetCommands(); 61 const commands::CommandInfoMap& command_map = commands::GetCommands();
50 commands::CommandInfoMap::const_iterator found_command = 62 commands::CommandInfoMap::const_iterator found_command =
51 command_map.find(command); 63 command_map.find(command);
52 64
53 int retval; 65 int retval;
54 if (found_command != command_map.end()) { 66 if (found_command != command_map.end()) {
55 retval = found_command->second.runner(args); 67 retval = found_command->second.runner(args);
56 } else { 68 } else {
57 Err(Location(), 69 Err(Location(),
58 "Command \"" + command + "\" unknown.").PrintToStdout(); 70 "Command \"" + command + "\" unknown.").PrintToStdout();
59 commands::RunHelp(std::vector<std::string>()); 71 commands::RunHelp(std::vector<std::string>());
60 retval = 1; 72 retval = 1;
61 } 73 }
62 74
63 exit(retval); // Don't free memory, it can be really slow! 75 exit(retval); // Don't free memory, it can be really slow!
64 return retval; 76 return retval;
65 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698