diff --git a/python/private/toolchains_repo.bzl b/python/private/toolchains_repo.bzl index 0c468bf01..0f5db3e8c 100644 --- a/python/private/toolchains_repo.bzl +++ b/python/private/toolchains_repo.bzl @@ -23,46 +23,13 @@ alias repository with only the toolchain attribute pointing into the platform-specific repositories. """ -MACOS_NAME = "mac os" -LINUX_NAME = "linux" -WINDOWS_NAME = "windows" - -PLATFORMS = { - "aarch64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:aarch64", - ], - os_name = MACOS_NAME, - # Matches the value returned from: - # repository_ctx.execute(["uname", "-m"]).stdout.strip() - arch = "arm64", - ), - "x86_64-apple-darwin": struct( - compatible_with = [ - "@platforms//os:macos", - "@platforms//cpu:x86_64", - ], - os_name = MACOS_NAME, - arch = "x86_64", - ), - "x86_64-pc-windows-msvc": struct( - compatible_with = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - os_name = WINDOWS_NAME, - arch = "x86_64", - ), - "x86_64-unknown-linux-gnu": struct( - compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], - os_name = LINUX_NAME, - arch = "x86_64", - ), -} +load( + "//python:versions.bzl", + "PLATFORMS", + "MACOS_NAME", + "LINUX_NAME", + "WINDOWS_NAME", +) def _toolchains_repo_impl(rctx): build_content = """\ diff --git a/python/repositories.bzl b/python/repositories.bzl index 65121f3ce..8b2e3cf05 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -17,10 +17,11 @@ For historic reasons, pip_repositories() is defined in //python:pip.bzl. """ -load("//python/private:toolchains_repo.bzl", "PLATFORMS", "host_os_alias", "toolchains_repo") +load("//python/private:toolchains_repo.bzl", "host_os_alias", "toolchains_repo") load( ":versions.bzl", "MINOR_MAPPING", + "PLATFORMS", "TOOL_VERSIONS", "get_release_url", ) diff --git a/python/tests/toolchains/BUILD.bazel b/python/tests/toolchains/BUILD.bazel index bb640fe41..2f804a4ca 100644 --- a/python/tests/toolchains/BUILD.bazel +++ b/python/tests/toolchains/BUILD.bazel @@ -12,13 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//python:versions.bzl", "TOOL_VERSIONS") -load(":defs.bzl", "acceptance_test") +load(":defs.bzl", "acceptance_tests") load(":versions_test.bzl", "versions_test_suite") versions_test_suite(name = "versions_test") -[acceptance_test( - name = "python_{}_test".format(python_version.replace(".", "_")), - python_version = python_version, -) for python_version in TOOL_VERSIONS.keys()] +acceptance_tests() diff --git a/python/tests/toolchains/defs.bzl b/python/tests/toolchains/defs.bzl index b832dd87b..bd7704bbf 100644 --- a/python/tests/toolchains/defs.bzl +++ b/python/tests/toolchains/defs.bzl @@ -15,6 +15,8 @@ """This module contains the definition for the toolchains testing rules. """ +load("//python:versions.bzl", "PLATFORMS", "TOOL_VERSIONS") + def _acceptance_test_impl(ctx): workspace = ctx.actions.declare_file("/".join([ctx.attr.python_version, "WORKSPACE"])) ctx.actions.expand_template( @@ -57,8 +59,8 @@ def _acceptance_test_impl(ctx): executable = ctx.actions.declare_file("run_test_{}.sh".format(ctx.attr.python_version)) ctx.actions.write( - output=executable, - content="""\ + output = executable, + content = """\ #!/bin/bash exec "{interpreter_path}" "{run_acceptance_test_py}" @@ -66,7 +68,7 @@ exec "{interpreter_path}" "{run_acceptance_test_py}" interpreter_path = interpreter_path, run_acceptance_test_py = run_acceptance_test_py.short_path, ), - is_executable=True, + is_executable = True, ) files = [ @@ -117,3 +119,20 @@ def acceptance_test(python_version, **kwargs): test_location = native.package_name(), **kwargs ) + +# buildifier: disable=unnamed-macro +def acceptance_tests(): + """Creates a matrix of acceptance_test targets for all the toolchains. + """ + for python_version in TOOL_VERSIONS.keys(): + for platform, meta in PLATFORMS.items(): + if platform not in TOOL_VERSIONS[python_version]["sha256"]: + continue + acceptance_test( + name = "python_{python_version}_{platform}_test".format( + python_version = python_version.replace(".", "_"), + platform = platform, + ), + python_version = python_version, + target_compatible_with = meta.compatible_with, + ) diff --git a/python/versions.bzl b/python/versions.bzl index 353c011ae..a61527cc1 100644 --- a/python/versions.bzl +++ b/python/versions.bzl @@ -15,13 +15,17 @@ """The Python versions we use for the toolchains. """ +MACOS_NAME = "mac os" +LINUX_NAME = "linux" +WINDOWS_NAME = "windows" + _RELEASE_BASE_URL = "https://github.com/indygreg/python-build-standalone/releases/download" def get_release_url(platform, python_version): release_filename = TOOL_VERSIONS[python_version]["url"].format( platform = platform, python_version = python_version, - build = "static-install_only" if ("windows" in platform) else "install_only", + build = "static-install_only" if (WINDOWS_NAME in platform) else "install_only", ) url = "/".join([_RELEASE_BASE_URL, release_filename]) return (release_filename, url) @@ -74,6 +78,43 @@ MINOR_MAPPING = { "3.10": "3.10.2", } +PLATFORMS = { + "aarch64-apple-darwin": struct( + compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:aarch64", + ], + os_name = MACOS_NAME, + # Matches the value returned from: + # repository_ctx.execute(["uname", "-m"]).stdout.strip() + arch = "arm64", + ), + "x86_64-apple-darwin": struct( + compatible_with = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + os_name = MACOS_NAME, + arch = "x86_64", + ), + "x86_64-pc-windows-msvc": struct( + compatible_with = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], + os_name = WINDOWS_NAME, + arch = "x86_64", + ), + "x86_64-unknown-linux-gnu": struct( + compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + os_name = LINUX_NAME, + arch = "x86_64", + ), +} + def print_toolchains_checksums(name): native.genrule( name = name,