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 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_GN_NINJA_WRITER_H_ 6 #define TOOLS_GN_NINJA_WRITER_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 #include <vector> 12 13 class Builder; 14 class BuildSettings; 15 class Err; 16 class Target; 17 class Toolchain; 18 19 class NinjaWriter { 20 public: 21 // Combines a target and the computed build rule for it. 22 using TargetRulePair = std::pair<const Target*, std::string>; 23 24 // Associates the build rules with each toolchain. 25 using PerToolchainRules = 26 std::map<const Toolchain*, std::vector<TargetRulePair>>; 27 28 // On failure will populate |err| and will return false. The map contains 29 // the per-toolchain set of rules collected to write to the toolchain build 30 // files. 31 static bool RunAndWriteFiles(const BuildSettings* build_settings, 32 const Builder& builder, 33 const PerToolchainRules& per_toolchain_rules, 34 Err* err); 35 36 private: 37 NinjaWriter(const Builder& builder); 38 ~NinjaWriter(); 39 40 bool WriteToolchains(const PerToolchainRules& per_toolchain_rules, Err* err); 41 42 const Builder& builder_; 43 44 NinjaWriter(const NinjaWriter&) = delete; 45 NinjaWriter& operator=(const NinjaWriter&) = delete; 46 }; 47 48 #endif // TOOLS_GN_NINJA_WRITER_H_ 49