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

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

Issue 1252403005: Add output reference to gen written files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added escaping for generated filenames. Created 5 years, 4 months 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
« no previous file with comments | « tools/gn/function_write_file.cc ('k') | tools/gn/scheduler.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_build_writer.h" 5 #include "tools/gn/ninja_build_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 } 71 }
72 72
73 #if defined(OS_WIN) 73 #if defined(OS_WIN)
74 return base::WideToUTF8(cmdline.GetCommandLineString()); 74 return base::WideToUTF8(cmdline.GetCommandLineString());
75 #else 75 #else
76 return cmdline.GetCommandLineString(); 76 return cmdline.GetCommandLineString();
77 #endif 77 #endif
78 } 78 }
79 79
80 void WriteAnotherFile(std::ostream& out, const base::FilePath& name) {
Peter Mayo 2015/07/28 22:37:37 I'm not sure this name is good enough, but I don't
81 EscapeOptions path_escaping;
82 path_escaping.mode = ESCAPE_NINJA_COMMAND;
Peter Mayo 2015/07/28 22:37:37 This mode says it handles one "thing" for ninja, t
83
84 out << " ";
Dirk Pranke 2015/07/28 22:35:05 I probably would've left line 84 out of this funct
Peter Mayo 2015/07/28 22:41:38 And 178, and 183. That's why I snuck it in here,
Dirk Pranke 2015/07/28 22:43:11 fair enough. Yeah, I understood the naming.
85 EscapeStringToStream(out, FilePathToUTF8(name), path_escaping);
86 }
87
80 } // namespace 88 } // namespace
81 89
82 NinjaBuildWriter::NinjaBuildWriter( 90 NinjaBuildWriter::NinjaBuildWriter(
83 const BuildSettings* build_settings, 91 const BuildSettings* build_settings,
84 const std::vector<const Settings*>& all_settings, 92 const std::vector<const Settings*>& all_settings,
85 const Toolchain* default_toolchain, 93 const Toolchain* default_toolchain,
86 const std::vector<const Target*>& default_toolchain_targets, 94 const std::vector<const Target*>& default_toolchain_targets,
87 std::ostream& out, 95 std::ostream& out,
88 std::ostream& dep_out) 96 std::ostream& dep_out)
89 : build_settings_(build_settings), 97 : build_settings_(build_settings),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 144 }
137 145
138 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, 146 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain,
139 default_toolchain_targets, file, depfile); 147 default_toolchain_targets, file, depfile);
140 return gen.Run(err); 148 return gen.Run(err);
141 } 149 }
142 150
143 void NinjaBuildWriter::WriteNinjaRules() { 151 void NinjaBuildWriter::WriteNinjaRules() {
144 out_ << "rule gn\n"; 152 out_ << "rule gn\n";
145 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; 153 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n";
146 out_ << " description = Regenerating ninja files\n\n"; 154 out_ << " description = Regenerating ninja files\n";
155 out_ << " restat = 1\n\n";
147 156
148 // This rule will regenerate the ninja files when any input file has changed. 157 // This rule will regenerate the ninja files when any input file has changed,
149 out_ << "build build.ninja: gn\n" 158 // or is missing.
159 out_ << "build build.ninja";
160
161 // Other files read by the build.
162 std::vector<SourceFile> written_files = g_scheduler->GetWrittenFiles();
163 for (const auto& written_file : written_files)
164 WriteAnotherFile(out_, build_settings_->GetFullPath(written_file));
165
166 out_ << ": gn\n"
150 << " generator = 1\n" 167 << " generator = 1\n"
151 << " depfile = build.ninja.d\n"; 168 << " depfile = build.ninja.d\n";
152 169
153 // Input build files. These go in the ".d" file. If we write them as 170 // Input build files. These go in the ".d" file. If we write them as
154 // dependencies in the .ninja file itself, ninja will expect the files to 171 // dependencies in the .ninja file itself, ninja will expect the files to
155 // exist and will error if they don't. When files are listed in a depfile, 172 // exist and will error if they don't. When files are listed in a depfile,
156 // missing files are ignored. 173 // missing files are ignored.
157 dep_out_ << "build.ninja:"; 174 dep_out_ << "build.ninja:";
158 std::vector<base::FilePath> input_files; 175 std::vector<base::FilePath> input_files;
159 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); 176 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files);
160 for (const auto& input_file : input_files) 177 for (const auto& input_file : input_files)
161 dep_out_ << " " << FilePathToUTF8(input_file); 178 WriteAnotherFile(dep_out_, input_file);
162 179
163 // Other files read by the build. 180 // Other files read by the build.
164 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); 181 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies();
165 for (const auto& other_file : other_files) 182 for (const auto& other_file : other_files)
166 dep_out_ << " " << FilePathToUTF8(other_file); 183 WriteAnotherFile(dep_out_, other_file);
167 184
168 out_ << std::endl; 185 out_ << std::endl;
169 } 186 }
170 187
171 void NinjaBuildWriter::WriteLinkPool() { 188 void NinjaBuildWriter::WriteLinkPool() {
172 out_ << "pool link_pool\n" 189 out_ << "pool link_pool\n"
173 << " depth = " << default_toolchain_->concurrent_links() << std::endl 190 << " depth = " << default_toolchain_->concurrent_links() << std::endl
174 << std::endl; 191 << std::endl;
175 } 192 }
176 193
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EscapeOptions ninja_escape; 330 EscapeOptions ninja_escape;
314 ninja_escape.mode = ESCAPE_NINJA; 331 ninja_escape.mode = ESCAPE_NINJA;
315 332
316 // Escape for special chars Ninja will handle. 333 // Escape for special chars Ninja will handle.
317 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); 334 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr);
318 335
319 out_ << "build " << escaped << ": phony "; 336 out_ << "build " << escaped << ": phony ";
320 path_output_.WriteFile(out_, target_file); 337 path_output_.WriteFile(out_, target_file);
321 out_ << std::endl; 338 out_ << std::endl;
322 } 339 }
OLDNEW
« no previous file with comments | « tools/gn/function_write_file.cc ('k') | tools/gn/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698