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

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

Issue 265693003: Redo GN "args" command (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows Created 6 years, 7 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
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 "tools/gn/ninja_build_writer.h" 5 #include "tools/gn/ninja_build_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // The command line code quoting varies by platform. We have one string, 44 // The command line code quoting varies by platform. We have one string,
45 // possibly with spaces, that we want to quote. The Windows command line 45 // possibly with spaces, that we want to quote. The Windows command line
46 // quotes again, so we don't want quoting. The Posix one doesn't. 46 // quotes again, so we don't want quoting. The Posix one doesn't.
47 escape_shell.inhibit_quoting = true; 47 escape_shell.inhibit_quoting = true;
48 #endif 48 #endif
49 49
50 const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess(); 50 const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess();
51 const CommandLine::SwitchMap& switches = our_cmdline.GetSwitches(); 51 const CommandLine::SwitchMap& switches = our_cmdline.GetSwitches();
52 for (CommandLine::SwitchMap::const_iterator i = switches.begin(); 52 for (CommandLine::SwitchMap::const_iterator i = switches.begin();
53 i != switches.end(); ++i) { 53 i != switches.end(); ++i) {
54 if (i->first != "q" && i->first != "root") { 54 // Only write arguments we haven't already written. Always skip "args"
55 // since those will have been written to the file and will be used
56 // implicitly in the future. Keeping --args would mean changes to the file
57 // would be ignored.
58 if (i->first != "q" && i->first != "root" && i->first != "args") {
55 std::string escaped_value = 59 std::string escaped_value =
56 EscapeString(FilePathToUTF8(i->second), escape_shell, NULL); 60 EscapeString(FilePathToUTF8(i->second), escape_shell, NULL);
57 cmdline.AppendSwitchASCII(i->first, escaped_value); 61 cmdline.AppendSwitchASCII(i->first, escaped_value);
58 } 62 }
59 } 63 }
60 64
61 #if defined(OS_WIN) 65 #if defined(OS_WIN)
62 return base::WideToUTF8(cmdline.GetCommandLineString()); 66 return base::WideToUTF8(cmdline.GetCommandLineString());
63 #else 67 #else
64 return cmdline.GetCommandLineString(); 68 return cmdline.GetCommandLineString();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void NinjaBuildWriter::WriteNinjaRules() { 127 void NinjaBuildWriter::WriteNinjaRules() {
124 out_ << "rule gn\n"; 128 out_ << "rule gn\n";
125 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; 129 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n";
126 out_ << " description = Regenerating ninja files\n\n"; 130 out_ << " description = Regenerating ninja files\n\n";
127 131
128 // This rule will regenerate the ninja files when any input file has changed. 132 // This rule will regenerate the ninja files when any input file has changed.
129 out_ << "build build.ninja: gn\n" 133 out_ << "build build.ninja: gn\n"
130 << " generator = 1\n" 134 << " generator = 1\n"
131 << " depfile = build.ninja.d\n"; 135 << " depfile = build.ninja.d\n";
132 136
133 // Provide a way to force regenerating ninja files if the user is suspicious
134 // something is out-of-date. This will be "ninja refresh".
135 out_ << "\nbuild refresh: gn\n";
136
137 // Provide a way to see what flags are associated with this build:
138 // This will be "ninja show".
139 const CommandLine& our_cmdline = *CommandLine::ForCurrentProcess();
140 std::string args = our_cmdline.GetSwitchValueASCII("args");
141 out_ << "rule echo\n";
142 out_ << " command = echo $text\n";
143 out_ << " description = ECHO $desc\n";
144 out_ << "build show: echo\n";
145 out_ << " desc = build arguments:\n";
146 out_ << " text = "
147 << (args.empty() ? std::string("No build args, using defaults.") : args)
148 << "\n";
149
150 // Input build files. These go in the ".d" file. If we write them as 137 // Input build files. These go in the ".d" file. If we write them as
151 // dependencies in the .ninja file itself, ninja will expect the files to 138 // dependencies in the .ninja file itself, ninja will expect the files to
152 // exist and will error if they don't. When files are listed in a depfile, 139 // exist and will error if they don't. When files are listed in a depfile,
153 // missing files are ignored. 140 // missing files are ignored.
154 dep_out_ << "build.ninja:"; 141 dep_out_ << "build.ninja:";
155 std::vector<base::FilePath> input_files; 142 std::vector<base::FilePath> input_files;
156 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); 143 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files);
157 for (size_t i = 0; i < input_files.size(); i++) 144 for (size_t i = 0; i < input_files.size(); i++)
158 dep_out_ << " " << FilePathToUTF8(input_files[i]); 145 dep_out_ << " " << FilePathToUTF8(input_files[i]);
159 146
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 EscapeOptions ninja_escape; 244 EscapeOptions ninja_escape;
258 ninja_escape.mode = ESCAPE_NINJA; 245 ninja_escape.mode = ESCAPE_NINJA;
259 246
260 // Escape for special chars Ninja will handle. 247 // Escape for special chars Ninja will handle.
261 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); 248 std::string escaped = EscapeString(phony_name, ninja_escape, NULL);
262 249
263 out_ << "build " << escaped << ": phony "; 250 out_ << "build " << escaped << ": phony ";
264 path_output_.WriteFile(out_, target_file); 251 path_output_.WriteFile(out_, target_file);
265 out_ << std::endl; 252 out_ << std::endl;
266 } 253 }
OLDNEW
« tools/gn/args.cc ('K') | « tools/gn/gn.gyp ('k') | tools/gn/setup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698