From 133e544c082854fd04e95a0726504c55ced57754 Mon Sep 17 00:00:00 2001 From: Elvis Wianda Date: Wed, 4 Sep 2024 12:45:17 -0400 Subject: [PATCH] fix: Update the BUILD.cypress to use template substitutions instead of select statements --- cypress/BUILD.cypress | 22 +++++----------------- cypress/private/toolchains_repo.bzl | 6 ++++++ cypress/repositories.bzl | 11 ++++++++++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cypress/BUILD.cypress b/cypress/BUILD.cypress index 8176126..9c04e3d 100644 --- a/cypress/BUILD.cypress +++ b/cypress/BUILD.cypress @@ -8,14 +8,8 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") # Copy the cypress binary directory to make it RBE compatible. copy_directory( name = "cypress_binary", - src = select({ - "@bazel_tools//src/conditions:darwin": "Cypress.app", - "//conditions:default": "Cypress", - }), - out = select({ - "@bazel_tools//src/conditions:darwin": "Cypress.app", - "//conditions:default": "Cypress", - }), + src = "%{COPY_DIRECTORY_SRC}", + out = "%{COPY_DIRECTORY_SRC}", tags = ["manual"] ) @@ -27,18 +21,12 @@ copy_to_bin( filegroup( name = "files", - srcs = select({ - "@bazel_tools//src/conditions:darwin": ["Cypress.app", "binary_state.json"], - "//conditions:default": [":cypress_binary", ":binary_state_file"] - }), + srcs = ["%{FILE_APP}", "%{FILE_BINARY_STATE}"], visibility = ["//visibility:public"], ) cypress_toolchain( name = "cypress_toolchain", - target_tool = select({ - "@bazel_tools//src/conditions:darwin": "Cypress.app/Contents/MacOS/Cypress", - "//conditions:default": "Cypress/Cypress", - }), + target_tool = "%{TARGET_TOOL}", target_tool_files = ":files", -) \ No newline at end of file +) diff --git a/cypress/private/toolchains_repo.bzl b/cypress/private/toolchains_repo.bzl index e6ea4d6..03316b7 100644 --- a/cypress/private/toolchains_repo.bzl +++ b/cypress/private/toolchains_repo.bzl @@ -86,6 +86,12 @@ toolchain( toolchain = "@{user_repository_name}_{platform}//:cypress_toolchain", toolchain_type = "@aspect_rules_cypress//cypress:toolchain_type", ) +toolchain( + name = "{platform}_toolchain_target", + target_compatible_with = {compatible_with}, + toolchain = "@{user_repository_name}_{platform}//:cypress_toolchain", + toolchain_type = "@aspect_rules_cypress//cypress:toolchain_type", +) """.format( platform = platform, name = repository_ctx.attr.name, diff --git a/cypress/repositories.bzl b/cypress/repositories.bzl index 43f633e..116ac66 100644 --- a/cypress/repositories.bzl +++ b/cypress/repositories.bzl @@ -32,7 +32,14 @@ def _cypress_repo_impl(repository_ctx): repository_ctx.file("binary_state.json", binary_state_json_contents) # Base BUILD file for this repository - repository_ctx.template("BUILD.bazel", Label("//cypress:BUILD.cypress")) + is_darwin = repository_ctx.attr.platform.startswith("darwin") + substitution = { + "%{COPY_DIRECTORY_SRC}": "Cypress.app" if is_darwin else "Cypress", + "%{FILE_APP}": "Cypress.app" if is_darwin else ":cypress_binary", + "%{FILE_BINARY_STATE}": "binary_state.json" if is_darwin else ":binary_state_file", + "%{TARGET_TOOL}": "Cypress.app/Contents/MacOS/Cypress" if is_darwin else "Cypress/Cypress", + } + repository_ctx.template("BUILD.bazel", Label("//cypress:BUILD.cypress"), substitution) cypress_repositories = repository_rule( _cypress_repo_impl, @@ -78,6 +85,7 @@ Alternately, you may manually specify platform integrity hashes with cypress_int cypress_integrity = TOOL_VERSIONS[cypress_version] for platform in PLATFORMS.keys(): + print("Registering cypress toolchain for platform: " + platform) cypress_repositories( name = name + "_" + platform, version = cypress_version, @@ -86,6 +94,7 @@ Alternately, you may manually specify platform integrity hashes with cypress_int ) if register: native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform)) + native.register_toolchains("@%s_toolchains//:%s_toolchain_target" % (name, platform)) toolchains_repo( name = name + "_toolchains",