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

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

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moves sort into ninja_toolchain_writer.cc for consistency Created 5 years 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 << " generator = 1\n" 187 << " generator = 1\n"
188 << " depfile = build.ninja.d\n"; 188 << " depfile = build.ninja.d\n";
189 189
190 // Input build files. These go in the ".d" file. If we write them as 190 // Input build files. These go in the ".d" file. If we write them as
191 // dependencies in the .ninja file itself, ninja will expect the files to 191 // dependencies in the .ninja file itself, ninja will expect the files to
192 // exist and will error if they don't. When files are listed in a depfile, 192 // exist and will error if they don't. When files are listed in a depfile,
193 // missing files are ignored. 193 // missing files are ignored.
194 dep_out_ << "build.ninja:"; 194 dep_out_ << "build.ninja:";
195 std::vector<base::FilePath> input_files; 195 std::vector<base::FilePath> input_files;
196 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); 196 g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files);
197 for (const auto& input_file : input_files) 197
198 dep_out_ << " " << FilePathToUTF8(input_file); 198 // Put the files into a set so that the output is sorted and hence
M-A Ruel 2015/12/07 00:20:16 Why not just std::sort(input_files.begin(), input_
Zachary Forman 2015/12/07 03:18:17 Interestingly, the two vectors seem to contain a n
199 // deterministic.
200 std::set<base::FilePath> file_set(input_files.begin(), input_files.end());
199 201
200 // Other files read by the build. 202 // Other files read by the build.
201 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); 203 input_files = g_scheduler->GetGenDependencies();
202 for (const auto& other_file : other_files) 204
203 dep_out_ << " " << FilePathToUTF8(other_file); 205 file_set.insert(input_files.begin(), input_files.end());
206
207 for (const auto& input_file : file_set)
208 dep_out_ << " " << FilePathToUTF8(input_file);
204 209
205 out_ << std::endl; 210 out_ << std::endl;
206 } 211 }
207 212
208 void NinjaBuildWriter::WriteLinkPool() { 213 void NinjaBuildWriter::WriteLinkPool() {
209 out_ << "pool link_pool\n" 214 out_ << "pool link_pool\n"
210 << " depth = " << default_toolchain_->concurrent_links() << std::endl 215 << " depth = " << default_toolchain_->concurrent_links() << std::endl
211 << std::endl; 216 << std::endl;
212 } 217 }
213 218
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 EscapeOptions ninja_escape; 353 EscapeOptions ninja_escape;
349 ninja_escape.mode = ESCAPE_NINJA; 354 ninja_escape.mode = ESCAPE_NINJA;
350 355
351 // Escape for special chars Ninja will handle. 356 // Escape for special chars Ninja will handle.
352 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); 357 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr);
353 358
354 out_ << "build " << escaped << ": phony "; 359 out_ << "build " << escaped << ": phony ";
355 path_output_.WriteFile(out_, target_file); 360 path_output_.WriteFile(out_, target_file);
356 out_ << std::endl; 361 out_ << std::endl;
357 } 362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698