Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 // | 38 // |
| 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. |
|
brettw
2016/10/05 19:47:50
Can you append a note here that the functions that
Petr Hosek
2016/10/11 00:59:50
Done.
| |
| 49 class SubstitutionWriter { | 49 class SubstitutionWriter { |
| 50 public: | 50 public: |
| 51 enum OutputStyle { | 51 enum OutputStyle { |
| 52 OUTPUT_ABSOLUTE, // Dirs will be absolute "//foo/bar". | 52 OUTPUT_ABSOLUTE, // Dirs will be absolute "//foo/bar". |
| 53 OUTPUT_RELATIVE, // Dirs will be relative to a given directory. | 53 OUTPUT_RELATIVE, // Dirs will be relative to a given directory. |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Writes the pattern to the given stream with no special handling, and with | 56 // Writes the pattern to the given stream with no special handling, and with |
| 57 // Ninja variables replacing the patterns. | 57 // Ninja variables replacing the patterns. |
| 58 static void WriteWithNinjaVariables( | 58 static void WriteWithNinjaVariables( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 73 const Settings* settings, | 73 const Settings* settings, |
| 74 const SubstitutionList& list, | 74 const SubstitutionList& list, |
| 75 std::vector<OutputFile>* output); | 75 std::vector<OutputFile>* output); |
| 76 | 76 |
| 77 // Source substitutions ----------------------------------------------------- | 77 // Source substitutions ----------------------------------------------------- |
| 78 | 78 |
| 79 // Applies the substitution pattern to a source file, returning the result | 79 // 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 | 80 // 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 | 81 // 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 | 82 // result isn't in the correct directory. The caller should validate this |
| 83 // first (see for example IsFileInOuputDir). | 83 // first (see for example IsFileInOuputDir). |
|
brettw
2016/10/05 19:47:50
GN almost never supports random pointers being nul
Petr Hosek
2016/10/11 00:59:49
Done.
| |
| 84 static SourceFile ApplyPatternToSource( | 84 static SourceFile ApplyPatternToSource( |
| 85 const Target* target, | |
| 85 const Settings* settings, | 86 const Settings* settings, |
| 86 const SubstitutionPattern& pattern, | 87 const SubstitutionPattern& pattern, |
| 87 const SourceFile& source); | 88 const SourceFile& source); |
| 88 static std::string ApplyPatternToSourceAsString( | 89 static std::string ApplyPatternToSourceAsString( |
| 90 const Target* target, | |
| 89 const Settings* settings, | 91 const Settings* settings, |
| 90 const SubstitutionPattern& pattern, | 92 const SubstitutionPattern& pattern, |
| 91 const SourceFile& source); | 93 const SourceFile& source); |
| 92 static OutputFile ApplyPatternToSourceAsOutputFile( | 94 static OutputFile ApplyPatternToSourceAsOutputFile( |
| 95 const Target* target, | |
| 93 const Settings* settings, | 96 const Settings* settings, |
| 94 const SubstitutionPattern& pattern, | 97 const SubstitutionPattern& pattern, |
| 95 const SourceFile& source); | 98 const SourceFile& source); |
| 96 | 99 |
| 97 // Applies the substitution list to a source, APPENDING the result to the | 100 // 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 | 101 // 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 | 102 // apply to multiple files and create a list. The result can either be |
| 100 // SourceFiles or OutputFiles. | 103 // SourceFiles or OutputFiles. |
| 101 static void ApplyListToSource( | 104 static void ApplyListToSource( |
| 105 const Target* target, | |
| 102 const Settings* settings, | 106 const Settings* settings, |
| 103 const SubstitutionList& list, | 107 const SubstitutionList& list, |
| 104 const SourceFile& source, | 108 const SourceFile& source, |
| 105 std::vector<SourceFile>* output); | 109 std::vector<SourceFile>* output); |
| 106 static void ApplyListToSourceAsString( | 110 static void ApplyListToSourceAsString( |
| 111 const Target* target, | |
| 107 const Settings* settings, | 112 const Settings* settings, |
| 108 const SubstitutionList& list, | 113 const SubstitutionList& list, |
| 109 const SourceFile& source, | 114 const SourceFile& source, |
| 110 std::vector<std::string>* output); | 115 std::vector<std::string>* output); |
| 111 static void ApplyListToSourceAsOutputFile( | 116 static void ApplyListToSourceAsOutputFile( |
| 117 const Target* target, | |
| 112 const Settings* settings, | 118 const Settings* settings, |
| 113 const SubstitutionList& list, | 119 const SubstitutionList& list, |
| 114 const SourceFile& source, | 120 const SourceFile& source, |
| 115 std::vector<OutputFile>* output); | 121 std::vector<OutputFile>* output); |
| 116 | 122 |
| 117 // Like ApplyListToSource but applies the list to all sources and replaces | 123 // Like ApplyListToSource but applies the list to all sources and replaces |
| 118 // rather than appends the output (this produces the complete output). | 124 // rather than appends the output (this produces the complete output). |
| 119 static void ApplyListToSources( | 125 static void ApplyListToSources( |
| 126 const Target* target, | |
| 120 const Settings* settings, | 127 const Settings* settings, |
| 121 const SubstitutionList& list, | 128 const SubstitutionList& list, |
| 122 const std::vector<SourceFile>& sources, | 129 const std::vector<SourceFile>& sources, |
| 123 std::vector<SourceFile>* output); | 130 std::vector<SourceFile>* output); |
| 124 static void ApplyListToSourcesAsString( | 131 static void ApplyListToSourcesAsString( |
| 132 const Target* target, | |
| 125 const Settings* settings, | 133 const Settings* settings, |
| 126 const SubstitutionList& list, | 134 const SubstitutionList& list, |
| 127 const std::vector<SourceFile>& sources, | 135 const std::vector<SourceFile>& sources, |
| 128 std::vector<std::string>* output); | 136 std::vector<std::string>* output); |
| 129 static void ApplyListToSourcesAsOutputFile( | 137 static void ApplyListToSourcesAsOutputFile( |
| 138 const Target* target, | |
| 130 const Settings* settings, | 139 const Settings* settings, |
| 131 const SubstitutionList& list, | 140 const SubstitutionList& list, |
| 132 const std::vector<SourceFile>& sources, | 141 const std::vector<SourceFile>& sources, |
| 133 std::vector<OutputFile>* output); | 142 std::vector<OutputFile>* output); |
| 134 | 143 |
| 135 // Given a list of source replacement types used, writes the Ninja variable | 144 // 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 | 145 // 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 | 146 // 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 | 147 // 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 | 148 // for {{source}} will be written since that maps to Ninja's implicit $in |
| 140 // variable. | 149 // variable. |
| 141 static void WriteNinjaVariablesForSource( | 150 static void WriteNinjaVariablesForSource( |
| 151 const Target* target, | |
| 142 const Settings* settings, | 152 const Settings* settings, |
| 143 const SourceFile& source, | 153 const SourceFile& source, |
| 144 const std::vector<SubstitutionType>& types, | 154 const std::vector<SubstitutionType>& types, |
| 145 const EscapeOptions& escape_options, | 155 const EscapeOptions& escape_options, |
| 146 std::ostream& out); | 156 std::ostream& out); |
| 147 | 157 |
| 148 // Extracts the given type of substitution related to a source file from the | 158 // 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 | 159 // given source file. If output_style is OUTPUT_RELATIVE, relative_to |
| 150 // indicates the directory that the relative directories should be relative | 160 // indicates the directory that the relative directories should be relative |
| 151 // to, otherwise it is ignored. | 161 // to, otherwise it is ignored. |
| 152 static std::string GetSourceSubstitution( | 162 static std::string GetSourceSubstitution( |
| 163 const Target* target, | |
| 153 const Settings* settings, | 164 const Settings* settings, |
| 154 const SourceFile& source, | 165 const SourceFile& source, |
| 155 SubstitutionType type, | 166 SubstitutionType type, |
| 156 OutputStyle output_style, | 167 OutputStyle output_style, |
| 157 const SourceDir& relative_to); | 168 const SourceDir& relative_to); |
| 158 | 169 |
| 159 // Target substitutions ------------------------------------------------------ | 170 // Target substitutions ------------------------------------------------------ |
| 160 // | 171 // |
| 161 // Handles the target substitutions that apply to both compiler and linker | 172 // Handles the target substitutions that apply to both compiler and linker |
| 162 // tools. | 173 // 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 | 231 // Like GetSourceSubstitution but for strings based on the target or |
| 221 // toolchain. This type of result will always be relative to the build | 232 // toolchain. This type of result will always be relative to the build |
| 222 // directory. | 233 // directory. |
| 223 static std::string GetLinkerSubstitution( | 234 static std::string GetLinkerSubstitution( |
| 224 const Target* target, | 235 const Target* target, |
| 225 const Tool* tool, | 236 const Tool* tool, |
| 226 SubstitutionType type); | 237 SubstitutionType type); |
| 227 }; | 238 }; |
| 228 | 239 |
| 229 #endif // TOOLS_GN_SUBSTITUTION_WRITER_H_ | 240 #endif // TOOLS_GN_SUBSTITUTION_WRITER_H_ |
| OLD | NEW |