 Chromium Code Reviews
 Chromium Code Reviews Issue 1570113002:
  Visual Studio generators for GN  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1570113002:
  Visual Studio generators for GN  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/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 Loading... | |
| 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(); | |
| 156 bool res = | |
| 157 VisualStudioWriter::RunAndWriteFiles(build_settings, builder, err); | |
| 158 if (res) { | |
| 159 OutputString("Generating Visual Studio projects took " + | |
| 
Daniel Bratell
2016/01/25 14:06:52
I know I did this so it's not your fault, but I se
 
Tomasz Moniuszko
2016/01/28 15:06:58
Done.
 | |
| 160 base::Int64ToString((base::TimeTicks::Now() - begin_vs_gen) | |
| 161 .InMilliseconds()) + | |
| 162 "ms\n"); | |
| 163 } | |
| 164 return res; | |
| 165 } | |
| 166 | |
| 167 *err = Err(Location(), "Unknown IDE: " + ide); | |
| 168 return false; | |
| 169 } | |
| 170 | |
| 147 } // namespace | 171 } // namespace | 
| 148 | 172 | 
| 149 const char kGen[] = "gen"; | 173 const char kGen[] = "gen"; | 
| 150 const char kGen_HelpShort[] = | 174 const char kGen_HelpShort[] = | 
| 151 "gen: Generate ninja files."; | 175 "gen: Generate ninja files."; | 
| 152 const char kGen_Help[] = | 176 const char kGen_Help[] = | 
| 153 "gn gen: Generate ninja files.\n" | 177 "gn gen: Generate ninja files.\n" | 
| 154 "\n" | 178 "\n" | 
| 155 " gn gen <out_dir>\n" | 179 " gn gen [--ide=<ide_name>] <out_dir>\n" | 
| 156 "\n" | 180 "\n" | 
| 157 " Generates ninja files from the current tree and puts them in the given\n" | 181 " Generates ninja files from the current tree and puts them in the given\n" | 
| 158 " output directory.\n" | 182 " output directory.\n" | 
| 159 "\n" | 183 "\n" | 
| 160 " The output directory can be a source-repo-absolute path name such as:\n" | 184 " The output directory can be a source-repo-absolute path name such as:\n" | 
| 161 " //out/foo\n" | 185 " //out/foo\n" | 
| 162 " Or it can be a directory relative to the current directory such as:\n" | 186 " Or it can be a directory relative to the current directory such as:\n" | 
| 163 " out/foo\n" | 187 " out/foo\n" | 
| 164 "\n" | 188 "\n" | 
| 189 " --ide=<ide_name>\n" | |
| 190 " Also generate files for an IDE. Currently supported values:\n" | |
| 191 " 'vs' - Visual Studio project/solution files.\n" | |
| 192 "\n" | |
| 165 " See \"gn help switches\" for the common command-line switches.\n"; | 193 " See \"gn help switches\" for the common command-line switches.\n"; | 
| 166 | 194 | 
| 167 int RunGen(const std::vector<std::string>& args) { | 195 int RunGen(const std::vector<std::string>& args) { | 
| 168 base::ElapsedTimer timer; | 196 base::ElapsedTimer timer; | 
| 169 | 197 | 
| 170 if (args.size() != 1) { | 198 if (args.size() != 1) { | 
| 171 Err(Location(), "Need exactly one build directory to generate.", | 199 Err(Location(), "Need exactly one build directory to generate.", | 
| 172 "I expected something more like \"gn gen out/foo\"\n" | 200 "I expected something more like \"gn gen out/foo\"\n" | 
| 173 "You can also see \"gn help gen\".").PrintToStdout(); | 201 "You can also see \"gn help gen\".").PrintToStdout(); | 
| 174 return 1; | 202 return 1; | 
| 175 } | 203 } | 
| 176 | 204 | 
| 177 // Deliberately leaked to avoid expensive process teardown. | 205 // Deliberately leaked to avoid expensive process teardown. | 
| 178 Setup* setup = new Setup(); | 206 Setup* setup = new Setup(); | 
| 179 if (!setup->DoSetup(args[0], true)) | 207 if (!setup->DoSetup(args[0], true)) | 
| 180 return 1; | 208 return 1; | 
| 181 | 209 | 
| 182 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchCheck)) | 210 const base::CommandLine* command_line = | 
| 211 base::CommandLine::ForCurrentProcess(); | |
| 212 if (command_line->HasSwitch(kSwitchCheck)) | |
| 183 setup->set_check_public_headers(true); | 213 setup->set_check_public_headers(true); | 
| 184 | 214 | 
| 185 // Cause the load to also generate the ninja files for each target. We wrap | 215 // Cause the load to also generate the ninja files for each target. We wrap | 
| 186 // the writing to maintain a counter. | 216 // the writing to maintain a counter. | 
| 187 base::subtle::Atomic32 write_counter = 0; | 217 base::subtle::Atomic32 write_counter = 0; | 
| 188 setup->builder()->set_resolved_callback( | 218 setup->builder()->set_resolved_callback( | 
| 189 base::Bind(&ItemResolvedCallback, &write_counter, | 219 base::Bind(&ItemResolvedCallback, &write_counter, | 
| 190 scoped_refptr<Builder>(setup->builder()))); | 220 scoped_refptr<Builder>(setup->builder()))); | 
| 191 | 221 | 
| 192 // Do the actual load. This will also write out the target ninja files. | 222 // Do the actual load. This will also write out the target ninja files. | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 203 } | 233 } | 
| 204 | 234 | 
| 205 if (!WriteRuntimeDepsFilesIfNecessary(*setup->builder(), &err)) { | 235 if (!WriteRuntimeDepsFilesIfNecessary(*setup->builder(), &err)) { | 
| 206 err.PrintToStdout(); | 236 err.PrintToStdout(); | 
| 207 return 1; | 237 return 1; | 
| 208 } | 238 } | 
| 209 | 239 | 
| 210 if (!CheckForInvalidGeneratedInputs(setup)) | 240 if (!CheckForInvalidGeneratedInputs(setup)) | 
| 211 return 1; | 241 return 1; | 
| 212 | 242 | 
| 243 if (command_line->HasSwitch(kSwitchIde) && | |
| 244 !RunIdeWriter(command_line->GetSwitchValueASCII(kSwitchIde), | |
| 245 &setup->build_settings(), setup->builder(), &err)) { | |
| 246 err.PrintToStdout(); | |
| 247 return 1; | |
| 248 } | |
| 249 | |
| 213 base::TimeDelta elapsed_time = timer.Elapsed(); | 250 base::TimeDelta elapsed_time = timer.Elapsed(); | 
| 214 | 251 | 
| 215 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) { | 252 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) { | 
| 
Daniel Bratell
2016/01/25 14:06:52
base::CommandLine::ForCurrentProcess() is now stor
 
Tomasz Moniuszko
2016/01/28 15:06:58
Done.
 | |
| 216 OutputString("Done. ", DECORATION_GREEN); | 253 OutputString("Done. ", DECORATION_GREEN); | 
| 217 | 254 | 
| 218 std::string stats = "Wrote " + | 255 std::string stats = "Wrote " + | 
| 219 base::IntToString(static_cast<int>(write_counter)) + | 256 base::IntToString(static_cast<int>(write_counter)) + | 
| 220 " targets from " + | 257 " targets from " + | 
| 221 base::IntToString( | 258 base::IntToString( | 
| 222 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 259 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 
| 223 " files in " + | 260 " files in " + | 
| 224 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; | 261 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; | 
| 225 OutputString(stats); | 262 OutputString(stats); | 
| 226 } | 263 } | 
| 227 | 264 | 
| 228 return 0; | 265 return 0; | 
| 229 } | 266 } | 
| 230 | 267 | 
| 231 } // namespace commands | 268 } // namespace commands | 
| OLD | NEW |