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

Side by Side Diff: tools/gn/substitution_type.cc

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.h ('k') | tools/gn/substitution_writer.h » ('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 #include "tools/gn/substitution_type.h"
6
7 #include <stdlib.h>
8
9 #include "tools/gn/err.h"
10
11 const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES] = {
12 NULL, // SUBSTITUTION_LITERAL
13
14 "{{source}}", // SUBSTITUTION_SOURCE
15 "{{source_name_part}}", // SUBSTITUTION_NAME_PART
16 "{{source_file_part}}", // SUBSTITUTION_FILE_PART
17 "{{source_dir}}", // SUBSTITUTION_SOURCE_DIR
18 "{{source_root_relative_dir}}", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR
19 "{{source_gen_dir}}", // SUBSTITUTION_SOURCE_GEN_DIR
20 "{{source_out_dir}}", // SUBSTITUTION_SOURCE_OUT_DIR
21
22 "{{output}}", // SUBSTITUTION_OUTPUT
23 "{{root_gen_dir}}", // SUBSTITUTION_ROOT_GEN_DIR
24 "{{root_out_dir}}", // SUBSTITUTION_ROOT_OUT_DIR
25 "{{target_gen_dir}}", // SUBSTITUTION_TARGET_GEN_DIR
26 "{{target_out_dir}}", // SUBSTITUTION_TARGET_OUT_DIR
27 "{{target_output_name}}", // SUBSTITUTION_TARGET_OUTPUT_NAME
28
29 "{{cflags}}", // SUBSTITUTION_CFLAGS
30 "{{cflags_c}}", // SUBSTITUTION_CFLAGS_C
31 "{{cflags_cc}}", // SUBSTITUTION_CFLAGS_CC
32 "{{cflags_objc}}", // SUBSTITUTION_CFLAGS_OBJC
33 "{{cflags_objcc}}", // SUBSTITUTION_CFLAGS_OBJCC
34 "{{defines}}", // SUBSTITUTION_DEFINES
35 "{{include_dirs}}", // SUBSTITUTION_INCLUDE_DIRS
36
37 "{{inputs}}", // SUBSTITUTION_LINKER_INPUTS
38 "{{ldflags}}", // SUBSTITUTION_LDFLAGS
39 "{{libs}}", // SUBSTITUTION_LIBS
40 "{{output_extension}}", // SUBSTITUTION_OUTPUT_EXTENSION
41 "{{solibs}}", // SUBSTITUTION_SOLIBS
42 };
43
44 const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES] = {
45 NULL, // SUBSTITUTION_LITERAL
46
47 // This isn't written by GN, the name here is referring to the Ninja variable
48 // since when we would use this would be for writing source rules.
49 "in", // SUBSTITUTION_SOURCE
50 "source_name_part", // SUBSTITUTION_NAME_PART
51 "source_file_part", // SUBSTITUTION_FILE_PART
52 "source_dir", // SUBSTITUTION_SOURCE_DIR
53 "source_root_relative_dir", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR
54 "source_gen_dir", // SUBSTITUTION_SOURCE_GEN_DIR
55 "source_out_dir", // SUBSTITUTION_SOURCE_OUT_DIR
56
57 "output", // SUBSTITUTION_OUTPUT
58 "root_gen_dir", // SUBSTITUTION_ROOT_GEN_DIR
59 "root_out_dir", // SUBSTITUTION_ROOT_OUT_DIR
60 "target_gen_dir", // SUBSTITUTION_TARGET_GEN_DIR
61 "target_out_dir", // SUBSTITUTION_TARGET_OUT_DIR
62 "target_output_name", // SUBSTITUTION_TARGET_OUTPUT_NAME
63
64 "cflags", // SUBSTITUTION_CFLAGS
65 "cflags_c", // SUBSTITUTION_CFLAGS_C
66 "cflags_cc", // SUBSTITUTION_CFLAGS_CC
67 "cflags_objc", // SUBSTITUTION_CFLAGS_OBJC
68 "cflags_objcc", // SUBSTITUTION_CFLAGS_OBJCC
69 "defines", // SUBSTITUTION_DEFINES
70 "include_dirs", // SUBSTITUTION_INCLUDE_DIRS
71
72 "inputs", // SUBSTITUTION_LINKER_INPUTS
73 "ldflags", // SUBSTITUTION_LDFLAGS
74 "libs", // SUBSTITUTION_LIBS
75 "output_extension", // SUBSTITUTION_OUTPUT_EXTENSION
76 "solibs", // SUBSTITUTION_SOLIBS
77 };
78
79 bool SubstitutionIsInOutputDir(SubstitutionType type) {
80 return type == SUBSTITUTION_SOURCE_GEN_DIR ||
81 type == SUBSTITUTION_SOURCE_OUT_DIR;
82 }
83
84 bool IsValidSourceSubstitution(SubstitutionType type) {
85 return type == SUBSTITUTION_SOURCE ||
86 type == SUBSTITUTION_SOURCE_NAME_PART ||
87 type == SUBSTITUTION_SOURCE_FILE_PART ||
88 type == SUBSTITUTION_SOURCE_DIR ||
89 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR ||
90 type == SUBSTITUTION_SOURCE_GEN_DIR ||
91 type == SUBSTITUTION_SOURCE_OUT_DIR;
92 }
93
94 bool IsValidToolSubstutition(SubstitutionType type) {
95 return type == SUBSTITUTION_OUTPUT ||
96 type == SUBSTITUTION_ROOT_GEN_DIR ||
97 type == SUBSTITUTION_ROOT_OUT_DIR ||
98 type == SUBSTITUTION_TARGET_GEN_DIR ||
99 type == SUBSTITUTION_TARGET_OUT_DIR ||
100 type == SUBSTITUTION_TARGET_OUTPUT_NAME;
101 }
102
103 bool IsValidCompilerSubstitution(SubstitutionType type) {
104 return IsValidToolSubstutition(type) ||
105 type == SUBSTITUTION_CFLAGS ||
106 type == SUBSTITUTION_CFLAGS_C ||
107 type == SUBSTITUTION_CFLAGS_CC ||
108 type == SUBSTITUTION_CFLAGS_OBJC ||
109 type == SUBSTITUTION_CFLAGS_OBJCC ||
110 type == SUBSTITUTION_DEFINES ||
111 type == SUBSTITUTION_INCLUDE_DIRS;
112 }
113
114 bool IsValidCompilerOutputsSubstitution(SubstitutionType type) {
115 // All tool types except "output" (which would be infinitely recursive).
116 return IsValidToolSubstutition(type) &&
117 type != SUBSTITUTION_OUTPUT;
118 }
119
120 bool IsValidLinkerSubstitution(SubstitutionType type) {
121 return IsValidToolSubstutition(type) ||
122 type == SUBSTITUTION_LINKER_INPUTS ||
123 type == SUBSTITUTION_LDFLAGS ||
124 type == SUBSTITUTION_LIBS ||
125 type == SUBSTITUTION_OUTPUT_EXTENSION ||
126 type == SUBSTITUTION_SOLIBS;
127 }
128
129 bool IsValidLinkerOutputsSubstitution(SubstitutionType type) {
130 // All valid compiler outputs plus the output extension.
131 return IsValidCompilerOutputsSubstitution(type) ||
132 type == SUBSTITUTION_OUTPUT_EXTENSION;
133 }
134
135 bool EnsureValidSourcesSubstitutions(
136 const std::vector<SubstitutionType>& types,
137 const ParseNode* origin,
138 Err* err) {
139 for (size_t i = 0; i < types.size(); i++) {
140 if (!IsValidSourceSubstitution(types[i])) {
141 *err = Err(origin, "Invalid substitution type.",
142 "The substitution " + std::string(kSubstitutionNames[i]) +
143 " isn't valid for something\n"
144 "operating on a source file such as this.");
145 return false;
146 }
147 }
148 return true;
149 }
OLDNEW
« no previous file with comments | « tools/gn/substitution_type.h ('k') | tools/gn/substitution_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698