From e2c526b70d0f264dc3f38fe9bedb1839e324ed34 Mon Sep 17 00:00:00 2001 From: Jaden Peterson Date: Wed, 4 Dec 2024 17:55:02 -0500 Subject: [PATCH] Manually register the Play routes compiler toolchain --- MODULE.bazel | 2 + WORKSPACE | 6 --- play-routes-toolchain/BUILD.bazel | 13 ++++++ play-routes-toolchain/create-toolchain.bzl | 2 +- play-routes-toolchain/register-toolchains.bzl | 40 ------------------- play-routes-toolchain/transitions.bzl | 4 +- 6 files changed, 18 insertions(+), 49 deletions(-) delete mode 100644 WORKSPACE delete mode 100644 play-routes-toolchain/register-toolchains.bzl diff --git a/MODULE.bazel b/MODULE.bazel index d7209de..ee1332f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -20,6 +20,8 @@ bazel_dep(name = "stardoc", version = "0.7.1") register_toolchains( "//:repository_default_toolchain_21_definition", + "//play-routes-toolchain:play-routes-3", + "//play-routes-toolchain:play-routes-2-13", "//scala:zinc_2_13", "//scala:zinc_3", ) diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 3887faa..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,6 +0,0 @@ -workspace(name = "rules_play_routes") - -# Play routes compiler -load("//play-routes-toolchain:register-toolchains.bzl", "play_routes_register_toolchains") - -play_routes_register_toolchains(default_toolchain_name = "play-routes-3") diff --git a/play-routes-toolchain/BUILD.bazel b/play-routes-toolchain/BUILD.bazel index 45fa0e7..9c01fd1 100644 --- a/play-routes-toolchain/BUILD.bazel +++ b/play-routes-toolchain/BUILD.bazel @@ -1,8 +1,21 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_setting") load(":create-toolchain.bzl", "create_play_routes_toolchain") toolchain_type(name = "toolchain_type") +string_setting( + name = "original-play-routes-toolchain", + build_setting_default = "", + visibility = ["//visibility:public"], +) + +string_flag( + name = "play-routes-toolchain", + build_setting_default = "play-routes-3", + visibility = ["//visibility:public"], +) + create_play_routes_toolchain( name = "play-routes-3", play_routes_compiler = "//play-routes-compiler-cli:play-routes-compiler-cli-3", diff --git a/play-routes-toolchain/create-toolchain.bzl b/play-routes-toolchain/create-toolchain.bzl index 4fc2ff9..b355b27 100644 --- a/play-routes-toolchain/create-toolchain.bzl +++ b/play-routes-toolchain/create-toolchain.bzl @@ -12,7 +12,7 @@ def create_play_routes_toolchain(name, play_routes_compiler): native.config_setting( name = config_setting_name, flag_values = { - "@rules_play_routes_toolchain//:play-routes-toolchain": name, + "//play-routes-toolchain": name, }, ) diff --git a/play-routes-toolchain/register-toolchains.bzl b/play-routes-toolchain/register-toolchains.bzl deleted file mode 100644 index 23f4d3f..0000000 --- a/play-routes-toolchain/register-toolchains.bzl +++ /dev/null @@ -1,40 +0,0 @@ -def _toolchain_configuration_repository_impl(repository_ctx): - repository_ctx.file( - "BUILD.bazel", - """\ -load("@bazel_skylib//rules:common_settings.bzl", "string_setting") - -string_setting( - name = "play-routes-toolchain", - build_setting_default = "{}", - visibility = ["//visibility:public"], -) - -string_setting( - name = "original-play-routes-toolchain", - build_setting_default = "", - visibility = ["//visibility:public"], -) -""".format(repository_ctx.attr.default_toolchain_name), - ) - -_toolchain_configuration_repository = repository_rule( - attrs = { - "default_toolchain_name": attr.string(mandatory = True), - }, - doc = "Defines build settings used by the Play Routes toolchains to use. This is done in a separate repository so we can provide the default dynamically.", - implementation = _toolchain_configuration_repository_impl, -) - -def play_routes_register_toolchains( - default_toolchain_name, - toolchains = [ - "//play-routes-toolchain:play-routes-3", - "//play-routes-toolchain:play-routes-2-13", - ]): - _toolchain_configuration_repository( - name = "rules_play_routes_toolchain", - default_toolchain_name = default_toolchain_name, - ) - - native.register_toolchains(*toolchains) diff --git a/play-routes-toolchain/transitions.bzl b/play-routes-toolchain/transitions.bzl index 6cc4ec6..e629eb3 100644 --- a/play-routes-toolchain/transitions.bzl +++ b/play-routes-toolchain/transitions.bzl @@ -1,8 +1,8 @@ # This approach of incoming transition, store original values, outgoing # transition, reset to original values is inspired by what the rules_go # folks are doing. -toolchain_setting_key = "@rules_play_routes_toolchain//:play-routes-toolchain" -original_toolchain_setting_key = "@rules_play_routes_toolchain//:original-play-routes-toolchain" +toolchain_setting_key = "//play-routes-toolchain" +original_toolchain_setting_key = "//play-routes-toolchain:original-play-routes-toolchain" def _play_routes_toolchain_transition_impl(settings, attr): """Update the rules_play_routes toolchain to the overridden value. Store