diff --git a/docs/stardoc/scala.md b/docs/stardoc/scala.md
index c82c9580f..43f860d2d 100644
--- a/docs/stardoc/scala.md
+++ b/docs/stardoc/scala.md
@@ -163,6 +163,171 @@ Compiles a Scala JVM library.
+
+## bootstrap_scala_library
+
+
+bootstrap_scala_library(name, data, deps, deps_used_whitelist, exports, javacopts, macro, neverlink, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, scala, scalacopts, srcs)
+
+
+Compiles a Scala JVM library.
+
+### Attributes
+
+
+
+
+
+
+
+
+ name |
+
+ String; required
+
+ A unique name for this target.
+
+ |
+
+
+ data |
+
+ List of labels; optional
+
+ The additional runtime files needed by this library.
+
+ |
+
+
+ deps |
+
+ List of labels; optional
+
+ The JVM library dependencies.
+
+ |
+
+
+ deps_used_whitelist |
+
+ List of labels; optional
+
+ The JVM library dependencies to always consider used for `scala_deps_used` checks.
+
+ |
+
+
+ exports |
+
+ List of labels; optional
+
+ The JVM libraries to add as dependencies to any libraries dependent on this one.
+
+ |
+
+
+ javacopts |
+
+ List of strings; optional
+
+ The Javac options.
+
+ |
+
+
+ macro |
+
+ Boolean; optional
+
+ Whether this library provides macros.
+
+ |
+
+
+ neverlink |
+
+ Boolean; optional
+
+ Whether this library should be excluded at runtime.
+
+ |
+
+
+ plugins |
+
+ List of labels; optional
+
+ The Scalac plugins.
+
+ |
+
+
+ resource_jars |
+
+ List of labels; optional
+
+ The JARs to merge into the output JAR.
+
+ |
+
+
+ resource_strip_prefix |
+
+ String; optional
+
+ The path prefix to strip from classpath resources.
+
+ |
+
+
+ resources |
+
+ List of labels; optional
+
+ The files to include as classpath resources.
+
+ |
+
+
+ runtime_deps |
+
+ List of labels; optional
+
+ The JVM runtime-only library dependencies.
+
+ |
+
+
+ scala |
+
+ Label; optional
+
+ The `ScalaConfiguration`.
+
+ |
+
+
+ scalacopts |
+
+ List of strings; optional
+
+ The Scalac options.
+
+ |
+
+
+ srcs |
+
+ List of labels; optional
+
+ The source Scala and Java files (and `.srcjar` files of those).
+
+ |
+
+
+
+
+
## scala_binary
@@ -346,6 +511,186 @@ Compiles and links a Scala JVM executable.
+
+## bootstrap_scala_binary
+
+
+bootstrap_scala_binary(name, data, deps, deps_used_whitelist, exports, javacopts, jvm_flags, macro, main_class, neverlink, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, scala, scalacopts, srcs)
+
+
+Compiles and links a Scala JVM executable.
+
+### Attributes
+
+
+
+
+
+
+
+
+ name |
+
+ String; required
+
+ A unique name for this target.
+
+ |
+
+
+ data |
+
+ List of labels; optional
+
+ The additional runtime files needed by this library.
+
+ |
+
+
+ deps |
+
+ List of labels; optional
+
+ The JVM library dependencies.
+
+ |
+
+
+ deps_used_whitelist |
+
+ List of labels; optional
+
+ The JVM library dependencies to always consider used for `scala_deps_used` checks.
+
+ |
+
+
+ exports |
+
+ List of labels; optional
+
+ The JVM libraries to add as dependencies to any libraries dependent on this one.
+
+ |
+
+
+ javacopts |
+
+ List of strings; optional
+
+ The Javac options.
+
+ |
+
+
+ jvm_flags |
+
+ List of strings; optional
+
+ The JVM runtime flags.
+
+ |
+
+
+ macro |
+
+ Boolean; optional
+
+ Whether this library provides macros.
+
+ |
+
+
+ main_class |
+
+ String; required
+ |
+
+
+ neverlink |
+
+ Boolean; optional
+
+ Whether this library should be excluded at runtime.
+
+ |
+
+
+ plugins |
+
+ List of labels; optional
+
+ The Scalac plugins.
+
+ |
+
+
+ resource_jars |
+
+ List of labels; optional
+
+ The JARs to merge into the output JAR.
+
+ |
+
+
+ resource_strip_prefix |
+
+ String; optional
+
+ The path prefix to strip from classpath resources.
+
+ |
+
+
+ resources |
+
+ List of labels; optional
+
+ The files to include as classpath resources.
+
+ |
+
+
+ runtime_deps |
+
+ List of labels; optional
+
+ The JVM runtime-only library dependencies.
+
+ |
+
+
+ scala |
+
+ Label; optional
+
+ The `ScalaConfiguration`.
+
+ |
+
+
+ scalacopts |
+
+ List of strings; optional
+
+ The Scalac options.
+
+ |
+
+
+ srcs |
+
+ List of labels; optional
+
+ The source Scala and Java files (and `.srcjar` files of those).
+
+ |
+
+
+
+
+
## scala_test
diff --git a/docs/stardoc/scalac.md b/docs/stardoc/scalac.md
deleted file mode 100644
index 2030f420e..000000000
--- a/docs/stardoc/scalac.md
+++ /dev/null
@@ -1,339 +0,0 @@
-
-## scalac_library
-
-
-scalac_library(name, deps, macro, runtime_deps, scala, srcs)
-
-
-
-Compiles a Scala JVM library.
-
-This is a low-level rule used to bootstrap higher-level rules.
-You probably don't want to use this directly.
-
-
-### Attributes
-
-
-
-
-
-
-
-
- name |
-
- String; required
-
- A unique name for this target.
-
- |
-
-
- deps |
-
- List of labels; optional
-
- The JVM library dependencies.
-
- |
-
-
- macro |
-
- Boolean; optional
-
- Whether this library provides macros.
-
- |
-
-
- runtime_deps |
-
- List of labels; optional
-
- The JVM runtime-only library dependencies.
-
- |
-
-
- scala |
-
- Label; required
-
- The `ScalaConfiguration`.
-
- |
-
-
- srcs |
-
- List of labels; optional
-
- The source Scala and Java files (and `.srcjar` files of those).
-
- |
-
-
-
-
-
-
-## scalac_binary
-
-
-scalac_binary(name, deps, macro, main_class, runtime_deps, scala, srcs)
-
-
-
-Compiles and link a Scala JVM executable.
-
-This is a low-level rule used to bootstrap higher-level rules.
-You probably don't want to use this directly.
-
-
-### Attributes
-
-
-
-
-
-
-
-
- name |
-
- String; required
-
- A unique name for this target.
-
- |
-
-
- deps |
-
- List of labels; optional
-
- The JVM library dependencies.
-
- |
-
-
- macro |
-
- Boolean; optional
-
- Whether this library provides macros.
-
- |
-
-
- main_class |
-
- String; required
-
- The main class.
-
- |
-
-
- runtime_deps |
-
- List of labels; optional
-
- The JVM runtime-only library dependencies.
-
- |
-
-
- scala |
-
- Label; required
-
- The `ScalaConfiguration`.
-
- |
-
-
- srcs |
-
- List of labels; optional
-
- The source Scala and Java files (and `.srcjar` files of those).
-
- |
-
-
-
-
-
-
-##
-
-
-(name, compiler_bridge)
-
-
-Creates a `ZincConfiguration`.
-
-### Attributes
-
-
-
-
-
-
-
-
- name |
-
- String; required
-
- A unique name for this target.
-
- |
-
-
- compiler_bridge |
-
- Label; required
- |
-
-
-
-
-
-
-##
-
-
-(name, compiler_classpath, global_plugins, runtime_classpath, version)
-
-
-Creates a `ScalaConfiguration`.
-
-### Attributes
-
-
-
-
-
-
-
-
- name |
-
- String; required
-
- A unique name for this target.
-
- |
-
-
- compiler_classpath |
-
- List of labels; required
- |
-
-
- global_plugins |
-
- List of labels; optional
-
- Scalac plugins that will always be enabled.
-
- |
-
-
- runtime_classpath |
-
- List of labels; required
- |
-
-
- version |
-
- String; required
- |
-
-
-
-
-
-
-##
-
-
-(name, configurations)
-
-
-
-
-### Attributes
-
-
-
-
-
-
-
-
- name |
-
- String; required
-
- A unique name for this target.
-
- |
-
-
- configurations |
-
- List of labels; required
- |
-
-
-
-
-
-
-## _ScalaConfiguration
-
-Scala compile-time and runtime configuration
-
-### Fields
-
-
-
-
-
-
-
-
- version |
-
- The Scala full version.
- |
-
-
- compiler_classpath |
-
- The compiler classpath.
- |
-
-
- runtime_classpath |
-
- The runtime classpath.
- |
-
-
- global_plugins |
-
- Globally enabled compiler plugins
- |
-
-
-
-
-
diff --git a/rules/BUILD b/rules/BUILD
index 4e6222b95..a6ce389b3 100644
--- a/rules/BUILD
+++ b/rules/BUILD
@@ -45,7 +45,6 @@ bzl_library(
"//rules/jvm:bzl",
"//rules/scala:bzl",
"//rules/scala_proto:bzl",
- "//rules/scalac:bzl",
"//rules/scalafmt:bzl",
],
deps = ["@bazel_skylib//lib:dicts"],
diff --git a/rules/common/BUILD b/rules/common/BUILD
index 778390f37..4ca9b5248 100644
--- a/rules/common/BUILD
+++ b/rules/common/BUILD
@@ -1,7 +1,7 @@
load("//rules:scalafmt.bzl", "scala_format_test")
-load("//rules:scalac.bzl", "scalac_library")
+load("//rules:scala.bzl", "bootstrap_scala_library")
-scalac_library(
+bootstrap_scala_library(
name = "args",
srcs = glob(["args/**/*.scala"]),
scala = "//external:scala_annex_scala_basic",
@@ -11,7 +11,7 @@ scalac_library(
],
)
-scalac_library(
+bootstrap_scala_library(
name = "worker",
srcs = glob(["worker/**/*.scala"]),
scala = "//external:scala_annex_scala_basic",
diff --git a/rules/scala.bzl b/rules/scala.bzl
index a3d7a6df5..649a3437b 100644
--- a/rules/scala.bzl
+++ b/rules/scala.bzl
@@ -14,6 +14,10 @@ load(
)
load(
"//rules/scala:private/core.bzl",
+ _bootstrap_scala_binary_implementation = "bootstrap_scala_binary_implementation",
+ _bootstrap_scala_binary_private_attributes = "bootstrap_scala_binary_private_attributes",
+ _bootstrap_scala_library_implementation = "bootstrap_scala_library_implementation",
+ _bootstrap_scala_library_private_attributes = "bootstrap_scala_library_private_attributes",
_scala_binary_implementation = "scala_binary_implementation",
_scala_binary_private_attributes = "scala_binary_private_attributes",
_scala_library_implementation = "scala_library_implementation",
@@ -104,7 +108,7 @@ _library_common_attributes = {
doc = "The `ScalaConfiguration`.",
providers = [
_ScalaConfiguration,
- _ZincConfiguration,
+ #_ZincConfiguration,
],
),
"scalacopts": attr.string_list(
@@ -128,6 +132,18 @@ scala_library = rule(
implementation = _scala_library_implementation,
)
+bootstrap_scala_library = rule(
+ attrs = _dicts.add(
+ _library_common_attributes,
+ _bootstrap_scala_library_private_attributes,
+ ),
+ doc = "Compiles a Scala JVM library.",
+ outputs = {
+ "jar": "%{name}.jar",
+ },
+ implementation = _bootstrap_scala_library_implementation,
+)
+
_runner_common_attributes = {
"jvm_flags": attr.string_list(
doc = "The JVM runtime flags.",
@@ -163,6 +179,27 @@ scala_binary = rule(
implementation = _scala_binary_implementation,
)
+bootstrap_scala_binary = rule(
+ attrs = _dicts.add(
+ _library_common_attributes,
+ _runner_common_attributes,
+ _bootstrap_scala_binary_private_attributes,
+ {
+ "main_class": attr.string(
+ mandatory = True,
+ ),
+ },
+ ),
+ doc = "Compiles and links a Scala JVM executable.",
+ executable = True,
+ outputs = {
+ "bin": "%{name}-bin",
+ "jar": "%{name}.jar",
+ "deploy_jar": "%{name}_deploy.jar",
+ },
+ implementation = _bootstrap_scala_binary_implementation,
+)
+
scala_test = rule(
attrs = _dicts.add(
_library_common_attributes,
diff --git a/rules/scala/BUILD b/rules/scala/BUILD
index 8ffec95d3..39187cd0e 100644
--- a/rules/scala/BUILD
+++ b/rules/scala/BUILD
@@ -1,10 +1,9 @@
-load("//rules:scala.bzl", "scala_binary", "scala_deps_toolchain", "scala_library", "scala_runner_toolchain")
-load("//rules:scalac.bzl", "scalac_binary", "scalac_library")
+load("//rules:scala.bzl", "bootstrap_scala_binary", "bootstrap_scala_library", "scala_binary", "scala_deps_toolchain", "scala_library", "scala_runner_toolchain")
load("//rules:scalafmt.bzl", "scala_format_test")
# Bloop
-scalac_binary(
+bootstrap_scala_binary(
name = "bloop",
srcs = glob(["bloop/**/*.scala"]),
main_class = "annex.bloop.BloopRunner",
@@ -55,7 +54,7 @@ config_setting(
},
)
-scalac_library(
+bootstrap_scala_library(
name = "compiler",
srcs = glob(["compiler/**/*.scala"]),
scala = "//external:scala_annex_scala_basic",
@@ -129,7 +128,7 @@ toolchain(
visibility = ["//visibility:public"],
)
-scalac_binary(
+bootstrap_scala_binary(
name = "deps",
srcs = glob(["deps/**/*.scala"]),
main_class = "annex.deps.DepsRunner",
@@ -235,7 +234,7 @@ java_proto_library(
deps = [":zinc_options_proto"],
)
-scalac_binary(
+bootstrap_scala_binary(
name = "zinc",
srcs = glob(["zinc/**/*.scala"]),
main_class = "annex.zinc.ZincRunner",
diff --git a/rules/scala/private/core.bzl b/rules/scala/private/core.bzl
index de73bb0b6..15ba5127b 100644
--- a/rules/scala/private/core.bzl
+++ b/rules/scala/private/core.bzl
@@ -2,6 +2,7 @@ load(
":private/phases.bzl",
_phase_binary_deployjar = "phase_binary_deployjar",
_phase_binary_launcher = "phase_binary_launcher",
+ _phase_boostrap_compile = "phase_boostrap_compile",
_phase_coda = "phase_coda",
_phase_compile = "phase_compile",
_phase_depscheck = "phase_depscheck",
@@ -48,6 +49,27 @@ scala_test_phases = [
("coda", _phase_coda),
]
+bootstrap_scala_library_phases = [
+ ("javainfo", _phase_javainfo),
+ ("resources", _phase_resources),
+ ("compile", _phase_boostrap_compile),
+ ("singlejar", _phase_singlejar),
+ ("ijinfo", _phase_ijinfo),
+ ("library_defaultinfo", _phase_library_defaultinfo),
+ ("coda", _phase_coda),
+]
+
+bootstrap_scala_binary_phases = [
+ ("javainfo", _phase_javainfo),
+ ("resources", _phase_resources),
+ ("compile", _phase_boostrap_compile),
+ ("singlejar", _phase_singlejar),
+ ("ijinfo", _phase_ijinfo),
+ ("binary_deployjar", _phase_binary_deployjar),
+ ("binary_launcher", _phase_binary_launcher),
+ ("coda", _phase_coda),
+]
+
def scala_library_implementation(ctx):
return _run_phases(ctx, scala_library_phases).coda
@@ -57,6 +79,12 @@ def scala_binary_implementation(ctx):
def scala_test_implementation(ctx):
return _run_phases(ctx, scala_test_phases).coda
+def bootstrap_scala_library_implementation(ctx):
+ return _run_phases(ctx, bootstrap_scala_library_phases).coda
+
+def bootstrap_scala_binary_implementation(ctx):
+ return _run_phases(ctx, bootstrap_scala_binary_phases).coda
+
runner_common_attributes = {
"_java_toolchain": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_toolchain"),
@@ -79,16 +107,45 @@ runner_common_attributes = {
scala_library_private_attributes = runner_common_attributes
-scala_binary_private_attributes = dict({
- "_java": attr.label(
- default = Label("@bazel_tools//tools/jdk:java"),
- executable = True,
- cfg = "host",
- ),
- "_java_stub_template": attr.label(
- default = Label("@anx_java_stub_template//file"),
- allow_single_file = True,
- ),
-}, **runner_common_attributes)
+scala_binary_private_attributes = dict(
+ {
+ "_java": attr.label(
+ default = Label("@bazel_tools//tools/jdk:java"),
+ executable = True,
+ cfg = "host",
+ ),
+ "_java_stub_template": attr.label(
+ default = Label("@anx_java_stub_template//file"),
+ allow_single_file = True,
+ ),
+ },
+ **runner_common_attributes
+)
scala_test_private_attributes = scala_binary_private_attributes
+
+bootstrap_scala_library_private_attributes = dict(
+ {
+ "_java": attr.label(
+ default = Label("@bazel_tools//tools/jdk:java"),
+ executable = True,
+ cfg = "host",
+ ),
+ "_jar_creator": attr.label(
+ default = Label("@rules_scala_annex//rules/common/third_party/bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:jarcreator_bin"),
+ executable = True,
+ cfg = "host",
+ ),
+ },
+ **runner_common_attributes
+)
+
+bootstrap_scala_binary_private_attributes = dict(
+ {
+ "_java_stub_template": attr.label(
+ default = Label("@anx_java_stub_template//file"),
+ allow_single_file = True,
+ ),
+ },
+ **bootstrap_scala_library_private_attributes
+)
diff --git a/rules/scala/private/phases.bzl b/rules/scala/private/phases.bzl
index b6fb7a13c..e7b072391 100644
--- a/rules/scala/private/phases.bzl
+++ b/rules/scala/private/phases.bzl
@@ -7,7 +7,7 @@ load(
_ZincConfiguration = "ZincConfiguration",
_ZincInfo = "ZincInfo",
)
-load("//rules/common:private/utils.bzl", _collect = "collect", _write_launcher = "write_launcher")
+load("//rules/common:private/utils.bzl", _collect = "collect", _strip_margin = "strip_margin", _write_launcher = "write_launcher")
load(":private/import.bzl", _create_intellij_info = "create_intellij_info")
def run_phases(ctx, phases):
@@ -220,11 +220,105 @@ def _compile_analysis(analysis):
analysis.relations.path,
] + [jar.path for jar in analysis.jars]
+#
+# PHASE: bootstrap compile
+#
+# An alternative compile phase that shells out to scalac directly
+#
+def phase_boostrap_compile(ctx, g):
+ # TODO: This code was copied in from the scalac rules. The setup
+ # is very similar to the regular compile phase, so we should refactor
+ # the common parts into a new 'pre' compile phase. I think...
+
+ name = ctx.label.name
+ java = ctx.executable._java
+ jar_creator = ctx.executable._jar_creator
+
+ class_jar = ctx.actions.declare_file("{}/classes.jar".format(ctx.label.name))
+ scala = g.init.scala_configuration
+
+ deps = [dep[JavaInfo] for dep in scala.runtime_classpath + ctx.attr.deps]
+ sdep = java_common.merge(deps)
+
+ macro_classpath = [
+ dep[JavaInfo].transitive_runtime_jars
+ for dep in ctx.attr.deps
+ if _ScalaInfo in dep and dep[_ScalaInfo].macro
+ ]
+
+ # Note: we pull in transitive_compile_time_jars for the time being
+ # to make development of runners way easier (bloop/zinc have big dep graphs).
+ # Consider removing transitive_compile_time_jars in the future.
+ compile_deps = depset(order = "preorder", transitive = macro_classpath + [sdep.transitive_compile_time_jars])
+ runtime_deps = sdep.transitive_runtime_jars
+
+ compiler_classpath_str = ":".join([file.path for file in scala.compiler_classpath])
+ compile_classpath_str = ":".join([file.path for file in compile_deps.to_list()])
+
+ inputs = depset(
+ [java] + ctx.files.srcs + scala.compiler_classpath,
+ transitive = [compile_deps],
+ )
+ tools = [jar_creator]
+
+ srcs = [
+ file.path
+ for file in ctx.files.srcs
+ if file.path.endswith(".java") or file.path.endswith(".scala")
+ ]
+
+ src_jars = [
+ file.path
+ for file in ctx.files.srcs
+ if file.path.endswith(".srcjar")
+ ]
+
+ if src_jars:
+ fail("source jars aren't yet supported for direct scalac rules")
+
+ srcs_string = " ".join(srcs)
+ src_jars_string = " ".join(src_jars)
+
+ ctx.actions.run_shell(
+ inputs = inputs,
+ tools = tools,
+ outputs = [class_jar],
+ command = _strip_margin(
+ """
+ |set -eo pipefail
+ |
+ |mkdir -p tmp/classes
+ |
+ |{java} \\
+ | -cp {compiler_classpath} \\
+ | scala.tools.nsc.Main \\
+ | -cp {compile_classpath} \\
+ | -d tmp/classes \\
+ | {srcs}
+ |
+ |{jar_creator} {output_jar} tmp/classes 2> /dev/null
+ |""".format(
+ java = java.path,
+ jar_creator = jar_creator.path,
+ compiler_classpath = compiler_classpath_str,
+ compile_classpath = compile_classpath_str,
+ srcs = srcs_string,
+ src_jars = src_jars_string,
+ output_jar = class_jar.path,
+ ),
+ ),
+ )
+
+ return struct(
+ jar = class_jar,
+ )
+
#
# PHASE: depscheck
# Dependencies are checked to see if they are used/unused.
# Success files are outputted if dependency checking was "successful"
# according to the configuration/options.
+#
def phase_depscheck(ctx, g):
deps_toolchain = ctx.toolchains["@rules_scala_annex//rules/scala:deps_toolchain_type"]
@@ -444,21 +538,29 @@ def _binary_deployjar_build_deployable(ctx, jars_list):
#
def phase_binary_launcher(ctx, g):
- mains_file = g.compile.mains_file
+ inputs = ctx.files.data
+
+ if ctx.attr.main_class != "":
+ main_class = ctx.attr.main_class
+ else:
+ mains_file = g.compile.mains_file
+ inputs = inputs + [mains_file]
+ main_class = "$(head -1 $JAVA_RUNFILES/{}/{})".format(ctx.workspace_name, mains_file.short_path)
+
files = _write_launcher(
ctx,
"{}/".format(ctx.label.name),
ctx.outputs.bin,
g.javainfo.java_info.transitive_runtime_deps,
jvm_flags = [ctx.expand_location(f, ctx.attr.data) for f in ctx.attr.jvm_flags],
- main_class = ctx.attr.main_class or "$(head -1 $JAVA_RUNFILES/{}/{})".format(ctx.workspace_name, mains_file.short_path),
+ main_class = main_class,
)
g.out.providers.append(DefaultInfo(
executable = ctx.outputs.bin,
files = depset([ctx.outputs.bin, ctx.outputs.jar]),
runfiles = ctx.runfiles(
- files = files + ctx.files.data + [mains_file],
+ files = inputs + files,
transitive_files = depset(
direct = [ctx.executable._java],
order = "default",
diff --git a/rules/scala/private/workspace.bzl b/rules/scala/private/workspace.bzl
index 3eac15832..073fe7306 100644
--- a/rules/scala/private/workspace.bzl
+++ b/rules/scala/private/workspace.bzl
@@ -8,15 +8,11 @@ def configure_scala_repository_implementation(ctx):
|
|load(
| "@rules_scala_annex//rules:scala.bzl",
+ | _bootstrap_scala_library = "bootstrap_scala_library",
| _configure_basic_scala = "configure_basic_scala",
| _configure_scala = "configure_scala",
|)
|
- |load(
- | "@rules_scala_annex//rules:scalac.bzl",
- | _scalac_library = "scalac_library",
- |)
- |
|_compiler_classpath = [
| '@{name}_scala_compiler//jar',
| '@{name}_scala_reflect//jar',
@@ -40,7 +36,7 @@ def configure_scala_repository_implementation(ctx):
| '@scala_annex_org_scala_sbt_util_interface//jar',
|]
|
- |_scalac_library(
+ |_bootstrap_scala_library(
| name = "compiler_bridge",
| srcs = ['{compiler_bridge}'],
| scala = ":basic",
diff --git a/rules/scalac.bzl b/rules/scalac.bzl
deleted file mode 100644
index a75f11a32..000000000
--- a/rules/scalac.bzl
+++ /dev/null
@@ -1,93 +0,0 @@
-"""
-Rules for invoking scalac directly.
-"""
-
-load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
-load(
- "@rules_scala_annex//rules:providers.bzl",
- _ScalaConfiguration = "ScalaConfiguration",
-)
-load(
- "//rules/scalac:private.bzl",
- _scalac_binary_implementation = "scalac_binary_implementation",
- _scalac_binary_private_attributes = "scalac_binary_private_attributes",
- _scalac_library_implementation = "scalac_library_implementation",
- _scalac_library_private_attributes = "scalac_library_private_attributes",
-)
-
-scalac_library = rule(
- doc = """
-Compiles a Scala JVM library.
-
-This is a low-level rule used to bootstrap higher-level rules.
-You probably don't want to use this directly.
-""",
- implementation = _scalac_library_implementation,
- attrs = _dicts.add(
- _scalac_library_private_attributes,
- {
- "srcs": attr.label_list(
- allow_files = [".scala", ".java", ".srcjar"],
- doc = "The source Scala and Java files (and `.srcjar` files of those).",
- ),
- "deps": attr.label_list(
- doc = "The JVM library dependencies.",
- providers = [JavaInfo],
- ),
- "macro": attr.bool(
- doc = "Whether this library provides macros.",
- default = False,
- ),
- "runtime_deps": attr.label_list(
- doc = "The JVM runtime-only library dependencies.",
- providers = [JavaInfo],
- ),
- "scala": attr.label(
- doc = "The `ScalaConfiguration`.",
- mandatory = True,
- providers = [_ScalaConfiguration],
- ),
- },
- ),
-)
-
-scalac_binary = rule(
- doc = """
-Compiles and link a Scala JVM executable.
-
-This is a low-level rule used to bootstrap higher-level rules.
-You probably don't want to use this directly.
-""",
- implementation = _scalac_binary_implementation,
- attrs = _dicts.add(
- _scalac_binary_private_attributes,
- {
- "srcs": attr.label_list(
- allow_files = [".scala", ".java", ".srcjar"],
- doc = "The source Scala and Java files (and `.srcjar` files of those).",
- ),
- "deps": attr.label_list(
- doc = "The JVM library dependencies.",
- providers = [JavaInfo],
- ),
- "macro": attr.bool(
- default = False,
- doc = "Whether this library provides macros.",
- ),
- "runtime_deps": attr.label_list(
- doc = "The JVM runtime-only library dependencies.",
- providers = [JavaInfo],
- ),
- "main_class": attr.string(
- doc = "The main class.",
- mandatory = True,
- ),
- "scala": attr.label(
- doc = "The `ScalaConfiguration`.",
- mandatory = True,
- providers = [_ScalaConfiguration],
- ),
- },
- ),
- executable = True,
-)
diff --git a/rules/scalac/BUILD b/rules/scalac/BUILD
deleted file mode 100644
index 70a038db4..000000000
--- a/rules/scalac/BUILD
+++ /dev/null
@@ -1,5 +0,0 @@
-filegroup(
- name = "bzl",
- srcs = glob(["**/*.bzl"]),
- visibility = ["//rules:__pkg__"],
-)
diff --git a/rules/scalac/private.bzl b/rules/scalac/private.bzl
deleted file mode 100644
index 5eaf1bebb..000000000
--- a/rules/scalac/private.bzl
+++ /dev/null
@@ -1,219 +0,0 @@
-load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
-load("@rules_scala_annex//rules:providers.bzl", "ScalaConfiguration", "ScalaInfo")
-load("//rules/common:private/utils.bzl", "strip_margin", "write_launcher")
-load("//rules/scala:private/import.bzl", "create_intellij_info")
-
-_common_private_attributes = {
- "_host_javabase": attr.label(
- default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
- cfg = "host",
- ),
- "_java": attr.label(
- default = Label("@bazel_tools//tools/jdk:java"),
- executable = True,
- cfg = "host",
- ),
- "_jar": attr.label(
- default = Label("@bazel_tools//tools/jdk:jar"),
- executable = True,
- cfg = "host",
- ),
- "_jar_creator": attr.label(
- default = Label("@rules_scala_annex//rules/common/third_party/bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:jarcreator_bin"),
- executable = True,
- cfg = "host",
- ),
- "_java_toolchain": attr.label(
- default = Label("@bazel_tools//tools/jdk:current_java_toolchain"),
- ),
-}
-
-scalac_library_private_attributes = _common_private_attributes
-scalac_binary_private_attributes = _dicts.add(
- _common_private_attributes,
- {
- "_java_stub_template": attr.label(
- allow_single_file = True,
- default = Label("@anx_java_stub_template//file"),
- ),
- },
-)
-
-def scalac_binary_implementation(ctx):
- res = _scalac_common(ctx)
- launcher = ctx.actions.declare_file("%s.sh" % ctx.label.name)
- files = write_launcher(
- ctx,
- "{}/".format(ctx.label.name),
- launcher,
- res["java_info"].transitive_runtime_deps,
- main_class = ctx.attr.main_class,
- jvm_flags = [],
- )
- return _format_providers(ctx, dict({
- "executable": launcher,
- "files": files,
- }, **res))
-
-def scalac_library_implementation(ctx):
- res = _scalac_common(ctx)
- return _format_providers(ctx, res)
-
-def _scalac_common(ctx):
- name = ctx.label.name
- jar = ctx.executable._jar
- java = ctx.executable._java
- jar_creator = ctx.executable._jar_creator
-
- output_jar = ctx.actions.declare_file("%s.jar" % name)
-
- scala = ctx.attr.scala[ScalaConfiguration]
-
- deps = [dep[JavaInfo] for dep in scala.runtime_classpath + ctx.attr.deps]
- sdep = java_common.merge(deps)
-
- macro_classpath = [
- dep[JavaInfo].transitive_runtime_jars
- for dep in ctx.attr.deps
- if ScalaInfo in dep and dep[ScalaInfo].macro
- ]
-
- # Note: we pull in transitive_compile_time_jars for the time being
- # to make development of runners way easier (bloop/zinc have big dep graphs).
- # Consider removing transitive_compile_time_jars in the future.
- compile_deps = depset(order = "preorder", transitive = macro_classpath + [sdep.transitive_compile_time_jars])
- runtime_deps = sdep.transitive_runtime_jars
-
- compiler_classpath_str = ":".join([file.path for file in scala.compiler_classpath])
- compile_classpath_str = ":".join([file.path for file in compile_deps.to_list()])
-
- inputs = depset(
- [jar, java] + ctx.files.srcs + scala.compiler_classpath,
- transitive = [compile_deps],
- )
- tools = [jar_creator]
-
- srcs = [
- file.path
- for file in ctx.files.srcs
- if file.path.endswith(".java") or file.path.endswith(".scala")
- ]
-
- src_jars = [
- file.path
- for file in ctx.files.srcs
- if file.path.endswith(".srcjar")
- ]
-
- if src_jars:
- fail("source jars aren't yet supported for direct scalac rules")
-
- srcs_string = " ".join(srcs)
- src_jars_string = " ".join(src_jars)
-
- ctx.actions.run_shell(
- inputs = inputs,
- tools = tools,
- outputs = [output_jar],
- command = strip_margin(
- """
- |set -eo pipefail
- |
- |mkdir -p tmp/classes
- |
- |{java} \\
- | -cp {compiler_classpath} \\
- | scala.tools.nsc.Main \\
- | -cp {compile_classpath} \\
- | -d tmp/classes \\
- | {srcs}
- |
- |{jar_creator} {output_jar} tmp/classes 2> /dev/null
- |""".format(
- jar = jar.path,
- java = java.path,
- jar_creator = jar_creator.path,
- compiler_classpath = compiler_classpath_str,
- compile_classpath = compile_classpath_str,
- srcs = srcs_string,
- src_jars = src_jars_string,
- output_jar = output_jar.path,
- ),
- ),
- )
-
- compile_jar = java_common.run_ijar(
- ctx.actions,
- jar = output_jar,
- target_label = ctx.label,
- java_toolchain = ctx.attr._java_toolchain,
- )
-
- source_jar = java_common.pack_sources(
- ctx.actions,
- output_jar = output_jar,
- sources = ctx.files.srcs,
- host_javabase = ctx.attr._host_javabase,
- java_toolchain = ctx.attr._java_toolchain,
- )
-
- java_info = JavaInfo(
- output_jar = output_jar,
- compile_jar = compile_jar,
- source_jar = source_jar,
- deps = deps,
- runtime_deps = [dep[JavaInfo] for dep in ctx.attr.runtime_deps],
- )
-
- scala_info = ScalaInfo(
- scala_configuration = ctx.attr.scala[ScalaConfiguration],
- macro = ctx.attr.macro,
- )
-
- return {
- "output_jar": output_jar,
- "java_info": java_info,
- "scala_info": scala_info,
- }
-
- # TODO: put me in a common place?
-
-def _create_default_info(ctx, blob):
- args = {}
-
- files = []
- if "output_jar" in blob:
- files += [blob["output_jar"]]
- if "files" in blob:
- files += blob["files"]
- args["files"] = depset(files)
-
- if "executable" in blob:
- args["executable"] = blob["executable"]
- args["runfiles"] = ctx.runfiles(
- files = files,
- transitive_files = depset(
- order = "default",
- direct = [ctx.executable._java],
- transitive = [blob["java_info"].transitive_runtime_deps],
- ),
- collect_default = True,
- )
-
- return DefaultInfo(**args)
-
-def _format_providers(ctx, blob):
- default_info = _create_default_info(ctx, blob)
- java_info = blob["java_info"]
- scala_info = blob["scala_info"]
- intellij_info = create_intellij_info(ctx.label, ctx.attr.deps, java_info)
-
- return struct(
- providers = [
- default_info,
- java_info,
- intellij_info,
- scala_info,
- ],
- java = java_info,
- )
diff --git a/tests/providers/BUILD b/tests/providers/BUILD
index d1f6f80a8..9b786bb28 100644
--- a/tests/providers/BUILD
+++ b/tests/providers/BUILD
@@ -5,8 +5,8 @@ load(
"join_configurations",
)
load(
- "@rules_scala_annex//rules:scalac.bzl",
- "scalac_library",
+ "@rules_scala_annex//rules:scala.bzl",
+ "bootstrap_scala_library",
)
load(
":build.bzl",
@@ -28,7 +28,7 @@ declare_scala_configuration(
version = "2.12.4",
)
-scalac_library(
+bootstrap_scala_library(
name = "compiler_bridge",
srcs = ["@compiler_bridge_2_12//:src"],
scala = ":provided_scala_configuration",
diff --git a/tests/scalac/BUILD b/tests/scala_bootstrap/BUILD
similarity index 63%
rename from tests/scalac/BUILD
rename to tests/scala_bootstrap/BUILD
index 464e76a7a..e233f9b50 100644
--- a/tests/scalac/BUILD
+++ b/tests/scala_bootstrap/BUILD
@@ -1,16 +1,16 @@
load(
- "@rules_scala_annex//rules:scalac.bzl",
- "scalac_binary",
- "scalac_library",
+ "@rules_scala_annex//rules:scala.bzl",
+ "bootstrap_scala_binary",
+ "bootstrap_scala_library",
)
-scalac_library(
+bootstrap_scala_library(
name = "hello_world_lib",
srcs = ["HelloWorldLib.scala"],
scala = "@scala_2_12",
)
-scalac_binary(
+bootstrap_scala_binary(
name = "hello_world_bin",
srcs = ["HelloWorldBin.scala"],
main_class = "anx.HelloWorld",
diff --git a/tests/scalac/HelloWorldBin.scala b/tests/scala_bootstrap/HelloWorldBin.scala
similarity index 100%
rename from tests/scalac/HelloWorldBin.scala
rename to tests/scala_bootstrap/HelloWorldBin.scala
diff --git a/tests/scalac/HelloWorldLib.scala b/tests/scala_bootstrap/HelloWorldLib.scala
similarity index 100%
rename from tests/scalac/HelloWorldLib.scala
rename to tests/scala_bootstrap/HelloWorldLib.scala
diff --git a/tests/scalac/test b/tests/scala_bootstrap/test
similarity index 100%
rename from tests/scalac/test
rename to tests/scala_bootstrap/test