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