Skip to content

Commit

Permalink
Expose language in C++ compile API
Browse files Browse the repository at this point in the history
This is currently guarded by a flag. It is meant to be used only by native
rules while re-writing them to Starlark, there are no plans to make any of this
methods public.

RELNOTES:none
PiperOrigin-RevId: 354305518
  • Loading branch information
oquenchil authored and copybara-github committed Jan 28, 2021
1 parent e1c146d commit a2b7e40
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Tuple compile(
Object codeCoverageEnabled,
Object hdrsCheckingMode,
Object variablesExtension,
Object language,
StarlarkThread thread)
throws EvalException, InterruptedException {
return compile(
Expand Down Expand Up @@ -141,6 +142,7 @@ public Tuple compile(
codeCoverageEnabled,
hdrsCheckingMode,
variablesExtension,
language,
thread);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.CompilationInfo;
import com.google.devtools.build.lib.rules.cpp.CcCompilationHelper.SourceCategory;
import com.google.devtools.build.lib.rules.cpp.CcLinkingContext.LinkOptions;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ActionConfig;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ArtifactNamePattern;
Expand Down Expand Up @@ -1923,6 +1924,7 @@ protected Tuple compile(
Object codeCoverageEnabledObject,
Object hdrsCheckingModeObject,
Object variablesExtension,
Object languageObject,
StarlarkThread thread)
throws EvalException, InterruptedException {
if (checkObjectsBound(
Expand All @@ -1934,7 +1936,8 @@ protected Tuple compile(
doNotGenerateModuleMapObject,
codeCoverageEnabledObject,
hdrsCheckingModeObject,
variablesExtension)) {
variablesExtension,
languageObject)) {
CcModule.checkPrivateStarlarkificationAllowlist(thread);
}

Expand Down Expand Up @@ -1999,6 +2002,17 @@ protected Tuple compile(
throw Starlark.errorf("Either PIC or no PIC actions have to be created.");
}

String language = convertFromNoneable(languageObject, Language.CPP.getRepresentation());
validateLanguage(language);
SourceCategory sourceCategory;
if (language.equals(Language.CPP.getRepresentation())) {
sourceCategory = SourceCategory.CC;
} else if (language.equals(Language.OBJC.getRepresentation())
|| language.equals(Language.OBJCPP.getRepresentation())) {
sourceCategory = SourceCategory.CC_AND_OBJC;
} else {
throw Starlark.errorf("Language '%s' is not supported", language);
}
CcCommon common = new CcCommon(actions.getRuleContext(), ccToolchainProvider);
CcCompilationHelper helper =
new CcCompilationHelper(
Expand All @@ -2008,8 +2022,10 @@ protected Tuple compile(
grepIncludes,
getSemantics(),
featureConfiguration.getFeatureConfiguration(),
sourceCategory,
ccToolchainProvider,
fdoContext,
actions.getActionConstructionContext().getConfiguration(),
TargetUtils.getExecutionInfo(
actions.getRuleContext().getRule(),
actions.getRuleContext().isAllowTagsPropagation()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ public interface BazelCcModuleApi<
documented = false,
allowedTypes = {@ParamType(type = Dict.class)},
defaultValue = "unbound"),
@Param(
name = "language",
positional = false,
named = true,
documented = false,
allowedTypes = {@ParamType(type = String.class)},
defaultValue = "unbound"),
})
Tuple compile(
StarlarkActionFactoryT starlarkActionFactoryApi,
Expand Down Expand Up @@ -327,6 +334,7 @@ Tuple compile(
Object codeCoverageEnabled,
Object hdrsCheckingMode,
Object variablesExtension,
Object language,
StarlarkThread thread)
throws EvalException, InterruptedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public Tuple compile(
Object codeCoverageEnabled,
Object hdrsCheckingMode,
Object variablesExtension,
Object language,
StarlarkThread thread)
throws EvalException, InterruptedException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6834,7 +6834,8 @@ public void testExpandedCompileApiBlocked() throws Exception {
compileCall + "propagate_module_map_to_compile_action = True)",
compileCall + "do_not_generate_module_map = True)",
compileCall + "code_coverage_enabled = True)",
compileCall + "hdrs_checking_mode = 'strict')");
compileCall + "hdrs_checking_mode = 'strict')",
compileCall + "language = 'c++')");
scratch.overwriteFile(
"a/BUILD",
"load(':rule.bzl', 'crule')",
Expand Down

0 comments on commit a2b7e40

Please sign in to comment.