Skip to content

Commit

Permalink
feat: use matrix for acceptance tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
  • Loading branch information
f0rmiga committed Mar 4, 2022
1 parent 651ce7f commit 9549c4a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 51 deletions.
47 changes: 7 additions & 40 deletions python/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down
3 changes: 2 additions & 1 deletion python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
8 changes: 2 additions & 6 deletions python/tests/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 22 additions & 3 deletions python/tests/toolchains/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -57,16 +59,16 @@ 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}"
""".format(
interpreter_path = interpreter_path,
run_acceptance_test_py = run_acceptance_test_py.short_path,
),
is_executable=True,
is_executable = True,
)

files = [
Expand Down Expand Up @@ -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,
)
43 changes: 42 additions & 1 deletion python/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9549c4a

Please sign in to comment.