Skip to content

Commit 0d9e2b3

Browse files
hvadehracopybara-github
authored andcommitted
Automated rollback of commit 3fe2a1c.
PiperOrigin-RevId: 792651764 Change-Id: I172c5bd194508df3c58c9a8f3666ff6cd4d0520f
1 parent 8fd848e commit 0d9e2b3

File tree

3 files changed

+91
-132
lines changed

3 files changed

+91
-132
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CcStarlarkInternal.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.devtools.build.lib.rules.cpp;
1616

1717
import static com.google.common.collect.ImmutableList.toImmutableList;
18-
import static com.google.devtools.build.lib.rules.cpp.CcModule.nullIfNone;
1918
import static com.google.devtools.build.lib.rules.cpp.CppHelper.asDict;
2019

2120
import com.google.common.base.Strings;
@@ -954,41 +953,73 @@ public Artifact createCompileActionTemplate(
954953
documented = false,
955954
parameters = {
956955
@Param(name = "action_construction_context", positional = false, named = true),
956+
@Param(name = "cc_compilation_context", positional = false, named = true),
957+
@Param(name = "cc_toolchain", positional = false, named = true),
957958
@Param(name = "configuration", positional = false, named = true),
959+
@Param(name = "conlyopts", positional = false, named = true, defaultValue = "[]"),
960+
@Param(name = "copts", positional = false, named = true, defaultValue = "[]"),
961+
@Param(name = "cpp_configuration", positional = false, named = true),
962+
@Param(name = "cxxopts", positional = false, named = true, defaultValue = "[]"),
963+
@Param(name = "fdo_context", positional = false, named = true, defaultValue = "None"),
964+
@Param(
965+
name = "auxiliary_fdo_inputs",
966+
positional = false,
967+
named = true,
968+
defaultValue = "None"),
958969
@Param(
959970
name = "feature_configuration",
960971
positional = false,
961972
named = true), // FeatureConfigurationForStarlark
962973
@Param(name = "use_pic", positional = false, named = true),
963974
@Param(name = "label", positional = false, named = true),
964975
@Param(name = "common_compile_build_variables", positional = false, named = true),
965-
@Param(name = "specific_compile_build_variables", positional = false, named = true),
976+
@Param(name = "fdo_build_variables", positional = false, named = true),
966977
@Param(name = "cpp_semantics", positional = false, named = true),
978+
@Param(name = "source_label", positional = false, named = true),
967979
@Param(name = "output_name_base", positional = false, named = true),
968980
@Param(name = "cpp_compile_action_builder", positional = false, named = true)
969981
})
970982
public Artifact createParseHeaderAction(
971983
StarlarkRuleContext starlarkRuleContext,
984+
CcCompilationContext ccCompilationContext,
985+
StarlarkInfo ccToolchain,
972986
BuildConfigurationValue configuration,
987+
Sequence<?> conlyopts,
988+
Sequence<?> copts,
989+
CppConfiguration cppConfiguration,
990+
Sequence<?> cxxopts,
991+
StructImpl fdoContext,
992+
Depset auxiliaryFdoInputs,
973993
FeatureConfigurationForStarlark featureConfigurationForStarlark,
974994
boolean generatePicAction,
975995
Label label,
976996
CcToolchainVariables commonCompileBuildVariables,
977-
CcToolchainVariables specificCompileBuildVariables,
997+
Dict<?, ?> fdoBuildVariables,
978998
CppSemantics semantics,
999+
Label sourceLabel,
9791000
String outputNameBase,
9801001
CppCompileActionBuilder builder)
9811002
throws RuleErrorException, EvalException {
9821003
return CcStaticCompilationHelper.createParseHeaderAction(
9831004
starlarkRuleContext.getRuleContext(),
1005+
ccCompilationContext,
1006+
CcToolchainProvider.create(ccToolchain),
9841007
configuration,
1008+
Sequence.cast(conlyopts, String.class, "conlyopts").getImmutableList(),
1009+
Sequence.cast(copts, String.class, "copts").getImmutableList(),
1010+
cppConfiguration,
1011+
Sequence.cast(cxxopts, String.class, "cxxopts").getImmutableList(),
1012+
new FdoContext(fdoContext),
1013+
Depset.cast(auxiliaryFdoInputs, Artifact.class, "auxiliary_fdo_inputs"),
9851014
featureConfigurationForStarlark.getFeatureConfiguration(),
9861015
generatePicAction,
9871016
label,
9881017
commonCompileBuildVariables,
989-
specificCompileBuildVariables,
1018+
ImmutableMap.copyOf(
1019+
Dict.cast(fdoBuildVariables, String.class, String.class, "fdo_build_variables")),
9901020
starlarkRuleContext.getRuleContext().getRuleErrorConsumer(),
9911021
semantics,
1022+
sourceLabel,
9921023
outputNameBase,
9931024
builder);
9941025
}
@@ -1112,9 +1143,6 @@ public CppCompileActionBuilder createCppCompileActionBuilder(
11121143
@Param(name = "source_artifact", positional = false, named = true),
11131144
@Param(name = "additional_compilation_inputs", positional = false, named = true),
11141145
@Param(name = "additional_include_scanning_roots", positional = false, named = true),
1115-
@Param(name = "output_file", positional = false, named = true, defaultValue = "None"),
1116-
@Param(name = "dotd_file", positional = false, named = true, defaultValue = "None"),
1117-
@Param(name = "diagnostics_file", positional = false, named = true, defaultValue = "None"),
11181146
})
11191147
public CppCompileActionBuilder createCppCompileActionBuilderWithInputs(
11201148
StarlarkRuleContext actionConstructionContext,
@@ -1126,10 +1154,7 @@ public CppCompileActionBuilder createCppCompileActionBuilderWithInputs(
11261154
CppSemantics semantics,
11271155
Artifact sourceArtifact,
11281156
Sequence<?> additionalCompilationInputs,
1129-
Sequence<?> additionalIncludeScanningRoots,
1130-
Object outputFile,
1131-
Object dotdFile,
1132-
Object diagnosticsFile)
1157+
Sequence<?> additionalIncludeScanningRoots)
11331158
throws EvalException {
11341159
CppCompileActionBuilder builder =
11351160
createCppCompileActionBuilder(
@@ -1150,10 +1175,6 @@ public CppCompileActionBuilder createCppCompileActionBuilderWithInputs(
11501175
additionalIncludeScanningRoots,
11511176
Artifact.class,
11521177
"additional_include_scanning_roots"));
1153-
builder.setOutputs(
1154-
nullIfNone(outputFile, Artifact.class),
1155-
nullIfNone(dotdFile, Artifact.class),
1156-
nullIfNone(diagnosticsFile, Artifact.class));
11571178
return builder;
11581179
}
11591180

src/main/java/com/google/devtools/build/lib/rules/cpp/CcStaticCompilationHelper.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,24 +527,59 @@ static void createModuleCodegenAction(
527527

528528
static Artifact createParseHeaderAction(
529529
ActionConstructionContext actionConstructionContext,
530+
CcCompilationContext ccCompilationContext,
531+
CcToolchainProvider ccToolchain,
530532
BuildConfigurationValue configuration,
533+
ImmutableList<String> conlyopts,
534+
ImmutableList<String> copts,
535+
CppConfiguration cppConfiguration,
536+
ImmutableList<String> cxxopts,
537+
FdoContext fdoContext,
538+
NestedSet<Artifact> auxiliaryFdoInputs,
531539
FeatureConfiguration featureConfiguration,
532540
boolean generatePicAction,
533541
Label label,
534542
CcToolchainVariables commonToolchainVariables,
535-
CcToolchainVariables specificToolchainVariables,
543+
ImmutableMap<String, String> fdoBuildVariables,
536544
RuleErrorConsumer ruleErrorConsumer,
537545
CppSemantics semantics,
546+
Label sourceLabel,
538547
String outputNameBase,
539548
CppCompileActionBuilder builder)
540549
throws RuleErrorException, EvalException {
541550
builder
551+
.setOutputs(
552+
actionConstructionContext,
553+
ruleErrorConsumer,
554+
label,
555+
ArtifactCategory.PROCESSED_HEADER,
556+
outputNameBase)
542557
// If we generate pic actions, we prefer the header actions to use the pic artifacts.
543558
.setPicMode(generatePicAction);
544559
builder.setVariables(
545-
CcToolchainVariables.builder(commonToolchainVariables)
546-
.addAllNonTransitive(specificToolchainVariables)
547-
.build());
560+
setupSpecificCompileBuildVariables(
561+
commonToolchainVariables,
562+
ccCompilationContext,
563+
conlyopts,
564+
copts,
565+
cppConfiguration,
566+
cxxopts,
567+
fdoContext,
568+
auxiliaryFdoInputs,
569+
featureConfiguration,
570+
semantics,
571+
builder,
572+
sourceLabel,
573+
generatePicAction,
574+
/* needsFdoBuildVariables= */ false,
575+
fdoBuildVariables,
576+
ccCompilationContext.getCppModuleMap(),
577+
/* enableCoverage= */ false,
578+
/* gcnoFile= */ null,
579+
/* isUsingFission= */ false,
580+
/* dwoFile= */ null,
581+
/* ltoIndexingFile= */ null,
582+
/* additionalBuildVariables= */ ImmutableMap.of()));
548583
semantics.finalizeCompileActionBuilder(configuration, featureConfiguration, builder);
549584
CppCompileAction compileAction = builder.buildOrThrowRuleError(ruleErrorConsumer);
550585
actionConstructionContext.registerAction(compileAction);

src/main/starlark/builtins_bzl/common/cc/compile/compile.bzl

Lines changed: 16 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ load(
2424
"should_create_per_object_debug_info",
2525
)
2626
load(":common/cc/compile/cc_compilation_helper.bzl", "cc_compilation_helper")
27-
load(":common/cc/compile/compile_build_variables.bzl", "get_specific_compile_build_variables")
28-
load(":common/cc/semantics.bzl", _starlark_cc_semantics = "semantics")
2927
load(":common/paths.bzl", "paths")
3028

3129
cc_common_internal = _builtins.internal.cc_common
@@ -728,38 +726,8 @@ def _create_cc_compile_actions(
728726
_basename_without_extension(source_artifact) in compiled_basenames):
729727
continue
730728

731-
output_name_base = cc_internal.get_artifact_name_for_category(
732-
cc_toolchain = cc_toolchain,
733-
category = artifact_category.GENERATED_HEADER,
734-
output_name = output_name_map[source_artifact],
735-
)
736-
output_file = _get_compile_output_file(
737-
action_construction_context,
738-
label,
739-
output_name = cc_internal.get_artifact_name_for_category(
740-
cc_toolchain = cc_toolchain,
741-
category = artifact_category.PROCESSED_HEADER,
742-
output_name = output_name_base,
743-
),
744-
)
745-
dotd_file = _get_compile_output_file(
746-
action_construction_context,
747-
label,
748-
output_name = cc_internal.get_artifact_name_for_category(
749-
cc_toolchain = cc_toolchain,
750-
category = artifact_category.INCLUDED_FILE_LIST,
751-
output_name = output_name_base,
752-
),
753-
) if _dotd_files_enabled(language, cpp_configuration, feature_configuration) else None
754-
diagnostics_file = _get_compile_output_file(
755-
action_construction_context,
756-
label,
757-
output_name = cc_internal.get_artifact_name_for_category(
758-
cc_toolchain = cc_toolchain,
759-
category = artifact_category.SERIALIZED_DIAGNOSTICS_FILE,
760-
output_name = output_name_base,
761-
),
762-
) if _serialized_diagnostics_file_enabled(feature_configuration) else None
729+
output_name = output_name_map[source_artifact]
730+
763731
cpp_compile_action_builder = cc_internal.create_cpp_compile_action_builder_with_inputs(
764732
action_construction_context = action_construction_context,
765733
cc_compilation_context = cc_compilation_context,
@@ -771,38 +739,30 @@ def _create_cc_compile_actions(
771739
source_artifact = source_artifact,
772740
additional_compilation_inputs = additional_compilation_inputs,
773741
additional_include_scanning_roots = additional_include_scanning_roots,
774-
output_file = output_file,
775-
dotd_file = dotd_file,
776-
diagnostics_file = diagnostics_file,
777742
)
778-
specific_compile_build_variables = get_specific_compile_build_variables(
779-
feature_configuration,
780-
use_pic = generate_pic_action,
781-
source_file = source_artifact,
782-
output_file = output_file,
783-
dotd_file = dotd_file,
784-
diagnostics_file = diagnostics_file,
785-
cpp_module_map = cc_compilation_context.module_map(),
786-
direct_module_maps = cc_compilation_context.direct_module_maps,
787-
user_compile_flags = _get_copts(
788-
language = language,
789-
cpp_configuration = cpp_configuration,
790-
source_file = source_artifact,
791-
conlyopts = conlyopts,
792-
copts = copts,
793-
cxxopts = cxxopts,
794-
label = cpp_source.label,
795-
),
743+
output_name_base = cc_internal.get_artifact_name_for_category(
744+
cc_toolchain = cc_toolchain,
745+
category = artifact_category.GENERATED_HEADER,
746+
output_name = output_name,
796747
)
797748
header_token_file = cc_internal.create_parse_header_action(
798749
action_construction_context = action_construction_context,
750+
cc_compilation_context = cc_compilation_context,
751+
cc_toolchain = cc_toolchain,
799752
configuration = configuration,
753+
conlyopts = conlyopts,
754+
copts = copts,
755+
cpp_configuration = cpp_configuration,
756+
cxxopts = cxxopts,
757+
fdo_context = fdo_context,
758+
auxiliary_fdo_inputs = auxiliary_fdo_inputs,
800759
feature_configuration = feature_configuration,
801760
use_pic = generate_pic_action,
802761
label = label,
803762
common_compile_build_variables = common_compile_build_variables,
804-
specific_compile_build_variables = specific_compile_build_variables,
763+
fdo_build_variables = fdo_build_variables,
805764
cpp_semantics = cpp_semantics,
765+
source_label = cpp_source.label,
806766
output_name_base = output_name_base,
807767
cpp_compile_action_builder = cpp_compile_action_builder,
808768
)
@@ -861,63 +821,6 @@ def _create_module_action(
861821
bitcode_output = False,
862822
)
863823

864-
def _get_compile_output_file(ctx, label, *, output_name):
865-
return ctx.actions.declare_file(paths.join("_objs", label.name, output_name))
866-
867-
def _dotd_files_enabled(language, cpp_configuration, feature_configuration):
868-
enabled_in_config = (
869-
_starlark_cc_semantics.dotd_files_enabled(cpp_configuration) if language == "cpp" else cpp_configuration.objc_should_generate_dotd_files()
870-
)
871-
return (
872-
enabled_in_config and
873-
not feature_configuration.is_enabled("parse_showincludes") and
874-
not feature_configuration.is_enabled("no_dotd_file")
875-
)
876-
877-
def _serialized_diagnostics_file_enabled(feature_configuration):
878-
return feature_configuration.is_enabled("serialized_diagnostics_file")
879-
880-
_SOURCE_TYPES_FOR_CXXOPTS = set(
881-
extensions.CC_SOURCE +
882-
extensions.CC_HEADER +
883-
[".cppmap"] + # cpp module map
884-
[".pcm", ".gcm", ".ifc"] + # clif input proto
885-
[".mm"], # objc source
886-
)
887-
888-
def _get_copts(
889-
language,
890-
cpp_configuration,
891-
source_file,
892-
conlyopts,
893-
copts,
894-
cxxopts,
895-
label):
896-
extension = "." + source_file.extension if source_file.extension else ""
897-
result = []
898-
result.extend(_copts_from_options(language, cpp_configuration, extension))
899-
result.extend(copts)
900-
if extension in extensions.C_SOURCE:
901-
result.extend(conlyopts)
902-
if extension in _SOURCE_TYPES_FOR_CXXOPTS:
903-
result.extend(cxxopts)
904-
if label:
905-
result.extend(cc_internal.per_file_copts(cpp_configuration, source_file, label))
906-
return result
907-
908-
def _copts_from_options(language, cpp_configuration, extension):
909-
result = []
910-
result.extend(cpp_configuration.copts)
911-
if extension in extensions.C_SOURCE:
912-
result.extend(cpp_configuration.conlyopts)
913-
if extension in _SOURCE_TYPES_FOR_CXXOPTS:
914-
result.extend(cpp_configuration.cxxopts)
915-
if extension in [".m", ".mm"] or (
916-
language == "objc" and extension in extensions.CC_HEADER
917-
):
918-
result.extend(cpp_configuration.objccopts)
919-
return result
920-
921824
def _calculate_output_name_map_by_type(sources, prefix_dir):
922825
return (
923826
_calculate_output_name_map(

0 commit comments

Comments
 (0)