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

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

Issue 1494883002: GN: Makes GN output deterministic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaked some comments for clarity 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_toolchain_writer.h" 5 #include "tools/gn/ninja_toolchain_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/strings/stringize_macros.h" 10 #include "base/strings/stringize_macros.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 void NinjaToolchainWriter::Run() { 43 void NinjaToolchainWriter::Run() {
44 WriteRules(); 44 WriteRules();
45 WriteSubninjas(); 45 WriteSubninjas();
46 } 46 }
47 47
48 // static 48 // static
49 bool NinjaToolchainWriter::RunAndWriteFile( 49 bool NinjaToolchainWriter::RunAndWriteFile(
50 const Settings* settings, 50 const Settings* settings,
51 const Toolchain* toolchain, 51 const Toolchain* toolchain,
52 const std::vector<const Target*>& targets) { 52 std::vector<const Target*>& targets) {
53 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 53 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
54 GetNinjaFileForToolchain(settings))); 54 GetNinjaFileForToolchain(settings)));
55 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, FilePathToUTF8(ninja_file)); 55 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, FilePathToUTF8(ninja_file));
56 56
57 base::CreateDirectory(ninja_file.DirName()); 57 base::CreateDirectory(ninja_file.DirName());
58 58
59 std::ofstream file; 59 std::ofstream file;
60 file.open(FilePathToUTF8(ninja_file).c_str(), 60 file.open(FilePathToUTF8(ninja_file).c_str(),
61 std::ios_base::out | std::ios_base::binary); 61 std::ios_base::out | std::ios_base::binary);
62 if (file.fail()) 62 if (file.fail())
63 return false; 63 return false;
64 64
65 // Sort targets so that they are in a deterministic order.
M-A Ruel 2015/12/07 15:09:50 I'd still prefer: DCHECK( std::is_sorted(targe
Zachary Forman 2015/12/08 09:40:42 I've followed your advice here and effectively rem
66 std::sort(
67 targets.begin(), targets.end(),
68 [](const Target* a, const Target* b) { return a->label() < b->label(); });
69
65 NinjaToolchainWriter gen(settings, toolchain, targets, file); 70 NinjaToolchainWriter gen(settings, toolchain, targets, file);
66 gen.Run(); 71 gen.Run();
67 return true; 72 return true;
68 } 73 }
69 74
70 void NinjaToolchainWriter::WriteRules() { 75 void NinjaToolchainWriter::WriteRules() {
71 std::string rule_prefix = GetNinjaRulePrefixForToolchain(settings_); 76 std::string rule_prefix = GetNinjaRulePrefixForToolchain(settings_);
72 77
73 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { 78 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) {
74 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); 79 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // Write subninja commands for each generated target. 138 // Write subninja commands for each generated target.
134 for (const auto& target : targets_) { 139 for (const auto& target : targets_) {
135 OutputFile ninja_file(target->settings()->build_settings(), 140 OutputFile ninja_file(target->settings()->build_settings(),
136 GetNinjaFileForTarget(target)); 141 GetNinjaFileForTarget(target));
137 out_ << "subninja "; 142 out_ << "subninja ";
138 path_output_.WriteFile(out_, ninja_file); 143 path_output_.WriteFile(out_, ninja_file);
139 out_ << std::endl; 144 out_ << std::endl;
140 } 145 }
141 out_ << std::endl; 146 out_ << std::endl;
142 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698