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

Side by Side Diff: tools/gn/ninja_target_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_target_writer.h ('k') | tools/gn/ninja_toolchain_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_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"
(...skipping 17 matching lines...) Expand all
28 out_(out), 28 out_(out),
29 path_output_(settings_->build_settings()->build_dir(), 29 path_output_(settings_->build_settings()->build_dir(),
30 ESCAPE_NINJA, true), 30 ESCAPE_NINJA, true),
31 helper_(settings_->build_settings()) { 31 helper_(settings_->build_settings()) {
32 } 32 }
33 33
34 NinjaTargetWriter::~NinjaTargetWriter() { 34 NinjaTargetWriter::~NinjaTargetWriter() {
35 } 35 }
36 36
37 // static 37 // static
38 void NinjaTargetWriter::RunAndWriteFile(const Target* target) { 38 void NinjaTargetWriter::RunAndWriteFile(const Target* target,
39 // External targets don't get written to disk, we assume they're managed by 39 const Toolchain* toolchain) {
40 // an external program. If we're not using an external generator, this is
41 // ignored.
42 if (target->settings()->build_settings()->using_external_generator() &&
43 target->external())
44 return;
45
46 const Settings* settings = target->settings(); 40 const Settings* settings = target->settings();
47 NinjaHelper helper(settings->build_settings()); 41 NinjaHelper helper(settings->build_settings());
48 42
49 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, 43 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE,
50 target->label().GetUserVisibleName(false)); 44 target->label().GetUserVisibleName(false));
51 trace.SetToolchain(settings->toolchain_label()); 45 trace.SetToolchain(settings->toolchain_label());
52 46
53 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 47 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
54 helper.GetNinjaFileForTarget(target).GetSourceFile( 48 helper.GetNinjaFileForTarget(target).GetSourceFile(
55 settings->build_settings()))); 49 settings->build_settings())));
56 50
57 if (g_scheduler->verbose_logging()) 51 if (g_scheduler->verbose_logging())
58 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); 52 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file));
59 53
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()); 54 file_util::CreateDirectory(ninja_file.DirName());
65 55
66 // It's rediculously faster to write to a string and then write that to 56 // 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. 57 // disk in one operation than to use an fstream here.
68 std::stringstream file; 58 std::stringstream file;
69 59
70 // Call out to the correct sub-type of writer. 60 // Call out to the correct sub-type of writer.
71 if (target->output_type() == Target::COPY_FILES) { 61 if (target->output_type() == Target::COPY_FILES) {
72 NinjaCopyTargetWriter writer(target, tc, file); 62 NinjaCopyTargetWriter writer(target, toolchain, file);
73 writer.Run(); 63 writer.Run();
74 } else if (target->output_type() == Target::CUSTOM) { 64 } else if (target->output_type() == Target::CUSTOM) {
75 NinjaScriptTargetWriter writer(target, tc, file); 65 NinjaScriptTargetWriter writer(target, toolchain, file);
76 writer.Run(); 66 writer.Run();
77 } else if (target->output_type() == Target::GROUP) { 67 } else if (target->output_type() == Target::GROUP) {
78 NinjaGroupTargetWriter writer(target, tc, file); 68 NinjaGroupTargetWriter writer(target, toolchain, file);
79 writer.Run(); 69 writer.Run();
80 } else if (target->output_type() == Target::EXECUTABLE || 70 } else if (target->output_type() == Target::EXECUTABLE ||
81 target->output_type() == Target::STATIC_LIBRARY || 71 target->output_type() == Target::STATIC_LIBRARY ||
82 target->output_type() == Target::SHARED_LIBRARY || 72 target->output_type() == Target::SHARED_LIBRARY ||
83 target->output_type() == Target::SOURCE_SET) { 73 target->output_type() == Target::SOURCE_SET) {
84 NinjaBinaryTargetWriter writer(target, tc, file); 74 NinjaBinaryTargetWriter writer(target, toolchain, file);
85 writer.Run(); 75 writer.Run();
86 } else { 76 } else {
87 CHECK(0); 77 CHECK(0);
88 } 78 }
89 79
90 std::string contents = file.str(); 80 std::string contents = file.str();
91 file_util::WriteFile(ninja_file, contents.c_str(), 81 file_util::WriteFile(ninja_file, contents.c_str(),
92 static_cast<int>(contents.size())); 82 static_cast<int>(contents.size()));
93 } 83 }
94 84
(...skipping 28 matching lines...) Expand all
123 const Target::FileList& outputs = target_->script_values().outputs(); 113 const Target::FileList& outputs = target_->script_values().outputs();
124 std::vector<std::string> output_template_args; 114 std::vector<std::string> output_template_args;
125 for (size_t i = 0; i < outputs.size(); i++) { 115 for (size_t i = 0; i < outputs.size(); i++) {
126 // All outputs should be in the output dir. 116 // All outputs should be in the output dir.
127 output_template_args.push_back( 117 output_template_args.push_back(
128 RemovePrefix(outputs[i].value(), 118 RemovePrefix(outputs[i].value(),
129 settings_->build_settings()->build_dir().value())); 119 settings_->build_settings()->build_dir().value()));
130 } 120 }
131 return FileTemplate(output_template_args); 121 return FileTemplate(output_template_args);
132 } 122 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_target_writer.h ('k') | tools/gn/ninja_toolchain_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698