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

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

Issue 56433003: GN threading refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « tools/gn/ninja_toolchain_writer.h ('k') | tools/gn/ninja_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_toolchain_writer.h" 5 #include "tools/gn/ninja_toolchain_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/strings/stringize_macros.h" 10 #include "base/strings/stringize_macros.h"
11 #include "tools/gn/build_settings.h" 11 #include "tools/gn/build_settings.h"
12 #include "tools/gn/item_node.h"
13 #include "tools/gn/settings.h" 12 #include "tools/gn/settings.h"
14 #include "tools/gn/target.h" 13 #include "tools/gn/target.h"
15 #include "tools/gn/toolchain.h" 14 #include "tools/gn/toolchain.h"
16 #include "tools/gn/toolchain_manager.h"
17 #include "tools/gn/trace.h" 15 #include "tools/gn/trace.h"
18 16
19 NinjaToolchainWriter::NinjaToolchainWriter( 17 NinjaToolchainWriter::NinjaToolchainWriter(
20 const Settings* settings, 18 const Settings* settings,
19 const Toolchain* toolchain,
21 const std::vector<const Target*>& targets, 20 const std::vector<const Target*>& targets,
22 const std::set<std::string>& skip_files,
23 std::ostream& out) 21 std::ostream& out)
24 : settings_(settings), 22 : settings_(settings),
23 toolchain_(toolchain),
25 targets_(targets), 24 targets_(targets),
26 skip_files_(skip_files),
27 out_(out), 25 out_(out),
28 path_output_(settings_->build_settings()->build_dir(), 26 path_output_(settings_->build_settings()->build_dir(),
29 ESCAPE_NINJA, true), 27 ESCAPE_NINJA, true),
30 helper_(settings->build_settings()) { 28 helper_(settings->build_settings()) {
31 } 29 }
32 30
33 NinjaToolchainWriter::~NinjaToolchainWriter() { 31 NinjaToolchainWriter::~NinjaToolchainWriter() {
34 } 32 }
35 33
36 void NinjaToolchainWriter::Run() { 34 void NinjaToolchainWriter::Run() {
37 WriteRules(); 35 WriteRules();
38 WriteSubninjas(); 36 WriteSubninjas();
39 } 37 }
40 38
41 // static 39 // static
42 bool NinjaToolchainWriter::RunAndWriteFile( 40 bool NinjaToolchainWriter::RunAndWriteFile(
43 const Settings* settings, 41 const Settings* settings,
44 const std::vector<const Target*>& targets, 42 const Toolchain* toolchain,
45 const std::set<std::string>& skip_files) { 43 const std::vector<const Target*>& targets) {
46 NinjaHelper helper(settings->build_settings()); 44 NinjaHelper helper(settings->build_settings());
47 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 45 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
48 helper.GetNinjaFileForToolchain(settings).GetSourceFile( 46 helper.GetNinjaFileForToolchain(settings).GetSourceFile(
49 settings->build_settings()))); 47 settings->build_settings())));
50 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, FilePathToUTF8(ninja_file)); 48 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, FilePathToUTF8(ninja_file));
51 49
52 file_util::CreateDirectory(ninja_file.DirName()); 50 file_util::CreateDirectory(ninja_file.DirName());
53 51
54 std::ofstream file; 52 std::ofstream file;
55 file.open(FilePathToUTF8(ninja_file).c_str(), 53 file.open(FilePathToUTF8(ninja_file).c_str(),
56 std::ios_base::out | std::ios_base::binary); 54 std::ios_base::out | std::ios_base::binary);
57 if (file.fail()) 55 if (file.fail())
58 return false; 56 return false;
59 57
60 NinjaToolchainWriter gen(settings, targets, skip_files, file); 58 NinjaToolchainWriter gen(settings, toolchain, targets, file);
61 gen.Run(); 59 gen.Run();
62 return true; 60 return true;
63 } 61 }
64 62
65 void NinjaToolchainWriter::WriteRules() { 63 void NinjaToolchainWriter::WriteRules() {
66 const Toolchain* tc = settings_->build_settings()->toolchain_manager()
67 .GetToolchainDefinitionUnlocked(settings_->toolchain_label());
68 CHECK(tc);
69
70 std::string indent(" "); 64 std::string indent(" ");
71 65
72 NinjaHelper helper(settings_->build_settings()); 66 NinjaHelper helper(settings_->build_settings());
73 std::string rule_prefix = helper.GetRulePrefix(settings_); 67 std::string rule_prefix = helper.GetRulePrefix(settings_);
74 68
75 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { 69 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) {
76 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); 70 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i);
77 const Toolchain::Tool& tool = tc->GetTool(tool_type); 71 const Toolchain::Tool& tool = toolchain_->GetTool(tool_type);
78 if (tool.command.empty()) 72 if (tool.command.empty())
79 continue; 73 continue;
80 74
81 out_ << "rule " << rule_prefix << Toolchain::ToolTypeToName(tool_type) 75 out_ << "rule " << rule_prefix << Toolchain::ToolTypeToName(tool_type)
82 << std::endl; 76 << std::endl;
83 77
84 #define WRITE_ARG(name) \ 78 #define WRITE_ARG(name) \
85 if (!tool.name.empty()) \ 79 if (!tool.name.empty()) \
86 out_ << indent << " " STRINGIZE(name) " = " << tool.name << std::endl; 80 out_ << indent << " " STRINGIZE(name) " = " << tool.name << std::endl;
87 WRITE_ARG(command); 81 WRITE_ARG(command);
88 WRITE_ARG(depfile); 82 WRITE_ARG(depfile);
89 WRITE_ARG(deps); 83 WRITE_ARG(deps);
90 WRITE_ARG(description); 84 WRITE_ARG(description);
91 WRITE_ARG(pool); 85 WRITE_ARG(pool);
92 WRITE_ARG(restat); 86 WRITE_ARG(restat);
93 WRITE_ARG(rspfile); 87 WRITE_ARG(rspfile);
94 WRITE_ARG(rspfile_content); 88 WRITE_ARG(rspfile_content);
95 #undef WRITE_ARG 89 #undef WRITE_ARG
96 } 90 }
97 out_ << std::endl; 91 out_ << std::endl;
98 } 92 }
99 93
100 void NinjaToolchainWriter::WriteSubninjas() { 94 void NinjaToolchainWriter::WriteSubninjas() {
101 // Write subninja commands for each generated target. 95 // Write subninja commands for each generated target.
102 for (size_t i = 0; i < targets_.size(); i++) { 96 for (size_t i = 0; i < targets_.size(); i++) {
103 if (!targets_[i]->item_node()->should_generate() ||
104 (targets_[i]->settings()->build_settings()->using_external_generator()
105 && targets_[i]->external()))
106 continue;
107
108 OutputFile ninja_file = helper_.GetNinjaFileForTarget(targets_[i]); 97 OutputFile ninja_file = helper_.GetNinjaFileForTarget(targets_[i]);
109 if (skip_files_.find(ninja_file.value()) != skip_files_.end())
110 continue;
111
112 out_ << "subninja "; 98 out_ << "subninja ";
113 path_output_.WriteFile(out_, ninja_file); 99 path_output_.WriteFile(out_, ninja_file);
114 out_ << std::endl; 100 out_ << std::endl;
115 } 101 }
116 out_ << std::endl; 102 out_ << std::endl;
117 } 103 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_toolchain_writer.h ('k') | tools/gn/ninja_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698