From e618e8e1483ca820b467220b28b3e631c12b9282 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 18 Oct 2022 17:08:44 -0700 Subject: [PATCH] Disable Starlark implementation of py_library for unsupported cases. * Most of this is due to Python 2 support (which is being dropped as part of the Starlark rewrite). * Also disables the Starlark impl for tests of the `imports` attribute (this is disabled within Google, and not yet implemented). Work towards #15897 PiperOrigin-RevId: 482060859 Change-Id: I0c839c8cb20624d804d8d87e10170011ac6a3e55 --- .../python/PyBinaryConfiguredTargetTest.java | 9 +++++--- .../PyExecutableConfiguredTargetTestBase.java | 12 +++++++---- .../python/PythonSrcsVersionAspectTest.java | 21 ++++++++++++------- .../rules/python/PythonStarlarkApiTest.java | 2 ++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java index 4e2ea704941a51..e3896648cb1134 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java @@ -51,7 +51,8 @@ private void declareBinDependingOnLibWithVersions(String binVersion, String libS @Test public void python2WithPy3SrcsVersionDependency() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); declareBinDependingOnLibWithVersions("PY2", "PY3"); assertThat(getPyExecutableDeferredError("//pkg:bin")) .startsWith( @@ -61,7 +62,8 @@ public void python2WithPy3SrcsVersionDependency() throws Exception { @Test public void python2WithPy3OnlySrcsVersionDependency() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); declareBinDependingOnLibWithVersions("PY2", "PY3ONLY"); assertThat(getPyExecutableDeferredError("//pkg:bin")) .contains("being built for Python 2 but (transitively) includes Python 3-only sources"); @@ -69,7 +71,8 @@ public void python2WithPy3OnlySrcsVersionDependency() throws Exception { @Test public void python3WithPy2OnlySrcsVersionDependency_NewSemantics() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); declareBinDependingOnLibWithVersions("PY3", "PY2ONLY"); assertThat(getPyExecutableDeferredError("//pkg:bin")) .contains("being built for Python 3 but (transitively) includes Python 2-only sources"); diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java index c59bb897db8335..59fc7db1dfe5df 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java @@ -171,7 +171,8 @@ public void versionAttr_GoodValue() throws Exception { @Test public void py3IsDefaultFlag_SetsDefaultPythonVersion() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file( "pkg/BUILD", // ruleName + "(", @@ -192,7 +193,8 @@ public void py3IsDefaultFlag_SetsDefaultPythonVersion() throws Exception { @Test public void py3IsDefaultFlag_DoesntOverrideExplicitVersion() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY2")); assertPythonVersionIs_UnderNewConfig( "//pkg:foo", @@ -206,7 +208,8 @@ public void py3IsDefaultFlag_DoesntOverrideExplicitVersion() throws Exception { @Test public void versionAttrWorks_WhenNotDefaultValue() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY2")); assertPythonVersionIs("//pkg:foo", PythonVersion.PY2); @@ -237,7 +240,8 @@ public void versionAttrTakesPrecedence_DefaultValue() throws Exception { @Test public void canBuildWithDifferentVersionAttrs() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file( "pkg/BUILD", ruleDeclWithPyVersionAttr("foo_v2", "PY2"), diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java index 94313f73d99e2d..cd3cffd78f455b 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java @@ -58,7 +58,8 @@ private String evaluateAspectFor(String label) throws Exception { @Test public void simpleCase() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file( "pkg/BUILD", "py_library(", @@ -116,7 +117,8 @@ public void noRequirements() throws Exception { @Test public void twoContradictoryRequirements() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file( "pkg/BUILD", "py_library(", @@ -152,7 +154,8 @@ public void twoContradictoryRequirements() throws Exception { @Test public void toplevelSelfContradictory() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); scratch.file( "pkg/BUILD", "py_binary(", @@ -178,7 +181,8 @@ public void toplevelSelfContradictory() throws Exception { @Test public void indirectDependencies() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); // A <- B <- C <- bin, where only B has the constraint. scratch.file( "pkg/BUILD", @@ -219,7 +223,8 @@ public void indirectDependencies() throws Exception { @Test public void onlyReportTopmost() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); // A <- B <- C <- bin, where A and C have the constraint. scratch.file( "pkg/BUILD", @@ -261,7 +266,8 @@ public void onlyReportTopmost() throws Exception { @Test public void oneTopmostReachesAnother() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); // A <- B <- C, where A and C have the constraint. // A <- bin and C <- bin, so both A and C are top-most even though C has a path to A. scratch.file( @@ -306,7 +312,8 @@ public void oneTopmostReachesAnother() throws Exception { @Test public void multiplePathsToRequirement() throws Exception { - setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary"); + setBuildLanguageOptions( + "--experimental_builtins_injection_override=-py_test,-py_binary,-py_library"); // Diamond graph A <- B, A <- C, B <- bin, C <- bin, where only A has the constraint. // A is reached through two different paths but reported only once. scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java index d82059f4184ff1..41b277aed4fc9a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java @@ -97,6 +97,8 @@ public void librarySandwich() throws Exception { " deps = [':pylib'],", " imports = ['upperuserlib_path'],", ")"); + // TODO(bazel-team): Implement support for `imports` attribute + setBuildLanguageOptions("--experimental_builtins_injection_override=-py_library"); ConfiguredTarget target = getConfiguredTarget("//pkg:upperuserlib"); PyInfo info = target.get(PyInfo.PROVIDER);