Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 here to ensure the files are deterministically ordered. | |
|
M-A Ruel
2015/12/07 00:20:16
You could DCHECK instead that the list is sorted.
Zachary Forman
2015/12/07 03:18:17
This is poor phrasing on my part - they come in un
| |
| 66 std::sort(targets.begin(), targets.end(), DereferenceComparator<Target>()); | |
| 67 | |
| 65 NinjaToolchainWriter gen(settings, toolchain, targets, file); | 68 NinjaToolchainWriter gen(settings, toolchain, targets, file); |
| 66 gen.Run(); | 69 gen.Run(); |
| 67 return true; | 70 return true; |
| 68 } | 71 } |
| 69 | 72 |
| 70 void NinjaToolchainWriter::WriteRules() { | 73 void NinjaToolchainWriter::WriteRules() { |
| 71 std::string rule_prefix = GetNinjaRulePrefixForToolchain(settings_); | 74 std::string rule_prefix = GetNinjaRulePrefixForToolchain(settings_); |
| 72 | 75 |
| 73 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { | 76 for (int i = Toolchain::TYPE_NONE + 1; i < Toolchain::TYPE_NUMTYPES; i++) { |
| 74 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); | 77 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(i); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // Write subninja commands for each generated target. | 136 // Write subninja commands for each generated target. |
| 134 for (const auto& target : targets_) { | 137 for (const auto& target : targets_) { |
| 135 OutputFile ninja_file(target->settings()->build_settings(), | 138 OutputFile ninja_file(target->settings()->build_settings(), |
| 136 GetNinjaFileForTarget(target)); | 139 GetNinjaFileForTarget(target)); |
| 137 out_ << "subninja "; | 140 out_ << "subninja "; |
| 138 path_output_.WriteFile(out_, ninja_file); | 141 path_output_.WriteFile(out_, ninja_file); |
| 139 out_ << std::endl; | 142 out_ << std::endl; |
| 140 } | 143 } |
| 141 out_ << std::endl; | 144 out_ << std::endl; |
| 142 } | 145 } |
| OLD | NEW |