-
Notifications
You must be signed in to change notification settings - Fork 278
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 for selecting scala version #544
Changes from 39 commits
d27e73f
abae2b2
f670436
50deaf3
b9f1b22
2aa315c
27d3af0
0e5c5dd
72aba58
25132c9
d8edfb6
cf37e0f
5b2a053
2dc260f
94d0ab1
a47af87
52bdef1
a125428
dd28058
e6aff25
e600177
927e5f8
22f216f
87dad40
d45943d
990cb9d
57449bb
adeff15
2bd3825
e1846f5
5d67d4d
0dc4361
a66d27a
8b48a1e
1648bd4
e1e7cfb
b819162
b6c5806
ed646b4
bc36a86
ae407ac
f5e5ff6
5f26b2b
8a7b120
7b36b2d
dc9eb43
a72372c
260fd7f
829705d
8abd79f
2252748
b43be39
2db2ada
f0c262c
78cb80e
6c05916
50cbd54
e1b12ba
4774178
4661265
a834ba5
e518edc
16767e3
25db5f6
20ee544
c9dffbf
b131900
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 |
---|---|---|
|
@@ -13,7 +13,10 @@ | |
# limitations under the License. | ||
"""Rules for supporting the Scala language.""" | ||
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain") | ||
load("@io_bazel_rules_scala//scala:providers.bzl", "create_scala_provider") | ||
load( | ||
"@io_bazel_rules_scala//scala:providers.bzl", | ||
"create_scala_provider", | ||
_ScalacProvider = "ScalacProvider") | ||
load( | ||
":common.bzl", | ||
"add_labels_of_jars_to", | ||
|
@@ -222,15 +225,21 @@ StatsfileOutput: {statsfile_output} | |
ctx.actions.write( | ||
output = argfile, content = scalac_args + optional_scalac_args) | ||
|
||
scalac_provider = ctx.attr._scalac[_ScalacProvider] | ||
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. @johnynek given your work trying to make 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. Yeah, I’d prefer a parameter right keep function cleaner. Eventually I’d like to not accept ctx and instead only actions. |
||
scalac_inputs, _, scalac_input_manifests = ctx.resolve_command( | ||
tools = [scalac_provider.scalac]) | ||
|
||
outs = [output, statsfile] | ||
ins = (compiler_classpath_jars.to_list() + all_srcjars.to_list() + | ||
list(sources) + plugins_list + dependency_analyzer_plugin_jars + | ||
classpath_resources + resources + resource_jars + [manifest, argfile]) | ||
ins = ( | ||
compiler_classpath_jars.to_list() + all_srcjars.to_list() + list(sources) | ||
+ plugins_list + dependency_analyzer_plugin_jars + classpath_resources + | ||
resources + resource_jars + [manifest, argfile] + scalac_inputs) | ||
|
||
ctx.actions.run( | ||
inputs = ins, | ||
outputs = outs, | ||
executable = ctx.executable._scalac, | ||
executable = scalac_provider.scalac.files_to_run.executable, | ||
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. can you take this from the tuple output ( 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. Doesn't work, command is 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. @laurentlb is this the expected behavior? Sounds strange we can get the inputs and manifests from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @laurentlb @c-parsons |
||
input_manifests = scalac_input_manifests, | ||
mnemonic = "Scalac", | ||
progress_message = "scala %s" % target_label, | ||
execution_requirements = {"supports-workers": "1"}, | ||
|
@@ -478,7 +487,8 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], | |
dependency_analyzer_is_off = is_dependency_analyzer_off(ctx) | ||
|
||
# Get jars from deps | ||
auto_deps = [ctx.attr._scalalib, ctx.attr._scalareflect] | ||
scalac_provider = ctx.attr._scalac[_ScalacProvider] | ||
auto_deps = [scalac_provider.scalalib, scalac_provider.scalareflect] | ||
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. This could directly be given in the toolchain/provider. |
||
deps_jars = collect_jars(ctx.attr.deps + auto_deps + extra_deps, | ||
dependency_analyzer_is_off) | ||
(cjars, transitive_rjars, jars2labels, | ||
|
@@ -616,7 +626,8 @@ def scala_binary_impl(ctx): | |
def scala_repl_impl(ctx): | ||
# need scala-compiler for MainGenericRunner below | ||
jars = _collect_jars_from_common_ctx( | ||
ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) | ||
ctx, | ||
extra_runtime_deps = [ctx.attr._scalac[_ScalacProvider].scalacompiler]) | ||
(cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) | ||
|
||
args = " ".join(ctx.attr.scalacopts) | ||
|
@@ -664,6 +675,7 @@ def _scala_test_flags(ctx): | |
def scala_test_impl(ctx): | ||
if len(ctx.attr.suites) != 0: | ||
print("suites attribute is deprecated. All scalatest test suites are run") | ||
|
||
jars = _collect_jars_from_common_ctx( | ||
ctx, | ||
extra_runtime_deps = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,36 @@ def create_scala_provider(ijar, class_jar, compile_jars, | |
transitive_runtime_jars = transitive_runtime_jars, | ||
transitive_exports = [] #needed by intellij plugin | ||
) | ||
|
||
ScalacProvider = provider( | ||
doc = "ScalaProvider", | ||
fields = [ | ||
"scalac", | ||
"scalalib", | ||
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 think we should consider instead 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. In Would the idea be to have 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 think attr.label_list is convenient. |
||
"scalareflect", | ||
"scalacompiler", | ||
]) | ||
|
||
def _declare_scalac_provider(ctx): | ||
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. this is an interesting approach. |
||
return [ | ||
ScalacProvider( | ||
scalac = ctx.attr.scalac, | ||
scalalib = ctx.attr.scalalib, | ||
scalareflect = ctx.attr.scalareflect, | ||
scalacompiler = ctx.attr.scalacompiler, | ||
) | ||
] | ||
|
||
declare_scalac_provider = rule( | ||
implementation = _declare_scalac_provider, | ||
attrs = { | ||
"scalac": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
allow_files = True, | ||
mandatory = True), | ||
"scalalib": attr.label(mandatory = True, allow_files = True), | ||
"scalareflect": attr.label(mandatory = True, allow_files = True), | ||
"scalacompiler": attr.label(mandatory = True, allow_files = True), | ||
"scalaxml": attr.label(mandatory = True, allow_files = True) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,18 @@ load( | |
"@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", | ||
_scala_maven_import_external = "scala_maven_import_external") | ||
|
||
load( | ||
"@io_bazel_rules_scala//scala:providers.bzl", | ||
_ScalacProvider = "ScalacProvider", | ||
) | ||
|
||
load( | ||
"@io_bazel_rules_scala//scala:scala_cross_version.bzl", | ||
_new_scala_repository = "new_scala_repository", | ||
_extract_major_version = "extract_major_version", | ||
_default_scala_version = "default_scala_version", | ||
_default_scala_version_jar_shas = "default_scala_version_jar_shas") | ||
|
||
load( | ||
"@io_bazel_rules_scala//specs2:specs2_junit.bzl", | ||
_specs2_junit_dependencies = "specs2_junit_dependencies") | ||
|
@@ -33,23 +45,6 @@ _implicit_deps = { | |
cfg = "host", | ||
default = Label("@bazel_tools//tools/jdk:singlejar"), | ||
allow_files = True), | ||
"_scalac": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
default = Label("//src/java/io/bazel/rulesscala/scalac"), | ||
allow_files = True), | ||
"_scalalib": attr.label( | ||
default = Label( | ||
"//external:io_bazel_rules_scala/dependency/scala/scala_library"), | ||
allow_files = True), | ||
"_scalacompiler": attr.label( | ||
default = Label( | ||
"//external:io_bazel_rules_scala/dependency/scala/scala_compiler"), | ||
allow_files = True), | ||
"_scalareflect": attr.label( | ||
default = Label( | ||
"//external:io_bazel_rules_scala/dependency/scala/scala_reflect"), | ||
allow_files = True), | ||
"_zipper": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
|
@@ -61,7 +56,9 @@ _implicit_deps = { | |
default = Label("@bazel_tools//tools/jdk:current_java_runtime"), | ||
cfg = "host"), | ||
"_java_runtime": attr.label( | ||
default = Label("@bazel_tools//tools/jdk:current_java_runtime")) | ||
default = Label("@bazel_tools//tools/jdk:current_java_runtime")), | ||
"_scalac": attr.label( | ||
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.
Also, if we make this public, e.g. use 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. Currently there's no point in making it public as we can only have one version of I'll change the name to |
||
default = Label("@scala_default"), providers = [_ScalacProvider]) | ||
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’d like to namespace this io_bazel_rules_scala... |
||
} | ||
|
||
# Single dep to allow IDEs to pickup all the implicit dependencies. | ||
|
@@ -257,54 +254,66 @@ scala_repl = rule( | |
toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], | ||
) | ||
|
||
def scala_repositories(maven_servers = ["http://central.maven.org/maven2"]): | ||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scala_library", | ||
artifact = "org.scala-lang:scala-library:2.11.12", | ||
jar_sha256 = | ||
"0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce", | ||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scala_compiler", | ||
artifact = "org.scala-lang:scala-compiler:2.11.12", | ||
jar_sha256 = | ||
"3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0", | ||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
def scala_repositories( | ||
scala_version = _default_scala_version(), | ||
scala_version_jar_shas = _default_scala_version_jar_shas(), | ||
maven_servers = ["http://central.maven.org/maven2"]): | ||
major_version = _extract_major_version(scala_version) | ||
version_underscore = scala_version.replace(".", "_") | ||
|
||
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. Do we need version_underscore? Seems like a pure function of scala_version. 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. Not necessarily, I can call it when needed instead ( |
||
_new_scala_repository( | ||
name = "scala_default", | ||
scala_version = scala_version, | ||
scala_version_jar_shas = scala_version_jar_shas, | ||
maven_servers = maven_servers) | ||
|
||
scala_jar_shas = { | ||
"2.11": { | ||
"scalatest": "2aafeb41257912cbba95f9d747df9ecdc7ff43f039d35014b4c2a8eb7ed9ba2f", | ||
"scalactic": "84723064f5716f38990fe6e65468aa39700c725484efceef015771d267341cf2", | ||
"scala_xml": "767e11f33eddcd506980f0ff213f9d553a6a21802e3be1330345f62f7ee3d50f", | ||
"scala_parser_combinators": "0dfaafce29a9a245b0a9180ec2c1073d2bd8f0330f03a9f1f6a74d1bc83f62d6" | ||
}, | ||
"2.12": { | ||
"scalatest": "b416b5bcef6720da469a8d8a5726e457fc2d1cd5d316e1bc283aa75a2ae005e5", | ||
"scalactic": "57e25b4fd969b1758fe042595112c874dfea99dca5cc48eebe07ac38772a0c41", | ||
"scala_xml": "035015366f54f403d076d95f4529ce9eeaf544064dbc17c2d10e4f5908ef4256", | ||
"scala_parser_combinators": "282c78d064d3e8f09b3663190d9494b85e0bb7d96b0da05994fe994384d96111" | ||
}, | ||
} | ||
|
||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scala_reflect", | ||
artifact = "org.scala-lang:scala-reflect:2.11.12", | ||
jar_sha256 = | ||
"6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04", | ||
name = "io_bazel_rules_scala_scalatest", | ||
artifact = "org.scalatest:scalatest_{major_version}:3.0.5".format( | ||
major_version = major_version), | ||
jar_sha256 = scala_jar_shas[major_version]["scalatest"], | ||
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. We should do one lookup of |
||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scalatest", | ||
artifact = "org.scalatest:scalatest_2.11:2.2.6", | ||
jar_sha256 = | ||
"f198967436a5e7a69cfd182902adcfbcb9f2e41b349e1a5c8881a2407f615962", | ||
name = "io_bazel_rules_scala_scalactic", | ||
artifact = "org.scalactic:scalactci_{major_version}:3.0.5".format( | ||
major_version = major_version), | ||
jar_sha256 = scala_jar_shas[major_version]["scalactic"], | ||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
|
||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scala_xml", | ||
artifact = "org.scala-lang.modules:scala-xml_2.11:1.0.5", | ||
jar_sha256 = | ||
"767e11f33eddcd506980f0ff213f9d553a6a21802e3be1330345f62f7ee3d50f", | ||
artifact = "org.scala-lang.modules:scala-xml_{major_version}:1.0.5". | ||
format(major_version = major_version), | ||
jar_sha256 = scala_jar_shas[major_version]["scala_xml"], | ||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
|
||
_scala_maven_import_external( | ||
name = "io_bazel_rules_scala_scala_parser_combinators", | ||
artifact = "org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4", | ||
jar_sha256 = | ||
"0dfaafce29a9a245b0a9180ec2c1073d2bd8f0330f03a9f1f6a74d1bc83f62d6", | ||
artifact = | ||
"org.scala-lang.modules:scala-parser-combinators_{major_version}:1.0.4". | ||
format(major_version = major_version), | ||
jar_sha256 = scala_jar_shas[major_version]["scala_parser_combinators"], | ||
licenses = ["notice"], | ||
server_urls = maven_servers, | ||
) | ||
|
@@ -355,17 +364,24 @@ def scala_repositories(maven_servers = ["http://central.maven.org/maven2"]): | |
name = "io_bazel_rules_scala/dependency/commons_io/commons_io", | ||
actual = "@scalac_rules_commons_io//jar") | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scalatest/scalatest", | ||
actual = "@io_bazel_rules_scala//scala/scalatest:scalatest") | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scala/scala_compiler", | ||
actual = "@io_bazel_rules_scala_scala_compiler") | ||
actual = "@io_bazel_rules_scala_scala_compiler_{}".format( | ||
version_underscore)) | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scala/scala_library", | ||
actual = "@io_bazel_rules_scala_scala_library") | ||
actual = "@io_bazel_rules_scala_scala_library_{}".format( | ||
version_underscore)) | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scala/scala_reflect", | ||
actual = "@io_bazel_rules_scala_scala_reflect") | ||
actual = "@io_bazel_rules_scala_scala_reflect_{}".format( | ||
version_underscore)) | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scala/scala_xml", | ||
|
@@ -375,10 +391,6 @@ def scala_repositories(maven_servers = ["http://central.maven.org/maven2"]): | |
name = "io_bazel_rules_scala/dependency/scala/parser_combinators", | ||
actual = "@io_bazel_rules_scala_scala_parser_combinators") | ||
|
||
native.bind( | ||
name = "io_bazel_rules_scala/dependency/scalatest/scalatest", | ||
actual = "@io_bazel_rules_scala_scalatest") | ||
|
||
def _sanitize_string_for_usage(s): | ||
res_array = [] | ||
for idx in range(len(s)): | ||
|
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.
Seems like the shas need to become a map of scala version -> artifact -> sha.
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.
My understanding is that these maven_jars are just for tests and as they always use
default_scala_version()
(which is hardcoded) we shouldn't need a map here. The shas only need to be changed if we changedefault_scala_version()
. Or should we add a map just to make the fact that they need to be changed more explicit?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.
yeah, we should refactor these into a bzl function
load_test_jars()
or something to make it clearer. Don't need to do that in this PR.