Skip to content

Commit

Permalink
Disable Starlark implementation of py_library for unsupported cases.
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
rickeylev authored and copybara-github committed Oct 19, 2022
1 parent 0564b83 commit e618e8e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -61,15 +62,17 @@ 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");
}

@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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "(",
Expand All @@ -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",
Expand All @@ -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);
Expand Down Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(",
Expand Down Expand Up @@ -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(",
Expand Down Expand Up @@ -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(",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e618e8e

Please sign in to comment.