| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef TOOLS_GN_SUBSTITUTION_WRITER_H_ | 5 #ifndef TOOLS_GN_SUBSTITUTION_WRITER_H_ |
| 6 #define TOOLS_GN_SUBSTITUTION_WRITER_H_ | 6 #define TOOLS_GN_SUBSTITUTION_WRITER_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // - Compiler substitutions: These are used to compute compiler outputs. | 39 // - Compiler substitutions: These are used to compute compiler outputs. |
| 40 // It includes all source substitutions (since they depend on the various | 40 // It includes all source substitutions (since they depend on the various |
| 41 // parts of the source file) as well as the target substitutions. | 41 // parts of the source file) as well as the target substitutions. |
| 42 // | 42 // |
| 43 // - Linker substitutions: These are used to compute linker outputs. It | 43 // - Linker substitutions: These are used to compute linker outputs. It |
| 44 // includes the target substitutions. | 44 // includes the target substitutions. |
| 45 // | 45 // |
| 46 // The compiler and linker specific substitutions do NOT include the various | 46 // The compiler and linker specific substitutions do NOT include the various |
| 47 // cflags, ldflags, libraries, etc. These are written by the ninja target | 47 // cflags, ldflags, libraries, etc. These are written by the ninja target |
| 48 // writer since they depend on traversing the dependency tree. | 48 // writer since they depend on traversing the dependency tree. |
| 49 // |
| 50 // The methods which take a target as an argument can accept null target |
| 51 // pointer if there is no target context, in which case the substitutions |
| 52 // requiring target context will not work. |
| 49 class SubstitutionWriter { | 53 class SubstitutionWriter { |
| 50 public: | 54 public: |
| 51 enum OutputStyle { | 55 enum OutputStyle { |
| 52 OUTPUT_ABSOLUTE, // Dirs will be absolute "//foo/bar". | 56 OUTPUT_ABSOLUTE, // Dirs will be absolute "//foo/bar". |
| 53 OUTPUT_RELATIVE, // Dirs will be relative to a given directory. | 57 OUTPUT_RELATIVE, // Dirs will be relative to a given directory. |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 // Writes the pattern to the given stream with no special handling, and with | 60 // Writes the pattern to the given stream with no special handling, and with |
| 57 // Ninja variables replacing the patterns. | 61 // Ninja variables replacing the patterns. |
| 58 static void WriteWithNinjaVariables( | 62 static void WriteWithNinjaVariables( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 const SubstitutionList& list, | 78 const SubstitutionList& list, |
| 75 std::vector<OutputFile>* output); | 79 std::vector<OutputFile>* output); |
| 76 | 80 |
| 77 // Source substitutions ----------------------------------------------------- | 81 // Source substitutions ----------------------------------------------------- |
| 78 | 82 |
| 79 // Applies the substitution pattern to a source file, returning the result | 83 // Applies the substitution pattern to a source file, returning the result |
| 80 // as either a string, a SourceFile or an OutputFile. If the result is | 84 // as either a string, a SourceFile or an OutputFile. If the result is |
| 81 // expected to be a SourceFile or an OutputFile, this will CHECK if the | 85 // expected to be a SourceFile or an OutputFile, this will CHECK if the |
| 82 // result isn't in the correct directory. The caller should validate this | 86 // result isn't in the correct directory. The caller should validate this |
| 83 // first (see for example IsFileInOuputDir). | 87 // first (see for example IsFileInOuputDir). |
| 88 // |
| 89 // The target can be null (see class comment above). |
| 84 static SourceFile ApplyPatternToSource( | 90 static SourceFile ApplyPatternToSource( |
| 91 const Target* target, |
| 85 const Settings* settings, | 92 const Settings* settings, |
| 86 const SubstitutionPattern& pattern, | 93 const SubstitutionPattern& pattern, |
| 87 const SourceFile& source); | 94 const SourceFile& source); |
| 88 static std::string ApplyPatternToSourceAsString( | 95 static std::string ApplyPatternToSourceAsString( |
| 96 const Target* target, |
| 89 const Settings* settings, | 97 const Settings* settings, |
| 90 const SubstitutionPattern& pattern, | 98 const SubstitutionPattern& pattern, |
| 91 const SourceFile& source); | 99 const SourceFile& source); |
| 92 static OutputFile ApplyPatternToSourceAsOutputFile( | 100 static OutputFile ApplyPatternToSourceAsOutputFile( |
| 101 const Target* target, |
| 93 const Settings* settings, | 102 const Settings* settings, |
| 94 const SubstitutionPattern& pattern, | 103 const SubstitutionPattern& pattern, |
| 95 const SourceFile& source); | 104 const SourceFile& source); |
| 96 | 105 |
| 97 // Applies the substitution list to a source, APPENDING the result to the | 106 // Applies the substitution list to a source, APPENDING the result to the |
| 98 // given output vector. It works this way so one can call multiple times to | 107 // given output vector. It works this way so one can call multiple times to |
| 99 // apply to multiple files and create a list. The result can either be | 108 // apply to multiple files and create a list. The result can either be |
| 100 // SourceFiles or OutputFiles. | 109 // SourceFiles or OutputFiles. |
| 110 // |
| 111 // The target can be null (see class comment above). |
| 101 static void ApplyListToSource( | 112 static void ApplyListToSource( |
| 113 const Target* target, |
| 102 const Settings* settings, | 114 const Settings* settings, |
| 103 const SubstitutionList& list, | 115 const SubstitutionList& list, |
| 104 const SourceFile& source, | 116 const SourceFile& source, |
| 105 std::vector<SourceFile>* output); | 117 std::vector<SourceFile>* output); |
| 106 static void ApplyListToSourceAsString( | 118 static void ApplyListToSourceAsString( |
| 119 const Target* target, |
| 107 const Settings* settings, | 120 const Settings* settings, |
| 108 const SubstitutionList& list, | 121 const SubstitutionList& list, |
| 109 const SourceFile& source, | 122 const SourceFile& source, |
| 110 std::vector<std::string>* output); | 123 std::vector<std::string>* output); |
| 111 static void ApplyListToSourceAsOutputFile( | 124 static void ApplyListToSourceAsOutputFile( |
| 125 const Target* target, |
| 112 const Settings* settings, | 126 const Settings* settings, |
| 113 const SubstitutionList& list, | 127 const SubstitutionList& list, |
| 114 const SourceFile& source, | 128 const SourceFile& source, |
| 115 std::vector<OutputFile>* output); | 129 std::vector<OutputFile>* output); |
| 116 | 130 |
| 117 // Like ApplyListToSource but applies the list to all sources and replaces | 131 // Like ApplyListToSource but applies the list to all sources and replaces |
| 118 // rather than appends the output (this produces the complete output). | 132 // rather than appends the output (this produces the complete output). |
| 133 // |
| 134 // The target can be null (see class comment above). |
| 119 static void ApplyListToSources( | 135 static void ApplyListToSources( |
| 136 const Target* target, |
| 120 const Settings* settings, | 137 const Settings* settings, |
| 121 const SubstitutionList& list, | 138 const SubstitutionList& list, |
| 122 const std::vector<SourceFile>& sources, | 139 const std::vector<SourceFile>& sources, |
| 123 std::vector<SourceFile>* output); | 140 std::vector<SourceFile>* output); |
| 124 static void ApplyListToSourcesAsString( | 141 static void ApplyListToSourcesAsString( |
| 142 const Target* target, |
| 125 const Settings* settings, | 143 const Settings* settings, |
| 126 const SubstitutionList& list, | 144 const SubstitutionList& list, |
| 127 const std::vector<SourceFile>& sources, | 145 const std::vector<SourceFile>& sources, |
| 128 std::vector<std::string>* output); | 146 std::vector<std::string>* output); |
| 129 static void ApplyListToSourcesAsOutputFile( | 147 static void ApplyListToSourcesAsOutputFile( |
| 148 const Target* target, |
| 130 const Settings* settings, | 149 const Settings* settings, |
| 131 const SubstitutionList& list, | 150 const SubstitutionList& list, |
| 132 const std::vector<SourceFile>& sources, | 151 const std::vector<SourceFile>& sources, |
| 133 std::vector<OutputFile>* output); | 152 std::vector<OutputFile>* output); |
| 134 | 153 |
| 135 // Given a list of source replacement types used, writes the Ninja variable | 154 // Given a list of source replacement types used, writes the Ninja variable |
| 136 // definitions for the given source file to use for those replacements. The | 155 // definitions for the given source file to use for those replacements. The |
| 137 // variables will be indented two spaces. Since this is for writing to | 156 // variables will be indented two spaces. Since this is for writing to |
| 138 // Ninja files, paths will be relative to the build dir, and no definition | 157 // Ninja files, paths will be relative to the build dir, and no definition |
| 139 // for {{source}} will be written since that maps to Ninja's implicit $in | 158 // for {{source}} will be written since that maps to Ninja's implicit $in |
| 140 // variable. | 159 // variable. |
| 160 // |
| 161 // The target can be null (see class comment above). |
| 141 static void WriteNinjaVariablesForSource( | 162 static void WriteNinjaVariablesForSource( |
| 163 const Target* target, |
| 142 const Settings* settings, | 164 const Settings* settings, |
| 143 const SourceFile& source, | 165 const SourceFile& source, |
| 144 const std::vector<SubstitutionType>& types, | 166 const std::vector<SubstitutionType>& types, |
| 145 const EscapeOptions& escape_options, | 167 const EscapeOptions& escape_options, |
| 146 std::ostream& out); | 168 std::ostream& out); |
| 147 | 169 |
| 148 // Extracts the given type of substitution related to a source file from the | 170 // Extracts the given type of substitution related to a source file from the |
| 149 // given source file. If output_style is OUTPUT_RELATIVE, relative_to | 171 // given source file. If output_style is OUTPUT_RELATIVE, relative_to |
| 150 // indicates the directory that the relative directories should be relative | 172 // indicates the directory that the relative directories should be relative |
| 151 // to, otherwise it is ignored. | 173 // to, otherwise it is ignored. |
| 174 // |
| 175 // The target can be null (see class comment above). |
| 152 static std::string GetSourceSubstitution( | 176 static std::string GetSourceSubstitution( |
| 177 const Target* target, |
| 153 const Settings* settings, | 178 const Settings* settings, |
| 154 const SourceFile& source, | 179 const SourceFile& source, |
| 155 SubstitutionType type, | 180 SubstitutionType type, |
| 156 OutputStyle output_style, | 181 OutputStyle output_style, |
| 157 const SourceDir& relative_to); | 182 const SourceDir& relative_to); |
| 158 | 183 |
| 159 // Target substitutions ------------------------------------------------------ | 184 // Target substitutions ------------------------------------------------------ |
| 160 // | 185 // |
| 161 // Handles the target substitutions that apply to both compiler and linker | 186 // Handles the target substitutions that apply to both compiler and linker |
| 162 // tools. | 187 // tools. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // Like GetSourceSubstitution but for strings based on the target or | 245 // Like GetSourceSubstitution but for strings based on the target or |
| 221 // toolchain. This type of result will always be relative to the build | 246 // toolchain. This type of result will always be relative to the build |
| 222 // directory. | 247 // directory. |
| 223 static std::string GetLinkerSubstitution( | 248 static std::string GetLinkerSubstitution( |
| 224 const Target* target, | 249 const Target* target, |
| 225 const Tool* tool, | 250 const Tool* tool, |
| 226 SubstitutionType type); | 251 SubstitutionType type); |
| 227 }; | 252 }; |
| 228 | 253 |
| 229 #endif // TOOLS_GN_SUBSTITUTION_WRITER_H_ | 254 #endif // TOOLS_GN_SUBSTITUTION_WRITER_H_ |
| OLD | NEW |