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

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

Issue 1265793002: patch from petermayo to fix GN dependency regeneration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not escape paths in build.ninja.d 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,
81 EscapingMode mode) {
82 EscapeOptions path_escaping;
83 path_escaping.mode = mode;
84
85 out << " ";
86 EscapeStringToStream(out, FilePathToUTF8(name), path_escaping);
87 }
88
80 } // namespace 89 } // namespace
81 90
82 NinjaBuildWriter::NinjaBuildWriter( 91 NinjaBuildWriter::NinjaBuildWriter(
83 const BuildSettings* build_settings, 92 const BuildSettings* build_settings,
84 const std::vector<const Settings*>& all_settings, 93 const std::vector<const Settings*>& all_settings,
85 const Toolchain* default_toolchain, 94 const Toolchain* default_toolchain,
86 const std::vector<const Target*>& default_toolchain_targets, 95 const std::vector<const Target*>& default_toolchain_targets,
87 std::ostream& out, 96 std::ostream& out,
88 std::ostream& dep_out) 97 std::ostream& dep_out)
89 : build_settings_(build_settings), 98 : build_settings_(build_settings),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 145 }
137 146
138 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, 147 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain,
139 default_toolchain_targets, file, depfile); 148 default_toolchain_targets, file, depfile);
140 return gen.Run(err); 149 return gen.Run(err);
141 } 150 }
142 151
143 void NinjaBuildWriter::WriteNinjaRules() { 152 void NinjaBuildWriter::WriteNinjaRules() {
144 out_ << "rule gn\n"; 153 out_ << "rule gn\n";
145 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; 154 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n";
146 out_ << " description = Regenerating ninja files\n\n"; 155 out_ << " description = Regenerating ninja files\n";
156 out_ << " restat = 1\n\n";
147 157
148 // This rule will regenerate the ninja files when any input file has changed. 158 // This rule will regenerate the ninja files when any input file has changed,
149 out_ << "build build.ninja: gn\n" 159 // or is missing.
160 out_ << "build build.ninja";
161
162 // Other files read by the build.
163 std::vector<SourceFile> written_files = g_scheduler->GetWrittenFiles();
164 for (const auto& written_file : written_files)
165 WriteAnotherFile(out_, build_settings_->GetFullPath(written_file),
166 ESCAPE_NINJA_COMMAND);
167
168 out_ << ": gn\n"
150 << " generator = 1\n" 169 << " generator = 1\n"
151 << " depfile = build.ninja.d\n"; 170 << " depfile = build.ninja.d\n";
152 171
153 // Input build files. These go in the ".d" file. If we write them as 172 // 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 173 // 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, 174 // exist and will error if they don't. When files are listed in a depfile,
156 // missing files are ignored. 175 // missing files are ignored.
157 dep_out_ << "build.ninja:"; 176 dep_out_ << "build.ninja:";
158 std::vector<base::FilePath> input_files; 177 std::vector<base::FilePath> input_files;
159 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); 178 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files);
160 for (const auto& input_file : input_files) 179 for (const auto& input_file : input_files)
161 dep_out_ << " " << FilePathToUTF8(input_file); 180 WriteAnotherFile(dep_out_, input_file, ESCAPE_NONE);
162 181
163 // Other files read by the build. 182 // Other files read by the build.
164 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); 183 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies();
165 for (const auto& other_file : other_files) 184 for (const auto& other_file : other_files)
166 dep_out_ << " " << FilePathToUTF8(other_file); 185 WriteAnotherFile(dep_out_, other_file, ESCAPE_NONE);
167 186
168 out_ << std::endl; 187 out_ << std::endl;
169 } 188 }
170 189
171 void NinjaBuildWriter::WriteLinkPool() { 190 void NinjaBuildWriter::WriteLinkPool() {
172 out_ << "pool link_pool\n" 191 out_ << "pool link_pool\n"
173 << " depth = " << default_toolchain_->concurrent_links() << std::endl 192 << " depth = " << default_toolchain_->concurrent_links() << std::endl
174 << std::endl; 193 << std::endl;
175 } 194 }
176 195
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EscapeOptions ninja_escape; 332 EscapeOptions ninja_escape;
314 ninja_escape.mode = ESCAPE_NINJA; 333 ninja_escape.mode = ESCAPE_NINJA;
315 334
316 // Escape for special chars Ninja will handle. 335 // Escape for special chars Ninja will handle.
317 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); 336 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr);
318 337
319 out_ << "build " << escaped << ": phony "; 338 out_ << "build " << escaped << ": phony ";
320 path_output_.WriteFile(out_, target_file); 339 path_output_.WriteFile(out_, target_file);
321 out_ << std::endl; 340 out_ << std::endl;
322 } 341 }
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