Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: tools/gn/substitution_writer.h

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/substitution_type.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_GN_SUBSTITUTION_WRITER_H_
6 #define TOOLS_GN_SUBSTITUTION_WRITER_H_
7
8 #include <iosfwd>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "tools/gn/substitution_type.h"
13
14 struct EscapeOptions;
15 class OutputFile;
16 class Settings;
17 class SourceDir;
18 class SourceFile;
19 class SubstitutionList;
20 class SubstitutionPattern;
21
22 // Help text for script source expansion.
23 extern const char kSourceExpansion_Help[];
24
25 // This class handles writing or applying substitution patterns to strings.
26 class SubstitutionWriter {
27 public:
28 enum OutputStyle {
29 OUTPUT_ABSOLUTE, // Dirs will be absolute "//foo/bar".
30 OUTPUT_RELATIVE, // Dirs will be relative to a given directory.
31 };
32
33 SubstitutionWriter();
34 ~SubstitutionWriter();
35
36 // Applies the substitution pattern to a source file, returning the result
37 // as either a SourceFile or OutputFile.
38 static SourceFile ApplyPatternToSource(
39 const Settings* settings,
40 const SubstitutionPattern& pattern,
41 const SourceFile& source);
42 static OutputFile ApplyPatternToSourceAsOutputFile(
43 const Settings* settings,
44 const SubstitutionPattern& pattern,
45 const SourceFile& source);
46
47 // Applies the substitution list to a source, APPENDING the result to the
48 // given output vector. It works this way so one can call multiple times to
49 // apply to multiple files and create a list. The result can either be
50 // SourceFiles or OutputFiles.
51 static void ApplyListToSource(
52 const Settings* settings,
53 const SubstitutionList& list,
54 const SourceFile& source,
55 std::vector<SourceFile>* output);
56 static void ApplyListToSourceAsOutputFile(
57 const Settings* settings,
58 const SubstitutionList& list,
59 const SourceFile& source,
60 std::vector<OutputFile>* output);
61
62 // Like ApplyListToSource but applies the list to all sources and replaces
63 // rather than appesnds the output (this produces the complete output).
64 static void ApplyListToSources(
65 const Settings* settings,
66 const SubstitutionList& list,
67 const std::vector<SourceFile>& sources,
68 std::vector<SourceFile>* output);
69 static void ApplyListToSourcesAsOutputFile(
70 const Settings* settings,
71 const SubstitutionList& list,
72 const std::vector<SourceFile>& sources,
73 std::vector<OutputFile>* output);
74
75 // Given a list of source replacement types used, writes the Ninja variable
76 // definitions for the given source file to use for those replacements. The
77 // variables will be indented two spaces. Since this is for writing to
78 // Ninja files, paths will be relative to the build dir, and no definition
79 // for {{source}} will be written since that maps to Ninja's implicit $in
80 // variable.
81 static void WriteNinjaVariablesForSource(
82 const Settings* settings,
83 const SourceFile& source,
84 const std::vector<SubstitutionType>& types,
85 const EscapeOptions& escape_options,
86 std::ostream& out);
87
88 // Writes the pattern to the given stream with no special handling, and with
89 // Ninja variables replacing the patterns.
90 static void WriteWithNinjaVariables(
91 const SubstitutionPattern& pattern,
92 const EscapeOptions& escape_options,
93 std::ostream& out);
94
95 // Extracts the given type of substitution related to a source file from the
96 // given source file. If output_style is OUTPUT_RELATIVE, relative_to
97 // indicates the directory that the relative directories should be relative
98 // to, otherwise it is ignored.
99 static std::string GetSourceSubstitution(
100 const Settings* settings,
101 const SourceFile& source,
102 SubstitutionType type,
103 OutputStyle output_style,
104 const SourceDir& relative_to);
105 };
106
107 #endif // TOOLS_GN_SUBSTITUTION_WRITER_H_
OLDNEW
« no previous file with comments | « tools/gn/substitution_type.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698