Skip to content

Commit e618e8e

Browse files
rickeylevcopybara-github
authored andcommitted
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
1 parent 0564b83 commit e618e8e

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private void declareBinDependingOnLibWithVersions(String binVersion, String libS
5151

5252
@Test
5353
public void python2WithPy3SrcsVersionDependency() throws Exception {
54-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
54+
setBuildLanguageOptions(
55+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
5556
declareBinDependingOnLibWithVersions("PY2", "PY3");
5657
assertThat(getPyExecutableDeferredError("//pkg:bin"))
5758
.startsWith(
@@ -61,15 +62,17 @@ public void python2WithPy3SrcsVersionDependency() throws Exception {
6162

6263
@Test
6364
public void python2WithPy3OnlySrcsVersionDependency() throws Exception {
64-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
65+
setBuildLanguageOptions(
66+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
6567
declareBinDependingOnLibWithVersions("PY2", "PY3ONLY");
6668
assertThat(getPyExecutableDeferredError("//pkg:bin"))
6769
.contains("being built for Python 2 but (transitively) includes Python 3-only sources");
6870
}
6971

7072
@Test
7173
public void python3WithPy2OnlySrcsVersionDependency_NewSemantics() throws Exception {
72-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
74+
setBuildLanguageOptions(
75+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
7376
declareBinDependingOnLibWithVersions("PY3", "PY2ONLY");
7477
assertThat(getPyExecutableDeferredError("//pkg:bin"))
7578
.contains("being built for Python 3 but (transitively) includes Python 2-only sources");

src/test/java/com/google/devtools/build/lib/rules/python/PyExecutableConfiguredTargetTestBase.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public void versionAttr_GoodValue() throws Exception {
171171

172172
@Test
173173
public void py3IsDefaultFlag_SetsDefaultPythonVersion() throws Exception {
174-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
174+
setBuildLanguageOptions(
175+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
175176
scratch.file(
176177
"pkg/BUILD", //
177178
ruleName + "(",
@@ -192,7 +193,8 @@ public void py3IsDefaultFlag_SetsDefaultPythonVersion() throws Exception {
192193

193194
@Test
194195
public void py3IsDefaultFlag_DoesntOverrideExplicitVersion() throws Exception {
195-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
196+
setBuildLanguageOptions(
197+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
196198
scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY2"));
197199
assertPythonVersionIs_UnderNewConfig(
198200
"//pkg:foo",
@@ -206,7 +208,8 @@ public void py3IsDefaultFlag_DoesntOverrideExplicitVersion() throws Exception {
206208

207209
@Test
208210
public void versionAttrWorks_WhenNotDefaultValue() throws Exception {
209-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
211+
setBuildLanguageOptions(
212+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
210213
scratch.file("pkg/BUILD", ruleDeclWithPyVersionAttr("foo", "PY2"));
211214

212215
assertPythonVersionIs("//pkg:foo", PythonVersion.PY2);
@@ -237,7 +240,8 @@ public void versionAttrTakesPrecedence_DefaultValue() throws Exception {
237240

238241
@Test
239242
public void canBuildWithDifferentVersionAttrs() throws Exception {
240-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
243+
setBuildLanguageOptions(
244+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
241245
scratch.file(
242246
"pkg/BUILD",
243247
ruleDeclWithPyVersionAttr("foo_v2", "PY2"),

src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private String evaluateAspectFor(String label) throws Exception {
5858

5959
@Test
6060
public void simpleCase() throws Exception {
61-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
61+
setBuildLanguageOptions(
62+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
6263
scratch.file(
6364
"pkg/BUILD",
6465
"py_library(",
@@ -116,7 +117,8 @@ public void noRequirements() throws Exception {
116117

117118
@Test
118119
public void twoContradictoryRequirements() throws Exception {
119-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
120+
setBuildLanguageOptions(
121+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
120122
scratch.file(
121123
"pkg/BUILD",
122124
"py_library(",
@@ -152,7 +154,8 @@ public void twoContradictoryRequirements() throws Exception {
152154

153155
@Test
154156
public void toplevelSelfContradictory() throws Exception {
155-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
157+
setBuildLanguageOptions(
158+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
156159
scratch.file(
157160
"pkg/BUILD",
158161
"py_binary(",
@@ -178,7 +181,8 @@ public void toplevelSelfContradictory() throws Exception {
178181

179182
@Test
180183
public void indirectDependencies() throws Exception {
181-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
184+
setBuildLanguageOptions(
185+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
182186
// A <- B <- C <- bin, where only B has the constraint.
183187
scratch.file(
184188
"pkg/BUILD",
@@ -219,7 +223,8 @@ public void indirectDependencies() throws Exception {
219223

220224
@Test
221225
public void onlyReportTopmost() throws Exception {
222-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
226+
setBuildLanguageOptions(
227+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
223228
// A <- B <- C <- bin, where A and C have the constraint.
224229
scratch.file(
225230
"pkg/BUILD",
@@ -261,7 +266,8 @@ public void onlyReportTopmost() throws Exception {
261266

262267
@Test
263268
public void oneTopmostReachesAnother() throws Exception {
264-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
269+
setBuildLanguageOptions(
270+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
265271
// A <- B <- C, where A and C have the constraint.
266272
// A <- bin and C <- bin, so both A and C are top-most even though C has a path to A.
267273
scratch.file(
@@ -306,7 +312,8 @@ public void oneTopmostReachesAnother() throws Exception {
306312

307313
@Test
308314
public void multiplePathsToRequirement() throws Exception {
309-
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_test,-py_binary");
315+
setBuildLanguageOptions(
316+
"--experimental_builtins_injection_override=-py_test,-py_binary,-py_library");
310317
// Diamond graph A <- B, A <- C, B <- bin, C <- bin, where only A has the constraint.
311318
// A is reached through two different paths but reported only once.
312319
scratch.file(

src/test/java/com/google/devtools/build/lib/rules/python/PythonStarlarkApiTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public void librarySandwich() throws Exception {
9797
" deps = [':pylib'],",
9898
" imports = ['upperuserlib_path'],",
9999
")");
100+
// TODO(bazel-team): Implement support for `imports` attribute
101+
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_library");
100102
ConfiguredTarget target = getConfiguredTarget("//pkg:upperuserlib");
101103

102104
PyInfo info = target.get(PyInfo.PROVIDER);

0 commit comments

Comments
 (0)