From 76d4ab9f855f78113ee5990a84b0ad55d2417e4a Mon Sep 17 00:00:00 2001 From: Johan Jern Date: Fri, 29 Jun 2018 14:38:52 -0700 Subject: [PATCH] Add scala-xml and scala-parser-combinators jars individually (#549) * Add scala-xml and scala-parser-combinators individually - Update aspect test with new labels * Download scalalib, compiler and reflect as jars * Download jars using http_file, import using scala_import * Use * Run linter * Remove https from maven url * Correct artifacts * Add DefaultInfo provider to outputs of scala_import * maven_servers as parameter * Prefix scala_repositories labels with io_bazel_rules_scala --- scala/scala.bzl | 120 ++++++++++++++++++++++------------------- test/BUILD | 2 +- test/aspect/aspect.bzl | 18 +++---- 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/scala/scala.bzl b/scala/scala.bzl index 5753d1a55..920cb6d54 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -10,10 +10,18 @@ load( load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +load( + "@io_bazel_rules_scala//scala:scala_maven_import_external.bzl", + _scala_maven_import_external = "scala_maven_import_external") + load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", _specs2_junit_dependencies = "specs2_junit_dependencies") +load( + "@io_bazel_rules_scala//scala:scala_import.bzl", + _scala_import = "scala_import") + _launcher_template = { "_java_stub_template": attr.label( default = Label("@java_stub_template//file")), @@ -249,56 +257,56 @@ scala_repl = rule( toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) -_SCALA_BUILD_FILE = """ -# scala.BUILD -java_import( - name = "scala-xml", - jars = ["lib/scala-xml_2.11-1.0.5.jar"], - visibility = ["//visibility:public"], -) - -java_import( - name = "scala-parser-combinators", - jars = ["lib/scala-parser-combinators_2.11-1.0.4.jar"], - visibility = ["//visibility:public"], -) - -java_import( - name = "scala-library", - jars = ["lib/scala-library.jar"], - visibility = ["//visibility:public"], -) - -java_import( - name = "scala-compiler", - jars = ["lib/scala-compiler.jar"], - visibility = ["//visibility:public"], -) - -java_import( - name = "scala-reflect", - jars = ["lib/scala-reflect.jar"], - visibility = ["//visibility:public"], -) -""" +def scala_repositories(maven_servers = ["http://central.maven.org/maven2"]): + _scala_maven_import_external( + name = "io_bazel_rules_scala_scala_library", + artifact = "org.scala-lang:scala-library:2.11.12", + jar_sha256 = + "0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce", + licenses = ["notice"], + server_urls = maven_servers, + ) + _scala_maven_import_external( + name = "io_bazel_rules_scala_scala_compiler", + artifact = "org.scala-lang:scala-compiler:2.11.12", + jar_sha256 = + "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0", + licenses = ["notice"], + server_urls = maven_servers, + ) + _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", + licenses = ["notice"], + server_urls = maven_servers, + ) -def scala_repositories(): - native.new_http_archive( - name = "scala", - strip_prefix = "scala-2.11.12", - sha256 = - "b11d7d33699ca4f60bc3b2b6858fd953e3de2b8522c943f4cda4b674316196a8", - url = "http://downloads.lightbend.com/scala/2.11.12/scala-2.11.12.tgz", - build_file_content = _SCALA_BUILD_FILE, + _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", + licenses = ["notice"], + server_urls = maven_servers, ) - # scalatest has macros, note http_jar is invoking ijar - native.http_jar( - name = "scalatest", - url = - "https://mirror.bazel.build/oss.sonatype.org/content/groups/public/org/scalatest/scalatest_2.11/2.2.6/scalatest_2.11-2.2.6.jar", - sha256 = - "f198967436a5e7a69cfd182902adcfbcb9f2e41b349e1a5c8881a2407f615962", + _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", + licenses = ["notice"], + server_urls = maven_servers, ) native.maven_server( @@ -347,29 +355,29 @@ def scala_repositories(): name = "io_bazel_rules_scala/dependency/commons_io/commons_io", actual = "@scalac_rules_commons_io//jar") - native.bind( - name = "io_bazel_rules_scala/dependency/scala/parser_combinators", - actual = "@scala//:scala-parser-combinators") - native.bind( name = "io_bazel_rules_scala/dependency/scala/scala_compiler", - actual = "@scala//:scala-compiler") + actual = "@io_bazel_rules_scala_scala_compiler") native.bind( name = "io_bazel_rules_scala/dependency/scala/scala_library", - actual = "@scala//:scala-library") + actual = "@io_bazel_rules_scala_scala_library") native.bind( name = "io_bazel_rules_scala/dependency/scala/scala_reflect", - actual = "@scala//:scala-reflect") + actual = "@io_bazel_rules_scala_scala_reflect") native.bind( name = "io_bazel_rules_scala/dependency/scala/scala_xml", - actual = "@scala//:scala-xml") + actual = "@io_bazel_rules_scala_scala_xml") + + native.bind( + 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 = "@scalatest//jar") + actual = "@io_bazel_rules_scala_scalatest") def _sanitize_string_for_usage(s): res_array = [] diff --git a/test/BUILD b/test/BUILD index e7bc55f5d..4af03ce5c 100644 --- a/test/BUILD +++ b/test/BUILD @@ -26,7 +26,7 @@ java_binary( main_class = "scalarules.test.JavaBinary", runtime_deps = [ ":OtherJavaLib", - "@scala//:scala-library", + "@io_bazel_rules_scala_scala_library//jar", ], deps = [ ":Exported", diff --git a/test/aspect/aspect.bzl b/test/aspect/aspect.bzl index c37a53601..eaa3c932f 100644 --- a/test/aspect/aspect.bzl +++ b/test/aspect/aspect.bzl @@ -23,30 +23,30 @@ def _rule_impl(ctx): expected_deps = { "scala_library": [ "//test/aspect:scala_library", - "@scala//:scala-library", + "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", ], "scala_test": [ "//test/aspect:scala_test", - "@scala//:scala-library", - "@scalatest//jar:jar", + "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", + "@io_bazel_rules_scala_scalatest//:io_bazel_rules_scala_scalatest", ], "scala_junit_test": [ "//test/aspect:scala_junit_test", - "@scala//:scala-library", + "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", "@io_bazel_rules_scala_junit_junit//jar:jar", "@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar:jar", ], "scala_specs2_junit_test": [ "//test/aspect:scala_specs2_junit_test", - "@scala//:scala-library", + "@io_bazel_rules_scala_scala_library//:io_bazel_rules_scala_scala_library", "@io_bazel_rules_scala_junit_junit//jar:jar", "@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar:jar", # From specs2/specs2.bzl:specs2_dependencies() "@io_bazel_rules_scala//specs2:specs2", - "@scala//:scala-xml", - "@scala//:scala-parser-combinators", - "@scala//:scala-library", - "@scala//:scala-reflect", + "@io_bazel_rules_scala_scala_xml//:io_bazel_rules_scala_scala_xml", + "@io_bazel_rules_scala_scala_parser_combinators//:io_bazel_rules_scala_scala_parser_combinators", + "@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", ],