Skip to content

Commit

Permalink
Load Python rules in integration tests instead of using builtins (#2)
Browse files Browse the repository at this point in the history
This is to facilitate moving the rule implementation out of Bazel itself and into rules_python. This also makes the tests pass when an allowlist is used to enforce that the Python rules are being loaded through rules_python instead of used from builtins.

This the same change as before, but with some internal fixes applied.

PiperOrigin-RevId: 565113515
Change-Id: I999dbfaace8cce2168e718093fe418d548ab1b73
  • Loading branch information
rickeylev authored and copybara-github committed Sep 13, 2023
1 parent 7c1b139 commit 0c617b3
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ load(
"exports_test",
)
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
load("@rules_python//python:py_test.bzl", "py_test")

LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE"

Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/integration/aquery_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,8 @@ function test_aquery_include_template_substitution_for_template_expand_of_py_bin
local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg" || fail "mkdir -p $pkg"
cat > "$pkg/BUILD" <<'EOF'
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(
name='foo',
srcs=['foo.py']
Expand Down
15 changes: 15 additions & 0 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ function test_show_transitive_config_fragments() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
cc_library(
name = "cclib",
srcs = ["mylib.cc"],
Expand Down Expand Up @@ -326,6 +328,8 @@ function test_show_transitive_config_fragments_alias() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
cc_library(
name = "cclib_with_py_dep",
srcs = ["mylib2.cc"],
Expand Down Expand Up @@ -385,6 +389,8 @@ function test_show_transitive_config_fragments_host_deps() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
cc_library(
name = "cclib_with_py_dep",
srcs = ["mylib2.cc"],
Expand Down Expand Up @@ -414,6 +420,8 @@ function test_show_transitive_config_fragments_through_output_file() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
cc_library(
name = "cclib_with_py_dep",
srcs = ["mylib2.cc"],
Expand Down Expand Up @@ -443,6 +451,8 @@ function test_show_direct_config_fragments() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
cc_library(
name = "cclib",
srcs = ["mylib.cc"],
Expand Down Expand Up @@ -866,6 +876,8 @@ function test_starlark_output_mode() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
py_library(
name = "pylib",
srcs = ["pylib.py"],
Expand Down Expand Up @@ -991,6 +1003,7 @@ EOF

cat > $pkg/BUILD <<'EOF'
load(":rules.bzl", "bool_flag", "list_flag", "root_rule")
load("@rules_python//python:py_library.bzl", "py_library")
exports_files(["rules.bzl"])
Expand Down Expand Up @@ -1060,6 +1073,8 @@ function test_starlark_build_options_invalid_arg() {
mkdir -p $pkg

cat > $pkg/BUILD <<'EOF'
load("@rules_python//python:py_library.bzl", "py_library")
py_library(
name = "foo",
srcs = ["pylib.py"],
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/integration/modify_execution_info_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ EOF
mkdir -p "$pkg" || fail "mkdir -p $pkg"
echo "load('//$pkg:shell.bzl', 'starlark_shell')" > "$pkg/BUILD"
cat >> "$pkg/BUILD" <<'EOF'
load("@rules_python//python:py_binary.bzl", "py_binary")
starlark_shell(
name = "shelly",
output = "ok.txt",
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/integration/nestedset_as_skykey_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ function test_dirty_file() {
export DONT_SANITY_CHECK_SERIALIZATION=1
cat > foo/BUILD <<EOF
load(":foo.bzl", "foo_library", "foo_binary")
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(
name = "foocc",
srcs = ["foocc.py"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ EOF

cat > package/BUILD <<EOF
load(":lib.bzl", "flag_per_line")
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(
name = "flag_copy",
Expand Down
6 changes: 6 additions & 0 deletions src/test/shell/integration/python_stub_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function test_python_version() {
mkdir -p test
touch test/main3.py
cat > test/BUILD << EOF
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(name = "main3",
python_version = "PY3",
srcs = ["main3.py"],
Expand All @@ -91,6 +93,8 @@ EOF
function test_can_build_py_library_at_top_level_regardless_of_version() {
mkdir -p test
cat > test/BUILD << EOF
load("@rules_python//python:py_library.bzl", "py_library")
py_library(
name = "lib3",
srcs = ["lib3.py"],
Expand All @@ -112,6 +116,8 @@ function test_python_through_bash_without_runfile_links() {
mkdir -p python_through_bash

cat > python_through_bash/BUILD << EOF
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(
name = "inner",
srcs = ["inner.py"],
Expand Down
4 changes: 4 additions & 0 deletions src/test/shell/integration/python_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ fi
function test_python_binary_empty_files_in_runfiles_are_regular_files() {
mkdir -p test/mypackage
cat > test/BUILD <<'EOF'
load("@rules_python//python:py_test.bzl", "py_test")
py_test(
name = "a",
srcs = [
Expand Down Expand Up @@ -128,6 +130,8 @@ function test_building_transitive_py_binary_runfiles_trees() {
touch main.py script.sh
chmod u+x script.sh
cat > BUILD <<'EOF'
load("@rules_python//python:py_binary.bzl", "py_binary")
py_binary(
name = 'py-tool',
srcs = ['main.py'],
Expand Down
9 changes: 7 additions & 2 deletions src/test/shell/integration/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ add_to_bazelrc "test --notest_loasd"
function write_py_files() {
mkdir -p py || fail "mkdir py failed"

echo "py_binary(name = 'binary', srcs = ['binary.py'])" > py/BUILD
echo "py_test(name = 'test', srcs = ['test.py'])" >> py/BUILD
cat > py/BUILD <<'EOF'
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_test.bzl", "py_test")
py_binary(name = "binary", srcs = ["binary.py"])
py_test(name = "test", srcs = ["test.py"])
EOF

echo "print('Hello, Python World!')" >py/py.py
chmod +x py/py.py
Expand Down
4 changes: 4 additions & 0 deletions src/test/shell/integration/runfiles_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ function test_foo_runfiles() {
local -r pkg=$FUNCNAME
create_pkg $pkg
cat > BUILD << EOF
load("@rules_python//python:py_library.bzl", "py_library")
py_library(name = "root",
srcs = ["__init__.py"],
visibility = ["//visibility:public"])
EOF
cat > $pkg/BUILD << EOF
load("@rules_python//python:py_binary.bzl", "py_binary")
sh_binary(name = "foo",
srcs = [ "x/y/z.sh" ],
data = [ ":py",
Expand Down
3 changes: 3 additions & 0 deletions src/test/shell/integration/stub_finds_runfiles_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ fi
function set_up() {
mkdir -p pkg pkg/java
cat > pkg/BUILD << 'EOF'
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_test.bzl", "py_test")
java_binary(name = "javabin",
main_class = "test.ExitZero",
srcs = [ "java/ExitZero.java", ])
Expand Down

0 comments on commit 0c617b3

Please sign in to comment.