Skip to content

Commit

Permalink
C++: Remove whitelisting of Starlark API for Bazel
Browse files Browse the repository at this point in the history
#4570

RELNOTES:C++ Starlark API for compilation and linking is no longer whitelisted
PiperOrigin-RevId: 245964332
  • Loading branch information
oquenchil authored and copybara-github committed Apr 30, 2019
1 parent 17a2351 commit 0b80b9c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Tuple<Object> compile(
/* grepIncludes= */ null,
SkylarkList.createImmutable(ImmutableList.of()),
location,
environment);
/* environment= */ null);
}

@Override
Expand Down Expand Up @@ -136,7 +136,7 @@ public CcLinkingOutputs link(
additionalInputs,
/* grepIncludes= */ null,
location,
environment,
/* environment= */ null,
starlarkContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,12 @@ public SkylarkList<Artifact> getSkylarkObjectFiles(
}

@Override
public SkylarkList<Artifact> getSkylarkObjects(Location location, Environment environment)
throws EvalException {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
public SkylarkList<Artifact> getSkylarkObjects(Location location) throws EvalException {
return SkylarkList.createImmutable(getObjectFiles(/* usePic= */ false));
}

@Override
public SkylarkList<Artifact> getSkylarkPicObjects(Location location, Environment environment)
throws EvalException {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
public SkylarkList<Artifact> getSkylarkPicObjects(Location location) throws EvalException {
return SkylarkList.createImmutable(getObjectFiles(/* usePic= */ true));
}

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1348,13 +1348,8 @@ public Tuple<Object> createLinkingContextFromCompilationOutputs(
boolean disallowDynamicLibraries,
Object grepIncludes,
Location location,
Environment environment,
StarlarkContext starlarkContext)
throws InterruptedException, EvalException {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
validateLanguage(location, language);
SkylarkActionFactory actions = skylarkActionFactoryApi;
CcToolchainProvider ccToolchainProvider = convertFromNoneable(skylarkCcToolchainProvider, null);
Expand Down Expand Up @@ -1474,12 +1469,14 @@ protected Tuple<Object> compile(
Artifact grepIncludes,
SkylarkList<Artifact> headersForClifDoNotUseThisParam,
Location location,
Environment environment)
@Nullable Environment environment)
throws EvalException {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
if (environment != null) {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
}
SkylarkActionFactory actions = skylarkActionFactoryApi;
CcToolchainProvider ccToolchainProvider = convertFromNoneable(skylarkCcToolchainProvider, null);
FeatureConfigurationForStarlark featureConfiguration =
Expand Down Expand Up @@ -1564,13 +1561,15 @@ protected CcLinkingOutputs link(
SkylarkList<Artifact> additionalInputs,
Object grepIncludes,
Location location,
Environment environment,
@Nullable Environment environment,
StarlarkContext starlarkContext)
throws InterruptedException, EvalException {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
if (environment != null) {
CcCommon.checkLocationWhitelisted(
environment.getSemantics(),
location,
environment.getGlobals().getLabel().getPackageIdentifier().toString());
}
validateLanguage(location, language);
validateOutputType(location, outputType);
CcToolchainProvider ccToolchainProvider = convertFromNoneable(skylarkCcToolchainProvider, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface CcCompilationOutputsApi<FileT extends FileApi> {
/** @deprecated use {@link #getSkylarkObjects} or {@link #getSkylarkPicObjects}. */
@SkylarkCallable(
name = "object_files",
documented = false,
doc = "Do not use. Use eiher 'objects' or 'pic_objects'.",
useEnvironment = true,
useLocation = true,
parameters = {
Expand All @@ -45,21 +45,9 @@ public interface CcCompilationOutputsApi<FileT extends FileApi> {
SkylarkList<FileT> getSkylarkObjectFiles(
boolean usePic, Location location, Environment environment) throws EvalException;

@SkylarkCallable(
name = "objects",
documented = false,
useEnvironment = true,
useLocation = true,
structField = true)
SkylarkList<FileT> getSkylarkObjects(Location location, Environment environment)
throws EvalException;
@SkylarkCallable(name = "objects", documented = false, useLocation = true, structField = true)
SkylarkList<FileT> getSkylarkObjects(Location location) throws EvalException;

@SkylarkCallable(
name = "pic_objects",
documented = false,
useEnvironment = true,
useLocation = true,
structField = true)
SkylarkList<FileT> getSkylarkPicObjects(Location location, Environment environment)
throws EvalException;
@SkylarkCallable(name = "pic_objects", documented = false, useLocation = true, structField = true)
SkylarkList<FileT> getSkylarkPicObjects(Location location) throws EvalException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ CcToolchainConfigInfoT ccToolchainConfigInfoFromSkylark(
+ " order to be linked later by a top level rule that does transitive linking to"
+ " create an executable or dynamic library.",
useLocation = true,
useEnvironment = true,
useContext = true,
parameters = {
@Param(
Expand Down Expand Up @@ -974,7 +973,6 @@ Tuple<Object> createLinkingContextFromCompilationOutputs(
boolean disallowDynamicLibraries,
Object grepIncludes,
Location location,
Environment environment,
StarlarkContext bazelStarlarkContext)
throws InterruptedException, EvalException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ public Tuple<Object> createLinkingContextFromCompilationOutputs(
boolean disallowDynamicLibraries,
Object grepIncludes,
Location location,
Environment environment,
StarlarkContext starlarkContext)
throws InterruptedException, EvalException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4987,6 +4987,7 @@ public void testWrongSrcExtensionGivesError() throws Exception {

@Test
public void testFlagWhitelist() throws Exception {
if (!AnalysisMock.get().isThisBazel()) {
setSkylarkSemanticsOptions("--experimental_cc_skylark_api_enabled_packages=\"\"");
createFiles(scratch, "foo/bar");
reporter.removeHandler(failFastHandler);
Expand All @@ -4995,6 +4996,7 @@ public void testFlagWhitelist() throws Exception {
"You can try it out by passing "
+ "--experimental_cc_skylark_api_enabled_packages=<list of packages>. Beware that we "
+ "will be making breaking changes to this API without prior warning.");
}
}

private static void createFilesForTestingCompilation(
Expand Down

0 comments on commit 0b80b9c

Please sign in to comment.