| # Copyright 2023 The Bazel Authors. All rights reserved. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| load("@rules_pkg//pkg:tar.bzl", "pkg_tar") |
| load("@rules_shell//shell:sh_test.bzl", "sh_test") |
| load("//tests/support:py_reconfig.bzl", "py_reconfig_binary", "py_reconfig_test") |
| load("//tests/support:sh_py_run_test.bzl", "sh_py_run_test") |
| load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT") |
| load(":venv_relative_path_tests.bzl", "relative_path_test_suite") |
| |
| py_reconfig_binary( |
| name = "bootstrap_script_zipapp_bin", |
| srcs = ["bin.py"], |
| bootstrap_impl = "script", |
| # Force it to not be self-executable |
| build_python_zip = False, |
| main = "bin.py", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| filegroup( |
| name = "bootstrap_script_zipapp_zip", |
| testonly = 1, |
| srcs = [":bootstrap_script_zipapp_bin"], |
| output_group = "python_zip_file", |
| ) |
| |
| sh_test( |
| name = "bootstrap_script_zipapp_test", |
| srcs = ["bootstrap_script_zipapp_test.sh"], |
| data = [":bootstrap_script_zipapp_zip"], |
| env = { |
| "ZIP_RLOCATION": "$(rlocationpaths :bootstrap_script_zipapp_zip)".format(), |
| }, |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| deps = [ |
| "@bazel_tools//tools/bash/runfiles", |
| ], |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_zip_no_test", |
| build_python_zip = False, |
| py_src = "bin.py", |
| sh_src = "run_binary_zip_no_test.sh", |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_zip_yes_test", |
| build_python_zip = True, |
| py_src = "bin.py", |
| sh_src = "run_binary_zip_yes_test.sh", |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_venvs_use_declare_symlink_no_test", |
| bootstrap_impl = "script", |
| py_src = "bin.py", |
| sh_src = "run_binary_venvs_use_declare_symlink_no_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| venvs_use_declare_symlink = "no", |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_find_runfiles_test", |
| py_src = "bin.py", |
| sh_src = "run_binary_find_runfiles_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_bootstrap_script_zip_yes_test", |
| bootstrap_impl = "script", |
| build_python_zip = True, |
| py_src = "bin.py", |
| sh_src = "run_binary_zip_yes_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_bootstrap_script_zip_no_test", |
| bootstrap_impl = "script", |
| build_python_zip = False, |
| py_src = "bin.py", |
| sh_src = "run_binary_zip_no_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| sh_py_run_test( |
| name = "run_binary_bootstrap_script_find_runfiles_test", |
| bootstrap_impl = "script", |
| py_src = "bin.py", |
| sh_src = "run_binary_find_runfiles_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| py_reconfig_test( |
| name = "bazel_tools_importable_system_python_test", |
| srcs = ["bazel_tools_importable_test.py"], |
| bootstrap_impl = "system_python", |
| # Necessary because bazel_tools doesn't have __init__.py files. |
| legacy_create_init = True, |
| main = "bazel_tools_importable_test.py", |
| deps = [ |
| "@bazel_tools//tools/python/runfiles", |
| ], |
| ) |
| |
| py_reconfig_test( |
| name = "sys_path_order_bootstrap_script_test", |
| srcs = ["sys_path_order_test.py"], |
| bootstrap_impl = "script", |
| env = {"BOOTSTRAP": "script"}, |
| imports = ["./USER_IMPORT/site-packages"], |
| main = "sys_path_order_test.py", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| py_reconfig_test( |
| name = "sys_path_order_bootstrap_system_python_test", |
| srcs = ["sys_path_order_test.py"], |
| bootstrap_impl = "system_python", |
| env = {"BOOTSTRAP": "system_python"}, |
| imports = ["./site-packages"], |
| main = "sys_path_order_test.py", |
| ) |
| |
| py_reconfig_test( |
| name = "main_module_test", |
| srcs = ["main_module.py"], |
| bootstrap_impl = "script", |
| imports = ["."], |
| main_module = "tests.bootstrap_impls.main_module", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| sh_py_run_test( |
| name = "inherit_pythonsafepath_env_test", |
| bootstrap_impl = "script", |
| py_src = "bin.py", |
| sh_src = "inherit_pythonsafepath_env_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| sh_py_run_test( |
| name = "sys_executable_inherits_sys_path", |
| bootstrap_impl = "script", |
| imports = ["./MARKER"], |
| py_src = "call_sys_exe.py", |
| sh_src = "sys_executable_inherits_sys_path_test.sh", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| py_reconfig_test( |
| name = "interpreter_args_test", |
| srcs = ["interpreter_args_test.py"], |
| bootstrap_impl = "script", |
| interpreter_args = ["-XSPECIAL=1"], |
| main = "interpreter_args_test.py", |
| target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, |
| ) |
| |
| pkg_tar( |
| name = "external_binary", |
| testonly = True, |
| srcs = ["@other//:external_main"], |
| include_runfiles = True, |
| tags = ["manual"], # Don't build as part of wildcards |
| ) |
| |
| sh_test( |
| name = "external_binary_test", |
| srcs = ["external_binary_test.sh"], |
| data = [":external_binary"], |
| # For now, skip this test on Windows because it fails for reasons |
| # other than the code path being tested. |
| target_compatible_with = select({ |
| "@platforms//os:windows": ["@platforms//:incompatible"], |
| "//conditions:default": [], |
| }), |
| ) |
| |
| relative_path_test_suite(name = "relative_path_tests") |