diff options
author | laurentlb <laurentlb@google.com> | 2018-03-27 12:43:22 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-27 12:45:58 -0700 |
commit | 1cbce0fad88d02c76386e8525e03d0f427515ad2 (patch) | |
tree | d014f99feea84a2d13bfc8344a89e06ae91427a9 /src/test/java | |
parent | 44eb96413bc99291854c51a04b18397a400ccd90 (diff) |
New incompatible flag to disable PACKAGE_NAME and REPOSITORY_NAME.
RELNOTES[INC]:
Variables PACKAGE_NAME and REPOSITORY_NAME are deprecated in favor of
functions `package_name()` and `repository_name()`.
https://docs.bazel.build/versions/master/skylark/lib/native.html#package_name
PiperOrigin-RevId: 190657188
Diffstat (limited to 'src/test/java')
4 files changed, 66 insertions, 11 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java index bbb8be7e82..501037574a 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java @@ -247,6 +247,14 @@ public class PackageFactoryTest extends PackageFactoryTestBase { } @Test + public void testPackageConstantIsForbidden() throws Exception { + events.setFailFast(false); + Path buildFile = scratch.file("/pina/BUILD", "cc_library(name=PACKAGE_NAME + '-colada')"); + packages.createPackage("pina", buildFile, "--incompatible_package_name_is_a_function=true"); + events.assertContainsError("The value 'PACKAGE_NAME' has been removed"); + } + + @Test public void testPackageNameFunction() throws Exception { Path buildFile = scratch.file("/pina/BUILD", "cc_library(name=package_name() + '-colada')"); @@ -272,6 +280,20 @@ public class PackageFactoryTest extends PackageFactoryTestBase { } @Test + public void testPackageConstantInExternalRepositoryIsForbidden() throws Exception { + events.setFailFast(false); + Path buildFile = + scratch.file( + "/external/a/b/BUILD", "genrule(name='c', srcs=[], outs=['ao'], cmd=REPOSITORY_NAME)"); + packages.createPackage( + PackageIdentifier.create("@a", PathFragment.create("b")), + buildFile, + events.reporter(), + "--incompatible_package_name_is_a_function=true"); + events.assertContainsError("The value 'REPOSITORY_NAME' has been removed"); + } + + @Test public void testPackageFunctionInExternalRepository() throws Exception { Path buildFile = scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java index a9a3d517f7..7cfedfec14 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java @@ -128,6 +128,7 @@ public class SkylarkSemanticsConsistencyTest { "--incompatible_disallow_three_arg_vardef=" + rand.nextBoolean(), "--incompatible_disallow_toplevel_if_statement=" + rand.nextBoolean(), "--incompatible_new_actions_api=" + rand.nextBoolean(), + "--incompatible_package_name_is_a_function=" + rand.nextBoolean(), "--incompatible_remove_native_git_repository=" + rand.nextBoolean(), "--incompatible_remove_native_http_archive=" + rand.nextBoolean(), "--incompatible_string_is_not_iterable=" + rand.nextBoolean(), @@ -150,6 +151,7 @@ public class SkylarkSemanticsConsistencyTest { .incompatibleDisallowThreeArgVardef(rand.nextBoolean()) .incompatibleDisallowToplevelIfStatement(rand.nextBoolean()) .incompatibleNewActionsApi(rand.nextBoolean()) + .incompatiblePackageNameIsAFunction(rand.nextBoolean()) .incompatibleRemoveNativeGitRepository(rand.nextBoolean()) .incompatibleRemoveNativeHttpArchive(rand.nextBoolean()) .incompatibleStringIsNotIterable(rand.nextBoolean()) diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java index e91b2ded27..6fa2949ec4 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageFactoryApparatus.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.packages.Package.Builder; import com.google.devtools.build.lib.packages.PackageFactory; import com.google.devtools.build.lib.packages.PackageFactory.LegacyGlobber; import com.google.devtools.build.lib.packages.RuleClassProvider; +import com.google.devtools.build.lib.packages.SkylarkSemanticsOptions; import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.syntax.Environment.Extension; import com.google.devtools.build.lib.syntax.ParserInputSource; @@ -39,6 +40,7 @@ import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.common.options.OptionsParser; import java.io.IOException; /** @@ -76,12 +78,15 @@ public class PackageFactoryApparatus { return createEmptyLocator(); } - /** - * Parses and evaluates {@code buildFile} and returns the resulting {@link Package} instance. - */ + /** Parses and evaluates {@code buildFile} and returns the resulting {@link Package} instance. */ public Package createPackage(String packageName, Path buildFile) throws Exception { - return createPackage(PackageIdentifier.createInMainRepo(packageName), buildFile, - eventHandler); + return createPackage(PackageIdentifier.createInMainRepo(packageName), buildFile, eventHandler); + } + + public Package createPackage(String packageName, Path buildFile, String skylarkOption) + throws Exception { + return createPackage( + PackageIdentifier.createInMainRepo(packageName), buildFile, eventHandler, skylarkOption); } /** @@ -89,21 +94,41 @@ public class PackageFactoryApparatus { * resulting {@link Package} instance. */ public Package createPackage( - PackageIdentifier packageIdentifier, Path buildFile, ExtendedEventHandler reporter) + PackageIdentifier packageIdentifier, + Path buildFile, + ExtendedEventHandler reporter, + String skylarkOption) throws Exception { + + OptionsParser parser = OptionsParser.newOptionsParser(SkylarkSemanticsOptions.class); + parser.parse( + skylarkOption == null + ? ImmutableList.<String>of() + : ImmutableList.<String>of(skylarkOption)); + SkylarkSemantics semantics = + parser.getOptions(SkylarkSemanticsOptions.class).toSkylarkSemantics(); + try { + Package externalPkg = + factory + .newExternalPackageBuilder( + buildFile.getRelative(Label.WORKSPACE_FILE_NAME), "TESTING") + .build(); Package pkg = factory.createPackageForTesting( - packageIdentifier, - buildFile, - getPackageLocator(), - reporter); + packageIdentifier, externalPkg, buildFile, getPackageLocator(), reporter, semantics); return pkg; } catch (InterruptedException e) { throw new IllegalStateException(e); } } + public Package createPackage( + PackageIdentifier packageIdentifier, Path buildFile, ExtendedEventHandler reporter) + throws Exception { + return createPackage(packageIdentifier, buildFile, reporter, null); + } + /** * Parses the {@code buildFile} into a {@link BuildFileAST}. */ diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TransitiveTraversalFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TransitiveTraversalFunctionTest.java index 80a07e0b8b..7749f9e9ff 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TransitiveTraversalFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TransitiveTraversalFunctionTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.NoSuchTargetException; import com.google.devtools.build.lib.packages.Package; import com.google.devtools.build.lib.skyframe.TransitiveBaseTraversalFunction.TargetAndErrorIfAnyImpl; +import com.google.devtools.build.lib.syntax.SkylarkSemantics; import com.google.devtools.build.lib.util.GroupedList; import com.google.devtools.build.lib.util.GroupedList.GroupedListHelper; import com.google.devtools.build.lib.vfs.Path; @@ -104,6 +105,11 @@ public class TransitiveTraversalFunctionTest extends BuildViewTestCase { Package.Builder.DefaultHelper.INSTANCE, buildFile.getRelative("WORKSPACE"), "TESTING"); externalPkg.setWorkspaceName(workspaceName); return pkgFactory.createPackageForTesting( - packageId, externalPkg.build(), buildFile, packageIdentifier -> buildFile, reporter); + packageId, + externalPkg.build(), + buildFile, + packageIdentifier -> buildFile, + reporter, + SkylarkSemantics.DEFAULT_SEMANTICS); } } |