| 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/eclipse_writer.h" | 13 #include "tools/gn/eclipse_writer.h" |
| 14 #include "tools/gn/ninja_target_writer.h" | 14 #include "tools/gn/ninja_target_writer.h" |
| 15 #include "tools/gn/ninja_writer.h" | 15 #include "tools/gn/ninja_writer.h" |
| 16 #include "tools/gn/runtime_deps.h" | 16 #include "tools/gn/runtime_deps.h" |
| 17 #include "tools/gn/scheduler.h" | 17 #include "tools/gn/scheduler.h" |
| 18 #include "tools/gn/setup.h" | 18 #include "tools/gn/setup.h" |
| 19 #include "tools/gn/standard_out.h" | 19 #include "tools/gn/standard_out.h" |
| 20 #include "tools/gn/switches.h" | 20 #include "tools/gn/switches.h" |
| 21 #include "tools/gn/target.h" | 21 #include "tools/gn/target.h" |
| 22 #include "tools/gn/visual_studio_writer.h" | 22 #include "tools/gn/visual_studio_writer.h" |
| 23 | 23 |
| 24 namespace commands { | 24 namespace commands { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kSwitchCheck[] = "check"; | 28 const char kSwitchCheck[] = "check"; |
| 29 const char kSwitchFilters[] = "filters"; |
| 29 const char kSwitchIde[] = "ide"; | 30 const char kSwitchIde[] = "ide"; |
| 30 const char kSwitchIdeValueEclipse[] = "eclipse"; | 31 const char kSwitchIdeValueEclipse[] = "eclipse"; |
| 31 const char kSwitchIdeValueVs[] = "vs"; | 32 const char kSwitchIdeValueVs[] = "vs"; |
| 32 const char kSwitchIdeValueVs2013[] = "vs2013"; | 33 const char kSwitchIdeValueVs2013[] = "vs2013"; |
| 33 const char kSwitchIdeValueVs2015[] = "vs2015"; | 34 const char kSwitchIdeValueVs2015[] = "vs2015"; |
| 35 const char kSwitchSln[] = "sln"; |
| 34 | 36 |
| 35 // Called on worker thread to write the ninja file. | 37 // Called on worker thread to write the ninja file. |
| 36 void BackgroundDoWrite(const Target* target) { | 38 void BackgroundDoWrite(const Target* target) { |
| 37 NinjaTargetWriter::RunAndWriteFile(target); | 39 NinjaTargetWriter::RunAndWriteFile(target); |
| 38 g_scheduler->DecrementWorkCount(); | 40 g_scheduler->DecrementWorkCount(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 // Called on the main thread. | 43 // Called on the main thread. |
| 42 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, | 44 void ItemResolvedCallback(base::subtle::Atomic32* write_counter, |
| 43 scoped_refptr<Builder> builder, | 45 scoped_refptr<Builder> builder, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 OutputString(base::StringPrintf("\n%d generated input errors found.\n", | 150 OutputString(base::StringPrintf("\n%d generated input errors found.\n", |
| 149 errors_found), DECORATION_YELLOW); | 151 errors_found), DECORATION_YELLOW); |
| 150 } | 152 } |
| 151 return false; | 153 return false; |
| 152 } | 154 } |
| 153 | 155 |
| 154 bool RunIdeWriter(const std::string& ide, | 156 bool RunIdeWriter(const std::string& ide, |
| 155 const BuildSettings* build_settings, | 157 const BuildSettings* build_settings, |
| 156 Builder* builder, | 158 Builder* builder, |
| 157 Err* err) { | 159 Err* err) { |
| 160 const base::CommandLine* command_line = |
| 161 base::CommandLine::ForCurrentProcess(); |
| 158 base::ElapsedTimer timer; | 162 base::ElapsedTimer timer; |
| 163 |
| 159 if (ide == kSwitchIdeValueEclipse) { | 164 if (ide == kSwitchIdeValueEclipse) { |
| 160 bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err); | 165 bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err); |
| 161 if (res && | 166 if (res && !command_line->HasSwitch(switches::kQuiet)) { |
| 162 !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) { | |
| 163 OutputString("Generating Eclipse settings took " + | 167 OutputString("Generating Eclipse settings took " + |
| 164 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 168 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
| 165 "ms\n"); | 169 "ms\n"); |
| 166 } | 170 } |
| 167 return res; | 171 return res; |
| 168 } else if (ide == kSwitchIdeValueVs || ide == kSwitchIdeValueVs2013 || | 172 } else if (ide == kSwitchIdeValueVs || ide == kSwitchIdeValueVs2013 || |
| 169 ide == kSwitchIdeValueVs2015) { | 173 ide == kSwitchIdeValueVs2015) { |
| 170 VisualStudioWriter::Version version = | 174 VisualStudioWriter::Version version = |
| 171 ide == kSwitchIdeValueVs2013 ? VisualStudioWriter::Version::Vs2013 | 175 ide == kSwitchIdeValueVs2013 ? VisualStudioWriter::Version::Vs2013 |
| 172 : VisualStudioWriter::Version::Vs2015; | 176 : VisualStudioWriter::Version::Vs2015; |
| 173 bool res = VisualStudioWriter::RunAndWriteFiles(build_settings, builder, | 177 std::string sln_name; |
| 174 version, err); | 178 if (command_line->HasSwitch(kSwitchSln)) |
| 175 if (res && | 179 sln_name = command_line->GetSwitchValueASCII(kSwitchSln); |
| 176 !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kQuiet)) { | 180 std::string filters; |
| 181 if (command_line->HasSwitch(kSwitchFilters)) |
| 182 filters = command_line->GetSwitchValueASCII(kSwitchFilters); |
| 183 bool res = VisualStudioWriter::RunAndWriteFiles( |
| 184 build_settings, builder, version, sln_name, filters, err); |
| 185 if (res && !command_line->HasSwitch(switches::kQuiet)) { |
| 177 OutputString("Generating Visual Studio projects took " + | 186 OutputString("Generating Visual Studio projects took " + |
| 178 base::Int64ToString(timer.Elapsed().InMilliseconds()) + | 187 base::Int64ToString(timer.Elapsed().InMilliseconds()) + |
| 179 "ms\n"); | 188 "ms\n"); |
| 180 } | 189 } |
| 181 return res; | 190 return res; |
| 182 } | 191 } |
| 183 | 192 |
| 184 *err = Err(Location(), "Unknown IDE: " + ide); | 193 *err = Err(Location(), "Unknown IDE: " + ide); |
| 185 return false; | 194 return false; |
| 186 } | 195 } |
| 187 | 196 |
| 188 } // namespace | 197 } // namespace |
| 189 | 198 |
| 190 const char kGen[] = "gen"; | 199 const char kGen[] = "gen"; |
| 191 const char kGen_HelpShort[] = | 200 const char kGen_HelpShort[] = |
| 192 "gen: Generate ninja files."; | 201 "gen: Generate ninja files."; |
| 193 const char kGen_Help[] = | 202 const char kGen_Help[] = |
| 194 "gn gen: Generate ninja files.\n" | 203 "gn gen: Generate ninja files.\n" |
| 195 "\n" | 204 "\n" |
| 196 " gn gen [--ide=<ide_name>] <out_dir>\n" | 205 " gn gen [<ide options>] <out_dir>\n" |
| 197 "\n" | 206 "\n" |
| 198 " Generates ninja files from the current tree and puts them in the given\n" | 207 " Generates ninja files from the current tree and puts them in the given\n" |
| 199 " output directory.\n" | 208 " output directory.\n" |
| 200 "\n" | 209 "\n" |
| 201 " The output directory can be a source-repo-absolute path name such as:\n" | 210 " The output directory can be a source-repo-absolute path name such as:\n" |
| 202 " //out/foo\n" | 211 " //out/foo\n" |
| 203 " Or it can be a directory relative to the current directory such as:\n" | 212 " Or it can be a directory relative to the current directory such as:\n" |
| 204 " out/foo\n" | 213 " out/foo\n" |
| 205 "\n" | 214 "\n" |
| 215 " See \"gn help switches\" for the common command-line switches.\n" |
| 216 "\n" |
| 217 "IDE options\n" |
| 218 "\n" |
| 219 " GN optionally generates files for IDE. Possibilities for <ide options>\n" |
| 220 "\n" |
| 206 " --ide=<ide_name>\n" | 221 " --ide=<ide_name>\n" |
| 207 " Also generate files for an IDE. Currently supported values:\n" | 222 " Generate files for an IDE. Currently supported values:\n" |
| 208 " \"eclipse\" - Eclipse CDT settings file.\n" | 223 " \"eclipse\" - Eclipse CDT settings file.\n" |
| 209 " \"vs\" - Visual Studio project/solution files.\n" | 224 " \"vs\" - Visual Studio project/solution files.\n" |
| 210 " (default Visual Studio version: 2015)\n" | 225 " (default Visual Studio version: 2015)\n" |
| 211 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" | 226 " \"vs2013\" - Visual Studio 2013 project/solution files.\n" |
| 212 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" | 227 " \"vs2015\" - Visual Studio 2015 project/solution files.\n" |
| 213 "\n" | 228 "\n" |
| 214 " See \"gn help switches\" for the common command-line switches.\n" | 229 " --sln=<file_name>\n" |
| 230 " Override default sln file name (\"all\"). Solution file is written\n" |
| 231 " to the root build directory. Only for Visual Studio.\n" |
| 232 "\n" |
| 233 " --filters=<path_prefixes>\n" |
| 234 " Semicolon-separated list of label patterns used to limit the set\n" |
| 235 " of generated projects (see \"gn help label_pattern\"). Only\n" |
| 236 " matching targets will be included to the solution. Only for Visual\n" |
| 237 " Studio.\n" |
| 215 "\n" | 238 "\n" |
| 216 "Eclipse IDE Support\n" | 239 "Eclipse IDE Support\n" |
| 217 "\n" | 240 "\n" |
| 218 " GN DOES NOT generate Eclipse CDT projects. Instead, it generates a\n" | 241 " GN DOES NOT generate Eclipse CDT projects. Instead, it generates a\n" |
| 219 " settings file which can be imported into an Eclipse CDT project. The\n" | 242 " settings file which can be imported into an Eclipse CDT project. The\n" |
| 220 " XML file contains a list of include paths and defines. Because GN does\n" | 243 " XML file contains a list of include paths and defines. Because GN does\n" |
| 221 " not generate a full .cproject definition, it is not possible to\n" | 244 " not generate a full .cproject definition, it is not possible to\n" |
| 222 " properly define includes/defines for each file individually.\n" | 245 " properly define includes/defines for each file individually.\n" |
| 223 " Instead, one set of includes/defines is generated for the entire\n" | 246 " Instead, one set of includes/defines is generated for the entire\n" |
| 224 " project. This works fairly well but may still result in a few indexer\n" | 247 " project. This works fairly well but may still result in a few indexer\n" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 setup->scheduler().input_file_manager()->GetInputFileCount()) + | 314 setup->scheduler().input_file_manager()->GetInputFileCount()) + |
| 292 " files in " + | 315 " files in " + |
| 293 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; | 316 base::Int64ToString(elapsed_time.InMilliseconds()) + "ms\n"; |
| 294 OutputString(stats); | 317 OutputString(stats); |
| 295 } | 318 } |
| 296 | 319 |
| 297 return 0; | 320 return 0; |
| 298 } | 321 } |
| 299 | 322 |
| 300 } // namespace commands | 323 } // namespace commands |
| OLD | NEW |