-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Deps Toolchain Infrastructure #1067
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load(":toolchain_dep_rules.bzl", "common_toolchain_deps", "scala_toolchain_deps") | ||
|
||
# dependencies from ScalacProvider | ||
scala_toolchain_deps( | ||
name = "scala_compile_classpath", | ||
from_classpath = "default_repl_classpath", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
scala_toolchain_deps( | ||
name = "scala_library_classpath", | ||
from_classpath = "default_classpath", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# dependencies from DepsInfo | ||
common_toolchain_deps( | ||
name = "scala_xml", | ||
provider_id = "scala_xml", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
common_toolchain_deps( | ||
name = "parser_combinators", | ||
provider_id = "parser_combinators", | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("@io_bazel_rules_scala//scala:providers.bzl", _ScalacProvider = "ScalacProvider") | ||
load("//scala/private/toolchain_deps:toolchain_deps.bzl", "expose_toolchain_deps", "java_info_for_deps") | ||
|
||
def _scala_toolchain_deps(ctx): | ||
_toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type" | ||
from_classpath = ctx.attr.from_classpath | ||
|
||
scalac_provider = ctx.toolchains[_toolchain_type].scalac_provider_attr[_ScalacProvider] | ||
classpath_deps = getattr(scalac_provider, from_classpath) | ||
return java_info_for_deps(classpath_deps) | ||
|
||
scala_toolchain_deps = rule( | ||
implementation = _scala_toolchain_deps, | ||
attrs = { | ||
"from_classpath": attr.string(mandatory = True), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check my understanding: Is it correct to say that we need this (and we can't use Either way is fine by me, even if we were to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks! Seems reasonable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate PR sounds very reasonable while also important since I think having multiple mental models would make things really hard |
||
}, | ||
toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], | ||
) | ||
|
||
def _common_toolchain_deps(ctx): | ||
return expose_toolchain_deps(ctx, "@io_bazel_rules_scala//scala:deps_toolchain_type") | ||
|
||
common_toolchain_deps = rule( | ||
implementation = _common_toolchain_deps, | ||
attrs = { | ||
"provider_id": attr.string(mandatory = True), | ||
}, | ||
toolchains = ["@io_bazel_rules_scala//scala:deps_toolchain_type"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("@io_bazel_rules_scala//scala:providers.bzl", "DepsInfo") | ||
|
||
def _log_required_provider_id(target, toolchain_type_label, provider_id): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it misleading? it's called log but you're actually failing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. |
||
fail(target + " requires mapping of " + provider_id + " provider id on the toolchain " + toolchain_type_label) | ||
|
||
def java_info_for_deps(deps): | ||
return [java_common.merge([dep[JavaInfo] for dep in deps])] | ||
|
||
def expose_toolchain_deps(ctx, toolchain_type_label): | ||
dep_provider_id = ctx.attr.provider_id | ||
dep_providers_map = getattr(ctx.toolchains[toolchain_type_label], "dep_providers") | ||
dep_provider = {v: k for k, v in dep_providers_map.items()}.get(dep_provider_id) | ||
|
||
if dep_provider == None: | ||
_log_required_provider_id(ctx.attr.name, toolchain_type_label, dep_provider_id) | ||
|
||
deps = dep_provider[DepsInfo].deps | ||
return java_info_for_deps(deps) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
load("@io_bazel_rules_scala//scala/toolchains:toolchains.bzl", "declare_deps_toolchain") | ||
load("@io_bazel_rules_scala//scala:providers.bzl", "declare_deps_provider") | ||
load("//scala/scalatest/toolchain:toolchain.bzl", "scalatest_toolchain_deps") | ||
|
||
toolchain_type( | ||
name = "scalatest_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "scalatest_toolchain", | ||
toolchain = ":scalatest_toolchain_impl", | ||
toolchain_type = ":scalatest_toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
declare_deps_provider( | ||
name = "scalatest_deps_provider", | ||
deps = [ | ||
"//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", | ||
"//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", | ||
], | ||
) | ||
|
||
declare_deps_toolchain( | ||
name = "scalatest_toolchain_impl", | ||
dep_providers = { | ||
":scalatest_deps_provider": "scalatest_classpath", | ||
}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
scalatest_toolchain_deps( | ||
name = "scalatest_classapth", | ||
provider_id = "scalatest_classpath", | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("//scala/private/toolchain_deps:toolchain_deps.bzl", "expose_toolchain_deps") | ||
|
||
toolchain_type_label = "@io_bazel_rules_scala//scala/scalatest/toolchain:scalatest_toolchain_type" | ||
|
||
def _scalatest_toolchain_deps(ctx): | ||
return expose_toolchain_deps(ctx, toolchain_type_label) | ||
|
||
scalatest_toolchain_deps = rule( | ||
toolchains = [toolchain_type_label], | ||
attrs = { | ||
"provider_id": attr.string( | ||
mandatory = True, | ||
), | ||
}, | ||
implementation = _scalatest_toolchain_deps, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
def scala_register_toolchains(): | ||
native.register_toolchains("@io_bazel_rules_scala//scala:default_toolchain") | ||
native.register_toolchains( | ||
"@io_bazel_rules_scala//scala:deps_toolchain", | ||
"@io_bazel_rules_scala//scala:default_toolchain", | ||
) | ||
|
||
def scala_register_unused_deps_toolchains(): | ||
native.register_toolchains( | ||
"@io_bazel_rules_scala//scala:deps_toolchain", | ||
"@io_bazel_rules_scala//scala:unused_dependency_checker_error_toolchain", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this for backwards compatibility? if so have you thought of how/when we should break it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's for backwards compatibility. To get rid of it we need to provide users with an alternative for binds (
*_repositories
without binds, toolchains, or something loader specific).