Skip to content

Commit

Permalink
Toolchainize twitter_scrooge
Browse files Browse the repository at this point in the history
This is the last of the toolchain to receive the "toolchainization"
treatment prior to Bzlmodification, and moves `twitter_scrooge()` to
`twitter_scrooge/toolchain/toolchain.bzl` for `rules_java` 8
compatibility. Part of bazelbuild#1482 and bazelbuild#1652.
  • Loading branch information
mbland committed Dec 10, 2024
1 parent 15c8e02 commit 984b13d
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 240 deletions.
5 changes: 1 addition & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ scala_toolchains(
scala_proto = True,
scalafmt = True,
testing = True,
twitter_scrooge = True,
)

register_toolchains(
Expand All @@ -62,10 +63,6 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge")

twitter_scrooge()

# needed for the cross repo proto test
local_repository(
name = "proto_cross_repo_boundary",
Expand Down
31 changes: 30 additions & 1 deletion scala/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ load("//scalatest:scalatest.bzl", "scalatest_artifact_ids")
load("//specs2:specs2.bzl", "specs2_artifact_ids")
load("//specs2:specs2_junit.bzl", "specs2_junit_artifact_ids")
load("//third_party/repositories:repositories.bzl", "repositories")
load(
"//twitter_scrooge/toolchain:toolchain.bzl",
"twitter_scrooge_artifact_ids",
)
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS")

def scala_toolchains(
Expand All @@ -33,7 +37,13 @@ def scala_toolchains(
scalafmt_default_config_path = ".scalafmt.conf",
scala_proto = False,
scala_proto_enable_all_options = False,
jmh = False):
jmh = False,
twitter_scrooge = False,
libthrift = None,
scrooge_core = None,
scrooge_generator = None,
util_core = None,
util_logging = None):
"""Instantiates @io_bazel_rules_scala_toolchains and all its dependencies.
Provides a unified interface to configuring rules_scala both directly in a
Expand Down Expand Up @@ -86,6 +96,13 @@ def scala_toolchains(
toolchain with all options enabled; `scala_proto` must also be
`True` for this to take effect
jmh: whether to instantiate the jmh toolchain
twitter_scrooge: whether to instantiate the twitter_scrooge toolchain
libthrift: label to a libthrift artifact for twitter_scrooge
scrooge_core: label to a scrooge_core artifact for twitter_scrooge
scrooge_generator: label to a scrooge_generator artifact for
twitter_scrooge
util_core: label to a util_core artifact for twitter_scrooge
util_logging: label to a util_logging artifact for twitter_scrooge
"""
scala_repositories(
maven_servers = maven_servers,
Expand Down Expand Up @@ -130,6 +147,17 @@ def scala_toolchains(
id: False
for id in jmh_artifact_ids()
})
if twitter_scrooge:
artifact_ids_to_fetch_sources.update({
id: False
for id in twitter_scrooge_artifact_ids(
libthrift = libthrift,
scrooge_core = scrooge_core,
scrooge_generator = scrooge_generator,
util_core = util_core,
util_logging = util_logging,
)
})

for scala_version in SCALA_VERSIONS:
version_specific_artifact_ids = {}
Expand Down Expand Up @@ -168,6 +196,7 @@ def scala_toolchains(
scala_proto = scala_proto,
scala_proto_enable_all_options = scala_proto_enable_all_options,
jmh = jmh,
twitter_scrooge = twitter_scrooge,
)

def scala_register_toolchains():
Expand Down
12 changes: 12 additions & 0 deletions scala/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def _scala_toolchains_repo_impl(repository_ctx):
toolchains["scala_proto"] = _SCALA_PROTO_TOOLCHAIN_BUILD
if repo_attr.jmh:
toolchains["jmh"] = _JMH_TOOLCHAIN_BUILD
if repo_attr.twitter_scrooge:
toolchains["twitter_scrooge"] = _TWITTER_SCROOGE_TOOLCHAIN_BUILD

testing_build_args = _generate_testing_toolchain_build_file_args(repo_attr)
if testing_build_args != None:
Expand Down Expand Up @@ -81,6 +83,7 @@ _scala_toolchains_repo = repository_rule(
"scala_proto": attr.bool(),
"scala_proto_enable_all_options": attr.bool(),
"jmh": attr.bool(),
"twitter_scrooge": attr.bool(),
},
)

Expand Down Expand Up @@ -210,3 +213,12 @@ load("@@{rules_scala_repo}//jmh/toolchain:toolchain.bzl", "setup_jmh_toolchain")
setup_jmh_toolchain(name = "jmh_toolchain")
"""

_TWITTER_SCROOGE_TOOLCHAIN_BUILD = """
load(
"@@{rules_scala_repo}//twitter_scrooge/toolchain:toolchain.bzl",
"setup_scrooge_toolchain",
)
setup_scrooge_toolchain(name = "scrooge_toolchain")
"""
2 changes: 1 addition & 1 deletion test_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ run_in_test_repo() {

if [[ -n "$TWITTER_SCROOGE_VERSION" ]]; then
local version_param="version = \"$TWITTER_SCROOGE_VERSION\""
scrooge_ws="scrooge_repositories($version_param)"
scrooge_ws="$version_param"
fi

sed -e "s%\${twitter_scrooge_repositories}%${scrooge_ws}\n%" \
Expand Down
11 changes: 5 additions & 6 deletions test_version/WORKSPACE.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "extract_major_vers

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

load(":scrooge_repositories.bzl", "scrooge_repositories")

scrooge_repositories(${twitter_scrooge_repositories})

scala_toolchains(
fetch_sources = True,
scala_proto = True,
Expand All @@ -70,11 +74,6 @@ scala_toolchains(

register_toolchains(
"@io_bazel_rules_scala//scala:unused_dependency_checker_error_toolchain",
"@io_bazel_rules_scala//testing:testing_toolchain",
"@twitter_scrooge_test_toolchain//...:all",
"@io_bazel_rules_scala_toolchains//...:all",
)

load(":scrooge_repositories.bzl", "scrooge_repositories")
${twitter_scrooge_repositories}
load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge")
twitter_scrooge()
37 changes: 33 additions & 4 deletions test_version/version_specific_tests_dir/scrooge_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
)
load(
"@io_bazel_rules_scala//scala:scala_maven_import_external.bzl",
_scala_maven_import_external = "scala_maven_import_external",
)
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
"@io_bazel_rules_scala//scala:toolchains_repo.bzl",
"scala_toolchains_repo",
)
load(
"@io_bazel_rules_scala//twitter_scrooge/toolchain:toolchain.bzl",
"twitter_scrooge",
)

def _import_external(id, artifact, sha256, deps = [], runtime_deps = []):
_scala_maven_import_external(
name = id,
generated_rule_name = id,
artifact = artifact,
artifact_sha256 = sha256,
licenses = ["notice"],
Expand All @@ -20,8 +29,11 @@ def _import_external(id, artifact, sha256, deps = [], runtime_deps = []):
fetch_sources = False,
)

def scrooge_repositories(version):
def scrooge_repositories(version = None):
use_labels = False

if version == "18.6.0":
use_labels = True
_import_external(
id = "io_bazel_rules_scala_scrooge_core",
artifact = "com.twitter:scrooge-core_2.11:18.6.0",
Expand All @@ -48,7 +60,8 @@ def scrooge_repositories(version):
sha256 = "73ddd61cedabd4dab82b30e6c52c1be6c692b063b8ba310d716ead9e3b4e9267",
)

if version == "21.2.0":
elif version == "21.2.0":
use_labels = True
_import_external(
id = "io_bazel_rules_scala_scrooge_core",
artifact = "com.twitter:scrooge-core_2.11:21.2.0",
Expand All @@ -74,3 +87,19 @@ def scrooge_repositories(version):
artifact = "com.twitter:util-logging_2.11:21.2.0",
sha256 = "f3b62465963fbf0fe9860036e6255337996bb48a1a3f21a29503a2750d34f319",
)

if use_labels:
twitter_scrooge(
scrooge_core = "@io_bazel_rules_scala_scrooge_core",
scrooge_generator = "@io_bazel_rules_scala_scrooge_generator",
util_core = "@io_bazel_rules_scala_util_core",
util_logging = "@io_bazel_rules_scala_util_logging",
register_toolchains = False,
)
else:
twitter_scrooge(register_toolchains = False)

scala_toolchains_repo(
name = "twitter_scrooge_test_toolchain",
twitter_scrooge = True,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies_to_test = [
deps_with_external_binds = [
(
dep_name,
"//external:io_bazel_rules_scala/dependency/thrift/{}".format(dep_name),
"@io_bazel_rules_scala_{}".format(dep_name),
)
for dep_name in dependencies_to_test
]
Expand Down
99 changes: 14 additions & 85 deletions twitter_scrooge/BUILD
Original file line number Diff line number Diff line change
@@ -1,85 +1,14 @@
load("//twitter_scrooge/toolchain:toolchain.bzl", "export_scrooge_deps", "scrooge_toolchain")
load("//scala:providers.bzl", "declare_deps_provider")

scrooge_toolchain(
name = "scrooge_toolchain_impl",
visibility = ["//visibility:public"],
)

toolchain(
name = "scrooge_toolchain",
toolchain = ":scrooge_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//twitter_scrooge/toolchain:scrooge_toolchain_type",
visibility = ["//visibility:public"],
)

declare_deps_provider(
name = "aspect_compile_classpath_provider",
deps_id = "aspect_compile_classpath",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/thrift/javax_annotation_api",
"//external:io_bazel_rules_scala/dependency/thrift/libthrift",
"//external:io_bazel_rules_scala/dependency/thrift/scrooge_core",
"//external:io_bazel_rules_scala/dependency/thrift/util_core",
"//scala/private/toolchain_deps:scala_library_classpath",
],
)

declare_deps_provider(
name = "compile_classpath_provider",
deps_id = "compile_classpath",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/thrift/libthrift",
"//external:io_bazel_rules_scala/dependency/thrift/scrooge_core",
"//scala/private/toolchain_deps:scala_library_classpath",
],
)

declare_deps_provider(
name = "scrooge_generator_classpath_provider",
deps_id = "scrooge_generator_classpath",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/thrift/scrooge_generator",
],
)

declare_deps_provider(
name = "compiler_classpath_provider",
deps_id = "compiler_classpath",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/thrift/mustache",
"//external:io_bazel_rules_scala/dependency/thrift/scopt",
"//external:io_bazel_rules_scala/dependency/thrift/scrooge_generator",
"//external:io_bazel_rules_scala/dependency/thrift/util_core",
"//external:io_bazel_rules_scala/dependency/thrift/util_logging",
"//scala/private/toolchain_deps:parser_combinators",
],
)

export_scrooge_deps(
name = "compile_classpath",
deps_id = "compile_classpath",
visibility = ["//visibility:public"],
)

export_scrooge_deps(
name = "aspect_compile_classpath",
deps_id = "aspect_compile_classpath",
visibility = ["//visibility:public"],
)

export_scrooge_deps(
name = "scrooge_generator_classpath",
deps_id = "scrooge_generator_classpath",
visibility = ["//visibility:public"],
)

export_scrooge_deps(
name = "compiler_classpath",
deps_id = "compiler_classpath",
visibility = ["//visibility:public"],
)
load(
"//twitter_scrooge/toolchain:toolchain.bzl",
"DEP_PROVIDERS",
"export_scrooge_deps",
)

[
export_scrooge_deps(
name = dep,
deps_id = dep,
visibility = ["//visibility:public"],
)
for dep in DEP_PROVIDERS
]
Loading

0 comments on commit 984b13d

Please sign in to comment.