43
43
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .EnvEntry ;
44
44
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .EnvSet ;
45
45
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .Feature ;
46
- import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .FeatureConfiguration ;
47
46
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .Flag ;
48
47
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .FlagGroup ;
49
48
import com .google .devtools .build .lib .rules .cpp .CcToolchainFeatures .FlagSet ;
83
82
public class CcModule
84
83
implements CcModuleApi <
85
84
CcToolchainProvider ,
86
- FeatureConfiguration ,
85
+ FeatureConfigurationForStarlark ,
87
86
CcCompilationContext ,
88
87
CcLinkingContext ,
89
88
LibraryToLink ,
@@ -132,7 +131,7 @@ public Provider getCcToolchainProvider() {
132
131
}
133
132
134
133
@ Override
135
- public FeatureConfiguration configureFeatures (
134
+ public FeatureConfigurationForStarlark configureFeatures (
136
135
Object ruleContextOrNone ,
137
136
CcToolchainProvider toolchain ,
138
137
SkylarkList <String > requestedFeatures ,
@@ -150,51 +149,62 @@ public FeatureConfiguration configureFeatures(
150
149
+ "Please add 'ctx' as a named parameter. See "
151
150
+ "https://github.com/bazelbuild/bazel/issues/7793 for details." );
152
151
}
153
- return CcCommon .configureFeaturesOrThrowEvalException (
154
- ImmutableSet .copyOf (requestedFeatures ),
155
- ImmutableSet .copyOf (unsupportedFeatures ),
156
- toolchain ,
152
+ CppConfiguration cppConfiguration =
157
153
ruleContext == null
158
154
? toolchain .getCppConfigurationEvenThoughItCanBeDifferentThatWhatTargetHas ()
159
- : ruleContext .getRuleContext ().getFragment (CppConfiguration .class ));
155
+ : ruleContext .getRuleContext ().getFragment (CppConfiguration .class );
156
+ return FeatureConfigurationForStarlark .from (
157
+ CcCommon .configureFeaturesOrThrowEvalException (
158
+ ImmutableSet .copyOf (requestedFeatures ),
159
+ ImmutableSet .copyOf (unsupportedFeatures ),
160
+ toolchain ,
161
+ cppConfiguration ),
162
+ cppConfiguration );
160
163
}
161
164
162
165
@ Override
163
- public String getToolForAction (FeatureConfiguration featureConfiguration , String actionName ) {
164
- return featureConfiguration .getToolPathForAction (actionName );
166
+ public String getToolForAction (
167
+ FeatureConfigurationForStarlark featureConfiguration , String actionName ) {
168
+ return featureConfiguration .getFeatureConfiguration ().getToolPathForAction (actionName );
165
169
}
166
170
167
171
@ Override
168
- public boolean isEnabled (FeatureConfiguration featureConfiguration , String featureName ) {
169
- return featureConfiguration .isEnabled (featureName );
172
+ public boolean isEnabled (
173
+ FeatureConfigurationForStarlark featureConfiguration , String featureName ) {
174
+ return featureConfiguration .getFeatureConfiguration ().isEnabled (featureName );
170
175
}
171
176
172
177
@ Override
173
- public boolean actionIsEnabled (FeatureConfiguration featureConfiguration , String actionName ) {
174
- return featureConfiguration .actionIsConfigured (actionName );
178
+ public boolean actionIsEnabled (
179
+ FeatureConfigurationForStarlark featureConfiguration , String actionName ) {
180
+ return featureConfiguration .getFeatureConfiguration ().actionIsConfigured (actionName );
175
181
}
176
182
177
183
@ Override
178
184
public SkylarkList <String > getCommandLine (
179
- FeatureConfiguration featureConfiguration ,
185
+ FeatureConfigurationForStarlark featureConfiguration ,
180
186
String actionName ,
181
187
CcToolchainVariables variables ) {
182
- return SkylarkList .createImmutable (featureConfiguration .getCommandLine (actionName , variables ));
188
+ return SkylarkList .createImmutable (
189
+ featureConfiguration .getFeatureConfiguration ().getCommandLine (actionName , variables ));
183
190
}
184
191
185
192
@ Override
186
193
public SkylarkDict <String , String > getEnvironmentVariable (
187
- FeatureConfiguration featureConfiguration ,
194
+ FeatureConfigurationForStarlark featureConfiguration ,
188
195
String actionName ,
189
196
CcToolchainVariables variables ) {
190
197
return SkylarkDict .copyOf (
191
- null , featureConfiguration .getEnvironmentVariables (actionName , variables ));
198
+ null ,
199
+ featureConfiguration
200
+ .getFeatureConfiguration ()
201
+ .getEnvironmentVariables (actionName , variables ));
192
202
}
193
203
194
204
@ Override
195
205
public CcToolchainVariables getCompileBuildVariables (
196
206
CcToolchainProvider ccToolchainProvider ,
197
- FeatureConfiguration featureConfiguration ,
207
+ FeatureConfigurationForStarlark featureConfiguration ,
198
208
Object sourceFile ,
199
209
Object outputFile ,
200
210
Object userCompileFlags ,
@@ -206,7 +216,7 @@ public CcToolchainVariables getCompileBuildVariables(
206
216
boolean addLegacyCxxOptions )
207
217
throws EvalException {
208
218
return CompileBuildVariables .setupVariablesOrThrowEvalException (
209
- featureConfiguration ,
219
+ featureConfiguration . getFeatureConfiguration () ,
210
220
ccToolchainProvider ,
211
221
convertFromNoneable (sourceFile , /* defaultValue= */ null ),
212
222
convertFromNoneable (outputFile , /* defaultValue= */ null ),
@@ -234,7 +244,7 @@ public CcToolchainVariables getCompileBuildVariables(
234
244
@ Override
235
245
public CcToolchainVariables getLinkBuildVariables (
236
246
CcToolchainProvider ccToolchainProvider ,
237
- FeatureConfiguration featureConfiguration ,
247
+ FeatureConfigurationForStarlark featureConfiguration ,
238
248
Object librarySearchDirectories ,
239
249
Object runtimeLibrarySearchDirectories ,
240
250
Object userLinkFlags ,
@@ -257,9 +267,9 @@ public CcToolchainVariables getLinkBuildVariables(
257
267
/* thinltoMergedObjectFile= */ null ,
258
268
mustKeepDebug ,
259
269
ccToolchainProvider ,
260
- // TODO(b/117917928): We cannot use cpp configuration from cc toolchain. Fix.
261
- ccToolchainProvider . getCppConfiguration (),
262
- featureConfiguration ,
270
+ featureConfiguration
271
+ . getCppConfigurationFromFeatureConfigurationCreatedForStarlark_andIKnowWhatImDoing (),
272
+ featureConfiguration . getFeatureConfiguration () ,
263
273
useTestOnlyFlags ,
264
274
/* isLtoIndexing= */ false ,
265
275
userFlagsToIterable (userLinkFlags ),
@@ -354,8 +364,8 @@ public LibraryToLink createLibraryLinkerInput(
354
364
throws EvalException , InterruptedException {
355
365
SkylarkActionFactory skylarkActionFactory =
356
366
nullIfNone (actionsObject , SkylarkActionFactory .class );
357
- FeatureConfiguration featureConfiguration =
358
- nullIfNone (featureConfigurationObject , FeatureConfiguration .class );
367
+ FeatureConfigurationForStarlark featureConfiguration =
368
+ nullIfNone (featureConfigurationObject , FeatureConfigurationForStarlark .class );
359
369
CcToolchainProvider ccToolchainProvider =
360
370
nullIfNone (ccToolchainProviderObject , CcToolchainProvider .class );
361
371
Artifact staticLibrary = nullIfNone (staticLibraryObject , Artifact .class );
@@ -425,7 +435,7 @@ public LibraryToLink createLibraryLinkerInput(
425
435
426
436
Artifact resolvedSymlinkDynamicLibrary = null ;
427
437
Artifact resolvedSymlinkInterfaceLibrary = null ;
428
- if (!featureConfiguration .isEnabled (CppRuleClasses .TARGETS_WINDOWS )) {
438
+ if (!featureConfiguration .getFeatureConfiguration (). isEnabled (CppRuleClasses .TARGETS_WINDOWS )) {
429
439
if (dynamicLibrary != null ) {
430
440
resolvedSymlinkDynamicLibrary = dynamicLibrary ;
431
441
dynamicLibrary =
@@ -598,7 +608,7 @@ protected static CompilationInfo compile(
598
608
RuleContext ruleContext = skylarkRuleContext .getRuleContext ();
599
609
SkylarkActionFactory actions = skylarkRuleContext .actions ();
600
610
CcToolchainProvider ccToolchainProvider = convertFromNoneable (skylarkCcToolchainProvider , null );
601
- FeatureConfiguration featureConfiguration =
611
+ FeatureConfigurationForStarlark featureConfiguration =
602
612
convertFromNoneable (skylarkFeatureConfiguration , null );
603
613
Pair <List <Artifact >, List <Artifact >> separatedHeadersAndSources =
604
614
separateSourcesFromHeaders (sources );
@@ -616,7 +626,7 @@ protected static CompilationInfo compile(
616
626
? ruleContext .getPrerequisiteArtifact ("$grep_includes" , Mode .HOST )
617
627
: null ,
618
628
cppSemantics ,
619
- featureConfiguration ,
629
+ featureConfiguration . getFeatureConfiguration () ,
620
630
ccToolchainProvider ,
621
631
fdoContext )
622
632
.addPublicHeaders (headers )
@@ -685,7 +695,7 @@ protected static LinkingInfo link(
685
695
CcCommon .checkRuleWhitelisted (skylarkRuleContext );
686
696
RuleContext ruleContext = skylarkRuleContext .getRuleContext ();
687
697
CcToolchainProvider ccToolchainProvider = convertFromNoneable (skylarkCcToolchainProvider , null );
688
- FeatureConfiguration featureConfiguration =
698
+ FeatureConfigurationForStarlark featureConfiguration =
689
699
convertFromNoneable (skylarkFeatureConfiguration , null );
690
700
FdoContext fdoContext = ccToolchainProvider .getFdoContext ();
691
701
NestedSet <String > linkopts =
@@ -694,7 +704,7 @@ protected static LinkingInfo link(
694
704
new CcLinkingHelper (
695
705
ruleContext ,
696
706
cppSemantics ,
697
- featureConfiguration ,
707
+ featureConfiguration . getFeatureConfiguration () ,
698
708
ccToolchainProvider ,
699
709
fdoContext ,
700
710
ruleContext .getConfiguration ())
0 commit comments