Skip to content

Commit

Permalink
Introduce --incompatible_disallow_native_in_build_file to forbid nati…
Browse files Browse the repository at this point in the history
…ve module in BUILD files

#7513

RELNOTES:
  Using the `native` module in BUILD files is deprecated. It will be forbidden with --incompatible_disallow_native_in_build_file.
PiperOrigin-RevId: 235207912
  • Loading branch information
laurentlb authored and copybara-github committed Feb 22, 2019
1 parent 12a11cb commit 64e833c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,10 @@ private void buildPkgEnv(Environment pkgEnv, PackageContext context) {
"error getting package_name or repository_name functions from the native module",
exception);
}
if (!pkgEnv.getSemantics().incompatibleDisallowNativeInBuildFile()) {
pkgEnv.setup("native", nativeModule);
}
pkgEnv
.setup("native", nativeModule)
.setup("distribs", newDistribsFunction.apply(context))
.setup("glob", newGlobFunction.apply(context))
.setup("licenses", newLicensesFunction.apply(context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl
help = "If set to true, the label argument to 'load' cannot cross a package boundary.")
public boolean incompatibleDisallowLoadLabelsToCrossPackageBoundaries;

@Option(
name = "incompatible_disallow_native_in_build_file",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If set to true, the native module is not accessible in BUILD files. "
+ "Use for example `cc_library` instead of `native.cc_library`.")
public boolean incompatibleDisallowNativeInBuildFile;

@Option(
name = "incompatible_disallow_struct_provider_syntax",
defaultValue = "false",
Expand Down Expand Up @@ -532,6 +546,7 @@ public StarlarkSemantics toSkylarkSemantics() {
.incompatibleDisallowLegacyJavaProvider(incompatibleDisallowLegacyJavaProvider)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(
incompatibleDisallowLoadLabelsToCrossPackageBoundaries)
.incompatibleDisallowNativeInBuildFile(incompatibleDisallowNativeInBuildFile)
.incompatibleDisallowOldStyleArgsAdd(incompatibleDisallowOldStyleArgsAdd)
.incompatibleDisallowStructProviderSyntax(incompatibleDisallowStructProviderSyntax)
.incompatibleExpandDirectories(incompatibleExpandDirectories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public boolean flagValue(FlagIdentifier flagIdentifier) {

public abstract boolean incompatibleDisallowLoadLabelsToCrossPackageBoundaries();

public abstract boolean incompatibleDisallowNativeInBuildFile();

public abstract boolean incompatibleDisallowOldStyleArgsAdd();

public abstract boolean incompatibleDisallowStructProviderSyntax();
Expand Down Expand Up @@ -221,6 +223,7 @@ public static Builder builderWithDefaults() {
.incompatibleDisallowLegacyJavaProvider(false)
.incompatibleDisallowLegacyJavaInfo(false)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(false)
.incompatibleDisallowNativeInBuildFile(false)
.incompatibleDisallowOldStyleArgsAdd(true)
.incompatibleDisallowStructProviderSyntax(false)
.incompatibleExpandDirectories(true)
Expand Down Expand Up @@ -286,6 +289,8 @@ public abstract static class Builder {

public abstract Builder incompatibleDisallowOldStyleArgsAdd(boolean value);

public abstract Builder incompatibleDisallowNativeInBuildFile(boolean value);

public abstract Builder incompatibleDisallowStructProviderSyntax(boolean value);

public abstract Builder incompatibleExpandDirectories(boolean value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,29 @@ public void testGlobWithIOErrors() throws Exception {
events.assertContainsError("Directory is not readable");
}

@Test
public void testNativeModuleIsAvailable() throws Exception {
Path buildFile = scratch.file("/pkg/BUILD", "native.cc_library(name='bar')");
Package pkg =
packages.createPackage(
"pkg",
RootedPath.toRootedPath(root, buildFile),
"--incompatible_disallow_native_in_build_file=false");
assertThat(pkg.containsErrors()).isFalse();
}

@Test
public void testNativeModuleIsDisabled() throws Exception {
events.setFailFast(false);
Path buildFile = scratch.file("/pkg/BUILD", "native.cc_library(name='bar')");
Package pkg =
packages.createPackage(
"pkg",
RootedPath.toRootedPath(root, buildFile),
"--incompatible_disallow_native_in_build_file=true");
assertThat(pkg.containsErrors()).isTrue();
}

@Test
public void testPackageGroupSpecMinimal() throws Exception {
expectEvalSuccess("package_group(name='skin', packages=[])");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private static StarlarkSemanticsOptions buildRandomOptions(Random rand) throws E
"--incompatible_disallow_legacy_javainfo=" + rand.nextBoolean(),
"--incompatible_disallow_legacy_java_provider=" + rand.nextBoolean(),
"--incompatible_disallow_load_labels_to_cross_package_boundaries=" + rand.nextBoolean(),
"--incompatible_disallow_native_in_build_file=" + rand.nextBoolean(),
"--incompatible_disallow_old_style_args_add=" + rand.nextBoolean(),
"--incompatible_disallow_struct_provider_syntax=" + rand.nextBoolean(),
"--incompatible_expand_directories=" + rand.nextBoolean(),
Expand Down Expand Up @@ -190,6 +191,7 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) {
.incompatibleDisallowLegacyJavaInfo(rand.nextBoolean())
.incompatibleDisallowLegacyJavaProvider(rand.nextBoolean())
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(rand.nextBoolean())
.incompatibleDisallowNativeInBuildFile(rand.nextBoolean())
.incompatibleDisallowOldStyleArgsAdd(rand.nextBoolean())
.incompatibleDisallowStructProviderSyntax(rand.nextBoolean())
.incompatibleExpandDirectories(rand.nextBoolean())
Expand Down

0 comments on commit 64e833c

Please sign in to comment.