• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TOOLCHAIN_WRITER_H_
6 #define TOOLS_GN_NINJA_TOOLCHAIN_WRITER_H_
7 
8 #include <iosfwd>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 #include "base/gtest_prod_util.h"
14 #include "gn/ninja_writer.h"
15 #include "gn/path_output.h"
16 #include "gn/toolchain.h"
17 
18 struct EscapeOptions;
19 class Settings;
20 class Tool;
21 
22 class NinjaToolchainWriter {
23  public:
24   // Takes the settings for the toolchain, as well as the list of all targets
25   // associated with the toolchain.
26   static bool RunAndWriteFile(
27       const Settings* settings,
28       const Toolchain* toolchain,
29       const std::vector<NinjaWriter::TargetRulePair>& rules);
30 
31  private:
32   FRIEND_TEST_ALL_PREFIXES(NinjaToolchainWriter, WriteToolRule);
33   FRIEND_TEST_ALL_PREFIXES(NinjaToolchainWriter, WriteToolRuleWithLauncher);
34 
35   NinjaToolchainWriter(const Settings* settings,
36                        const Toolchain* toolchain,
37                        std::ostream& out);
38   ~NinjaToolchainWriter();
39 
40   void Run(const std::vector<NinjaWriter::TargetRulePair>& extra_rules);
41 
42   void WriteRules();
43   void WriteToolRule(Tool* tool, const std::string& rule_prefix);
44   void WriteRulePattern(const char* name,
45                         const SubstitutionPattern& pattern,
46                         const EscapeOptions& options);
47   void WriteCommandRulePattern(const char* name,
48                                const std::string& launcher,
49                                const SubstitutionPattern& command,
50                                const EscapeOptions& options);
51 
52   const Settings* settings_;
53   const Toolchain* toolchain_;
54   std::ostream& out_;
55   PathOutput path_output_;
56 
57   NinjaToolchainWriter(const NinjaToolchainWriter&) = delete;
58   NinjaToolchainWriter& operator=(const NinjaToolchainWriter&) = delete;
59 };
60 
61 #endif  // TOOLS_GN_NINJA_TOOLCHAIN_WRITER_H_
62