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

Side by Side Diff: trunk/src/tools/gn/ninja_target_writer.cc

Issue 46313006: Revert 232657 "GN: toolchain threading cleanup" (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | « trunk/src/tools/gn/ninja_target_writer.h ('k') | trunk/src/tools/gn/ninja_toolchain_writer.cc » ('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_target_writer.h" 5 #include "tools/gn/ninja_target_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "tools/gn/err.h" 11 #include "tools/gn/err.h"
12 #include "tools/gn/file_template.h" 12 #include "tools/gn/file_template.h"
13 #include "tools/gn/ninja_binary_target_writer.h" 13 #include "tools/gn/ninja_binary_target_writer.h"
14 #include "tools/gn/ninja_copy_target_writer.h" 14 #include "tools/gn/ninja_copy_target_writer.h"
15 #include "tools/gn/ninja_group_target_writer.h" 15 #include "tools/gn/ninja_group_target_writer.h"
16 #include "tools/gn/ninja_script_target_writer.h" 16 #include "tools/gn/ninja_script_target_writer.h"
17 #include "tools/gn/scheduler.h" 17 #include "tools/gn/scheduler.h"
18 #include "tools/gn/string_utils.h" 18 #include "tools/gn/string_utils.h"
19 #include "tools/gn/target.h" 19 #include "tools/gn/target.h"
20 #include "tools/gn/trace.h" 20 #include "tools/gn/trace.h"
21 21
22 NinjaTargetWriter::NinjaTargetWriter(const Target* target, 22 NinjaTargetWriter::NinjaTargetWriter(const Target* target, std::ostream& out)
23 const Toolchain* toolchain,
24 std::ostream& out)
25 : settings_(target->settings()), 23 : settings_(target->settings()),
26 target_(target), 24 target_(target),
27 toolchain_(toolchain),
28 out_(out), 25 out_(out),
29 path_output_(settings_->build_settings()->build_dir(), 26 path_output_(settings_->build_settings()->build_dir(),
30 ESCAPE_NINJA, true), 27 ESCAPE_NINJA, true),
31 helper_(settings_->build_settings()) { 28 helper_(settings_->build_settings()) {
32 } 29 }
33 30
34 NinjaTargetWriter::~NinjaTargetWriter() { 31 NinjaTargetWriter::~NinjaTargetWriter() {
35 } 32 }
36 33
37 // static 34 // static
38 void NinjaTargetWriter::RunAndWriteFile(const Target* target) { 35 void NinjaTargetWriter::RunAndWriteFile(const Target* target) {
39 // External targets don't get written to disk, we assume they're managed by 36 // External targets don't get written to disk, we assume they're managed by
40 // an external program. If we're not using an external generator, this is 37 // an external program. If we're not using an external generator, this is
41 // ignored. 38 // ignored.
42 if (target->settings()->build_settings()->using_external_generator() && 39 if (target->settings()->build_settings()->using_external_generator() &&
43 target->external()) 40 target->external())
44 return; 41 return;
45 42
46 const Settings* settings = target->settings(); 43 const Settings* settings = target->settings();
47 NinjaHelper helper(settings->build_settings()); 44 NinjaHelper helper(settings->build_settings());
48 45
49 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, 46 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE,
50 target->label().GetUserVisibleName(false)); 47 target->label().GetUserVisibleName(false));
51 trace.SetToolchain(settings->toolchain_label()); 48 trace.SetToolchain(settings->toolchain()->label());
52 49
53 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 50 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
54 helper.GetNinjaFileForTarget(target).GetSourceFile( 51 helper.GetNinjaFileForTarget(target).GetSourceFile(
55 settings->build_settings()))); 52 settings->build_settings())));
56 53
57 if (g_scheduler->verbose_logging()) 54 if (g_scheduler->verbose_logging())
58 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); 55 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file));
59 56
60 const Toolchain* tc = settings->build_settings()->toolchain_manager()
61 .GetToolchainDefinitionUnlocked(settings->toolchain_label());
62 CHECK(tc);
63
64 file_util::CreateDirectory(ninja_file.DirName()); 57 file_util::CreateDirectory(ninja_file.DirName());
65 58
66 // It's rediculously faster to write to a string and then write that to 59 // It's rediculously faster to write to a string and then write that to
67 // disk in one operation than to use an fstream here. 60 // disk in one operation than to use an fstream here.
68 std::stringstream file; 61 std::stringstream file;
69 62
70 // Call out to the correct sub-type of writer. 63 // Call out to the correct sub-type of writer.
71 if (target->output_type() == Target::COPY_FILES) { 64 if (target->output_type() == Target::COPY_FILES) {
72 NinjaCopyTargetWriter writer(target, tc, file); 65 NinjaCopyTargetWriter writer(target, file);
73 writer.Run(); 66 writer.Run();
74 } else if (target->output_type() == Target::CUSTOM) { 67 } else if (target->output_type() == Target::CUSTOM) {
75 NinjaScriptTargetWriter writer(target, tc, file); 68 NinjaScriptTargetWriter writer(target, file);
76 writer.Run(); 69 writer.Run();
77 } else if (target->output_type() == Target::GROUP) { 70 } else if (target->output_type() == Target::GROUP) {
78 NinjaGroupTargetWriter writer(target, tc, file); 71 NinjaGroupTargetWriter writer(target, file);
79 writer.Run(); 72 writer.Run();
80 } else if (target->output_type() == Target::EXECUTABLE || 73 } else if (target->output_type() == Target::EXECUTABLE ||
81 target->output_type() == Target::STATIC_LIBRARY || 74 target->output_type() == Target::STATIC_LIBRARY ||
82 target->output_type() == Target::SHARED_LIBRARY || 75 target->output_type() == Target::SHARED_LIBRARY ||
83 target->output_type() == Target::SOURCE_SET) { 76 target->output_type() == Target::SOURCE_SET) {
84 NinjaBinaryTargetWriter writer(target, tc, file); 77 NinjaBinaryTargetWriter writer(target, file);
85 writer.Run(); 78 writer.Run();
86 } else { 79 } else {
87 CHECK(0); 80 CHECK(0);
88 } 81 }
89 82
90 std::string contents = file.str(); 83 std::string contents = file.str();
91 file_util::WriteFile(ninja_file, contents.c_str(), 84 file_util::WriteFile(ninja_file, contents.c_str(),
92 static_cast<int>(contents.size())); 85 static_cast<int>(contents.size()));
93 } 86 }
94 87
88 const Toolchain* NinjaTargetWriter::GetToolchain() const {
89 return target_->settings()->toolchain();
90 }
91
95 std::string NinjaTargetWriter::GetSourcesImplicitDeps() const { 92 std::string NinjaTargetWriter::GetSourcesImplicitDeps() const {
96 std::ostringstream ret; 93 std::ostringstream ret;
97 ret << " |"; 94 ret << " |";
98 95
99 // Input files are order-only deps. 96 // Input files are order-only deps.
100 const Target::FileList& prereqs = target_->source_prereqs(); 97 const Target::FileList& prereqs = target_->source_prereqs();
101 bool has_files = !prereqs.empty(); 98 bool has_files = !prereqs.empty();
102 for (size_t i = 0; i < prereqs.size(); i++) { 99 for (size_t i = 0; i < prereqs.size(); i++) {
103 ret << " "; 100 ret << " ";
104 path_output_.WriteFile(ret, prereqs[i]); 101 path_output_.WriteFile(ret, prereqs[i]);
(...skipping 18 matching lines...) Expand all
123 const Target::FileList& outputs = target_->script_values().outputs(); 120 const Target::FileList& outputs = target_->script_values().outputs();
124 std::vector<std::string> output_template_args; 121 std::vector<std::string> output_template_args;
125 for (size_t i = 0; i < outputs.size(); i++) { 122 for (size_t i = 0; i < outputs.size(); i++) {
126 // All outputs should be in the output dir. 123 // All outputs should be in the output dir.
127 output_template_args.push_back( 124 output_template_args.push_back(
128 RemovePrefix(outputs[i].value(), 125 RemovePrefix(outputs[i].value(),
129 settings_->build_settings()->build_dir().value())); 126 settings_->build_settings()->build_dir().value()));
130 } 127 }
131 return FileTemplate(output_template_args); 128 return FileTemplate(output_template_args);
132 } 129 }
OLDNEW
« no previous file with comments | « trunk/src/tools/gn/ninja_target_writer.h ('k') | trunk/src/tools/gn/ninja_toolchain_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698