Skip to content

Commit

Permalink
fix: Update the BUILD.cypress to use template substitutions instead o…
Browse files Browse the repository at this point in the history
…f select statements
  • Loading branch information
ewianda committed Sep 5, 2024
1 parent 12c8fc3 commit ce9e944
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
22 changes: 5 additions & 17 deletions cypress/BUILD.cypress
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "Cypress",
tags = ["manual"]
)

Expand All @@ -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 = [":cypress_binary", ":binary_state_file"],
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",
)
)
6 changes: 6 additions & 0 deletions cypress/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion cypress/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ 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",
"%{TARGET_TOOL}": "Cypress/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,
Expand Down Expand Up @@ -78,6 +83,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,
Expand All @@ -86,6 +92,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",
Expand Down

0 comments on commit ce9e944

Please sign in to comment.