1515package com .google .devtools .build .lib .rules .cpp ;
1616
1717import static com .google .common .base .StandardSystemProperty .LINE_SEPARATOR ;
18+ import static com .google .common .collect .ImmutableList .toImmutableList ;
19+ import static com .google .common .collect .ImmutableSet .toImmutableSet ;
1820
1921import com .google .common .annotations .VisibleForTesting ;
2022import com .google .common .base .Ascii ;
@@ -831,13 +833,43 @@ public CcCompilationContext createCcCompilationContext(
831833 Sequence <?> directPrivateHdrs ,
832834 Object purposeNoneable ,
833835 Object moduleMap ,
836+ Object actionFactoryForMiddlemanOwnerAndConfiguration ,
837+ Object labelForMiddlemanNameObject ,
838+ Object externalIncludes ,
839+ Object virtualToOriginalHeaders ,
840+ Sequence <?> dependentCcCompilationContexts ,
841+ Sequence <?> nonCodeInputs ,
842+ Sequence <?> looseHdrsDirsObject ,
843+ String headersCheckingMode ,
844+ Boolean propagateModuleMapToCompileAction ,
845+ Object picHeaderModule ,
846+ Object headerModule ,
847+ Sequence <?> separateModuleHeaders ,
848+ Object separateModule ,
849+ Object separatePicModule ,
850+ Object addPublicHeadersToModularHeaders ,
834851 StarlarkThread thread )
835852 throws EvalException {
836853 isCalledFromStarlarkCcCommon (thread );
854+
855+ Label label = convertFromNoneable (labelForMiddlemanNameObject , null );
837856 CcCompilationContext .Builder ccCompilationContext =
838857 CcCompilationContext .builder (
839- /* actionConstructionContext= */ null , /* configuration= */ null , /* label= */ null );
858+ /* actionConstructionContext= */ actionFactoryForMiddlemanOwnerAndConfiguration
859+ == Starlark .NONE
860+ ? null
861+ : ((StarlarkActionFactory ) actionFactoryForMiddlemanOwnerAndConfiguration )
862+ .getActionConstructionContext (),
863+ /* configuration= */ actionFactoryForMiddlemanOwnerAndConfiguration == Starlark .NONE
864+ ? null
865+ : ((StarlarkActionFactory ) actionFactoryForMiddlemanOwnerAndConfiguration )
866+ .getActionConstructionContext ()
867+ .getConfiguration (),
868+ /* label= */ label );
869+
870+ // Public parameters.
840871 ImmutableList <Artifact > headerList = toNestedSetOfArtifacts (headers , "headers" ).toList ();
872+ ccCompilationContext .addDeclaredIncludeSrcs (headerList );
841873 ImmutableList <Artifact > textualHdrsList =
842874 Sequence .cast (directTextualHdrs , Artifact .class , "direct_textual_headers" )
843875 .getImmutableList ();
@@ -846,39 +878,82 @@ public CcCompilationContext createCcCompilationContext(
846878 ImmutableList <Artifact > modularPrivateHdrsList =
847879 Sequence .cast (directPrivateHdrs , Artifact .class , "direct_private_headers" )
848880 .getImmutableList ();
849- ccCompilationContext .addDeclaredIncludeSrcs (headerList );
850- ccCompilationContext .addModularPublicHdrs (headerList );
881+
851882 ccCompilationContext .addSystemIncludeDirs (
852883 toNestedSetOfStrings (systemIncludes , "system_includes" ).toList ().stream ()
853884 .map (x -> PathFragment .create (x ))
854- .collect (ImmutableList . toImmutableList ()));
885+ .collect (toImmutableList ()));
855886 ccCompilationContext .addIncludeDirs (
856887 toNestedSetOfStrings (includes , "includes" ).toList ().stream ()
857888 .map (x -> PathFragment .create (x ))
858- .collect (ImmutableList . toImmutableList ()));
889+ .collect (toImmutableList ()));
859890 ccCompilationContext .addQuoteIncludeDirs (
860891 toNestedSetOfStrings (quoteIncludes , "quote_includes" ).toList ().stream ()
861892 .map (x -> PathFragment .create (x ))
862- .collect (ImmutableList . toImmutableList ()));
893+ .collect (toImmutableList ()));
863894 ccCompilationContext .addFrameworkIncludeDirs (
864895 toNestedSetOfStrings (frameworkIncludes , "framework_includes" ).toList ().stream ()
865896 .map (x -> PathFragment .create (x ))
866- .collect (ImmutableList . toImmutableList ()));
897+ .collect (toImmutableList ()));
867898 ccCompilationContext .addDefines (toNestedSetOfStrings (defines , "defines" ).toList ());
868899 ccCompilationContext .addNonTransitiveDefines (
869900 toNestedSetOfStrings (localDefines , "local_defines" ).toList ());
870901 ccCompilationContext .addTextualHdrs (textualHdrsList );
871902 ccCompilationContext .addModularPublicHdrs (modularPublicHdrsList );
872903 ccCompilationContext .addModularPrivateHdrs (modularPrivateHdrsList );
904+
905+ // Private parameters.
873906 if (purposeNoneable != null
874907 && purposeNoneable != Starlark .UNBOUND
875908 && purposeNoneable != Starlark .NONE ) {
876909 ccCompilationContext .setPurpose ((String ) purposeNoneable );
877910 }
911+
878912 if (moduleMap != null && moduleMap != Starlark .UNBOUND && moduleMap != Starlark .NONE ) {
879913 ccCompilationContext .setCppModuleMap ((CppModuleMap ) moduleMap );
880914 }
881915
916+ ccCompilationContext .addExternalIncludeDirs (
917+ toNestedSetOfStrings (externalIncludes , "external_includes" ).toList ().stream ()
918+ .map (PathFragment ::create )
919+ .collect (toImmutableList ()));
920+
921+ ccCompilationContext .addVirtualToOriginalHeaders (
922+ Depset .cast (virtualToOriginalHeaders , Tuple .class , "virtual_to_original_headers" ));
923+
924+ ccCompilationContext .addDependentCcCompilationContexts (
925+ Sequence .cast (
926+ dependentCcCompilationContexts ,
927+ CcCompilationContext .class ,
928+ "dependent_cc_compilation_contexts" )
929+ .getImmutableList ());
930+
931+ ccCompilationContext .addNonCodeInputs (
932+ Sequence .cast (nonCodeInputs , Artifact .class , "non_code_inputs" ).getImmutableList ());
933+
934+ ImmutableList <PathFragment > looseHdrsDirs =
935+ Sequence .cast (looseHdrsDirsObject , String .class , "loose_hdrs_dirs" ).stream ()
936+ .map (PathFragment ::create )
937+ .collect (toImmutableList ());
938+ for (PathFragment looseHdrDir : looseHdrsDirs ) {
939+ ccCompilationContext .addLooseHdrsDir (looseHdrDir );
940+ }
941+
942+ ccCompilationContext .setHeadersCheckingMode (HeadersCheckingMode .getValue (headersCheckingMode ));
943+ ccCompilationContext .setPropagateCppModuleMapAsActionInput (propagateModuleMapToCompileAction );
944+ ccCompilationContext .setPicHeaderModule (
945+ picHeaderModule == Starlark .NONE ? null : (Artifact .DerivedArtifact ) picHeaderModule );
946+ ccCompilationContext .setHeaderModule (
947+ headerModule == Starlark .NONE ? null : (Artifact .DerivedArtifact ) headerModule );
948+ ccCompilationContext .setSeparateModuleHdrs (
949+ Sequence .cast (separateModuleHeaders , Artifact .class , "separate_module_headers" ),
950+ convertFromNoneable (separateModule , null ),
951+ convertFromNoneable (separatePicModule , null ));
952+
953+ if ((Boolean ) addPublicHeadersToModularHeaders ) {
954+ ccCompilationContext .addModularPublicHdrs (headerList );
955+ }
956+
882957 return ccCompilationContext .build ();
883958 }
884959
@@ -1212,9 +1287,7 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromStarlark(
12121287 ImmutableList <Feature > featureList = featureBuilder .build ();
12131288
12141289 ImmutableSet <String > featureNames =
1215- featureList .stream ()
1216- .map (feature -> feature .getName ())
1217- .collect (ImmutableSet .toImmutableSet ());
1290+ featureList .stream ().map (Feature ::getName ).collect (toImmutableSet ());
12181291
12191292 ImmutableList .Builder <ActionConfig > actionConfigBuilder = ImmutableList .builder ();
12201293 for (Object actionConfig : actionConfigs ) {
@@ -1226,7 +1299,7 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromStarlark(
12261299 ImmutableSet <String > actionConfigNames =
12271300 actionConfigList .stream ()
12281301 .map (actionConfig -> actionConfig .getActionName ())
1229- .collect (ImmutableSet . toImmutableSet ());
1302+ .collect (toImmutableSet ());
12301303
12311304 CcToolchainFeatures .ArtifactNamePatternMapper .Builder artifactNamePatternBuilder =
12321305 new CcToolchainFeatures .ArtifactNamePatternMapper .Builder ();
@@ -1315,7 +1388,7 @@ public CcToolchainConfigInfo ccToolchainConfigInfoFromStarlark(
13151388 featureList .stream ()
13161389 .filter (feature -> !feature .getName ().equals (CppRuleClasses .LEGACY_COMPILE_FLAGS ))
13171390 .filter (feature -> !feature .getName ().equals (CppRuleClasses .DEFAULT_COMPILE_FLAGS ))
1318- .collect (ImmutableList . toImmutableList ()));
1391+ .collect (toImmutableList ()));
13191392 for (CToolchain .Feature feature :
13201393 CppActionConfigs .getFeaturesToAppearLastInFeaturesList (featureNames )) {
13211394 legacyFeaturesBuilder .add (new Feature (feature ));
@@ -2068,7 +2141,7 @@ public void checkPrivateApi(Object allowlistObject, StarlarkThread thread) throw
20682141 // TODO(bazel-team): This probably doesn't work with bzlmod since there's no repo
20692142 // mapping applied.
20702143 .map (p -> PackageIdentifier .createUnchecked ((String ) p .get (0 ), (String ) p .get (1 )))
2071- .collect (ImmutableList . toImmutableList ());
2144+ .collect (toImmutableList ());
20722145 BuiltinRestriction .failIfLabelOutsideAllowlist (label , allowlist );
20732146 }
20742147
@@ -2583,20 +2656,19 @@ public Tuple compile(
25832656 Sequence .cast (
25842657 ccCompilationContexts , CcCompilationContext .class , "compilation_contexts" ))
25852658 .addImplementationDepsCcCompilationContexts (implementationContexts )
2586- .addIncludeDirs (
2587- includes .stream ().map (PathFragment ::create ).collect (ImmutableList .toImmutableList ()))
2659+ .addIncludeDirs (includes .stream ().map (PathFragment ::create ).collect (toImmutableList ()))
25882660 .addQuoteIncludeDirs (
25892661 Sequence .cast (quoteIncludes , String .class , "quote_includes" ).stream ()
25902662 .map (PathFragment ::create )
2591- .collect (ImmutableList . toImmutableList ()))
2663+ .collect (toImmutableList ()))
25922664 .addSystemIncludeDirs (
25932665 Sequence .cast (systemIncludes , String .class , "system_includes" ).stream ()
25942666 .map (PathFragment ::create )
2595- .collect (ImmutableList . toImmutableList ()))
2667+ .collect (toImmutableList ()))
25962668 .addFrameworkIncludeDirs (
25972669 Sequence .cast (frameworkIncludes , String .class , "framework_includes" ).stream ()
25982670 .map (PathFragment ::create )
2599- .collect (ImmutableList . toImmutableList ()))
2671+ .collect (toImmutableList ()))
26002672 .addDefines (Sequence .cast (defines , String .class , "defines" ))
26012673 .addNonTransitiveDefines (Sequence .cast (localDefines , String .class , "local_defines" ))
26022674 .setCopts (
@@ -2608,15 +2680,13 @@ public Tuple compile(
26082680 .addAdditionalIncludeScanningRoots (includeScanningRoots )
26092681 .setPurpose (common .getPurpose (getSemantics (language )))
26102682 .addAdditionalExportedHeaders (
2611- additionalExportedHeaders .stream ()
2612- .map (PathFragment ::create )
2613- .collect (ImmutableList .toImmutableList ()))
2683+ additionalExportedHeaders .stream ().map (PathFragment ::create ).collect (toImmutableList ()))
26142684 .setPropagateModuleMapToCompileAction (propagateModuleMapToCompileAction )
26152685 .setCodeCoverageEnabled (codeCoverageEnabled )
26162686 .setHeadersCheckingMode (HeadersCheckingMode .getValue (hdrsCheckingMode ));
26172687
26182688 ImmutableList <PathFragment > looseIncludeDirs =
2619- looseIncludes .stream ().map (PathFragment ::create ).collect (ImmutableList . toImmutableList ());
2689+ looseIncludes .stream ().map (PathFragment ::create ).collect (toImmutableList ());
26202690 if (!looseIncludeDirs .isEmpty ()) {
26212691 helper .setLooseIncludeDirs (ImmutableSet .copyOf (looseIncludeDirs ));
26222692 }
@@ -3022,6 +3092,6 @@ private ImmutableList<Pair<Artifact, Label>> convertSequenceTupleToPair(Sequence
30223092 throws EvalException {
30233093 return Sequence .cast (sequenceTuple , Tuple .class , "files" ).stream ()
30243094 .map (p -> Pair .of ((Artifact ) p .get (0 ), (Label ) p .get (1 )))
3025- .collect (ImmutableList . toImmutableList ());
3095+ .collect (toImmutableList ());
30263096 }
30273097}
0 commit comments