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

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

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unsigned check 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
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 #include "tools/gn/substitution_type.h" 5 #include "tools/gn/substitution_type.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
10 10
11 const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES] = { 11 const char* kSubstitutionNames[SUBSTITUTION_NUM_TYPES] = {
12 NULL, // SUBSTITUTION_LITERAL 12 "<<literal>>", // SUBSTITUTION_LITERAL
13 13
14 "{{source}}", // SUBSTITUTION_SOURCE 14 "{{source}}", // SUBSTITUTION_SOURCE
15 "{{output}}", // SUBSTITUTION_OUTPUT
16
15 "{{source_name_part}}", // SUBSTITUTION_NAME_PART 17 "{{source_name_part}}", // SUBSTITUTION_NAME_PART
16 "{{source_file_part}}", // SUBSTITUTION_FILE_PART 18 "{{source_file_part}}", // SUBSTITUTION_FILE_PART
17 "{{source_dir}}", // SUBSTITUTION_SOURCE_DIR 19 "{{source_dir}}", // SUBSTITUTION_SOURCE_DIR
18 "{{source_root_relative_dir}}", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR 20 "{{source_root_relative_dir}}", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR
19 "{{source_gen_dir}}", // SUBSTITUTION_SOURCE_GEN_DIR 21 "{{source_gen_dir}}", // SUBSTITUTION_SOURCE_GEN_DIR
20 "{{source_out_dir}}", // SUBSTITUTION_SOURCE_OUT_DIR 22 "{{source_out_dir}}", // SUBSTITUTION_SOURCE_OUT_DIR
21 23
22 "{{output}}", // SUBSTITUTION_OUTPUT 24 "{{label}}", // SUBSTITUTION_LABEL
23 "{{root_gen_dir}}", // SUBSTITUTION_ROOT_GEN_DIR 25 "{{root_gen_dir}}", // SUBSTITUTION_ROOT_GEN_DIR
24 "{{root_out_dir}}", // SUBSTITUTION_ROOT_OUT_DIR 26 "{{root_out_dir}}", // SUBSTITUTION_ROOT_OUT_DIR
25 "{{target_gen_dir}}", // SUBSTITUTION_TARGET_GEN_DIR 27 "{{target_gen_dir}}", // SUBSTITUTION_TARGET_GEN_DIR
26 "{{target_out_dir}}", // SUBSTITUTION_TARGET_OUT_DIR 28 "{{target_out_dir}}", // SUBSTITUTION_TARGET_OUT_DIR
27 "{{target_output_name}}", // SUBSTITUTION_TARGET_OUTPUT_NAME 29 "{{target_output_name}}", // SUBSTITUTION_TARGET_OUTPUT_NAME
28 30
29 "{{cflags}}", // SUBSTITUTION_CFLAGS 31 "{{cflags}}", // SUBSTITUTION_CFLAGS
30 "{{cflags_c}}", // SUBSTITUTION_CFLAGS_C 32 "{{cflags_c}}", // SUBSTITUTION_CFLAGS_C
31 "{{cflags_cc}}", // SUBSTITUTION_CFLAGS_CC 33 "{{cflags_cc}}", // SUBSTITUTION_CFLAGS_CC
32 "{{cflags_objc}}", // SUBSTITUTION_CFLAGS_OBJC 34 "{{cflags_objc}}", // SUBSTITUTION_CFLAGS_OBJC
33 "{{cflags_objcc}}", // SUBSTITUTION_CFLAGS_OBJCC 35 "{{cflags_objcc}}", // SUBSTITUTION_CFLAGS_OBJCC
34 "{{defines}}", // SUBSTITUTION_DEFINES 36 "{{defines}}", // SUBSTITUTION_DEFINES
35 "{{include_dirs}}", // SUBSTITUTION_INCLUDE_DIRS 37 "{{include_dirs}}", // SUBSTITUTION_INCLUDE_DIRS
36 38
37 "{{inputs}}", // SUBSTITUTION_LINKER_INPUTS 39 "{{inputs}}", // SUBSTITUTION_LINKER_INPUTS
38 "{{ldflags}}", // SUBSTITUTION_LDFLAGS 40 "{{ldflags}}", // SUBSTITUTION_LDFLAGS
39 "{{libs}}", // SUBSTITUTION_LIBS 41 "{{libs}}", // SUBSTITUTION_LIBS
40 "{{output_extension}}", // SUBSTITUTION_OUTPUT_EXTENSION 42 "{{output_extension}}", // SUBSTITUTION_OUTPUT_EXTENSION
41 "{{solibs}}", // SUBSTITUTION_SOLIBS 43 "{{solibs}}", // SUBSTITUTION_SOLIBS
42 }; 44 };
43 45
44 const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES] = { 46 const char* kSubstitutionNinjaNames[SUBSTITUTION_NUM_TYPES] = {
45 NULL, // SUBSTITUTION_LITERAL 47 NULL, // SUBSTITUTION_LITERAL
46 48
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 49 "in", // SUBSTITUTION_SOURCE
50 "out", // SUBSTITUTION_OUTPUT
51
50 "source_name_part", // SUBSTITUTION_NAME_PART 52 "source_name_part", // SUBSTITUTION_NAME_PART
51 "source_file_part", // SUBSTITUTION_FILE_PART 53 "source_file_part", // SUBSTITUTION_FILE_PART
52 "source_dir", // SUBSTITUTION_SOURCE_DIR 54 "source_dir", // SUBSTITUTION_SOURCE_DIR
53 "source_root_relative_dir", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR 55 "source_root_relative_dir", // SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR
54 "source_gen_dir", // SUBSTITUTION_SOURCE_GEN_DIR 56 "source_gen_dir", // SUBSTITUTION_SOURCE_GEN_DIR
55 "source_out_dir", // SUBSTITUTION_SOURCE_OUT_DIR 57 "source_out_dir", // SUBSTITUTION_SOURCE_OUT_DIR
56 58
57 "output", // SUBSTITUTION_OUTPUT 59 "label", // SUBSTITUTION_LABEL
58 "root_gen_dir", // SUBSTITUTION_ROOT_GEN_DIR 60 "root_gen_dir", // SUBSTITUTION_ROOT_GEN_DIR
59 "root_out_dir", // SUBSTITUTION_ROOT_OUT_DIR 61 "root_out_dir", // SUBSTITUTION_ROOT_OUT_DIR
60 "target_gen_dir", // SUBSTITUTION_TARGET_GEN_DIR 62 "target_gen_dir", // SUBSTITUTION_TARGET_GEN_DIR
61 "target_out_dir", // SUBSTITUTION_TARGET_OUT_DIR 63 "target_out_dir", // SUBSTITUTION_TARGET_OUT_DIR
62 "target_output_name", // SUBSTITUTION_TARGET_OUTPUT_NAME 64 "target_output_name", // SUBSTITUTION_TARGET_OUTPUT_NAME
63 65
64 "cflags", // SUBSTITUTION_CFLAGS 66 "cflags", // SUBSTITUTION_CFLAGS
65 "cflags_c", // SUBSTITUTION_CFLAGS_C 67 "cflags_c", // SUBSTITUTION_CFLAGS_C
66 "cflags_cc", // SUBSTITUTION_CFLAGS_CC 68 "cflags_cc", // SUBSTITUTION_CFLAGS_CC
67 "cflags_objc", // SUBSTITUTION_CFLAGS_OBJC 69 "cflags_objc", // SUBSTITUTION_CFLAGS_OBJC
68 "cflags_objcc", // SUBSTITUTION_CFLAGS_OBJCC 70 "cflags_objcc", // SUBSTITUTION_CFLAGS_OBJCC
69 "defines", // SUBSTITUTION_DEFINES 71 "defines", // SUBSTITUTION_DEFINES
70 "include_dirs", // SUBSTITUTION_INCLUDE_DIRS 72 "include_dirs", // SUBSTITUTION_INCLUDE_DIRS
71 73
72 "inputs", // SUBSTITUTION_LINKER_INPUTS 74 // LINKER_INPUTS expands to the same Ninja var as SUBSTITUTION_SOURCE. These
75 // are used in different contexts and are named differently to keep things
76 // clear, but they both expand to the "set of input files" for a build rule.
77 "in", // SUBSTITUTION_LINKER_INPUTS
73 "ldflags", // SUBSTITUTION_LDFLAGS 78 "ldflags", // SUBSTITUTION_LDFLAGS
74 "libs", // SUBSTITUTION_LIBS 79 "libs", // SUBSTITUTION_LIBS
75 "output_extension", // SUBSTITUTION_OUTPUT_EXTENSION 80 "output_extension", // SUBSTITUTION_OUTPUT_EXTENSION
76 "solibs", // SUBSTITUTION_SOLIBS 81 "solibs", // SUBSTITUTION_SOLIBS
77 }; 82 };
78 83
84 SubstitutionBits::SubstitutionBits() : used() {
85 }
86
87 void SubstitutionBits::MergeFrom(const SubstitutionBits& other) {
88 for (size_t i = 0; i < SUBSTITUTION_NUM_TYPES; i++)
89 used[i] |= other.used[i];
90 }
91
92 void SubstitutionBits::FillVector(std::vector<SubstitutionType>* vect) const {
93 for (size_t i = SUBSTITUTION_FIRST_PATTERN; i < SUBSTITUTION_NUM_TYPES; i++) {
94 if (used[i])
95 vect->push_back(static_cast<SubstitutionType>(i));
96 }
97 }
98
79 bool SubstitutionIsInOutputDir(SubstitutionType type) { 99 bool SubstitutionIsInOutputDir(SubstitutionType type) {
80 return type == SUBSTITUTION_SOURCE_GEN_DIR || 100 return type == SUBSTITUTION_SOURCE_GEN_DIR ||
81 type == SUBSTITUTION_SOURCE_OUT_DIR; 101 type == SUBSTITUTION_SOURCE_OUT_DIR ||
102 type == SUBSTITUTION_ROOT_GEN_DIR ||
103 type == SUBSTITUTION_ROOT_OUT_DIR ||
104 type == SUBSTITUTION_TARGET_GEN_DIR ||
105 type == SUBSTITUTION_TARGET_OUT_DIR;
82 } 106 }
83 107
84 bool IsValidSourceSubstitution(SubstitutionType type) { 108 bool IsValidSourceSubstitution(SubstitutionType type) {
85 return type == SUBSTITUTION_SOURCE || 109 return type == SUBSTITUTION_LITERAL ||
110 type == SUBSTITUTION_SOURCE ||
86 type == SUBSTITUTION_SOURCE_NAME_PART || 111 type == SUBSTITUTION_SOURCE_NAME_PART ||
87 type == SUBSTITUTION_SOURCE_FILE_PART || 112 type == SUBSTITUTION_SOURCE_FILE_PART ||
88 type == SUBSTITUTION_SOURCE_DIR || 113 type == SUBSTITUTION_SOURCE_DIR ||
89 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR || 114 type == SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR ||
90 type == SUBSTITUTION_SOURCE_GEN_DIR || 115 type == SUBSTITUTION_SOURCE_GEN_DIR ||
91 type == SUBSTITUTION_SOURCE_OUT_DIR; 116 type == SUBSTITUTION_SOURCE_OUT_DIR;
92 } 117 }
93 118
94 bool IsValidToolSubstutition(SubstitutionType type) { 119 bool IsValidToolSubstutition(SubstitutionType type) {
95 return type == SUBSTITUTION_OUTPUT || 120 return type == SUBSTITUTION_LITERAL ||
121 type == SUBSTITUTION_OUTPUT ||
122 type == SUBSTITUTION_LABEL ||
96 type == SUBSTITUTION_ROOT_GEN_DIR || 123 type == SUBSTITUTION_ROOT_GEN_DIR ||
97 type == SUBSTITUTION_ROOT_OUT_DIR || 124 type == SUBSTITUTION_ROOT_OUT_DIR ||
98 type == SUBSTITUTION_TARGET_GEN_DIR || 125 type == SUBSTITUTION_TARGET_GEN_DIR ||
99 type == SUBSTITUTION_TARGET_OUT_DIR || 126 type == SUBSTITUTION_TARGET_OUT_DIR ||
100 type == SUBSTITUTION_TARGET_OUTPUT_NAME; 127 type == SUBSTITUTION_TARGET_OUTPUT_NAME;
101 } 128 }
102 129
103 bool IsValidCompilerSubstitution(SubstitutionType type) { 130 bool IsValidCompilerSubstitution(SubstitutionType type) {
104 return IsValidToolSubstutition(type) || 131 return IsValidToolSubstutition(type) ||
132 IsValidSourceSubstitution(type) ||
133 type == SUBSTITUTION_SOURCE ||
105 type == SUBSTITUTION_CFLAGS || 134 type == SUBSTITUTION_CFLAGS ||
106 type == SUBSTITUTION_CFLAGS_C || 135 type == SUBSTITUTION_CFLAGS_C ||
107 type == SUBSTITUTION_CFLAGS_CC || 136 type == SUBSTITUTION_CFLAGS_CC ||
108 type == SUBSTITUTION_CFLAGS_OBJC || 137 type == SUBSTITUTION_CFLAGS_OBJC ||
109 type == SUBSTITUTION_CFLAGS_OBJCC || 138 type == SUBSTITUTION_CFLAGS_OBJCC ||
110 type == SUBSTITUTION_DEFINES || 139 type == SUBSTITUTION_DEFINES ||
111 type == SUBSTITUTION_INCLUDE_DIRS; 140 type == SUBSTITUTION_INCLUDE_DIRS;
112 } 141 }
113 142
114 bool IsValidCompilerOutputsSubstitution(SubstitutionType type) { 143 bool IsValidCompilerOutputsSubstitution(SubstitutionType type) {
115 // All tool types except "output" (which would be infinitely recursive). 144 // All tool types except "output" (which would be infinitely recursive).
116 return IsValidToolSubstutition(type) && 145 return (IsValidToolSubstutition(type) && type != SUBSTITUTION_OUTPUT) ||
117 type != SUBSTITUTION_OUTPUT; 146 IsValidSourceSubstitution(type);
118 } 147 }
119 148
120 bool IsValidLinkerSubstitution(SubstitutionType type) { 149 bool IsValidLinkerSubstitution(SubstitutionType type) {
121 return IsValidToolSubstutition(type) || 150 return IsValidToolSubstutition(type) ||
122 type == SUBSTITUTION_LINKER_INPUTS || 151 type == SUBSTITUTION_LINKER_INPUTS ||
123 type == SUBSTITUTION_LDFLAGS || 152 type == SUBSTITUTION_LDFLAGS ||
124 type == SUBSTITUTION_LIBS || 153 type == SUBSTITUTION_LIBS ||
125 type == SUBSTITUTION_OUTPUT_EXTENSION || 154 type == SUBSTITUTION_OUTPUT_EXTENSION ||
126 type == SUBSTITUTION_SOLIBS; 155 type == SUBSTITUTION_SOLIBS;
127 } 156 }
128 157
129 bool IsValidLinkerOutputsSubstitution(SubstitutionType type) { 158 bool IsValidLinkerOutputsSubstitution(SubstitutionType type) {
130 // All valid compiler outputs plus the output extension. 159 // All valid compiler outputs plus the output extension.
131 return IsValidCompilerOutputsSubstitution(type) || 160 return IsValidCompilerOutputsSubstitution(type) ||
132 type == SUBSTITUTION_OUTPUT_EXTENSION; 161 type == SUBSTITUTION_OUTPUT_EXTENSION;
133 } 162 }
134 163
164 bool IsValidCopySubstitution(SubstitutionType type) {
165 return IsValidToolSubstutition(type) ||
166 type == SUBSTITUTION_SOURCE;
167 }
168
135 bool EnsureValidSourcesSubstitutions( 169 bool EnsureValidSourcesSubstitutions(
136 const std::vector<SubstitutionType>& types, 170 const std::vector<SubstitutionType>& types,
137 const ParseNode* origin, 171 const ParseNode* origin,
138 Err* err) { 172 Err* err) {
139 for (size_t i = 0; i < types.size(); i++) { 173 for (size_t i = 0; i < types.size(); i++) {
140 if (!IsValidSourceSubstitution(types[i])) { 174 if (!IsValidSourceSubstitution(types[i])) {
141 *err = Err(origin, "Invalid substitution type.", 175 *err = Err(origin, "Invalid substitution type.",
142 "The substitution " + std::string(kSubstitutionNames[i]) + 176 "The substitution " + std::string(kSubstitutionNames[i]) +
143 " isn't valid for something\n" 177 " isn't valid for something\n"
144 "operating on a source file such as this."); 178 "operating on a source file such as this.");
145 return false; 179 return false;
146 } 180 }
147 } 181 }
148 return true; 182 return true;
149 } 183 }
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