-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support not bundling SemanticDB files in the output JAR #50
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
load("@bazel_skylib//lib:paths.bzl", "paths") | ||
load("@rules_scala_annex//rules:providers.bzl", _ScalaConfiguration = "ScalaConfiguration") | ||
|
||
# | ||
# PHASE: semanticdb | ||
# | ||
# Configures the compiler to output SemanticDB metadata. Note that this phase won't work without the | ||
# SemanticDB compiler plugin being enabled. | ||
# | ||
def phase_semanticdb(ctx, g): | ||
scala_configuration = ctx.attr.scala[_ScalaConfiguration] | ||
|
||
if scala_configuration.semanticdb_bundle: | ||
return struct(outputs = [], scalacopts = []) | ||
|
||
outputs = [] | ||
semanticdb_directory = paths.join("_semanticdb/", ctx.label.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for the name to contain characters that are illegal to use as file names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From Bazel's documentation on labels:
I assume legal target names can't include slashes because that'd make the package and name indistinguishable. I think the only illegal characters in Unix filenames are |
||
semanticdb_target_root = paths.join(paths.dirname(ctx.outputs.jar.path), semanticdb_directory) | ||
|
||
for source in ctx.files.srcs: | ||
if source.extension == "scala": | ||
output_filename = paths.join( | ||
semanticdb_directory, | ||
"META-INF", | ||
"semanticdb", | ||
"{}.semanticdb".format(source.path), | ||
) | ||
|
||
outputs.append(ctx.actions.declare_file(output_filename)) | ||
|
||
if scala_configuration.version.startswith("2"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how much we care about this, but how does this work for things like Scalajs or Scala Native? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it depends on what Now that I think about it, is SemanticDB even a concept in Scala.js and Scala Native? I think both Scala.js and Scala Native use the same compiler, so it should be. For now, I'll leave this as is and dig into it further if folks want Scala.js and/or Scala Native support (assuming that's ok with you). |
||
scalacopts = [ | ||
"-P:semanticdb:failures:error", | ||
"-P:semanticdb:targetroot:{}".format(semanticdb_target_root), | ||
] | ||
else: | ||
scalacopts = [ | ||
"-semanticdb-target:{}".format(semanticdb_target_root), | ||
"-Ysemanticdb", | ||
] | ||
|
||
return struct(outputs = outputs, scalacopts = scalacopts) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,65 +484,79 @@ Generates Scaladocs. | |
|
||
configure_bootstrap_scala = rule( | ||
attrs = { | ||
"version": attr.string(mandatory = True), | ||
"compiler_classpath": attr.label_list( | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"runtime_classpath": attr.label_list( | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"global_plugins": attr.label_list( | ||
doc = "Scalac plugins that will always be enabled.", | ||
providers = [JavaInfo], | ||
), | ||
"global_scalacopts": attr.string_list( | ||
doc = "Scalac options that will always be enabled.", | ||
), | ||
"runtime_classpath": attr.label_list( | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"semanticdb_bundle": attr.bool( | ||
default = True, | ||
doc = "Whether to bundle SemanticDB files in the resulting JAR. Note that in Scala 2, this requires the SemanticDB compiler plugin.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we provide some default for Scala 2? Is that even possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we even want to do that if we could? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by this? The default is set to |
||
), | ||
"use_ijar": attr.bool( | ||
doc = "Whether to use ijars for this compiler.", | ||
default = True, | ||
), | ||
"version": attr.string(mandatory = True), | ||
}, | ||
implementation = _configure_bootstrap_scala_implementation, | ||
) | ||
|
||
_configure_zinc_scala = rule( | ||
attrs = { | ||
"version": attr.string(mandatory = True), | ||
"runtime_classpath": attr.label_list( | ||
"compiler_bridge": attr.label( | ||
allow_single_file = True, | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"compiler_classpath": attr.label_list( | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"compiler_bridge": attr.label( | ||
allow_single_file = True, | ||
mandatory = True, | ||
), | ||
"deps_direct": attr.string(default = "error"), | ||
"deps_used": attr.string(default = "error"), | ||
"global_plugins": attr.label_list( | ||
doc = "Scalac plugins that will always be enabled.", | ||
providers = [JavaInfo], | ||
), | ||
"global_scalacopts": attr.string_list( | ||
doc = "Scalac options that will always be enabled.", | ||
), | ||
"incremental": attr.bool( | ||
doc = "Whether Zinc's incremental compilation will be available for this Zinc compiler. If True, this requires additional configuration to use incremental compilation.", | ||
default = False, | ||
), | ||
"log_level": attr.string( | ||
doc = "Compiler log level", | ||
default = "warn", | ||
), | ||
"runtime_classpath": attr.label_list( | ||
mandatory = True, | ||
providers = [JavaInfo], | ||
), | ||
"semanticdb_bundle": attr.bool( | ||
default = True, | ||
doc = "Whether to bundle SemanticDB files in the resulting JAR. Note that in Scala 2, this requires the SemanticDB compiler plugin.", | ||
), | ||
"use_ijar": attr.bool( | ||
doc = "Whether to use ijars for this compiler.", | ||
default = True, | ||
), | ||
"deps_direct": attr.string(default = "error"), | ||
"deps_used": attr.string(default = "error"), | ||
"incremental": attr.bool( | ||
doc = "Whether Zinc's incremental compilation will be available for this Zinc compiler. If True, this requires additional configuration to use incremental compilation.", | ||
default = False, | ||
"version": attr.string(mandatory = True), | ||
"_code_coverage_instrumentation_worker": attr.label( | ||
default = "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/jacoco/instrumenter", | ||
allow_files = True, | ||
executable = True, | ||
cfg = "host", | ||
), | ||
"_compile_worker": attr.label( | ||
default = "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/zinc/compile", | ||
|
@@ -556,12 +570,6 @@ _configure_zinc_scala = rule( | |
executable = True, | ||
cfg = "host", | ||
), | ||
"_code_coverage_instrumentation_worker": attr.label( | ||
default = "@rules_scala_annex//src/main/scala/higherkindness/rules_scala/workers/jacoco/instrumenter", | ||
allow_files = True, | ||
executable = True, | ||
cfg = "host", | ||
), | ||
}, | ||
implementation = _configure_zinc_scala_implementation, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class A |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class B |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these were sorted alphabetically. Is that what is going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.