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

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

Issue 1570113002: Visual Studio generators for GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests failing on non-Windows platforms Created 4 years, 10 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
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/atomicops.h" 5 #include "base/atomicops.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/timer/elapsed_timer.h" 10 #include "base/timer/elapsed_timer.h"
11 #include "tools/gn/build_settings.h" 11 #include "tools/gn/build_settings.h"
12 #include "tools/gn/commands.h" 12 #include "tools/gn/commands.h"
13 #include "tools/gn/ninja_target_writer.h" 13 #include "tools/gn/ninja_target_writer.h"
14 #include "tools/gn/ninja_writer.h" 14 #include "tools/gn/ninja_writer.h"
15 #include "tools/gn/runtime_deps.h" 15 #include "tools/gn/runtime_deps.h"
16 #include "tools/gn/scheduler.h" 16 #include "tools/gn/scheduler.h"
17 #include "tools/gn/setup.h" 17 #include "tools/gn/setup.h"
18 #include "tools/gn/standard_out.h" 18 #include "tools/gn/standard_out.h"
19 #include "tools/gn/switches.h" 19 #include "tools/gn/switches.h"
20 #include "tools/gn/target.h" 20 #include "tools/gn/target.h"
21 #include "tools/gn/visual_studio_writer.h"
21 22
22 namespace commands { 23 namespace commands {
23 24
24 namespace { 25 namespace {
25 26
26 const char kSwitchCheck[] = "check"; 27 const char kSwitchCheck[] = "check";
28 const char kSwitchIde[] = "ide";
29 const char kSwitchIdeValueVs[] = "vs";
27 30
28 // Called on worker thread to write the ninja file. 31 // Called on worker thread to write the ninja file.
29 void BackgroundDoWrite(const Target* target) { 32 void BackgroundDoWrite(const Target* target) {
30 NinjaTargetWriter::RunAndWriteFile(target); 33 NinjaTargetWriter::RunAndWriteFile(target);
31 g_scheduler->DecrementWorkCount(); 34 g_scheduler->DecrementWorkCount();
32 } 35 }
33 36
34 // Called on the main thread. 37 // Called on the main thread.
35 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, 38 void ItemResolvedCallback(base::subtle::Atomic32* write_counter,
36 scoped_refptr<Builder> builder, 39 scoped_refptr<Builder> builder,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 "you think a dependency chain exists, it might be\nbecause the chain " 140 "you think a dependency chain exists, it might be\nbecause the chain "
138 "is private. Try \"gn path\" to analyze.\n"); 141 "is private. Try \"gn path\" to analyze.\n");
139 142
140 if (errors_found > 1) { 143 if (errors_found > 1) {
141 OutputString(base::StringPrintf("\n%d generated input errors found.\n", 144 OutputString(base::StringPrintf("\n%d generated input errors found.\n",
142 errors_found), DECORATION_YELLOW); 145 errors_found), DECORATION_YELLOW);
143 } 146 }
144 return false; 147 return false;
145 } 148 }
146 149
150 bool RunIdeWriter(const std::string& ide,
151 const BuildSettings* build_settings,
152 Builder* builder,
153 Err* err) {
154 if (ide == kSwitchIdeValueVs) {
155 base::TimeTicks begin_vs_gen = base::TimeTicks::Now();
tfarina 2016/01/29 16:30:12 Have you considered using base::ElapsedTimer here
Daniel Bratell 2016/01/29 16:41:21 I was not aware of base::ElapsedTimer so I used wh
Tomasz Moniuszko 2016/02/01 13:51:12 https://codereview.chromium.org/1651113002/
156 bool res =
157 VisualStudioWriter::RunAndWriteFiles(build_settings, builder, err);
158 if (res &&
159 !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) {
160 OutputString(
161 "Generating Visual Studio projects took " +
162 base::Int64ToString(
163 (base::TimeTicks::Now() - begin_vs_gen).InMilliseconds()) +
164 "ms\n");
165 }
166 return res;
167 }
168
169 *err = Err(Location(), "Unknown IDE: " + ide);
170 return false;
171 }
172
147 } // namespace 173 } // namespace
148 174
149 const char kGen[] = "gen"; 175 const char kGen[] = "gen";
150 const char kGen_HelpShort[] = 176 const char kGen_HelpShort[] =
151 "gen: Generate ninja files."; 177 "gen: Generate ninja files.";
152 const char kGen_Help[] = 178 const char kGen_Help[] =
153 "gn gen: Generate ninja files.\n" 179 "gn gen: Generate ninja files.\n"
154 "\n" 180 "\n"
155 " gn gen <out_dir>\n" 181 " gn gen [--ide=<ide_name>] <out_dir>\n"
156 "\n" 182 "\n"
157 " Generates ninja files from the current tree and puts them in the given\n" 183 " Generates ninja files from the current tree and puts them in the given\n"
158 " output directory.\n" 184 " output directory.\n"
159 "\n" 185 "\n"
160 " The output directory can be a source-repo-absolute path name such as:\n" 186 " The output directory can be a source-repo-absolute path name such as:\n"
161 " //out/foo\n" 187 " //out/foo\n"
162 " Or it can be a directory relative to the current directory such as:\n" 188 " Or it can be a directory relative to the current directory such as:\n"
163 " out/foo\n" 189 " out/foo\n"
164 "\n" 190 "\n"
191 " --ide=<ide_name>\n"
192 " Also generate files for an IDE. Currently supported values:\n"
193 " 'vs' - Visual Studio project/solution files.\n"
194 "\n"
165 " See \"gn help switches\" for the common command-line switches.\n"; 195 " See \"gn help switches\" for the common command-line switches.\n";
166 196
167 int RunGen(const std::vector<std::string>& args) { 197 int RunGen(const std::vector<std::string>& args) {
168 base::ElapsedTimer timer; 198 base::ElapsedTimer timer;
169 199
170 if (args.size() != 1) { 200 if (args.size() != 1) {
171 Err(Location(), "Need exactly one build directory to generate.", 201 Err(Location(), "Need exactly one build directory to generate.",
172 "I expected something more like \"gn gen out/foo\"\n" 202 "I expected something more like \"gn gen out/foo\"\n"
173 "You can also see \"gn help gen\".").PrintToStdout(); 203 "You can also see \"gn help gen\".").PrintToStdout();
174 return 1; 204 return 1;
175 } 205 }
176 206
177 // Deliberately leaked to avoid expensive process teardown. 207 // Deliberately leaked to avoid expensive process teardown.
178 Setup* setup = new Setup(); 208 Setup* setup = new Setup();
179 if (!setup->DoSetup(args[0], true)) 209 if (!setup->DoSetup(args[0], true))
180 return 1; 210 return 1;
181 211
182 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchCheck)) 212 const base::CommandLine* command_line =
213 base::CommandLine::ForCurrentProcess();
214 if (command_line->HasSwitch(kSwitchCheck))
183 setup->set_check_public_headers(true); 215 setup->set_check_public_headers(true);
184 216
185 // Cause the load to also generate the ninja files for each target. We wrap 217 // Cause the load to also generate the ninja files for each target. We wrap
186 // the writing to maintain a counter. 218 // the writing to maintain a counter.
187 base::subtle::Atomic32 write_counter = 0; 219 base::subtle::Atomic32 write_counter = 0;
188 setup->builder()->set_resolved_callback( 220 setup->builder()->set_resolved_callback(
189 base::Bind(&ItemResolvedCallback, &write_counter, 221 base::Bind(&ItemResolvedCallback, &write_counter,
190 scoped_refptr<Builder>(setup->builder()))); 222 scoped_refptr<Builder>(setup->builder())));
191 223
192 // Do the actual load. This will also write out the target ninja files. 224 // Do the actual load. This will also write out the target ninja files.
(...skipping 10 matching lines...) Expand all
203 } 235 }
204 236
205 if (!WriteRuntimeDepsFilesIfNecessary(*setup->builder(), &err)) { 237 if (!WriteRuntimeDepsFilesIfNecessary(*setup->builder(), &err)) {
206 err.PrintToStdout(); 238 err.PrintToStdout();
207 return 1; 239 return 1;
208 } 240 }
209 241
210 if (!CheckForInvalidGeneratedInputs(setup)) 242 if (!CheckForInvalidGeneratedInputs(setup))
211 return 1; 243 return 1;
212 244
245 if (command_line->HasSwitch(kSwitchIde) &&
246 !RunIdeWriter(command_line->GetSwitchValueASCII(kSwitchIde),
247 &setup->build_settings(), setup->builder(), &err)) {
248 err.PrintToStdout();
249 return 1;
250 }
251
213 base::TimeDelta elapsed_time = timer.Elapsed(); 252 base::TimeDelta elapsed_time = timer.Elapsed();
214 253
215 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) { 254 if (!command_line->HasSwitch(switches::kQuiet)) {
216 OutputString("Done. ", DECORATION_GREEN); 255 OutputString("Done. ", DECORATION_GREEN);
217 256
218 std::string stats = "Wrote " + 257 std::string stats = "Wrote " +
219 base::IntToString(static_cast<int>(write_counter)) + 258 base::IntToString(static_cast<int>(write_counter)) +
220 " targets from " + 259 " targets from " +
221 base::IntToString( 260 base::IntToString(
222 setup->scheduler().input_file_manager()->GetInputFileCount()) + 261 setup->scheduler().input_file_manager()->GetInputFileCount()) +
223 " files in " + 262 " files in " +
224 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; 263 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n";
225 OutputString(stats); 264 OutputString(stats);
226 } 265 }
227 266
228 return 0; 267 return 0;
229 } 268 }
230 269
231 } // namespace commands 270 } // namespace commands
OLDNEW
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/gn.gyp » ('j') | tools/gn/xml_element_writer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698