• 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_ACTION_TARGET_WRITER_H_
6 #define TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_
7 
8 #include <vector>
9 
10 #include "base/gtest_prod_util.h"
11 #include "gn/ninja_target_writer.h"
12 
13 class OutputFile;
14 
15 // Writes a .ninja file for a action target type.
16 class NinjaActionTargetWriter : public NinjaTargetWriter {
17  public:
18   NinjaActionTargetWriter(const Target* target, std::ostream& out);
19   ~NinjaActionTargetWriter() override;
20 
21   void Run() override;
22 
23  private:
24   FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter,
25                            WriteOutputFilesForBuildLine);
26   FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter,
27                            WriteOutputFilesForBuildLineWithDepfile);
28   FRIEND_TEST_ALL_PREFIXES(NinjaActionTargetWriter, WriteArgsSubstitutions);
29 
30   // Writes the Ninja rule for invoking the script.
31   //
32   // Returns the name of the custom rule generated. This will be based on the
33   // target name, and will include the string "$unique_name" if there are
34   // multiple inputs.
35   std::string WriteRuleDefinition();
36 
37   // Writes the rules for compiling each source, writing all output files
38   // to the given vector.
39   //
40   // input_deps are the dependencies common to all build steps.
41   void WriteSourceRules(const std::string& custom_rule_name,
42                         const std::vector<OutputFile>& input_deps,
43                         std::vector<OutputFile>* output_files);
44 
45   // Writes the output files generated by the output template for the given
46   // source file. This will start with a space and will not include a newline.
47   // Appends the output files to the given vector.
48   void WriteOutputFilesForBuildLine(const SourceFile& source,
49                                     std::vector<OutputFile>* output_files);
50 
51   void WriteDepfile(const SourceFile& source);
52 
53   // Writes variables that we make available to all actions, irrespective
54   // of whether they're associated with a specific source file.
55   void WriteNinjaVariablesForAction();
56 
57   // Path output writer that doesn't do any escaping or quoting. It does,
58   // however, convert slashes.  Used for
59   // computing intermediate strings.
60   PathOutput path_output_no_escaping_;
61 
62   NinjaActionTargetWriter(const NinjaActionTargetWriter&) = delete;
63   NinjaActionTargetWriter& operator=(const NinjaActionTargetWriter&) = delete;
64 };
65 
66 #endif  // TOOLS_GN_NINJA_ACTION_TARGET_WRITER_H_
67