diff --git a/README.md b/README.md index d7495a5d7..8802ed390 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,25 @@ test --strategy=Scalac=worker ``` to your command line, or to enable by default for building/testing add it to your .bazelrc. +## Selecting Scala version + +Rules scala supports all minor versions of Scala 2.11/2.12. By default `Scala 2.11.12` is used and to use another +version you need to +specify it when calling `scala_repositories`. `scala_repositories` takes a tuple `(scala_version, scala_version_jar_shas)` +as a parameter where `scala_version` is the scala version and `scala_version_jar_shas` is a `dict` with +`sha256` hashes for the maven artifacts `scala_library`, `scala_reflect` and `scala_compiler`: +```python +scala_repositories(("2.12.6", { + "scala_compiler": "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0", + "scala_library": "0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce", + "scala_reflect": "6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04" +})) +``` +If you're using any of the rules `twitter_scrooge`, `tut_repositories`, `scala_proto_repositories` +or `specs2_junit_repositories` you also need to specify `scala_version` for them. See `./test_version/WORKSPACE.template` +for an example workspace using another scala version. + + ## Bazel compatible versions | bazel | rules_scala gitsha | diff --git a/WORKSPACE b/WORKSPACE index 4b587eb66..c378150b4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,26 +24,35 @@ load("//specs2:specs2_junit.bzl", "specs2_junit_repositories") specs2_junit_repositories() -load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") +load("//scala:scala_cross_version.bzl", "scala_mvn_artifact", "default_scala_major_version") # test adding a scala jar: maven_jar( name = "com_twitter__scalding_date", - artifact = scala_mvn_artifact("com.twitter:scalding-date:0.17.0"), + artifact = scala_mvn_artifact( + "com.twitter:scalding-date:0.17.0", + default_scala_major_version(), + ), sha1 = "420fb0c4f737a24b851c4316ee0362095710caa5", ) # For testing that we don't include sources jars to the classpath maven_jar( name = "org_typelevel__cats_core", - artifact = scala_mvn_artifact("org.typelevel:cats-core:0.9.0"), + artifact = scala_mvn_artifact( + "org.typelevel:cats-core:0.9.0", + default_scala_major_version(), + ), sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314", ) # test of a plugin maven_jar( name = "org_psywerx_hairyfotr__linter", - artifact = scala_mvn_artifact("org.psywerx.hairyfotr:linter:0.1.13"), + artifact = scala_mvn_artifact( + "org.psywerx.hairyfotr:linter:0.1.13", + default_scala_major_version(), + ), sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4", ) diff --git a/scala/BUILD b/scala/BUILD index b2eefcd35..c76b2defb 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -1,3 +1,7 @@ +load( + "@io_bazel_rules_scala//scala:providers.bzl", + _declare_scalac_provider = "declare_scalac_provider", +) load("//scala:scala_toolchain.bzl", "scala_toolchain") toolchain_type( @@ -23,3 +27,22 @@ java_import( jars = ["@bazel_tools//tools/jdk:TestRunner_deploy.jar"], visibility = ["//visibility:public"], ) + +_declare_scalac_provider( + name = "scala_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", + ], + scalac = "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac", + visibility = ["//visibility:public"], +) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index fb859d13a..7f75ef0bf 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -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", @@ -132,7 +135,7 @@ def compile_scala(ctx, target_label, output, manifest, statsfile, sources, cjars, all_srcjars, transitive_compile_jars, plugins, resource_strip_prefix, resources, resource_jars, labels, in_scalacopts, print_compile_time, expect_java_output, - scalac_jvm_flags): + scalac_jvm_flags, scalac_provider): # look for any plugins: plugins = _collect_plugin_paths(plugins) dependency_analyzer_plugin_jars = [] @@ -223,15 +226,20 @@ StatsfileOutput: {statsfile_output} ctx.actions.write( output = argfile, content = scalac_args + optional_scalac_args) + 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, + input_manifests = scalac_input_manifests, mnemonic = "Scalac", progress_message = "scala %s" % target_label, execution_requirements = {"supports-workers": "1"}, @@ -263,7 +271,8 @@ def try_to_compile_java_jar(ctx, scala_output, all_srcjars, java_srcs, providers_of_dependencies = collect_java_providers_of(ctx.attr.deps) providers_of_dependencies += collect_java_providers_of( implicit_junit_deps_needed_for_java_compilation) - providers_of_dependencies += collect_java_providers_of([ctx.attr._scalalib]) + providers_of_dependencies += collect_java_providers_of( + ctx.attr._scala_provider[_ScalacProvider].default_classpath) scala_sources_java_provider = _interim_java_provider_for_java_compilation( scala_output) providers_of_dependencies += [scala_sources_java_provider] @@ -323,13 +332,13 @@ def _compile_or_empty(ctx, manifest, jars, srcjars, buildijar, sources = [ f for f in ctx.files.srcs if f.basename.endswith(_scala_extension) ] + java_srcs - compile_scala(ctx, ctx.label, ctx.outputs.jar, manifest, - ctx.outputs.statsfile, sources, jars, all_srcjars, - transitive_compile_jars, ctx.attr.plugins, - ctx.attr.resource_strip_prefix, ctx.files.resources, - ctx.files.resource_jars, jars2labels, ctx.attr.scalacopts, - ctx.attr.print_compile_time, ctx.attr.expect_java_output, - ctx.attr.scalac_jvm_flags) + compile_scala( + ctx, ctx.label, ctx.outputs.jar, manifest, ctx.outputs.statsfile, + sources, jars, all_srcjars, transitive_compile_jars, ctx.attr.plugins, + ctx.attr.resource_strip_prefix, ctx.files.resources, + ctx.files.resource_jars, jars2labels, ctx.attr.scalacopts, + ctx.attr.print_compile_time, ctx.attr.expect_java_output, + ctx.attr.scalac_jvm_flags, ctx.attr._scala_provider[_ScalacProvider]) # build ijar if needed if buildijar: @@ -474,15 +483,16 @@ def is_dependency_analyzer_off(ctx): # Extract very common code out from dependency analysis into single place # automatically adds dependency on scala-library and scala-reflect # collects jars from deps, runtime jars from runtime_deps, and -def _collect_jars_from_common_ctx(ctx, extra_deps = [], +def _collect_jars_from_common_ctx(ctx, + base_classpath, + extra_deps = [], extra_runtime_deps = []): dependency_analyzer_is_off = is_dependency_analyzer_off(ctx) - # Get jars from deps - auto_deps = [ctx.attr._scalalib, ctx.attr._scalareflect] - deps_jars = collect_jars(ctx.attr.deps + auto_deps + extra_deps, + deps_jars = collect_jars(ctx.attr.deps + extra_deps + base_classpath, dependency_analyzer_is_off) + (cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, @@ -499,13 +509,14 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], jars2labels = jars2labels, transitive_compile_jars = transitive_compile_jars) -def _lib(ctx, non_macro_lib): +def _lib(ctx, base_classpath, non_macro_lib): # Build up information from dependency-like attributes # This will be used to pick up srcjars from non-scala library # targets (like thrift code generation) srcjars = collect_srcjars(ctx.attr.deps) - jars = _collect_jars_from_common_ctx(ctx) + + jars = _collect_jars_from_common_ctx(ctx, base_classpath) (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) write_manifest(ctx) @@ -551,10 +562,13 @@ def _lib(ctx, non_macro_lib): ) def scala_library_impl(ctx): - return _lib(ctx, True) + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] + return _lib(ctx, scalac_provider.default_classpath, True) def scala_macro_library_impl(ctx): - return _lib(ctx, False) # don't build the ijar for macros + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] + return _lib(ctx, scalac_provider.default_macro_classpath, + False) # don't build the ijar for macros # Common code shared by all scala binary implementations. def _scala_binary_common(ctx, @@ -600,7 +614,8 @@ def _scala_binary_common(ctx, runfiles = runfiles) def scala_binary_impl(ctx): - jars = _collect_jars_from_common_ctx(ctx) + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] + jars = _collect_jars_from_common_ctx(ctx, scalac_provider.default_classpath) (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) wrapper = _write_java_wrapper(ctx, "", "") @@ -616,9 +631,12 @@ def scala_binary_impl(ctx): return out def scala_repl_impl(ctx): + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] # need scala-compiler for MainGenericRunner below jars = _collect_jars_from_common_ctx( - ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) + ctx, + scalac_provider.default_repl_classpath, + ) (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) args = " ".join(ctx.attr.scalacopts) @@ -666,8 +684,11 @@ 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") + + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] jars = _collect_jars_from_common_ctx( ctx, + scalac_provider.default_classpath, extra_runtime_deps = [ ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner ], @@ -731,8 +752,10 @@ def scala_junit_test_impl(ctx): fail( "Setting at least one of the attributes ('prefixes','suffixes') is required" ) + scalac_provider = ctx.attr._scala_provider[_ScalacProvider] jars = _collect_jars_from_common_ctx( ctx, + scalac_provider.default_classpath, extra_deps = [ ctx.attr._junit, ctx.attr._hamcrest, ctx.attr.suite_label, ctx.attr._bazel_test_runner diff --git a/scala/providers.bzl b/scala/providers.bzl index 1d68dd49a..4f271a16d 100644 --- a/scala/providers.bzl +++ b/scala/providers.bzl @@ -24,3 +24,35 @@ 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", + "default_classpath", + "default_macro_classpath", + "default_repl_classpath", + ]) + +def _declare_scalac_provider(ctx): + return [ + ScalacProvider( + scalac = ctx.attr.scalac, + 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 = { + "scalac": attr.label( + executable = True, + cfg = "host", + allow_files = True, + mandatory = True), + "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.bzl b/scala/scala.bzl index 920cb6d54..41e99e3ca 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -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_default_repository = "new_scala_default_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,10 @@ _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")), + "_scala_provider": attr.label( + default = Label("@io_bazel_rules_scala//scala:scala_default"), + providers = [_ScalacProvider]) } # Single dep to allow IDEs to pickup all the implicit dependencies. @@ -257,54 +255,67 @@ 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, - ) +def scala_repositories( + scala_version_shas = (_default_scala_version(), + _default_scala_version_jar_shas()), + maven_servers = ["http://central.maven.org/maven2"]): + (scala_version, scala_version_jar_shas) = scala_version_shas + major_version = _extract_major_version(scala_version) + + _new_scala_default_repository( + scala_version = scala_version, + scala_version_jar_shas = scala_version_jar_shas, + maven_servers = maven_servers) + + scala_extra_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_version_extra_jar_shas = scala_extra_jar_shas[major_version] + _scala_maven_import_external( - name = "io_bazel_rules_scala_scala_compiler", - artifact = "org.scala-lang:scala-compiler:2.11.12", - jar_sha256 = - "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0", + name = "io_bazel_rules_scala_scalatest", + artifact = "org.scalatest:scalatest_{major_version}:3.0.5".format( + major_version = major_version), + jar_sha256 = scala_version_extra_jar_shas["scalatest"], licenses = ["notice"], server_urls = maven_servers, ) _scala_maven_import_external( - name = "io_bazel_rules_scala_scala_reflect", - artifact = "org.scala-lang:scala-reflect:2.11.12", - jar_sha256 = - "6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04", - 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:scalactic_{major_version}:3.0.5".format( + major_version = major_version), + jar_sha256 = scala_version_extra_jar_shas["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_version_extra_jar_shas["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_version_extra_jar_shas["scala_parser_combinators"], licenses = ["notice"], server_urls = maven_servers, ) @@ -355,6 +366,10 @@ 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") @@ -375,10 +390,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)): diff --git a/scala/scala_cross_version.bzl b/scala/scala_cross_version.bzl index 3895296c0..3b9c7c1b8 100644 --- a/scala/scala_cross_version.bzl +++ b/scala/scala_cross_version.bzl @@ -5,23 +5,72 @@ # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 -# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") """Helper functions for Scala cross-version support. Encapsulates the logic of abstracting over Scala major version (2.11, 2.12, etc) for dependency resolution.""" -def scala_version(): +def default_scala_version(): """return the scala version for use in maven coordinates""" - return "2.11" + return "2.11.12" + +def default_scala_version_jar_shas(): + return { + "scala_compiler": "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0", + "scala_library": "0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce", + "scala_reflect": "6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04", + } + +def extract_major_version(scala_version): + """Return major Scala version given a full version, e.g. "2.11.11" -> "2.11" """ + return scala_version[:scala_version.find(".", 2)] -def scala_mvn_artifact(artifact): +def extract_major_version_underscore(scala_version): + """Return major Scala version with underscore given a full version, + e.g. "2.11.11" -> "2_11" """ + return extract_major_version(scala_version).replace(".", "_") + +def default_scala_major_version(): + return extract_major_version(default_scala_version()) + +def scala_mvn_artifact(artifact, + major_scala_version = default_scala_major_version()): + """Add scala version to maven artifact""" gav = artifact.split(":") groupid = gav[0] artifactid = gav[1] version = gav[2] - return "%s:%s_%s:%s" % (groupid, artifactid, scala_version(), version) + return "%s:%s_%s:%s" % (groupid, artifactid, major_scala_version, version) + +def new_scala_default_repository(scala_version, scala_version_jar_shas, + maven_servers): + + _scala_maven_import_external( + name = "io_bazel_rules_scala_scala_library", + artifact = "org.scala-lang:scala-library:{}".format(scala_version), + jar_sha256 = scala_version_jar_shas["scala_library"], + licenses = ["notice"], + server_urls = maven_servers, + ) + _scala_maven_import_external( + name = "io_bazel_rules_scala_scala_compiler", + artifact = "org.scala-lang:scala-compiler:{}".format(scala_version), + jar_sha256 = scala_version_jar_shas["scala_compiler"], + licenses = ["notice"], + server_urls = maven_servers, + ) + _scala_maven_import_external( + name = "io_bazel_rules_scala_scala_reflect", + artifact = "org.scala-lang:scala-reflect:{}".format(scala_version), + jar_sha256 = scala_version_jar_shas["scala_reflect"], + licenses = ["notice"], + server_urls = maven_servers, + ) diff --git a/scala/scalatest/BUILD b/scala/scalatest/BUILD new file mode 100644 index 000000000..2e4ad67bb --- /dev/null +++ b/scala/scalatest/BUILD @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +load("//scala:scala_import.bzl", "scala_import") + +scala_import( + name = "scalatest", + jars = [], + exports = [ + "@io_bazel_rules_scala_scalactic", + "@io_bazel_rules_scala_scalatest", + ], +) diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index 2179edc34..25ca86c5b 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -5,16 +5,26 @@ load( load( "//scala:scala_cross_version.bzl", - "scala_mvn_artifact", + _scala_mvn_artifact = "scala_mvn_artifact", + _extract_major_version = "extract_major_version", + _default_scala_version = "default_scala_version", ) +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") + load( "//scala/private:common.bzl", "collect_jars", "create_java_provider", ) -def scala_proto_repositories(): +def scala_proto_repositories( + scala_version = _default_scala_version(), + maven_servers = ["http://central.maven.org/maven2"]): + major_version = _extract_major_version(scala_version) + native.maven_server( name = "scala_proto_deps_maven_server", url = "http://central.maven.org/maven2/", @@ -31,86 +41,108 @@ def scala_proto_repositories(): name = 'io_bazel_rules_scala/dependency/proto/protoc', actual = '@scala_proto_rules_protoc_jar//jar') - native.maven_jar( + scala_jar_shas = { + "2.11": { + "scalapb_plugin": "c79e1e1398de88779611fda91ef1a9699f9390946bee6a4bba113f3cc036a838", + "protoc_bridge": "a5beafaa7d49822d1412cce675c226304c6499ff65ec6e8cff7e65ae537076b5", + "scalapbc": "32b7340a545b282c513d3c91e0ebf906e2ad1de45c0875e7e7bbaaa0909f5e60", + "scalapb_runtime": "d5b597f637a6f99560d674715647fc5bb199ebf4ca6e263ed1614ea4eb63baad", + "scalapb_runtime_grpc": "d7ce3059cc63b3e1bcc4f710cff55facb92a478cc2225e4c6830ab7ba0fd4fe8", + "scalapb_lenses": "1e9fa3830dfcee99ba20bb55468757bb35762b5ee243ddb8c4d238e749a95cd7", + "scalapb_fastparse": "9e07298f20ee37e828f2699b71b447008ebf122cc86cab1d1fcd8d00fad4837b", + }, + "2.12": { + "scalapb_plugin": "8fec3566010ffbd61b1b44e23bd344790533f5648d918b42ab683d79bdee9ddf", + "protoc_bridge": "bb53dacf3dcd588ea8039b44abc9d816f3150f01916d07a76e1e248389b35d71", + "scalapbc": "d2d3a7477f7c89b70476627c1eb44781ccb1c99f36ed208fca69849e5d8dd692", + "scalapb_runtime": "26a8446755b1b11a75a5e3a1d055ef251b7a479a07bf2285ee1aaf8df92a71f5", + "scalapb_runtime_grpc": "fb2ca8ea6c66ec79e4a9ad279c143af08ec9d0c9b607fb0965cc5aee19a8679a", + "scalapb_lenses": "7cedcbc3125ad3f156466d6f3aec24b7fe6954cdc54a426ea089b4a46cd84c1c", + "scalapb_fastparse": "7bc2a3131204e737f020f94e19b1e62a1bf5359f5741c35dff9351ef36d7a80e", + }, + } + + scala_version_jar_shas = scala_jar_shas[major_version] + + _scala_maven_import_external( name = "scala_proto_rules_scalapb_plugin", - artifact = scala_mvn_artifact( - "com.trueaccord.scalapb:compilerplugin:0.6.5"), - sha1 = "290094c632c95b36b6f66d7dbfdc15242b9a247f", - server = "scala_proto_deps_maven_server", - ) + artifact = _scala_mvn_artifact( + "com.trueaccord.scalapb:compilerplugin:0.6.5", major_version), + jar_sha256 = scala_version_jar_shas["scalapb_plugin"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapb_plugin', - actual = '@scala_proto_rules_scalapb_plugin//jar') + actual = '@scala_proto_rules_scalapb_plugin') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_protoc_bridge", - artifact = scala_mvn_artifact( - "com.trueaccord.scalapb:protoc-bridge:0.3.0-M1"), - sha1 = "73d38f045ea8f09cc1264991d1064add6eac9e00", - server = "scala_proto_deps_maven_server", - ) + artifact = _scala_mvn_artifact( + "com.trueaccord.scalapb:protoc-bridge:0.3.0-M1", major_version), + jar_sha256 = scala_version_jar_shas["protoc_bridge"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/protoc_bridge', - actual = '@scala_proto_rules_protoc_bridge//jar') + actual = '@scala_proto_rules_protoc_bridge') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_scalapbc", - artifact = scala_mvn_artifact("com.trueaccord.scalapb:scalapbc:0.6.5"), - sha1 = "b204d6d56a042b973af5b6fe28f81ece232d1fe4", - server = "scala_proto_deps_maven_server", - ) - + artifact = _scala_mvn_artifact("com.trueaccord.scalapb:scalapbc:0.6.5", + major_version), + jar_sha256 = scala_version_jar_shas["scalapbc"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapbc', - actual = '@scala_proto_rules_scalapbc//jar') + actual = '@scala_proto_rules_scalapbc') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_scalapb_runtime", - artifact = scala_mvn_artifact( - "com.trueaccord.scalapb:scalapb-runtime:0.6.5"), - sha1 = "ac9287ff48c632df525773570ee4842e3ddf40e9", - server = "scala_proto_deps_maven_server", - ) - + artifact = _scala_mvn_artifact( + "com.trueaccord.scalapb:scalapb-runtime:0.6.5", major_version), + jar_sha256 = scala_version_jar_shas["scalapb_runtime"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime', - actual = '@scala_proto_rules_scalapb_runtime//jar') + actual = '@scala_proto_rules_scalapb_runtime') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_scalapb_runtime_grpc", - artifact = scala_mvn_artifact( - "com.trueaccord.scalapb:scalapb-runtime-grpc:0.6.5"), - sha1 = "9dc3374001f4190548db36a7dc87bd4f9bca6f9c", - server = "scala_proto_deps_maven_server", - ) - + artifact = _scala_mvn_artifact( + "com.trueaccord.scalapb:scalapb-runtime-grpc:0.6.5", major_version), + jar_sha256 = scala_version_jar_shas["scalapb_runtime_grpc"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime_grpc', - actual = '@scala_proto_rules_scalapb_runtime_grpc//jar') + actual = '@scala_proto_rules_scalapb_runtime_grpc') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_scalapb_lenses", - artifact = scala_mvn_artifact("com.trueaccord.lenses:lenses:0.4.12"), - sha1 = "c5fbf5b872ce99d9a16d3392ccc0d15a0e43d823", - server = "scala_proto_deps_maven_server", - ) - + artifact = _scala_mvn_artifact("com.trueaccord.lenses:lenses:0.4.12", + major_version), + jar_sha256 = scala_version_jar_shas["scalapb_lenses"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapb_lenses', - actual = '@scala_proto_rules_scalapb_lenses//jar') + actual = '@scala_proto_rules_scalapb_lenses') - native.maven_jar( + _scala_maven_import_external( name = "scala_proto_rules_scalapb_fastparse", - artifact = scala_mvn_artifact("com.lihaoyi:fastparse:0.4.4"), - sha1 = "f065fe0afe6fd2b4557d985c37362c36f08f9947", - server = "scala_proto_deps_maven_server", - ) + artifact = _scala_mvn_artifact("com.lihaoyi:fastparse:0.4.4", + major_version), + jar_sha256 = scala_version_jar_shas["scalapb_fastparse"], + licenses = ["notice"], + server_urls = maven_servers) native.bind( name = 'io_bazel_rules_scala/dependency/proto/scalapb_fastparse', - actual = '@scala_proto_rules_scalapb_fastparse//jar') + actual = '@scala_proto_rules_scalapb_fastparse') native.maven_jar( name = "scala_proto_rules_grpc_core", diff --git a/specs2/BUILD b/specs2/BUILD index 3b73536df..8106d7c6a 100644 --- a/specs2/BUILD +++ b/specs2/BUILD @@ -4,11 +4,11 @@ java_import( name = "specs2", jars = [], exports = [ - "@io_bazel_rules_scala_org_scalaz_scalaz_core//jar", - "@io_bazel_rules_scala_org_scalaz_scalaz_effect//jar", - "@io_bazel_rules_scala_org_specs2_specs2_common//jar", - "@io_bazel_rules_scala_org_specs2_specs2_core//jar", - "@io_bazel_rules_scala_org_specs2_specs2_matcher//jar", + "@io_bazel_rules_scala_org_scalaz_scalaz_core", + "@io_bazel_rules_scala_org_scalaz_scalaz_effect", + "@io_bazel_rules_scala_org_specs2_specs2_common", + "@io_bazel_rules_scala_org_specs2_specs2_core", + "@io_bazel_rules_scala_org_specs2_specs2_matcher", ], deps = [ "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", diff --git a/specs2/specs2.bzl b/specs2/specs2.bzl index 260b34f18..83ee448a8 100644 --- a/specs2/specs2.bzl +++ b/specs2/specs2.bzl @@ -1,44 +1,82 @@ load( "//scala:scala_cross_version.bzl", - "scala_mvn_artifact", -) + _scala_mvn_artifact = "scala_mvn_artifact", + _default_scala_version = "default_scala_version", + _extract_major_version = "extract_major_version") + +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") def specs2_version(): return "3.8.8" -def specs2_repositories(): +def specs2_repositories(scala_version = _default_scala_version(), + maven_servers = ["http://central.maven.org/maven2"]): + major_version = _extract_major_version(scala_version) + + scala_jar_shas = { + "2.11": { + "specs2_core": "692eafc052a838c0c8552afc1a15e10978979d1703c812bd16f572d77ddd07ab", + "specs2_common": "ba06a6218704cff61296e13300a87b07ac5ab5ad45fc82dce37e550101b8cdb5", + "specs2_matcher": "9c8cc2148a6692aa4e2fcd1282c28971215f501f10d532d1a3a3c33fd803fedc", + "scalaz_effect": "4d45f0d1bb6958f5c6781a5e94d9528934b6a1404346d224dda25da064b0c964", + "scalaz_core": "810504bc8d669913af830dd5d9c87f83e0570898f09be6474f0d5603bba8ba79", + }, + "2.12": { + "specs2_core": "1fc47c1199675ed60b58923c84006cc4f776818b11e0a18a47db29c03a60ee97", + "specs2_common": "c0a892fd1a5a1aaf5bb29792e39da5459f1564a721d9a6a0954fb52c395b2deb", + "specs2_matcher": "c17b8f1e4c3da6c1489c59f67e03374b358fdfbe90d9def2a7e4e1b1b10f5046", + "scalaz_effect": "eca21ba69a1532c74ea77356b59d6175a5fd54dac7f57f1d1979738c98521919", + "scalaz_core": "b53cd091daec1c8df8c4244e5b8b460b7416c2cc86aecd25dec4c93d2baf2b04", + }, + } + + scala_version_jar_shas = scala_jar_shas[major_version] - native.maven_jar( + _scala_maven_import_external( name = "io_bazel_rules_scala_org_specs2_specs2_core", - artifact = scala_mvn_artifact( - "org.specs2:specs2-core:" + specs2_version()), - sha1 = "495bed00c73483f4f5f43945fde63c615d03e637", + artifact = _scala_mvn_artifact( + "org.specs2:specs2-core:" + specs2_version(), major_version), + jar_sha256 = scala_version_jar_shas["specs2_core"], + licenses = ["notice"], + server_urls = maven_servers, ) - native.maven_jar( + _scala_maven_import_external( name = "io_bazel_rules_scala_org_specs2_specs2_common", - artifact = scala_mvn_artifact( - "org.specs2:specs2-common:" + specs2_version()), - sha1 = "15bc009eaae3a574796c0f558d8696b57ae903c3", + artifact = _scala_mvn_artifact( + "org.specs2:specs2-common:" + specs2_version(), major_version), + jar_sha256 = scala_version_jar_shas["specs2_common"], + licenses = ["notice"], + server_urls = maven_servers, ) - native.maven_jar( + _scala_maven_import_external( name = "io_bazel_rules_scala_org_specs2_specs2_matcher", - artifact = scala_mvn_artifact( - "org.specs2:specs2-matcher:" + specs2_version()), - sha1 = "d2e967737abef7421e47b8994a8c92784e624d62", + artifact = _scala_mvn_artifact( + "org.specs2:specs2-matcher:" + specs2_version(), major_version), + jar_sha256 = scala_version_jar_shas["specs2_matcher"], + licenses = ["notice"], + server_urls = maven_servers, ) - native.maven_jar( + _scala_maven_import_external( name = "io_bazel_rules_scala_org_scalaz_scalaz_effect", - artifact = scala_mvn_artifact("org.scalaz:scalaz-effect:7.2.7"), - sha1 = "824bbb83da12224b3537c354c51eb3da72c435b5", + artifact = _scala_mvn_artifact("org.scalaz:scalaz-effect:7.2.7", + major_version), + jar_sha256 = scala_version_jar_shas["scalaz_effect"], + licenses = ["notice"], + server_urls = maven_servers, ) - native.maven_jar( + _scala_maven_import_external( name = "io_bazel_rules_scala_org_scalaz_scalaz_core", - artifact = scala_mvn_artifact("org.scalaz:scalaz-core:7.2.7"), - sha1 = "ebf85118d0bf4ce18acebf1d8475ee7deb7f19f1", + artifact = _scala_mvn_artifact("org.scalaz:scalaz-core:7.2.7", + major_version), + jar_sha256 = scala_version_jar_shas["scalaz_core"], + licenses = ["notice"], + server_urls = maven_servers, ) native.bind( diff --git a/specs2/specs2_junit.bzl b/specs2/specs2_junit.bzl index 771e86f48..07189e578 100644 --- a/specs2/specs2_junit.bzl +++ b/specs2/specs2_junit.bzl @@ -1,21 +1,47 @@ load("//specs2:specs2.bzl", "specs2_repositories", "specs2_dependencies", "specs2_version") -load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") + load("//junit:junit.bzl", "junit_repositories") -def specs2_junit_repositories(): - specs2_repositories() +load( + "//scala:scala_cross_version.bzl", + _scala_mvn_artifact = "scala_mvn_artifact", + _default_scala_version = "default_scala_version", + _extract_major_version = "extract_major_version") + +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") + +def specs2_junit_repositories( + scala_version = _default_scala_version(), + maven_servers = ["http://central.maven.org/maven2"]): + major_version = _extract_major_version(scala_version) + + specs2_repositories(scala_version, maven_servers) junit_repositories() + + scala_jar_shas = { + "2.11": { + "specs2_junit": "516e1c07340878bd2d37ee764c0c0f03985a658af2d638810d8cff7bec4a89f3", + }, + "2.12": { + "specs2_junit": "4704f2e706d5df76e7993fe0d3fb10499dd623f9cef98fe4ac7f84f66823b35f", + }, + } # Aditional dependencies for specs2 junit runner - native.maven_jar( - name = "io_bazel_rules_scala_org_specs2_specs2_junit_2_11", - artifact = scala_mvn_artifact( - "org.specs2:specs2-junit:" + specs2_version()), - sha1 = "1dc9e43970557c308ee313842d84094bc6c1c1b5", + _scala_maven_import_external( + name = "io_bazel_rules_scala_org_specs2_specs2_junit", + artifact = _scala_mvn_artifact( + "org.specs2:specs2-junit:" + specs2_version(), major_version), + jar_sha256 = scala_jar_shas[major_version]["specs2_junit"], + licenses = ["notice"], + server_urls = maven_servers, ) + native.bind( name = 'io_bazel_rules_scala/dependency/specs2/specs2_junit', - actual = '@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar') + actual = '@io_bazel_rules_scala_org_specs2_specs2_junit') def specs2_junit_dependencies(): return specs2_dependencies() + [ diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index 2084c3019..d7da9c54a 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -1,20 +1,32 @@ java_binary( name = "scalac", + srcs = [ + "@io_bazel_rules_scala//src/java/io/bazel/rulesscala/scalac:scalac_files", + ], + javacopts = [ + "-source 1.8", + "-target 1.8", + ], + main_class = "io.bazel.rulesscala.scalac.ScalaCInvoker", + visibility = ["//visibility:public"], + deps = [ + "@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", + "@io_bazel_rules_scala_scala_compiler", + "@io_bazel_rules_scala_scala_library", + "@io_bazel_rules_scala_scala_reflect", + "@scalac_rules_commons_io//jar", + ], +) + +filegroup( + name = "scalac_files", srcs = [ "CompileOptions.java", "Resource.java", "ScalaCInvoker.java", "ScalacProcessor.java", ], - main_class = "io.bazel.rulesscala.scalac.ScalaCInvoker", visibility = ["//visibility:public"], - deps = [ - "//external:io_bazel_rules_scala/dependency/commons_io/commons_io", - "//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", - "//src/java/com/google/devtools/build/lib:worker", - "//src/java/io/bazel/rulesscala/jar", - "//src/java/io/bazel/rulesscala/worker", - ], ) diff --git a/test/BUILD b/test/BUILD index d4ba533dd..bb1f58ddd 100644 --- a/test/BUILD +++ b/test/BUILD @@ -26,7 +26,7 @@ java_binary( main_class = "scalarules.test.JavaBinary", runtime_deps = [ ":OtherJavaLib", - "@io_bazel_rules_scala_scala_library//jar", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", ], deps = [ ":Exported", diff --git a/test/aspect/aspect.bzl b/test/aspect/aspect.bzl index eaa3c932f..70c5becc7 100644 --- a/test/aspect/aspect.bzl +++ b/test/aspect/aspect.bzl @@ -28,7 +28,7 @@ def _rule_impl(ctx): "scala_test": [ "//test/aspect:scala_test", "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", - "@io_bazel_rules_scala_scalatest//:io_bazel_rules_scala_scalatest", + "@io_bazel_rules_scala//scala/scalatest:scalatest", ], "scala_junit_test": [ "//test/aspect:scala_junit_test", @@ -48,7 +48,7 @@ def _rule_impl(ctx): "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", "@io_bazel_rules_scala_scala_reflect//:io_bazel_rules_scala_scala_reflect", # From specs2/specs2_junit.bzl:specs2_junit_dependencies() - "@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar:jar", + "@io_bazel_rules_scala_org_specs2_specs2_junit//:io_bazel_rules_scala_org_specs2_specs2_junit", ], } content = "" diff --git a/test_all.sh b/test_all.sh index c869cba1c..7990e3ad5 100755 --- a/test_all.sh +++ b/test_all.sh @@ -4,5 +4,6 @@ set -euo pipefail dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) "${dir}"/test_rules_scala.sh +"${dir}"/test_version.sh "${dir}"/test_reproducibility.sh "${dir}"/test_intellij_aspect.sh diff --git a/test_version.sh b/test_version.sh new file mode 100755 index 000000000..f6315d79e --- /dev/null +++ b/test_version.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +test_scala_version() { + SCALA_VERSION=$1 + + SCALA_VERSION_SHAS='' + SCALA_VERSION_SHAS+='"scala_compiler": "'$2'",' + SCALA_VERSION_SHAS+='"scala_library": "'$3'",' + SCALA_VERSION_SHAS+='"scala_reflect": "'$4'"' + + cd "${dir}"/test_version + + timestamp=$(date +%s) + + NEW_TEST_DIR="test_${SCALA_VERSION}_${timestamp}" + + cp -r version_specific_tests_dir/ $NEW_TEST_DIR + + sed \ + -e "s/\${scala_version}/$SCALA_VERSION/" \ + -e "s/\${scala_version_shas}/$SCALA_VERSION_SHAS/" \ + WORKSPACE.template >> $NEW_TEST_DIR/WORKSPACE + + cd $NEW_TEST_DIR + + bazel test //... + RESPONSE_CODE=$? + + cd .. + rm -rf $NEW_TEST_DIR + + exit $RESPONSE_CODE + +} + +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +# shellcheck source=./test_runner.sh +. "${dir}"/test_runner.sh +runner=$(get_test_runner "${1:-local}") + +$runner test_scala_version "2.11.12" \ + "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0" \ + "0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce" \ + "6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04" +$runner test_scala_version "2.12.6" \ + "3023b07cc02f2b0217b2c04f8e636b396130b3a8544a8dfad498a19c3e57a863" \ + "f81d7144f0ce1b8123335b72ba39003c4be2870767aca15dd0888ba3dab65e98" \ + "ffa70d522fc9f9deec14358aa674e6dd75c9dfa39d4668ef15bb52f002ce99fa" diff --git a/test_version/WORKSPACE.template b/test_version/WORKSPACE.template new file mode 100644 index 000000000..f01bcf151 --- /dev/null +++ b/test_version/WORKSPACE.template @@ -0,0 +1,43 @@ +workspace(name = "io_bazel_rules_scala_test") + +local_repository( + name = "io_bazel_rules_scala", + path = "../../" +) + +load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "extract_major_version") + +scala_version = "${scala_version}" + +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") + +scala_repositories((scala_version, { +${scala_version_shas} +})) + +load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge", "scrooge_scala_library") + +twitter_scrooge(scala_version) + +load("@io_bazel_rules_scala//tut_rule:tut.bzl", "tut_repositories") + +tut_repositories(scala_version) + +load("@io_bazel_rules_scala//scala_proto:scala_proto.bzl", "scala_proto_repositories") + +scala_proto_repositories(scala_version) + +load("@io_bazel_rules_scala//specs2:specs2_junit.bzl", "specs2_junit_repositories") + +specs2_junit_repositories(scala_version) + +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + +scala_register_toolchains() + +http_archive( + name = "com_google_protobuf", + sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163", + strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", + urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], +) diff --git a/test_version/version_specific_tests_dir/BUILD b/test_version/version_specific_tests_dir/BUILD new file mode 100644 index 000000000..26267b8cf --- /dev/null +++ b/test_version/version_specific_tests_dir/BUILD @@ -0,0 +1,182 @@ +package(default_testonly = 1) + +load( + "@io_bazel_rules_scala//scala:scala.bzl", + "scala_binary", + "scala_library", + "scala_test", + "scala_macro_library", + "scala_repl", + "scala_junit_test", + "scala_specs2_junit_test", +) +load( + "@io_bazel_rules_scala//scala_proto:scala_proto.bzl", + "scalapb_proto_library", +) + +# The examples below show how to combine Scala and Java rules. +# ScalaBinary is the Scala equivalent of JavaBinary. + +java_binary( + name = "JavaBinary", + srcs = ["JavaBinary.java"], + main_class = "scalarules.test.JavaBinary", + deps = [ + ":Exported", + ":HelloLib", + ":OtherLib", + ":Runtime", + ], +) + +scala_binary( + name = "ScalaBinary", + srcs = ["ScalaBinary.scala"], + main_class = "scalarules.test.ScalaBinary", + print_compile_time = True, + deps = [ + ":HelloLib", + ":MacroTest", + ], +) + +scala_library( + name = "HelloLib", + srcs = ["HelloLib.scala"], + deps = [ + "Exported", + "MacroTest", + "OtherJavaLib", + "OtherLib", + ], +) + +scala_repl( + name = "HelloLibRepl", + deps = [":HelloLib"], +) + +scala_test( + name = "HelloLibTest", + size = "small", # Not a macro, can pass test-specific attributes. + srcs = ["HelloLibTest.scala"], + deps = [ + ":HelloLib", + ], +) + +scala_library( + name = "OtherLib", + srcs = ["OtherLib.scala"], + deps = ["ExportOnly"], +) + +# Test of library without src +scala_library( + name = "ExportOnly", + exports = ["Exported"], +) + +scala_library( + name = "Exported", + srcs = ["Exported.scala"], + runtime_deps = ["Runtime"], +) + +scala_macro_library( + name = "MacroTest", + srcs = ["MacroTest.scala"], +) + +scala_library( + name = "Runtime", + srcs = ["Runtime.scala"], +) + +java_library( + name = "OtherJavaLib", + srcs = ["OtherJavaLib.java"], +) + +#Mix java scala +scala_library( + name = "MixJavaScalaLib", + srcs = glob(["src/main/scala/scalarules/test/mix_java_scala/*.scala"]) + glob([ + "src/main/scala/scalarules/test/mix_java_scala/*.java", + ]), + jvm_flags = [ + "-Xms1G", + "-Xmx4G", + ], +) + +#needed to test java sources are compiled +scala_binary( + name = "MixJavaScalaLibBinary", + srcs = ["src/main/scala/scalarules/test/MixJavaScalaLibBinary.scala"], + main_class = "scalarules.test.MixJavaScalaLibBinary", + deps = ["MixJavaScalaLib"], +) + +scala_library( + name = "JUnitCompileTimeDep", + srcs = ["src/main/scala/scalarules/test/junit/support/JUnitCompileTimeDep.scala"], +) + +scala_library( + name = "JUnitRuntimeDep", + srcs = ["src/main/scala/scalarules/test/junit/support/JUnitRuntimeDep.scala"], +) + +scala_junit_test( + name = "JunitTestWithDeps", + size = "small", + srcs = ["src/main/scala/scalarules/test/junit/JunitTests.scala"], + jvm_flags = ["-XX:HeapDumpPath=/some/custom/path"], + suffixes = ["Test"], + runtime_deps = [":JUnitRuntimeDep"], + deps = [":JUnitCompileTimeDep"], +) + +scala_specs2_junit_test( + name = "Specs2Tests", + size = "small", + srcs = ["src/main/scala/scalarules/test/junit/specs2/Specs2Tests.scala"], + print_discovered_classes = True, + suffixes = ["Test"], + deps = [":JUnitCompileTimeDep"], +) + +# Make sure scala_binary works in test environment +[sh_test( + name = "Run" + "".join([binary[idx] if binary[idx].isalnum() else "_" for idx in range(len(binary))]), + srcs = ["test_binary.sh"], + args = ["$(location %s)" % binary], + data = [binary if (":" in binary) else (":%s" % binary)], +) for binary in [ + "JavaBinary", + "MixJavaScalaLibBinary", + "ScalaBinary", +]] + +scala_library( + name = "lib_with_scala_proto_dep", + srcs = ["TestServer.scala"], + deps = ["//proto:test_proto"], +) + +scala_binary( + name = "test_scala_proto_server", + main_class = "test.proto.TestServer", + deps = [":lib_with_scala_proto_dep"], +) + +scalapb_proto_library( + name = "test_proto_scala_dep", + visibility = ["//visibility:public"], + deps = [ + ":HelloLib", + "//proto:test2", + ], +) diff --git a/test_version/version_specific_tests_dir/Exported.scala b/test_version/version_specific_tests_dir/Exported.scala new file mode 100644 index 000000000..bc0ae33da --- /dev/null +++ b/test_version/version_specific_tests_dir/Exported.scala @@ -0,0 +1,11 @@ +package scalarules.test + +object Exported { + def message: String = { + // terrible, don't do this in real code: + val msg = Class.forName("scalarules.test.Runtime") + .newInstance + .toString + "you all, everybody. " + msg + } +} diff --git a/test_version/version_specific_tests_dir/HelloLib.scala b/test_version/version_specific_tests_dir/HelloLib.scala new file mode 100644 index 000000000..a4c536fa8 --- /dev/null +++ b/test_version/version_specific_tests_dir/HelloLib.scala @@ -0,0 +1,38 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +object HelloLib { + // This is to check the linter, which will recommend changing this + // to just def dumb(x: Int) = x == 3 + def dumb(x: Int) = if (x == 3) true else false + + def printMessage(arg: String) { + MacroTest.hello(arg == "yo") + println(getOtherLibMessage(arg)) + println(getOtherJavaLibMessage(arg)) + println(Exported.message) + } + + + def getOtherLibMessage(arg: String) : String = { + arg + " " + OtherLib.getMessage() + } + + def getOtherJavaLibMessage(arg: String) : String = { + arg + " " + OtherJavaLib.getMessage() + } +} + diff --git a/test_version/version_specific_tests_dir/HelloLibTest.scala b/test_version/version_specific_tests_dir/HelloLibTest.scala new file mode 100644 index 000000000..b7f54fd97 --- /dev/null +++ b/test_version/version_specific_tests_dir/HelloLibTest.scala @@ -0,0 +1,33 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +import org.scalatest._ + +object TestUtil { + def foo: String = "bar" +} + +class ScalaSuite extends FlatSpec { + "HelloLib" should "call scala" in { + assert(HelloLib.getOtherLibMessage("hello").equals("hello you all, everybody. I am Runtime")) + } +} + +class JavaSuite extends FlatSpec { + "HelloLib" should "call java" in { + assert(HelloLib.getOtherJavaLibMessage("hello").equals("hello java!")) + } +} diff --git a/test_version/version_specific_tests_dir/JavaBinary.java b/test_version/version_specific_tests_dir/JavaBinary.java new file mode 100644 index 000000000..ea316387c --- /dev/null +++ b/test_version/version_specific_tests_dir/JavaBinary.java @@ -0,0 +1,22 @@ +// Copyright 2015 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test; + +/** Example class */ +public class JavaBinary { + public static void main(String[] args) { + HelloLib.printMessage("Hello"); + } +} diff --git a/test_version/version_specific_tests_dir/MacroTest.scala b/test_version/version_specific_tests_dir/MacroTest.scala new file mode 100644 index 000000000..39155d7fa --- /dev/null +++ b/test_version/version_specific_tests_dir/MacroTest.scala @@ -0,0 +1,17 @@ +package scalarules.test + +import language.experimental.macros + +import reflect.macros.Context + +object MacroTest { + def hello(param: Any): Unit = macro hello_impl + + def hello_impl(c: Context)(param: c.Expr[Any]): c.Expr[Unit] = { + import c.universe._ + val paramRep = show(param.tree) + val paramRepTree = Literal(Constant(paramRep)) + val paramRepExpr = c.Expr[String](paramRepTree) + reify { println(paramRepExpr.splice + " = " + param.splice) } + } +} diff --git a/test_version/version_specific_tests_dir/OtherJavaLib.java b/test_version/version_specific_tests_dir/OtherJavaLib.java new file mode 100644 index 000000000..c408d7f11 --- /dev/null +++ b/test_version/version_specific_tests_dir/OtherJavaLib.java @@ -0,0 +1,22 @@ +// Copyright 2015 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test; + +/** Example class */ +public class OtherJavaLib { + public static String getMessage() { + return "java!"; + } +} diff --git a/test_version/version_specific_tests_dir/OtherLib.scala b/test_version/version_specific_tests_dir/OtherLib.scala new file mode 100644 index 000000000..5cfa1e947 --- /dev/null +++ b/test_version/version_specific_tests_dir/OtherLib.scala @@ -0,0 +1,20 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +// It is just to show how a Scala library can depend on another Scala library. +object OtherLib { + def getMessage(): String = Exported.message +} diff --git a/test_version/version_specific_tests_dir/Runtime.scala b/test_version/version_specific_tests_dir/Runtime.scala new file mode 100644 index 000000000..96e00be42 --- /dev/null +++ b/test_version/version_specific_tests_dir/Runtime.scala @@ -0,0 +1,5 @@ +package scalarules.test + +class Runtime { + override def toString = "I am Runtime" +} diff --git a/test_version/version_specific_tests_dir/ScalaBinary.scala b/test_version/version_specific_tests_dir/ScalaBinary.scala new file mode 100644 index 000000000..673abf184 --- /dev/null +++ b/test_version/version_specific_tests_dir/ScalaBinary.scala @@ -0,0 +1,22 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +object ScalaBinary { + def main(args: Array[String]) { + println(MacroTest.hello(1 + 2)) + HelloLib.printMessage("Hello"); + } +} diff --git a/test_version/version_specific_tests_dir/TestServer.scala b/test_version/version_specific_tests_dir/TestServer.scala new file mode 100644 index 000000000..3a44df27f --- /dev/null +++ b/test_version/version_specific_tests_dir/TestServer.scala @@ -0,0 +1,98 @@ +package test.proto + +import test.{TestRequest, TestMessage} +import test2.TestResponse1 +import test3.TestResponse2 +import test_service.TestServiceGrpc +import test_service.TestServiceGrpc.TestServiceBlockingStub + +import io.grpc.{Server, ServerBuilder, StatusRuntimeException, ManagedChannelBuilder, ManagedChannel} + +import java.util.concurrent.TimeUnit +import java.util.logging.{Level, Logger} + +import scala.concurrent.{ExecutionContext, Future} + +/** + * Adapted from https://github.com/xuwei-k/grpc-scala-sample/blob/master/grpc-scala/src/main/scala/io/grpc/examples/helloworld/HelloWorldServer.scala + */ +object TestServer { + private val logger = Logger.getLogger(classOf[TestServer].getName) + + def main(args: Array[String]): Unit = { + val server = new TestServer(ExecutionContext.global) + server.start() + val client = TestClient("localhost", 50051) + val msg = args.headOption.getOrElse("ping") + client.send(msg) + client.shutdown() + server.stop() + } + + private val port = 50051 +} + +class TestServer(executionContext: ExecutionContext) { self => + lazy val server: Server = ServerBuilder + .forPort(TestServer.port) + .addService(TestServiceGrpc.bindService(new TestServiceImpl, executionContext)) + .build + + private def start(): Unit = { + server.start() + TestServer.logger.info(s"Server started, listening on ${TestServer.port}") + sys.addShutdownHook { + System.err.println("*** shutting down gRPC server since JVM is shutting down") + self.stop() + System.err.println("*** server shut down") + } + } + + private def stop(): Unit = server.shutdown() + + private def blockUntilShutdown(): Unit = server.awaitTermination() + + private class TestServiceImpl extends TestServiceGrpc.TestService { + override def testMethod1(request: TestRequest): Future[TestResponse1] = { + val response = TestResponse1().withTestMsg(TestMessage(Some("foo"))) + Future.successful(response) + } + + override def testMethod2(request: TestRequest): Future[TestResponse2] = { + val response = TestResponse2().withTestMsg(TestMessage(Some("bar"))) + Future.successful(response) + } + } +} + +object TestClient { + def apply(host: String, port: Int): TestClient = { + val channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build + val blockingStub = TestServiceGrpc.blockingStub(channel) + new TestClient(channel, blockingStub) + } +} + +class TestClient private( + private val channel: ManagedChannel, + private val blockingStub: TestServiceBlockingStub +) { + private[this] val logger = Logger.getLogger(classOf[TestClient].getName) + + def shutdown(): Unit = { + channel.shutdown.awaitTermination(5, TimeUnit.SECONDS) + } + + def send(name: String): Unit = { + logger.info("Will try to send " + name + " ...") + val request = TestRequest() + try { + val response = blockingStub.testMethod1(request) + logger.info("Response: " + response.testMsg) + } + catch { + case e: StatusRuntimeException => + logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus) + } + } +} diff --git a/test_version/version_specific_tests_dir/proto/BUILD b/test_version/version_specific_tests_dir/proto/BUILD new file mode 100644 index 000000000..5f4ce4e4d --- /dev/null +++ b/test_version/version_specific_tests_dir/proto/BUILD @@ -0,0 +1,62 @@ +load( + "@io_bazel_rules_scala//scala_proto:scala_proto.bzl", + "scalapb_proto_library", +) + +proto_library( + name = "test2", + srcs = ["test2.proto"], + visibility = ["//visibility:public"], + deps = ["//proto2:test"], +) + +proto_library( + name = "test3", + srcs = ["test3.proto"], + visibility = ["//visibility:public"], + deps = ["//proto2:test"], +) + +proto_library( + name = "test_service", + srcs = ["test_service.proto"], + visibility = ["//visibility:public"], + deps = [ + ":test2", + ":test3", + "//proto2:test", + ], +) + +scalapb_proto_library( + name = "test_proto_nogrpc", + visibility = ["//visibility:public"], + deps = [":test2"], +) + +java_proto_library( + name = "test_proto_java_lib", + deps = [ + ":test2", + "//proto2:test", + ], +) + +scalapb_proto_library( + name = "test_proto_java_conversions", + visibility = ["//visibility:public"], + with_flat_package = True, + with_java = True, + deps = [ + ":test2", + ":test_proto_java_lib", + "//proto2:test", + ], +) + +scalapb_proto_library( + name = "test_proto", + visibility = ["//visibility:public"], + with_grpc = True, + deps = [":test_service"], +) diff --git a/test_version/version_specific_tests_dir/proto/test2.proto b/test_version/version_specific_tests_dir/proto/test2.proto new file mode 100644 index 000000000..75d912ee0 --- /dev/null +++ b/test_version/version_specific_tests_dir/proto/test2.proto @@ -0,0 +1,10 @@ +syntax = "proto2"; + +import "proto2/test.proto"; +option java_package = "test.proto"; + +message TestResponse1 { + optional uint32 c = 1; + optional bool d = 2; + optional TestMessage testMsg = 3; +} diff --git a/test_version/version_specific_tests_dir/proto/test3.proto b/test_version/version_specific_tests_dir/proto/test3.proto new file mode 100644 index 000000000..80efe45f2 --- /dev/null +++ b/test_version/version_specific_tests_dir/proto/test3.proto @@ -0,0 +1,10 @@ +syntax = "proto2"; + +import "proto2/test.proto"; +option java_package = "test.proto"; + +message TestResponse2 { + optional uint32 e = 1; + optional bool f = 2; + optional TestMessage testMsg = 3; +} diff --git a/test_version/version_specific_tests_dir/proto/test_service.proto b/test_version/version_specific_tests_dir/proto/test_service.proto new file mode 100644 index 000000000..e4e3038c4 --- /dev/null +++ b/test_version/version_specific_tests_dir/proto/test_service.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +import "proto2/test.proto"; +import "proto/test2.proto"; +import "proto/test3.proto"; + +option java_package = "test.proto"; + +service TestService { + rpc TestMethod1 (TestRequest) returns (TestResponse1) {} + rpc TestMethod2 (TestRequest) returns (TestResponse2) {} +} diff --git a/test_version/version_specific_tests_dir/proto2/BUILD b/test_version/version_specific_tests_dir/proto2/BUILD new file mode 100644 index 000000000..96e963557 --- /dev/null +++ b/test_version/version_specific_tests_dir/proto2/BUILD @@ -0,0 +1,5 @@ +proto_library( + name = "test", + srcs = ["test.proto"], + visibility = ["//visibility:public"], +) diff --git a/test_version/version_specific_tests_dir/proto2/test.proto b/test_version/version_specific_tests_dir/proto2/test.proto new file mode 100644 index 000000000..6a51d45b2 --- /dev/null +++ b/test_version/version_specific_tests_dir/proto2/test.proto @@ -0,0 +1,12 @@ +syntax = "proto2"; + +option java_package = "test.proto"; + +message TestRequest { + optional uint32 a = 1; + optional bool b = 2; +} + +message TestMessage { + optional string foo = 1; +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/MixJavaScalaLibBinary.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/MixJavaScalaLibBinary.scala new file mode 100644 index 000000000..56cbee2d9 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/MixJavaScalaLibBinary.scala @@ -0,0 +1,22 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +object MixJavaScalaLibBinary { + def main(args: Array[String]) { + val bar = new Bar() + println("created an instance of a mixed java scala code from a library") + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/ScalaLibBinary.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/ScalaLibBinary.scala new file mode 100644 index 000000000..549dc5366 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/ScalaLibBinary.scala @@ -0,0 +1,23 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scalarules.test + +object ScalaLibBinary { + def main(args:Array[String]) { + ScalaLibResources.getGreetings foreach println + ScalaLibResources.getFarewells foreach println + ScalaLibResources.getData foreach println + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/JunitTests.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/JunitTests.scala new file mode 100644 index 000000000..7ef9fa0ef --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/JunitTests.scala @@ -0,0 +1,30 @@ +package scalarules.test.junit + +import org.junit.Test +import org.hamcrest.CoreMatchers._ +import org.hamcrest.MatcherAssert._ +import scalarules.test.junit.support.JUnitCompileTimeDep +import java.lang.management.ManagementFactory +import java.lang.management.RuntimeMXBean + +class JunitWithDepsTest { + + @Test + def hasCompileTimeDependencies: Unit = { + println(JUnitCompileTimeDep.hello) + } + + @Test + def hasRuntimeDependencies: Unit = { + Class.forName("scalarules.test.junit.support.JUnitRuntimeDep") + } + + @Test + def supportsCustomJVMArgs: Unit = { + assertThat(ManagementFactory.getRuntimeMXBean().getInputArguments(), + hasItem("-XX:HeapDumpPath=/some/custom/path")) + } + +} + +class ClassCoveringRegressionFromTakingAllClassesInArchive diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/specs2/Specs2Tests.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/specs2/Specs2Tests.scala new file mode 100644 index 000000000..d7b078f05 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/specs2/Specs2Tests.scala @@ -0,0 +1,52 @@ +package scalarules.test.junit.specs2 + +import org.specs2.mutable.SpecWithJUnit +import scalarules.test.junit.support.JUnitCompileTimeDep + +class JunitSpecs2Test extends SpecWithJUnit { + + "specs2 tests" should { + "run smoothly in bazel" in { + println(JUnitCompileTimeDep.hello) + success + } + + "not run smoothly in bazel" in { + success + } + } +} + +class JunitSpecs2AnotherTest extends SpecWithJUnit { + + "other specs2 tests" should { + "run from another test" >> { + println(JUnitCompileTimeDep.hello) + success + } + + "run from another test 2" >> { + success + } + } + + "unrelated test" should { + "not run" in { + success + } + } +} + +class JunitSpec2RegexTest extends SpecWithJUnit { + + "tests with unsafe characters" should { + "2 + 2 != 5" in { + 2 + 2 must be_!=(5) + } + + "work escaped (with regex)" in { + success + } + } +} + diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitCompileTimeDep.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitCompileTimeDep.scala new file mode 100644 index 000000000..6517163f0 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitCompileTimeDep.scala @@ -0,0 +1,4 @@ +package scalarules.test.junit.support +object JUnitCompileTimeDep { + val hello = "hello" +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitRuntimeDep.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitRuntimeDep.scala new file mode 100644 index 000000000..07746aaed --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/junit/support/JUnitRuntimeDep.scala @@ -0,0 +1,2 @@ +package scalarules.test.junit.support +class JUnitRuntimeDep diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Bar.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Bar.scala new file mode 100644 index 000000000..5629668d9 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Bar.scala @@ -0,0 +1,3 @@ +package scalarules.test +class Foo +class Bar extends Baz diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Baz.java b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Baz.java new file mode 100644 index 000000000..750484cd3 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/Baz.java @@ -0,0 +1,3 @@ +package scalarules.test; + +public class Baz extends Foo {} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/FooBar.java b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/FooBar.java new file mode 100644 index 000000000..90b4f1ac1 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/mix_java_scala/FooBar.java @@ -0,0 +1,3 @@ +package scalarules.test; + +public class FooBar extends Foo {} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BUILD new file mode 100644 index 000000000..22a773d40 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BUILD @@ -0,0 +1,229 @@ +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary", "scala_library") +load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +scrooge_scala_library( + name = "scrooge1", + visibility = ["//visibility:public"], + exports = [ + ":scrooge2_a", + ":scrooge2_b", + ":scrooge3", + ], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/thrift"], +) + +scrooge_scala_library( + name = "scrooge2_a", + visibility = ["//visibility:public"], + exports = [ + ":scrooge3", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a", + ], +) + +scrooge_scala_library( + name = "scrooge2_b", + visibility = ["//visibility:public"], + exports = [ + ":scrooge3", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], +) + +scrooge_scala_library( + name = "scrooge2_b_imp", + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_b_imp", + ], +) + +scrooge_scala_library( + name = "scrooge3", + visibility = ["//visibility:public"], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3"], +) + +scrooge_scala_library( + name = "scrooge2", + visibility = ["//visibility:public"], + exports = [ + ":scrooge3", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a", + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], +) + +scrooge_scala_library( + name = "scrooge4", + visibility = ["//visibility:public"], + exports = [ + ":scrooge2", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4", + ], +) + +scrooge_scala_library( + name = "scrooge4a", + visibility = ["//visibility:public"], + exports = [ + ":scrooge4", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4:thrift4a", + ], +) + +scrooge_scala_library( + name = "scroogebarejar1", + visibility = ["//visibility:public"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", + ], +) + +scrooge_scala_library( + name = "scroogebarejar2", + visibility = ["//visibility:public"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", + ], +) + +scrooge_scala_library( + name = "bare_thrift_scrooge", + visibility = ["//visibility:public"], + exports = [ + ":scroogebarejar1", + ":scroogebarejar2", + ], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts", + ], +) + +scala_library( + name = "justscrooge1", + srcs = ["JustScrooge1.scala"], + exports = [":scrooge1"], + deps = [":scrooge1"], +) + +scala_library( + name = "justscrooge2a", + srcs = ["JustScrooge2a.scala"], + deps = [":scrooge2_a"], +) + +scala_library( + name = "justscrooge2b", + srcs = ["JustScrooge2b.scala"], + deps = [":scrooge2_b"], +) + +scala_library( + name = "justscrooge3", + srcs = ["JustScrooge3.scala"], + exports = [":scrooge3"], + deps = [":scrooge3"], +) + +scala_library( + name = "justscrooge3_import", + srcs = ["JustScrooge3.scala"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3:thrift3_import", + ], +) + +scala_library( + name = "scrooge2_both", + srcs = ["Scrooge2.scala"], + deps = [":scrooge2"], +) + +scala_library( + name = "mixed", + srcs = ["Mixed.scala"], + deps = [ + ":justscrooge1", + ":justscrooge2a", + ":justscrooge2b", + ":justscrooge3", + ], +) + +scala_library( + name = "twodeep", + srcs = ["Twodeep.scala"], + deps = [":justscrooge3"], +) + +scala_binary( + name = "twodeep_binary", + main_class = "scalarules.test.twitter_scrooge.Twodeep", + deps = [":twodeep"], +) + +scala_binary( + name = "justscrooge2b_binary", + main_class = "scalarules.test.twitter_scrooge.JustScrooge2b", + deps = [":justscrooge2b"], +) + +scala_library( + name = "allscrooges", + exports = [ + ":scrooge1", + ":scrooge2_a", + ":scrooge2_b", + ":scrooge3", + ], +) + +scala_binary( + name = "justscrooges", + srcs = ["JustScrooge1.scala"], + main_class = "scalarules.test.twitter_scrooge.JustScrooge1", + deps = [":allscrooges"], +) + +scala_library( + name = "barethriftslib", + srcs = ["BareThrifts.scala"], + deps = [":bare_thrift_scrooge"], +) + +scala_binary( + name = "barethrifts", + main_class = "scalarules.test.twitter_scrooge.BareThrifts", + deps = [":barethriftslib"], +) + +sh_test( + name = "libthrift2_a_not_on_classpath", + srcs = ["grep.sh"], + args = [ + "libthrift2_a", + "$(location :justscrooges)", + ], + data = [":justscrooges"], +) + +sh_test( + name = "java_jar_not_on_classpath", + srcs = ["grep.sh"], + args = [ + "_java.jar", + "$(location :justscrooges)", + ], + data = [":justscrooges"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BareThrifts.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BareThrifts.scala new file mode 100644 index 000000000..b558becb5 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/BareThrifts.scala @@ -0,0 +1,13 @@ +package scalarules.test.twitter_scrooge + +import com.foo.bar.baz.Foo +import com.foo.bar.baz.Bar +import com.foo.bar.baz.Baz + +object BareThrifts { + val classes = Seq(classOf[Foo], classOf[Bar], classOf[Baz]) + + def main(args: Array[String]) { + print(s"classes ${classes.mkString(",")}") + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge1.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge1.scala new file mode 100644 index 000000000..7cd16720e --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge1.scala @@ -0,0 +1,14 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.Struct1 +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2A +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2B +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object JustScrooge1 { + val classes = Seq(classOf[Struct1], classOf[Struct2A], classOf[Struct2B], classOf[Struct3]) + + def main(args: Array[String]) { + print(s"classes ${classes.mkString(",")}") + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2a.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2a.scala new file mode 100644 index 000000000..741e21455 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2a.scala @@ -0,0 +1,8 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2A +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object JustScrooge2a { + val classes = Seq(classOf[Struct2A], classOf[Struct3]) +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2b.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2b.scala new file mode 100644 index 000000000..65d438e52 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge2b.scala @@ -0,0 +1,12 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2B +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object JustScrooge2b { + val classes = Seq(classOf[Struct2B], classOf[Struct3]) + + def main(args: Array[String]) { + classes foreach println + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge3.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge3.scala new file mode 100644 index 000000000..c6e778964 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/JustScrooge3.scala @@ -0,0 +1,7 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object JustScrooge3 { + val classes = Seq(classOf[Struct3]) +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Mixed.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Mixed.scala new file mode 100644 index 000000000..60fb9de00 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Mixed.scala @@ -0,0 +1,20 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.Struct1 +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2A +import scalarules.test.twitter_scrooge.thrift.thrift2.Struct2B +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object Mixed { + val classes = + Seq( + classOf[Struct1], + classOf[Struct2A], + classOf[Struct2B], + classOf[Struct3], + JustScrooge1.getClass, + JustScrooge2a.getClass, + JustScrooge2b.getClass, + JustScrooge3.getClass + ) +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Scrooge2.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Scrooge2.scala new file mode 100644 index 000000000..653844fac --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Scrooge2.scala @@ -0,0 +1,8 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.thrift2.{Struct2A, Struct2B} +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object Scrooge2 { + val classes = Seq(classOf[Struct2A], classOf[Struct2B], classOf[Struct3]) +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Twodeep.scala b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Twodeep.scala new file mode 100644 index 000000000..45972e013 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/Twodeep.scala @@ -0,0 +1,15 @@ +package scalarules.test.twitter_scrooge + +import scalarules.test.twitter_scrooge.thrift.thrift2.thrift3.Struct3 + +object Twodeep { + val classes = + Seq( + classOf[Struct3], + JustScrooge3.getClass + ) + + def main(args: Array[String]) { + classes foreach println + } +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/grep.sh b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/grep.sh new file mode 100755 index 000000000..880b6e840 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/grep.sh @@ -0,0 +1,13 @@ +#!/bin/sh + + +# this is used by a sh_test to test that a string is NOT +# found in a file. This is used for instance to check if +# stray jars are not making it onto the classpath + +if grep -q $1 $2 ; then + echo "ERROR: found $1" + exit 1 +else + exit 0 +fi diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/A.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/A.thrift new file mode 100644 index 000000000..90da77b14 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/A.thrift @@ -0,0 +1,5 @@ +namespace java scalarules.test.twitter_scrooge.prefix_test.a.b.c.d + +struct StructA { + 1: string field +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD new file mode 100644 index 000000000..928a7c8dc --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD @@ -0,0 +1,17 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") +load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") + +thrift_library( + name = "a_thrift", + srcs = ["A.thrift"], + absolute_prefix = "prefix_test/a", + visibility = ["//visibility:public"], +) + +scrooge_scala_library( + name = "d", + visibility = ["//visibility:public"], + deps = [ + ":a_thrift", + ], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/B.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/B.thrift new file mode 100644 index 000000000..38532bf9a --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/B.thrift @@ -0,0 +1,7 @@ +namespace java scalarules.test.twitter_scrooge.prefix_test.a.b.c.d + +include "b/c/d/A.thrift" + +struct StructB { + 1: A.StructA field +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD new file mode 100644 index 000000000..731f3be99 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD @@ -0,0 +1,24 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") +load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") + +thrift_library( + name = "b_thrift", + srcs = ["B.thrift"], + absolute_prefixes = [ + "prefix_test/a", + "prefix_test/e/f", + ], + visibility = ["//visibility:public"], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d:a_thrift"], +) + +scrooge_scala_library( + name = "d", + visibility = ["//visibility:public"], + exports = [ + "//src/main/scala/scalarules/test/twitter_scrooge/prefix_test/a/b/c/d", + ], + deps = [ + ":b_thrift", + ], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/BUILD new file mode 100644 index 000000000..d478437e9 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/BUILD @@ -0,0 +1,20 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +thrift_library( + name = "thrift", + srcs = ["Thrift1.thrift"], + visibility = ["//visibility:public"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a", + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], +) + +thrift_library( + name = "thrift_many", + srcs = [ + "ThriftMany1.thrift", + "ThriftMany2.thrift", + ], + visibility = ["//visibility:public"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/Thrift1.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/Thrift1.thrift new file mode 100644 index 000000000..5b070a245 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/Thrift1.thrift @@ -0,0 +1,11 @@ +namespace java scalarules.test.twitter_scrooge.thrift + +include "thrift2/Thrift2_A.thrift" +include "thrift2/Thrift2_B.thrift" +include "thrift2/thrift3/Thrift3.thrift" + +struct Struct1 { + 1: Thrift2_A.Struct2A msg_a + 2: Thrift2_B.Struct2B msg_b + 3: Thrift3.Struct3 msg +} \ No newline at end of file diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany1.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany1.thrift new file mode 100644 index 000000000..5bece4e93 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany1.thrift @@ -0,0 +1,3 @@ +struct Many1 { + 1: i32 one +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany2.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany2.thrift new file mode 100644 index 000000000..67ea53fa9 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/ThriftMany2.thrift @@ -0,0 +1,3 @@ +struct Many2 { + 1: i16 two +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD new file mode 100644 index 000000000..199526a6a --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD @@ -0,0 +1,19 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +java_import( + name = "barejar", + jars = ["bare-thrift.jar"], + visibility = ["//visibility:public"], +) + +thrift_library( + name = "bare_jar_thrifts", + external_jars = [ + ":barejar", + ], + visibility = ["//visibility:public"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", + ], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BareJar.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BareJar.thrift new file mode 100644 index 000000000..897c1f431 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/BareJar.thrift @@ -0,0 +1,11 @@ +namespace java com.foo.bar.baz + +include "Foo.thrift" +include "Bar.thrift" +include "Baz.thrift" + +struct BareJar { + 1: Foo foo + 2: Bar bar + 3: Baz baz +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare-thrift.jar b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare-thrift.jar new file mode 100644 index 000000000..e95a5bfa5 Binary files /dev/null and b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare-thrift.jar differ diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD new file mode 100644 index 000000000..3bd75bd7b --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD @@ -0,0 +1,9 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +thrift_library( + name = "bare_jar_1", + external_jars = [ + "bare-thrift-1.jar", + ], + visibility = ["//visibility:public"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/bare-thrift-1.jar b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/bare-thrift-1.jar new file mode 100644 index 000000000..81ff04bc3 Binary files /dev/null and b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/bare-thrift-1.jar differ diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD new file mode 100644 index 000000000..093f3d457 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD @@ -0,0 +1,9 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +thrift_library( + name = "bare_jar_2", + external_jars = [ + "bare-thrift-2.jar", + ], + visibility = ["//visibility:public"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/bare-thrift-2.jar b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/bare-thrift-2.jar new file mode 100644 index 000000000..14c9ca469 Binary files /dev/null and b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/bare-thrift-2.jar differ diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/BUILD new file mode 100644 index 000000000..a09690a58 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/BUILD @@ -0,0 +1,22 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +thrift_library( + name = "thrift2_a", + srcs = ["Thrift2_A.thrift"], + visibility = ["//visibility:public"], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3"], +) + +thrift_library( + name = "thrift2_b", + srcs = ["Thrift2_B.thrift"], + visibility = ["//visibility:public"], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3"], +) + +thrift_library( + name = "thrift2_b_imp", + srcs = ["Thrift2_B.thrift"], + visibility = ["//visibility:public"], + deps = ["//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3:thrift3_import"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_A.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_A.thrift new file mode 100644 index 000000000..574ca556c --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_A.thrift @@ -0,0 +1,7 @@ +namespace java scalarules.test.twitter_scrooge.thrift.thrift2 + +include "thrift3/Thrift3.thrift" + +struct Struct2A { + 1: Thrift3.Struct3 msg +} \ No newline at end of file diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_B.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_B.thrift new file mode 100644 index 000000000..42839f3e0 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/Thrift2_B.thrift @@ -0,0 +1,9 @@ +namespace java scalarules.test.twitter_scrooge.thrift.thrift2 + +// TODO We should be able to do a full import based on the full package +// which will make refactoring targets much less fragile +include "thrift3/Thrift3.thrift" + +struct Struct2B { + 1: Thrift3.Struct3 msg +} \ No newline at end of file diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD new file mode 100644 index 000000000..1e6b3c5ae --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD @@ -0,0 +1,15 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") +load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_import") + +thrift_library( + name = "thrift3", + srcs = ["Thrift3.thrift"], + visibility = ["//visibility:public"], +) + +scrooge_scala_import( + name = "thrift3_import", + scala_jars = ["thrift3_scrooge.jar"], + thrift_jars = ["libthrift3.jar"], + visibility = ["//visibility:public"], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/Thrift3.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/Thrift3.thrift new file mode 100644 index 000000000..e3d6286ae --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/Thrift3.thrift @@ -0,0 +1,9 @@ +namespace java scalarules.test.twitter_scrooge.thrift.thrift2.thrift3 + +struct Struct3 { + 1: string msg +} + +struct Struct3Extra { + 1: string msg +} \ No newline at end of file diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/thrift3_scrooge.jar b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/thrift3_scrooge.jar new file mode 100755 index 000000000..0e0f1c989 Binary files /dev/null and b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift3/thrift3_scrooge.jar differ diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD new file mode 100644 index 000000000..b3a533ba6 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD @@ -0,0 +1,20 @@ +load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library") + +thrift_library( + name = "thrift4", + srcs = ["Thrift4.thrift"], + visibility = ["//visibility:public"], + deps = [ + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a", + ], +) + +thrift_library( + name = "thrift4a", + srcs = ["Thrift4a.thrift"], + visibility = ["//visibility:public"], + deps = [ + ":thrift4", + "//src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2:thrift2_a", + ], +) diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4.thrift new file mode 100644 index 000000000..5f6baad02 --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4.thrift @@ -0,0 +1,7 @@ +namespace java scalarules.test.twitter_scrooge.thrift.thrift2.thrift3 + +include "../Thrift2_A.thrift" + +struct Struct4 { + 1: Thrift2_A.Struct2A nested +} diff --git a/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4a.thrift b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4a.thrift new file mode 100644 index 000000000..b592f227c --- /dev/null +++ b/test_version/version_specific_tests_dir/src/main/scala/scalarules/test/twitter_scrooge/thrift/thrift2/thrift4/Thrift4a.thrift @@ -0,0 +1,5 @@ +include "./Thrift4.thrift" + +struct Struct4a { + 1: Thrift4.Struct4 nest; +} diff --git a/test_version/version_specific_tests_dir/test_binary.sh b/test_version/version_specific_tests_dir/test_binary.sh new file mode 100755 index 000000000..2590251d0 --- /dev/null +++ b/test_version/version_specific_tests_dir/test_binary.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Executing: " $@ +$@ diff --git a/test_version/version_specific_tests_dir/tut/BUILD b/test_version/version_specific_tests_dir/tut/BUILD new file mode 100644 index 000000000..acacc8084 --- /dev/null +++ b/test_version/version_specific_tests_dir/tut/BUILD @@ -0,0 +1,13 @@ +load("@io_bazel_rules_scala//tut_rule:tut.bzl", "scala_tut_doc") +load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library") + +scala_library( + name = "test_dep", + srcs = ["TestDep.scala"], +) + +scala_tut_doc( + name = "some_example", + src = "SomeExample.md", + deps = [":test_dep"], +) diff --git a/test_version/version_specific_tests_dir/tut/SomeExample.md b/test_version/version_specific_tests_dir/tut/SomeExample.md new file mode 100644 index 000000000..b38270ccc --- /dev/null +++ b/test_version/version_specific_tests_dir/tut/SomeExample.md @@ -0,0 +1,12 @@ +# This is markdown + +``` +With some stuff +``` + +```tut +List(1, 2, 3).sum + +import foo.Bar +Bar.values +``` diff --git a/test_version/version_specific_tests_dir/tut/TestDep.scala b/test_version/version_specific_tests_dir/tut/TestDep.scala new file mode 100644 index 000000000..15578b96e --- /dev/null +++ b/test_version/version_specific_tests_dir/tut/TestDep.scala @@ -0,0 +1,5 @@ +package foo + +object Bar { + def values: List[Int] = List(2, 3, 5, 7) +} diff --git a/third_party/plugin/src/main/BUILD b/third_party/plugin/src/main/BUILD index c9b712921..40fb822a6 100644 --- a/third_party/plugin/src/main/BUILD +++ b/third_party/plugin/src/main/BUILD @@ -1,6 +1,6 @@ licenses(["notice"]) # 3-clause BSD -load("//scala:scala.bzl", "scala_library", "scala_library_for_plugin_bootstrapping") +load("//scala:scala.bzl", "scala_library_for_plugin_bootstrapping") scala_library_for_plugin_bootstrapping( name = "dependency_analyzer", @@ -11,5 +11,6 @@ scala_library_for_plugin_bootstrapping( visibility = ["//visibility:public"], deps = [ "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], ) diff --git a/third_party/plugin/src/test/BUILD b/third_party/plugin/src/test/BUILD index 68dd168ba..8629d6ab4 100644 --- a/third_party/plugin/src/test/BUILD +++ b/third_party/plugin/src/test/BUILD @@ -19,6 +19,7 @@ scala_junit_test( 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/plugin/src/main:dependency_analyzer", "@com_google_guava_guava_21_0_with_file//jar", "@org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file", diff --git a/tut_rule/tut.bzl b/tut_rule/tut.bzl index 92252021d..9a17ea78e 100644 --- a/tut_rule/tut.bzl +++ b/tut_rule/tut.bzl @@ -1,21 +1,39 @@ load("//scala:scala.bzl", "scala_binary") -load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") +load( + "//scala:scala_cross_version.bzl", + "scala_mvn_artifact", + _extract_major_version = "extract_major_version", + _default_scala_version = "default_scala_version") -def tut_repositories(): - native.maven_server( - name = "tut_repositories_maven_server", - url = "https://dl.bintray.com/tpolecat/maven/", - ) +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") + +def tut_repositories(scala_version = _default_scala_version(), + server_urls = ["https://dl.bintray.com/tpolecat/maven/"]): + major_version = _extract_major_version(scala_version) - native.maven_jar( + scala_jar_shas = { + "2.11": { + "tut_core": "edab4e9963dd7dbab1a8bfff2ef087eb6b6882804dfb3a2641895c958a62ba89", + }, + "2.12": { + "tut_core": "767735128b6d5694d59ccb3bd1f5544a05d83146577121bcf7b6a32327adf281", + }, + } + + _scala_maven_import_external( name = "io_bazel_rules_scala_org_tpolecat_tut_core", - artifact = scala_mvn_artifact("org.tpolecat:tut-core:0.4.8"), - sha1 = "fc723eb822494580cc05d6b3b3a6039d2280a5a0", - server = "tut_repositories_maven_server", + artifact = scala_mvn_artifact("org.tpolecat:tut-core:0.4.8", + major_version), + jar_sha256 = scala_jar_shas[major_version]["tut_core"], + licenses = ["notice"], + server_urls = server_urls, ) + native.bind( name = 'io_bazel_rules_scala/dependency/tut/tut_core', - actual = '@io_bazel_rules_scala_org_tpolecat_tut_core//jar') + actual = '@io_bazel_rules_scala_org_tpolecat_tut_core') def scala_tut_doc(**kw): name = kw["name"] @@ -26,7 +44,8 @@ def scala_tut_doc(**kw): name = tool, main_class = "io.bazel.rules_scala.tut_support.TutCompiler", deps = deps + [ - "@io_bazel_rules_scala//src/scala/io/bazel/rules_scala/tut_support:tut_compiler_lib" + "@io_bazel_rules_scala//src/scala/io/bazel/rules_scala/tut_support:tut_compiler_lib", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", ], ) native.genrule( diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index e582be7c9..0adf7c6db 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -1,12 +1,12 @@ load( - "//scala:scala.bzl", - "scala_library", -) + "//scala:scala_cross_version.bzl", + _scala_mvn_artifact = "scala_mvn_artifact", + _default_scala_version = "default_scala_version", + _extract_major_version = "extract_major_version") load( - "//scala:scala_cross_version.bzl", - "scala_mvn_artifact", -) + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") load("//scala/private:common.bzl", "write_manifest_file", "collect_srcjars", "collect_jars") @@ -18,9 +18,16 @@ load("@io_bazel_rules_scala//thrift:thrift_info.bzl", "ThriftInfo") load("@io_bazel_rules_scala//thrift:thrift.bzl", "merge_thrift_infos", "empty_thrift_info") +load( + "@io_bazel_rules_scala//scala:providers.bzl", + _ScalacProvider = "ScalacProvider") + _jar_extension = ".jar" -def twitter_scrooge(): +def twitter_scrooge(scala_version = _default_scala_version(), + maven_servers = ["http://central.maven.org/maven2"]): + major_version = _extract_major_version(scala_version) + native.maven_server( name = "twitter_scrooge_maven_server", url = "http://mirror.bazel.build/repo1.maven.org/maven2/", @@ -36,46 +43,71 @@ def twitter_scrooge(): name = 'io_bazel_rules_scala/dependency/thrift/libthrift', actual = '@libthrift//jar') - native.maven_jar( - name = "scrooge_core", - artifact = scala_mvn_artifact("com.twitter:scrooge-core:4.6.0"), - sha1 = "84b86c2e082aba6e0c780b3c76281703b891a2c8", - server = "twitter_scrooge_maven_server", + scala_jar_shas = { + "2.11": { + "util_logging": "73ddd61cedabd4dab82b30e6c52c1be6c692b063b8ba310d716ead9e3b4e9267", + "scrooge_core": "00351f73b555d61cfe7320ef3b1367a9641e694cfb8dfa8a733cfcf49df872e8", + "scrooge_generator": "0f0027e815e67985895a6f3caa137f02366ceeea4966498f34fb82cabb11dee6", + "util_core": "5336da4846dfc3db8ffe5ae076be1021828cfee35aa17bda9af461e203cf265c" + }, + "2.12": { + "util_logging": "c0cba01705e9321b3444adcd4a9ce27c2acefd27e14c13b5aec2c318ce1b4fdf", + "scrooge_core": "02a6d7cf9fe8d872dfabd20298e4315d677748708e153d8b464fd5abac9a7430", + "scrooge_generator": "e7d5da1e3f0e494d3c81a26f44f3e3dc92d7efd757133de8c71758646fd5a833", + "util_core": "65bb92e70f95cbbfc640e54a5823a16154eac1a2631dc0211347e085aaa6ed0b" + }, + } + + scala_version_jar_shas = scala_jar_shas[major_version] + + _scala_maven_import_external( + name = "io_bazel_rules_scala_scrooge_core", + artifact = _scala_mvn_artifact("com.twitter:scrooge-core:18.6.0", + major_version), + jar_sha256 = scala_version_jar_shas["scrooge_core"], + licenses = ["notice"], + server_urls = maven_servers, ) native.bind( name = 'io_bazel_rules_scala/dependency/thrift/scrooge_core', - actual = '@scrooge_core//jar') + actual = '@io_bazel_rules_scala_scrooge_core') #scrooge-generator related dependencies - native.maven_jar( - name = "scrooge_generator", - artifact = scala_mvn_artifact("com.twitter:scrooge-generator:4.6.0"), - sha1 = "cacf72eedeb5309ca02b2d8325c587198ecaac82", - server = "twitter_scrooge_maven_server", + _scala_maven_import_external( + name = "io_bazel_rules_scala_scrooge_generator", + artifact = _scala_mvn_artifact("com.twitter:scrooge-generator:18.6.0", + major_version), + jar_sha256 = scala_version_jar_shas["scrooge_generator"], + licenses = ["notice"], + server_urls = maven_servers, ) native.bind( name = 'io_bazel_rules_scala/dependency/thrift/scrooge_generator', - actual = '@scrooge_generator//jar') - - native.maven_jar( - name = "util_core", - artifact = scala_mvn_artifact("com.twitter:util-core:6.33.0"), - sha1 = "bb49fa66a3ca9b7db8cd764d0b26ce498bbccc83", - server = "twitter_scrooge_maven_server", + actual = '@io_bazel_rules_scala_scrooge_generator') + + _scala_maven_import_external( + name = "io_bazel_rules_scala_util_core", + artifact = _scala_mvn_artifact("com.twitter:util-core:18.6.0", + major_version), + jar_sha256 = scala_version_jar_shas["util_core"], + licenses = ["notice"], + server_urls = maven_servers, ) native.bind( name = 'io_bazel_rules_scala/dependency/thrift/util_core', - actual = '@util_core//jar') - - native.maven_jar( - name = "util_logging", - artifact = scala_mvn_artifact("com.twitter:util-logging:6.33.0"), - sha1 = "3d28e46f8ee3b7ad1b98a51b98089fc01c9755dd", - server = "twitter_scrooge_maven_server", + actual = '@io_bazel_rules_scala_util_core') + + _scala_maven_import_external( + name = "io_bazel_rules_scala_util_logging", + artifact = _scala_mvn_artifact("com.twitter:util-logging:18.6.0", + major_version), + jar_sha256 = scala_version_jar_shas["util_logging"], + licenses = ["notice"], + server_urls = maven_servers, ) native.bind( name = 'io_bazel_rules_scala/dependency/thrift/util_logging', - actual = '@util_logging//jar') + actual = '@io_bazel_rules_scala_util_logging') def _colon_paths(data): return ':'.join([f.path for f in sorted(data)]) @@ -183,7 +215,8 @@ def _compile_scala(ctx, label, output, scrooge_jar, deps_java_info, in_scalacopts = [], print_compile_time = False, expect_java_output = False, - scalac_jvm_flags = []) + scalac_jvm_flags = [], + scalac_provider = ctx.attr._scalac[_ScalacProvider]) return java_common.create_provider( use_ijar = False, @@ -269,10 +302,8 @@ scrooge_aspect = aspect( default = Label("//src/scala/scripts:generator"), allow_files = True), "_scalac": attr.label( - executable = True, - cfg = "host", - default = Label("//src/java/io/bazel/rulesscala/scalac"), - allow_files = True), + default = Label("@io_bazel_rules_scala//scala:scala_default"), + providers = [_ScalacProvider]), "_implicit_compile_deps": attr.label_list( providers = [JavaInfo], default = [ @@ -285,6 +316,9 @@ scrooge_aspect = aspect( Label( "//external:io_bazel_rules_scala/dependency/thrift/scrooge_core" ), + Label( + "//external:io_bazel_rules_scala/dependency/thrift/util_core" + ), ]), }, required_aspect_providers = [[ThriftInfo],