From 9aee74fe0e6753c576666cd26003fce326f8a70c Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Sun, 26 Jan 2020 21:47:55 -0800 Subject: [PATCH 01/37] wip --- BUILD.bazel | 0 multiscala/BUILD.bazel | 2 + multiscala/configuration.bzl | 130 ++++++++++++++++++ multiscala/configuration.bzl.tpl | 18 +++ multiscala/configure.bzl | 18 +++ multiscala/example/App.scala | 3 + multiscala/example/AppTest.scala | 9 ++ multiscala/example/BUILD.bazel | 49 +++++++ multiscala/example/WORKSPACE | 64 +++++++++ multiscala/example/repositories/BUILD.bazel | 0 .../example/repositories/bazel_skylib.bzl | 11 ++ .../repositories/rules_jvm_external.bzl | 10 ++ .../example/repositories/rules_scala.bzl | 5 + multiscala/example/repositories/tools.bzl | 20 +++ multiscala/multiscala.bzl | 14 ++ multiscala/repositories.bzl | 44 ++++++ multiscala/toolchains.bzl | 62 +++++++++ multiscala/tools.bzl | 7 + scala/BUILD | 14 +- src/java/io/bazel/rulesscala/scalac/BUILD | 2 +- 20 files changed, 474 insertions(+), 8 deletions(-) create mode 100644 BUILD.bazel create mode 100644 multiscala/BUILD.bazel create mode 100644 multiscala/configuration.bzl create mode 100644 multiscala/configuration.bzl.tpl create mode 100644 multiscala/configure.bzl create mode 100644 multiscala/example/App.scala create mode 100644 multiscala/example/AppTest.scala create mode 100644 multiscala/example/BUILD.bazel create mode 100644 multiscala/example/WORKSPACE create mode 100644 multiscala/example/repositories/BUILD.bazel create mode 100644 multiscala/example/repositories/bazel_skylib.bzl create mode 100644 multiscala/example/repositories/rules_jvm_external.bzl create mode 100644 multiscala/example/repositories/rules_scala.bzl create mode 100644 multiscala/example/repositories/tools.bzl create mode 100644 multiscala/multiscala.bzl create mode 100644 multiscala/repositories.bzl create mode 100644 multiscala/toolchains.bzl create mode 100644 multiscala/tools.bzl diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/multiscala/BUILD.bazel b/multiscala/BUILD.bazel new file mode 100644 index 000000000..3ea0cd023 --- /dev/null +++ b/multiscala/BUILD.bazel @@ -0,0 +1,2 @@ +load(":toolchains.bzl", "create_toolchains") +create_toolchains() diff --git a/multiscala/configuration.bzl b/multiscala/configuration.bzl new file mode 100644 index 000000000..1634bc24d --- /dev/null +++ b/multiscala/configuration.bzl @@ -0,0 +1,130 @@ +load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") +load("@bazel_skylib//lib:sets.bzl", _sets = "sets") + +default_configuration = { + "scala": { + "2.11": { + "minor": "12", + }, + }, + "scalatest": "3.0.5", + "scalactic": "3.0.5", + "scala-xml": "1.0.5", + "scala-parser-combinators": "1.0.4", + "repositories": [ + "https://jcenter.bintray.com/", + "https://maven.google.com", + "https://repo1.maven.org/maven2", + ], + "scala_bootstrap_toolchain": { + "scala_test_jvm_flags": [], + "scalac_jvm_flags": [], + "scalacopts": [], + }, + "scala_toolchain": { + "enable_code_coverage_aspect": "off", + "plus_one_deps_mode": "off", + "unused_dependency_checker_mode": "off", + }, + "compatability_labels": True, +} + + +def _repo_impl(ctx): + ctx.file( + "BUILD.bazel", + content = 'exports_files(["configuration.bzl"])', + executable = False, + ) + ctx.template( + "configuration.bzl", + ctx.attr._template, + substitutions = {"%{STARLARK_STRING}": ctx.attr.starlark_string}, + executable = False, + ) + +_repo = repository_rule( + implementation = _repo_impl, + attrs = { + "starlark_string": attr.string(mandatory = True), + "_template": attr.label( + default = ":configuration.bzl.tpl", + ), + }, +) + +def _merge_dicts(*dicts, exclude = None): + configuration = {} + + for input in dicts: + + keys = _sets.make(configuration.keys() + input.keys()) + + if exclude and _sets.contains(keys, exclude): + _sets.remove(keys, exclude) + + keys = _sets.to_list(keys) + + for key in keys: + if key in input: + field_type = type(input[key]) + if field_type == "string" or field_type == "list" or field_type == "bool": + configuration[key] = input[key] + elif field_type == "dict": + configuration[key] = _dicts.add( + configuration.get(key, {}), + input[key], + ) + else: + fail([key, field_type]) + else: + configuration[key] = configuration[key] + + return configuration + + +def multiscala_configuration(user_configuration = default_configuration): + configuration = _merge_dicts(default_configuration, user_configuration) + + if not "default" in configuration and len(configuration["scala"].keys()) == 1: + configuration = _dicts.add( + configuration, + {"default": configuration["scala"][configuration["scala"].keys()[0]] } + ) + + scala = {} + + for version in configuration["scala"].keys(): + scala[version] = _merge_dicts(configuration, configuration["scala"][version], exclude = "scala") + scala[version]["scala"] = version + scala[version]["mvn"] = version.replace(".", "_") + scala[version]["complete"] = version+"."+ scala[version]["minor"] + scala[version]["default"] = True if scala[version].get("default") == version else False + + configuration["scala"] = scala + + starlark_string = struct(**configuration).to_json() # .replace(":null,", ":None,") + + _repo( + name = "io_bazel_rules_scala_configuration", + starlark_string = starlark_string, + ) + +def multiscala_configure(configuration): + _maybe_register_default_toolchains(configuration) + +def _maybe_default(configuration): + return configuration["scala"][configuration["default"]] if "default" in configuration else None + +def toolchain_label(toolchain, version): + return "{toolchain}_{version}_toolchain".format(toolchain = toolchain, version = version["mvn"]) + +def _maybe_register_default_toolchains(configuration): + version = _maybe_default(configuration) + if version: + for toolchain in [ + # "bootstrap", + "scala", + # "scalatest" + ]: + native.register_toolchains("@io_bazel_rules_scala//multiscala:"+toolchain_label(toolchain, version)) diff --git a/multiscala/configuration.bzl.tpl b/multiscala/configuration.bzl.tpl new file mode 100644 index 000000000..9d1d1009b --- /dev/null +++ b/multiscala/configuration.bzl.tpl @@ -0,0 +1,18 @@ +# -*- mode: python -*- + +load("@io_bazel_rules_scala//multiscala:tools.bzl", _maven_install = "maven_install") +load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") + +def _from_json(): + # starlark vs json ... + + true = True + false = False + null = None + + return %{STARLARK_STRING} + +configuration = _from_json() + +def versions(): + return configuration["scala"].values() diff --git a/multiscala/configure.bzl b/multiscala/configure.bzl new file mode 100644 index 000000000..e3ce674ad --- /dev/null +++ b/multiscala/configure.bzl @@ -0,0 +1,18 @@ +load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration") +load("@io_bazel_rules_scala//multiscala:toolchains.bzl", _toolchain_label = "toolchain_label") + +def multiscala_configure(): + _maybe_register_default_toolchains() + +def _maybe_default(): + return _configuration["scala"][_configuration["default"]] if "default" in _configuration else None + +def _maybe_register_default_toolchains(): + version = _maybe_default() + if version: + for toolchain in [ + # "bootstrap", + "scala", + # "scalatest" + ]: + native.register_toolchains("@io_bazel_rules_scala//multiscala:"+_toolchain_label(toolchain, version)) diff --git a/multiscala/example/App.scala b/multiscala/example/App.scala new file mode 100644 index 000000000..c53463be0 --- /dev/null +++ b/multiscala/example/App.scala @@ -0,0 +1,3 @@ +object App extends scala.App { + println(s"hello, world from ${scala.util.Properties.versionString}!") +} diff --git a/multiscala/example/AppTest.scala b/multiscala/example/AppTest.scala new file mode 100644 index 000000000..27bb7c3ec --- /dev/null +++ b/multiscala/example/AppTest.scala @@ -0,0 +1,9 @@ +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class AppTest extends AnyFlatSpec with Matchers { + it should "have a successful test" in { + System.err.println(s"hello, world from ${scala.util.Properties.versionString}!") + true should be (true) + } +} diff --git a/multiscala/example/BUILD.bazel b/multiscala/example/BUILD.bazel new file mode 100644 index 000000000..fb77308ce --- /dev/null +++ b/multiscala/example/BUILD.bazel @@ -0,0 +1,49 @@ +load( + "@io_bazel_rules_scala//multiscala:multiscala.bzl", + _scala_binary = "scala_binary", + _scala_library = "scala_library", + _scala_test = "scala_test" +) + +_scala_library( + name = "library", + srcs = ["App.scala"], +) + +_scala_binary( + name = "app", + main_class = "App", + runtime_deps = [":library"], +) + +_scala_test( + name = "test", + srcs = ["AppTest.scala"], +) + +# # static example ... manaully specify toolchains. Will fail if requested toolchain is not configured. + +# scala_library( +# name = "library-static", +# srcs = ["App.scala"], +# toolchains = [scala_toolchain("2.12")], +# ) + +# java_binary( +# name = "app-static", +# main_class = "App", +# runtime_deps = [":library"], +# ) + +# scala_test( +# name = "test-static", +# srcs = ["AppTest.scala"], +# toolchains = [ +# scala_toolchain("2.12"), +# scalatest_toolchain("2.12"), +# ], +# ) + +# # dynamic examples: generated in BUILD.bzl + +# build() diff --git a/multiscala/example/WORKSPACE b/multiscala/example/WORKSPACE new file mode 100644 index 000000000..9c4d741e7 --- /dev/null +++ b/multiscala/example/WORKSPACE @@ -0,0 +1,64 @@ +load("//repositories:bazel_skylib.bzl", "load_bazel_skylib") +load_bazel_skylib() + +load("//repositories:rules_jvm_external.bzl", "load_rules_jvm_external") +load_rules_jvm_external() + +load("//repositories:rules_scala.bzl", "load_rules_scala") +load_rules_scala() + +load( + "@io_bazel_rules_scala//multiscala:configuration.bzl", + "multiscala_configuration", + "multiscala_configure" +) + +multiscala_configuration({ + "scala": { + "2.11": { + "minor": "12", + }, + "2.12": { + "minor": "10", + }, + "2.13": { + "minor": "1", + "scala_bootstrap_toolchain": { + "scalacopts": [ + "-deprecation:true", + "-encoding", + "UTF-8", + "-feature", + "-unchecked", + "-Xfatal-warnings", + "-Xsource:2.13", + ], + }, + }, + }, + "default": "2.12", + "scalatest": "3.1.0", + "scala-xml": "1.2.0", + "scala-parser-combinators": "1.1.2", + "scala_bootstrap_toolchain": { + "scalacopts": [ + "-deprecation:true", + "-encoding", + "UTF-8", + "-feature", + "-unchecked", + "-Xfatal-warnings", + "-Xfuture", + "-Xsource:2.12", + "-Ypartial-unification", + ], + }, + "scala_toolchain": { + "unused_dependency_checker_mode": "error", + }, +}) + +load("@io_bazel_rules_scala//multiscala:repositories.bzl", "create_repositories") +create_repositories() +load("@io_bazel_rules_scala//multiscala:configure.bzl", "multiscala_configure") +multiscala_configure() diff --git a/multiscala/example/repositories/BUILD.bazel b/multiscala/example/repositories/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/multiscala/example/repositories/bazel_skylib.bzl b/multiscala/example/repositories/bazel_skylib.bzl new file mode 100644 index 000000000..d0a8f9af0 --- /dev/null +++ b/multiscala/example/repositories/bazel_skylib.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load(":tools.bzl", _github_release = "github_release") + +def load_bazel_skylib(): + _github_release( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + repository = "bazelbuild/bazel-skylib", + release = "1.0.2", + + ) diff --git a/multiscala/example/repositories/rules_jvm_external.bzl b/multiscala/example/repositories/rules_jvm_external.bzl new file mode 100644 index 000000000..8f976e213 --- /dev/null +++ b/multiscala/example/repositories/rules_jvm_external.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_jvm_external(): + _github_archive( + name = "rules_jvm_external", + repository = "bazelbuild/rules_jvm_external", + sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", + tag = "3.0", + ) diff --git a/multiscala/example/repositories/rules_scala.bzl b/multiscala/example/repositories/rules_scala.bzl new file mode 100644 index 000000000..35e3c292a --- /dev/null +++ b/multiscala/example/repositories/rules_scala.bzl @@ -0,0 +1,5 @@ +def load_rules_scala(): + native.local_repository( + name = "io_bazel_rules_scala", + path = "../..", + ) diff --git a/multiscala/example/repositories/tools.bzl b/multiscala/example/repositories/tools.bzl new file mode 100644 index 000000000..41e97a6ee --- /dev/null +++ b/multiscala/example/repositories/tools.bzl @@ -0,0 +1,20 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def github_release(name, repository, release, sha256): + http_archive( + name = name, + sha256 = sha256, + urls = [ + "https://github.com/{repository}/releases/download/{release}/{repository}-{release}.tar.gz".format(repository = repository, release = release), + ], + ) + +def github_archive(name, repository, sha256, tag): + http_archive( + name = name, + sha256 = sha256, + strip_prefix = "{name}-{tag}".format(name = name, tag = tag), + urls = [ + "https://github.com/{repository}/archive/{tag}.zip".format(repository = repository, tag = tag), + ], + ) diff --git a/multiscala/multiscala.bzl b/multiscala/multiscala.bzl new file mode 100644 index 000000000..23ff24ab6 --- /dev/null +++ b/multiscala/multiscala.bzl @@ -0,0 +1,14 @@ +load("//scala:scala.bzl", + _scala_binary = "scala_binary", + _scala_library = "scala_library", + _scala_test = "scala_test", +) + +def scala_binary(**kwargs): + _scala_binary(**kwargs) + +def scala_library(**kwargs): + _scala_library(**kwargs) + +def scala_test(**kwargs): + _scala_test(**kwargs) diff --git a/multiscala/repositories.bzl b/multiscala/repositories.bzl new file mode 100644 index 000000000..6114f667d --- /dev/null +++ b/multiscala/repositories.bzl @@ -0,0 +1,44 @@ +load(":tools.bzl", _maven_install = "maven_install") +load("@io_bazel_rules_scala_configuration//:configuration.bzl", _versions = "versions") +load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") + +def create_repositories(): + for version in _versions(): + repository_name = "io_bazel_rules_scala_" + version["mvn"] + _maven_install( + name = repository_name, + artifacts = [ + "org.scala-lang:scala-compiler:" + version["complete"], + "org.scala-lang:scala-library:" + version["complete"], + "org.scala-lang:scala-reflect:" + version["complete"], + ], + repositories = version["repositories"], + ) + if version["compatability_labels"]: + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_library", + actual = _artifact("org.scala-lang:scala-library", repository_name = repository_name) + ) + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_compiler", + actual = _artifact("org.scala-lang:scala-compiler", repository_name = repository_name) + ) + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_reflect", + actual = _artifact("org.scala-lang:scala-reflect", repository_name = repository_name) + ) + + if version["default"] and version["compatability_labels"]: + pass + _maven_install( + name = "io_bazel_rules_scala_scalac", + artifacts = [ + "commons-io:commons-io:2.6" + ], + repositories = version["repositories"], + ) + if version["compatability_labels"]: + native.bind( + name = "io_bazel_rules_scala/dependency/scalac_rules_commons_io", + actual = _artifact("commons-io:commons-io", repository_name = "io_bazel_rules_scala_scalac") + ) diff --git a/multiscala/toolchains.bzl b/multiscala/toolchains.bzl new file mode 100644 index 000000000..4a3346e03 --- /dev/null +++ b/multiscala/toolchains.bzl @@ -0,0 +1,62 @@ +load("@io_bazel_rules_scala_configuration//:configuration.bzl", + _versions = "versions" +) +load( + "@io_bazel_rules_scala//scala:scala_toolchain.bzl", + _scala_toolchain_rule = "scala_toolchain", +) +load( + "@io_bazel_rules_scala//scala:providers.bzl", + _ScalacProvider = "ScalacProvider", +) +load( + ":configuration.bzl", + _toolchain_label = "toolchain_label", +) + +def toolchain_label(toolchain, version): + return "{toolchain}_{version}_toolchain".format(toolchain = toolchain, version = version["mvn"]) + +def create_toolchains(): + _create_all_toolchains() + +def _create_all_toolchains(): + for version in _versions(): + _create_version_toolchains(version) + +def _create_version_toolchains(version): + _create_bootstrap_toolchain(version) + _create_scala_toolchain(version) + _create_scalatest_toolchain(version) + +def _create_bootstrap_toolchain(version): + pass + +_scala_toolchain_attrs = [ + "scalacopts", + "scalac_provider_attr", + "unused_dependency_checker_mode", + "plus_one_deps_mode", + "enable_code_coverage_aspect", + "scalac_jvm_flags", + "scala_test_jvm_flags", +] + +def _create_scala_toolchain(version): + impl_name = _toolchain_label("scala", version) + "_impl" + attrs = {} + for attr in _scala_toolchain_attrs: + if attr in version["scala_toolchain"]: + attrs[attr] = version["scala_toolchain"][attr] + attrs["name"] = impl_name + _scala_toolchain_rule(**attrs) + + native.toolchain( + name = _toolchain_label("scala", version), + toolchain = impl_name, + toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", + visibility = ["//visibility:public"], + ) + +def _create_scalatest_toolchain(version): + pass diff --git a/multiscala/tools.bzl b/multiscala/tools.bzl new file mode 100644 index 000000000..2bcc8d9df --- /dev/null +++ b/multiscala/tools.bzl @@ -0,0 +1,7 @@ +load("@rules_jvm_external//:defs.bzl", _maven_install = "maven_install") + +def maven_install(**kwargs): + _maven_install(**kwargs) + +def scala_maven_install(): + fail() diff --git a/scala/BUILD b/scala/BUILD index a5c8f2416..7641b0eae 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -44,17 +44,17 @@ java_import( _declare_scalac_provider( name = "scalac_default", default_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], default_macro_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], default_repl_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", - "@io_bazel_rules_scala_scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", ], visibility = ["//visibility:public"], ) diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index d80b8152f..20bac9114 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -23,7 +23,7 @@ java_binary( "@io_bazel_rules_scala//src/java/com/google/devtools/build/lib:worker", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/jar", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/worker", - "@scalac_rules_commons_io//jar", + "//external:io_bazel_rules_scala/dependency/scalac_rules_commons_io", ], ) From c1e5f88aaa9438b913419f4c024fd93b0eb3bc88 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 08:31:34 -0800 Subject: [PATCH 02/37] typo --- multiscala/example/repositories/tools.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/multiscala/example/repositories/tools.bzl b/multiscala/example/repositories/tools.bzl index 41e97a6ee..d0894efa6 100644 --- a/multiscala/example/repositories/tools.bzl +++ b/multiscala/example/repositories/tools.bzl @@ -1,11 +1,12 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def github_release(name, repository, release, sha256): + (org, repo) = repository.split("/") http_archive( name = name, sha256 = sha256, urls = [ - "https://github.com/{repository}/releases/download/{release}/{repository}-{release}.tar.gz".format(repository = repository, release = release), + "https://github.com/{repository}/releases/download/{release}/{repo}-{release}.tar.gz".format(repository = repository, repo = repo, release = release), ], ) From 5cccebc87b772593aa4a6c765594c8a940e9cc7a Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 09:14:04 -0800 Subject: [PATCH 03/37] wip --- multiscala/repositories.bzl | 91 ++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/multiscala/repositories.bzl b/multiscala/repositories.bzl index 6114f667d..399d5269f 100644 --- a/multiscala/repositories.bzl +++ b/multiscala/repositories.bzl @@ -1,44 +1,73 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load(":tools.bzl", _maven_install = "maven_install") -load("@io_bazel_rules_scala_configuration//:configuration.bzl", _versions = "versions") +load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration", _versions = "versions") load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") +def _github_archive(name, repository, sha256, tag): + (org, repo) = repository.split("/") + without_v = tag[1:] if tag.startswith("v") else tag + http_archive( + name = name, + sha256 = sha256, + strip_prefix = "{repo}-{without_v}".format(repo = repo, without_v = without_v), + urls = [ + "https://github.com/{repository}/archive/{tag}.zip".format(repository = repository, tag = tag), + ], + ) + +def _maven_install_artifacts(artifacts): + return artifacts.keys() + +def _bind_default_labels(repository_name, artifacts): + for artifact in artifacts.items(): + (mvn, label) = artifact + without_version = ":".join(mvn.split(":")[0:2]) + native.bind( + name = label, + actual = _artifact(without_version, repository_name = repository_name) + ) + def create_repositories(): + _create_protobuf() + _create_maven_installed_repos() + +def _create_protobuf(): + _github_archive( + name = "com_google_protobuf", + sha256 = "", + repository = "protocolbuffers/protobuf", + tag = "v3.11.2", + ) + if _configuration["compatability_labels"]: + native.bind( + name = "io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", + actual = "@com_google_protobuf//:protobuf_java", + ) + +def _create_maven_installed_repos(): for version in _versions(): repository_name = "io_bazel_rules_scala_" + version["mvn"] + artifacts = { + "org.scala-lang:scala-compiler:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_compiler", + "org.scala-lang:scala-library:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_library", + "org.scala-lang:scala-reflect:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_reflect", + } + _maven_install( name = repository_name, - artifacts = [ - "org.scala-lang:scala-compiler:" + version["complete"], - "org.scala-lang:scala-library:" + version["complete"], - "org.scala-lang:scala-reflect:" + version["complete"], - ], + artifacts = _maven_install_artifacts(artifacts), repositories = version["repositories"], ) - if version["compatability_labels"]: - native.bind( - name = "io_bazel_rules_scala/dependency/scala/scala_library", - actual = _artifact("org.scala-lang:scala-library", repository_name = repository_name) - ) - native.bind( - name = "io_bazel_rules_scala/dependency/scala/scala_compiler", - actual = _artifact("org.scala-lang:scala-compiler", repository_name = repository_name) - ) - native.bind( - name = "io_bazel_rules_scala/dependency/scala/scala_reflect", - actual = _artifact("org.scala-lang:scala-reflect", repository_name = repository_name) - ) - - if version["default"] and version["compatability_labels"]: - pass + + if version["default"] and version["compatability_labels"]: _bind_default_labels(repository_name, artifacts) + + java_artifacts = { + "commons-io:commons-io:2.6": "io_bazel_rules_scala/dependency/scalac_rules_commons_io", + } + _maven_install( name = "io_bazel_rules_scala_scalac", - artifacts = [ - "commons-io:commons-io:2.6" - ], - repositories = version["repositories"], + artifacts = _maven_install_artifacts(java_artifacts), + repositories = _configuration["repositories"], ) - if version["compatability_labels"]: - native.bind( - name = "io_bazel_rules_scala/dependency/scalac_rules_commons_io", - actual = _artifact("commons-io:commons-io", repository_name = "io_bazel_rules_scala_scalac") - ) + if _configuration["compatability_labels"]: _bind_default_labels("io_bazel_rules_scala_scalac", java_artifacts) From f0d27d8addaf4451749ea599229cdd49d1ddf281 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 11:09:06 -0800 Subject: [PATCH 04/37] wip --- multiscala/example/WORKSPACE | 6 ++++ .../repositories/rules_jvm_external.bzl | 1 - .../example/repositories/rules_proto.bzl | 9 +++++ .../example/repositories/rules_python.bzl | 9 +++++ multiscala/example/repositories/tools.bzl | 4 ++- multiscala/repositories.bzl | 36 +++++++++++++++++-- scala/scalatest/BUILD | 4 +-- 7 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 multiscala/example/repositories/rules_proto.bzl create mode 100644 multiscala/example/repositories/rules_python.bzl diff --git a/multiscala/example/WORKSPACE b/multiscala/example/WORKSPACE index 9c4d741e7..8e8a5afd0 100644 --- a/multiscala/example/WORKSPACE +++ b/multiscala/example/WORKSPACE @@ -7,6 +7,12 @@ load_rules_jvm_external() load("//repositories:rules_scala.bzl", "load_rules_scala") load_rules_scala() +load("//repositories:rules_proto.bzl", "load_rules_proto") +load_rules_proto() + +load("//repositories:rules_python.bzl", "load_rules_python") +load_rules_python() + load( "@io_bazel_rules_scala//multiscala:configuration.bzl", "multiscala_configuration", diff --git a/multiscala/example/repositories/rules_jvm_external.bzl b/multiscala/example/repositories/rules_jvm_external.bzl index 8f976e213..664236949 100644 --- a/multiscala/example/repositories/rules_jvm_external.bzl +++ b/multiscala/example/repositories/rules_jvm_external.bzl @@ -1,4 +1,3 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load(":tools.bzl", _github_archive = "github_archive") def load_rules_jvm_external(): diff --git a/multiscala/example/repositories/rules_proto.bzl b/multiscala/example/repositories/rules_proto.bzl new file mode 100644 index 000000000..61149bd82 --- /dev/null +++ b/multiscala/example/repositories/rules_proto.bzl @@ -0,0 +1,9 @@ +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_proto(): + _github_archive( + name = "rules_proto", + repository = "bazelbuild/rules_proto", + sha256 = "62847ac7740865d73a2c8199be292bba913d62e79084442f3e829c3058a25e64", + tag = "d7666ec475c1f8d4a6803cbc0a0b6b4374360868", + ) diff --git a/multiscala/example/repositories/rules_python.bzl b/multiscala/example/repositories/rules_python.bzl new file mode 100644 index 000000000..e0910e5a8 --- /dev/null +++ b/multiscala/example/repositories/rules_python.bzl @@ -0,0 +1,9 @@ +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_python(): + _github_archive( + name = "rules_python", + repository = "bazelbuild/rules_python", + sha256 = "7d64815f4b22400bed0f1b9da663037e1578573446b7bc78f20f24b2b5459bb9", + tag = "38f86fb55b698c51e8510c807489c9f4e047480e", + ) diff --git a/multiscala/example/repositories/tools.bzl b/multiscala/example/repositories/tools.bzl index d0894efa6..ecbf3a0d7 100644 --- a/multiscala/example/repositories/tools.bzl +++ b/multiscala/example/repositories/tools.bzl @@ -11,10 +11,12 @@ def github_release(name, repository, release, sha256): ) def github_archive(name, repository, sha256, tag): + (org, repo) = repository.split("/") + without_v = tag[1:] if tag.startswith("v") else tag http_archive( name = name, sha256 = sha256, - strip_prefix = "{name}-{tag}".format(name = name, tag = tag), + strip_prefix = "{repo}-{without_v}".format(repo = repo, without_v = without_v), urls = [ "https://github.com/{repository}/archive/{tag}.zip".format(repository = repository, tag = tag), ], diff --git a/multiscala/repositories.bzl b/multiscala/repositories.bzl index 399d5269f..c0b1f039a 100644 --- a/multiscala/repositories.bzl +++ b/multiscala/repositories.bzl @@ -1,4 +1,4 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") load(":tools.bzl", _maven_install = "maven_install") load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration", _versions = "versions") load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") @@ -6,7 +6,7 @@ load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") def _github_archive(name, repository, sha256, tag): (org, repo) = repository.split("/") without_v = tag[1:] if tag.startswith("v") else tag - http_archive( + _http_archive( name = name, sha256 = sha256, strip_prefix = "{repo}-{without_v}".format(repo = repo, without_v = without_v), @@ -34,23 +34,46 @@ def create_repositories(): def _create_protobuf(): _github_archive( name = "com_google_protobuf", - sha256 = "", + sha256 = "e4f8bedb19a93d0dccc359a126f51158282e0b24d92e0cad9c76a9699698268d", repository = "protocolbuffers/protobuf", tag = "v3.11.2", ) + + # N.B.: could use protobuf/protobuf_deps.bzl + + _http_archive( + name = "zlib", + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff", + strip_prefix = "zlib-1.2.11", + urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"], + ) + if _configuration["compatability_labels"]: native.bind( name = "io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", actual = "@com_google_protobuf//:protobuf_java", ) +def _scala_artifact(version, scala_coordinate): + components = scala_coordinate.split(":") + if len(components) == 2: + components.append("{" + components[1] + "}") + (org, artifact, artifact_version) = components + java_coordinate = ":".join([org, artifact + "_" + version["scala"], artifact_version]) + return java_coordinate.format(**version) + def _create_maven_installed_repos(): for version in _versions(): repository_name = "io_bazel_rules_scala_" + version["mvn"] + artifacts = { "org.scala-lang:scala-compiler:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_compiler", "org.scala-lang:scala-library:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_library", "org.scala-lang:scala-reflect:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_reflect", + _scala_artifact(version, "org.scala-lang.modules:scala-xml"): "io_bazel_rules_scala/dependency/scala/scala_xml", + _scala_artifact(version, "org.scalatest:scalatest"): "io_bazel_rules_scala/dependency/scala/scalatest/scalatest", + _scala_artifact(version, "org.scalactic:scalactic"): "io_bazel_rules_scala/dependency/scala/scalactic/scalactic", } _maven_install( @@ -61,8 +84,15 @@ def _create_maven_installed_repos(): if version["default"] and version["compatability_labels"]: _bind_default_labels(repository_name, artifacts) + if version["default"] and version["compatability_labels"]: + native.bind( + name = "io_bazel_rules_scala/dependency/scalatest/scalatest", + actual = "@io_bazel_rules_scala//scala/scalatest:scalatest", + ) + java_artifacts = { "commons-io:commons-io:2.6": "io_bazel_rules_scala/dependency/scalac_rules_commons_io", + "com.google.guava:guava:21.0": "io_bazel_rules_scala/dependency/scala/guava", } _maven_install( diff --git a/scala/scalatest/BUILD b/scala/scalatest/BUILD index 2e4ad67bb..197d66180 100644 --- a/scala/scalatest/BUILD +++ b/scala/scalatest/BUILD @@ -6,7 +6,7 @@ scala_import( name = "scalatest", jars = [], exports = [ - "@io_bazel_rules_scala_scalactic", - "@io_bazel_rules_scala_scalatest", + "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", + "//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", ], ) From 8432103ce6fc5426ee9b6fc4fb1601b8b18a3e28 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 11:28:36 -0800 Subject: [PATCH 05/37] wip --- scala/private/macros/scala_repositories.bzl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scala/private/macros/scala_repositories.bzl b/scala/private/macros/scala_repositories.bzl index ff8017f37..fc8b0f651 100644 --- a/scala/private/macros/scala_repositories.bzl +++ b/scala/private/macros/scala_repositories.bzl @@ -198,3 +198,18 @@ def scala_repositories( name = "io_bazel_rules_scala/dependency/scala/guava", actual = "@io_bazel_rules_scala_guava", ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scalac_rules_commons_io", + actual = "@scalac_rules_commons_io", + ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scalatest/scalatest", + actual = "@io_bazel_rules_scala_scalatest", + ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scalactic/scalactic", + actual = "@io_bazel_rules_scala_scalactic", + ) From fe39370479c06bca6343e53d2086f1d71b8a6a77 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 11:57:25 -0800 Subject: [PATCH 06/37] "unstable" --- multiscala/example/BUILD.bazel | 49 ------------------- .../multiscala}/BUILD.bazel | 0 .../multiscala}/configuration.bzl | 2 +- .../multiscala}/configuration.bzl.tpl | 2 +- .../multiscala}/configure.bzl | 4 +- .../multiscala}/multiscala.bzl | 0 .../multiscala/private}/example/App.scala | 0 .../multiscala/private}/example/AppTest.scala | 0 .../multiscala/private/example/BUILD.bazel | 22 +++++++++ .../multiscala/private}/example/WORKSPACE | 6 +-- .../private}/example/repositories/BUILD.bazel | 0 .../example/repositories/bazel_skylib.bzl | 0 .../repositories/rules_jvm_external.bzl | 0 .../example/repositories/rules_proto.bzl | 0 .../example/repositories/rules_python.bzl | 0 .../example/repositories/rules_scala.bzl | 2 +- .../private}/example/repositories/tools.bzl | 0 .../multiscala}/repositories.bzl | 0 .../multiscala}/toolchains.bzl | 0 {multiscala => unstable/multiscala}/tools.bzl | 0 20 files changed, 30 insertions(+), 57 deletions(-) delete mode 100644 multiscala/example/BUILD.bazel rename {multiscala => unstable/multiscala}/BUILD.bazel (100%) rename {multiscala => unstable/multiscala}/configuration.bzl (97%) rename {multiscala => unstable/multiscala}/configuration.bzl.tpl (76%) rename {multiscala => unstable/multiscala}/configure.bzl (69%) rename {multiscala => unstable/multiscala}/multiscala.bzl (100%) rename {multiscala => unstable/multiscala/private}/example/App.scala (100%) rename {multiscala => unstable/multiscala/private}/example/AppTest.scala (100%) create mode 100644 unstable/multiscala/private/example/BUILD.bazel rename {multiscala => unstable/multiscala/private}/example/WORKSPACE (86%) rename {multiscala => unstable/multiscala/private}/example/repositories/BUILD.bazel (100%) rename {multiscala => unstable/multiscala/private}/example/repositories/bazel_skylib.bzl (100%) rename {multiscala => unstable/multiscala/private}/example/repositories/rules_jvm_external.bzl (100%) rename {multiscala => unstable/multiscala/private}/example/repositories/rules_proto.bzl (100%) rename {multiscala => unstable/multiscala/private}/example/repositories/rules_python.bzl (100%) rename {multiscala => unstable/multiscala/private}/example/repositories/rules_scala.bzl (76%) rename {multiscala => unstable/multiscala/private}/example/repositories/tools.bzl (100%) rename {multiscala => unstable/multiscala}/repositories.bzl (100%) rename {multiscala => unstable/multiscala}/toolchains.bzl (100%) rename {multiscala => unstable/multiscala}/tools.bzl (100%) diff --git a/multiscala/example/BUILD.bazel b/multiscala/example/BUILD.bazel deleted file mode 100644 index fb77308ce..000000000 --- a/multiscala/example/BUILD.bazel +++ /dev/null @@ -1,49 +0,0 @@ -load( - "@io_bazel_rules_scala//multiscala:multiscala.bzl", - _scala_binary = "scala_binary", - _scala_library = "scala_library", - _scala_test = "scala_test" -) - -_scala_library( - name = "library", - srcs = ["App.scala"], -) - -_scala_binary( - name = "app", - main_class = "App", - runtime_deps = [":library"], -) - -_scala_test( - name = "test", - srcs = ["AppTest.scala"], -) - -# # static example ... manaully specify toolchains. Will fail if requested toolchain is not configured. - -# scala_library( -# name = "library-static", -# srcs = ["App.scala"], -# toolchains = [scala_toolchain("2.12")], -# ) - -# java_binary( -# name = "app-static", -# main_class = "App", -# runtime_deps = [":library"], -# ) - -# scala_test( -# name = "test-static", -# srcs = ["AppTest.scala"], -# toolchains = [ -# scala_toolchain("2.12"), -# scalatest_toolchain("2.12"), -# ], -# ) - -# # dynamic examples: generated in BUILD.bzl - -# build() diff --git a/multiscala/BUILD.bazel b/unstable/multiscala/BUILD.bazel similarity index 100% rename from multiscala/BUILD.bazel rename to unstable/multiscala/BUILD.bazel diff --git a/multiscala/configuration.bzl b/unstable/multiscala/configuration.bzl similarity index 97% rename from multiscala/configuration.bzl rename to unstable/multiscala/configuration.bzl index 1634bc24d..dc844bc82 100644 --- a/multiscala/configuration.bzl +++ b/unstable/multiscala/configuration.bzl @@ -127,4 +127,4 @@ def _maybe_register_default_toolchains(configuration): "scala", # "scalatest" ]: - native.register_toolchains("@io_bazel_rules_scala//multiscala:"+toolchain_label(toolchain, version)) + native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:"+toolchain_label(toolchain, version)) diff --git a/multiscala/configuration.bzl.tpl b/unstable/multiscala/configuration.bzl.tpl similarity index 76% rename from multiscala/configuration.bzl.tpl rename to unstable/multiscala/configuration.bzl.tpl index 9d1d1009b..375c08247 100644 --- a/multiscala/configuration.bzl.tpl +++ b/unstable/multiscala/configuration.bzl.tpl @@ -1,6 +1,6 @@ # -*- mode: python -*- -load("@io_bazel_rules_scala//multiscala:tools.bzl", _maven_install = "maven_install") +load("@io_bazel_rules_scala//unstable/multiscala:tools.bzl", _maven_install = "maven_install") load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") def _from_json(): diff --git a/multiscala/configure.bzl b/unstable/multiscala/configure.bzl similarity index 69% rename from multiscala/configure.bzl rename to unstable/multiscala/configure.bzl index e3ce674ad..213e9061a 100644 --- a/multiscala/configure.bzl +++ b/unstable/multiscala/configure.bzl @@ -1,5 +1,5 @@ load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration") -load("@io_bazel_rules_scala//multiscala:toolchains.bzl", _toolchain_label = "toolchain_label") +load("@io_bazel_rules_scala//unstable/multiscala:toolchains.bzl", _toolchain_label = "toolchain_label") def multiscala_configure(): _maybe_register_default_toolchains() @@ -15,4 +15,4 @@ def _maybe_register_default_toolchains(): "scala", # "scalatest" ]: - native.register_toolchains("@io_bazel_rules_scala//multiscala:"+_toolchain_label(toolchain, version)) + native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:"+_toolchain_label(toolchain, version)) diff --git a/multiscala/multiscala.bzl b/unstable/multiscala/multiscala.bzl similarity index 100% rename from multiscala/multiscala.bzl rename to unstable/multiscala/multiscala.bzl diff --git a/multiscala/example/App.scala b/unstable/multiscala/private/example/App.scala similarity index 100% rename from multiscala/example/App.scala rename to unstable/multiscala/private/example/App.scala diff --git a/multiscala/example/AppTest.scala b/unstable/multiscala/private/example/AppTest.scala similarity index 100% rename from multiscala/example/AppTest.scala rename to unstable/multiscala/private/example/AppTest.scala diff --git a/unstable/multiscala/private/example/BUILD.bazel b/unstable/multiscala/private/example/BUILD.bazel new file mode 100644 index 000000000..d27a88a82 --- /dev/null +++ b/unstable/multiscala/private/example/BUILD.bazel @@ -0,0 +1,22 @@ +load( + "@io_bazel_rules_scala//unstable/multiscala:multiscala.bzl", + _scala_binary = "scala_binary", + _scala_library = "scala_library", + _scala_test = "scala_test" +) + +_scala_library( + name = "library", + srcs = ["App.scala"], +) + +_scala_binary( + name = "app", + main_class = "App", + runtime_deps = [":library"], +) + +_scala_test( + name = "test", + srcs = ["AppTest.scala"], +) diff --git a/multiscala/example/WORKSPACE b/unstable/multiscala/private/example/WORKSPACE similarity index 86% rename from multiscala/example/WORKSPACE rename to unstable/multiscala/private/example/WORKSPACE index 8e8a5afd0..5537260a2 100644 --- a/multiscala/example/WORKSPACE +++ b/unstable/multiscala/private/example/WORKSPACE @@ -14,7 +14,7 @@ load("//repositories:rules_python.bzl", "load_rules_python") load_rules_python() load( - "@io_bazel_rules_scala//multiscala:configuration.bzl", + "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", "multiscala_configuration", "multiscala_configure" ) @@ -64,7 +64,7 @@ multiscala_configuration({ }, }) -load("@io_bazel_rules_scala//multiscala:repositories.bzl", "create_repositories") +load("@io_bazel_rules_scala//unstable/multiscala:repositories.bzl", "create_repositories") create_repositories() -load("@io_bazel_rules_scala//multiscala:configure.bzl", "multiscala_configure") +load("@io_bazel_rules_scala//unstable/multiscala:configure.bzl", "multiscala_configure") multiscala_configure() diff --git a/multiscala/example/repositories/BUILD.bazel b/unstable/multiscala/private/example/repositories/BUILD.bazel similarity index 100% rename from multiscala/example/repositories/BUILD.bazel rename to unstable/multiscala/private/example/repositories/BUILD.bazel diff --git a/multiscala/example/repositories/bazel_skylib.bzl b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl similarity index 100% rename from multiscala/example/repositories/bazel_skylib.bzl rename to unstable/multiscala/private/example/repositories/bazel_skylib.bzl diff --git a/multiscala/example/repositories/rules_jvm_external.bzl b/unstable/multiscala/private/example/repositories/rules_jvm_external.bzl similarity index 100% rename from multiscala/example/repositories/rules_jvm_external.bzl rename to unstable/multiscala/private/example/repositories/rules_jvm_external.bzl diff --git a/multiscala/example/repositories/rules_proto.bzl b/unstable/multiscala/private/example/repositories/rules_proto.bzl similarity index 100% rename from multiscala/example/repositories/rules_proto.bzl rename to unstable/multiscala/private/example/repositories/rules_proto.bzl diff --git a/multiscala/example/repositories/rules_python.bzl b/unstable/multiscala/private/example/repositories/rules_python.bzl similarity index 100% rename from multiscala/example/repositories/rules_python.bzl rename to unstable/multiscala/private/example/repositories/rules_python.bzl diff --git a/multiscala/example/repositories/rules_scala.bzl b/unstable/multiscala/private/example/repositories/rules_scala.bzl similarity index 76% rename from multiscala/example/repositories/rules_scala.bzl rename to unstable/multiscala/private/example/repositories/rules_scala.bzl index 35e3c292a..6fdd108a7 100644 --- a/multiscala/example/repositories/rules_scala.bzl +++ b/unstable/multiscala/private/example/repositories/rules_scala.bzl @@ -1,5 +1,5 @@ def load_rules_scala(): native.local_repository( name = "io_bazel_rules_scala", - path = "../..", + path = "../../../..", ) diff --git a/multiscala/example/repositories/tools.bzl b/unstable/multiscala/private/example/repositories/tools.bzl similarity index 100% rename from multiscala/example/repositories/tools.bzl rename to unstable/multiscala/private/example/repositories/tools.bzl diff --git a/multiscala/repositories.bzl b/unstable/multiscala/repositories.bzl similarity index 100% rename from multiscala/repositories.bzl rename to unstable/multiscala/repositories.bzl diff --git a/multiscala/toolchains.bzl b/unstable/multiscala/toolchains.bzl similarity index 100% rename from multiscala/toolchains.bzl rename to unstable/multiscala/toolchains.bzl diff --git a/multiscala/tools.bzl b/unstable/multiscala/tools.bzl similarity index 100% rename from multiscala/tools.bzl rename to unstable/multiscala/tools.bzl From 0ef707a7f7cc0f4a9ba53d063a2f278536853f8e Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 13:30:40 -0800 Subject: [PATCH 07/37] buildifier --- scala/scalatest/BUILD | 2 +- src/java/io/bazel/rulesscala/scalac/BUILD | 2 +- unstable/multiscala/BUILD.bazel | 1 + unstable/multiscala/configuration.bzl | 17 +++++++---------- unstable/multiscala/configure.bzl | 8 ++++---- unstable/multiscala/multiscala.bzl | 9 +++++---- unstable/multiscala/private/example/BUILD.bazel | 2 +- unstable/multiscala/private/example/WORKSPACE | 10 +++++++++- .../example/repositories/bazel_skylib.bzl | 1 - unstable/multiscala/repositories.bzl | 12 +++++++----- unstable/multiscala/toolchains.bzl | 5 +++-- 11 files changed, 39 insertions(+), 30 deletions(-) diff --git a/scala/scalatest/BUILD b/scala/scalatest/BUILD index 197d66180..4e7439e96 100644 --- a/scala/scalatest/BUILD +++ b/scala/scalatest/BUILD @@ -6,7 +6,7 @@ scala_import( name = "scalatest", jars = [], exports = [ - "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", "//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", + "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", ], ) diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index 20bac9114..575dd9504 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -20,10 +20,10 @@ java_binary( visibility = ["//visibility:public"], deps = [ ":exported_scalac_repositories_from_toolchain_to_jvm", + "//external:io_bazel_rules_scala/dependency/scalac_rules_commons_io", "@io_bazel_rules_scala//src/java/com/google/devtools/build/lib:worker", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/jar", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/worker", - "//external:io_bazel_rules_scala/dependency/scalac_rules_commons_io", ], ) diff --git a/unstable/multiscala/BUILD.bazel b/unstable/multiscala/BUILD.bazel index 3ea0cd023..2086fcc96 100644 --- a/unstable/multiscala/BUILD.bazel +++ b/unstable/multiscala/BUILD.bazel @@ -1,2 +1,3 @@ load(":toolchains.bzl", "create_toolchains") + create_toolchains() diff --git a/unstable/multiscala/configuration.bzl b/unstable/multiscala/configuration.bzl index dc844bc82..e9fd758fc 100644 --- a/unstable/multiscala/configuration.bzl +++ b/unstable/multiscala/configuration.bzl @@ -29,7 +29,6 @@ default_configuration = { "compatability_labels": True, } - def _repo_impl(ctx): ctx.file( "BUILD.bazel", @@ -57,7 +56,6 @@ def _merge_dicts(*dicts, exclude = None): configuration = {} for input in dicts: - keys = _sets.make(configuration.keys() + input.keys()) if exclude and _sets.contains(keys, exclude): @@ -82,14 +80,13 @@ def _merge_dicts(*dicts, exclude = None): return configuration - def multiscala_configuration(user_configuration = default_configuration): configuration = _merge_dicts(default_configuration, user_configuration) if not "default" in configuration and len(configuration["scala"].keys()) == 1: configuration = _dicts.add( configuration, - {"default": configuration["scala"][configuration["scala"].keys()[0]] } + {"default": configuration["scala"][configuration["scala"].keys()[0]]}, ) scala = {} @@ -98,12 +95,12 @@ def multiscala_configuration(user_configuration = default_configuration): scala[version] = _merge_dicts(configuration, configuration["scala"][version], exclude = "scala") scala[version]["scala"] = version scala[version]["mvn"] = version.replace(".", "_") - scala[version]["complete"] = version+"."+ scala[version]["minor"] + scala[version]["complete"] = version + "." + scala[version]["minor"] scala[version]["default"] = True if scala[version].get("default") == version else False configuration["scala"] = scala - starlark_string = struct(**configuration).to_json() # .replace(":null,", ":None,") + starlark_string = struct(**configuration).to_json() # .replace(":null,", ":None,") _repo( name = "io_bazel_rules_scala_configuration", @@ -123,8 +120,8 @@ def _maybe_register_default_toolchains(configuration): version = _maybe_default(configuration) if version: for toolchain in [ - # "bootstrap", - "scala", - # "scalatest" + # "bootstrap", + "scala", + # "scalatest" ]: - native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:"+toolchain_label(toolchain, version)) + native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:" + toolchain_label(toolchain, version)) diff --git a/unstable/multiscala/configure.bzl b/unstable/multiscala/configure.bzl index 213e9061a..b1f64f282 100644 --- a/unstable/multiscala/configure.bzl +++ b/unstable/multiscala/configure.bzl @@ -11,8 +11,8 @@ def _maybe_register_default_toolchains(): version = _maybe_default() if version: for toolchain in [ - # "bootstrap", - "scala", - # "scalatest" + # "bootstrap", + "scala", + # "scalatest" ]: - native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:"+_toolchain_label(toolchain, version)) + native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:" + _toolchain_label(toolchain, version)) diff --git a/unstable/multiscala/multiscala.bzl b/unstable/multiscala/multiscala.bzl index 23ff24ab6..4fac1b5dd 100644 --- a/unstable/multiscala/multiscala.bzl +++ b/unstable/multiscala/multiscala.bzl @@ -1,7 +1,8 @@ -load("//scala:scala.bzl", - _scala_binary = "scala_binary", - _scala_library = "scala_library", - _scala_test = "scala_test", +load( + "//scala:scala.bzl", + _scala_binary = "scala_binary", + _scala_library = "scala_library", + _scala_test = "scala_test", ) def scala_binary(**kwargs): diff --git a/unstable/multiscala/private/example/BUILD.bazel b/unstable/multiscala/private/example/BUILD.bazel index d27a88a82..674e410fb 100644 --- a/unstable/multiscala/private/example/BUILD.bazel +++ b/unstable/multiscala/private/example/BUILD.bazel @@ -2,7 +2,7 @@ load( "@io_bazel_rules_scala//unstable/multiscala:multiscala.bzl", _scala_binary = "scala_binary", _scala_library = "scala_library", - _scala_test = "scala_test" + _scala_test = "scala_test", ) _scala_library( diff --git a/unstable/multiscala/private/example/WORKSPACE b/unstable/multiscala/private/example/WORKSPACE index 5537260a2..e9eef62c0 100644 --- a/unstable/multiscala/private/example/WORKSPACE +++ b/unstable/multiscala/private/example/WORKSPACE @@ -1,22 +1,27 @@ load("//repositories:bazel_skylib.bzl", "load_bazel_skylib") + load_bazel_skylib() load("//repositories:rules_jvm_external.bzl", "load_rules_jvm_external") + load_rules_jvm_external() load("//repositories:rules_scala.bzl", "load_rules_scala") + load_rules_scala() load("//repositories:rules_proto.bzl", "load_rules_proto") + load_rules_proto() load("//repositories:rules_python.bzl", "load_rules_python") + load_rules_python() load( "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", "multiscala_configuration", - "multiscala_configure" + "multiscala_configure", ) multiscala_configuration({ @@ -65,6 +70,9 @@ multiscala_configuration({ }) load("@io_bazel_rules_scala//unstable/multiscala:repositories.bzl", "create_repositories") + create_repositories() + load("@io_bazel_rules_scala//unstable/multiscala:configure.bzl", "multiscala_configure") + multiscala_configure() diff --git a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl index d0a8f9af0..800837d1c 100644 --- a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl +++ b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl @@ -7,5 +7,4 @@ def load_bazel_skylib(): sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", repository = "bazelbuild/bazel-skylib", release = "1.0.2", - ) diff --git a/unstable/multiscala/repositories.bzl b/unstable/multiscala/repositories.bzl index c0b1f039a..ddd082f2a 100644 --- a/unstable/multiscala/repositories.bzl +++ b/unstable/multiscala/repositories.bzl @@ -24,7 +24,7 @@ def _bind_default_labels(repository_name, artifacts): without_version = ":".join(mvn.split(":")[0:2]) native.bind( name = label, - actual = _artifact(without_version, repository_name = repository_name) + actual = _artifact(without_version, repository_name = repository_name), ) def create_repositories(): @@ -69,8 +69,8 @@ def _create_maven_installed_repos(): artifacts = { "org.scala-lang:scala-compiler:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_compiler", - "org.scala-lang:scala-library:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_library", - "org.scala-lang:scala-reflect:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_reflect", + "org.scala-lang:scala-library:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_library", + "org.scala-lang:scala-reflect:" + version["complete"]: "io_bazel_rules_scala/dependency/scala/scala_reflect", _scala_artifact(version, "org.scala-lang.modules:scala-xml"): "io_bazel_rules_scala/dependency/scala/scala_xml", _scala_artifact(version, "org.scalatest:scalatest"): "io_bazel_rules_scala/dependency/scala/scalatest/scalatest", _scala_artifact(version, "org.scalactic:scalactic"): "io_bazel_rules_scala/dependency/scala/scalactic/scalactic", @@ -82,7 +82,8 @@ def _create_maven_installed_repos(): repositories = version["repositories"], ) - if version["default"] and version["compatability_labels"]: _bind_default_labels(repository_name, artifacts) + if version["default"] and version["compatability_labels"]: + _bind_default_labels(repository_name, artifacts) if version["default"] and version["compatability_labels"]: native.bind( @@ -100,4 +101,5 @@ def _create_maven_installed_repos(): artifacts = _maven_install_artifacts(java_artifacts), repositories = _configuration["repositories"], ) - if _configuration["compatability_labels"]: _bind_default_labels("io_bazel_rules_scala_scalac", java_artifacts) + if _configuration["compatability_labels"]: + _bind_default_labels("io_bazel_rules_scala_scalac", java_artifacts) diff --git a/unstable/multiscala/toolchains.bzl b/unstable/multiscala/toolchains.bzl index 4a3346e03..b1bed2b67 100644 --- a/unstable/multiscala/toolchains.bzl +++ b/unstable/multiscala/toolchains.bzl @@ -1,5 +1,6 @@ -load("@io_bazel_rules_scala_configuration//:configuration.bzl", - _versions = "versions" +load( + "@io_bazel_rules_scala_configuration//:configuration.bzl", + _versions = "versions", ) load( "@io_bazel_rules_scala//scala:scala_toolchain.bzl", From 6cffd0d30537383fab124fb37866adb0b6f07c7f Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 13:49:55 -0800 Subject: [PATCH 08/37] wip --- unstable/multiscala/configuration.bzl | 66 +++++++++++-------- unstable/multiscala/configure.bzl | 4 +- unstable/multiscala/multiscala.bzl | 5 ++ unstable/multiscala/private/example/WORKSPACE | 9 ++- .../example/repositories/bazel_skylib.bzl | 1 - unstable/multiscala/repositories.bzl | 4 +- unstable/multiscala/toolchains.bzl | 8 +-- 7 files changed, 55 insertions(+), 42 deletions(-) diff --git a/unstable/multiscala/configuration.bzl b/unstable/multiscala/configuration.bzl index e9fd758fc..597f978a9 100644 --- a/unstable/multiscala/configuration.bzl +++ b/unstable/multiscala/configuration.bzl @@ -1,21 +1,26 @@ +"""Macros to configure scala versions and dependencies. + +Creates the configuration repo @io_bazel_rules_scala_configuration. +""" + load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts") load("@bazel_skylib//lib:sets.bzl", _sets = "sets") +# default configuration: public for user examination (if desired?) default_configuration = { + "compatability_labels": True, + "repositories": [ + "https://jcenter.bintray.com/", + "https://maven.google.com", + "https://repo1.maven.org/maven2", + ], "scala": { "2.11": { "minor": "12", }, }, - "scalatest": "3.0.5", - "scalactic": "3.0.5", - "scala-xml": "1.0.5", "scala-parser-combinators": "1.0.4", - "repositories": [ - "https://jcenter.bintray.com/", - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], + "scala-xml": "1.0.5", "scala_bootstrap_toolchain": { "scala_test_jvm_flags": [], "scalac_jvm_flags": [], @@ -26,7 +31,8 @@ default_configuration = { "plus_one_deps_mode": "off", "unused_dependency_checker_mode": "off", }, - "compatability_labels": True, + "scalactic": "3.0.5", + "scalatest": "3.0.5", } def _repo_impl(ctx): @@ -53,6 +59,17 @@ _repo = repository_rule( ) def _merge_dicts(*dicts, exclude = None): + """merge multiple dictionaries + + This is a lot like typical map merging but limited by the lack of + recursion in starlark. It will merge values to one level only. + + Args: + *dicts: the list of dicts to merge, sequentially + exclude: a key to exclude from merging (merging may not work) + + """ + configuration = {} for input in dicts: @@ -80,15 +97,26 @@ def _merge_dicts(*dicts, exclude = None): return configuration -def multiscala_configuration(user_configuration = default_configuration): - configuration = _merge_dicts(default_configuration, user_configuration) +def multiscala_configuration(configuration = default_configuration): + """Primary entry point for configuration. + + Args: + configuration: the configuration the user desires. Defaults to the one distributed. + """ + configuration = _merge_dicts(default_configuration, configuration) + + # include default (true or false) for each target scala version rather than the selected default if not "default" in configuration and len(configuration["scala"].keys()) == 1: configuration = _dicts.add( configuration, {"default": configuration["scala"][configuration["scala"].keys()[0]]}, ) + # since "scala" is a map key, we need to merge each item rather + # than having a user-specified scala key completely override the + # default. + scala = {} for version in configuration["scala"].keys(): @@ -107,21 +135,5 @@ def multiscala_configuration(user_configuration = default_configuration): starlark_string = starlark_string, ) -def multiscala_configure(configuration): - _maybe_register_default_toolchains(configuration) - -def _maybe_default(configuration): - return configuration["scala"][configuration["default"]] if "default" in configuration else None - def toolchain_label(toolchain, version): return "{toolchain}_{version}_toolchain".format(toolchain = toolchain, version = version["mvn"]) - -def _maybe_register_default_toolchains(configuration): - version = _maybe_default(configuration) - if version: - for toolchain in [ - # "bootstrap", - "scala", - # "scalatest" - ]: - native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:" + toolchain_label(toolchain, version)) diff --git a/unstable/multiscala/configure.bzl b/unstable/multiscala/configure.bzl index b1f64f282..9696f1807 100644 --- a/unstable/multiscala/configure.bzl +++ b/unstable/multiscala/configure.bzl @@ -1,5 +1,7 @@ -load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration") +"""post-configuration generation, complete other actions based on the resulting configuration""" + load("@io_bazel_rules_scala//unstable/multiscala:toolchains.bzl", _toolchain_label = "toolchain_label") +load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration") def multiscala_configure(): _maybe_register_default_toolchains() diff --git a/unstable/multiscala/multiscala.bzl b/unstable/multiscala/multiscala.bzl index 4fac1b5dd..c701aa0a7 100644 --- a/unstable/multiscala/multiscala.bzl +++ b/unstable/multiscala/multiscala.bzl @@ -1,3 +1,8 @@ +"""multiscala equivalents to scala/scala.bzl + +TBD +""" + load( "//scala:scala.bzl", _scala_binary = "scala_binary", diff --git a/unstable/multiscala/private/example/WORKSPACE b/unstable/multiscala/private/example/WORKSPACE index e9eef62c0..a9f12068f 100644 --- a/unstable/multiscala/private/example/WORKSPACE +++ b/unstable/multiscala/private/example/WORKSPACE @@ -21,10 +21,10 @@ load_rules_python() load( "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", "multiscala_configuration", - "multiscala_configure", ) -multiscala_configuration({ +multiscala_configuration(configuration = { + "default": "2.12", "scala": { "2.11": { "minor": "12", @@ -47,10 +47,8 @@ multiscala_configuration({ }, }, }, - "default": "2.12", - "scalatest": "3.1.0", - "scala-xml": "1.2.0", "scala-parser-combinators": "1.1.2", + "scala-xml": "1.2.0", "scala_bootstrap_toolchain": { "scalacopts": [ "-deprecation:true", @@ -67,6 +65,7 @@ multiscala_configuration({ "scala_toolchain": { "unused_dependency_checker_mode": "error", }, + "scalatest": "3.1.0", }) load("@io_bazel_rules_scala//unstable/multiscala:repositories.bzl", "create_repositories") diff --git a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl index 800837d1c..37d207e3d 100644 --- a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl +++ b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl @@ -1,4 +1,3 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load(":tools.bzl", _github_release = "github_release") def load_bazel_skylib(): diff --git a/unstable/multiscala/repositories.bzl b/unstable/multiscala/repositories.bzl index ddd082f2a..e20039c70 100644 --- a/unstable/multiscala/repositories.bzl +++ b/unstable/multiscala/repositories.bzl @@ -1,7 +1,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") -load(":tools.bzl", _maven_install = "maven_install") load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration", _versions = "versions") load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") +load(":tools.bzl", _maven_install = "maven_install") def _github_archive(name, repository, sha256, tag): (org, repo) = repository.split("/") @@ -92,8 +92,8 @@ def _create_maven_installed_repos(): ) java_artifacts = { - "commons-io:commons-io:2.6": "io_bazel_rules_scala/dependency/scalac_rules_commons_io", "com.google.guava:guava:21.0": "io_bazel_rules_scala/dependency/scala/guava", + "commons-io:commons-io:2.6": "io_bazel_rules_scala/dependency/scalac_rules_commons_io", } _maven_install( diff --git a/unstable/multiscala/toolchains.bzl b/unstable/multiscala/toolchains.bzl index b1bed2b67..7cb877cbb 100644 --- a/unstable/multiscala/toolchains.bzl +++ b/unstable/multiscala/toolchains.bzl @@ -1,14 +1,10 @@ -load( - "@io_bazel_rules_scala_configuration//:configuration.bzl", - _versions = "versions", -) load( "@io_bazel_rules_scala//scala:scala_toolchain.bzl", _scala_toolchain_rule = "scala_toolchain", ) load( - "@io_bazel_rules_scala//scala:providers.bzl", - _ScalacProvider = "ScalacProvider", + "@io_bazel_rules_scala_configuration//:configuration.bzl", + _versions = "versions", ) load( ":configuration.bzl", From 84e9bfbdcb45e77852621685a5adb2e5340517ad Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 14:01:46 -0800 Subject: [PATCH 09/37] lint --- unstable/multiscala/configure.bzl | 10 ++++++++-- .../private/example/repositories/bazel_skylib.bzl | 2 ++ .../example/repositories/rules_jvm_external.bzl | 2 ++ .../private/example/repositories/rules_proto.bzl | 2 ++ .../private/example/repositories/rules_python.bzl | 2 ++ .../private/example/repositories/rules_scala.bzl | 2 ++ .../private/example/repositories/tools.bzl | 5 +++++ unstable/multiscala/repositories.bzl | 14 ++++++++++++++ unstable/multiscala/toolchains.bzl | 5 ++--- unstable/multiscala/tools.bzl | 5 +++++ 10 files changed, 44 insertions(+), 5 deletions(-) diff --git a/unstable/multiscala/configure.bzl b/unstable/multiscala/configure.bzl index 9696f1807..082522116 100644 --- a/unstable/multiscala/configure.bzl +++ b/unstable/multiscala/configure.bzl @@ -1,7 +1,13 @@ """post-configuration generation, complete other actions based on the resulting configuration""" -load("@io_bazel_rules_scala//unstable/multiscala:toolchains.bzl", _toolchain_label = "toolchain_label") -load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration") +load( + "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", + _toolchain_label = "toolchain_label", +) +load( + "@io_bazel_rules_scala_configuration//:configuration.bzl", + _configuration = "configuration", +) def multiscala_configure(): _maybe_register_default_toolchains() diff --git a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl index 37d207e3d..e6477bed7 100644 --- a/unstable/multiscala/private/example/repositories/bazel_skylib.bzl +++ b/unstable/multiscala/private/example/repositories/bazel_skylib.bzl @@ -1,3 +1,5 @@ +"""load skylib""" + load(":tools.bzl", _github_release = "github_release") def load_bazel_skylib(): diff --git a/unstable/multiscala/private/example/repositories/rules_jvm_external.bzl b/unstable/multiscala/private/example/repositories/rules_jvm_external.bzl index 664236949..d68a0e2c4 100644 --- a/unstable/multiscala/private/example/repositories/rules_jvm_external.bzl +++ b/unstable/multiscala/private/example/repositories/rules_jvm_external.bzl @@ -1,3 +1,5 @@ +"""load rules_jvm_external""" + load(":tools.bzl", _github_archive = "github_archive") def load_rules_jvm_external(): diff --git a/unstable/multiscala/private/example/repositories/rules_proto.bzl b/unstable/multiscala/private/example/repositories/rules_proto.bzl index 61149bd82..bddf5cc67 100644 --- a/unstable/multiscala/private/example/repositories/rules_proto.bzl +++ b/unstable/multiscala/private/example/repositories/rules_proto.bzl @@ -1,3 +1,5 @@ +"""load rules_proto: needed by protobuf repo""" + load(":tools.bzl", _github_archive = "github_archive") def load_rules_proto(): diff --git a/unstable/multiscala/private/example/repositories/rules_python.bzl b/unstable/multiscala/private/example/repositories/rules_python.bzl index e0910e5a8..9ab16594c 100644 --- a/unstable/multiscala/private/example/repositories/rules_python.bzl +++ b/unstable/multiscala/private/example/repositories/rules_python.bzl @@ -1,3 +1,5 @@ +"""load rules_python: needed by protobuf repo""" + load(":tools.bzl", _github_archive = "github_archive") def load_rules_python(): diff --git a/unstable/multiscala/private/example/repositories/rules_scala.bzl b/unstable/multiscala/private/example/repositories/rules_scala.bzl index 6fdd108a7..d02164e0c 100644 --- a/unstable/multiscala/private/example/repositories/rules_scala.bzl +++ b/unstable/multiscala/private/example/repositories/rules_scala.bzl @@ -1,3 +1,5 @@ +"""link back to parent rules_scala repo""" + def load_rules_scala(): native.local_repository( name = "io_bazel_rules_scala", diff --git a/unstable/multiscala/private/example/repositories/tools.bzl b/unstable/multiscala/private/example/repositories/tools.bzl index ecbf3a0d7..88f628714 100644 --- a/unstable/multiscala/private/example/repositories/tools.bzl +++ b/unstable/multiscala/private/example/repositories/tools.bzl @@ -1,3 +1,8 @@ +"""helpers for to remove http_archive boilerplate + +N.B.: doesn't currently include the bazel mirros +""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def github_release(name, repository, release, sha256): diff --git a/unstable/multiscala/repositories.bzl b/unstable/multiscala/repositories.bzl index e20039c70..432afa73d 100644 --- a/unstable/multiscala/repositories.bzl +++ b/unstable/multiscala/repositories.bzl @@ -1,3 +1,16 @@ +"""macros to load all necessary repos + +Only public function is `create_repositories` + +Determines all necessary dependences from configuration and loads them. + +All loading via rules_jvm_external. + +If configuration asks for compatiblity labels, `bind`s aliases. + +Includes helpers to reduce boilerplate for github archives and artifact naming. +""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") load("@io_bazel_rules_scala_configuration//:configuration.bzl", _configuration = "configuration", _versions = "versions") load("@rules_jvm_external//:defs.bzl", _artifact = "artifact") @@ -28,6 +41,7 @@ def _bind_default_labels(repository_name, artifacts): ) def create_repositories(): + """create all necessary repos""" _create_protobuf() _create_maven_installed_repos() diff --git a/unstable/multiscala/toolchains.bzl b/unstable/multiscala/toolchains.bzl index 7cb877cbb..6c997c784 100644 --- a/unstable/multiscala/toolchains.bzl +++ b/unstable/multiscala/toolchains.bzl @@ -1,3 +1,5 @@ +"""create toolchains required by configuration""" + load( "@io_bazel_rules_scala//scala:scala_toolchain.bzl", _scala_toolchain_rule = "scala_toolchain", @@ -11,9 +13,6 @@ load( _toolchain_label = "toolchain_label", ) -def toolchain_label(toolchain, version): - return "{toolchain}_{version}_toolchain".format(toolchain = toolchain, version = version["mvn"]) - def create_toolchains(): _create_all_toolchains() diff --git a/unstable/multiscala/tools.bzl b/unstable/multiscala/tools.bzl index 2bcc8d9df..551c0f042 100644 --- a/unstable/multiscala/tools.bzl +++ b/unstable/multiscala/tools.bzl @@ -1,3 +1,8 @@ +"""helpers for loading externa repos + +TBD: maybe delete +""" + load("@rules_jvm_external//:defs.bzl", _maven_install = "maven_install") def maven_install(**kwargs): From 476901e53bbfa3b2408f30f3cb2a335f81e021f3 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Mon, 27 Jan 2020 15:39:30 -0800 Subject: [PATCH 10/37] Include toolchains attrs in example Turns out I made some mistakes on the native toolchain name vs. the implementtion name. Not for the first time. Also had to add TemplateVariableInfo to the core scala_toolchain as required when using the standard toolchains attr. Simply initialized it with an empty map (not really familiar with this provider ...) --- scala/scala_toolchain.bzl | 2 +- unstable/multiscala/BUILD.bazel | 5 ++++ unstable/multiscala/configuration.bzl | 20 ++++++++++++---- unstable/multiscala/configure.bzl | 4 ++-- .../multiscala/private/example/BUILD.bazel | 23 +++++++++++++++++++ unstable/multiscala/toolchains.bzl | 14 +++++++---- 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index f57e23302..8b4b4f828 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -13,7 +13,7 @@ def _scala_toolchain_impl(ctx): scalac_jvm_flags = ctx.attr.scalac_jvm_flags, scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) - return [toolchain] + return [toolchain, platform_common.TemplateVariableInfo({})] scala_toolchain = rule( _scala_toolchain_impl, diff --git a/unstable/multiscala/BUILD.bazel b/unstable/multiscala/BUILD.bazel index 2086fcc96..0915b96c9 100644 --- a/unstable/multiscala/BUILD.bazel +++ b/unstable/multiscala/BUILD.bazel @@ -1,3 +1,8 @@ load(":toolchains.bzl", "create_toolchains") create_toolchains() + +toolchain_type( + name = "test_toolchain_type", + visibility = ["//visibility:public"], +) diff --git a/unstable/multiscala/configuration.bzl b/unstable/multiscala/configuration.bzl index 597f978a9..4e5ac2509 100644 --- a/unstable/multiscala/configuration.bzl +++ b/unstable/multiscala/configuration.bzl @@ -9,6 +9,7 @@ load("@bazel_skylib//lib:sets.bzl", _sets = "sets") # default configuration: public for user examination (if desired?) default_configuration = { "compatability_labels": True, + "default": "2.11", "repositories": [ "https://jcenter.bintray.com/", "https://maven.google.com", @@ -90,10 +91,10 @@ def _merge_dicts(*dicts, exclude = None): configuration.get(key, {}), input[key], ) + elif field_type == "NoneType": + pass # None means delete ... else: fail([key, field_type]) - else: - configuration[key] = configuration[key] return configuration @@ -135,5 +136,16 @@ def multiscala_configuration(configuration = default_configuration): starlark_string = starlark_string, ) -def toolchain_label(toolchain, version): - return "{toolchain}_{version}_toolchain".format(toolchain = toolchain, version = version["mvn"]) +def toolchain_label(toolchain, version, in_package = False): + return "{package}{toolchain}_{version}_toolchain".format( + package = "@io_bazel_rules_scala//unstable/multiscala:" if not in_package else "", + toolchain = toolchain, + version = version.replace(".", "_"), + ) + +def native_toolchain_label(toolchain, version, in_package = False): + return "{package}native_{toolchain}_{version}_toolchain".format( + package = "@io_bazel_rules_scala//unstable/multiscala:" if not in_package else "", + toolchain = toolchain, + version = version.replace(".", "_"), + ) diff --git a/unstable/multiscala/configure.bzl b/unstable/multiscala/configure.bzl index 082522116..3a3aa025c 100644 --- a/unstable/multiscala/configure.bzl +++ b/unstable/multiscala/configure.bzl @@ -2,7 +2,7 @@ load( "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", - _toolchain_label = "toolchain_label", + _native_toolchain_label = "native_toolchain_label", ) load( "@io_bazel_rules_scala_configuration//:configuration.bzl", @@ -23,4 +23,4 @@ def _maybe_register_default_toolchains(): "scala", # "scalatest" ]: - native.register_toolchains("@io_bazel_rules_scala//unstable/multiscala:" + _toolchain_label(toolchain, version)) + native.register_toolchains(_native_toolchain_label(toolchain, version["mvn"])) diff --git a/unstable/multiscala/private/example/BUILD.bazel b/unstable/multiscala/private/example/BUILD.bazel index 674e410fb..d5ae84ca0 100644 --- a/unstable/multiscala/private/example/BUILD.bazel +++ b/unstable/multiscala/private/example/BUILD.bazel @@ -1,3 +1,7 @@ +load( + "@io_bazel_rules_scala//unstable/multiscala:configuration.bzl", + "toolchain_label", +) load( "@io_bazel_rules_scala//unstable/multiscala:multiscala.bzl", _scala_binary = "scala_binary", @@ -20,3 +24,22 @@ _scala_test( name = "test", srcs = ["AppTest.scala"], ) + +_scala_library( + name = "library_with_explict_toolchain", + srcs = ["App.scala"], + toolchains = [toolchain_label("scala", "2.11")], +) + +_scala_binary( + name = "app_with_explict_toolchain", + main_class = "App", + toolchains = [toolchain_label("scala", "2.11")], + runtime_deps = [":library"], +) + +_scala_test( + name = "test_with_explict_toolchain", + srcs = ["AppTest.scala"], + toolchains = [toolchain_label("scala", "2.11")], +) diff --git a/unstable/multiscala/toolchains.bzl b/unstable/multiscala/toolchains.bzl index 6c997c784..91440ad5e 100644 --- a/unstable/multiscala/toolchains.bzl +++ b/unstable/multiscala/toolchains.bzl @@ -10,6 +10,7 @@ load( ) load( ":configuration.bzl", + _native_toolchain_label = "native_toolchain_label", _toolchain_label = "toolchain_label", ) @@ -39,17 +40,22 @@ _scala_toolchain_attrs = [ ] def _create_scala_toolchain(version): - impl_name = _toolchain_label("scala", version) + "_impl" + name = _toolchain_label("scala", version["mvn"], in_package = True) + attrs = {} + for attr in _scala_toolchain_attrs: if attr in version["scala_toolchain"]: attrs[attr] = version["scala_toolchain"][attr] - attrs["name"] = impl_name + + attrs["name"] = name + attrs["visibility"] = ["//visibility:public"] + _scala_toolchain_rule(**attrs) native.toolchain( - name = _toolchain_label("scala", version), - toolchain = impl_name, + name = _native_toolchain_label("scala", version["mvn"], in_package = True), + toolchain = name, toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", visibility = ["//visibility:public"], ) From 3bc7668cf5aacbf335d0dce76dccf8ca98c3ee60 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 09:45:08 -0800 Subject: [PATCH 11/37] very early documentation --- unstable/multiscala/README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 unstable/multiscala/README.md diff --git a/unstable/multiscala/README.md b/unstable/multiscala/README.md new file mode 100644 index 000000000..8360f3c8e --- /dev/null +++ b/unstable/multiscala/README.md @@ -0,0 +1,33 @@ +# This is a very early work-in-progress. + +It is not only not stable, it's not complete. All the documentation here is as much or more about collaborating on the design as it is on documenting the behavior. In other words, it's highly likely that the behavior does not yet match the documentation. + +## example + +In `private/example` + +## Configuration + +Is currently via a dict of dicts, lists, strings and booleans. It's not yet documented but there is an example in the example `WORKSPACE`. The feeling is that this is ripe for refactoring. There's been a request to support multiple minor version for the same major version which wouldn't be very hard. Other things to be considered is do we use helpers to construct this rather than core types. This would be less error prone. Also, it's possible structs might be preferable to dicts since it might make code more succinct and less error prone. + +## Creating targets + +I would like to make the use of multiscala easy ("make easy things simple and hard things possible") + +One goal would be that + +``` +scala_library( + name = "foo", + ... +) +``` +Would act with the current default configuration just as it does today: it would create a single jar, `foo_.jar`. + +A change of configuration to specify two scala versions would not require any changes from the user. In other words, the default behavior is to build everything against all versions and use argument to reduce targets, not to increase them. + +So in the example above, with two scala versions configured, a build would create, for example, `foo_2_11.jar` and `foo_2_12.jar`. (This is a simplified example. I think we'll end up creating one jar for every version and then a set of aliases to give people the names that they expect.) + +To do this, we'd need to change `scala_library` from a rule to a macro. The macro has access to the configuration (which is why it's an external repo) and can instantiate the necessary targets and aliases. + +I do wonder if folks will consider this _too magic_. I can say that the developers I work with would prefer this to manual copying or having to write a starlark loop themselves for every target. From 12a2bba51176be18fb26a403bf7badba9f883582 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 09:58:48 -0800 Subject: [PATCH 12/37] typos and clarity --- unstable/multiscala/README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/unstable/multiscala/README.md b/unstable/multiscala/README.md index 8360f3c8e..fdd43224b 100644 --- a/unstable/multiscala/README.md +++ b/unstable/multiscala/README.md @@ -4,11 +4,11 @@ It is not only not stable, it's not complete. All the documentation here is as m ## example -In `private/example` +In [`private/example`](private/example) ## Configuration -Is currently via a dict of dicts, lists, strings and booleans. It's not yet documented but there is an example in the example `WORKSPACE`. The feeling is that this is ripe for refactoring. There's been a request to support multiple minor version for the same major version which wouldn't be very hard. Other things to be considered is do we use helpers to construct this rather than core types. This would be less error prone. Also, it's possible structs might be preferable to dicts since it might make code more succinct and less error prone. +The configuration is currently via a dict of dicts, lists, strings and booleans. It's not yet documented but there is an example in the example [`WORKSPACE`]((private/example/WORKSPACE)). The feeling is that this is ripe for refactoring. There's been a request to support multiple minor versions for the same major version which wouldn't be very hard. Another thing to consider is do we use helper macros to construct this rather than core types. That would be less error prone. Also, it's possible structs might be preferable to dicts since it might make code more succinct and less error prone. ## Creating targets @@ -18,15 +18,24 @@ One goal would be that ``` scala_library( - name = "foo", + name = "lib", + ... +) + +scala_library( + name = "app", + deps = [ + ":lib", + ... + ] ... ) ``` -Would act with the current default configuration just as it does today: it would create a single jar, `foo_.jar`. +ould act with the current default single version configuration mostly exactly as it does today: it would create a single jar for each target, e.g., `lib.jar` and `app.jar` (but we would probably add some aliases, too, with version suffixes as commmonly seen in maven). -A change of configuration to specify two scala versions would not require any changes from the user. In other words, the default behavior is to build everything against all versions and use argument to reduce targets, not to increase them. +A change of configuration to specify two scala versions would not require any changes from the user. In other words, the default behavior would be to build everything against all versions and use arguments to reduce targets, not require them to increase them. -So in the example above, with two scala versions configured, a build would create, for example, `foo_2_11.jar` and `foo_2_12.jar`. (This is a simplified example. I think we'll end up creating one jar for every version and then a set of aliases to give people the names that they expect.) +So in the example above, with two scala versions configured, a build would create, for example, `lib_2_11.jar`, `lib_2_12.jar`, `app_2_11.jar` and `app_2_12.jar`. The mutliscala code will create the versioned targets based on the version deps. (This is a simplified example. As mentioned, I think we'll end up creating one jar for every version and then a set of aliases to give people the names that they expect.) To do this, we'd need to change `scala_library` from a rule to a macro. The macro has access to the configuration (which is why it's an external repo) and can instantiate the necessary targets and aliases. From d6a3f6363d50bf212f767b0fb2a6088ac62a860d Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 09:59:29 -0800 Subject: [PATCH 13/37] typo --- unstable/multiscala/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unstable/multiscala/README.md b/unstable/multiscala/README.md index fdd43224b..b2f9f1498 100644 --- a/unstable/multiscala/README.md +++ b/unstable/multiscala/README.md @@ -22,7 +22,7 @@ scala_library( ... ) -scala_library( +scala_binary( name = "app", deps = [ ":lib", From ec684eda10102ec895d8e88f6675e1af28f806cd Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 09:59:43 -0800 Subject: [PATCH 14/37] yat: yet another typo --- unstable/multiscala/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unstable/multiscala/README.md b/unstable/multiscala/README.md index b2f9f1498..ecf585e96 100644 --- a/unstable/multiscala/README.md +++ b/unstable/multiscala/README.md @@ -31,7 +31,7 @@ scala_binary( ... ) ``` -ould act with the current default single version configuration mostly exactly as it does today: it would create a single jar for each target, e.g., `lib.jar` and `app.jar` (but we would probably add some aliases, too, with version suffixes as commmonly seen in maven). +would act with the current default single version configuration mostly exactly as it does today: it would create a single jar for each target, e.g., `lib.jar` and `app.jar` (but we would probably add some aliases, too, with version suffixes as commmonly seen in maven). A change of configuration to specify two scala versions would not require any changes from the user. In other words, the default behavior would be to build everything against all versions and use arguments to reduce targets, not require them to increase them. From cccf90a532eb3384890f1c1522cf7c5aa2a03dd2 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 13:11:42 -0800 Subject: [PATCH 15/37] setting to None should remove key, not leave it unchanged --- unstable/multiscala/configuration.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unstable/multiscala/configuration.bzl b/unstable/multiscala/configuration.bzl index 4e5ac2509..f56aef55e 100644 --- a/unstable/multiscala/configuration.bzl +++ b/unstable/multiscala/configuration.bzl @@ -92,7 +92,7 @@ def _merge_dicts(*dicts, exclude = None): input[key], ) elif field_type == "NoneType": - pass # None means delete ... + configuration.pop(key) else: fail([key, field_type]) From 3ca7ab3e49c4e261d1f864a8c4d632a95247f169 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Tue, 28 Jan 2020 13:21:38 -0800 Subject: [PATCH 16/37] stupid typo during merge :-( --- src/java/io/bazel/rulesscala/scalac/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index b547de260..f63f60f30 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -1,4 +1,4 @@ -gwload( +load( ":jvm_export_toolchain.bzl", _export_scalac_repositories_from_toolchain_to_jvm = "export_scalac_repositories_from_toolchain_to_jvm", ) From ccb535e21bec3fd26e1d83a718b1544f06057234 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Wed, 29 Jan 2020 14:32:50 -0800 Subject: [PATCH 17/37] thoughts on external repos --- unstable/multiscala/ExternalRepositories.md | 98 +++++++++++++++++++++ unstable/multiscala/README.md | 4 + 2 files changed, 102 insertions(+) create mode 100644 unstable/multiscala/ExternalRepositories.md diff --git a/unstable/multiscala/ExternalRepositories.md b/unstable/multiscala/ExternalRepositories.md new file mode 100644 index 000000000..e7aa4f269 --- /dev/null +++ b/unstable/multiscala/ExternalRepositories.md @@ -0,0 +1,98 @@ +# External Repositories + +## Summary + +This is a WIP summary of approaches to external dependencies. The text isn't structured at this point. It's a raw capture of current understanding so we can collaborate on the issues and approaches. When we close on that, we can turn this into real user documentation. + +Every scala build is going to have external dependencies. There are toolchain dependencies like the scala compiler and runtime library. There are dependencies used by the `rules_scala` infrastructure like `commons-io` in the scalac driver. There are dependencies in user code like `com.fasterxml.jackson.core`. + +Some of these dependencies are java and so can be imported fairly straightforwardly. + +Scala dependencies are more complicated in a multiscala environment. Now in each dependency is potentially a different dependency. For example, abstractly `scalatest` is a single dependency. In a multiscala environment, this can actually mean multiple jars, e.g., `org.scalatest:scalatest_2_11` and `org.scalatest:scalatest_2_12`. We do not want any manual pre-version repetition. + +There are also multiple mechanisms for downloading external dependencies. All these mechanisms end up downloading the desired contents into one or more external bazel repositories. + +The mapping from dependency to label depends on the loader used: e.g., [`jvm.bzl`](), [`rules_jvm_external`](), etc. Each of these mechanisms creates labels in incompatible ways. Moreover, in many cases, the exact labels used also depends on arguments provided by the user. + +Mandating a particular loading mechanism and with particular arguments would provide the ability to uniquely map scala version to label but this restriction is not acceptable. + +There appear to be two options: +1. use pairs of helper macros to produce and consume structured labels +2. use `bind` to create labels in a canonical pattern + +Both of these approaches would rely on a canonical representation of a dependency. Presumably this would be something like `{org}:{artifact}:{version}`. At rule time version would be dropped, e.g., `{org}:{artifact}`. The scala version is not included in the canonical representation since it's assume to follow the common scala pattern. (This is actually a problem for the `org.scala-lang` artifacts that don't follow the standard pattern.) + +## Using helper macros + +In essence, for each loader type (and with the user being able to extend), a pair of macros would be defined, each of which takes the canonical format. The loader macro would translate the canonical coordinate to an external repo request, e.g., +``` +"commons-io:commons-io:2.6" +``` +could translate to a macro the calls, approximately, +``` + _scala_maven_import_external( + name = "scalac_rules_commons_io", + artifact = "commons-io:commons-io:2.6", + artifact_sha256 = "f877d304660ac2a142f3865badfc971dec7ed73c747c7f8d5d2f5139ca736513", + licenses = ["notice"], + server_urls = maven_servers, + ) +``` +or one that calls +``` +maven_install( + artifacts = [ + "commons-io:commons-io:2.6", + ], + repositories = [ + # Private repositories are supported through HTTP Basic auth + "http://username:password@localhost:8081/artifactory/my-repository", + "https://jcenter.bintray.com/", + "https://maven.google.com", + "https://repo1.maven.org/maven2", + ], +) +``` +These aren't literal but accurate in direction. + +In the case of a scala dep, they must make loader calls for each coordinate for each version. (FWIW, bazel is smart enough to only download the versions you ask for at run time ... but will download all if you use `bazel fetch`.) + +The rule-time reference takes the coordinate and returns the label the loader produces. In the cases above, these would be `@scalac_rules_common_io//jar` and `@maven//:commons_io_commons_io`. + +In both cases the macros needs to know whether the jar is scala-versioned and react accordingly. + +This all seems very doable and can, to some extent, be built into the library so it doesn't have to be reflected in every build file. + +Since loading and rule-time reference are so far apart in the structure of bazel, I believe the only way to customize this behavior is by injecting the user configuration into the synthetically-created configuration repository but this is not particularly objectionable. + +The bigger concern is if multiple loading techniques are used, e.g., some `jvm.bzl` and some `rules_jvm_external`. It'd be possible to do this but the simplest approach would require each build file to know which mechanism was used for which dependencies. It's possible to imagine keeping track of this in the configuration repo but that's a bit scary ... + +## Using `bind` + +A potentially straightforward alternative a approach is to simply require `bind` whatever label is created by the loader to a canonical label in the external namespace. This separates loading mechanism from consumption mechanism. Although it's assumed we'd want to automate the loading of repos, that would not be necessary and ad hoc corner-cases could be handled relatively easily, more easily than with the previous mechanism. It's also amenable to using multiple loading mechanisms without having to reflect the loader chose in build files. + +It's assumed that the `external` path is canonically paired with the maven coordinate, e.g., `commons-io:commons-io` would end up at `//external:maven/commons-io/commons-io`. + +## Which to use? + +I'm not sure. I don't know if we need to support mixed loaders in a single workspace. If we did, I think I'd tend to lean towards `bind`. + +`bind` is considered bad in many cases for good reason. Where patterns aren't strongly enforced and/or where it's not actually adding any value, it's a significant increase in complexity. However, here we'd be using a very strict target pattern which, among other things, would make understanding meaning and search for references straightforward. + +The alternative, at this point, in the face of multiple mechanism of having to reflect the mechanism in each build I find a significant complexity for build file writers. + +The alternative of keeping a map of the necessary information in the configuration workspace is potentially viable but I haven't really investigated it. + +## Open issues + +### Handling different versions across different targets + +Do we need this? I suspect we might, for instance if the version of `commons-io` we need for building the toolchain is different than the one a user wants. I think the answer to this is the idea of a scope. `rules_jvm_external` has this and it's just part of the name in `jvm.bzl`. This is easy to handle at load time but we have to figure out how to reflect it in rule dependencies since it's not reflected in the normal maven coordinate. + +### Handling different shas for tools that want to pass the shas inline + +`rules_jvm_external` doesn't use this (it puts the shas in a separate out-of-band file in a way that shouldn't affect this work). Other tools like `jvm.bzl` do. Maybe we factor our the shas into a dict and add them at repo call time. + +### Handling multiple references to the same object + +This is essentially the `if not native.existing_rule` issue and I still don't have a handle on what happens (or should happen) when you have reconvergence: where two paths want the same dependency and give it he same label but spec different versions, e.g., protobufs. IIUC, it's possible you could get non-deterministic builds because I think the results would depend on execution order of loads which I think can run concurrently and therefore non-deterministicly. diff --git a/unstable/multiscala/README.md b/unstable/multiscala/README.md index ecf585e96..594c8c4a6 100644 --- a/unstable/multiscala/README.md +++ b/unstable/multiscala/README.md @@ -40,3 +40,7 @@ So in the example above, with two scala versions configured, a build would creat To do this, we'd need to change `scala_library` from a rule to a macro. The macro has access to the configuration (which is why it's an external repo) and can instantiate the necessary targets and aliases. I do wonder if folks will consider this _too magic_. I can say that the developers I work with would prefer this to manual copying or having to write a starlark loop themselves for every target. + +## External Repos + +See [External Repositories](ExternalReposistories.md) From c4086c0783d17eaa9437fc4e87f7a0845e7724e9 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Wed, 29 Jan 2020 14:58:30 -0800 Subject: [PATCH 18/37] editing for typos and clarity --- unstable/multiscala/ExternalRepositories.md | 42 ++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/unstable/multiscala/ExternalRepositories.md b/unstable/multiscala/ExternalRepositories.md index e7aa4f269..1d9c6a9d2 100644 --- a/unstable/multiscala/ExternalRepositories.md +++ b/unstable/multiscala/ExternalRepositories.md @@ -4,15 +4,15 @@ This is a WIP summary of approaches to external dependencies. The text isn't structured at this point. It's a raw capture of current understanding so we can collaborate on the issues and approaches. When we close on that, we can turn this into real user documentation. -Every scala build is going to have external dependencies. There are toolchain dependencies like the scala compiler and runtime library. There are dependencies used by the `rules_scala` infrastructure like `commons-io` in the scalac driver. There are dependencies in user code like `com.fasterxml.jackson.core`. +Every scala build is going to have external dependencies. There are toolchain dependencies like the scala compiler and runtime library. There are dependencies used by the `rules_scala` infrastructure like `commons-io` in the scalac driver. Users will have dependencies in their code represented in build files, things like like `com.fasterxml.jackson.core`. Some of these dependencies are java and so can be imported fairly straightforwardly. -Scala dependencies are more complicated in a multiscala environment. Now in each dependency is potentially a different dependency. For example, abstractly `scalatest` is a single dependency. In a multiscala environment, this can actually mean multiple jars, e.g., `org.scalatest:scalatest_2_11` and `org.scalatest:scalatest_2_12`. We do not want any manual pre-version repetition. +Scala dependencies are more complicated in a multiscala environment. Now each abstract dependency is potentially multiple concrete dependencies. For example, abstractly `scalatest` is a single dependency. In a multiscala environment, this can actually mean multiple jars, e.g., `org.scalatest:scalatest_2_11` and `org.scalatest:scalatest_2_12`. We do not want any manual per-version repetition exposed to the user in the common case. There are also multiple mechanisms for downloading external dependencies. All these mechanisms end up downloading the desired contents into one or more external bazel repositories. -The mapping from dependency to label depends on the loader used: e.g., [`jvm.bzl`](), [`rules_jvm_external`](), etc. Each of these mechanisms creates labels in incompatible ways. Moreover, in many cases, the exact labels used also depends on arguments provided by the user. +The mapping from dependency to label depends on the loader used: e.g., [`jvm.bzl`](https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/jvm.bzl)(and it's variants), [`rules_jvm_external`](https://github.com/bazelbuild/rules_jvm_external), etc. These mechanisms create labels in incompatible ways. Moreover, in many cases, the exact labels used depends on arguments provided by the user. Mandating a particular loading mechanism and with particular arguments would provide the ability to uniquely map scala version to label but this restriction is not acceptable. @@ -20,7 +20,7 @@ There appear to be two options: 1. use pairs of helper macros to produce and consume structured labels 2. use `bind` to create labels in a canonical pattern -Both of these approaches would rely on a canonical representation of a dependency. Presumably this would be something like `{org}:{artifact}:{version}`. At rule time version would be dropped, e.g., `{org}:{artifact}`. The scala version is not included in the canonical representation since it's assume to follow the common scala pattern. (This is actually a problem for the `org.scala-lang` artifacts that don't follow the standard pattern.) +Both of these approaches would rely on a canonical representation of a dependency. Presumably this would be something like `{org}:{artifact}:{version}`. At target creation time, version would be dropped, e.g., `{org}:{artifact}`. The scala version _is not_ included in the canonical representation since it's assume to follow the common scala pattern. (This is actually a bit of a problem for the `org.scala-lang` artifacts that don't follow the common pattern.) ## Using helper macros @@ -35,7 +35,7 @@ could translate to a macro the calls, approximately, artifact = "commons-io:commons-io:2.6", artifact_sha256 = "f877d304660ac2a142f3865badfc971dec7ed73c747c7f8d5d2f5139ca736513", licenses = ["notice"], - server_urls = maven_servers, + server_urls = ... ) ``` or one that calls @@ -44,42 +44,36 @@ maven_install( artifacts = [ "commons-io:commons-io:2.6", ], - repositories = [ - # Private repositories are supported through HTTP Basic auth - "http://username:password@localhost:8081/artifactory/my-repository", - "https://jcenter.bintray.com/", - "https://maven.google.com", - "https://repo1.maven.org/maven2", - ], + repositories = ... ) ``` These aren't literal but accurate in direction. -In the case of a scala dep, they must make loader calls for each coordinate for each version. (FWIW, bazel is smart enough to only download the versions you ask for at run time ... but will download all if you use `bazel fetch`.) +In the case of a scala dep, they must make loader calls for each coordinate for each version. (FWIW, bazel is smart enough to only download the versions you need for the targets you ask for.) The rule-time reference takes the coordinate and returns the label the loader produces. In the cases above, these would be `@scalac_rules_common_io//jar` and `@maven//:commons_io_commons_io`. -In both cases the macros needs to know whether the jar is scala-versioned and react accordingly. +In both cases, the macros needs to know whether the jar is scala-versioned and adjust accordingly. This all seems very doable and can, to some extent, be built into the library so it doesn't have to be reflected in every build file. -Since loading and rule-time reference are so far apart in the structure of bazel, I believe the only way to customize this behavior is by injecting the user configuration into the synthetically-created configuration repository but this is not particularly objectionable. +Because loading and rule-time reference are so far apart in the structure of bazel, I think it might be necessary to parameterize this behavior per repo by injecting the user choice into the synthetically-created configuration repository. This is not particularly hard or objectionable. -The bigger concern is if multiple loading techniques are used, e.g., some `jvm.bzl` and some `rules_jvm_external`. It'd be possible to do this but the simplest approach would require each build file to know which mechanism was used for which dependencies. It's possible to imagine keeping track of this in the configuration repo but that's a bit scary ... +The bigger concern is if multiple loading techniques are used within the same workspace, e.g., some `jvm.bzl` and some `rules_jvm_external`. It relatively straightfoward to to do this but the simplest approach would require each build file to know which mechanism was used for each dependencies. It's possible to imagine keeping track of the per-coordinate choice in the configuration repo but that might be a bit scary ... ## Using `bind` -A potentially straightforward alternative a approach is to simply require `bind` whatever label is created by the loader to a canonical label in the external namespace. This separates loading mechanism from consumption mechanism. Although it's assumed we'd want to automate the loading of repos, that would not be necessary and ad hoc corner-cases could be handled relatively easily, more easily than with the previous mechanism. It's also amenable to using multiple loading mechanisms without having to reflect the loader chose in build files. +A potentially straightforward alternative is to simply require `bind`ing whatever label is created by the loader to a canonical label in the external namespace. This separates the loading mechanism from the rule-time consumption mechanism. This simplies consumtion at the expense of loading time work (`bind`ing labels) which, if you have to choose, is the right place to mange the complexity. Among other things, ad hoc corner-cases could be handled relatively easily, more easily than with the previous mechanism. It's also amenable to using multiple loading mechanisms without having to reflect the loader chose in build files. -It's assumed that the `external` path is canonically paired with the maven coordinate, e.g., `commons-io:commons-io` would end up at `//external:maven/commons-io/commons-io`. +It's required that the `external` path is canonically paired with the maven coordinate, e.g., `commons-io:commons-io` would end up at `//external:maven/commons-io/commons-io` no matter how the jar was loaded. ## Which to use? I'm not sure. I don't know if we need to support mixed loaders in a single workspace. If we did, I think I'd tend to lean towards `bind`. -`bind` is considered bad in many cases for good reason. Where patterns aren't strongly enforced and/or where it's not actually adding any value, it's a significant increase in complexity. However, here we'd be using a very strict target pattern which, among other things, would make understanding meaning and search for references straightforward. +`bind` is considered bad in many cases and for good reason. Where patterns aren't strongly enforced and/or where it's not actually adding any value (you could easily depend on the loader label because it's well known), using `bind` is a significant increase in complexity. However, here we'd be using a very strict target pattern which, among other things, would make understanding the meaning of th label and searching for references to the label straightforward. -The alternative, at this point, in the face of multiple mechanism of having to reflect the mechanism in each build I find a significant complexity for build file writers. +The alternative, at this point, in the face of supporting multiple loading mechanisms by needing to reflect the mechanism for each dependency in every build file, I find a significant burden for build file writers. The alternative of keeping a map of the necessary information in the configuration workspace is potentially viable but I haven't really investigated it. @@ -87,7 +81,11 @@ The alternative of keeping a map of the necessary information in the configurati ### Handling different versions across different targets -Do we need this? I suspect we might, for instance if the version of `commons-io` we need for building the toolchain is different than the one a user wants. I think the answer to this is the idea of a scope. `rules_jvm_external` has this and it's just part of the name in `jvm.bzl`. This is easy to handle at load time but we have to figure out how to reflect it in rule dependencies since it's not reflected in the normal maven coordinate. +Do we need this? I suspect we might, for instance if the version of `commons-io` we need for building the toolchain is different than the one a user wants for their own code. I think the answer to this is the idea of a scope. + +This is easy to handle at load time: `rules_jvm_external` has this natively and it can added systemtically as part of the name in `jvm.bzl` repos. + +We would have to figure out how to reflect scopes in rule dependencies since it's not reflected in the normal maven coordinate. ### Handling different shas for tools that want to pass the shas inline @@ -95,4 +93,4 @@ Do we need this? I suspect we might, for instance if the version of `commons-io` ### Handling multiple references to the same object -This is essentially the `if not native.existing_rule` issue and I still don't have a handle on what happens (or should happen) when you have reconvergence: where two paths want the same dependency and give it he same label but spec different versions, e.g., protobufs. IIUC, it's possible you could get non-deterministic builds because I think the results would depend on execution order of loads which I think can run concurrently and therefore non-deterministicly. +This is essentially the `if not native.existing_rule` issue and I still don't have a handle on what happens (or should happen) when you have reconvergence: where two paths want the same dependency and give it the same label but spec different versions, e.g., protobufs. IIUC, it's possible you could get non-deterministic builds because I think the results would depend on execution order of loads which I think can run concurrently and therefore non-deterministicly. From 0aba00e850774963f81a541b9ddec1f8b9354a09 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 08:44:29 -0800 Subject: [PATCH 19/37] wip --- scala/BUILD | 32 ++++++++++++++++++++++--- scala/bootstrap_toolchain.bzl | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 scala/bootstrap_toolchain.bzl diff --git a/scala/BUILD b/scala/BUILD index a5c8f2416..9273d54f1 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -4,24 +4,50 @@ load( ) load("//scala:scala_toolchain.bzl", "scala_toolchain") +# bootstrap toolchain + +toolchain_type( + name = "bootstrap_toolchain_type", + visibility = ["//visibility:public"], +) + +scala_toolchain( + name = "bootstrap_toolchain_impl", + scalacopts = [], + visibility = ["//visibility:public"], +) + +toolchain( + name = "bootstrap_toolchain", + toolchain = ":bootstrap_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + visibility = ["//visibility:public"], +) + +# standard toolchain + toolchain_type( name = "toolchain_type", visibility = ["//visibility:public"], ) scala_toolchain( - name = "default_toolchain_impl", + name = "toolchain_impl", scalacopts = [], visibility = ["//visibility:public"], ) toolchain( - name = "default_toolchain", - toolchain = ":default_toolchain_impl", + name = "toolchain", + toolchain = ":toolchain_impl", toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", visibility = ["//visibility:public"], ) +# test toolchain + +# unused dependency checker toolchain + scala_toolchain( name = "unused_dependency_checker_error_toolchain_impl", unused_dependency_checker_mode = "error", diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl new file mode 100644 index 000000000..8dbdae603 --- /dev/null +++ b/scala/bootstrap_toolchain.bzl @@ -0,0 +1,44 @@ +BootstrapInfo = provider( + doc = "BootstrapProvider", + fields = [ + "classpath", + "macro_classpath", + "repl_classpath", + ], +) + +def _impl(ctx): + toolchain = platform_common.ToolchainInfo( + # scalacopts = ctx.attr.scalacopts, + # scalac_provider_attr = ctx.attr.scalac_provider_attr, + # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, + # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, + # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, + # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, + # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, + ) + return [toolchain] + +bootstrap_toolchain = rule( + __impl, + attrs = { + # "scalacopts": attr.string_list(), + # "scalac_provider_attr": attr.label( + # default = "@io_bazel_rules_scala//scala:scalac_default", + # providers = [_ScalacProvider], + # ), + # "unused_dependency_checker_mode": attr.string( + # default = "off", + # values = ["off", "warn", "error"], + # ), + # "plus_one_deps_mode": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "enable_code_coverage_aspect": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "scalac_jvm_flags": attr.string_list(), + }, +) From c83091976fa9394bebca59cb6a8453ccfdbdd3af Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 09:45:23 -0800 Subject: [PATCH 20/37] wip --- WORKSPACE | 3 + private/example/App.scala | 5 ++ private/example/AppTest.scala | 9 +++ private/example/BUILD.bazel | 28 +++++++++ private/example/WORKSPACE | 25 ++++++++ private/example/repositories/BUILD.bazel | 0 private/example/repositories/bazel_skylib.bzl | 11 ++++ .../repositories/rules_jvm_external.bzl | 11 ++++ private/example/repositories/rules_proto.bzl | 11 ++++ private/example/repositories/rules_python.bzl | 11 ++++ private/example/repositories/rules_scala.bzl | 7 +++ private/example/repositories/tools.bzl | 28 +++++++++ scala/BUILD | 62 +++++++++++-------- scala/bootstrap_toolchain.bzl | 14 ++++- scala/private/phases/phase_collect_jars.bzl | 8 +-- scala/private/phases/phase_compile.bzl | 16 ++--- .../private/phases/phase_scalac_provider.bzl | 11 ++-- scala/private/rules/scala_binary.bzl | 5 +- scala/private/rules/scala_junit_test.bzl | 8 ++- scala/private/rules/scala_library.bzl | 15 ++++- scala/private/rules/scala_repl.bzl | 5 +- scala/private/rules/scala_test.bzl | 6 +- scala/providers.bzl | 48 +++++++------- scala/scala_toolchain.bzl | 52 +++++++++++++--- scala/test_toolchain.bzl | 36 +++++++++++ scala/toolchains.bzl | 4 +- .../scalac/jvm_export_toolchain.bzl | 13 ++-- .../twitter_scrooge/twitter_scrooge_test.bzl | 2 +- 28 files changed, 360 insertions(+), 94 deletions(-) create mode 100644 private/example/App.scala create mode 100644 private/example/AppTest.scala create mode 100644 private/example/BUILD.bazel create mode 100644 private/example/WORKSPACE create mode 100644 private/example/repositories/BUILD.bazel create mode 100644 private/example/repositories/bazel_skylib.bzl create mode 100644 private/example/repositories/rules_jvm_external.bzl create mode 100644 private/example/repositories/rules_proto.bzl create mode 100644 private/example/repositories/rules_python.bzl create mode 100644 private/example/repositories/rules_scala.bzl create mode 100644 private/example/repositories/tools.bzl create mode 100644 scala/test_toolchain.bzl diff --git a/WORKSPACE b/WORKSPACE index 708662bce..08ecaeff9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,6 +15,9 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen buildifier_dependencies() +load("//scala:toolchains.bzl", "scala_register_toolchains") +scala_register_toolchains() + load("//scala:scala.bzl", "scala_repositories") scala_repositories() diff --git a/private/example/App.scala b/private/example/App.scala new file mode 100644 index 000000000..79148dace --- /dev/null +++ b/private/example/App.scala @@ -0,0 +1,5 @@ +object App extends scala.App { + def version = scala.util.Properties.versionString + + println(s"hello, world from $version!") +} diff --git a/private/example/AppTest.scala b/private/example/AppTest.scala new file mode 100644 index 000000000..a7f9bf841 --- /dev/null +++ b/private/example/AppTest.scala @@ -0,0 +1,9 @@ +import org.scalatest._ + +class AppTest extends FlatSpec with Matchers { + it should "have a successful test" in { + System.err.println(s"hello, world from ${scala.util.Properties.versionString}!") + + App.version should be (scala.util.Properties.versionString) + } +} diff --git a/private/example/BUILD.bazel b/private/example/BUILD.bazel new file mode 100644 index 000000000..8cb3d09c7 --- /dev/null +++ b/private/example/BUILD.bazel @@ -0,0 +1,28 @@ +load( + "@io_bazel_rules_scala//scala:scala.bzl", + "scala_binary", + "scala_library", + "scala_test", +) + +# default case: builds all configured versions with version suffixes + +scala_library( + name = "library", + srcs = glob( + ["*.scala"], + exclude = ["*Test.scala"], + ), +) + +scala_binary( + name = "app", + main_class = "App", + runtime_deps = [":library"], +) + +scala_test( + name = "test", + srcs = ["AppTest.scala"], + deps = [":library"], +) diff --git a/private/example/WORKSPACE b/private/example/WORKSPACE new file mode 100644 index 000000000..930408d14 --- /dev/null +++ b/private/example/WORKSPACE @@ -0,0 +1,25 @@ +load("//repositories:bazel_skylib.bzl", "load_bazel_skylib") + +load_bazel_skylib() + +load("//repositories:rules_jvm_external.bzl", "load_rules_jvm_external") + +load_rules_jvm_external() + +load("//repositories:rules_scala.bzl", "load_rules_scala") + +load_rules_scala() + +load("//repositories:rules_proto.bzl", "load_rules_proto") + +load_rules_proto() + +load("//repositories:rules_python.bzl", "load_rules_python") + +load_rules_python() + +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") +scala_register_toolchains() + +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") +scala_repositories() diff --git a/private/example/repositories/BUILD.bazel b/private/example/repositories/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/private/example/repositories/bazel_skylib.bzl b/private/example/repositories/bazel_skylib.bzl new file mode 100644 index 000000000..e6477bed7 --- /dev/null +++ b/private/example/repositories/bazel_skylib.bzl @@ -0,0 +1,11 @@ +"""load skylib""" + +load(":tools.bzl", _github_release = "github_release") + +def load_bazel_skylib(): + _github_release( + name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", + repository = "bazelbuild/bazel-skylib", + release = "1.0.2", + ) diff --git a/private/example/repositories/rules_jvm_external.bzl b/private/example/repositories/rules_jvm_external.bzl new file mode 100644 index 000000000..d68a0e2c4 --- /dev/null +++ b/private/example/repositories/rules_jvm_external.bzl @@ -0,0 +1,11 @@ +"""load rules_jvm_external""" + +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_jvm_external(): + _github_archive( + name = "rules_jvm_external", + repository = "bazelbuild/rules_jvm_external", + sha256 = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a", + tag = "3.0", + ) diff --git a/private/example/repositories/rules_proto.bzl b/private/example/repositories/rules_proto.bzl new file mode 100644 index 000000000..bddf5cc67 --- /dev/null +++ b/private/example/repositories/rules_proto.bzl @@ -0,0 +1,11 @@ +"""load rules_proto: needed by protobuf repo""" + +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_proto(): + _github_archive( + name = "rules_proto", + repository = "bazelbuild/rules_proto", + sha256 = "62847ac7740865d73a2c8199be292bba913d62e79084442f3e829c3058a25e64", + tag = "d7666ec475c1f8d4a6803cbc0a0b6b4374360868", + ) diff --git a/private/example/repositories/rules_python.bzl b/private/example/repositories/rules_python.bzl new file mode 100644 index 000000000..9ab16594c --- /dev/null +++ b/private/example/repositories/rules_python.bzl @@ -0,0 +1,11 @@ +"""load rules_python: needed by protobuf repo""" + +load(":tools.bzl", _github_archive = "github_archive") + +def load_rules_python(): + _github_archive( + name = "rules_python", + repository = "bazelbuild/rules_python", + sha256 = "7d64815f4b22400bed0f1b9da663037e1578573446b7bc78f20f24b2b5459bb9", + tag = "38f86fb55b698c51e8510c807489c9f4e047480e", + ) diff --git a/private/example/repositories/rules_scala.bzl b/private/example/repositories/rules_scala.bzl new file mode 100644 index 000000000..3eb26a745 --- /dev/null +++ b/private/example/repositories/rules_scala.bzl @@ -0,0 +1,7 @@ +"""link back to parent rules_scala repo""" + +def load_rules_scala(): + native.local_repository( + name = "io_bazel_rules_scala", + path = "../..", + ) diff --git a/private/example/repositories/tools.bzl b/private/example/repositories/tools.bzl new file mode 100644 index 000000000..88f628714 --- /dev/null +++ b/private/example/repositories/tools.bzl @@ -0,0 +1,28 @@ +"""helpers for to remove http_archive boilerplate + +N.B.: doesn't currently include the bazel mirros +""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def github_release(name, repository, release, sha256): + (org, repo) = repository.split("/") + http_archive( + name = name, + sha256 = sha256, + urls = [ + "https://github.com/{repository}/releases/download/{release}/{repo}-{release}.tar.gz".format(repository = repository, repo = repo, release = release), + ], + ) + +def github_archive(name, repository, sha256, tag): + (org, repo) = repository.split("/") + without_v = tag[1:] if tag.startswith("v") else tag + http_archive( + name = name, + sha256 = sha256, + strip_prefix = "{repo}-{without_v}".format(repo = repo, without_v = without_v), + urls = [ + "https://github.com/{repository}/archive/{tag}.zip".format(repository = repository, tag = tag), + ], + ) diff --git a/scala/BUILD b/scala/BUILD index 9273d54f1..f5200bf4c 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -1,8 +1,10 @@ -load( - "@io_bazel_rules_scala//scala:providers.bzl", - _declare_scalac_provider = "declare_scalac_provider", -) +# load( +# "@io_bazel_rules_scala//scala:providers.bzl", +# _declare_scalac_provider = "declare_scalac_provider", +# ) +load("//scala:bootstrap_toolchain.bzl", "bootstrap_toolchain") load("//scala:scala_toolchain.bzl", "scala_toolchain") +load("//scala:test_toolchain.bzl", "test_toolchain") # bootstrap toolchain @@ -11,9 +13,21 @@ toolchain_type( visibility = ["//visibility:public"], ) -scala_toolchain( +bootstrap_toolchain( name = "bootstrap_toolchain_impl", - scalacopts = [], + classpath = [ + "@io_bazel_rules_scala_scala_library", + "@io_bazel_rules_scala_scala_reflect", + ], + macro_classpath = [ + "@io_bazel_rules_scala_scala_library", + "@io_bazel_rules_scala_scala_reflect", + ], + repl_classpath = [ + "@io_bazel_rules_scala_scala_library", + "@io_bazel_rules_scala_scala_reflect", + "@io_bazel_rules_scala_scala_compiler", + ], visibility = ["//visibility:public"], ) @@ -46,6 +60,23 @@ toolchain( # test toolchain +toolchain_type( + name = "test_toolchain_type", + visibility = ["//visibility:public"], +) + +test_toolchain( + name = "test_toolchain_impl", + visibility = ["//visibility:public"], +) + +toolchain( + name = "test_toolchain", + toolchain = ":test_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//scala:test_toolchain_type", + visibility = ["//visibility:public"], +) + # unused dependency checker toolchain scala_toolchain( @@ -66,25 +97,6 @@ java_import( jars = ["@bazel_tools//tools/jdk:TestRunner_deploy.jar"], visibility = ["//visibility:public"], ) - -_declare_scalac_provider( - name = "scalac_default", - default_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", - ], - default_macro_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", - ], - default_repl_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", - "@io_bazel_rules_scala_scala_compiler", - ], - visibility = ["//visibility:public"], -) - java_library( name = "PlaceHolderClassToCreateEmptyJarForScalaImport", srcs = ["PlaceHolderClassToCreateEmptyJarForScalaImport.java"], diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl index 8dbdae603..78c61eda8 100644 --- a/scala/bootstrap_toolchain.bzl +++ b/scala/bootstrap_toolchain.bzl @@ -1,5 +1,5 @@ BootstrapInfo = provider( - doc = "BootstrapProvider", + doc = "BootstrapInfo", fields = [ "classpath", "macro_classpath", @@ -9,6 +9,11 @@ BootstrapInfo = provider( def _impl(ctx): toolchain = platform_common.ToolchainInfo( + bootstrapInfo = BootstrapInfo( + classpath = ctx.attr.classpath, + macro_classpath = ctx.attr.macro_classpath, + repl_classpath = ctx.attr.repl_classpath, + ) # scalacopts = ctx.attr.scalacopts, # scalac_provider_attr = ctx.attr.scalac_provider_attr, # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, @@ -20,8 +25,11 @@ def _impl(ctx): return [toolchain] bootstrap_toolchain = rule( - __impl, - attrs = { + _impl, + attrs = { + "classpath": attr.label_list(mandatory=True, allow_files = True), + "repl_classpath": attr.label_list(mandatory=True, allow_files = True), + "macro_classpath": attr.label_list(mandatory=True, allow_files = True), # "scalacopts": attr.string_list(), # "scalac_provider_attr": attr.label( # default = "@io_bazel_rules_scala//scala:scalac_default", diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index d3d4fce9b..8f6c86c36 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -15,7 +15,7 @@ load( def phase_collect_jars_scalatest(ctx, p): args = struct( - base_classpath = p.scalac_provider.default_classpath + [ctx.attr._scalatest], + base_classpath = p.scalac_provider.bootstrapInfo.classpath + [ctx.attr._scalatest], extra_runtime_deps = [ ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner, @@ -25,13 +25,13 @@ def phase_collect_jars_scalatest(ctx, p): def phase_collect_jars_repl(ctx, p): args = struct( - base_classpath = p.scalac_provider.default_repl_classpath, + base_classpath = p.scalac_provider.bootstrapInfo.repl_classpath, ) return _phase_collect_jars_default(ctx, p, args) def phase_collect_jars_macro_library(ctx, p): args = struct( - base_classpath = p.scalac_provider.default_macro_classpath, + base_classpath = p.scalac_provider.bootstrapInfo.macro_classpath, ) return _phase_collect_jars_default(ctx, p, args) @@ -58,7 +58,7 @@ def phase_collect_jars_common(ctx, p): def _phase_collect_jars_default(ctx, p, _args = struct()): return _phase_collect_jars( ctx, - _args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.default_classpath, + _args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.bootstrapInfo.classpath, _args.extra_deps if hasattr(_args, "extra_deps") else [], _args.extra_runtime_deps if hasattr(_args, "extra_runtime_deps") else [], _args.unused_dependency_checker_mode if hasattr(_args, "unused_dependency_checker_mode") else p.unused_deps_checker, diff --git a/scala/private/phases/phase_compile.bzl b/scala/private/phases/phase_compile.bzl index e98946899..5fe184e87 100644 --- a/scala/private/phases/phase_compile.bzl +++ b/scala/private/phases/phase_compile.bzl @@ -34,7 +34,7 @@ def phase_compile_binary(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_classpath + + for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -45,7 +45,7 @@ def phase_compile_library(ctx, p): srcjars = p.collect_srcjars, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_classpath + ctx.attr.exports + + for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -55,7 +55,7 @@ def phase_compile_library_for_plugin_bootstrapping(ctx, p): args = struct( unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_classpath + ctx.attr.exports + for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.exports ], unused_dependency_checker_mode = "off", ) @@ -66,7 +66,7 @@ def phase_compile_macro_library(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_macro_classpath + ctx.attr.exports + + for target in p.scalac_provider.bootstrapInfo.macro_classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -81,7 +81,7 @@ def phase_compile_junit_test(ctx, p): ], unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_classpath + + for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ] + [ ctx.attr._junit.label, @@ -97,7 +97,7 @@ def phase_compile_repl(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_repl_classpath + + for target in p.scalac_provider.bootstrapInfo.repl_classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -108,7 +108,7 @@ def phase_compile_scalatest(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.default_classpath + + for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -143,7 +143,7 @@ def _phase_compile( transitive_compile_jars = p.collect_jars.transitive_compile_jars jars2labels = p.collect_jars.jars2labels.jars_to_labels deps_providers = p.collect_jars.deps_providers - default_classpath = p.scalac_provider.default_classpath + default_classpath = p.scalac_provider.bootstrapInfo.classpath out = _compile_or_empty( ctx, diff --git a/scala/private/phases/phase_scalac_provider.bzl b/scala/private/phases/phase_scalac_provider.bzl index aff54f32f..83ea42bad 100644 --- a/scala/private/phases/phase_scalac_provider.bzl +++ b/scala/private/phases/phase_scalac_provider.bzl @@ -3,10 +3,11 @@ # # DOCUMENT THIS # -load( - "@io_bazel_rules_scala//scala:providers.bzl", - _ScalacProvider = "ScalacProvider", -) +# load( +# "@io_bazel_rules_scala//scala:providers.bzl", +# _ScalacProvider = "ScalacProvider", +# ) def phase_scalac_provider(ctx, p): - return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider] + # return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider] + return ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"] diff --git a/scala/private/rules/scala_binary.bzl b/scala/private/rules/scala_binary.bzl index 07afd2574..4a8529b97 100644 --- a/scala/private/rules/scala_binary.bzl +++ b/scala/private/rules/scala_binary.bzl @@ -73,7 +73,10 @@ def make_scala_binary(*extras): common_outputs, *[extra["outputs"] for extra in extras if "outputs" in extra] ), - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type" + ], implementation = _scala_binary_impl, ) diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index 8b58180b7..1933b14db 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -125,7 +125,13 @@ def make_scala_junit_test(*extras): *[extra["outputs"] for extra in extras if "outputs" in extra] ), test = True, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type", + # unclear on next and will consider in factoring, whether + # scalatest and junit tests should be different toolchain types + "@io_bazel_rules_scala//scala:test_toolchain_type", + ], implementation = _scala_junit_test_impl, ) diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl index 17356b843..7c1272a15 100644 --- a/scala/private/rules/scala_library.bzl +++ b/scala/private/rules/scala_library.bzl @@ -92,7 +92,10 @@ def make_scala_library(*extras): common_outputs, *[extra["outputs"] for extra in extras if "outputs" in extra] ), - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type" + ], implementation = _scala_library_impl, ) @@ -173,7 +176,10 @@ def make_scala_library_for_plugin_bootstrapping(*extras): common_outputs, *[extra["outputs"] for extra in extras if "outputs" in extra] ), - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type" + ], implementation = _scala_library_for_plugin_bootstrapping_impl, ) @@ -238,7 +244,10 @@ def make_scala_macro_library(*extras): common_outputs, *[extra["outputs"] for extra in extras if "outputs" in extra] ), - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type" + ], implementation = _scala_macro_library_impl, ) diff --git a/scala/private/rules/scala_repl.bzl b/scala/private/rules/scala_repl.bzl index 3d508af45..3946467e5 100644 --- a/scala/private/rules/scala_repl.bzl +++ b/scala/private/rules/scala_repl.bzl @@ -72,7 +72,10 @@ def make_scala_repl(*extras): common_outputs, *[extra["outputs"] for extra in extras if "outputs" in extra] ), - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type" + ], implementation = _scala_repl_impl, ) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 1a6bd3e7d..6d70b045a 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -111,7 +111,11 @@ def make_scala_test(*extras): *[extra["outputs"] for extra in extras if "outputs" in extra] ), test = True, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", + "@io_bazel_rules_scala//scala:toolchain_type", + "@io_bazel_rules_scala//scala:test_toolchain_type", + ], implementation = _scala_test_impl, ) diff --git a/scala/providers.bzl b/scala/providers.bzl index 66fc97f0b..dc6ce964d 100644 --- a/scala/providers.bzl +++ b/scala/providers.bzl @@ -1,26 +1,26 @@ -ScalacProvider = provider( - doc = "ScalacProvider", - fields = [ - "default_classpath", - "default_macro_classpath", - "default_repl_classpath", - ], -) +# ScalacProvider = provider( +# doc = "ScalacProvider", +# fields = [ +# "default_classpath", +# "default_macro_classpath", +# "default_repl_classpath", +# ], +# ) -def _declare_scalac_provider(ctx): - return [ - ScalacProvider( - default_classpath = ctx.attr.default_classpath, - default_repl_classpath = ctx.attr.default_repl_classpath, - default_macro_classpath = ctx.attr.default_macro_classpath, - ), - ] +# def _declare_scalac_provider(ctx): +# return [ +# ScalacProvider( +# default_classpath = ctx.attr.default_classpath, +# default_repl_classpath = ctx.attr.default_repl_classpath, +# default_macro_classpath = ctx.attr.default_macro_classpath, +# ), +# ] -declare_scalac_provider = rule( - implementation = _declare_scalac_provider, - attrs = { - "default_classpath": attr.label_list(allow_files = True), - "default_repl_classpath": attr.label_list(allow_files = True), - "default_macro_classpath": attr.label_list(allow_files = True), - }, -) +# declare_scalac_provider = rule( +# implementation = _declare_scalac_provider, +# attrs = { +# "default_classpath": attr.label_list(allow_files = True), +# "default_repl_classpath": attr.label_list(allow_files = True), +# "default_macro_classpath": attr.label_list(allow_files = True), +# }, +# ) diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index f57e23302..f9264bb74 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -1,12 +1,7 @@ -load( - "@io_bazel_rules_scala//scala:providers.bzl", - _ScalacProvider = "ScalacProvider", -) - def _scala_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( scalacopts = ctx.attr.scalacopts, - scalac_provider_attr = ctx.attr.scalac_provider_attr, + # scalac_provider_attr = ctx.attr.scalac_provider_attr, unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, plus_one_deps_mode = ctx.attr.plus_one_deps_mode, enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, @@ -19,10 +14,10 @@ scala_toolchain = rule( _scala_toolchain_impl, attrs = { "scalacopts": attr.string_list(), - "scalac_provider_attr": attr.label( - default = "@io_bazel_rules_scala//scala:scalac_default", - providers = [_ScalacProvider], - ), + # "scalac_provider_attr": attr.label( + # default = "@io_bazel_rules_scala//scala:scalac_default", + # providers = [_ScalacProvider], + # ), "unused_dependency_checker_mode": attr.string( default = "off", values = ["off", "warn", "error"], @@ -39,3 +34,40 @@ scala_toolchain = rule( "scala_test_jvm_flags": attr.string_list(), }, ) + +def _test_toolchain_impl(ctx): + toolchain = platform_common.ToolchainInfo( + # scalacopts = ctx.attr.scalacopts, + # scalac_provider_attr = ctx.attr.scalac_provider_attr, + # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, + # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, + # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, + # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, + # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, + ) + return [toolchain] + +test_toolchain = rule( + _test_toolchain_impl, + attrs = { + # "scalacopts": attr.string_list(), + # "scalac_provider_attr": attr.label( + # default = "@io_bazel_rules_scala//scala:scalac_default", + # providers = [_ScalacProvider], + # ), + # "unused_dependency_checker_mode": attr.string( + # default = "off", + # values = ["off", "warn", "error"], + # ), + # "plus_one_deps_mode": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "enable_code_coverage_aspect": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "scalac_jvm_flags": attr.string_list(), + # "scala_test_jvm_flags": attr.string_list(), + }, +) diff --git a/scala/test_toolchain.bzl b/scala/test_toolchain.bzl new file mode 100644 index 000000000..62491f643 --- /dev/null +++ b/scala/test_toolchain.bzl @@ -0,0 +1,36 @@ +def _test_toolchain_impl(ctx): + toolchain = platform_common.ToolchainInfo( + # scalacopts = ctx.attr.scalacopts, + # scalac_provider_attr = ctx.attr.scalac_provider_attr, + # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, + # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, + # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, + # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, + # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, + ) + return [toolchain] + +test_toolchain = rule( + _test_toolchain_impl, + attrs = { + # "scalacopts": attr.string_list(), + # "scalac_provider_attr": attr.label( + # default = "@io_bazel_rules_scala//scala:scalac_default", + # providers = [_ScalacProvider], + # ), + # "unused_dependency_checker_mode": attr.string( + # default = "off", + # values = ["off", "warn", "error"], + # ), + # "plus_one_deps_mode": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "enable_code_coverage_aspect": attr.string( + # default = "off", + # values = ["off", "on"], + # ), + # "scalac_jvm_flags": attr.string_list(), + # "scala_test_jvm_flags": attr.string_list(), + }, +) diff --git a/scala/toolchains.bzl b/scala/toolchains.bzl index 89a2bdc08..35e6fa4d3 100644 --- a/scala/toolchains.bzl +++ b/scala/toolchains.bzl @@ -1,5 +1,7 @@ def scala_register_toolchains(): - native.register_toolchains("@io_bazel_rules_scala//scala:default_toolchain") + native.register_toolchains("@io_bazel_rules_scala//scala:bootstrap_toolchain") + native.register_toolchains("@io_bazel_rules_scala//scala:toolchain") + native.register_toolchains("@io_bazel_rules_scala//scala:test_toolchain") def scala_register_unused_deps_toolchains(): native.register_toolchains( diff --git a/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl b/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl index 6636a3add..e6223dafc 100644 --- a/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl +++ b/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl @@ -1,7 +1,7 @@ -load( - "@io_bazel_rules_scala//scala:providers.bzl", - _ScalacProvider = "ScalacProvider", -) +# load( +# "@io_bazel_rules_scala//scala:providers.bzl", +# _ScalacProvider = "ScalacProvider", +# ) def _files_of(deps): files = [] @@ -10,7 +10,8 @@ def _files_of(deps): return depset(transitive = files) def _export_scalac_repositories_from_toolchain_to_jvm_impl(ctx): - default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider].default_repl_classpath + # default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider].default_repl_classpath + default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapInfo.repl_classpath default_repl_classpath_files = _files_of( default_repl_classpath_deps, ).to_list() @@ -19,5 +20,5 @@ def _export_scalac_repositories_from_toolchain_to_jvm_impl(ctx): export_scalac_repositories_from_toolchain_to_jvm = rule( _export_scalac_repositories_from_toolchain_to_jvm_impl, - toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"], + toolchains = ["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"], ) diff --git a/test/src/main/scala/scalarules/test/twitter_scrooge/twitter_scrooge_test.bzl b/test/src/main/scala/scalarules/test/twitter_scrooge/twitter_scrooge_test.bzl index 8432659fc..1805d642c 100644 --- a/test/src/main/scala/scalarules/test/twitter_scrooge/twitter_scrooge_test.bzl +++ b/test/src/main/scala/scalarules/test/twitter_scrooge/twitter_scrooge_test.bzl @@ -1,4 +1,4 @@ -load("@bazel_skylib//:lib.bzl", "asserts", "unittest") +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") load("//thrift:thrift.bzl", "thrift_library") From fa7265fa5449c8844a4a84dbbdecd9b4611b171c Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 10:44:20 -0800 Subject: [PATCH 21/37] wip --- scala/BUILD | 6 ++---- scala/private/phases/phase_scalac_provider.bzl | 5 ----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/scala/BUILD b/scala/BUILD index f5200bf4c..c1bbfcc7f 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -1,11 +1,9 @@ -# load( -# "@io_bazel_rules_scala//scala:providers.bzl", -# _declare_scalac_provider = "declare_scalac_provider", -# ) load("//scala:bootstrap_toolchain.bzl", "bootstrap_toolchain") load("//scala:scala_toolchain.bzl", "scala_toolchain") load("//scala:test_toolchain.bzl", "test_toolchain") +# default toolchains registered by `scala_register_toolchains` + # bootstrap toolchain toolchain_type( diff --git a/scala/private/phases/phase_scalac_provider.bzl b/scala/private/phases/phase_scalac_provider.bzl index 83ea42bad..daf8c88e3 100644 --- a/scala/private/phases/phase_scalac_provider.bzl +++ b/scala/private/phases/phase_scalac_provider.bzl @@ -3,11 +3,6 @@ # # DOCUMENT THIS # -# load( -# "@io_bazel_rules_scala//scala:providers.bzl", -# _ScalacProvider = "ScalacProvider", -# ) def phase_scalac_provider(ctx, p): - # return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider] return ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"] From 052e029497820437a8e974bd1c07b24474cface1 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 11:53:26 -0800 Subject: [PATCH 22/37] cleanup --- scala/bootstrap_toolchain.bzl | 27 +------------- scala/private/phases/phase_collect_jars.bzl | 8 ++-- scala/private/phases/phase_compile.bzl | 16 ++++---- scala/scala_toolchain.bzl | 37 ------------------- .../scalac/jvm_export_toolchain.bzl | 8 +--- 5 files changed, 14 insertions(+), 82 deletions(-) diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl index 78c61eda8..5bd63bd89 100644 --- a/scala/bootstrap_toolchain.bzl +++ b/scala/bootstrap_toolchain.bzl @@ -9,18 +9,11 @@ BootstrapInfo = provider( def _impl(ctx): toolchain = platform_common.ToolchainInfo( - bootstrapInfo = BootstrapInfo( + bootstrapinfo = BootstrapInfo( classpath = ctx.attr.classpath, macro_classpath = ctx.attr.macro_classpath, repl_classpath = ctx.attr.repl_classpath, ) - # scalacopts = ctx.attr.scalacopts, - # scalac_provider_attr = ctx.attr.scalac_provider_attr, - # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, - # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, - # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, - # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, - # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) return [toolchain] @@ -30,23 +23,5 @@ bootstrap_toolchain = rule( "classpath": attr.label_list(mandatory=True, allow_files = True), "repl_classpath": attr.label_list(mandatory=True, allow_files = True), "macro_classpath": attr.label_list(mandatory=True, allow_files = True), - # "scalacopts": attr.string_list(), - # "scalac_provider_attr": attr.label( - # default = "@io_bazel_rules_scala//scala:scalac_default", - # providers = [_ScalacProvider], - # ), - # "unused_dependency_checker_mode": attr.string( - # default = "off", - # values = ["off", "warn", "error"], - # ), - # "plus_one_deps_mode": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "enable_code_coverage_aspect": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "scalac_jvm_flags": attr.string_list(), }, ) diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index 8f6c86c36..e5efea2ba 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -15,7 +15,7 @@ load( def phase_collect_jars_scalatest(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapInfo.classpath + [ctx.attr._scalatest], + base_classpath = p.scalac_provider.bootstrapinfo.classpath + [ctx.attr._scalatest], extra_runtime_deps = [ ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner, @@ -25,13 +25,13 @@ def phase_collect_jars_scalatest(ctx, p): def phase_collect_jars_repl(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapInfo.repl_classpath, + base_classpath = p.scalac_provider.bootstrapinfo.repl_classpath, ) return _phase_collect_jars_default(ctx, p, args) def phase_collect_jars_macro_library(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapInfo.macro_classpath, + base_classpath = p.scalac_provider.bootstrapinfo.macro_classpath, ) return _phase_collect_jars_default(ctx, p, args) @@ -58,7 +58,7 @@ def phase_collect_jars_common(ctx, p): def _phase_collect_jars_default(ctx, p, _args = struct()): return _phase_collect_jars( ctx, - _args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.bootstrapInfo.classpath, + _args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.bootstrapinfo.classpath, _args.extra_deps if hasattr(_args, "extra_deps") else [], _args.extra_runtime_deps if hasattr(_args, "extra_runtime_deps") else [], _args.unused_dependency_checker_mode if hasattr(_args, "unused_dependency_checker_mode") else p.unused_deps_checker, diff --git a/scala/private/phases/phase_compile.bzl b/scala/private/phases/phase_compile.bzl index 5fe184e87..826f662a3 100644 --- a/scala/private/phases/phase_compile.bzl +++ b/scala/private/phases/phase_compile.bzl @@ -34,7 +34,7 @@ def phase_compile_binary(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.classpath + + for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -45,7 +45,7 @@ def phase_compile_library(ctx, p): srcjars = p.collect_srcjars, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.exports + + for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -55,7 +55,7 @@ def phase_compile_library_for_plugin_bootstrapping(ctx, p): args = struct( unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.classpath + ctx.attr.exports + for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.exports ], unused_dependency_checker_mode = "off", ) @@ -66,7 +66,7 @@ def phase_compile_macro_library(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.macro_classpath + ctx.attr.exports + + for target in p.scalac_provider.bootstrapinfo.macro_classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -81,7 +81,7 @@ def phase_compile_junit_test(ctx, p): ], unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.classpath + + for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ] + [ ctx.attr._junit.label, @@ -97,7 +97,7 @@ def phase_compile_repl(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.repl_classpath + + for target in p.scalac_provider.bootstrapinfo.repl_classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -108,7 +108,7 @@ def phase_compile_scalatest(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapInfo.classpath + + for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -143,7 +143,7 @@ def _phase_compile( transitive_compile_jars = p.collect_jars.transitive_compile_jars jars2labels = p.collect_jars.jars2labels.jars_to_labels deps_providers = p.collect_jars.deps_providers - default_classpath = p.scalac_provider.bootstrapInfo.classpath + default_classpath = p.scalac_provider.bootstrapinfo.classpath out = _compile_or_empty( ctx, diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index f9264bb74..ac0672a73 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -34,40 +34,3 @@ scala_toolchain = rule( "scala_test_jvm_flags": attr.string_list(), }, ) - -def _test_toolchain_impl(ctx): - toolchain = platform_common.ToolchainInfo( - # scalacopts = ctx.attr.scalacopts, - # scalac_provider_attr = ctx.attr.scalac_provider_attr, - # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, - # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, - # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, - # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, - # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, - ) - return [toolchain] - -test_toolchain = rule( - _test_toolchain_impl, - attrs = { - # "scalacopts": attr.string_list(), - # "scalac_provider_attr": attr.label( - # default = "@io_bazel_rules_scala//scala:scalac_default", - # providers = [_ScalacProvider], - # ), - # "unused_dependency_checker_mode": attr.string( - # default = "off", - # values = ["off", "warn", "error"], - # ), - # "plus_one_deps_mode": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "enable_code_coverage_aspect": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "scalac_jvm_flags": attr.string_list(), - # "scala_test_jvm_flags": attr.string_list(), - }, -) diff --git a/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl b/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl index e6223dafc..9075fcc7d 100644 --- a/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl +++ b/src/java/io/bazel/rulesscala/scalac/jvm_export_toolchain.bzl @@ -1,8 +1,3 @@ -# load( -# "@io_bazel_rules_scala//scala:providers.bzl", -# _ScalacProvider = "ScalacProvider", -# ) - def _files_of(deps): files = [] for dep in deps: @@ -10,8 +5,7 @@ def _files_of(deps): return depset(transitive = files) def _export_scalac_repositories_from_toolchain_to_jvm_impl(ctx): - # default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_provider_attr[_ScalacProvider].default_repl_classpath - default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapInfo.repl_classpath + default_repl_classpath_deps = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.repl_classpath default_repl_classpath_files = _files_of( default_repl_classpath_deps, ).to_list() From 2263bdf74a84523eb3bc91c8dc442da8b58f74db Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 12:10:07 -0800 Subject: [PATCH 23/37] cleanup --- private/example/BUILD.bazel | 2 -- scala/bootstrap_toolchain.bzl | 6 +++--- scala/providers.bzl | 26 -------------------------- scala/scala_toolchain.bzl | 5 ----- scala/test_toolchain.bzl | 26 -------------------------- 5 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 scala/providers.bzl diff --git a/private/example/BUILD.bazel b/private/example/BUILD.bazel index 8cb3d09c7..4fd5480ca 100644 --- a/private/example/BUILD.bazel +++ b/private/example/BUILD.bazel @@ -5,8 +5,6 @@ load( "scala_test", ) -# default case: builds all configured versions with version suffixes - scala_library( name = "library", srcs = glob( diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl index 5bd63bd89..375557f83 100644 --- a/scala/bootstrap_toolchain.bzl +++ b/scala/bootstrap_toolchain.bzl @@ -20,8 +20,8 @@ def _impl(ctx): bootstrap_toolchain = rule( _impl, attrs = { - "classpath": attr.label_list(mandatory=True, allow_files = True), - "repl_classpath": attr.label_list(mandatory=True, allow_files = True), - "macro_classpath": attr.label_list(mandatory=True, allow_files = True), + "classpath": attr.label_list(mandatory = True, allow_files = True), + "repl_classpath": attr.label_list(mandatory = True, allow_files = True), + "macro_classpath": attr.label_list(mandatory = True, allow_files = True), }, ) diff --git a/scala/providers.bzl b/scala/providers.bzl deleted file mode 100644 index dc6ce964d..000000000 --- a/scala/providers.bzl +++ /dev/null @@ -1,26 +0,0 @@ -# ScalacProvider = provider( -# doc = "ScalacProvider", -# fields = [ -# "default_classpath", -# "default_macro_classpath", -# "default_repl_classpath", -# ], -# ) - -# def _declare_scalac_provider(ctx): -# return [ -# ScalacProvider( -# default_classpath = ctx.attr.default_classpath, -# default_repl_classpath = ctx.attr.default_repl_classpath, -# default_macro_classpath = ctx.attr.default_macro_classpath, -# ), -# ] - -# declare_scalac_provider = rule( -# implementation = _declare_scalac_provider, -# attrs = { -# "default_classpath": attr.label_list(allow_files = True), -# "default_repl_classpath": attr.label_list(allow_files = True), -# "default_macro_classpath": attr.label_list(allow_files = True), -# }, -# ) diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index ac0672a73..22c648e3a 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -1,7 +1,6 @@ def _scala_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( scalacopts = ctx.attr.scalacopts, - # scalac_provider_attr = ctx.attr.scalac_provider_attr, unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, plus_one_deps_mode = ctx.attr.plus_one_deps_mode, enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, @@ -14,10 +13,6 @@ scala_toolchain = rule( _scala_toolchain_impl, attrs = { "scalacopts": attr.string_list(), - # "scalac_provider_attr": attr.label( - # default = "@io_bazel_rules_scala//scala:scalac_default", - # providers = [_ScalacProvider], - # ), "unused_dependency_checker_mode": attr.string( default = "off", values = ["off", "warn", "error"], diff --git a/scala/test_toolchain.bzl b/scala/test_toolchain.bzl index 62491f643..b6446f8cb 100644 --- a/scala/test_toolchain.bzl +++ b/scala/test_toolchain.bzl @@ -1,36 +1,10 @@ def _test_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( - # scalacopts = ctx.attr.scalacopts, - # scalac_provider_attr = ctx.attr.scalac_provider_attr, - # unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, - # plus_one_deps_mode = ctx.attr.plus_one_deps_mode, - # enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, - # scalac_jvm_flags = ctx.attr.scalac_jvm_flags, - # scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) return [toolchain] test_toolchain = rule( _test_toolchain_impl, attrs = { - # "scalacopts": attr.string_list(), - # "scalac_provider_attr": attr.label( - # default = "@io_bazel_rules_scala//scala:scalac_default", - # providers = [_ScalacProvider], - # ), - # "unused_dependency_checker_mode": attr.string( - # default = "off", - # values = ["off", "warn", "error"], - # ), - # "plus_one_deps_mode": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "enable_code_coverage_aspect": attr.string( - # default = "off", - # values = ["off", "on"], - # ), - # "scalac_jvm_flags": attr.string_list(), - # "scala_test_jvm_flags": attr.string_list(), }, ) From 236cafb4bde853184b189bb9affa9d704892279a Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 12:28:03 -0800 Subject: [PATCH 24/37] use bind to remove loader-specific labels in dependencies --- scala/BUILD | 14 +++++++------- scala/private/macros/scala_repositories.bzl | 15 +++++++++++++++ scala/scalatest/BUILD | 4 ++-- src/java/io/bazel/rulesscala/scalac/BUILD | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scala/BUILD b/scala/BUILD index a5c8f2416..7641b0eae 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -44,17 +44,17 @@ java_import( _declare_scalac_provider( name = "scalac_default", default_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], default_macro_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], default_repl_classpath = [ - "@io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scala_reflect", - "@io_bazel_rules_scala_scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", ], visibility = ["//visibility:public"], ) diff --git a/scala/private/macros/scala_repositories.bzl b/scala/private/macros/scala_repositories.bzl index a822993a3..2cdbbee63 100644 --- a/scala/private/macros/scala_repositories.bzl +++ b/scala/private/macros/scala_repositories.bzl @@ -199,3 +199,18 @@ def scala_repositories( name = "io_bazel_rules_scala/dependency/scala/guava", actual = "@io_bazel_rules_scala_guava", ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scalac_rules_commons_io", + actual = "@scalac_rules_commons_io", + ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scalatest/scalatest", + actual = "@io_bazel_rules_scala_scalatest", + ) + + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scalactic/scalactic", + actual = "@io_bazel_rules_scala_scalactic", + ) diff --git a/scala/scalatest/BUILD b/scala/scalatest/BUILD index 2e4ad67bb..4e7439e96 100644 --- a/scala/scalatest/BUILD +++ b/scala/scalatest/BUILD @@ -6,7 +6,7 @@ scala_import( name = "scalatest", jars = [], exports = [ - "@io_bazel_rules_scala_scalactic", - "@io_bazel_rules_scala_scalatest", + "//external:io_bazel_rules_scala/dependency/scala/scalactic/scalactic", + "//external:io_bazel_rules_scala/dependency/scala/scalatest/scalatest", ], ) diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index ec7f89795..f63f60f30 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -20,10 +20,10 @@ java_binary( visibility = ["//visibility:public"], deps = [ ":exported_scalac_repositories_from_toolchain_to_jvm", + "//external:io_bazel_rules_scala/dependency/scalac_rules_commons_io", "//third_party/bazel/src/main/protobuf:worker_protocol_java_proto", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/jar", "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/worker", - "@scalac_rules_commons_io//jar", ], ) From 6ef373b035d153eef9c1b38e2f689ee26341283d Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 13:45:58 -0800 Subject: [PATCH 25/37] simple test works; //test/... does not --- scala/BUILD | 3 ++ scala/private/common_attributes.bzl | 16 +++--- scala/private/phases/phase_collect_jars.bzl | 6 +-- .../private/phases/phase_write_executable.bzl | 2 +- scala/private/rules/scala_junit_test.bzl | 24 ++++----- scala/private/rules/scala_test.bzl | 52 +++++++++---------- scala/scala_toolchain.bzl | 2 - scala/test_toolchain.bzl | 8 +++ scala_proto/default_dep_sets.bzl | 2 +- specs2/BUILD | 2 +- .../bazel/rules_scala/scaladoc_support/BUILD | 6 +-- test/BUILD | 2 +- .../dependency_analyzer/src/test/BUILD | 16 +++--- twitter_scrooge/twitter_scrooge.bzl | 4 +- 14 files changed, 77 insertions(+), 68 deletions(-) diff --git a/scala/BUILD b/scala/BUILD index c1bbfcc7f..95060fc35 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -65,6 +65,9 @@ toolchain_type( test_toolchain( name = "test_toolchain_impl", + jar = "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + reporter = "//scala/support:test_reporter", + runner = "//src/java/io/bazel/rulesscala/scala_test:runner", visibility = ["//visibility:public"], ) diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index bd6c3fc3c..39b525824 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -118,12 +118,12 @@ launcher_template = { # Single dep to allow IDEs to pickup all the implicit dependencies. resolve_deps = { - "_scala_toolchain": attr.label_list( - default = [ - Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - ), - ], - allow_files = False, - ), + # "_scala_toolchain": attr.label_list( + # default = [ + # Label( + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # ), + # ], + # allow_files = False, + # ), } diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index e5efea2ba..ddf8b7bab 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -15,10 +15,10 @@ load( def phase_collect_jars_scalatest(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapinfo.classpath + [ctx.attr._scalatest], + base_classpath = p.scalac_provider.bootstrapinfo.classpath + [ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].jar], extra_runtime_deps = [ - ctx.attr._scalatest_reporter, - ctx.attr._scalatest_runner, + ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].reporter, + ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].runner, ], ) return _phase_collect_jars_default(ctx, p, args) diff --git a/scala/private/phases/phase_write_executable.bzl b/scala/private/phases/phase_write_executable.bzl index 3c8c11fbc..e6697c8d5 100644 --- a/scala/private/phases/phase_write_executable.bzl +++ b/scala/private/phases/phase_write_executable.bzl @@ -21,7 +21,7 @@ def phase_write_executable_scalatest(ctx, p): # toolchain final_jvm_flags = first_non_empty( ctx.attr.jvm_flags, - ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scala_test_jvm_flags, + ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].scala_test_jvm_flags, ) args = struct( rjars = p.coverage_runfiles.rjars, diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index 1933b14db..70b8be78b 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -86,18 +86,18 @@ _scala_junit_test_attrs = { } _junit_resolve_deps = { - "_scala_toolchain": attr.label_list( - default = [ - Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - ), - Label("//external:io_bazel_rules_scala/dependency/junit/junit"), - Label( - "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", - ), - ], - allow_files = False, - ), + # "_scala_toolchain": attr.label_list( + # default = [ + # Label( + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # ), + # Label("//external:io_bazel_rules_scala/dependency/junit/junit"), + # Label( + # "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", + # ), + # ], + # allow_files = False, + # ), } _scala_junit_test_attrs.update(launcher_template) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 6d70b045a..019169945 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -55,18 +55,18 @@ _scala_test_attrs = { "colors": attr.bool(default = True), "full_stacktraces": attr.bool(default = True), "jvm_flags": attr.string_list(), - "_scalatest": attr.label( - default = Label( - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", - ), - ), - "_scalatest_runner": attr.label( - cfg = "host", - default = Label("//src/java/io/bazel/rulesscala/scala_test:runner"), - ), - "_scalatest_reporter": attr.label( - default = Label("//scala/support:test_reporter"), - ), + # "_scalatest": attr.label( + # default = Label( + # "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + # ), + # ), + # "_scalatest_runner": attr.label( + # cfg = "host", + # default = Label("//src/java/io/bazel/rulesscala/scala_test:runner"), + # ), + # "_scalatest_reporter": attr.label( + # default = Label("//scala/support:test_reporter"), + # ), "_jacocorunner": attr.label( default = Label("@bazel_tools//tools/jdk:JacocoCoverage"), ), @@ -75,19 +75,19 @@ _scala_test_attrs = { ), } -_test_resolve_deps = { - "_scala_toolchain": attr.label_list( - default = [ - Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - ), - Label( - "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", - ), - ], - allow_files = False, - ), -} +# _test_resolve_deps = { +# "_scala_toolchain": attr.label_list( +# default = [ +# Label( +# "//external:io_bazel_rules_scala/dependency/scala/scala_library", +# ), +# Label( +# "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", +# ), +# ], +# allow_files = False, +# ), +# } _scala_test_attrs.update(launcher_template) @@ -95,7 +95,7 @@ _scala_test_attrs.update(implicit_deps) _scala_test_attrs.update(common_attrs) -_scala_test_attrs.update(_test_resolve_deps) +# _scala_test_attrs.update(_test_resolve_deps) def make_scala_test(*extras): return rule( diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index 22c648e3a..8349007e9 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -5,7 +5,6 @@ def _scala_toolchain_impl(ctx): plus_one_deps_mode = ctx.attr.plus_one_deps_mode, enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, scalac_jvm_flags = ctx.attr.scalac_jvm_flags, - scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) return [toolchain] @@ -26,6 +25,5 @@ scala_toolchain = rule( values = ["off", "on"], ), "scalac_jvm_flags": attr.string_list(), - "scala_test_jvm_flags": attr.string_list(), }, ) diff --git a/scala/test_toolchain.bzl b/scala/test_toolchain.bzl index b6446f8cb..e6e52b30f 100644 --- a/scala/test_toolchain.bzl +++ b/scala/test_toolchain.bzl @@ -1,10 +1,18 @@ def _test_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( + jar = ctx.attr.jar, + reporter = ctx.attr.reporter, + runner = ctx.attr.runner, + scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) return [toolchain] test_toolchain = rule( _test_toolchain_impl, attrs = { + "jar": attr.label(mandatory = True), + "reporter": attr.label(mandatory = True), + "runner": attr.label(mandatory = True), + "scala_test_jvm_flags": attr.string_list(), }, ) diff --git a/scala_proto/default_dep_sets.bzl b/scala_proto/default_dep_sets.bzl index 345890cd8..077c1193c 100644 --- a/scala_proto/default_dep_sets.bzl +++ b/scala_proto/default_dep_sets.bzl @@ -11,7 +11,7 @@ DEFAULT_SCALAPB_COMPILE_DEPS = [ "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", "//external:io_bazel_rules_scala/dependency/proto/scalapb_lenses", "//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", ] DEFAULT_SCALAPB_GRPC_DEPS = [ diff --git a/specs2/BUILD b/specs2/BUILD index d610597db..94dfda9e6 100644 --- a/specs2/BUILD +++ b/specs2/BUILD @@ -11,7 +11,7 @@ java_import( ], deps = [ "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//external:io_bazel_rules_scala/dependency/scala/scala_xml", ], diff --git a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD index b48ad5fb4..d8e95e77e 100644 --- a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD +++ b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD @@ -9,9 +9,9 @@ scala_binary( visibility = ["//visibility:public"], runtime_deps = [ "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", - "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//external:io_bazel_rules_scala/dependency/scala/scala_xml", ], ) diff --git a/test/BUILD b/test/BUILD index 892fc1841..60999aa9a 100644 --- a/test/BUILD +++ b/test/BUILD @@ -27,7 +27,7 @@ java_binary( main_class = "scalarules.test.JavaBinary", runtime_deps = [ ":OtherJavaLib", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", # ], deps = [ ":Exported", diff --git a/third_party/dependency_analyzer/src/test/BUILD b/third_party/dependency_analyzer/src/test/BUILD index 6428762b4..b4eedb1a9 100644 --- a/third_party/dependency_analyzer/src/test/BUILD +++ b/third_party/dependency_analyzer/src/test/BUILD @@ -10,15 +10,15 @@ scala_test( ], jvm_flags = [ "-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)", - "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", + "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", # "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)", ], unused_dependency_checker_mode = "off", deps = [ - "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//third_party/dependency_analyzer/src/main:dependency_analyzer", "//third_party/utils/src/test:test_util", "@com_google_guava_guava_21_0_with_file//jar", @@ -34,14 +34,14 @@ scala_test( ], jvm_flags = [ "-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)", - "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", + "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", # "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)", ], unused_dependency_checker_mode = "off", deps = [ - "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + # "//external:io_bazel_rules_scala/dependency/scala/scala_library", + # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//third_party/dependency_analyzer/src/main:dependency_analyzer", "//third_party/utils/src/test:test_util", "@org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file", diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index a0217d668..0a805bb29 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -346,7 +346,7 @@ scrooge_aspect = aspect( providers = [JavaInfo], default = [ Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", # ), Label( "//external:io_bazel_rules_scala/dependency/thrift/libthrift", @@ -423,7 +423,7 @@ scrooge_scala_import = rule( providers = [JavaInfo], default = [ Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", # ), Label( "//external:io_bazel_rules_scala/dependency/thrift/libthrift", From 794574bf85eaf68df7682693dc89bbc935bd1819 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 13:54:48 -0800 Subject: [PATCH 26/37] cleanup --- scala/private/rules/scala_test.bzl | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 019169945..a82cb5067 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -55,18 +55,6 @@ _scala_test_attrs = { "colors": attr.bool(default = True), "full_stacktraces": attr.bool(default = True), "jvm_flags": attr.string_list(), - # "_scalatest": attr.label( - # default = Label( - # "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", - # ), - # ), - # "_scalatest_runner": attr.label( - # cfg = "host", - # default = Label("//src/java/io/bazel/rulesscala/scala_test:runner"), - # ), - # "_scalatest_reporter": attr.label( - # default = Label("//scala/support:test_reporter"), - # ), "_jacocorunner": attr.label( default = Label("@bazel_tools//tools/jdk:JacocoCoverage"), ), From 7b756bd193eeb990289e342c8de1462eb3c2bd42 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 14:05:35 -0800 Subject: [PATCH 27/37] remove scalac provider and use toolchain resolution --- scala/private/phases/phase_collect_jars.bzl | 8 ++++---- scala/private/phases/phase_compile.bzl | 16 ++++++++-------- scala/private/phases/phase_scalac_provider.bzl | 8 -------- scala/private/phases/phases.bzl | 4 ---- scala/private/rules/scala_binary.bzl | 2 -- scala/private/rules/scala_junit_test.bzl | 2 -- scala/private/rules/scala_library.bzl | 4 ---- scala/private/rules/scala_repl.bzl | 2 -- scala/private/rules/scala_test.bzl | 2 -- 9 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 scala/private/phases/phase_scalac_provider.bzl diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index e5efea2ba..c3c9c010d 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -15,7 +15,7 @@ load( def phase_collect_jars_scalatest(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapinfo.classpath + [ctx.attr._scalatest], + base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + [ctx.attr._scalatest], extra_runtime_deps = [ ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner, @@ -25,13 +25,13 @@ def phase_collect_jars_scalatest(ctx, p): def phase_collect_jars_repl(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapinfo.repl_classpath, + base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.repl_classpath, ) return _phase_collect_jars_default(ctx, p, args) def phase_collect_jars_macro_library(ctx, p): args = struct( - base_classpath = p.scalac_provider.bootstrapinfo.macro_classpath, + base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.macro_classpath, ) return _phase_collect_jars_default(ctx, p, args) @@ -58,7 +58,7 @@ def phase_collect_jars_common(ctx, p): def _phase_collect_jars_default(ctx, p, _args = struct()): return _phase_collect_jars( ctx, - _args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.bootstrapinfo.classpath, + _args.base_classpath if hasattr(_args, "base_classpath") else ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath, _args.extra_deps if hasattr(_args, "extra_deps") else [], _args.extra_runtime_deps if hasattr(_args, "extra_runtime_deps") else [], _args.unused_dependency_checker_mode if hasattr(_args, "unused_dependency_checker_mode") else p.unused_deps_checker, diff --git a/scala/private/phases/phase_compile.bzl b/scala/private/phases/phase_compile.bzl index 826f662a3..b6c985b97 100644 --- a/scala/private/phases/phase_compile.bzl +++ b/scala/private/phases/phase_compile.bzl @@ -34,7 +34,7 @@ def phase_compile_binary(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.classpath + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -45,7 +45,7 @@ def phase_compile_library(ctx, p): srcjars = p.collect_srcjars, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.exports + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -55,7 +55,7 @@ def phase_compile_library_for_plugin_bootstrapping(ctx, p): args = struct( unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.classpath + ctx.attr.exports + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + ctx.attr.exports ], unused_dependency_checker_mode = "off", ) @@ -66,7 +66,7 @@ def phase_compile_macro_library(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.macro_classpath + ctx.attr.exports + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.macro_classpath + ctx.attr.exports + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -81,7 +81,7 @@ def phase_compile_junit_test(ctx, p): ], unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.classpath + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ] + [ ctx.attr._junit.label, @@ -97,7 +97,7 @@ def phase_compile_repl(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.repl_classpath + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.repl_classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -108,7 +108,7 @@ def phase_compile_scalatest(ctx, p): buildijar = False, unused_dependency_checker_ignored_targets = [ target.label - for target in p.scalac_provider.bootstrapinfo.classpath + + for target in ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + ctx.attr.unused_dependency_checker_ignored_targets ], ) @@ -143,7 +143,7 @@ def _phase_compile( transitive_compile_jars = p.collect_jars.transitive_compile_jars jars2labels = p.collect_jars.jars2labels.jars_to_labels deps_providers = p.collect_jars.deps_providers - default_classpath = p.scalac_provider.bootstrapinfo.classpath + default_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath out = _compile_or_empty( ctx, diff --git a/scala/private/phases/phase_scalac_provider.bzl b/scala/private/phases/phase_scalac_provider.bzl deleted file mode 100644 index daf8c88e3..000000000 --- a/scala/private/phases/phase_scalac_provider.bzl +++ /dev/null @@ -1,8 +0,0 @@ -# -# PHASE: scalac provider -# -# DOCUMENT THIS -# - -def phase_scalac_provider(ctx, p): - return ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"] diff --git a/scala/private/phases/phases.bzl b/scala/private/phases/phases.bzl index cc2396684..b18798da5 100644 --- a/scala/private/phases/phases.bzl +++ b/scala/private/phases/phases.bzl @@ -46,7 +46,6 @@ load( _phase_runfiles_scalatest = "phase_runfiles_scalatest", ) load("@io_bazel_rules_scala//scala/private:phases/phase_default_info.bzl", _phase_default_info = "phase_default_info") -load("@io_bazel_rules_scala//scala/private:phases/phase_scalac_provider.bzl", _phase_scalac_provider = "phase_scalac_provider") load("@io_bazel_rules_scala//scala/private:phases/phase_write_manifest.bzl", _phase_write_manifest = "phase_write_manifest") load("@io_bazel_rules_scala//scala/private:phases/phase_collect_srcjars.bzl", _phase_collect_srcjars = "phase_collect_srcjars") load("@io_bazel_rules_scala//scala/private:phases/phase_collect_exports_jars.bzl", _phase_collect_exports_jars = "phase_collect_exports_jars") @@ -61,9 +60,6 @@ load("@io_bazel_rules_scala//scala/private:phases/phase_scalafmt.bzl", _phase_sc run_phases = _run_phases extras_phases = _extras_phases -# scalac_provider -phase_scalac_provider = _phase_scalac_provider - # collect_srcjars phase_collect_srcjars = _phase_collect_srcjars diff --git a/scala/private/rules/scala_binary.bzl b/scala/private/rules/scala_binary.bzl index 4a8529b97..8f066155d 100644 --- a/scala/private/rules/scala_binary.bzl +++ b/scala/private/rules/scala_binary.bzl @@ -19,7 +19,6 @@ load( "phase_java_wrapper_common", "phase_merge_jars", "phase_runfiles_common", - "phase_scalac_provider", "phase_unused_deps_checker", "phase_write_executable_common", "phase_write_manifest", @@ -31,7 +30,6 @@ def _scala_binary_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), ("collect_jars", phase_collect_jars_common), diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index 1933b14db..4340ff583 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -19,7 +19,6 @@ load( "phase_jvm_flags", "phase_merge_jars", "phase_runfiles_common", - "phase_scalac_provider", "phase_unused_deps_checker", "phase_write_executable_junit_test", "phase_write_manifest", @@ -35,7 +34,6 @@ def _scala_junit_test_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), ("collect_jars", phase_collect_jars_junit_test), diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl index 7c1272a15..f2bc468d7 100644 --- a/scala/private/rules/scala_library.bzl +++ b/scala/private/rules/scala_library.bzl @@ -29,7 +29,6 @@ load( "phase_default_info", "phase_merge_jars", "phase_runfiles_library", - "phase_scalac_provider", "phase_unused_deps_checker", "phase_write_manifest", "run_phases", @@ -57,7 +56,6 @@ def _scala_library_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("collect_srcjars", phase_collect_srcjars), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), @@ -137,7 +135,6 @@ def _scala_library_for_plugin_bootstrapping_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("collect_srcjars", phase_collect_srcjars), ("write_manifest", phase_write_manifest), ("collect_jars", phase_collect_jars_library_for_plugin_bootstrapping), @@ -194,7 +191,6 @@ def _scala_macro_library_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("collect_srcjars", phase_collect_srcjars), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), diff --git a/scala/private/rules/scala_repl.bzl b/scala/private/rules/scala_repl.bzl index 3946467e5..d1aaa6380 100644 --- a/scala/private/rules/scala_repl.bzl +++ b/scala/private/rules/scala_repl.bzl @@ -19,7 +19,6 @@ load( "phase_java_wrapper_repl", "phase_merge_jars", "phase_runfiles_common", - "phase_scalac_provider", "phase_unused_deps_checker", "phase_write_executable_repl", "phase_write_manifest", @@ -31,7 +30,6 @@ def _scala_repl_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), # need scala-compiler for MainGenericRunner below diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 6d70b045a..2d6c82d16 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -20,7 +20,6 @@ load( "phase_java_wrapper_common", "phase_merge_jars", "phase_runfiles_scalatest", - "phase_scalac_provider", "phase_unused_deps_checker", "phase_write_executable_scalatest", "phase_write_manifest", @@ -32,7 +31,6 @@ def _scala_test_impl(ctx): ctx, # customizable phases [ - ("scalac_provider", phase_scalac_provider), ("write_manifest", phase_write_manifest), ("unused_deps_checker", phase_unused_deps_checker), ("collect_jars", phase_collect_jars_scalatest), From fdddc970ce02603ff650634ce5e3598cef68e20d Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 14:34:14 -0800 Subject: [PATCH 28/37] put the scalac dep into the toolchain This moves the scalac attr to the toolchain so it can be overriden by different toolchain implementations. It also adds a `ScalaInfo` provider level for scala_toolchain to follow the pattern in the scala docs (rather than flattening into the ToolchainInfo). --- scala/BUILD | 2 ++ scala/plusone.bzl | 2 +- scala/private/common_attributes.bzl | 5 ----- .../coverage_replacements_provider.bzl | 2 +- scala/private/phases/phase_compile.bzl | 1 - .../phases/phase_unused_deps_checker.bzl | 2 +- .../private/phases/phase_write_executable.bzl | 2 +- scala/private/rule_impls.bzl | 13 ++++++------ scala/scala_toolchain.bzl | 20 ++++++++++++++++++- scala/test_toolchain.bzl | 6 ++++++ scala_proto/private/scalapb_aspect.bzl | 4 +--- scala_proto/scala_proto_toolchain.bzl | 6 ------ test/coverage/BUILD | 1 + twitter_scrooge/twitter_scrooge.bzl | 1 - 14 files changed, 40 insertions(+), 27 deletions(-) diff --git a/scala/BUILD b/scala/BUILD index c1bbfcc7f..781bd64a5 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -46,6 +46,7 @@ toolchain_type( scala_toolchain( name = "toolchain_impl", scalacopts = [], + scalac = "//src/java/io/bazel/rulesscala/scalac", visibility = ["//visibility:public"], ) @@ -80,6 +81,7 @@ toolchain( scala_toolchain( name = "unused_dependency_checker_error_toolchain_impl", unused_dependency_checker_mode = "error", + scalac = "//src/java/io/bazel/rulesscala/scalac", visibility = ["//visibility:public"], ) diff --git a/scala/plusone.bzl b/scala/plusone.bzl index 1efd17093..fc858c894 100644 --- a/scala/plusone.bzl +++ b/scala/plusone.bzl @@ -10,7 +10,7 @@ PlusOneDeps = provider( ) def _collect_plus_one_deps_aspect_impl(target, ctx): - if (ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].plus_one_deps_mode == "off"): + if (ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.plus_one_deps_mode == "off"): return [] export_plus_one_deps = [] for exported_dep in getattr(ctx.rule.attr, "exports", []): diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index bd6c3fc3c..09c4c3464 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -98,11 +98,6 @@ implicit_deps = { "_java_runtime": attr.label( default = Label("@bazel_tools//tools/jdk:current_java_runtime"), ), - "_scalac": attr.label( - default = Label( - "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac", - ), - ), "_exe": attr.label( executable = True, cfg = "host", diff --git a/scala/private/coverage_replacements_provider.bzl b/scala/private/coverage_replacements_provider.bzl index 3d45bf64b..da9cc4a13 100644 --- a/scala/private/coverage_replacements_provider.bzl +++ b/scala/private/coverage_replacements_provider.bzl @@ -74,7 +74,7 @@ def _is_enabled(ctx): if "@io_bazel_rules_scala//scala:toolchain_type" not in ctx.toolchains: return False else: - return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].enable_code_coverage_aspect == "on" + return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.enable_code_coverage_aspect == "on" coverage_replacements_provider = struct( aspect = _aspect, diff --git a/scala/private/phases/phase_compile.bzl b/scala/private/phases/phase_compile.bzl index b6c985b97..7c421d976 100644 --- a/scala/private/phases/phase_compile.bzl +++ b/scala/private/phases/phase_compile.bzl @@ -239,7 +239,6 @@ def _compile_or_empty( ctx.attr.print_compile_time, ctx.attr.expect_java_output, ctx.attr.scalac_jvm_flags, - ctx.attr._scalac, unused_dependency_checker_ignored_targets = unused_dependency_checker_ignored_targets, unused_dependency_checker_mode = unused_dependency_checker_mode, diff --git a/scala/private/phases/phase_unused_deps_checker.bzl b/scala/private/phases/phase_unused_deps_checker.bzl index 21f0daebb..6529e7b35 100644 --- a/scala/private/phases/phase_unused_deps_checker.bzl +++ b/scala/private/phases/phase_unused_deps_checker.bzl @@ -8,4 +8,4 @@ def phase_unused_deps_checker(ctx, p): if ctx.attr.unused_dependency_checker_mode: return ctx.attr.unused_dependency_checker_mode else: - return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].unused_dependency_checker_mode + return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.unused_dependency_checker_mode diff --git a/scala/private/phases/phase_write_executable.bzl b/scala/private/phases/phase_write_executable.bzl index 3c8c11fbc..d89ac04c8 100644 --- a/scala/private/phases/phase_write_executable.bzl +++ b/scala/private/phases/phase_write_executable.bzl @@ -21,7 +21,7 @@ def phase_write_executable_scalatest(ctx, p): # toolchain final_jvm_flags = first_non_empty( ctx.attr.jvm_flags, - ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scala_test_jvm_flags, + ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.scala_test_jvm_flags, # to be moved to test toolchain ) args = struct( rjars = p.coverage_runfiles.rjars, diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index c5747d1ca..5fb4ea2dd 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -59,7 +59,6 @@ def compile_scala( print_compile_time, expect_java_output, scalac_jvm_flags, - scalac, unused_dependency_checker_mode = "off", unused_dependency_checker_ignored_targets = []): # look for any plugins: @@ -135,7 +134,7 @@ CurrentTarget: {current_target} compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) toolchain = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"] - scalacopts = [ctx.expand_location(v, input_plugins) for v in toolchain.scalacopts + in_scalacopts] + scalacopts = [ctx.expand_location(v, input_plugins) for v in toolchain.scalainfo.scalacopts + in_scalacopts] resource_paths = _resource_paths(resources, resource_strip_prefix) scalac_args = """ @@ -186,7 +185,7 @@ StatsfileOutput: {statsfile_output} ) scalac_inputs, _, scalac_input_manifests = ctx.resolve_command( - tools = [scalac], + tools = [ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.scalac], ) outs = [output, statsfile] @@ -196,17 +195,19 @@ StatsfileOutput: {statsfile_output} resource_jars + [manifest, argfile] + scalac_inputs ) + scalainfo = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo + # scalac_jvm_flags passed in on the target override scalac_jvm_flags passed in on the # toolchain final_scalac_jvm_flags = first_non_empty( scalac_jvm_flags, - ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalac_jvm_flags, + scalainfo.scalac_jvm_flags, ) ctx.actions.run( inputs = ins, outputs = outs, - executable = scalac.files_to_run.executable, + executable = scalainfo.scalac.files_to_run.executable, input_manifests = scalac_input_manifests, mnemonic = "Scalac", progress_message = "scala %s" % target_label, @@ -262,7 +263,7 @@ def is_dependency_analyzer_off(ctx): return not is_dependency_analyzer_on(ctx) def is_plus_one_deps_off(ctx): - return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].plus_one_deps_mode == "off" + return ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.plus_one_deps_mode == "off" def is_windows(ctx): return ctx.configuration.host_path_separator == ";" diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index 22c648e3a..cfb311c29 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -1,11 +1,28 @@ +ScalaInfo = provider( + doc = "ScalaInfo", + fields = [ + "scalacopts", + "unused_dependency_checker_mode", + "plus_one_deps_mode", + "enable_code_coverage_aspect", + "scalac_jvm_flags", + "scala_test_jvm_flags", + "scalac", + ], +) + def _scala_toolchain_impl(ctx): - toolchain = platform_common.ToolchainInfo( + scalainfo = ScalaInfo( scalacopts = ctx.attr.scalacopts, unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode, plus_one_deps_mode = ctx.attr.plus_one_deps_mode, enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, scalac_jvm_flags = ctx.attr.scalac_jvm_flags, scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, + scalac = ctx.attr.scalac, + ) + toolchain = platform_common.ToolchainInfo( + scalainfo = scalainfo, ) return [toolchain] @@ -27,5 +44,6 @@ scala_toolchain = rule( ), "scalac_jvm_flags": attr.string_list(), "scala_test_jvm_flags": attr.string_list(), + "scalac": attr.label(mandatory = True, allow_files = True), }, ) diff --git a/scala/test_toolchain.bzl b/scala/test_toolchain.bzl index b6446f8cb..b527a2bd1 100644 --- a/scala/test_toolchain.bzl +++ b/scala/test_toolchain.bzl @@ -1,3 +1,9 @@ +TestInfo = provider( + doc = "TestInfo", + fields = [ + ], +) + def _test_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( ) diff --git a/scala_proto/private/scalapb_aspect.bzl b/scala_proto/private/scalapb_aspect.bzl index 0d51cfb65..142e32ad0 100644 --- a/scala_proto/private/scalapb_aspect.bzl +++ b/scala_proto/private/scalapb_aspect.bzl @@ -46,7 +46,6 @@ def _compiled_jar_file(actions, scalapb_jar): def _compile_scala( ctx, - scalac, label, output, scalapb_jar, @@ -88,7 +87,6 @@ def _compile_scala( print_compile_time = False, expect_java_output = False, scalac_jvm_flags = [], - scalac = scalac, ) return JavaInfo( @@ -133,6 +131,7 @@ def _scalapb_aspect_impl(target, ctx): compile_protos = sorted(target_ti.direct_sources) transitive_protos = sorted(target_ti.transitive_sources.to_list()) + scala_toolchain = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"] toolchain = ctx.toolchains["@io_bazel_rules_scala//scala_proto:toolchain_type"] flags = [] imps = [j[JavaInfo] for j in ctx.attr._implicit_compile_deps] @@ -189,7 +188,6 @@ def _scalapb_aspect_impl(target, ctx): outs = depset([output]) java_info = _compile_scala( ctx, - toolchain.scalac, target.label, output, scalapb_file, diff --git a/scala_proto/scala_proto_toolchain.bzl b/scala_proto/scala_proto_toolchain.bzl index a733a2fbf..7fd5a7a79 100644 --- a/scala_proto/scala_proto_toolchain.bzl +++ b/scala_proto/scala_proto_toolchain.bzl @@ -8,7 +8,6 @@ def _scala_proto_toolchain_impl(ctx): blacklisted_protos = ctx.attr.blacklisted_protos, code_generator = ctx.attr.code_generator, extra_generator_dependencies = ctx.attr.extra_generator_dependencies, - scalac = ctx.attr.scalac, named_generators = ctx.attr.named_generators, ) return [toolchain] @@ -36,10 +35,5 @@ scala_proto_toolchain = rule( "extra_generator_dependencies": attr.label_list( providers = [JavaInfo], ), - "scalac": attr.label( - default = Label( - "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac", - ), - ), }, ) diff --git a/test/coverage/BUILD b/test/coverage/BUILD index 1d3cc583b..0adeeb6f6 100644 --- a/test/coverage/BUILD +++ b/test/coverage/BUILD @@ -4,6 +4,7 @@ load("//scala:scala_toolchain.bzl", "scala_toolchain") scala_toolchain( name = "enable_code_coverage_aspect_impl", enable_code_coverage_aspect = "on", + scalac = "//src/java/io/bazel/rulesscala/scalac", visibility = ["//visibility:public"], ) diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index a0217d668..f3968a665 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -238,7 +238,6 @@ def _compile_scala( print_compile_time = False, expect_java_output = False, scalac_jvm_flags = [], - scalac = ctx.attr._scalac, ) return JavaInfo( From c24416183433183a026f6bd582f8c2f3b215502a Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 15:21:27 -0800 Subject: [PATCH 29/37] missed these pieces --- scala/private/phases/phase_collect_jars.bzl | 6 +++--- scala/scala_toolchain.bzl | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index a6ad2c363..74851e3eb 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -15,10 +15,10 @@ load( def phase_collect_jars_scalatest(ctx, p): args = struct( - base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + [ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].jar], + base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + [ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.jar], extra_runtime_deps = [ - ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].reporter, - ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].runner, + ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.reporter, + ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.runner, ], ) return _phase_collect_jars_default(ctx, p, args) diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index b4ccf1ec4..7b388297f 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -6,7 +6,6 @@ ScalaInfo = provider( "plus_one_deps_mode", "enable_code_coverage_aspect", "scalac_jvm_flags", - "scala_test_jvm_flags", "scalac", ], ) @@ -18,7 +17,7 @@ def _scala_toolchain_impl(ctx): plus_one_deps_mode = ctx.attr.plus_one_deps_mode, enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect, scalac_jvm_flags = ctx.attr.scalac_jvm_flags, - scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, + scalac = ctx.attr.scalac, ) toolchain = platform_common.ToolchainInfo( scalainfo = scalainfo, From d68b94c0a3dd5e1a45fa9345f88398fe9d0c0152 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 15:53:43 -0800 Subject: [PATCH 30/37] wip --- src/java/io/bazel/rulesscala/scalac/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index ec7f89795..ffdca9af8 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -1,9 +1,9 @@ load( ":jvm_export_toolchain.bzl", - _export_scalac_repositories_from_toolchain_to_jvm = "export_scalac_repositories_from_toolchain_to_jvm", + "export_scalac_repositories_from_toolchain_to_jvm", ) -_export_scalac_repositories_from_toolchain_to_jvm( +export_scalac_repositories_from_toolchain_to_jvm( name = "exported_scalac_repositories_from_toolchain_to_jvm", ) From ac4389289d42b1c85d9e3c44549be064250c1d30 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 18:11:36 -0800 Subject: [PATCH 31/37] cleanup handling of toolchains --- scala/private/common_attributes.bzl | 16 +++++------ scala/private/rules/scala_junit_test.bzl | 24 ++++++++-------- scala/private/rules/scala_test.bzl | 28 +++++++++---------- scala_proto/private/scalapb_aspect.bzl | 5 ++-- scala_proto/scala_proto_toolchain.bzl | 2 -- .../bazel/rules_scala/scaladoc_support/BUILD | 7 +++-- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/scala/private/common_attributes.bzl b/scala/private/common_attributes.bzl index 0a21eb984..09c4c3464 100644 --- a/scala/private/common_attributes.bzl +++ b/scala/private/common_attributes.bzl @@ -113,12 +113,12 @@ launcher_template = { # Single dep to allow IDEs to pickup all the implicit dependencies. resolve_deps = { - # "_scala_toolchain": attr.label_list( - # default = [ - # Label( - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", - # ), - # ], - # allow_files = False, - # ), + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + ), + ], + allow_files = False, + ), } diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index b56b08fd1..4340ff583 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -84,18 +84,18 @@ _scala_junit_test_attrs = { } _junit_resolve_deps = { - # "_scala_toolchain": attr.label_list( - # default = [ - # Label( - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", - # ), - # Label("//external:io_bazel_rules_scala/dependency/junit/junit"), - # Label( - # "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", - # ), - # ], - # allow_files = False, - # ), + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + ), + Label("//external:io_bazel_rules_scala/dependency/junit/junit"), + Label( + "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core", + ), + ], + allow_files = False, + ), } _scala_junit_test_attrs.update(launcher_template) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 173167328..04e42fb2f 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -61,19 +61,19 @@ _scala_test_attrs = { ), } -# _test_resolve_deps = { -# "_scala_toolchain": attr.label_list( -# default = [ -# Label( -# "//external:io_bazel_rules_scala/dependency/scala/scala_library", -# ), -# Label( -# "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", -# ), -# ], -# allow_files = False, -# ), -# } +_test_resolve_deps = { + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + ), + Label( + "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + ), + ], + allow_files = False, + ), +} _scala_test_attrs.update(launcher_template) @@ -81,7 +81,7 @@ _scala_test_attrs.update(implicit_deps) _scala_test_attrs.update(common_attrs) -# _scala_test_attrs.update(_test_resolve_deps) +_scala_test_attrs.update(_test_resolve_deps) def make_scala_test(*extras): return rule( diff --git a/scala_proto/private/scalapb_aspect.bzl b/scala_proto/private/scalapb_aspect.bzl index 142e32ad0..47c7605f2 100644 --- a/scala_proto/private/scalapb_aspect.bzl +++ b/scala_proto/private/scalapb_aspect.bzl @@ -131,10 +131,10 @@ def _scalapb_aspect_impl(target, ctx): compile_protos = sorted(target_ti.direct_sources) transitive_protos = sorted(target_ti.transitive_sources.to_list()) - scala_toolchain = ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"] toolchain = ctx.toolchains["@io_bazel_rules_scala//scala_proto:toolchain_type"] + boostrap_toolchain = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"] flags = [] - imps = [j[JavaInfo] for j in ctx.attr._implicit_compile_deps] + imps = [j[JavaInfo] for j in ctx.attr._implicit_compile_deps + boostrap_toolchain.bootstrapinfo.classpath] if toolchain.with_grpc: flags.append("grpc") @@ -234,6 +234,7 @@ scalapb_aspect = aspect( ]), }, toolchains = [ + "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", "@io_bazel_rules_scala//scala:toolchain_type", "@io_bazel_rules_scala//scala_proto:toolchain_type", ], diff --git a/scala_proto/scala_proto_toolchain.bzl b/scala_proto/scala_proto_toolchain.bzl index 7fd5a7a79..1ef1ad98e 100644 --- a/scala_proto/scala_proto_toolchain.bzl +++ b/scala_proto/scala_proto_toolchain.bzl @@ -1,5 +1,3 @@ -load("//scala_proto:default_dep_sets.bzl", "DEFAULT_SCALAPB_COMPILE_DEPS", "DEFAULT_SCALAPB_GRPC_DEPS") - def _scala_proto_toolchain_impl(ctx): toolchain = platform_common.ToolchainInfo( with_grpc = ctx.attr.with_grpc, diff --git a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD index d8e95e77e..e53e7c241 100644 --- a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD +++ b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD @@ -1,3 +1,4 @@ + load("//scala:scala.bzl", "scala_binary") # A simple scala_binary to run scaladoc. @@ -9,9 +10,9 @@ scala_binary( visibility = ["//visibility:public"], runtime_deps = [ "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", - # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", - # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//external:io_bazel_rules_scala/dependency/scala/scala_xml", ], ) From 578ad8f655c118361622cf2d1002ce21c5e88a66 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 18:17:52 -0800 Subject: [PATCH 32/37] cleanup --- scala_proto/default_dep_sets.bzl | 1 - specs2/BUILD | 2 +- src/scala/io/bazel/rules_scala/scaladoc_support/BUILD | 1 - test/BUILD | 2 +- third_party/dependency_analyzer/src/test/BUILD | 6 ------ twitter_scrooge/twitter_scrooge.bzl | 4 ++-- 6 files changed, 4 insertions(+), 12 deletions(-) diff --git a/scala_proto/default_dep_sets.bzl b/scala_proto/default_dep_sets.bzl index 077c1193c..6a5878727 100644 --- a/scala_proto/default_dep_sets.bzl +++ b/scala_proto/default_dep_sets.bzl @@ -11,7 +11,6 @@ DEFAULT_SCALAPB_COMPILE_DEPS = [ "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", "//external:io_bazel_rules_scala/dependency/proto/scalapb_lenses", "//external:io_bazel_rules_scala/dependency/proto/scalapb_fastparse", - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", ] DEFAULT_SCALAPB_GRPC_DEPS = [ diff --git a/specs2/BUILD b/specs2/BUILD index 94dfda9e6..d610597db 100644 --- a/specs2/BUILD +++ b/specs2/BUILD @@ -11,7 +11,7 @@ java_import( ], deps = [ "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", # + "//external:io_bazel_rules_scala/dependency/scala/scala_library", "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//external:io_bazel_rules_scala/dependency/scala/scala_xml", ], diff --git a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD index e53e7c241..b48ad5fb4 100644 --- a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD +++ b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD @@ -1,4 +1,3 @@ - load("//scala:scala.bzl", "scala_binary") # A simple scala_binary to run scaladoc. diff --git a/test/BUILD b/test/BUILD index 60999aa9a..892fc1841 100644 --- a/test/BUILD +++ b/test/BUILD @@ -27,7 +27,7 @@ java_binary( main_class = "scalarules.test.JavaBinary", runtime_deps = [ ":OtherJavaLib", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", # + "//external:io_bazel_rules_scala/dependency/scala/scala_library", ], deps = [ ":Exported", diff --git a/third_party/dependency_analyzer/src/test/BUILD b/third_party/dependency_analyzer/src/test/BUILD index b4eedb1a9..0b230b836 100644 --- a/third_party/dependency_analyzer/src/test/BUILD +++ b/third_party/dependency_analyzer/src/test/BUILD @@ -16,9 +16,6 @@ scala_test( ], unused_dependency_checker_mode = "off", deps = [ - # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", - # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//third_party/dependency_analyzer/src/main:dependency_analyzer", "//third_party/utils/src/test:test_util", "@com_google_guava_guava_21_0_with_file//jar", @@ -39,9 +36,6 @@ scala_test( ], unused_dependency_checker_mode = "off", deps = [ - # "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - # "//external:io_bazel_rules_scala/dependency/scala/scala_library", - # "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", "//third_party/dependency_analyzer/src/main:dependency_analyzer", "//third_party/utils/src/test:test_util", "@org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file", diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index 56519b7a5..f3968a665 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -345,7 +345,7 @@ scrooge_aspect = aspect( providers = [JavaInfo], default = [ Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", # + "//external:io_bazel_rules_scala/dependency/scala/scala_library", ), Label( "//external:io_bazel_rules_scala/dependency/thrift/libthrift", @@ -422,7 +422,7 @@ scrooge_scala_import = rule( providers = [JavaInfo], default = [ Label( - "//external:io_bazel_rules_scala/dependency/scala/scala_library", # + "//external:io_bazel_rules_scala/dependency/scala/scala_library", ), Label( "//external:io_bazel_rules_scala/dependency/thrift/libthrift", From 05ed1e4bf38a058d2e57b97a21b1e220f464689f Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 18:26:45 -0800 Subject: [PATCH 33/37] unused arguements --- third_party/dependency_analyzer/src/test/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/third_party/dependency_analyzer/src/test/BUILD b/third_party/dependency_analyzer/src/test/BUILD index 0b230b836..cadc55427 100644 --- a/third_party/dependency_analyzer/src/test/BUILD +++ b/third_party/dependency_analyzer/src/test/BUILD @@ -10,7 +10,6 @@ scala_test( ], jvm_flags = [ "-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)", - "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", # "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)", ], @@ -31,7 +30,6 @@ scala_test( ], jvm_flags = [ "-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)", - "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", # "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)", ], unused_dependency_checker_mode = "off", From a5e38a4f2a73f3970e08a390a8a94fe0ebcb687a Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 21:11:24 -0800 Subject: [PATCH 34/37] lint --- WORKSPACE | 1 + private/example/WORKSPACE | 2 ++ scala/BUILD | 1 + scala/bootstrap_toolchain.bzl | 2 +- scala/private/rules/scala_binary.bzl | 2 +- scala/private/rules/scala_library.bzl | 6 +++--- scala/private/rules/scala_repl.bzl | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 08ecaeff9..054ed1478 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,6 +16,7 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen buildifier_dependencies() load("//scala:toolchains.bzl", "scala_register_toolchains") + scala_register_toolchains() load("//scala:scala.bzl", "scala_repositories") diff --git a/private/example/WORKSPACE b/private/example/WORKSPACE index 930408d14..96a04949f 100644 --- a/private/example/WORKSPACE +++ b/private/example/WORKSPACE @@ -19,7 +19,9 @@ load("//repositories:rules_python.bzl", "load_rules_python") load_rules_python() load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + scala_register_toolchains() load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") + scala_repositories() diff --git a/scala/BUILD b/scala/BUILD index c1bbfcc7f..f525abff5 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -95,6 +95,7 @@ java_import( jars = ["@bazel_tools//tools/jdk:TestRunner_deploy.jar"], visibility = ["//visibility:public"], ) + java_library( name = "PlaceHolderClassToCreateEmptyJarForScalaImport", srcs = ["PlaceHolderClassToCreateEmptyJarForScalaImport.java"], diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl index 375557f83..b1b2628f8 100644 --- a/scala/bootstrap_toolchain.bzl +++ b/scala/bootstrap_toolchain.bzl @@ -13,7 +13,7 @@ def _impl(ctx): classpath = ctx.attr.classpath, macro_classpath = ctx.attr.macro_classpath, repl_classpath = ctx.attr.repl_classpath, - ) + ), ) return [toolchain] diff --git a/scala/private/rules/scala_binary.bzl b/scala/private/rules/scala_binary.bzl index 4a8529b97..fa1569388 100644 --- a/scala/private/rules/scala_binary.bzl +++ b/scala/private/rules/scala_binary.bzl @@ -75,7 +75,7 @@ def make_scala_binary(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_binary_impl, ) diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl index 7c1272a15..cc31a5cb0 100644 --- a/scala/private/rules/scala_library.bzl +++ b/scala/private/rules/scala_library.bzl @@ -94,7 +94,7 @@ def make_scala_library(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_library_impl, ) @@ -178,7 +178,7 @@ def make_scala_library_for_plugin_bootstrapping(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_library_for_plugin_bootstrapping_impl, ) @@ -246,7 +246,7 @@ def make_scala_macro_library(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_macro_library_impl, ) diff --git a/scala/private/rules/scala_repl.bzl b/scala/private/rules/scala_repl.bzl index 3946467e5..66f6138f6 100644 --- a/scala/private/rules/scala_repl.bzl +++ b/scala/private/rules/scala_repl.bzl @@ -74,7 +74,7 @@ def make_scala_repl(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_repl_impl, ) From 0d8f08c627c044d49626d6ed5534efb1de87085c Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Thu, 30 Jan 2020 21:14:23 -0800 Subject: [PATCH 35/37] lib --- scala/BUILD | 4 ++-- scala/private/phases/phase_write_executable.bzl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/BUILD b/scala/BUILD index 42b85e2ea..fdf42f72e 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -45,8 +45,8 @@ toolchain_type( scala_toolchain( name = "toolchain_impl", - scalacopts = [], scalac = "//src/java/io/bazel/rulesscala/scalac", + scalacopts = [], visibility = ["//visibility:public"], ) @@ -80,8 +80,8 @@ toolchain( scala_toolchain( name = "unused_dependency_checker_error_toolchain_impl", - unused_dependency_checker_mode = "error", scalac = "//src/java/io/bazel/rulesscala/scalac", + unused_dependency_checker_mode = "error", visibility = ["//visibility:public"], ) diff --git a/scala/private/phases/phase_write_executable.bzl b/scala/private/phases/phase_write_executable.bzl index d89ac04c8..aae6e5c6f 100644 --- a/scala/private/phases/phase_write_executable.bzl +++ b/scala/private/phases/phase_write_executable.bzl @@ -21,7 +21,7 @@ def phase_write_executable_scalatest(ctx, p): # toolchain final_jvm_flags = first_non_empty( ctx.attr.jvm_flags, - ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.scala_test_jvm_flags, # to be moved to test toolchain + ctx.toolchains["@io_bazel_rules_scala//scala:toolchain_type"].scalainfo.scala_test_jvm_flags, # to be moved to test toolchain ) args = struct( rjars = p.coverage_runfiles.rjars, From a4b7d3c732254d801fe8ec89f5b39bdd0f4b5097 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Fri, 31 Jan 2020 10:04:52 -0800 Subject: [PATCH 36/37] lint --- WORKSPACE | 1 + private/example/WORKSPACE | 2 ++ scala/bootstrap_toolchain.bzl | 2 +- scala/private/rules/scala_binary.bzl | 2 +- scala/private/rules/scala_library.bzl | 6 +++--- scala/private/rules/scala_repl.bzl | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 08ecaeff9..054ed1478 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,6 +16,7 @@ load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_depen buildifier_dependencies() load("//scala:toolchains.bzl", "scala_register_toolchains") + scala_register_toolchains() load("//scala:scala.bzl", "scala_repositories") diff --git a/private/example/WORKSPACE b/private/example/WORKSPACE index 930408d14..96a04949f 100644 --- a/private/example/WORKSPACE +++ b/private/example/WORKSPACE @@ -19,7 +19,9 @@ load("//repositories:rules_python.bzl", "load_rules_python") load_rules_python() load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + scala_register_toolchains() load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") + scala_repositories() diff --git a/scala/bootstrap_toolchain.bzl b/scala/bootstrap_toolchain.bzl index 375557f83..b1b2628f8 100644 --- a/scala/bootstrap_toolchain.bzl +++ b/scala/bootstrap_toolchain.bzl @@ -13,7 +13,7 @@ def _impl(ctx): classpath = ctx.attr.classpath, macro_classpath = ctx.attr.macro_classpath, repl_classpath = ctx.attr.repl_classpath, - ) + ), ) return [toolchain] diff --git a/scala/private/rules/scala_binary.bzl b/scala/private/rules/scala_binary.bzl index 4a8529b97..fa1569388 100644 --- a/scala/private/rules/scala_binary.bzl +++ b/scala/private/rules/scala_binary.bzl @@ -75,7 +75,7 @@ def make_scala_binary(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_binary_impl, ) diff --git a/scala/private/rules/scala_library.bzl b/scala/private/rules/scala_library.bzl index 7c1272a15..cc31a5cb0 100644 --- a/scala/private/rules/scala_library.bzl +++ b/scala/private/rules/scala_library.bzl @@ -94,7 +94,7 @@ def make_scala_library(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_library_impl, ) @@ -178,7 +178,7 @@ def make_scala_library_for_plugin_bootstrapping(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_library_for_plugin_bootstrapping_impl, ) @@ -246,7 +246,7 @@ def make_scala_macro_library(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_macro_library_impl, ) diff --git a/scala/private/rules/scala_repl.bzl b/scala/private/rules/scala_repl.bzl index 3946467e5..66f6138f6 100644 --- a/scala/private/rules/scala_repl.bzl +++ b/scala/private/rules/scala_repl.bzl @@ -74,7 +74,7 @@ def make_scala_repl(*extras): ), toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", - "@io_bazel_rules_scala//scala:toolchain_type" + "@io_bazel_rules_scala//scala:toolchain_type", ], implementation = _scala_repl_impl, ) From f577d41106711294b735d438adbedc71807bc828 Mon Sep 17 00:00:00 2001 From: Steven Parkes Date: Fri, 31 Jan 2020 11:53:23 -0800 Subject: [PATCH 37/37] update test toochain name --- scala/BUILD | 18 ++++++++------- scala/private/phases/phase_collect_jars.bzl | 8 ++++--- .../private/phases/phase_write_executable.bzl | 2 +- scala/private/rules/scala_junit_test.bzl | 2 +- scala/private/rules/scala_test.bzl | 2 +- ...toolchain.bzl => scala_test_toolchain.bzl} | 23 +++++++++++-------- scala/toolchains.bzl | 2 +- 7 files changed, 32 insertions(+), 25 deletions(-) rename scala/{test_toolchain.bzl => scala_test_toolchain.bzl} (56%) diff --git a/scala/BUILD b/scala/BUILD index d9f86c3f2..efae634cc 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -1,6 +1,6 @@ load("//scala:bootstrap_toolchain.bzl", "bootstrap_toolchain") load("//scala:scala_toolchain.bzl", "scala_toolchain") -load("//scala:test_toolchain.bzl", "test_toolchain") +load("//scala:scala_test_toolchain.bzl", "scala_test_toolchain") # default toolchains registered by `scala_register_toolchains` @@ -60,22 +60,24 @@ toolchain( # test toolchain toolchain_type( - name = "test_toolchain_type", + name = "scala_test_toolchain_type", visibility = ["//visibility:public"], ) -test_toolchain( - name = "test_toolchain_impl", - jar = "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", +scala_test_toolchain( + name = "scala_test_toolchain_impl", reporter = "//scala/support:test_reporter", runner = "//src/java/io/bazel/rulesscala/scala_test:runner", visibility = ["//visibility:public"], + deps = [ + "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", + ], ) toolchain( - name = "test_toolchain", - toolchain = ":test_toolchain_impl", - toolchain_type = "@io_bazel_rules_scala//scala:test_toolchain_type", + name = "scala_test_toolchain", + toolchain = ":scala_test_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//scala:scala_test_toolchain_type", visibility = ["//visibility:public"], ) diff --git a/scala/private/phases/phase_collect_jars.bzl b/scala/private/phases/phase_collect_jars.bzl index 74851e3eb..02e1035ff 100644 --- a/scala/private/phases/phase_collect_jars.bzl +++ b/scala/private/phases/phase_collect_jars.bzl @@ -14,11 +14,13 @@ load( ) def phase_collect_jars_scalatest(ctx, p): + boostrap_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + test_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:scala_test_toolchain_type"].scalatestinfo.deps args = struct( - base_classpath = ctx.toolchains["@io_bazel_rules_scala//scala:bootstrap_toolchain_type"].bootstrapinfo.classpath + [ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.jar], + base_classpath = boostrap_classpath + test_classpath, extra_runtime_deps = [ - ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.reporter, - ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.runner, + ctx.toolchains["@io_bazel_rules_scala//scala:scala_test_toolchain_type"].scalatestinfo.reporter, + ctx.toolchains["@io_bazel_rules_scala//scala:scala_test_toolchain_type"].scalatestinfo.runner, ], ) return _phase_collect_jars_default(ctx, p, args) diff --git a/scala/private/phases/phase_write_executable.bzl b/scala/private/phases/phase_write_executable.bzl index e423144d5..e92602243 100644 --- a/scala/private/phases/phase_write_executable.bzl +++ b/scala/private/phases/phase_write_executable.bzl @@ -21,7 +21,7 @@ def phase_write_executable_scalatest(ctx, p): # toolchain final_jvm_flags = first_non_empty( ctx.attr.jvm_flags, - ctx.toolchains["@io_bazel_rules_scala//scala:test_toolchain_type"].testinfo.scala_test_jvm_flags, + ctx.toolchains["@io_bazel_rules_scala//scala:scala_test_toolchain_type"].scalatestinfo.scala_test_jvm_flags, ) args = struct( rjars = p.coverage_runfiles.rjars, diff --git a/scala/private/rules/scala_junit_test.bzl b/scala/private/rules/scala_junit_test.bzl index 4340ff583..c70fbc39b 100644 --- a/scala/private/rules/scala_junit_test.bzl +++ b/scala/private/rules/scala_junit_test.bzl @@ -128,7 +128,7 @@ def make_scala_junit_test(*extras): "@io_bazel_rules_scala//scala:toolchain_type", # unclear on next and will consider in factoring, whether # scalatest and junit tests should be different toolchain types - "@io_bazel_rules_scala//scala:test_toolchain_type", + "@io_bazel_rules_scala//scala:scala_test_toolchain_type", ], implementation = _scala_junit_test_impl, ) diff --git a/scala/private/rules/scala_test.bzl b/scala/private/rules/scala_test.bzl index 04e42fb2f..a67775704 100644 --- a/scala/private/rules/scala_test.bzl +++ b/scala/private/rules/scala_test.bzl @@ -100,7 +100,7 @@ def make_scala_test(*extras): toolchains = [ "@io_bazel_rules_scala//scala:bootstrap_toolchain_type", "@io_bazel_rules_scala//scala:toolchain_type", - "@io_bazel_rules_scala//scala:test_toolchain_type", + "@io_bazel_rules_scala//scala:scala_test_toolchain_type", ], implementation = _scala_test_impl, ) diff --git a/scala/test_toolchain.bzl b/scala/scala_test_toolchain.bzl similarity index 56% rename from scala/test_toolchain.bzl rename to scala/scala_test_toolchain.bzl index 5f50bcb63..767d88c60 100644 --- a/scala/test_toolchain.bzl +++ b/scala/scala_test_toolchain.bzl @@ -1,29 +1,32 @@ -TestInfo = provider( - doc = "TestInfo", +ScalaTestInfo = provider( + doc = "ScalaTestInfo", fields = [ - "jar", + "deps", "reporter", "runner", "scala_test_jvm_flags", ], ) -def _test_toolchain_impl(ctx): - testinfo = TestInfo( - jar = ctx.attr.jar, +def _scala_test_toolchain_impl(ctx): + scalatestinfo = ScalaTestInfo( + deps = ctx.attr.deps, reporter = ctx.attr.reporter, runner = ctx.attr.runner, scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags, ) toolchain = platform_common.ToolchainInfo( - testinfo = testinfo, + scalatestinfo = scalatestinfo, ) return [toolchain] -test_toolchain = rule( - _test_toolchain_impl, +scala_test_toolchain = rule( + _scala_test_toolchain_impl, attrs = { - "jar": attr.label(mandatory = True), + "deps": attr.label_list( + providers = [JavaInfo], + mandatory = True, + ), "reporter": attr.label(mandatory = True), "runner": attr.label(mandatory = True), "scala_test_jvm_flags": attr.string_list(), diff --git a/scala/toolchains.bzl b/scala/toolchains.bzl index 35e6fa4d3..c4f438f50 100644 --- a/scala/toolchains.bzl +++ b/scala/toolchains.bzl @@ -1,7 +1,7 @@ def scala_register_toolchains(): native.register_toolchains("@io_bazel_rules_scala//scala:bootstrap_toolchain") native.register_toolchains("@io_bazel_rules_scala//scala:toolchain") - native.register_toolchains("@io_bazel_rules_scala//scala:test_toolchain") + native.register_toolchains("@io_bazel_rules_scala//scala:scala_test_toolchain") def scala_register_unused_deps_toolchains(): native.register_toolchains(