From 606ccaeb3de6ac88c73dba69f87767ab43e7707b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Tue, 10 Apr 2018 18:05:07 -0700 Subject: [PATCH 01/29] Enable local cache by default (#478) * Enable local cache by default * Spin up separate reproducibility Travis job --- .gitignore | 3 ++- .travis.yml | 6 +++++- test_reproducibility.sh | 37 +++++++++++++++++++++++++++++++++++++ test_rules_scala.sh | 27 --------------------------- tools/bazel.rc | 2 ++ 5 files changed, 46 insertions(+), 29 deletions(-) create mode 100755 test_reproducibility.sh create mode 100644 tools/bazel.rc diff --git a/.gitignore b/.gitignore index c44fe6f29..ddfd1e42d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ bazel-* *.idea hash1 hash2 -.DS_store \ No newline at end of file +.DS_store +.bazel_cache diff --git a/.travis.yml b/.travis.yml index 81c5ae232..a63c5ddef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,10 @@ osx_image: xcode8 # Not technically required but suppresses 'Ruby' in Job status message. language: java +cache: + directories: + - .bazel_cache + os: - linux - osx @@ -14,6 +18,7 @@ env: # we want to test the last release - V=0.11.1 TEST_SCRIPT=test_rules_scala.sh - V=0.11.1 TEST_SCRIPT=test_intellij_aspect.sh + - V=0.11.1 TEST_SCRIPT=test_reproducibility.sh before_install: - | @@ -40,4 +45,3 @@ before_install: script: - bash $TEST_SCRIPT ci - diff --git a/test_reproducibility.sh b/test_reproducibility.sh new file mode 100755 index 000000000..2c3a08a15 --- /dev/null +++ b/test_reproducibility.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -e + +md5_util() { + if [[ "$OSTYPE" == "darwin"* ]]; then + _md5_util="md5" + else + _md5_util="md5sum" + fi + echo "$_md5_util" +} + +non_deploy_jar_md5_sum() { + find bazel-bin/test -name "*.jar" ! -name "*_deploy.jar" | xargs -n 1 -P 5 $(md5_util) | sort +} + +test_build_is_identical() { + bazel build test/... + non_deploy_jar_md5_sum > hash1 + bazel clean + sleep 2 # to make sure that if timestamps slip in we get different ones + bazel build --noexperimental_local_disk_cache test/... + non_deploy_jar_md5_sum > hash2 + diff hash1 hash2 +} + +dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +# shellcheck source=./test_runner.sh +. "${dir}"/test_runner.sh +runner=$(get_test_runner "${1:-local}") + + +# This test is last/separate since it compares the current outputs to new ones to make sure they're identical +# If it runs before some of the above (like jmh) the "current" output in CI might be too close in time to the "new" one +# The test also adds sleep by itself but it's best if it's last +$runner test_build_is_identical diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 9ba69f625..dbc2df339 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -16,28 +16,6 @@ test_disappearing_class() { fi set -e } -md5_util() { -if [[ "$OSTYPE" == "darwin"* ]]; then - _md5_util="md5" -else - _md5_util="md5sum" -fi -echo "$_md5_util" -} - -non_deploy_jar_md5_sum() { - find bazel-bin/test -name "*.jar" ! -name "*_deploy.jar" | xargs -n 1 -P 5 $(md5_util) | sort -} - -test_build_is_identical() { - bazel build test/... - non_deploy_jar_md5_sum > hash1 - bazel clean - sleep 2 # to make sure that if timestamps slip in we get different ones - bazel build test/... - non_deploy_jar_md5_sum > hash2 - diff hash1 hash2 -} test_transitive_deps() { set +e @@ -813,8 +791,3 @@ $runner test_scala_import_library_passes_labels_of_direct_deps $runner java_toolchain_javacopts_are_used $runner bazel run test/src/main/scala/scala/test/classpath_resources:classpath_resource $runner test_scala_classpath_resources_expect_warning_on_namespace_conflict - -# This test is last since it compares the current outputs to new ones to make sure they're identical -# If it runs before some of the above (like jmh) the "current" output in CI might be too close in time to the "new" one -# The test also adds sleep by itself but it's best if it's last -$runner test_build_is_identical diff --git a/tools/bazel.rc b/tools/bazel.rc new file mode 100644 index 000000000..451816bf6 --- /dev/null +++ b/tools/bazel.rc @@ -0,0 +1,2 @@ +build --experimental_local_disk_cache +build --experimental_local_disk_cache_path=.bazel_cache From 8d61985b310e4804e600d3c4a11f57290a124e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Tue, 10 Apr 2018 22:07:19 -0700 Subject: [PATCH 02/29] Update test_all.sh to include test_reproducibility.sh --- test_all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test_all.sh b/test_all.sh index 1a51e8207..c869cba1c 100755 --- a/test_all.sh +++ b/test_all.sh @@ -4,4 +4,5 @@ set -euo pipefail dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) "${dir}"/test_rules_scala.sh +"${dir}"/test_reproducibility.sh "${dir}"/test_intellij_aspect.sh From 4afc7abc73e4fb688e7c95e7aec43005feb44b0b Mon Sep 17 00:00:00 2001 From: Natan Silnitsky Date: Fri, 13 Apr 2018 22:23:04 +0300 Subject: [PATCH 03/29] Scala maven import external (#473) * original jave_import_external * allow for direct jar file usage in dependencies * change java_import to scala_import * replace jar_urls with artifact + server_urls * remove filegroup target and use maven_jar for specific places that need files directly. an issue will be open for scala_import to support direct file output * rename to scala_maven_import_external. still need to decide on splitting to jvm_import_external/maven_import_external * _concat_with_needed_slash * fix typo * add 'return' in new method * extract common code to 'jvm_import_external' rule. introduce macros for 'scala_maven_import_external', 'maven_import_external', 'java_import_external' * CR changes * added documentation * moved license notice back to the top --- WORKSPACE | 23 +- scala/scala_maven_import_external.bzl | 371 ++++++++++++++++++ .../main/scala/scala/test/scala_import/BUILD | 4 +- .../missing_direct_deps/external_deps/BUILD | 2 +- test_expect_failure/scala_import/BUILD | 2 +- test_rules_scala.sh | 4 +- third_party/plugin/src/test/BUILD | 8 +- 7 files changed, 403 insertions(+), 11 deletions(-) create mode 100644 scala/scala_maven_import_external.bzl diff --git a/WORKSPACE b/WORKSPACE index e66f37740..26babf825 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -43,7 +43,7 @@ maven_jar( # test of strict deps (scalac plugin UT + E2E) maven_jar( - name = "com_google_guava_guava_21_0", + name = "com_google_guava_guava_21_0_with_file", artifact = "com.google.guava:guava:21.0", sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709" ) @@ -83,3 +83,24 @@ filegroup( load("@io_bazel_rules_scala//scala:toolchains.bzl","scala_register_toolchains") scala_register_toolchains() + +load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external", "java_import_external") +scala_maven_import_external( + name = "com_google_guava_guava_21_0", + licenses = ["notice"], # Apache 2.0 + artifact = "com.google.guava:guava:21.0", + server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], + jar_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480", +) + +# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external +# in order to allow for other jvm-language imports (e.g. scala_import) +# the 3rd-party dependency below is using the java_import_external macro +# in order to make sure no regression with the original java_import_external +load("//scala:scala_maven_import_external.bzl", "java_import_external") +java_import_external( + name = "org_apache_commons_commons_lang_3_5_without_file", + licenses = ["notice"], # Apache 2.0 + jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"], + jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c", +) \ No newline at end of file diff --git a/scala/scala_maven_import_external.bzl b/scala/scala_maven_import_external.bzl new file mode 100644 index 000000000..926375f7f --- /dev/null +++ b/scala/scala_maven_import_external.bzl @@ -0,0 +1,371 @@ +# Copyright 2017 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. + +""" +'jvm_import_external' offers additional functionality above what maven_jar has to offer. +In addition to downloading the jars, it allows to define this jar's dependencies. +thus it enables the explicit definition of the entire transitive dependency graph. + +The rule achieves this by writing 'import' build rules in BUILD files next to the downloaded jars. +The name of the underlying 'import' rule needs to be specified. +An optional 'load' statement can also be provided, along with any other relevant custom attribute. +These import rules must have the following attributes: +- "jars" +- "deps" +- "runtime_deps" +- "exports" + +the code here is solely based on `jave_import_external` from bazelbuild/bazel repository and is proposed to be upstreamed back. + +the following macros are defined below that utilize jvm_import_external: + +- scala_import_external - uses `scala_import` as the underlying build rule +- jvm_maven_import_external - offers a 'maven' like api for identifying jars using 'artifact' format +- scala_maven_import_external - combination of scala_import_external and jvm_maven_import_external +- java_import_external - to demonstrate that the original functionality of `java_import_external` stayed intact. +""" + +_HEADER = "# DO NOT EDIT: generated by jvm_import_external()" +_PASS_PROPS = ( + "neverlink", + "testonly_", + "visibility", + "exports", + "runtime_deps", + "deps", + "tags", +) + +def _jvm_import_external(repository_ctx): + """Implementation of `java_import_external` rule.""" + if (repository_ctx.attr.generated_linkable_rule_name and + not repository_ctx.attr.neverlink): + fail("Only use generated_linkable_rule_name if neverlink is set") + name = repository_ctx.attr.generated_rule_name or repository_ctx.name + urls = repository_ctx.attr.jar_urls + sha = repository_ctx.attr.jar_sha256 + path = repository_ctx.name + ".jar" + for url in urls: + if url.endswith(".jar"): + path = url[url.rindex("/") + 1:] + break + srcurls = repository_ctx.attr.srcjar_urls + srcsha = repository_ctx.attr.srcjar_sha256 + srcpath = repository_ctx.name + "-src.jar" if srcurls else "" + for url in srcurls: + if url.endswith(".jar"): + srcpath = url[url.rindex("/") + 1:].replace("-sources.jar", "-src.jar") + break + lines = [_HEADER, ""] + if repository_ctx.attr.rule_load: + lines.append(repository_ctx.attr.rule_load) + lines.append("") + if repository_ctx.attr.default_visibility: + lines.append("package(default_visibility = %s)" % ( + repository_ctx.attr.default_visibility)) + lines.append("") + lines.append("licenses(%s)" % repr(repository_ctx.attr.licenses)) + lines.append("") + lines.extend(_serialize_given_rule_import( + repository_ctx.attr.rule_name, name, path, srcpath, repository_ctx.attr, _PASS_PROPS, repository_ctx.attr.additional_rule_attrs)) + if (repository_ctx.attr.neverlink and + repository_ctx.attr.generated_linkable_rule_name): + lines.extend(_serialize_given_rule_import( + repository_ctx.attr.generated_linkable_rule_name, + path, + srcpath, + repository_ctx.attr, + [p for p in _PASS_PROPS if p != "neverlink"])) + extra = repository_ctx.attr.extra_build_file_content + if extra: + lines.append(extra) + if not extra.endswith("\n"): + lines.append("") + repository_ctx.download(urls, path, sha) + if srcurls: + repository_ctx.download(srcurls, srcpath, srcsha) + repository_ctx.file("BUILD", "\n".join(lines)) + repository_ctx.file("jar/BUILD", "\n".join([ + _HEADER, + "", + "package(default_visibility = %r)" % ( + repository_ctx.attr.visibility or + repository_ctx.attr.default_visibility), + "", + "alias(", + " name = \"jar\",", + " actual = \"@%s\"," % repository_ctx.name, + ")", + "", + ])) + +def _convert_to_url(artifact, server_urls): + parts = artifact.split(":") + group_id_part = parts[0].replace(".","/") + artifact_id = parts[1] + version = parts[2] + packaging = "jar" + classifier_part = "" + if len(parts) == 4: + packaging = parts[2] + version = parts[3] + elif len(parts) == 5: + packaging = parts[2] + classifier_part = "-"+parts[3] + version = parts[4] + + final_name = artifact_id + "-" + version + classifier_part + "." + packaging + url_suffix = group_id_part+"/"+artifact_id + "/" + version + "/" + final_name + urls = [] + for server_url in server_urls: + urls.append(_concat_with_needed_slash(server_url, url_suffix)) + return urls + +def _concat_with_needed_slash(server_url, url_suffix): + if server_url.endswith("/"): + return server_url + url_suffix + else: + return server_url + "/" + url_suffix + +def _serialize_given_rule_import(rule_name, name, path, srcpath, attrs, props, additional_rule_attrs): + lines = [ + "%s(" % rule_name, + " name = %s," % repr(name), + " jars = [%s]," % repr(path), + ] + if srcpath: + lines.append(" srcjar = %s," % repr(srcpath)) + for prop in props: + value = getattr(attrs, prop, None) + if value: + if prop.endswith("_"): + prop = prop[:-1] + lines.append(" %s = %s," % (prop, repr(value))) + for attr_key in additional_rule_attrs: + lines.append(" %s = %s," % (attr_key, additional_rule_attrs[attr_key])) + lines.append(")") + lines.append("") + return lines + +jvm_import_external = repository_rule( + implementation=_jvm_import_external, + attrs={ + "rule_name": attr.string(mandatory=True), + "licenses": attr.string_list(mandatory=True, allow_empty=False), + "jar_urls": attr.string_list(mandatory=True, allow_empty=False), + "jar_sha256": attr.string(), + "rule_load": attr.string(), + "additional_rule_attrs": attr.string_dict(), + "srcjar_urls": attr.string_list(), + "srcjar_sha256": attr.string(), + "deps": attr.string_list(), + "runtime_deps": attr.string_list(), + "testonly_": attr.bool(), + "exports": attr.string_list(), + "neverlink": attr.bool(), + "generated_rule_name": attr.string(), + "generated_linkable_rule_name": attr.string(), + "default_visibility": attr.string_list(default=["//visibility:public"]), + "extra_build_file_content": attr.string(), + }) + +def scala_maven_import_external(artifact, + server_urls, + rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", + **kwargs): + jvm_maven_import_external( + rule_name = "scala_import", + rule_load = rule_load, + artifact = artifact, + server_urls = server_urls, +#additional string attributes' values have to be escaped in order to accomodate non-string types +# additional_rule_attrs = {"foo": "'bar'"}, + **kwargs + ) + +def jvm_maven_import_external(artifact, server_urls, **kwargs): + jvm_import_external( + jar_urls = _convert_to_url(artifact, server_urls), + **kwargs + ) + +def scala_import_external(rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", + **kwargs): + jvm_import_external( + rule_name = "scala_import", + rule_load = rule_load, + **kwargs + ) + +"""Rules for defining external Java dependencies. + +java_import_external() replaces `maven_jar` and `http_jar`. It is the +recommended solution for defining third party Java dependencies that are +obtained from web servers. + +This solution offers high availability, low latency, and repository +scalability at the cost of simplicity. Tooling can be used to generate + +The default target in this BUILD file will always have the same name as +the repository itself. This means that other Bazel rules can depend on +it as `@repo//:repo` or `@repo` for short. + +### Setup + +Add the following to your `WORKSPACE` file: + +```python +load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external") +``` + +### Best Practices + +#### Downloading + +The recommended best practices for downloading Maven jars are as follows: + +1. Always follow release versions or pinned revisions. +2. Permanently mirror all dependencies to GCS or S3 as the first URL +3. Put the original URL in the GCS or S3 object name +4. Make the second URL the original repo1.maven.org URL +5. Make the third URL the maven.ibiblio.org mirror, if it isn't 404 +6. Always specify the sha256 checksum + +Bazel has one of the most sophisticated systems for downloading files of any +build system. Following these best practices will ensure that your codebase +takes full advantage of the level of reliability that Bazel able to offer. See +https://goo.gl/uQOE11 for more information. + +#### Selection + +Avoid using jars that bundle their dependencies. For example, a Maven jar for +the artifact com.initech:tps:1.0 should not contain a classes named +com.fakecorp.foo. Try to see if Initech distributes a tps jar that doesn't +bundle its dependencies. Then create a separate java_import_external() for each +one and have the first depend on the second. + +Sometimes jars are distributed with their dependencies shaded. What this means +is that com.initech.tps will contain classes like +com.initech.tps.shade.com.fakecorp.foo. This is less problematic, since it +won't lead to mysterious classpath conflicts. But it can lead to inefficient +use of space and make the license of the the end product more difficult to +determine. + +#### Licensing + +The following values for the licenses field are typically used. If a jar +contains multiple works with difference licenses, then only the most +restrictive one is listed, and the rest are noted in accompanying comments. + +The following are examples of how licenses could be categorized, ordered +by those with terms most permissive to least: + +- **unencumbered**: CC0, Unlicense +- **permissive**: Beerware +- **notice**: Apache, MIT, X11, BSD, ISC, ZPL, Unicode, JSON, Artistic +- **reciprocal**: MPL, CPL, EPL, Eclipse, APSL, IBMPL, CDDL +- **restricted**: GPL, LGPL, OSL, Sleepycat, QTPL, Java, QMail, NPL +- **by_exception_only**: AGPL, WTFPL + +### Naming + +Bazel repository names must match the following pattern: `[_0-9A-Za-z]+`. To +choose an appropriate name based on a Maven group and artifact ID, we recommend +an algorithm https://gist.github.com/jart/41bfd977b913c2301627162f1c038e55 which +can be best explained by the following examples: + +- com.google.guava:guava becomes com_google_guava +- commons-logging:commons-logging becomes commons_logging +- junit:junit becomes junit + +Adopting this naming convention will help maximize the chances that your +codebase will be able to successfully interoperate with other Bazel codebases +using Java. + +### Example + +Here is an example of a best practice definition of Google's Guava library: + +```python +java_import_external( + name = "com_google_guava", + licenses = ["notice"], # Apache 2.0 + jar_urls = [ + "http://bazel-mirror.storage.googleapis.com/repo1.maven.org/maven2/com/google/guava/guava/20.0/guava-20.0.jar", + "http://repo1.maven.org/maven2/com/google/guava/guava/20.0/guava-20.0.jar", + "http://maven.ibiblio.org/maven2/com/google/guava/guava/20.0/guava-20.0.jar", + ], + jar_sha256 = "36a666e3b71ae7f0f0dca23654b67e086e6c93d192f60ba5dfd5519db6c288c8", + deps = [ + "@com_google_code_findbugs_jsr305", + "@com_google_errorprone_error_prone_annotations", + ], +) + +java_import_external( + name = "com_google_code_findbugs_jsr305", + licenses = ["notice"], # BSD 3-clause + jar_urls = [ + "http://bazel-mirror.storage.googleapis.com/repo1.maven.org/maven2/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar", + "http://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar", + "http://maven.ibiblio.org/maven2/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar", + ], + jar_sha256 = "905721a0eea90a81534abb7ee6ef4ea2e5e645fa1def0a5cd88402df1b46c9ed", +) + +java_import_external( + name = "com_google_errorprone_error_prone_annotations", + licenses = ["notice"], # Apache 2.0 + jar_sha256 = "e7749ffdf03fb8ebe08a727ea205acb301c8791da837fee211b99b04f9d79c46", + jar_urls = [ + "http://bazel-mirror.storage.googleapis.com/repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.0.15/error_prone_annotations-2.0.15.jar", + "http://maven.ibiblio.org/maven2/com/google/errorprone/error_prone_annotations/2.0.15/error_prone_annotations-2.0.15.jar", + "http://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.0.15/error_prone_annotations-2.0.15.jar", + ], +) +``` + +### Annotation Processors + +Defining jars that contain annotation processors requires a certain level of +trickery, which is best done by copying and pasting from codebases that have +already done it before. Please see the Google Nomulus and Bazel Closure Rules +codebases for examples in which java_import_external has been used to define +Dagger 2.0, AutoValue, and AutoFactory. + +Please note that certain care needs to be taken into consideration regarding +whether or not these annotation processors generate actual API, or simply +generate code that implements them. See the Bazel documentation for further +information. + +### Test Dependencies + +It is strongly recommended that the `testonly_` attribute be specified on +libraries that are intended for testing purposes. This is passed along to the +generated `java_library` rule in order to ensure that test code remains +disjoint from production code. + +### Provided Dependencies + +The feature in Bazel most analagous to Maven's provided scope is the neverlink +attribute. This should be used in rare circumstances when a distributed jar +will be loaded into a runtime environment where certain dependencies can be +reasonably expected to already be provided. +""" +def java_import_external(jar_sha256, **kwargs): + jvm_import_external( + rule_name = "java_import", + jar_sha256 = jar_sha256, + **kwargs + ) diff --git a/test/src/main/scala/scala/test/scala_import/BUILD b/test/src/main/scala/scala/test/scala_import/BUILD index 0355f731a..510d77627 100644 --- a/test/src/main/scala/scala/test/scala_import/BUILD +++ b/test/src/main/scala/scala/test/scala_import/BUILD @@ -4,7 +4,7 @@ load("//scala:scala_import.bzl", "scala_import") #Many jars scala_import( name = "guava_and_commons_lang", - jars = ["@com_google_guava_guava_21_0//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], + jars = ["@com_google_guava_guava_21_0_with_file//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], ) # Jars as files @@ -67,7 +67,7 @@ scala_specs2_junit_test( java_import( name = "guava_and_commons_lang_java_import", - jars = ["@com_google_guava_guava_21_0//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], + jars = ["@com_google_guava_guava_21_0_with_file//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], ) #Exports diff --git a/test_expect_failure/missing_direct_deps/external_deps/BUILD b/test_expect_failure/missing_direct_deps/external_deps/BUILD index 44ea7e754..3fb0165a6 100644 --- a/test_expect_failure/missing_direct_deps/external_deps/BUILD +++ b/test_expect_failure/missing_direct_deps/external_deps/BUILD @@ -30,5 +30,5 @@ scala_library( srcs=[ "B.scala", ], - deps = ["@com_google_guava_guava_21_0//jar:file"], + deps = ["@com_google_guava_guava_21_0_with_file//jar:file"], ) \ No newline at end of file diff --git a/test_expect_failure/scala_import/BUILD b/test_expect_failure/scala_import/BUILD index cd8501d70..b0d037042 100644 --- a/test_expect_failure/scala_import/BUILD +++ b/test_expect_failure/scala_import/BUILD @@ -11,7 +11,7 @@ scala_import( scala_import( name = "guava", - jars = ["@com_google_guava_guava_21_0//jar:file"], + jars = ["@com_google_guava_guava_21_0_with_file//jar:file"], deps = [":dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage"] ) diff --git a/test_rules_scala.sh b/test_rules_scala.sh index dbc2df339..03687eb83 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -126,14 +126,14 @@ test_scala_binary_expect_failure_on_missing_direct_deps_located_in_dependency_wh } test_scala_library_expect_failure_on_missing_direct_external_deps_jar() { - dependenecy_target='@com_google_guava_guava_21_0//jar:jar' + dependenecy_target='@com_google_guava_guava_21_0//:com_google_guava_guava_21_0' test_target='test_expect_failure/missing_direct_deps/external_deps:transitive_external_dependency_user' test_scala_library_expect_failure_on_missing_direct_deps $dependenecy_target $test_target } test_scala_library_expect_failure_on_missing_direct_external_deps_file_group() { - dependenecy_target='@com_google_guava_guava_21_0//jar:file' + dependenecy_target='@com_google_guava_guava_21_0_with_file//jar:file' test_target='test_expect_failure/missing_direct_deps/external_deps:transitive_external_dependency_user_file_group' test_scala_library_expect_failure_on_missing_direct_deps $dependenecy_target $test_target diff --git a/third_party/plugin/src/test/BUILD b/third_party/plugin/src/test/BUILD index b5cbd69cb..0589fc5d2 100644 --- a/third_party/plugin/src/test/BUILD +++ b/third_party/plugin/src/test/BUILD @@ -11,11 +11,11 @@ scala_junit_test( deps = ["//third_party/plugin/src/main:dependency_analyzer", "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "@com_google_guava_guava_21_0//jar", - "@org_apache_commons_commons_lang_3_5//jar" + "@com_google_guava_guava_21_0_with_file//jar", + "@org_apache_commons_commons_lang_3_5_without_file//jar" ], jvm_flags = ["-Dplugin.jar.location=$(location //third_party/plugin/src/main:dependency_analyzer)", "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", - "-Dguava.jar.location=$(location @com_google_guava_guava_21_0//jar)", - "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5//jar)"], + "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", + "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//jar)"], ) \ No newline at end of file From 7456a0b5a945ff8b09530c6601dced9ad46e58be Mon Sep 17 00:00:00 2001 From: "P. Oscar Boykin" Date: Mon, 16 Apr 2018 09:38:30 -1000 Subject: [PATCH 04/29] Fix remaining incompatible changes warnings (#480) * Fix remaining incompatible changes warnings * add tests, fix test for strict deps --- scala/scala.bzl | 148 ++++++++++++++++++++--------------------- test/BUILD | 2 +- test/aspect/aspect.bzl | 2 +- test_rules_scala.sh | 2 + 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/scala/scala.bzl b/scala/scala.bzl index c843c29b9..c27342d9c 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -113,24 +113,27 @@ touch {statsfile} def _collect_plugin_paths(plugins): - paths = depset() + paths = [] for p in plugins: if hasattr(p, "path"): - paths += [p.path] + paths.append(p) elif hasattr(p, "scala"): - paths += [p.scala.outputs.jar.path] + paths.append(p.scala.outputs.jar) elif hasattr(p, "java"): - paths += [j.class_jar.path for j in p.java.outputs.jars] + paths.extend([j.class_jar for j in p.java.outputs.jars]) # support http_file pointed at a jar. http_jar uses ijar, # which breaks scala macros elif hasattr(p, "files"): - paths += [f.path for f in p.files if not_sources_jar(f.basename) ] - return paths + paths.extend([f for f in p.files if not_sources_jar(f.basename)]) + return depset(paths) def _expand_location(ctx, flags): return [ctx.expand_location(f, ctx.attr.data) for f in flags] +def _join_path(args, sep=","): + return sep.join([f.path for f in args]) + def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels, implicit_junit_deps_needed_for_java_compilation): ijar_output_path = "" ijar_cmd_path = "" @@ -141,7 +144,7 @@ def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels java_srcs = _java_filetype.filter(ctx.files.srcs) sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs srcjars = _srcjar_filetype.filter(ctx.files.srcs) - all_srcjars = depset(srcjars + list(dep_srcjars)) + all_srcjars = depset(srcjars, transitive = [dep_srcjars]) # look for any plugins: plugins = _collect_plugin_paths(ctx.attr.plugins) dependency_analyzer_plugin_jars = [] @@ -156,13 +159,14 @@ def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels # "off" mode is used as a feature toggle, that preserves original behaviour dependency_analyzer_mode = ctx.fragments.java.strict_java_deps dep_plugin = ctx.attr._dependency_analyzer_plugin - plugins += [f.path for f in dep_plugin.files] + plugins = depset(transitive = [plugins, dep_plugin.files]) dependency_analyzer_plugin_jars = ctx.files._dependency_analyzer_plugin compiler_classpath_jars = transitive_compile_jars - direct_jars = ",".join([j.path for j in cjars]) - indirect_jars = ",".join([j.path for j in transitive_compile_jars]) - indirect_targets = ",".join([labels[j.path] for j in transitive_compile_jars]) + direct_jars = _join_path(cjars.to_list()) + transitive_cjars_list = transitive_compile_jars.to_list() + indirect_jars = _join_path(transitive_cjars_list) + indirect_targets = ",".join([labels[j.path] for j in transitive_cjars_list]) current_target = str(ctx.label) optional_scalac_args = """ @@ -177,10 +181,10 @@ CurrentTarget: {current_target} current_target = current_target ) - plugin_arg = ",".join(list(plugins)) + plugin_arg = _join_path(plugins.to_list()) separator = ctx.configuration.host_path_separator - compiler_classpath = separator.join([j.path for j in compiler_classpath_jars]) + compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type'] scalacopts = toolchain.scalacopts + ctx.attr.scalacopts @@ -213,20 +217,21 @@ StatsfileOutput: {statsfile_output} print_compile_time=ctx.attr.print_compile_time, plugin_arg=plugin_arg, cp=compiler_classpath, - classpath_resource_src=",".join([f.path for f in classpath_resources]), - files=",".join([f.path for f in sources]), + classpath_resource_src=_join_path(classpath_resources), + files=_join_path(sources), enableijar=buildijar, ijar_out=ijar_output_path, ijar_cmd_path=ijar_cmd_path, - srcjars=",".join([f.path for f in all_srcjars]), - java_files=",".join([f.path for f in java_srcs]), + srcjars=_join_path(all_srcjars.to_list()), + java_files=_join_path(java_srcs), + # the resource paths need to be aligned in order resource_src=",".join([f.path for f in ctx.files.resources]), resource_short_paths=",".join([f.short_path for f in ctx.files.resources]), resource_dest=",".join( [_adjust_resources_path_by_default_prefixes(f.short_path)[1] for f in ctx.files.resources] ), resource_strip_prefix=ctx.attr.resource_strip_prefix, - resource_jars=",".join([f.path for f in ctx.files.resource_jars]), + resource_jars=_join_path(ctx.files.resource_jars), dependency_analyzer_mode = dependency_analyzer_mode, statsfile_output = ctx.outputs.statsfile.path ) @@ -240,8 +245,8 @@ StatsfileOutput: {statsfile_output} outs = [ctx.outputs.jar, ctx.outputs.statsfile] if buildijar: outs.extend([ctx.outputs.ijar]) - ins = (list(compiler_classpath_jars) + - list(dep_srcjars) + + ins = (compiler_classpath_jars.to_list() + + dep_srcjars.to_list() + list(srcjars) + list(sources) + ctx.files.srcs + @@ -344,7 +349,7 @@ def collect_java_providers_of(deps): def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation): # We assume that if a srcjar is present, it is not empty - if len(ctx.files.srcs) + len(srcjars) == 0: + if len(ctx.files.srcs) + len(srcjars.to_list()) == 0: _build_nosrc_jar(ctx, buildijar) # no need to build ijar when empty return struct(ijar=ctx.outputs.jar, @@ -372,17 +377,17 @@ def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, ja full_jars=full_jars, ijars=ijars) -def _build_deployable(ctx, jars): +def _build_deployable(ctx, jars_list): # This calls bazels singlejar utility. # For a full list of available command line options see: # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 args = ["--normalize", "--sources"] - args.extend([j.path for j in jars]) + args.extend([j.path for j in jars_list]) if getattr(ctx.attr, "main_class", ""): args.extend(["--main_class", ctx.attr.main_class]) args.extend(["--output", ctx.outputs.deploy_jar.path]) ctx.actions.run( - inputs=list(jars), + inputs=jars_list, outputs=[ctx.outputs.deploy_jar], executable=ctx.executable._singlejar, mnemonic="ScalaDeployJar", @@ -452,7 +457,7 @@ def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper): template = ctx.attr._java_stub_template.files.to_list()[0] # RUNPATH is defined here: # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227 - classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars]) + classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()]) jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags]) ctx.actions.expand_template( template = template, @@ -471,11 +476,11 @@ def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper): ) def collect_srcjars(targets): - srcjars = depset() + srcjars = [] for target in targets: if hasattr(target, "srcjars"): - srcjars += [target.srcjars.srcjar] - return srcjars + srcjars.append(target.srcjars.srcjar) + return depset(srcjars) def add_labels_of_jars_to(jars2labels, dependency, all_jars, direct_jars): for jar in direct_jars: @@ -526,68 +531,68 @@ def filter_not_sources(deps): return depset([dep for dep in deps.to_list() if not_sources_jar(dep.basename) ]) def _collect_runtime_jars(dep_targets): - runtime_jars = depset() + runtime_jars = [] for dep_target in dep_targets: if java_common.provider in dep_target: - runtime_jars += dep_target[java_common.provider].transitive_runtime_jars + runtime_jars.append(dep_target[java_common.provider].transitive_runtime_jars) else: # support http_file pointed at a jar. http_jar uses ijar, # which breaks scala macros - runtime_jars += filter_not_sources(dep_target.files) + runtime_jars.append(filter_not_sources(dep_target.files)) return runtime_jars def _collect_jars_when_dependency_analyzer_is_off(dep_targets): - compile_jars = depset() - runtime_jars = depset() + compile_jars = [] + runtime_jars = [] for dep_target in dep_targets: if java_common.provider in dep_target: java_provider = dep_target[java_common.provider] - compile_jars += java_provider.compile_jars - runtime_jars += java_provider.transitive_runtime_jars + compile_jars.append(java_provider.compile_jars) + runtime_jars.append(java_provider.transitive_runtime_jars) else: # support http_file pointed at a jar. http_jar uses ijar, # which breaks scala macros - compile_jars += filter_not_sources(dep_target.files) - runtime_jars += filter_not_sources(dep_target.files) + compile_jars.append(filter_not_sources(dep_target.files)) + runtime_jars.append(filter_not_sources(dep_target.files)) - return struct(compile_jars = compile_jars, - transitive_runtime_jars = runtime_jars, + return struct(compile_jars = depset(transitive = compile_jars), + transitive_runtime_jars = depset(transitive = runtime_jars), jars2labels = {}, transitive_compile_jars = depset()) def _collect_jars_when_dependency_analyzer_is_on(dep_targets): - transitive_compile_jars = depset() + transitive_compile_jars = [] jars2labels = {} - compile_jars = depset() - runtime_jars = depset() + compile_jars = [] + runtime_jars = [] for dep_target in dep_targets: - current_dep_compile_jars = depset() - current_dep_transitive_compile_jars = depset() + current_dep_compile_jars = None + current_dep_transitive_compile_jars = None if java_common.provider in dep_target: java_provider = dep_target[java_common.provider] current_dep_compile_jars = java_provider.compile_jars current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars - runtime_jars += java_provider.transitive_runtime_jars + runtime_jars.append(java_provider.transitive_runtime_jars) else: # support http_file pointed at a jar. http_jar uses ijar, # which breaks scala macros current_dep_compile_jars = filter_not_sources(dep_target.files) - runtime_jars += filter_not_sources(dep_target.files) current_dep_transitive_compile_jars = filter_not_sources(dep_target.files) + runtime_jars.append(filter_not_sources(dep_target.files)) - compile_jars += current_dep_compile_jars - transitive_compile_jars += current_dep_transitive_compile_jars - add_labels_of_jars_to(jars2labels, dep_target, current_dep_transitive_compile_jars, current_dep_compile_jars) + compile_jars.append(current_dep_compile_jars) + transitive_compile_jars.append(current_dep_transitive_compile_jars) + add_labels_of_jars_to(jars2labels, dep_target, current_dep_transitive_compile_jars.to_list(), current_dep_compile_jars.to_list()) - return struct(compile_jars = compile_jars, - transitive_runtime_jars = runtime_jars, + return struct(compile_jars = depset(transitive = compile_jars), + transitive_runtime_jars = depset(transitive = runtime_jars), jars2labels = jars2labels, - transitive_compile_jars = transitive_compile_jars) + transitive_compile_jars = depset(transitive = transitive_compile_jars)) def collect_jars(dep_targets, dependency_analyzer_is_off = True): """Compute the runtime and compile-time dependencies from the given targets""" # noqa @@ -620,7 +625,7 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = []) deps_jars = collect_jars(ctx.attr.deps + auto_deps + extra_deps, dependency_analyzer_is_off) (cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, deps_jars.jars2labels, deps_jars.transitive_compile_jars) - transitive_rjars += _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps) + transitive_rjars = depset(transitive = [transitive_rjars] + _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps)) return struct(compile_jars = cjars, transitive_runtime_jars = transitive_rjars, jars2labels=jars2labels, transitive_compile_jars = transitive_compile_jars) @@ -636,7 +641,7 @@ def create_java_provider(scalaattr, transitive_compile_time_jars): use_ijar = False, compile_time_jars = scalaattr.compile_jars, runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = transitive_compile_time_jars + scalaattr.compile_jars, + transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), transitive_runtime_jars = scalaattr.transitive_runtime_jars, ) else: @@ -692,14 +697,9 @@ def _lib(ctx, non_macro_lib): write_manifest(ctx) outputs = _compile_or_empty(ctx, cjars, srcjars, non_macro_lib, jars.transitive_compile_jars, jars.jars2labels, []) - transitive_rjars += outputs.full_jars - - _build_deployable(ctx, transitive_rjars) + transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) - # Now, need to setup providers for dependents - # Notice that transitive_rjars just carries over from dependency analysis - # but cjars 'resets' between cjars and next_cjars - next_cjars = depset(outputs.ijars) # use ijar, if available, for future compiles + _build_deployable(ctx, transitive_rjars.to_list()) # Using transitive_files since transitive_rjars a depset and avoiding linearization runfiles = ctx.runfiles( @@ -711,13 +711,12 @@ def _lib(ctx, non_macro_lib): # Since after, will not show up in deploy_jar or old jars runfiles # Notice that compile_jars is intentionally transitive for exports exports_jars = collect_jars(ctx.attr.exports) - next_cjars += exports_jars.compile_jars - transitive_rjars += exports_jars.transitive_runtime_jars + transitive_rjars = depset(transitive = [transitive_rjars, exports_jars.transitive_runtime_jars]) scalaattr = create_scala_provider( ijar = outputs.ijar, class_jar = outputs.class_jar, - compile_jars = next_cjars, + compile_jars = depset(outputs.ijars, transitive = [exports_jars.compile_jars]), transitive_runtime_jars = transitive_rjars, deploy_jar = ctx.outputs.deploy_jar, full_jars = outputs.full_jars, @@ -760,14 +759,13 @@ def _scala_macro_library_impl(ctx): # Common code shared by all scala binary implementations. def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2labels, java_wrapper, implicit_junit_deps_needed_for_java_compilation = []): write_manifest(ctx) - outputs = _compile_or_empty(ctx, cjars, [], False, transitive_compile_time_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) # no need to build an ijar for an executable - rjars += outputs.full_jars + outputs = _compile_or_empty(ctx, cjars, depset(), False, transitive_compile_time_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) # no need to build an ijar for an executable + rjars = depset(outputs.full_jars, transitive = [rjars]) - rjars_list = list(rjars) - _build_deployable(ctx, rjars_list) + _build_deployable(ctx, rjars.to_list()) runfiles = ctx.runfiles( - files = rjars_list + [ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, + transitive_files = depset([ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, transitive = [rjars]), collect_data = True) scalaattr = create_scala_provider( @@ -860,12 +858,13 @@ def _scala_test_impl(ctx): # _scalatest is an http_jar, so its compile jar is run through ijar # however, contains macros, so need to handle separately scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars - cjars += scalatest_jars - transitive_rjars += scalatest_jars + cjars = depset(transitive = [cjars, scalatest_jars]) + transitive_rjars = depset(transitive = [transitive_rjars, scalatest_jars]) if is_dependency_analyzer_on(ctx): - transitive_compile_jars += scalatest_jars - add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, scalatest_jars, scalatest_jars) + transitive_compile_jars = depset(transitive = [scalatest_jars, transitive_compile_jars]) + scalatest_jars_list = scalatest_jars.to_list() + add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, scalatest_jars_list, scalatest_jars_list) args = " ".join([ "-R \"{path}\"".format(path=ctx.outputs.jar.short_path), @@ -1206,7 +1205,8 @@ def scala_repositories(): def _sanitize_string_for_usage(s): res_array = [] - for c in s: + for idx in range(len(s)): + c = s[idx] if c.isalnum() or c == ".": res_array.append(c) else: diff --git a/test/BUILD b/test/BUILD index bf6ede594..dc533896e 100644 --- a/test/BUILD +++ b/test/BUILD @@ -307,7 +307,7 @@ scala_specs2_junit_test( # Make sure scala_binary works in test environment [sh_test( - name = "Run" + "".join([c if c.isalnum() else "_" for c in binary]), + 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], diff --git a/test/aspect/aspect.bzl b/test/aspect/aspect.bzl index ead7291f4..195ad94f7 100644 --- a/test/aspect/aspect.bzl +++ b/test/aspect/aspect.bzl @@ -65,7 +65,7 @@ def _rule_impl(ctx): """.format(name=target.label.name, expected=', '.join(expected), visited=', '.join(visited)) - ctx.file_action( + ctx.actions.write( output = ctx.outputs.executable, content = content, ) diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 03687eb83..4e44cc3ce 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -722,9 +722,11 @@ dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) runner=$(get_test_runner "${1:-local}") $runner bazel build test/... +$runner bazel build "test/... --all_incompatible_changes" $runner bazel test test/... $runner bazel test third_party/... $runner bazel build "test/... --strict_java_deps=ERROR" +$runner bazel build "test/... --strict_java_deps=ERROR --all_incompatible_changes" $runner bazel test "test/... --strict_java_deps=ERROR" $runner bazel run test/src/main/scala/scala/test/twitter_scrooge:justscrooges $runner bazel run test:JavaBinary From 550ddae279ed10f8d3feb9f493bc15c4cb8438be Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 23 Apr 2018 17:58:01 -0700 Subject: [PATCH 05/29] `+` operator on a depset is forbidden Fixes: ERROR: test/proto/BUILD:36:1: in scala_proto_srcjar rule //test/proto:test_proto_java_conversions_srcjar: Traceback (most recent call last): File "test/proto/BUILD", line 36 scala_proto_srcjar(name = 'test_proto_java_conversions_srcjar') File "scala_proto/scala_proto.bzl", line 332, in _gen_proto_srcjar_impl transitive_proto_paths += target.proto.transitive_proto_path `+` operator on a depset is forbidden. See https://docs.bazel.build/versions/master/skylark/depsets.html for recommendations. Use --incompatible_depset_union=false to temporarily disable this check. See also #480 --- scala_proto/scala_proto.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index a13228ac5..f3ddef678 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -320,7 +320,7 @@ def _colon_paths(data): def _gen_proto_srcjar_impl(ctx): acc_imports = [] - transitive_proto_paths = depset() + transitive_proto_paths = [] proto_deps, jvm_deps = [], [] for target in ctx.attr.deps: @@ -329,7 +329,7 @@ def _gen_proto_srcjar_impl(ctx): acc_imports.append(target.proto.transitive_sources) #inline this if after 0.12.0 is the oldest supported version if hasattr(target.proto, 'transitive_proto_path'): - transitive_proto_paths += target.proto.transitive_proto_path + transitive_proto_paths.append(target.proto.transitive_proto_path) else: jvm_deps.append(target) @@ -345,7 +345,7 @@ def _gen_proto_srcjar_impl(ctx): # Command line args to worker cannot be empty so using padding flags_arg = "-" + ",".join(ctx.attr.flags), # Command line args to worker cannot be empty so using padding - packages = "-" + ":".join(transitive_proto_paths.to_list()) + packages = "-" + ":".join(transitive_proto_paths) ) argfile = ctx.actions.declare_file("%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) ctx.actions.write(output=argfile, content=worker_content) From 52c1bcf54f73bce574999eb11e47b4031700a98c Mon Sep 17 00:00:00 2001 From: gkk-stripe Date: Wed, 25 Apr 2018 00:17:45 -0400 Subject: [PATCH 06/29] Updated jar creator (#483) * use upstream jarcreator (from bazel) * Patch up the new version of JarCreator Restore the old functionality of JarCreator (e.g. support for manifests) by patching up the new code of JarCreator that came from bazel. * Normalize in JarHelper by default Fixes reproducibility issues. Also, disable output from the JarCreator. --- .../io/bazel/rulesscala/jar/JarCreator.java | 214 ++++++++++++------ .../io/bazel/rulesscala/jar/JarHelper.java | 175 ++++++-------- .../rulesscala/scalac/ScalacProcessor.java | 2 +- 3 files changed, 217 insertions(+), 174 deletions(-) diff --git a/src/java/io/bazel/rulesscala/jar/JarCreator.java b/src/java/io/bazel/rulesscala/jar/JarCreator.java index 3c600ab70..6b6fdb1bb 100644 --- a/src/java/io/bazel/rulesscala/jar/JarCreator.java +++ b/src/java/io/bazel/rulesscala/jar/JarCreator.java @@ -18,8 +18,15 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; +import java.io.UncheckedIOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.Collection; import java.util.Map; import java.util.TreeMap; @@ -35,83 +42,145 @@ public class JarCreator extends JarHelper { // Map from Jar entry names to files. Use TreeMap so we can establish a canonical order for the // entries regardless in what order they get added. - private final Map jarEntries = new TreeMap<>(); + private final TreeMap jarEntries = new TreeMap<>(); private String manifestFile; private String mainClass; + private String targetLabel; + private String injectingRuleKind; + /** @deprecated use {@link JarCreator(Path)} instead */ + @Deprecated public JarCreator(String fileName) { - super(fileName); + this(Paths.get(fileName)); + } + + public JarCreator(Path path) { + super(path); } /** * Adds an entry to the Jar file, normalizing the name. * * @param entryName the name of the entry in the Jar file - * @param fileName the name of the input file for the entry + * @param path the path of the input for the entry * @return true iff a new entry was added */ - public boolean addEntry(String entryName, String fileName) { + public boolean addEntry(String entryName, Path path) { if (entryName.startsWith("/")) { entryName = entryName.substring(1); + } else if (entryName.length() >= 3 + && Character.isLetter(entryName.charAt(0)) + && entryName.charAt(1) == ':' + && (entryName.charAt(2) == '\\' || entryName.charAt(2) == '/')) { + // Windows absolute path, e.g. "D:\foo" or "e:/blah". + // Windows paths are case-insensitive, and support both backslashes and forward slashes. + entryName = entryName.substring(3); } else if (entryName.startsWith("./")) { entryName = entryName.substring(2); } - return jarEntries.put(entryName, fileName) == null; + return jarEntries.put(entryName, path) == null; } /** - * Adds the contents of a directory to the Jar file. All files below this - * directory will be added to the Jar file using the name relative to the - * directory as the name for the Jar entry. + * Adds an entry to the Jar file, normalizing the name. * - * @param directory the directory to add to the jar + * @param entryName the name of the entry in the Jar file + * @param fileName the name of the input file for the entry + * @return true iff a new entry was added */ - public void addDirectory(File directory) { - addDirectory(null, directory); + public boolean addEntry(String entryName, String fileName) { + return addEntry(entryName, Paths.get(fileName)); } - public void addJar(File file) { - jarEntries.put(file.getAbsolutePath(), file.getAbsolutePath()); + /** @deprecated prefer {@link #addDirectory(Path)} */ + @Deprecated + public void addDirectory(String directory) { + addDirectory(Paths.get(directory)); } + + /** @deprecated prefer {@link #addDirectory(Path)} */ + @Deprecated + public void addDirectory(File directory) { + addDirectory(directory.toPath()); + } + /** - * Adds the contents of a directory to the Jar file. All files below this - * directory will be added to the Jar file using the prefix and the name - * relative to the directory as the name for the Jar entry. Always uses '/' as - * the separator char for the Jar entries. + * Adds the contents of a directory to the Jar file. All files below this directory will be added + * to the Jar file using the name relative to the directory as the name for the Jar entry. * - * @param prefix the prefix to prepend to every Jar entry name found below the - * directory - * @param directory the directory to add to the Jar + * @param directory the directory to add to the jar */ - private void addDirectory(String prefix, File directory) { - File[] files = directory.listFiles(); - if (files != null) { - for (File file : files) { - String entryName = prefix != null ? prefix + "/" + file.getName() : file.getName(); - jarEntries.put(entryName, file.getAbsolutePath()); - if (file.isDirectory()) { - addDirectory(entryName, file); - } - } + public void addDirectory(Path directory) { + if (!Files.exists(directory)) { + throw new IllegalArgumentException("directory does not exist: " + directory); + } + try { + Files.walkFileTree( + directory, + new SimpleFileVisitor() { + + @Override + public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) + throws IOException { + if (!path.equals(directory)) { + // For consistency with legacy behaviour, include entries for directories except for + // the root. + addEntry(path, /* isDirectory= */ true); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) + throws IOException { + addEntry(path, /* isDirectory= */ false); + return FileVisitResult.CONTINUE; + } + + void addEntry(Path path, boolean isDirectory) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (Path entry : directory.relativize(path)) { + if (!first) { + // use `/` as the directory separator for jar paths, even on Windows + sb.append('/'); + } + sb.append(entry.getFileName()); + first = false; + } + if (isDirectory) { + sb.append('/'); + } + jarEntries.put(sb.toString(), path); + } + }); + } catch (IOException e) { + throw new UncheckedIOException(e); } } + public void addJar(Path path) { + jarEntries.put(path.toAbsolutePath().toString(), path.toAbsolutePath()); + } + /** - * Adds a collection of entries to the jar, each with a given source path, and with - * the resulting file in the root of the jar. + * Adds a collection of entries to the jar, each with a given source path, and with the resulting + * file in the root of the jar. + * *
    * some/long/path.foo => (path.foo, some/long/path.foo)
    * 
*/ public void addRootEntries(Collection entries) { for (String entry : entries) { - jarEntries.put(new File(entry).getName(), entry); + Path path = Paths.get(entry); + jarEntries.put(path.getFileName().toString(), path); } } /** - * Sets the main.class entry for the manifest. A value of null - * (the default) will omit the entry. + * Sets the main.class entry for the manifest. A value of null (the default) will + * omit the entry. * * @param mainClass the fully qualified name of the main class */ @@ -119,10 +188,14 @@ public void setMainClass(String mainClass) { this.mainClass = mainClass; } + public void setJarOwner(String targetLabel, String injectingRuleKind) { + this.targetLabel = targetLabel; + this.injectingRuleKind = injectingRuleKind; + } + /** - * Sets filename for the manifest content. If this is set the manifest will be - * read from this file otherwise the manifest content will get generated on - * the fly. + * Sets filename for the manifest content. If this is set the manifest will be read from this file + * otherwise the manifest content will get generated on the fly. * * @param manifestFile the filename of the manifest file. */ @@ -131,22 +204,31 @@ public void setManifestFile(String manifestFile) { } private byte[] manifestContent() throws IOException { - Manifest manifest; if (manifestFile != null) { - FileInputStream in = new FileInputStream(manifestFile); - manifest = new Manifest(in); + try (FileInputStream in = new FileInputStream(manifestFile)) { + return manifestContentImpl(new Manifest(in)); + } } else { - manifest = new Manifest(); + return manifestContentImpl(new Manifest()); } + } + + private byte[] manifestContentImpl(Manifest manifest) throws IOException { Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); Attributes.Name createdBy = new Attributes.Name("Created-By"); if (attributes.getValue(createdBy) == null) { - attributes.put(createdBy, "blaze"); + attributes.put(createdBy, "bazel"); } if (mainClass != null) { attributes.put(Attributes.Name.MAIN_CLASS, mainClass); } + if (targetLabel != null) { + attributes.put(JarHelper.TARGET_LABEL, targetLabel); + } + if (injectingRuleKind != null) { + attributes.put(JarHelper.INJECTING_RULE_KIND, injectingRuleKind); + } ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); return out.toByteArray(); @@ -155,34 +237,22 @@ private byte[] manifestContent() throws IOException { /** * Executes the creation of the Jar file. * - * @throws IOException if the Jar cannot be written or any of the entries - * cannot be read. + * @throws IOException if the Jar cannot be written or any of the entries cannot be read. */ public void execute() throws IOException { - out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jarFile))); + try (OutputStream os = Files.newOutputStream(jarPath); + BufferedOutputStream bos = new BufferedOutputStream(os); + JarOutputStream out = new JarOutputStream(bos)) { - // Create the manifest entry in the Jar file - writeManifestEntry(manifestContent()); - try { - for (Map.Entry entry : jarEntries.entrySet()) { - copyEntry(entry.getKey(), new File(entry.getValue())); + // Create the manifest entry in the Jar file + writeManifestEntry(out, manifestContent()); + + for (Map.Entry entry : jarEntries.entrySet()) { + copyEntry(out, entry.getKey(), entry.getValue()); } - } finally { - out.closeEntry(); - out.close(); } } - @Override - protected boolean ignoreFileName(String name) { - /* - * It does not make sense to copy signature files - * into a fat jar because the jar signature will - * be broken - */ - return (name.endsWith(".DSA") || name.endsWith(".RSA")); - } - public static void buildJar(String[] args) throws IOException { if (args.length < 1) { System.err.println("usage: CreateJar [-m manifest] output [root directories]"); @@ -200,7 +270,7 @@ public static void buildJar(String[] args) throws IOException { createJar.setManifestFile(manifestFile); for (int i = (idx+1); i < args.length; i++) { String thisName = args[i]; - File f = new File(thisName); + Path f = Paths.get(thisName); if (JarHelper.isJar(f)) { createJar.addJar(f); } @@ -208,19 +278,21 @@ public static void buildJar(String[] args) throws IOException { createJar.addDirectory(f); } } + createJar.setNormalize(true); createJar.setCompression(true); createJar.execute(); } - /** - * A simple way to create Jar file using the JarCreator class. - */ + /** A simple way to create Jar file using the JarCreator class. */ public static void main(String[] args) { + long start = System.currentTimeMillis(); try { buildJar(args); - } catch (Throwable e) { + } catch (IOException e) { e.printStackTrace(); System.exit(1); } + long stop = System.currentTimeMillis(); + System.err.println((stop - start) + "ms."); } -} +} \ No newline at end of file diff --git a/src/java/io/bazel/rulesscala/jar/JarHelper.java b/src/java/io/bazel/rulesscala/jar/JarHelper.java index d576df8a0..abea4cd9e 100644 --- a/src/java/io/bazel/rulesscala/jar/JarHelper.java +++ b/src/java/io/bazel/rulesscala/jar/JarHelper.java @@ -14,26 +14,25 @@ package io.bazel.rulesscala.jar; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; -import java.util.Enumeration; +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.HashSet; import java.util.Set; +import java.util.jar.Attributes; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.zip.CRC32; -import java.util.zip.ZipException; /** * A simple helper class for creating Jar files. All Jar entries are sorted alphabetically. Allows * normalization of Jar entries by setting the timestamp of non-.class files to the DOS epoch. * Timestamps of .class files are set to the DOS epoch + 2 seconds (The zip timestamp granularity) - * Adjusting the timestamp for .class files is neccessary since otherwise javac will recompile java + * Adjusting the timestamp for .class files is necessary since otherwise javac will recompile java * files if both the java file and its .class file are present. */ public class JarHelper { @@ -42,14 +41,26 @@ public class JarHelper { public static final String MANIFEST_NAME = JarFile.MANIFEST_NAME; public static final String SERVICES_DIR = "META-INF/services/"; + /** Normalize timestamps. */ + public static final long DEFAULT_TIMESTAMP = + LocalDateTime.of(2010, 1, 1, 0, 0, 0) + .atZone(ZoneId.systemDefault()) + .toInstant() + .toEpochMilli(); + // These attributes are used by JavaBuilder, Turbine, and ijar. + // They must all be kept in sync. + public static final Attributes.Name TARGET_LABEL = new Attributes.Name("Target-Label"); + public static final Attributes.Name INJECTING_RULE_KIND = + new Attributes.Name("Injecting-Rule-Kind"); + public static final long DOS_EPOCH_IN_JAVA_TIME = 315561600000L; // ZIP timestamps have a resolution of 2 seconds. // see http://www.info-zip.org/FAQ.html#limits public static final long MINIMUM_TIMESTAMP_INCREMENT = 2000L; - // The name of the Jar file we want to create - protected final String jarFile; + // The path to the Jar we want to create + protected final Path jarPath; // The properties to describe how to create the Jar protected boolean normalize = true; @@ -58,21 +69,19 @@ public class JarHelper { // The state needed to create the Jar protected final Set names = new HashSet<>(); - protected JarOutputStream out; - public JarHelper(String filename) { - jarFile = filename; + public JarHelper(Path path) { + jarPath = path; } - public static boolean isJar(File file) { - return file.getName().endsWith(".jar") && (file.isFile()); + public static boolean isJar(Path path) { + return path.getFileName().endsWith(".jar") && (Files.isRegularFile(path)); } /** * Enables or disables the Jar entry normalization. * - * @param normalize If true the timestamps of Jar entries will be set to the - * DOS epoch. + * @param normalize If true the timestamps of Jar entries will be set to the DOS epoch. */ public void setNormalize(boolean normalize) { this.normalize = normalize; @@ -97,27 +106,26 @@ public void setVerbose(boolean verbose) { } /** - * Returns the normalized timestamp for a jar entry based on its name. - * This is necessary since javac will, when loading a class X, prefer a - * source file to a class file, if both files have the same timestamp. - * Therefore, we need to adjust the timestamp for class files to slightly + * Returns the normalized timestamp for a jar entry based on its name. This is necessary since + * javac will, when loading a class X, prefer a source file to a class file, if both files have + * the same timestamp. Therefore, we need to adjust the timestamp for class files to slightly * after the normalized time. - * @param name The name of the file for which we should return the - * normalized timestamp. + * + * @param name The name of the file for which we should return the normalized timestamp. * @return the time for a new Jar file entry in milliseconds since the epoch. */ private long normalizedTimestamp(String name) { if (name.endsWith(".class")) { - return DOS_EPOCH_IN_JAVA_TIME + MINIMUM_TIMESTAMP_INCREMENT; + return DEFAULT_TIMESTAMP + MINIMUM_TIMESTAMP_INCREMENT; } else { - return DOS_EPOCH_IN_JAVA_TIME; + return DEFAULT_TIMESTAMP; } } /** - * Returns the time for a new Jar file entry in milliseconds since the epoch. - * Uses {@link JarCreator#DOS_EPOCH_IN_JAVA_TIME} for normalized entries, - * {@link System#currentTimeMillis()} otherwise. + * Returns the time for a new Jar file entry in milliseconds since the epoch. Uses {@link + * JarCreator#DEFAULT_TIMESTAMP} for normalized entries, {@link System#currentTimeMillis()} + * otherwise. * * @param filename The name of the file for which we are entering the time * @return the time for a new Jar file entry in milliseconds since the epoch. @@ -127,8 +135,8 @@ protected long newEntryTimeMillis(String filename) { } /** - * Writes an entry with specific contents to the jar. Directory entries must - * include the trailing '/'. + * Writes an entry with specific contents to the jar. Directory entries must include the trailing + * '/'. */ protected void writeEntry(JarOutputStream out, String name, byte[] content) throws IOException { if (names.add(name)) { @@ -156,13 +164,13 @@ protected void writeEntry(JarOutputStream out, String name, byte[] content) thro } /** - * Writes a standard Java manifest entry into the JarOutputStream. This - * includes the directory entry for the "META-INF" directory + * Writes a standard Java manifest entry into the JarOutputStream. This includes the directory + * entry for the "META-INF" directory * * @param content the Manifest content to write to the manifest entry. * @throws IOException */ - protected void writeManifestEntry(byte[] content) throws IOException { + protected void writeManifestEntry(JarOutputStream out, byte[] content) throws IOException { int oldStorageMethod = storageMethod; // Do not compress small manifest files, the compressed one is frequently // larger than the original. The threshold of 256 bytes is somewhat arbitrary. @@ -170,98 +178,61 @@ protected void writeManifestEntry(byte[] content) throws IOException { storageMethod = JarEntry.STORED; } try { - writeEntry(out, MANIFEST_DIR, new byte[]{}); + writeEntry(out, MANIFEST_DIR, new byte[] {}); writeEntry(out, MANIFEST_NAME, content); } finally { storageMethod = oldStorageMethod; } } - protected boolean ignoreFileName(String name) { - return false; - } - - /** - * This copies the contents of jarFile into out - * This is a static method to make it clear what is mutated (and it - * was written by someone who really likes to minimize state changes). - */ - private void copyJar(JarFile nameJf, Set names, JarOutputStream out) throws IOException { - byte[] buffer = new byte[2048]; - for (Enumeration e = nameJf.entries(); e.hasMoreElements();) { - JarEntry existing = e.nextElement(); - String name = existing.getName(); - if (!(ignoreFileName(name) || names.contains(name))) { - JarEntry outEntry = new JarEntry(name); - outEntry.setTime(existing.getTime()); - outEntry.setSize(existing.getSize()); - out.putNextEntry(outEntry); - InputStream in = nameJf.getInputStream(existing); - while (0 < in.available()) { - int read = in.read(buffer); - out.write(buffer, 0, read); - } - in.close(); - out.closeEntry(); - names.add(name); - } - } - } - /** - * Copies file or directory entries from the file system into the jar. - * Directory entries will be detected and their names automatically '/' - * suffixed. + * Copies file or directory entries from the file system into the jar. Directory entries will be + * detected and their names automatically '/' suffixed. */ - protected void copyEntry(String name, File file) throws IOException { + protected void copyEntry(JarOutputStream out, String name, Path path) throws IOException { if (!names.contains(name)) { - if (!file.exists()) { - throw new FileNotFoundException(file.getAbsolutePath() + " (No such file or directory)"); + if (!Files.exists(path)) { + throw new FileNotFoundException(path.toAbsolutePath() + " (No such file or directory)"); } - boolean isDirectory = file.isDirectory(); + boolean isDirectory = Files.isDirectory(path); if (isDirectory && !name.endsWith("/")) { - name = name + '/'; // always normalize directory names before checking set + name = name + '/'; // always normalize directory names before checking set } if (names.add(name)) { if (verbose) { - System.err.println("adding " + file); + System.err.println("adding " + path); } // Create a new entry - if (JarHelper.isJar(file)) { - JarFile nameJf = new JarFile(file); - copyJar(nameJf, names, out); - } - else { - long size = isDirectory ? 0 : file.length(); - JarEntry outEntry = new JarEntry(name); - long newtime = normalize ? normalizedTimestamp(name) : file.lastModified(); - outEntry.setTime(newtime); - outEntry.setSize(size); - if (size == 0L) { - outEntry.setMethod(JarEntry.STORED); - outEntry.setCrc(0); + long size = isDirectory ? 0 : Files.size(path); + JarEntry outEntry = new JarEntry(name); + long newtime = + normalize ? normalizedTimestamp(name) : Files.getLastModifiedTime(path).toMillis(); + outEntry.setTime(newtime); + outEntry.setSize(size); + if (size == 0L) { + outEntry.setMethod(JarEntry.STORED); + outEntry.setCrc(0); + out.putNextEntry(outEntry); + } else { + outEntry.setMethod(storageMethod); + if (storageMethod == JarEntry.STORED) { + // ZipFile requires us to calculate the CRC-32 for any STORED entry. + // It would be nicer to do this via DigestInputStream, but + // the architecture of ZipOutputStream requires us to know the CRC-32 + // before we write the data to the stream. + byte[] bytes = Files.readAllBytes(path); + CRC32 crc = new CRC32(); + crc.update(bytes); + outEntry.setCrc(crc.getValue()); out.putNextEntry(outEntry); + out.write(bytes); } else { - outEntry.setMethod(storageMethod); - if (storageMethod == JarEntry.STORED) { - outEntry.setCrc(hashFile(file)); - } out.putNextEntry(outEntry); - Files.copy(file.toPath(), out); + Files.copy(path, out); } - out.closeEntry(); } + out.closeEntry(); } } } - protected long hashFile(File f) throws IOException { - FileInputStream fis = new FileInputStream(f); - CRC32 crc = new CRC32(); - byte[] buffer = new byte[65536]; - int bytesRead; - while((bytesRead = fis.read(buffer)) != -1) { - crc.update(buffer, 0, bytesRead); - } - return crc.getValue(); - } -} +} \ No newline at end of file diff --git a/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java b/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java index d5693a8f4..d25423b7f 100644 --- a/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java +++ b/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java @@ -90,7 +90,7 @@ public void processRequest(List args) throws Exception { outputPath.toString(), tmpPath.toString() }; - JarCreator.buildJar(jarCreatorArgs); + JarCreator.main(jarCreatorArgs); /** * Now build the output ijar From f105ef7e0eb00ae4b4a3fca372dc10c30514c3bb Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 24 Apr 2018 21:18:16 -0700 Subject: [PATCH 07/29] Remove an unused helper function (#485) The only use was removed in 0688fa109811d0ba42483b97c28f4f038d9b92c8. --- scala/scala_import.bzl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scala/scala_import.bzl b/scala/scala_import.bzl index 03d4b4e83..67727509b 100644 --- a/scala/scala_import.bzl +++ b/scala/scala_import.bzl @@ -101,15 +101,6 @@ def _collect_runtime(runtime_deps): return depset(transitive = jar_deps) -def _collect_exports(exports): - exported_jars = depset() - - for dep_target in exports: - java_provider = dep_target[java_common.provider] - exported_jars += java_provider.full_compile_jars - - return exported_jars - scala_import = rule( implementation=_scala_import_impl, attrs={ From 357e3d10f6756f0510e4bd822bdbd0436955093d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Sat, 28 Apr 2018 22:34:11 -0700 Subject: [PATCH 08/29] Split core rules into public API file and private implementation files (#482) * Split core rules into public API file and private implementation files * Remove unused method * Move create_scala_provider to a new public providers.bzl file --- WORKSPACE | 6 +- scala/private/BUILD | 0 scala/private/common.bzl | 141 +++++ scala/private/rule_impls.bzl | 747 ++++++++++++++++++++++ scala/providers.bzl | 32 + scala/scala.bzl | 948 +--------------------------- scala_proto/scala_proto.bzl | 15 +- twitter_scrooge/twitter_scrooge.bzl | 13 +- 8 files changed, 966 insertions(+), 936 deletions(-) create mode 100644 scala/private/BUILD create mode 100644 scala/private/common.bzl create mode 100644 scala/private/rule_impls.bzl create mode 100644 scala/providers.bzl diff --git a/WORKSPACE b/WORKSPACE index 26babf825..cbe5b3eeb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,7 +2,7 @@ workspace(name = "io_bazel_rules_scala") -load("//scala:scala.bzl", "scala_repositories", "scala_mvn_artifact") +load("//scala:scala.bzl", "scala_repositories") scala_repositories() load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge", "scrooge_scala_library") @@ -20,6 +20,8 @@ scala_proto_repositories() load("//specs2:specs2_junit.bzl","specs2_junit_repositories") specs2_junit_repositories() +load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") + # test adding a scala jar: maven_jar( name = "com_twitter__scalding_date", @@ -103,4 +105,4 @@ java_import_external( licenses = ["notice"], # Apache 2.0 jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"], jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c", -) \ No newline at end of file +) diff --git a/scala/private/BUILD b/scala/private/BUILD new file mode 100644 index 000000000..e69de29bb diff --git a/scala/private/common.bzl b/scala/private/common.bzl new file mode 100644 index 000000000..493071cd5 --- /dev/null +++ b/scala/private/common.bzl @@ -0,0 +1,141 @@ +def write_manifest(ctx): + # TODO(bazel-team): I don't think this classpath is what you want + manifest = "Class-Path: \n" + if getattr(ctx.attr, "main_class", ""): + manifest += "Main-Class: %s\n" % ctx.attr.main_class + + ctx.actions.write( + output=ctx.outputs.manifest, + content=manifest) + +def collect_srcjars(targets): + srcjars = [] + for target in targets: + if hasattr(target, "srcjars"): + srcjars.append(target.srcjars.srcjar) + return depset(srcjars) + +def collect_jars(dep_targets, dependency_analyzer_is_off = True): + """Compute the runtime and compile-time dependencies from the given targets""" # noqa + + if dependency_analyzer_is_off: + return _collect_jars_when_dependency_analyzer_is_off(dep_targets) + else: + return _collect_jars_when_dependency_analyzer_is_on(dep_targets) + +def _collect_jars_when_dependency_analyzer_is_off(dep_targets): + compile_jars = [] + runtime_jars = [] + + for dep_target in dep_targets: + if java_common.provider in dep_target: + java_provider = dep_target[java_common.provider] + compile_jars.append(java_provider.compile_jars) + runtime_jars.append(java_provider.transitive_runtime_jars) + else: + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + compile_jars.append(filter_not_sources(dep_target.files)) + runtime_jars.append(filter_not_sources(dep_target.files)) + + return struct(compile_jars = depset(transitive = compile_jars), + transitive_runtime_jars = depset(transitive = runtime_jars), + jars2labels = {}, + transitive_compile_jars = depset()) + +def _collect_jars_when_dependency_analyzer_is_on(dep_targets): + transitive_compile_jars = [] + jars2labels = {} + compile_jars = [] + runtime_jars = [] + + for dep_target in dep_targets: + current_dep_compile_jars = None + current_dep_transitive_compile_jars = None + + if java_common.provider in dep_target: + java_provider = dep_target[java_common.provider] + current_dep_compile_jars = java_provider.compile_jars + current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars + runtime_jars.append(java_provider.transitive_runtime_jars) + else: + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + current_dep_compile_jars = filter_not_sources(dep_target.files) + current_dep_transitive_compile_jars = filter_not_sources(dep_target.files) + runtime_jars.append(filter_not_sources(dep_target.files)) + + compile_jars.append(current_dep_compile_jars) + transitive_compile_jars.append(current_dep_transitive_compile_jars) + add_labels_of_jars_to(jars2labels, dep_target, current_dep_transitive_compile_jars.to_list(), current_dep_compile_jars.to_list()) + + return struct(compile_jars = depset(transitive = compile_jars), + transitive_runtime_jars = depset(transitive = runtime_jars), + jars2labels = jars2labels, + transitive_compile_jars = depset(transitive = transitive_compile_jars)) + +# When import mavan_jar's for scala macros we have to use the jar:file requirement +# since bazel 0.6.0 this brings in the source jar too +# the scala compiler thinks a source jar can look like a package space +# causing a conflict between objects and packages warning +# error: package cats contains object and package with same name: implicits +# one of them needs to be removed from classpath +# import cats.implicits._ + +def not_sources_jar(name): + return "-sources.jar" not in name + +def filter_not_sources(deps): + return depset([dep for dep in deps.to_list() if not_sources_jar(dep.basename) ]) + +def add_labels_of_jars_to(jars2labels, dependency, all_jars, direct_jars): + for jar in direct_jars: + _add_label_of_direct_jar_to(jars2labels, dependency, jar) + for jar in all_jars: + _add_label_of_indirect_jar_to(jars2labels, dependency, jar) + +def _add_label_of_direct_jar_to(jars2labels, dependency, jar): + jars2labels[jar.path] = dependency.label + +def _add_label_of_indirect_jar_to(jars2labels, dependency, jar): + if _label_already_exists(jars2labels, jar): + return + + # skylark exposes only labels of direct dependencies. + # to get labels of indirect dependencies we collect them from the providers transitively + if _provider_of_dependency_contains_label_of(dependency, jar): + jars2labels[jar.path] = dependency.jars_to_labels[jar.path] + else: + jars2labels[jar.path] = "Unknown label of file {jar_path} which came from {dependency_label}".format( + jar_path = jar.path, + dependency_label = dependency.label + ) + +def _label_already_exists(jars2labels, jar): + return jar.path in jars2labels + +def _provider_of_dependency_contains_label_of(dependency, jar): + return hasattr(dependency, "jars_to_labels") and jar.path in dependency.jars_to_labels + +def create_java_provider(scalaattr, transitive_compile_time_jars): + # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java + # toolchain. Fortunately, the same change that added this requirement also + # added this field to the Java provider so we can use it to test which + # Bazel version we are running under. + test_provider = java_common.create_provider() + + if hasattr(test_provider, "full_compile_jars"): + return java_common.create_provider( + use_ijar = False, + compile_time_jars = scalaattr.compile_jars, + runtime_jars = scalaattr.transitive_runtime_jars, + transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), + transitive_runtime_jars = scalaattr.transitive_runtime_jars, + ) + else: + return java_common.create_provider( + compile_time_jars = scalaattr.compile_jars, + runtime_jars = scalaattr.transitive_runtime_jars, + transitive_compile_time_jars = transitive_compile_time_jars, + transitive_runtime_jars = scalaattr.transitive_runtime_jars, + ) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl new file mode 100644 index 000000000..d8df45262 --- /dev/null +++ b/scala/private/rule_impls.bzl @@ -0,0 +1,747 @@ +# 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. + +"""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(":common.bzl", + "add_labels_of_jars_to", + "create_java_provider", + "collect_jars", + "collect_srcjars", + "filter_not_sources", + "not_sources_jar", + "write_manifest", +) + +_jar_filetype = FileType([".jar"]) +_java_filetype = FileType([".java"]) +_scala_filetype = FileType([".scala"]) +_srcjar_filetype = FileType([".srcjar"]) + +def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix): + if not path.startswith(resource_strip_prefix): + fail("Resource file %s is not under the specified prefix to strip" % path) + + clean_path = path[len(resource_strip_prefix):] + return resource_strip_prefix, clean_path + +def _adjust_resources_path_by_default_prefixes(path): + # Here we are looking to find out the offset of this resource inside + # any resources folder. We want to return the root to the resources folder + # and then the sub path inside it + dir_1, dir_2, rel_path = path.partition("resources") + if rel_path: + return dir_1 + dir_2, rel_path + + # The same as the above but just looking for java + (dir_1, dir_2, rel_path) = path.partition("java") + if rel_path: + return dir_1 + dir_2, rel_path + + return "", path + +def _adjust_resources_path(path, resource_strip_prefix): + if resource_strip_prefix: + return _adjust_resources_path_by_strip_prefix(path,resource_strip_prefix) + else: + return _adjust_resources_path_by_default_prefixes(path) + +def _add_resources_cmd(ctx): + res_cmd = [] + for f in ctx.files.resources: + c_dir, res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix) + target_path = res_path + if target_path[0] == "/": + target_path = target_path[1:] + line = "{target_path}={c_dir}{res_path}\n".format( + res_path=res_path, + target_path=target_path, + c_dir=c_dir) + res_cmd.extend([line]) + return "".join(res_cmd) + +def _build_nosrc_jar(ctx, buildijar): + resources = _add_resources_cmd(ctx) + ijar_cmd = "" + if buildijar: + ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format( + jar_output=ctx.outputs.jar.path, + ijar_output=ctx.outputs.ijar.path) + + # this ensures the file is not empty + resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path + + zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name) + ctx.actions.write(zipper_arg_path, resources) + cmd = """ +rm -f {jar_output} +{zipper} c {jar_output} @{path} +# ensures that empty src targets still emit a statsfile +touch {statsfile} +""" + ijar_cmd + + cmd = cmd.format( + path = zipper_arg_path.path, + jar_output=ctx.outputs.jar.path, + zipper=ctx.executable._zipper.path, + statsfile=ctx.outputs.statsfile.path, + ) + + outs = [ctx.outputs.jar, ctx.outputs.statsfile] + if buildijar: + outs.extend([ctx.outputs.ijar]) + + inputs = ctx.files.resources + [ + ctx.outputs.manifest, + ctx.executable._zipper, + zipper_arg_path + ] + + ctx.actions.run_shell( + inputs=inputs, + outputs=outs, + command=cmd, + progress_message="scala %s" % ctx.label, + arguments=[]) + + +def _collect_plugin_paths(plugins): + paths = [] + for p in plugins: + if hasattr(p, "path"): + paths.append(p) + elif hasattr(p, "scala"): + paths.append(p.scala.outputs.jar) + elif hasattr(p, "java"): + paths.extend([j.class_jar for j in p.java.outputs.jars]) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + elif hasattr(p, "files"): + paths.extend([f for f in p.files if not_sources_jar(f.basename)]) + return depset(paths) + + +def _expand_location(ctx, flags): + return [ctx.expand_location(f, ctx.attr.data) for f in flags] + +def _join_path(args, sep=","): + return sep.join([f.path for f in args]) + +def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels, implicit_junit_deps_needed_for_java_compilation): + ijar_output_path = "" + ijar_cmd_path = "" + if buildijar: + ijar_output_path = ctx.outputs.ijar.path + ijar_cmd_path = ctx.executable._ijar.path + + java_srcs = _java_filetype.filter(ctx.files.srcs) + sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs + srcjars = _srcjar_filetype.filter(ctx.files.srcs) + all_srcjars = depset(srcjars, transitive = [dep_srcjars]) + # look for any plugins: + plugins = _collect_plugin_paths(ctx.attr.plugins) + dependency_analyzer_plugin_jars = [] + dependency_analyzer_mode = "off" + compiler_classpath_jars = cjars + optional_scalac_args = "" + classpath_resources = [] + if (hasattr(ctx.files, "classpath_resources")): + classpath_resources = ctx.files.classpath_resources + + if is_dependency_analyzer_on(ctx): + # "off" mode is used as a feature toggle, that preserves original behaviour + dependency_analyzer_mode = ctx.fragments.java.strict_java_deps + dep_plugin = ctx.attr._dependency_analyzer_plugin + plugins = depset(transitive = [plugins, dep_plugin.files]) + dependency_analyzer_plugin_jars = ctx.files._dependency_analyzer_plugin + compiler_classpath_jars = transitive_compile_jars + + direct_jars = _join_path(cjars.to_list()) + transitive_cjars_list = transitive_compile_jars.to_list() + indirect_jars = _join_path(transitive_cjars_list) + indirect_targets = ",".join([labels[j.path] for j in transitive_cjars_list]) + current_target = str(ctx.label) + + optional_scalac_args = """ +DirectJars: {direct_jars} +IndirectJars: {indirect_jars} +IndirectTargets: {indirect_targets} +CurrentTarget: {current_target} + """.format( + direct_jars=direct_jars, + indirect_jars=indirect_jars, + indirect_targets=indirect_targets, + current_target = current_target + ) + + plugin_arg = _join_path(plugins.to_list()) + + separator = ctx.configuration.host_path_separator + compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) + + toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type'] + scalacopts = toolchain.scalacopts + ctx.attr.scalacopts + + scalac_args = """ +Classpath: {cp} +ClasspathResourceSrcs: {classpath_resource_src} +EnableIjar: {enableijar} +Files: {files} +IjarCmdPath: {ijar_cmd_path} +IjarOutput: {ijar_out} +JarOutput: {out} +JavaFiles: {java_files} +Manifest: {manifest} +Plugins: {plugin_arg} +PrintCompileTime: {print_compile_time} +ResourceDests: {resource_dest} +ResourceJars: {resource_jars} +ResourceSrcs: {resource_src} +ResourceShortPaths: {resource_short_paths} +ResourceStripPrefix: {resource_strip_prefix} +ScalacOpts: {scala_opts} +SourceJars: {srcjars} +DependencyAnalyzerMode: {dependency_analyzer_mode} +StatsfileOutput: {statsfile_output} +""".format( + out=ctx.outputs.jar.path, + manifest=ctx.outputs.manifest.path, + scala_opts=",".join(scalacopts), + print_compile_time=ctx.attr.print_compile_time, + plugin_arg=plugin_arg, + cp=compiler_classpath, + classpath_resource_src=_join_path(classpath_resources), + files=_join_path(sources), + enableijar=buildijar, + ijar_out=ijar_output_path, + ijar_cmd_path=ijar_cmd_path, + srcjars=_join_path(all_srcjars.to_list()), + java_files=_join_path(java_srcs), + # the resource paths need to be aligned in order + resource_src=",".join([f.path for f in ctx.files.resources]), + resource_short_paths=",".join([f.short_path for f in ctx.files.resources]), + resource_dest=",".join( + [_adjust_resources_path_by_default_prefixes(f.short_path)[1] for f in ctx.files.resources] + ), + resource_strip_prefix=ctx.attr.resource_strip_prefix, + resource_jars=_join_path(ctx.files.resource_jars), + dependency_analyzer_mode = dependency_analyzer_mode, + statsfile_output = ctx.outputs.statsfile.path + ) + argfile = ctx.actions.declare_file( + "%s_worker_input" % ctx.label.name, + sibling = ctx.outputs.jar + ) + + ctx.actions.write(output=argfile, content=scalac_args + optional_scalac_args) + + outs = [ctx.outputs.jar, ctx.outputs.statsfile] + if buildijar: + outs.extend([ctx.outputs.ijar]) + ins = (compiler_classpath_jars.to_list() + + dep_srcjars.to_list() + + list(srcjars) + + list(sources) + + ctx.files.srcs + + ctx.files.plugins + + dependency_analyzer_plugin_jars + + classpath_resources + + ctx.files.resources + + ctx.files.resource_jars + + ctx.files._java_runtime + + [ctx.outputs.manifest, + ctx.executable._ijar, + argfile]) + ctx.actions.run( + inputs=ins, + outputs=outs, + executable=ctx.executable._scalac, + mnemonic="Scalac", + progress_message="scala %s" % ctx.label, + execution_requirements={"supports-workers": "1"}, + # when we run with a worker, the `@argfile.path` is removed and passed + # line by line as arguments in the protobuf. In that case, + # the rest of the arguments are passed to the process that + # starts up and stays resident. + + # In either case (worker or not), they will be jvm flags which will + # be correctly handled since the executable is a jvm app that will + # consume the flags on startup. + + arguments=["--jvm_flag=%s" % f for f in _expand_location(ctx, ctx.attr.scalac_jvm_flags)] + ["@" + argfile.path], + ) + + if buildijar: + scala_output = ctx.outputs.ijar + else: + scala_output = ctx.outputs.jar + java_jar = try_to_compile_java_jar(ctx, + scala_output, + all_srcjars, + java_srcs, + implicit_junit_deps_needed_for_java_compilation) + return java_jar + + +def _interim_java_provider_for_java_compilation(scala_output): + # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java + # toolchain. Fortunately, the same change that added this requirement also + # added this field to the Java provider so we can use it to test which + # Bazel version we are running under. + test_provider = java_common.create_provider() + if hasattr(test_provider, "full_compile_jars"): + return java_common.create_provider( + use_ijar = False, + compile_time_jars = [scala_output], + runtime_jars = [], + ) + else: + return java_common.create_provider( + compile_time_jars = [scala_output], + runtime_jars = [], + ) + +def try_to_compile_java_jar(ctx, + scala_output, + all_srcjars, + java_srcs, + implicit_junit_deps_needed_for_java_compilation): + if not java_srcs and not all_srcjars: + return False + + providers_of_dependencies = collect_java_providers_of(ctx.attr.deps) + providers_of_dependencies += collect_java_providers_of(implicit_junit_deps_needed_for_java_compilation) + scala_sources_java_provider = _interim_java_provider_for_java_compilation(scala_output) + providers_of_dependencies += [scala_sources_java_provider] + + full_java_jar = ctx.actions.declare_file(ctx.label.name + "_java.jar") + + provider = java_common.compile( + ctx, + source_jars = all_srcjars.to_list(), + source_files = java_srcs, + output = full_java_jar, + javac_opts = _expand_location(ctx, ctx.attr.javacopts + ctx.attr.javac_jvm_flags + java_common.default_javac_opts(ctx, java_toolchain_attr = "_java_toolchain")), + deps = providers_of_dependencies, + #exports can be empty since the manually created provider exposes exports + #needs to be empty since we want the provider.compile_jars to only contain the sources ijar + #workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved + exports = [], + java_toolchain = ctx.attr._java_toolchain, + host_javabase = ctx.attr._host_javabase, + strict_deps = ctx.fragments.java.strict_java_deps, + ) + return struct(jar = full_java_jar, ijar = provider.compile_jars.to_list().pop()) + +def collect_java_providers_of(deps): + providers = [] + for dep in deps: + if java_common.provider in dep: + providers.append(dep[java_common.provider]) + return providers + +def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation): + # We assume that if a srcjar is present, it is not empty + if len(ctx.files.srcs) + len(srcjars.to_list()) == 0: + _build_nosrc_jar(ctx, buildijar) + # no need to build ijar when empty + return struct(ijar=ctx.outputs.jar, + class_jar=ctx.outputs.jar, + java_jar=False, + full_jars=[ctx.outputs.jar], + ijars=[ctx.outputs.jar]) + else: + java_jar = _compile(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) + ijar = None + if buildijar: + ijar = ctx.outputs.ijar + else: + # macro code needs to be available at compile-time, + # so set ijar == jar + ijar = ctx.outputs.jar + full_jars = [ctx.outputs.jar] + ijars = [ijar] + if java_jar: + full_jars += [java_jar.jar] + ijars += [java_jar.ijar] + return struct(ijar=ijar, + class_jar=ctx.outputs.jar, + java_jar=java_jar, + full_jars=full_jars, + ijars=ijars) + +def _build_deployable(ctx, jars_list): + # This calls bazels singlejar utility. + # For a full list of available command line options see: + # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 + args = ["--normalize", "--sources"] + args.extend([j.path for j in jars_list]) + if getattr(ctx.attr, "main_class", ""): + args.extend(["--main_class", ctx.attr.main_class]) + args.extend(["--output", ctx.outputs.deploy_jar.path]) + ctx.actions.run( + inputs=jars_list, + outputs=[ctx.outputs.deploy_jar], + executable=ctx.executable._singlejar, + mnemonic="ScalaDeployJar", + progress_message="scala deployable %s" % ctx.label, + arguments=args) + +def _path_is_absolute(path): + # Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e., + # 'X:\' or 'X:/' where 'X' is a letter), false otherwise. + if len(path) >= 1 and path[0] == "/": + return True + if len(path) >= 3 \ + and path[0].isalpha() \ + and path[1] == ":" \ + and (path[2] == "/" or path[2] == "\\"): + return True + + return False + +def _runfiles_root(ctx): + return "${TEST_SRCDIR}/%s" % ctx.workspace_name + +def _write_java_wrapper(ctx, args="", wrapper_preamble=""): + """This creates a wrapper that sets up the correct path + to stand in for the java command.""" + + java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_runfiles_path) + if _path_is_absolute(java_path): + javabin = java_path + else: + runfiles_root = _runfiles_root(ctx) + javabin = "%s/%s" % (runfiles_root, java_path) + + + exec_str = "" + if wrapper_preamble == "": + exec_str = "exec " + + wrapper = ctx.actions.declare_file(ctx.label.name + "_wrapper.sh") + ctx.actions.write( + output = wrapper, + content = """#!/bin/bash +{preamble} + +{exec_str}{javabin} "$@" {args} +""".format( + preamble=wrapper_preamble, + exec_str=exec_str, + javabin=javabin, + args=args, + ), + is_executable = True + ) + return wrapper + +def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper): + template = ctx.attr._java_stub_template.files.to_list()[0] + # RUNPATH is defined here: + # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227 + classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()]) + jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags]) + ctx.actions.expand_template( + template = template, + output = ctx.outputs.executable, + substitutions = { + "%classpath%": classpath, + "%java_start_class%": main_class, + "%javabin%": "JAVABIN=%s/%s" % (_runfiles_root(ctx), wrapper.short_path), + "%jvm_flags%": jvm_flags, + "%needs_runfiles%": "", + "%runfiles_manifest_only%": "", + "%set_jacoco_metadata%": "", + "%workspace_prefix%": ctx.workspace_name + "/", + }, + is_executable = True, + ) + +def _collect_runtime_jars(dep_targets): + runtime_jars = [] + + for dep_target in dep_targets: + if java_common.provider in dep_target: + runtime_jars.append(dep_target[java_common.provider].transitive_runtime_jars) + else: + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + runtime_jars.append(filter_not_sources(dep_target.files)) + + return runtime_jars + +def is_dependency_analyzer_on(ctx): + if (hasattr(ctx.attr,"_dependency_analyzer_plugin") + # when the strict deps FT is removed the "default" check + # will be removed since "default" will mean it's turned on + and ctx.fragments.java.strict_java_deps != "default" + and ctx.fragments.java.strict_java_deps != "off"): + return True + +def is_dependency_analyzer_off(ctx): + return not is_dependency_analyzer_on(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 = [], 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, dependency_analyzer_is_off) + (cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, deps_jars.jars2labels, deps_jars.transitive_compile_jars) + + transitive_rjars = depset(transitive = [transitive_rjars] + _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps)) + + return struct(compile_jars = cjars, transitive_runtime_jars = transitive_rjars, jars2labels=jars2labels, transitive_compile_jars = transitive_compile_jars) + +def _lib(ctx, 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) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + + write_manifest(ctx) + outputs = _compile_or_empty(ctx, cjars, srcjars, non_macro_lib, jars.transitive_compile_jars, jars.jars2labels, []) + + transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) + + _build_deployable(ctx, transitive_rjars.to_list()) + + # Using transitive_files since transitive_rjars a depset and avoiding linearization + runfiles = ctx.runfiles( + transitive_files = transitive_rjars, + collect_data = True, + ) + + # Add information from exports (is key that AFTER all build actions/runfiles analysis) + # Since after, will not show up in deploy_jar or old jars runfiles + # Notice that compile_jars is intentionally transitive for exports + exports_jars = collect_jars(ctx.attr.exports) + transitive_rjars = depset(transitive = [transitive_rjars, exports_jars.transitive_runtime_jars]) + + scalaattr = create_scala_provider( + ijar = outputs.ijar, + class_jar = outputs.class_jar, + compile_jars = depset(outputs.ijars, transitive = [exports_jars.compile_jars]), + transitive_runtime_jars = transitive_rjars, + deploy_jar = ctx.outputs.deploy_jar, + full_jars = outputs.full_jars, + statsfile = ctx.outputs.statsfile) + + java_provider = create_java_provider(scalaattr, jars.transitive_compile_jars) + + return struct( + files = depset([ctx.outputs.jar]), # Here is the default output + scala = scalaattr, + providers = [java_provider], + runfiles = runfiles, + # This is a free monoid given to the graph for the purpose of + # extensibility. This is necessary when one wants to create + # new targets which want to leverage a scala_library. For example, + # new_target1 -> scala_library -> new_target2. There might be + # information that new_target2 needs to get from new_target1, + # but we do not want to have to change scala_library to pass + # this information through. extra_information allows passing + # this information through, and it is up to the new_targets + # to filter and make sense of this information. + extra_information=_collect_extra_information(ctx.attr.deps), + jars_to_labels = jars.jars2labels, + ) + + +def _collect_extra_information(targets): + r = [] + for target in targets: + if hasattr(target, "extra_information"): + r.extend(target.extra_information) + return r + +def scala_library_impl(ctx): + return _lib(ctx, True) + +def scala_macro_library_impl(ctx): + return _lib(ctx, False) # don't build the ijar for macros + +# Common code shared by all scala binary implementations. +def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2labels, java_wrapper, implicit_junit_deps_needed_for_java_compilation = []): + write_manifest(ctx) + outputs = _compile_or_empty(ctx, cjars, depset(), False, transitive_compile_time_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) # no need to build an ijar for an executable + rjars = depset(outputs.full_jars, transitive = [rjars]) + + _build_deployable(ctx, rjars.to_list()) + + runfiles = ctx.runfiles( + transitive_files = depset([ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, transitive = [rjars]), + collect_data = True) + + scalaattr = create_scala_provider( + ijar = outputs.class_jar, # we aren't using ijar here + class_jar = outputs.class_jar, + compile_jars = depset(outputs.ijars), + transitive_runtime_jars = rjars, + deploy_jar = ctx.outputs.deploy_jar, + full_jars = outputs.full_jars, + statsfile = ctx.outputs.statsfile) + + java_provider = create_java_provider(scalaattr, transitive_compile_time_jars) + + return struct( + files=depset([ctx.outputs.executable]), + providers = [java_provider], + scala = scalaattr, + transitive_rjars = rjars, #calling rules need this for the classpath in the launcher + jars_to_labels = jars2labels, + runfiles=runfiles) + +def scala_binary_impl(ctx): + jars = _collect_jars_from_common_ctx(ctx) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + + wrapper = _write_java_wrapper(ctx, "", "") + out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = ctx.attr.main_class, + jvm_flags = ctx.attr.jvm_flags, + wrapper = wrapper + ) + return out + +def scala_repl_impl(ctx): + # need scala-compiler for MainGenericRunner below + jars = _collect_jars_from_common_ctx(ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + + args = " ".join(ctx.attr.scalacopts) + wrapper = _write_java_wrapper(ctx, args, wrapper_preamble = """ +# save stty like in bin/scala +saved_stty=$(stty -g 2>/dev/null) +if [[ ! $? ]]; then + saved_stty="" +fi +function finish() { + if [[ "$saved_stty" != "" ]]; then + stty $saved_stty + saved_stty="" + fi +} +trap finish EXIT +""") + + out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = "scala.tools.nsc.MainGenericRunner", + jvm_flags = ["-Dscala.usejavacp=true"] + ctx.attr.jvm_flags, + wrapper = wrapper + ) + + return out + +def _scala_test_flags(ctx): + # output report test duration + flags = "-oD" + if ctx.attr.full_stacktraces: + flags += "F" + else: + flags += "S" + if not ctx.attr.colors: + flags += "W" + return flags + +def scala_test_impl(ctx): + if len(ctx.attr.suites) != 0: + print( + "suites attribute is deprecated. All scalatest test suites are run" + ) + jars = _collect_jars_from_common_ctx(ctx, + extra_runtime_deps = [ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner], + ) + (cjars, transitive_rjars, transitive_compile_jars, jars_to_labels) = (jars.compile_jars, jars.transitive_runtime_jars, + jars.transitive_compile_jars, jars.jars2labels) + # _scalatest is an http_jar, so its compile jar is run through ijar + # however, contains macros, so need to handle separately + scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars + cjars = depset(transitive = [cjars, scalatest_jars]) + transitive_rjars = depset(transitive = [transitive_rjars, scalatest_jars]) + + if is_dependency_analyzer_on(ctx): + transitive_compile_jars = depset(transitive = [scalatest_jars, transitive_compile_jars]) + scalatest_jars_list = scalatest_jars.to_list() + add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, scalatest_jars_list, scalatest_jars_list) + + args = " ".join([ + "-R \"{path}\"".format(path=ctx.outputs.jar.short_path), + _scala_test_flags(ctx), + "-C io.bazel.rules.scala.JUnitXmlReporter ", + ]) + # main_class almost has to be "org.scalatest.tools.Runner" due to args.... + wrapper = _write_java_wrapper(ctx, args, "") + out = _scala_binary_common(ctx, cjars, transitive_rjars, transitive_compile_jars, jars_to_labels, wrapper) + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = ctx.attr.main_class, + jvm_flags = ctx.attr.jvm_flags, + wrapper = wrapper + ) + return out + +def _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, archives): + serialized_archives = _serialize_archives_short_path(archives) + return struct( + testSuiteFlag = "-Dbazel.test_suite=%s" % ctx.attr.suite_class, + archiveFlag = "-Dbazel.discover.classes.archives.file.paths=%s" % serialized_archives, + prefixesFlag = "-Dbazel.discover.classes.prefixes=%s" % ",".join(ctx.attr.prefixes), + suffixesFlag = "-Dbazel.discover.classes.suffixes=%s" % ",".join(ctx.attr.suffixes), + printFlag = "-Dbazel.discover.classes.print.discovered=%s" % ctx.attr.print_discovered_classes) + +def _serialize_archives_short_path(archives): + archives_short_path = "" + for archive in archives: archives_short_path += archive.class_jar.short_path + "," + return archives_short_path[:-1] #remove redundant comma + +def scala_junit_test_impl(ctx): + if (not(ctx.attr.prefixes) and not(ctx.attr.suffixes)): + fail("Setting at least one of the attributes ('prefixes','suffixes') is required") + jars = _collect_jars_from_common_ctx(ctx, + extra_deps = [ctx.attr._junit, ctx.attr._hamcrest, ctx.attr.suite_label, ctx.attr._bazel_test_runner], + ) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + implicit_junit_deps_needed_for_java_compilation = [ctx.attr._junit, ctx.attr._hamcrest] + + wrapper = _write_java_wrapper(ctx, "", "") + out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper, implicit_junit_deps_needed_for_java_compilation) + test_suite = _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, out.scala.outputs.jars) + launcherJvmFlags = ["-ea", test_suite.archiveFlag, test_suite.prefixesFlag, test_suite.suffixesFlag, test_suite.printFlag, test_suite.testSuiteFlag] + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = "com.google.testing.junit.runner.BazelTestRunner", + jvm_flags = launcherJvmFlags + ctx.attr.jvm_flags, + wrapper = wrapper + ) + + return out + diff --git a/scala/providers.bzl b/scala/providers.bzl new file mode 100644 index 000000000..f275d5ef2 --- /dev/null +++ b/scala/providers.bzl @@ -0,0 +1,32 @@ +# TODO: this should really be a bazel provider, but we are using old-style rule outputs +# we need to document better what the intellij dependencies on this code actually are +def create_scala_provider( + ijar, + class_jar, + compile_jars, + transitive_runtime_jars, + deploy_jar, + full_jars, + statsfile): + + formatted_for_intellij = [struct( + class_jar = jar, + ijar = None, + source_jar = None, + source_jars = []) for jar in full_jars] + + rule_outputs = struct( + ijar = ijar, + class_jar = class_jar, + deploy_jar = deploy_jar, + jars = formatted_for_intellij, + statsfile = statsfile, + ) + # Note that, internally, rules only care about compile_jars and transitive_runtime_jars + # in a similar manner as the java_library and JavaProvider + return struct( + outputs = rule_outputs, + compile_jars = compile_jars, + transitive_runtime_jars = transitive_runtime_jars, + transitive_exports = [] #needed by intellij plugin + ) diff --git a/scala/scala.bzl b/scala/scala.bzl index c27342d9c..1e1059463 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -1,924 +1,18 @@ -# 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. - -"""Rules for supporting the Scala language.""" +load("@io_bazel_rules_scala//scala/private:rule_impls.bzl", + "scala_library_impl", + "scala_macro_library_impl", + "scala_binary_impl", + "scala_test_impl", + "scala_repl_impl", + "scala_junit_test_impl", +) -load("//specs2:specs2_junit.bzl", "specs2_junit_dependencies") -load(":scala_cross_version.bzl", "scala_version", "scala_mvn_artifact") -load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain") +load( + "@io_bazel_rules_scala//specs2:specs2_junit.bzl", + "specs2_junit_dependencies" +) _jar_filetype = FileType([".jar"]) -_java_filetype = FileType([".java"]) -_scala_filetype = FileType([".scala"]) -_srcjar_filetype = FileType([".srcjar"]) -# TODO is there a way to derive this from the above? -_scala_srcjar_filetype = FileType([".scala", ".srcjar", ".java"]) - -def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix): - if not path.startswith(resource_strip_prefix): - fail("Resource file %s is not under the specified prefix to strip" % path) - - clean_path = path[len(resource_strip_prefix):] - return resource_strip_prefix, clean_path - -def _adjust_resources_path_by_default_prefixes(path): - # Here we are looking to find out the offset of this resource inside - # any resources folder. We want to return the root to the resources folder - # and then the sub path inside it - dir_1, dir_2, rel_path = path.partition("resources") - if rel_path: - return dir_1 + dir_2, rel_path - - # The same as the above but just looking for java - (dir_1, dir_2, rel_path) = path.partition("java") - if rel_path: - return dir_1 + dir_2, rel_path - - return "", path - -def _adjust_resources_path(path, resource_strip_prefix): - if resource_strip_prefix: - return _adjust_resources_path_by_strip_prefix(path,resource_strip_prefix) - else: - return _adjust_resources_path_by_default_prefixes(path) - -def _add_resources_cmd(ctx): - res_cmd = [] - for f in ctx.files.resources: - c_dir, res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix) - target_path = res_path - if target_path[0] == "/": - target_path = target_path[1:] - line = "{target_path}={c_dir}{res_path}\n".format( - res_path=res_path, - target_path=target_path, - c_dir=c_dir) - res_cmd.extend([line]) - return "".join(res_cmd) - -def _build_nosrc_jar(ctx, buildijar): - resources = _add_resources_cmd(ctx) - ijar_cmd = "" - if buildijar: - ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format( - jar_output=ctx.outputs.jar.path, - ijar_output=ctx.outputs.ijar.path) - - # this ensures the file is not empty - resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path - - zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name) - ctx.actions.write(zipper_arg_path, resources) - cmd = """ -rm -f {jar_output} -{zipper} c {jar_output} @{path} -# ensures that empty src targets still emit a statsfile -touch {statsfile} -""" + ijar_cmd - - cmd = cmd.format( - path = zipper_arg_path.path, - jar_output=ctx.outputs.jar.path, - zipper=ctx.executable._zipper.path, - statsfile=ctx.outputs.statsfile.path, - ) - - outs = [ctx.outputs.jar, ctx.outputs.statsfile] - if buildijar: - outs.extend([ctx.outputs.ijar]) - - inputs = ctx.files.resources + [ - ctx.outputs.manifest, - ctx.executable._zipper, - zipper_arg_path - ] - - ctx.actions.run_shell( - inputs=inputs, - outputs=outs, - command=cmd, - progress_message="scala %s" % ctx.label, - arguments=[]) - - -def _collect_plugin_paths(plugins): - paths = [] - for p in plugins: - if hasattr(p, "path"): - paths.append(p) - elif hasattr(p, "scala"): - paths.append(p.scala.outputs.jar) - elif hasattr(p, "java"): - paths.extend([j.class_jar for j in p.java.outputs.jars]) - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - elif hasattr(p, "files"): - paths.extend([f for f in p.files if not_sources_jar(f.basename)]) - return depset(paths) - - -def _expand_location(ctx, flags): - return [ctx.expand_location(f, ctx.attr.data) for f in flags] - -def _join_path(args, sep=","): - return sep.join([f.path for f in args]) - -def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels, implicit_junit_deps_needed_for_java_compilation): - ijar_output_path = "" - ijar_cmd_path = "" - if buildijar: - ijar_output_path = ctx.outputs.ijar.path - ijar_cmd_path = ctx.executable._ijar.path - - java_srcs = _java_filetype.filter(ctx.files.srcs) - sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs - srcjars = _srcjar_filetype.filter(ctx.files.srcs) - all_srcjars = depset(srcjars, transitive = [dep_srcjars]) - # look for any plugins: - plugins = _collect_plugin_paths(ctx.attr.plugins) - dependency_analyzer_plugin_jars = [] - dependency_analyzer_mode = "off" - compiler_classpath_jars = cjars - optional_scalac_args = "" - classpath_resources = [] - if (hasattr(ctx.files, "classpath_resources")): - classpath_resources = ctx.files.classpath_resources - - if is_dependency_analyzer_on(ctx): - # "off" mode is used as a feature toggle, that preserves original behaviour - dependency_analyzer_mode = ctx.fragments.java.strict_java_deps - dep_plugin = ctx.attr._dependency_analyzer_plugin - plugins = depset(transitive = [plugins, dep_plugin.files]) - dependency_analyzer_plugin_jars = ctx.files._dependency_analyzer_plugin - compiler_classpath_jars = transitive_compile_jars - - direct_jars = _join_path(cjars.to_list()) - transitive_cjars_list = transitive_compile_jars.to_list() - indirect_jars = _join_path(transitive_cjars_list) - indirect_targets = ",".join([labels[j.path] for j in transitive_cjars_list]) - current_target = str(ctx.label) - - optional_scalac_args = """ -DirectJars: {direct_jars} -IndirectJars: {indirect_jars} -IndirectTargets: {indirect_targets} -CurrentTarget: {current_target} - """.format( - direct_jars=direct_jars, - indirect_jars=indirect_jars, - indirect_targets=indirect_targets, - current_target = current_target - ) - - plugin_arg = _join_path(plugins.to_list()) - - separator = ctx.configuration.host_path_separator - compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) - - toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type'] - scalacopts = toolchain.scalacopts + ctx.attr.scalacopts - - scalac_args = """ -Classpath: {cp} -ClasspathResourceSrcs: {classpath_resource_src} -EnableIjar: {enableijar} -Files: {files} -IjarCmdPath: {ijar_cmd_path} -IjarOutput: {ijar_out} -JarOutput: {out} -JavaFiles: {java_files} -Manifest: {manifest} -Plugins: {plugin_arg} -PrintCompileTime: {print_compile_time} -ResourceDests: {resource_dest} -ResourceJars: {resource_jars} -ResourceSrcs: {resource_src} -ResourceShortPaths: {resource_short_paths} -ResourceStripPrefix: {resource_strip_prefix} -ScalacOpts: {scala_opts} -SourceJars: {srcjars} -DependencyAnalyzerMode: {dependency_analyzer_mode} -StatsfileOutput: {statsfile_output} -""".format( - out=ctx.outputs.jar.path, - manifest=ctx.outputs.manifest.path, - scala_opts=",".join(scalacopts), - print_compile_time=ctx.attr.print_compile_time, - plugin_arg=plugin_arg, - cp=compiler_classpath, - classpath_resource_src=_join_path(classpath_resources), - files=_join_path(sources), - enableijar=buildijar, - ijar_out=ijar_output_path, - ijar_cmd_path=ijar_cmd_path, - srcjars=_join_path(all_srcjars.to_list()), - java_files=_join_path(java_srcs), - # the resource paths need to be aligned in order - resource_src=",".join([f.path for f in ctx.files.resources]), - resource_short_paths=",".join([f.short_path for f in ctx.files.resources]), - resource_dest=",".join( - [_adjust_resources_path_by_default_prefixes(f.short_path)[1] for f in ctx.files.resources] - ), - resource_strip_prefix=ctx.attr.resource_strip_prefix, - resource_jars=_join_path(ctx.files.resource_jars), - dependency_analyzer_mode = dependency_analyzer_mode, - statsfile_output = ctx.outputs.statsfile.path - ) - argfile = ctx.actions.declare_file( - "%s_worker_input" % ctx.label.name, - sibling = ctx.outputs.jar - ) - - ctx.actions.write(output=argfile, content=scalac_args + optional_scalac_args) - - outs = [ctx.outputs.jar, ctx.outputs.statsfile] - if buildijar: - outs.extend([ctx.outputs.ijar]) - ins = (compiler_classpath_jars.to_list() + - dep_srcjars.to_list() + - list(srcjars) + - list(sources) + - ctx.files.srcs + - ctx.files.plugins + - dependency_analyzer_plugin_jars + - classpath_resources + - ctx.files.resources + - ctx.files.resource_jars + - ctx.files._java_runtime + - [ctx.outputs.manifest, - ctx.executable._ijar, - argfile]) - ctx.actions.run( - inputs=ins, - outputs=outs, - executable=ctx.executable._scalac, - mnemonic="Scalac", - progress_message="scala %s" % ctx.label, - execution_requirements={"supports-workers": "1"}, - # when we run with a worker, the `@argfile.path` is removed and passed - # line by line as arguments in the protobuf. In that case, - # the rest of the arguments are passed to the process that - # starts up and stays resident. - - # In either case (worker or not), they will be jvm flags which will - # be correctly handled since the executable is a jvm app that will - # consume the flags on startup. - - arguments=["--jvm_flag=%s" % f for f in _expand_location(ctx, ctx.attr.scalac_jvm_flags)] + ["@" + argfile.path], - ) - - if buildijar: - scala_output = ctx.outputs.ijar - else: - scala_output = ctx.outputs.jar - java_jar = try_to_compile_java_jar(ctx, - scala_output, - all_srcjars, - java_srcs, - implicit_junit_deps_needed_for_java_compilation) - return java_jar - - -def _interim_java_provider_for_java_compilation(scala_output): - # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java - # toolchain. Fortunately, the same change that added this requirement also - # added this field to the Java provider so we can use it to test which - # Bazel version we are running under. - test_provider = java_common.create_provider() - if hasattr(test_provider, "full_compile_jars"): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = [scala_output], - runtime_jars = [], - ) - else: - return java_common.create_provider( - compile_time_jars = [scala_output], - runtime_jars = [], - ) - -def try_to_compile_java_jar(ctx, - scala_output, - all_srcjars, - java_srcs, - implicit_junit_deps_needed_for_java_compilation): - if not java_srcs and not all_srcjars: - return False - - providers_of_dependencies = collect_java_providers_of(ctx.attr.deps) - providers_of_dependencies += collect_java_providers_of(implicit_junit_deps_needed_for_java_compilation) - scala_sources_java_provider = _interim_java_provider_for_java_compilation(scala_output) - providers_of_dependencies += [scala_sources_java_provider] - - full_java_jar = ctx.actions.declare_file(ctx.label.name + "_java.jar") - - provider = java_common.compile( - ctx, - source_jars = all_srcjars.to_list(), - source_files = java_srcs, - output = full_java_jar, - javac_opts = _expand_location(ctx, ctx.attr.javacopts + ctx.attr.javac_jvm_flags + java_common.default_javac_opts(ctx, java_toolchain_attr = "_java_toolchain")), - deps = providers_of_dependencies, - #exports can be empty since the manually created provider exposes exports - #needs to be empty since we want the provider.compile_jars to only contain the sources ijar - #workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved - exports = [], - java_toolchain = ctx.attr._java_toolchain, - host_javabase = ctx.attr._host_javabase, - strict_deps = ctx.fragments.java.strict_java_deps, - ) - return struct(jar = full_java_jar, ijar = provider.compile_jars.to_list().pop()) - -def collect_java_providers_of(deps): - providers = [] - for dep in deps: - if java_common.provider in dep: - providers.append(dep[java_common.provider]) - return providers - -def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation): - # We assume that if a srcjar is present, it is not empty - if len(ctx.files.srcs) + len(srcjars.to_list()) == 0: - _build_nosrc_jar(ctx, buildijar) - # no need to build ijar when empty - return struct(ijar=ctx.outputs.jar, - class_jar=ctx.outputs.jar, - java_jar=False, - full_jars=[ctx.outputs.jar], - ijars=[ctx.outputs.jar]) - else: - java_jar = _compile(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) - ijar = None - if buildijar: - ijar = ctx.outputs.ijar - else: - # macro code needs to be available at compile-time, - # so set ijar == jar - ijar = ctx.outputs.jar - full_jars = [ctx.outputs.jar] - ijars = [ijar] - if java_jar: - full_jars += [java_jar.jar] - ijars += [java_jar.ijar] - return struct(ijar=ijar, - class_jar=ctx.outputs.jar, - java_jar=java_jar, - full_jars=full_jars, - ijars=ijars) - -def _build_deployable(ctx, jars_list): - # This calls bazels singlejar utility. - # For a full list of available command line options see: - # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 - args = ["--normalize", "--sources"] - args.extend([j.path for j in jars_list]) - if getattr(ctx.attr, "main_class", ""): - args.extend(["--main_class", ctx.attr.main_class]) - args.extend(["--output", ctx.outputs.deploy_jar.path]) - ctx.actions.run( - inputs=jars_list, - outputs=[ctx.outputs.deploy_jar], - executable=ctx.executable._singlejar, - mnemonic="ScalaDeployJar", - progress_message="scala deployable %s" % ctx.label, - arguments=args) - -def write_manifest(ctx): - # TODO(bazel-team): I don't think this classpath is what you want - manifest = "Class-Path: \n" - if getattr(ctx.attr, "main_class", ""): - manifest += "Main-Class: %s\n" % ctx.attr.main_class - - ctx.actions.write( - output=ctx.outputs.manifest, - content=manifest) - -def _path_is_absolute(path): - # Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e., - # 'X:\' or 'X:/' where 'X' is a letter), false otherwise. - if len(path) >= 1 and path[0] == "/": - return True - if len(path) >= 3 \ - and path[0].isalpha() \ - and path[1] == ":" \ - and (path[2] == "/" or path[2] == "\\"): - return True - - return False - -def _runfiles_root(ctx): - return "${TEST_SRCDIR}/%s" % ctx.workspace_name - -def _write_java_wrapper(ctx, args="", wrapper_preamble=""): - """This creates a wrapper that sets up the correct path - to stand in for the java command.""" - - java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_runfiles_path) - if _path_is_absolute(java_path): - javabin = java_path - else: - runfiles_root = _runfiles_root(ctx) - javabin = "%s/%s" % (runfiles_root, java_path) - - - exec_str = "" - if wrapper_preamble == "": - exec_str = "exec " - - wrapper = ctx.actions.declare_file(ctx.label.name + "_wrapper.sh") - ctx.actions.write( - output = wrapper, - content = """#!/bin/bash -{preamble} - -{exec_str}{javabin} "$@" {args} -""".format( - preamble=wrapper_preamble, - exec_str=exec_str, - javabin=javabin, - args=args, - ), - is_executable = True - ) - return wrapper - -def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper): - template = ctx.attr._java_stub_template.files.to_list()[0] - # RUNPATH is defined here: - # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227 - classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()]) - jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags]) - ctx.actions.expand_template( - template = template, - output = ctx.outputs.executable, - substitutions = { - "%classpath%": classpath, - "%java_start_class%": main_class, - "%javabin%": "JAVABIN=%s/%s" % (_runfiles_root(ctx), wrapper.short_path), - "%jvm_flags%": jvm_flags, - "%needs_runfiles%": "", - "%runfiles_manifest_only%": "", - "%set_jacoco_metadata%": "", - "%workspace_prefix%": ctx.workspace_name + "/", - }, - is_executable = True, - ) - -def collect_srcjars(targets): - srcjars = [] - for target in targets: - if hasattr(target, "srcjars"): - srcjars.append(target.srcjars.srcjar) - return depset(srcjars) - -def add_labels_of_jars_to(jars2labels, dependency, all_jars, direct_jars): - for jar in direct_jars: - add_label_of_direct_jar_to(jars2labels, dependency, jar) - for jar in all_jars: - add_label_of_indirect_jar_to(jars2labels, dependency, jar) - - -def add_label_of_direct_jar_to(jars2labels, dependency, jar): - jars2labels[jar.path] = dependency.label - -def add_label_of_indirect_jar_to(jars2labels, dependency, jar): - if label_already_exists(jars2labels, jar): - return - - # skylark exposes only labels of direct dependencies. - # to get labels of indirect dependencies we collect them from the providers transitively - if provider_of_dependency_contains_label_of(dependency, jar): - jars2labels[jar.path] = dependency.jars_to_labels[jar.path] - else: - jars2labels[jar.path] = "Unknown label of file {jar_path} which came from {dependency_label}".format( - jar_path = jar.path, - dependency_label = dependency.label - ) - -def label_already_exists(jars2labels, jar): - return jar.path in jars2labels - -def provider_of_dependency_contains_label_of(dependency, jar): - return hasattr(dependency, "jars_to_labels") and jar.path in dependency.jars_to_labels - -def dep_target_contains_ijar(dep_target): - return (hasattr(dep_target, 'scala') and hasattr(dep_target.scala, 'outputs') and - hasattr(dep_target.scala.outputs, 'ijar') and dep_target.scala.outputs.ijar) - -# When import mavan_jar's for scala macros we have to use the jar:file requirement -# since bazel 0.6.0 this brings in the source jar too -# the scala compiler thinks a source jar can look like a package space -# causing a conflict between objects and packages warning -# error: package cats contains object and package with same name: implicits -# one of them needs to be removed from classpath -# import cats.implicits._ - -def not_sources_jar(name): - return "-sources.jar" not in name - -def filter_not_sources(deps): - return depset([dep for dep in deps.to_list() if not_sources_jar(dep.basename) ]) - -def _collect_runtime_jars(dep_targets): - runtime_jars = [] - - for dep_target in dep_targets: - if java_common.provider in dep_target: - runtime_jars.append(dep_target[java_common.provider].transitive_runtime_jars) - else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - runtime_jars.append(filter_not_sources(dep_target.files)) - - return runtime_jars - -def _collect_jars_when_dependency_analyzer_is_off(dep_targets): - compile_jars = [] - runtime_jars = [] - - for dep_target in dep_targets: - if java_common.provider in dep_target: - java_provider = dep_target[java_common.provider] - compile_jars.append(java_provider.compile_jars) - runtime_jars.append(java_provider.transitive_runtime_jars) - else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - compile_jars.append(filter_not_sources(dep_target.files)) - runtime_jars.append(filter_not_sources(dep_target.files)) - - return struct(compile_jars = depset(transitive = compile_jars), - transitive_runtime_jars = depset(transitive = runtime_jars), - jars2labels = {}, - transitive_compile_jars = depset()) - -def _collect_jars_when_dependency_analyzer_is_on(dep_targets): - transitive_compile_jars = [] - jars2labels = {} - compile_jars = [] - runtime_jars = [] - - for dep_target in dep_targets: - current_dep_compile_jars = None - current_dep_transitive_compile_jars = None - - if java_common.provider in dep_target: - java_provider = dep_target[java_common.provider] - current_dep_compile_jars = java_provider.compile_jars - current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars - runtime_jars.append(java_provider.transitive_runtime_jars) - else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - current_dep_compile_jars = filter_not_sources(dep_target.files) - current_dep_transitive_compile_jars = filter_not_sources(dep_target.files) - runtime_jars.append(filter_not_sources(dep_target.files)) - - compile_jars.append(current_dep_compile_jars) - transitive_compile_jars.append(current_dep_transitive_compile_jars) - add_labels_of_jars_to(jars2labels, dep_target, current_dep_transitive_compile_jars.to_list(), current_dep_compile_jars.to_list()) - - return struct(compile_jars = depset(transitive = compile_jars), - transitive_runtime_jars = depset(transitive = runtime_jars), - jars2labels = jars2labels, - transitive_compile_jars = depset(transitive = transitive_compile_jars)) - -def collect_jars(dep_targets, dependency_analyzer_is_off = True): - """Compute the runtime and compile-time dependencies from the given targets""" # noqa - - if dependency_analyzer_is_off: - return _collect_jars_when_dependency_analyzer_is_off(dep_targets) - else: - return _collect_jars_when_dependency_analyzer_is_on(dep_targets) - -def is_dependency_analyzer_on(ctx): - if (hasattr(ctx.attr,"_dependency_analyzer_plugin") - # when the strict deps FT is removed the "default" check - # will be removed since "default" will mean it's turned on - and ctx.fragments.java.strict_java_deps != "default" - and ctx.fragments.java.strict_java_deps != "off"): - return True - -def is_dependency_analyzer_off(ctx): - return not is_dependency_analyzer_on(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 = [], 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, dependency_analyzer_is_off) - (cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, deps_jars.jars2labels, deps_jars.transitive_compile_jars) - - transitive_rjars = depset(transitive = [transitive_rjars] + _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps)) - - return struct(compile_jars = cjars, transitive_runtime_jars = transitive_rjars, jars2labels=jars2labels, transitive_compile_jars = transitive_compile_jars) - -def create_java_provider(scalaattr, transitive_compile_time_jars): - # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java - # toolchain. Fortunately, the same change that added this requirement also - # added this field to the Java provider so we can use it to test which - # Bazel version we are running under. - test_provider = java_common.create_provider() - - if hasattr(test_provider, "full_compile_jars"): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = scalaattr.compile_jars, - runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), - transitive_runtime_jars = scalaattr.transitive_runtime_jars, - ) - else: - return java_common.create_provider( - compile_time_jars = scalaattr.compile_jars, - runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = transitive_compile_time_jars, - transitive_runtime_jars = scalaattr.transitive_runtime_jars, - ) - -# TODO: this should really be a bazel provider, but we are using old-style rule outputs -# we need to document better what the intellij dependencies on this code actually are -def create_scala_provider( - ijar, - class_jar, - compile_jars, - transitive_runtime_jars, - deploy_jar, - full_jars, - statsfile): - - formatted_for_intellij = [struct( - class_jar = jar, - ijar = None, - source_jar = None, - source_jars = []) for jar in full_jars] - - rule_outputs = struct( - ijar = ijar, - class_jar = class_jar, - deploy_jar = deploy_jar, - jars = formatted_for_intellij, - statsfile = statsfile, - ) - # Note that, internally, rules only care about compile_jars and transitive_runtime_jars - # in a similar manner as the java_library and JavaProvider - return struct( - outputs = rule_outputs, - compile_jars = compile_jars, - transitive_runtime_jars = transitive_runtime_jars, - transitive_exports = [] #needed by intellij plugin - ) - -def _lib(ctx, 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) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - - write_manifest(ctx) - outputs = _compile_or_empty(ctx, cjars, srcjars, non_macro_lib, jars.transitive_compile_jars, jars.jars2labels, []) - - transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) - - _build_deployable(ctx, transitive_rjars.to_list()) - - # Using transitive_files since transitive_rjars a depset and avoiding linearization - runfiles = ctx.runfiles( - transitive_files = transitive_rjars, - collect_data = True, - ) - - # Add information from exports (is key that AFTER all build actions/runfiles analysis) - # Since after, will not show up in deploy_jar or old jars runfiles - # Notice that compile_jars is intentionally transitive for exports - exports_jars = collect_jars(ctx.attr.exports) - transitive_rjars = depset(transitive = [transitive_rjars, exports_jars.transitive_runtime_jars]) - - scalaattr = create_scala_provider( - ijar = outputs.ijar, - class_jar = outputs.class_jar, - compile_jars = depset(outputs.ijars, transitive = [exports_jars.compile_jars]), - transitive_runtime_jars = transitive_rjars, - deploy_jar = ctx.outputs.deploy_jar, - full_jars = outputs.full_jars, - statsfile = ctx.outputs.statsfile) - - java_provider = create_java_provider(scalaattr, jars.transitive_compile_jars) - - return struct( - files = depset([ctx.outputs.jar]), # Here is the default output - scala = scalaattr, - providers = [java_provider], - runfiles = runfiles, - # This is a free monoid given to the graph for the purpose of - # extensibility. This is necessary when one wants to create - # new targets which want to leverage a scala_library. For example, - # new_target1 -> scala_library -> new_target2. There might be - # information that new_target2 needs to get from new_target1, - # but we do not want to have to change scala_library to pass - # this information through. extra_information allows passing - # this information through, and it is up to the new_targets - # to filter and make sense of this information. - extra_information=_collect_extra_information(ctx.attr.deps), - jars_to_labels = jars.jars2labels, - ) - - -def _collect_extra_information(targets): - r = [] - for target in targets: - if hasattr(target, "extra_information"): - r.extend(target.extra_information) - return r - -def _scala_library_impl(ctx): - return _lib(ctx, True) - -def _scala_macro_library_impl(ctx): - return _lib(ctx, False) # don't build the ijar for macros - -# Common code shared by all scala binary implementations. -def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2labels, java_wrapper, implicit_junit_deps_needed_for_java_compilation = []): - write_manifest(ctx) - outputs = _compile_or_empty(ctx, cjars, depset(), False, transitive_compile_time_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) # no need to build an ijar for an executable - rjars = depset(outputs.full_jars, transitive = [rjars]) - - _build_deployable(ctx, rjars.to_list()) - - runfiles = ctx.runfiles( - transitive_files = depset([ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, transitive = [rjars]), - collect_data = True) - - scalaattr = create_scala_provider( - ijar = outputs.class_jar, # we aren't using ijar here - class_jar = outputs.class_jar, - compile_jars = depset(outputs.ijars), - transitive_runtime_jars = rjars, - deploy_jar = ctx.outputs.deploy_jar, - full_jars = outputs.full_jars, - statsfile = ctx.outputs.statsfile) - - java_provider = create_java_provider(scalaattr, transitive_compile_time_jars) - - return struct( - files=depset([ctx.outputs.executable]), - providers = [java_provider], - scala = scalaattr, - transitive_rjars = rjars, #calling rules need this for the classpath in the launcher - jars_to_labels = jars2labels, - runfiles=runfiles) - -def _scala_binary_impl(ctx): - jars = _collect_jars_from_common_ctx(ctx) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - - wrapper = _write_java_wrapper(ctx, "", "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = ctx.attr.main_class, - jvm_flags = ctx.attr.jvm_flags, - wrapper = wrapper - ) - return out - -def _scala_repl_impl(ctx): - # need scala-compiler for MainGenericRunner below - jars = _collect_jars_from_common_ctx(ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - - args = " ".join(ctx.attr.scalacopts) - wrapper = _write_java_wrapper(ctx, args, wrapper_preamble = """ -# save stty like in bin/scala -saved_stty=$(stty -g 2>/dev/null) -if [[ ! $? ]]; then - saved_stty="" -fi -function finish() { - if [[ "$saved_stty" != "" ]]; then - stty $saved_stty - saved_stty="" - fi -} -trap finish EXIT -""") - - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = "scala.tools.nsc.MainGenericRunner", - jvm_flags = ["-Dscala.usejavacp=true"] + ctx.attr.jvm_flags, - wrapper = wrapper - ) - - return out - -def _scala_test_flags(ctx): - # output report test duration - flags = "-oD" - if ctx.attr.full_stacktraces: - flags += "F" - else: - flags += "S" - if not ctx.attr.colors: - flags += "W" - return flags - -def _scala_test_impl(ctx): - if len(ctx.attr.suites) != 0: - print( - "suites attribute is deprecated. All scalatest test suites are run" - ) - jars = _collect_jars_from_common_ctx(ctx, - extra_runtime_deps = [ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner], - ) - (cjars, transitive_rjars, transitive_compile_jars, jars_to_labels) = (jars.compile_jars, jars.transitive_runtime_jars, - jars.transitive_compile_jars, jars.jars2labels) - # _scalatest is an http_jar, so its compile jar is run through ijar - # however, contains macros, so need to handle separately - scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars - cjars = depset(transitive = [cjars, scalatest_jars]) - transitive_rjars = depset(transitive = [transitive_rjars, scalatest_jars]) - - if is_dependency_analyzer_on(ctx): - transitive_compile_jars = depset(transitive = [scalatest_jars, transitive_compile_jars]) - scalatest_jars_list = scalatest_jars.to_list() - add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, scalatest_jars_list, scalatest_jars_list) - - args = " ".join([ - "-R \"{path}\"".format(path=ctx.outputs.jar.short_path), - _scala_test_flags(ctx), - "-C io.bazel.rules.scala.JUnitXmlReporter ", - ]) - # main_class almost has to be "org.scalatest.tools.Runner" due to args.... - wrapper = _write_java_wrapper(ctx, args, "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, transitive_compile_jars, jars_to_labels, wrapper) - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = ctx.attr.main_class, - jvm_flags = ctx.attr.jvm_flags, - wrapper = wrapper - ) - return out - -def _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, archives): - serialized_archives = _serialize_archives_short_path(archives) - return struct( - testSuiteFlag = "-Dbazel.test_suite=%s" % ctx.attr.suite_class, - archiveFlag = "-Dbazel.discover.classes.archives.file.paths=%s" % serialized_archives, - prefixesFlag = "-Dbazel.discover.classes.prefixes=%s" % ",".join(ctx.attr.prefixes), - suffixesFlag = "-Dbazel.discover.classes.suffixes=%s" % ",".join(ctx.attr.suffixes), - printFlag = "-Dbazel.discover.classes.print.discovered=%s" % ctx.attr.print_discovered_classes) - -def _serialize_archives_short_path(archives): - archives_short_path = "" - for archive in archives: archives_short_path += archive.class_jar.short_path + "," - return archives_short_path[:-1] #remove redundant comma - -def _scala_junit_test_impl(ctx): - if (not(ctx.attr.prefixes) and not(ctx.attr.suffixes)): - fail("Setting at least one of the attributes ('prefixes','suffixes') is required") - jars = _collect_jars_from_common_ctx(ctx, - extra_deps = [ctx.attr._junit, ctx.attr._hamcrest, ctx.attr.suite_label, ctx.attr._bazel_test_runner], - ) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - implicit_junit_deps_needed_for_java_compilation = [ctx.attr._junit, ctx.attr._hamcrest] - - wrapper = _write_java_wrapper(ctx, "", "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper, implicit_junit_deps_needed_for_java_compilation) - test_suite = _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, out.scala.outputs.jars) - launcherJvmFlags = ["-ea", test_suite.archiveFlag, test_suite.prefixesFlag, test_suite.suffixesFlag, test_suite.printFlag, test_suite.testSuiteFlag] - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = "com.google.testing.junit.runner.BazelTestRunner", - jvm_flags = launcherJvmFlags + ctx.attr.jvm_flags, - wrapper = wrapper - ) - - return out _launcher_template = { "_java_stub_template": attr.label(default=Label("@java_stub_template//file")), @@ -962,9 +56,9 @@ _junit_resolve_deps = { # Common attributes reused across multiple rules. _common_attrs_for_plugin_bootstrapping = { "srcs": attr.label_list( - allow_files=_scala_srcjar_filetype), + allow_files=FileType([".scala", ".srcjar", ".java"])), "deps": attr.label_list(), - "plugins": attr.label_list(allow_files=_jar_filetype), + "plugins": attr.label_list(allow_files=FileType([".jar"])), "runtime_deps": attr.label_list(), "data": attr.label_list(allow_files=True, cfg="data"), "resources": attr.label_list(allow_files=True), @@ -1011,7 +105,7 @@ _scala_library_attrs.update(_common_attrs) _scala_library_attrs.update(library_attrs) _scala_library_attrs.update(_resolve_deps) scala_library = rule( - implementation=_scala_library_impl, + implementation=scala_library_impl, attrs=_scala_library_attrs, outputs=library_outputs, fragments = ["java"], @@ -1027,7 +121,7 @@ _scala_library_for_plugin_bootstrapping_attrs.update(library_attrs) _scala_library_for_plugin_bootstrapping_attrs.update(_resolve_deps) _scala_library_for_plugin_bootstrapping_attrs.update(_common_attrs_for_plugin_bootstrapping) scala_library_for_plugin_bootstrapping = rule( - implementation=_scala_library_impl, + implementation=scala_library_impl, attrs= _scala_library_for_plugin_bootstrapping_attrs, outputs=library_outputs, fragments = ["java"], @@ -1043,7 +137,7 @@ _scala_macro_library_attrs.update(_common_attrs) _scala_macro_library_attrs.update(library_attrs) _scala_macro_library_attrs.update(_resolve_deps) scala_macro_library = rule( - implementation=_scala_macro_library_impl, + implementation=scala_macro_library_impl, attrs= _scala_macro_library_attrs, outputs= common_outputs, fragments = ["java"], @@ -1059,7 +153,7 @@ _scala_binary_attrs.update(_implicit_deps) _scala_binary_attrs.update(_common_attrs) _scala_binary_attrs.update(_resolve_deps) scala_binary = rule( - implementation=_scala_binary_impl, + implementation=scala_binary_impl, attrs= _scala_binary_attrs, outputs= common_outputs, executable=True, @@ -1081,7 +175,7 @@ _scala_test_attrs.update(_implicit_deps) _scala_test_attrs.update(_common_attrs) _scala_test_attrs.update(_test_resolve_deps) scala_test = rule( - implementation=_scala_test_impl, + implementation=scala_test_impl, attrs= _scala_test_attrs, outputs= common_outputs, executable=True, @@ -1096,7 +190,7 @@ _scala_repl_attrs.update(_implicit_deps) _scala_repl_attrs.update(_common_attrs) _scala_repl_attrs.update(_resolve_deps) scala_repl = rule( - implementation=_scala_repl_impl, + implementation=scala_repl_impl, attrs= _scala_repl_attrs, outputs= common_outputs, executable=True, @@ -1278,7 +372,7 @@ _scala_junit_test_attrs.update(_implicit_deps) _scala_junit_test_attrs.update(_common_attrs) _scala_junit_test_attrs.update(_junit_resolve_deps) scala_junit_test = rule( - implementation=_scala_junit_test_impl, + implementation=scala_junit_test_impl, attrs= _scala_junit_test_attrs, outputs= common_outputs, test=True, diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index f3ddef678..4d6ff09f8 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -1,8 +1,15 @@ load("//scala:scala.bzl", - "scala_mvn_artifact", - "scala_library", - "collect_jars", - "create_java_provider") + "scala_library", +) + +load("//scala:scala_cross_version.bzl", + "scala_mvn_artifact", +) + +load("//scala/private:common.bzl", + "collect_jars", + "create_java_provider", +) def scala_proto_repositories(): native.maven_server( diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index 2cc0f8a90..8b14af7ce 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -1,9 +1,16 @@ load("//scala:scala.bzl", - "scala_mvn_artifact", - "scala_library", + "scala_library", +) + +load("//scala:scala_cross_version.bzl", + "scala_mvn_artifact", +) + +load("//scala/private:common.bzl", "write_manifest", "collect_srcjars", - "collect_jars") + "collect_jars" +) load("//thrift:thrift.bzl", "ThriftInfo") From d2850c9c4f239f855bf7b872752cc45d01c27545 Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Sun, 29 Apr 2018 19:48:42 -0700 Subject: [PATCH 09/29] Privately scope as much as possible in scala.bzl --- scala/scala.bzl | 87 +++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/scala/scala.bzl b/scala/scala.bzl index 1e1059463..69d16f66d 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -1,15 +1,15 @@ load("@io_bazel_rules_scala//scala/private:rule_impls.bzl", - "scala_library_impl", - "scala_macro_library_impl", - "scala_binary_impl", - "scala_test_impl", - "scala_repl_impl", - "scala_junit_test_impl", + _scala_library_impl = "scala_library_impl", + _scala_macro_library_impl = "scala_macro_library_impl", + _scala_binary_impl = "scala_binary_impl", + _scala_test_impl = "scala_test_impl", + _scala_repl_impl = "scala_repl_impl", + _scala_junit_test_impl = "scala_junit_test_impl", ) load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", - "specs2_junit_dependencies" + _specs2_junit_dependencies = "specs2_junit_dependencies" ) _jar_filetype = FileType([".jar"]) @@ -81,33 +81,34 @@ _common_attrs.update({ "_dependency_analyzer_plugin": attr.label(default=Label("@io_bazel_rules_scala//third_party/plugin/src/main:dependency_analyzer"), allow_files=_jar_filetype, mandatory=False), }) -library_attrs = { +_library_attrs = { "main_class": attr.string(), "exports": attr.label_list(allow_files=False), } -common_outputs = { +_common_outputs = { "jar": "%{name}.jar", "deploy_jar": "%{name}_deploy.jar", "manifest": "%{name}_MANIFEST.MF", "statsfile": "%{name}.statsfile", } -library_outputs = {} -library_outputs.update(common_outputs) -library_outputs.update({ +_library_outputs = {} +_library_outputs.update(_common_outputs) +_library_outputs.update({ "ijar": "%{name}_ijar.jar", }) _scala_library_attrs = {} _scala_library_attrs.update(_implicit_deps) _scala_library_attrs.update(_common_attrs) -_scala_library_attrs.update(library_attrs) +_scala_library_attrs.update(_library_attrs) _scala_library_attrs.update(_resolve_deps) + scala_library = rule( - implementation=scala_library_impl, - attrs=_scala_library_attrs, - outputs=library_outputs, + implementation =_scala_library_impl, + attrs = _scala_library_attrs, + outputs = _library_outputs, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) @@ -117,13 +118,13 @@ scala_library = rule( # which does not contain plugin related attributes, and thus avoids the cyclic dependency issue _scala_library_for_plugin_bootstrapping_attrs = {} _scala_library_for_plugin_bootstrapping_attrs.update(_implicit_deps) -_scala_library_for_plugin_bootstrapping_attrs.update(library_attrs) +_scala_library_for_plugin_bootstrapping_attrs.update(_library_attrs) _scala_library_for_plugin_bootstrapping_attrs.update(_resolve_deps) _scala_library_for_plugin_bootstrapping_attrs.update(_common_attrs_for_plugin_bootstrapping) scala_library_for_plugin_bootstrapping = rule( - implementation=scala_library_impl, - attrs= _scala_library_for_plugin_bootstrapping_attrs, - outputs=library_outputs, + implementation = _scala_library_impl, + attrs = _scala_library_for_plugin_bootstrapping_attrs, + outputs = _library_outputs, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) @@ -134,12 +135,12 @@ _scala_macro_library_attrs = { } _scala_macro_library_attrs.update(_implicit_deps) _scala_macro_library_attrs.update(_common_attrs) -_scala_macro_library_attrs.update(library_attrs) +_scala_macro_library_attrs.update(_library_attrs) _scala_macro_library_attrs.update(_resolve_deps) scala_macro_library = rule( - implementation=scala_macro_library_impl, - attrs= _scala_macro_library_attrs, - outputs= common_outputs, + implementation = _scala_macro_library_impl, + attrs = _scala_macro_library_attrs, + outputs = _common_outputs, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) @@ -153,10 +154,10 @@ _scala_binary_attrs.update(_implicit_deps) _scala_binary_attrs.update(_common_attrs) _scala_binary_attrs.update(_resolve_deps) scala_binary = rule( - implementation=scala_binary_impl, + implementation = _scala_binary_impl, attrs= _scala_binary_attrs, - outputs= common_outputs, - executable=True, + outputs = _common_outputs, + executable = True, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) @@ -175,11 +176,11 @@ _scala_test_attrs.update(_implicit_deps) _scala_test_attrs.update(_common_attrs) _scala_test_attrs.update(_test_resolve_deps) scala_test = rule( - implementation=scala_test_impl, - attrs= _scala_test_attrs, - outputs= common_outputs, - executable=True, - test=True, + implementation =_scala_test_impl, + attrs = _scala_test_attrs, + outputs = _common_outputs, + executable = True, + test = True, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) @@ -190,15 +191,15 @@ _scala_repl_attrs.update(_implicit_deps) _scala_repl_attrs.update(_common_attrs) _scala_repl_attrs.update(_resolve_deps) scala_repl = rule( - implementation=scala_repl_impl, - attrs= _scala_repl_attrs, - outputs= common_outputs, - executable=True, + implementation =_scala_repl_impl, + attrs = _scala_repl_attrs, + outputs = _common_outputs, + executable = True, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) -SCALA_BUILD_FILE = """ +_SCALA_BUILD_FILE = """ # scala.BUILD java_import( name = "scala-xml", @@ -237,7 +238,7 @@ def scala_repositories(): strip_prefix = "scala-2.11.11", sha256 = "12037ca64c68468e717e950f47fc77d5ceae5e74e3bdca56f6d02fd5bfd6900b", url = "https://downloads.lightbend.com/scala/2.11.11/scala-2.11.11.tgz", - build_file_content = SCALA_BUILD_FILE, + build_file_content = _SCALA_BUILD_FILE, ) # scalatest has macros, note http_jar is invoking ijar @@ -372,10 +373,10 @@ _scala_junit_test_attrs.update(_implicit_deps) _scala_junit_test_attrs.update(_common_attrs) _scala_junit_test_attrs.update(_junit_resolve_deps) scala_junit_test = rule( - implementation=scala_junit_test_impl, - attrs= _scala_junit_test_attrs, - outputs= common_outputs, - test=True, + implementation = _scala_junit_test_impl, + attrs = _scala_junit_test_attrs, + outputs = _common_outputs, + test = True, fragments = ["java"], toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'] ) @@ -383,7 +384,7 @@ scala_junit_test = rule( def scala_specs2_junit_test(name, **kwargs): scala_junit_test( name = name, - deps = specs2_junit_dependencies() + kwargs.pop("deps",[]), + deps = _specs2_junit_dependencies() + kwargs.pop("deps",[]), suite_label = Label("//src/java/io/bazel/rulesscala/specs2:specs2_test_discovery"), suite_class = "io.bazel.rulesscala.specs2.Specs2DiscoveredTestSuite", **kwargs) From 3bc13824d14cd4caa52f00501097fb74253e07eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Fri, 4 May 2018 11:06:38 -0700 Subject: [PATCH 10/29] Remove unused proto_deps array (#490) --- scala_proto/scala_proto.bzl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index 4d6ff09f8..8887ad301 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -329,10 +329,9 @@ def _gen_proto_srcjar_impl(ctx): acc_imports = [] transitive_proto_paths = [] - proto_deps, jvm_deps = [], [] + jvm_deps = [] for target in ctx.attr.deps: if hasattr(target, 'proto'): - proto_deps.append(target) acc_imports.append(target.proto.transitive_sources) #inline this if after 0.12.0 is the oldest supported version if hasattr(target.proto, 'transitive_proto_path'): From 51b7848a100a9aff79e30c93ce9efafc87aeb2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Fri, 4 May 2018 22:17:24 -0700 Subject: [PATCH 11/29] Remove unused variables --- jmh/jmh.bzl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/jmh/jmh.bzl b/jmh/jmh.bzl index 973318015..8eeadf6a2 100644 --- a/jmh/jmh.bzl +++ b/jmh/jmh.bzl @@ -56,11 +56,6 @@ def jmh_repositories(): actual = '@io_bazel_rules_scala_org_apache_commons_commons_math3//jar', ) -jmh_benchmark_generator_tool = Label("//src/scala/io/bazel/rules_scala/jmh_support:benchmark_generator") -jdk_tool = Label("//tools/defaults:jdk") -jar_tool = Label("@local_jdk//:jar") -jar_creator_tool = Label("//src/java/io/bazel/rulesscala/jar:binary") - def _scala_construct_runtime_classpath(deps): scala_targets = [d.scala for d in deps if hasattr(d, "scala")] java_targets = [d.java for d in deps if hasattr(d, "java")] From 2dd2c78881b4bd988927ce3dfc35ac6c6e1cf744 Mon Sep 17 00:00:00 2001 From: Andy Scott Date: Fri, 4 May 2018 22:22:46 -0700 Subject: [PATCH 12/29] Remove old/unused file --- .bazel-installer-linux-x86_64.sh.sha256 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .bazel-installer-linux-x86_64.sh.sha256 diff --git a/.bazel-installer-linux-x86_64.sh.sha256 b/.bazel-installer-linux-x86_64.sh.sha256 deleted file mode 100644 index a5b4cee01..000000000 --- a/.bazel-installer-linux-x86_64.sh.sha256 +++ /dev/null @@ -1 +0,0 @@ -2744447c9999ceea3dc0b90013dcdfbc3683ebb416eb45287c98049bb7a1c6a8 bazel-0.3.2-installer-linux-x86_64.sh From 5f47e54fb3d1fbc9612566f9ac63e4f06f75edde Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Mon, 7 May 2018 16:16:39 +0200 Subject: [PATCH 13/29] Remove tools/bazel.rc on CI as it's incompatible. (#495) Local disk caching does not work on Bazel's CI and actually causes the project to fail in our downstream tests at the moment: https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/224#e8eab4eb-9baf-4503-8328-62d1ca2f454d --- .bazelci/presubmit.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index ea06a33e5..25b83077c 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -1,16 +1,25 @@ --- platforms: ubuntu1404: + shell_commands: + # Disable local disk caching on CI. + - rm -f tools/bazel.rc build_targets: - "//test/..." test_targets: - "//test/..." ubuntu1604: + shell_commands: + # Disable local disk caching on CI. + - rm -f tools/bazel.rc build_targets: - "//test/..." test_targets: - "//test/..." macos: + shell_commands: + # Disable local disk caching on CI. + - rm -f tools/bazel.rc build_targets: - "//test/..." test_targets: From 63eab9f4d80612e918ba954211f377cc83d27a07 Mon Sep 17 00:00:00 2001 From: natans Date: Mon, 7 May 2018 19:11:45 +0300 Subject: [PATCH 14/29] fix bug in jvm_import_external when user adds a 'generated_linkable_rule_name' attribute --- WORKSPACE | 2 ++ scala/scala_maven_import_external.bzl | 4 +++- third_party/plugin/src/test/BUILD | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index cbe5b3eeb..aa10fc7cd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -105,4 +105,6 @@ java_import_external( licenses = ["notice"], # Apache 2.0 jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"], jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c", + neverlink = True, + generated_linkable_rule_name="linkable_org_apache_commons_commons_lang_3_5_without_file", ) diff --git a/scala/scala_maven_import_external.bzl b/scala/scala_maven_import_external.bzl index 926375f7f..c4fcc5358 100644 --- a/scala/scala_maven_import_external.bzl +++ b/scala/scala_maven_import_external.bzl @@ -82,11 +82,13 @@ def _jvm_import_external(repository_ctx): if (repository_ctx.attr.neverlink and repository_ctx.attr.generated_linkable_rule_name): lines.extend(_serialize_given_rule_import( + repository_ctx.attr.rule_name, repository_ctx.attr.generated_linkable_rule_name, path, srcpath, repository_ctx.attr, - [p for p in _PASS_PROPS if p != "neverlink"])) + [p for p in _PASS_PROPS if p != "neverlink"], + repository_ctx.attr.additional_rule_attrs)) extra = repository_ctx.attr.extra_build_file_content if extra: lines.append(extra) diff --git a/third_party/plugin/src/test/BUILD b/third_party/plugin/src/test/BUILD index 0589fc5d2..6df6f27f3 100644 --- a/third_party/plugin/src/test/BUILD +++ b/third_party/plugin/src/test/BUILD @@ -12,10 +12,10 @@ scala_junit_test( "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", "//external:io_bazel_rules_scala/dependency/scala/scala_library", "@com_google_guava_guava_21_0_with_file//jar", - "@org_apache_commons_commons_lang_3_5_without_file//jar" + "@org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file" ], jvm_flags = ["-Dplugin.jar.location=$(location //third_party/plugin/src/main:dependency_analyzer)", "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", - "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//jar)"], + "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)"], ) \ No newline at end of file From a8ef632b1b020cdf2c215ecd9fcfa84bc435efcb Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Tue, 8 May 2018 10:25:50 +0300 Subject: [PATCH 15/29] update rules_scala commit in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e7f65dd4..be68a026d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ you must have bazel 0.5.3 or later and add the following to your WORKSPACE file: ```python -rules_scala_version="98dc457356c60b23ccbbdcbf73acfad9e15e8b07" # update this as needed +rules_scala_version="63eab9f4d80612e918ba954211f377cc83d27a07" # update this as needed http_archive( name = "io_bazel_rules_scala", From 9d19510dc0e74db4a570b0afdecaf4d002267fc0 Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Fri, 18 May 2018 23:00:30 +0300 Subject: [PATCH 16/29] enable workers on buildkite (#504) * Create bazel.rc.buildkite * Update presubmit.yml --- .bazelci/presubmit.yml | 6 +++--- tools/bazel.rc.buildkite | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tools/bazel.rc.buildkite diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 25b83077c..0bd65bce6 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -3,7 +3,7 @@ platforms: ubuntu1404: shell_commands: # Disable local disk caching on CI. - - rm -f tools/bazel.rc + - mv tools/bazel.rc.buildkite tools/bazel.rc build_targets: - "//test/..." test_targets: @@ -11,7 +11,7 @@ platforms: ubuntu1604: shell_commands: # Disable local disk caching on CI. - - rm -f tools/bazel.rc + - mv tools/bazel.rc.buildkite tools/bazel.rc build_targets: - "//test/..." test_targets: @@ -19,7 +19,7 @@ platforms: macos: shell_commands: # Disable local disk caching on CI. - - rm -f tools/bazel.rc + - mv tools/bazel.rc.buildkite tools/bazel.rc build_targets: - "//test/..." test_targets: diff --git a/tools/bazel.rc.buildkite b/tools/bazel.rc.buildkite new file mode 100644 index 000000000..9d784856c --- /dev/null +++ b/tools/bazel.rc.buildkite @@ -0,0 +1 @@ +build --strategy=Scalac=worker --strategy=ScroogeRule=worker --worker_max_instances=3 From aeb1da1145b7faffa8fe212f597410e2a8b40760 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Fri, 18 May 2018 23:03:59 +0300 Subject: [PATCH 17/29] Support custom runners (@RunWith) on filtered Scala junit tests (#461) * Changing applying the filtering logic directly on the underlying (private) TestClass object for a given runner * Adding a test for custom runner support * Renaming a method to something more suitable * Extracting the custom junit runner for tests to its own library * Extracting named fields for strings --- .../FilteredRunnerBuilder.scala | 61 +++++++++++++------ test/BUILD | 16 ++++- .../scala/test/junit/JunitCustomRunner.java | 23 +++++++ .../test/junit/JunitCustomRunnerTest.scala | 13 ++++ test_rules_scala.sh | 9 +++ 5 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 test/src/main/scala/scala/test/junit/JunitCustomRunner.java create mode 100644 test/src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala diff --git a/src/java/io/bazel/rulesscala/test_discovery/FilteredRunnerBuilder.scala b/src/java/io/bazel/rulesscala/test_discovery/FilteredRunnerBuilder.scala index fcc66e214..df9df7c5a 100644 --- a/src/java/io/bazel/rulesscala/test_discovery/FilteredRunnerBuilder.scala +++ b/src/java/io/bazel/rulesscala/test_discovery/FilteredRunnerBuilder.scala @@ -1,13 +1,20 @@ package io.bazel.rulesscala.test_discovery +import java.lang.annotation.Annotation +import java.util import java.util.regex.Pattern import io.bazel.rulesscala.test_discovery.FilteredRunnerBuilder.FilteringRunnerBuilder +import org.junit.Test import org.junit.runner.Runner import org.junit.runners.BlockJUnit4ClassRunner -import org.junit.runners.model.{FrameworkMethod, RunnerBuilder} +import org.junit.runners.model.{FrameworkMethod, RunnerBuilder, TestClass} -import scala.collection.JavaConverters._ +import scala.collection.JavaConversions._ + +object FilteredRunnerBuilder { + type FilteringRunnerBuilder = PartialFunction[(Runner, Class[_], Pattern), Runner] +} class FilteredRunnerBuilder(builder: RunnerBuilder, filteringRunnerBuilder: FilteringRunnerBuilder) extends RunnerBuilder { // Defined by --test_filter bazel flag. @@ -21,29 +28,43 @@ class FilteredRunnerBuilder(builder: RunnerBuilder, filteringRunnerBuilder: Filt } } -object FilteredRunnerBuilder { - type FilteringRunnerBuilder = PartialFunction[(Runner, Class[_], Pattern), Runner] +private[rulesscala] class FilteredTestClass(testClass: Class[_], pattern: Pattern) extends TestClass(testClass) { + override def getAnnotatedMethods(aClass: Class[_ <: Annotation]): util.List[FrameworkMethod] = { + val methods = super.getAnnotatedMethods(aClass) + if (aClass == classOf[Test]) methods.filter(method => methodMatchesPattern(method, pattern)) + else methods + } + + private def methodMatchesPattern(method: FrameworkMethod, pattern: Pattern): Boolean = { + val testCase = method.getDeclaringClass.getName + "#" + method.getName + pattern.matcher(testCase).find + } } object JUnitFilteringRunnerBuilder { + private final val TestClassFieldPreJUnit4_12 = "fTestClass" + private final val TestClassField = "testClass" + val f: FilteringRunnerBuilder = { - case (_: BlockJUnit4ClassRunner, testClass: Class[_], pattern: Pattern) => - new FilteredJUnitClassRunner(testClass, pattern) + case (runner: BlockJUnit4ClassRunner, testClass: Class[_], pattern: Pattern) => + replaceRunnerTestClass(runner, testClass, pattern) } -} -class FilteredJUnitClassRunner(testClass: Class[_], pattern: Pattern) - extends BlockJUnit4ClassRunner(testClass) { - override def getChildren: java.util.List[FrameworkMethod] = - super - .getChildren - .asScala - .filter(method => methodMatchesPattern(method, pattern)) - .asJava - - private def methodMatchesPattern(method: FrameworkMethod, pattern: Pattern): Boolean = { - val testCase = method.getDeclaringClass.getName + "#" + method.getName - pattern.matcher(testCase).find + private def replaceRunnerTestClass(runner: BlockJUnit4ClassRunner, testClass: Class[_], pattern: Pattern) = { + allFieldsOf(runner.getClass) + .find(f => f.getName == TestClassField || f.getName == TestClassFieldPreJUnit4_12) + .foreach(field => { + field.setAccessible(true) + field.set(runner, new FilteredTestClass(testClass, pattern)) + }) + runner } -} \ No newline at end of file + private def allFieldsOf(clazz: Class[_]) = { + def supers(cl: Class[_]): List[Class[_]] = { + if (cl == null) Nil else cl :: supers(cl.getSuperclass) + } + + supers(clazz).flatMap(_.getDeclaredFields) + } +} diff --git a/test/BUILD b/test/BUILD index dc533896e..5b98abd97 100644 --- a/test/BUILD +++ b/test/BUILD @@ -380,6 +380,14 @@ scala_junit_test( print_discovered_classes = True ) +scala_junit_test( + name = "JunitCustomRunner", + srcs = ["src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala"], + size = "small", + suffixes = ["Test"], + deps = [":customJunitRunner"] +) + scala_junit_test( name = "JunitIncludesClassesWithRunWith", srcs = ["src/main/scala/scala/test/junit/JunitIncludesRunWith.scala"], @@ -400,7 +408,13 @@ scala_library( name = "filesWithUtf8", srcs = ["src/main/scala/scala/test/utf8/JavaClassWithUtf8.java", "src/main/scala/scala/test/utf8/ScalaClassWithUtf8.scala"] - ) +) + +scala_library( + name = "customJunitRunner", + srcs = ["src/main/scala/scala/test/junit/JunitCustomRunner.java"], + deps = ["//external:io_bazel_rules_scala/dependency/junit/junit"] +) # make sure making a fat jar strips signatures java_import( diff --git a/test/src/main/scala/scala/test/junit/JunitCustomRunner.java b/test/src/main/scala/scala/test/junit/JunitCustomRunner.java new file mode 100644 index 000000000..78bd23cdb --- /dev/null +++ b/test/src/main/scala/scala/test/junit/JunitCustomRunner.java @@ -0,0 +1,23 @@ +package scala.test.junit; + +import org.junit.rules.TestRule; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +import java.util.List; + +public class JunitCustomRunner extends BlockJUnit4ClassRunner { + + public JunitCustomRunner(Class aClass) throws InitializationError { + super(aClass); + } + + public static final String EXPECTED_MESSAGE = "Hello from getTestRules!"; + public static String message; + + @Override + protected List getTestRules(Object target) { + message = EXPECTED_MESSAGE; + return super.getTestRules(target); + } +} diff --git a/test/src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala b/test/src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala new file mode 100644 index 000000000..f0cbfc0f2 --- /dev/null +++ b/test/src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala @@ -0,0 +1,13 @@ +package scala.test.junit + +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(classOf[JunitCustomRunner]) +class JunitCustomRunnerTest { + @Test + def myTest() = { + assert(JunitCustomRunner.message == JunitCustomRunner.EXPECTED_MESSAGE, + "JunitCustomRunner did not run, check the wiring in JUnitFilteringRunnerBuilder") + } +} \ No newline at end of file diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 4e44cc3ce..1eef4beb9 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -384,6 +384,14 @@ scala_junit_test_test_filter(){ done } +scala_junit_test_test_filter_custom_runner(){ + bazel test \ + --nocache_test_results \ + --test_output=streamed \ + '--test_filter=scala.test.junit.JunitCustomRunnerTest#' \ + test:JunitCustomRunner +} + scala_specs2_junit_test_test_filter_everything(){ local output=$(bazel test \ --nocache_test_results \ @@ -756,6 +764,7 @@ $runner scala_library_jar_without_srcs_must_include_filegroup_resources $runner bazel run test/src/main/scala/scala/test/large_classpath:largeClasspath $runner scala_test_test_filters $runner scala_junit_test_test_filter +$runner scala_junit_test_test_filter_custom_runner $runner scala_specs2_junit_test_test_filter_everything $runner scala_specs2_junit_test_test_filter_one_test $runner scala_specs2_junit_test_test_filter_whole_spec From 5095971c30c2338114297649c12258fb9bd6abaa Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sat, 19 May 2018 08:06:13 +0300 Subject: [PATCH 18/29] Upgrade bazel travis to 0.12.0 (#505) --- .travis.yml | 6 +++--- test_rules_scala.sh | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a63c5ddef..09da269d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ os: env: # we want to test the last release - - V=0.11.1 TEST_SCRIPT=test_rules_scala.sh - - V=0.11.1 TEST_SCRIPT=test_intellij_aspect.sh - - V=0.11.1 TEST_SCRIPT=test_reproducibility.sh + - V=0.12.0 TEST_SCRIPT=test_rules_scala.sh + - V=0.12.0 TEST_SCRIPT=test_intellij_aspect.sh + - V=0.12.0 TEST_SCRIPT=test_reproducibility.sh before_install: - | diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 1eef4beb9..e84959294 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -150,9 +150,11 @@ test_scala_library_expect_failure_on_missing_direct_deps_warn_mode() { test_scala_library_expect_failure_on_missing_direct_java() { dependency_target='//test_expect_failure/missing_direct_deps/internal_deps:transitive_dependency' + #since bazel 0.12.0 the labels are only emmitted if ijar is in play + dependency_file='test_expect_failure/missing_direct_deps/internal_deps/transitive_dependency_ijar.jar' test_target='//test_expect_failure/missing_direct_deps/internal_deps:transitive_dependency_java_user' - expected_message="$dependency_target[ \t]*to[ \t]*$test_target" + expected_message="$dependency_file.*$test_target" test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" $test_target "--strict_java_deps=error" } @@ -169,9 +171,10 @@ test_scala_library_expect_better_failure_message_on_missing_transitive_dependenc test_scala_library_expect_failure_on_missing_direct_deps_warn_mode_java() { dependency_target='//test_expect_failure/missing_direct_deps/internal_deps:transitive_dependency' + dependency_file='test_expect_failure/missing_direct_deps/internal_deps/transitive_dependency_ijar.jar' test_target='//test_expect_failure/missing_direct_deps/internal_deps:transitive_dependency_java_user' - local expected_message="buildozer 'add deps $dependency_target ' $test_target" + local expected_message="$dependency_file.*$test_target" test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message "${expected_message}" ${test_target} "--strict_java_deps=warn" "ne" } From 1e1e365aa5bfa582c57157ea7e59ef42604507de Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sun, 20 May 2018 15:48:59 +0300 Subject: [PATCH 19/29] flatten depset of transitive proto paths (currently broken accumulation) --- scala_proto/scala_proto.bzl | 2 +- test_rules_scala.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index 8887ad301..d22e22c90 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -351,7 +351,7 @@ def _gen_proto_srcjar_impl(ctx): # Command line args to worker cannot be empty so using padding flags_arg = "-" + ",".join(ctx.attr.flags), # Command line args to worker cannot be empty so using padding - packages = "-" + ":".join(transitive_proto_paths) + packages = "-" + ":".join(depset(transitive = transitive_proto_paths).to_list()) ) argfile = ctx.actions.declare_file("%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) ctx.actions.write(output=argfile, content=worker_content) diff --git a/test_rules_scala.sh b/test_rules_scala.sh index e84959294..3dec143b7 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -805,3 +805,4 @@ $runner test_scala_import_library_passes_labels_of_direct_deps $runner java_toolchain_javacopts_are_used $runner bazel run test/src/main/scala/scala/test/classpath_resources:classpath_resource $runner test_scala_classpath_resources_expect_warning_on_namespace_conflict +$runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off \ No newline at end of file From f8891f468157be3b5850619cf33908084ce201ea Mon Sep 17 00:00:00 2001 From: Oscar Boykin Date: Sun, 27 May 2018 15:45:12 -1000 Subject: [PATCH 20/29] Remove some old java_common checks --- scala/private/common.bzl | 37 ++++++++++++------------------------ scala/private/rule_impls.bzl | 29 +++++++++------------------- scala/scala_import.bzl | 26 +++++++++---------------- 3 files changed, 30 insertions(+), 62 deletions(-) diff --git a/scala/private/common.bzl b/scala/private/common.bzl index 493071cd5..761dd5f57 100644 --- a/scala/private/common.bzl +++ b/scala/private/common.bzl @@ -28,8 +28,8 @@ def _collect_jars_when_dependency_analyzer_is_off(dep_targets): runtime_jars = [] for dep_target in dep_targets: - if java_common.provider in dep_target: - java_provider = dep_target[java_common.provider] + if JavaInfo in dep_target: + java_provider = dep_target[JavaInfo] compile_jars.append(java_provider.compile_jars) runtime_jars.append(java_provider.transitive_runtime_jars) else: @@ -53,8 +53,8 @@ def _collect_jars_when_dependency_analyzer_is_on(dep_targets): current_dep_compile_jars = None current_dep_transitive_compile_jars = None - if java_common.provider in dep_target: - java_provider = dep_target[java_common.provider] + if JavaInfo in dep_target: + java_provider = dep_target[JavaInfo] current_dep_compile_jars = java_provider.compile_jars current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars runtime_jars.append(java_provider.transitive_runtime_jars) @@ -117,25 +117,12 @@ def _label_already_exists(jars2labels, jar): def _provider_of_dependency_contains_label_of(dependency, jar): return hasattr(dependency, "jars_to_labels") and jar.path in dependency.jars_to_labels +# TODO this seems to have limited value now that JavaInfo has everything def create_java_provider(scalaattr, transitive_compile_time_jars): - # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java - # toolchain. Fortunately, the same change that added this requirement also - # added this field to the Java provider so we can use it to test which - # Bazel version we are running under. - test_provider = java_common.create_provider() - - if hasattr(test_provider, "full_compile_jars"): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = scalaattr.compile_jars, - runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), - transitive_runtime_jars = scalaattr.transitive_runtime_jars, - ) - else: - return java_common.create_provider( - compile_time_jars = scalaattr.compile_jars, - runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = transitive_compile_time_jars, - transitive_runtime_jars = scalaattr.transitive_runtime_jars, - ) + return java_common.create_provider( + use_ijar = False, + compile_time_jars = scalaattr.compile_jars, + runtime_jars = scalaattr.transitive_runtime_jars, + transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), + transitive_runtime_jars = scalaattr.transitive_runtime_jars, + ) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index d8df45262..4c5e989d7 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -296,22 +296,11 @@ StatsfileOutput: {statsfile_output} def _interim_java_provider_for_java_compilation(scala_output): - # This is needed because Bazel >=0.7.0 requires ctx.actions and a Java - # toolchain. Fortunately, the same change that added this requirement also - # added this field to the Java provider so we can use it to test which - # Bazel version we are running under. - test_provider = java_common.create_provider() - if hasattr(test_provider, "full_compile_jars"): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = [scala_output], - runtime_jars = [], - ) - else: - return java_common.create_provider( - compile_time_jars = [scala_output], - runtime_jars = [], - ) + return java_common.create_provider( + use_ijar = False, + compile_time_jars = [scala_output], + runtime_jars = [], + ) def try_to_compile_java_jar(ctx, scala_output, @@ -348,8 +337,8 @@ def try_to_compile_java_jar(ctx, def collect_java_providers_of(deps): providers = [] for dep in deps: - if java_common.provider in dep: - providers.append(dep[java_common.provider]) + if JavaInfo in dep: + providers.append(dep[JavaInfo]) return providers def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation): @@ -474,8 +463,8 @@ def _collect_runtime_jars(dep_targets): runtime_jars = [] for dep_target in dep_targets: - if java_common.provider in dep_target: - runtime_jars.append(dep_target[java_common.provider].transitive_runtime_jars) + if JavaInfo in dep_target: + runtime_jars.append(dep_target[JavaInfo].transitive_runtime_jars) else: # support http_file pointed at a jar. http_jar uses ijar, # which breaks scala macros diff --git a/scala/scala_import.bzl b/scala/scala_import.bzl index 67727509b..c51221752 100644 --- a/scala/scala_import.bzl +++ b/scala/scala_import.bzl @@ -24,20 +24,11 @@ def _scala_import_impl(ctx): ], ) def _create_provider(current_target_compile_jars, transitive_runtime_jars, jars, exports): - test_provider = java_common.create_provider() - if hasattr(test_provider, "full_compile_jars"): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = depset(transitive = [current_target_compile_jars, exports.compile_jars]), - transitive_compile_time_jars = depset(transitive = [jars.transitive_compile_jars, current_target_compile_jars, exports.transitive_compile_jars]) , - transitive_runtime_jars = depset(transitive = [transitive_runtime_jars, jars.transitive_runtime_jars, current_target_compile_jars, exports.transitive_runtime_jars]) , - ) - else: - return java_common.create_provider( - compile_time_jars = current_target_compile_jars, - runtime_jars = transitive_runtime_jars + jars.transitive_runtime_jars, - transitive_compile_time_jars = jars.transitive_compile_jars + current_target_compile_jars, - transitive_runtime_jars = transitive_runtime_jars + jars.transitive_runtime_jars + current_target_compile_jars, + return java_common.create_provider( + use_ijar = False, + compile_time_jars = depset(transitive = [current_target_compile_jars, exports.compile_jars]), + transitive_compile_time_jars = depset(transitive = [jars.transitive_compile_jars, current_target_compile_jars, exports.transitive_compile_jars]) , + transitive_runtime_jars = depset(transitive = [transitive_runtime_jars, jars.transitive_runtime_jars, current_target_compile_jars, exports.transitive_runtime_jars]) , ) def _add_labels_of_current_code_jars(code_jars, label, jars2labels): @@ -66,13 +57,14 @@ def _filter_out_non_code_jars(files): def _is_source_jar(file): return file.basename.endswith("-sources.jar") +# TODO: it seems this could be reworked to use java_common.merge def _collect(deps): transitive_compile_jars = [] runtime_jars = [] compile_jars = [] for dep_target in deps: - java_provider = dep_target[java_common.provider] + java_provider = dep_target[JavaInfo] compile_jars.append(java_provider.compile_jars) transitive_compile_jars.append(java_provider.transitive_compile_time_jars) runtime_jars.append(java_provider.transitive_runtime_jars) @@ -83,7 +75,7 @@ def _collect(deps): def _collect_labels(deps, jars2labels): for dep_target in deps: - java_provider = dep_target[java_common.provider] + java_provider = dep_target[JavaInfo] _transitively_accumulate_labels(dep_target, java_provider,jars2labels) def _transitively_accumulate_labels(dep_target, java_provider, jars2labels): @@ -96,7 +88,7 @@ def _transitively_accumulate_labels(dep_target, java_provider, jars2labels): def _collect_runtime(runtime_deps): jar_deps = [] for dep_target in runtime_deps: - java_provider = dep_target[java_common.provider] + java_provider = dep_target[JavaInfo] jar_deps.append(java_provider.transitive_runtime_jars) return depset(transitive = jar_deps) From 861d4faab281a42f79922b087a026b88a22c20b3 Mon Sep 17 00:00:00 2001 From: Igal Tabachnik Date: Wed, 30 May 2018 19:01:34 +0300 Subject: [PATCH 21/29] Prevent exception in static initializers in specs2 tests taking down the test runner (#500) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adding main_class from —define, if exists * Returning an empty description in case of exception * Moving failing test to its proper location --- .../specs2/Specs2RunnerBuilder.scala | 9 +++++ test_expect_failure/scala_junit_test/BUILD | 9 ++++- .../scala_junit_test/specs2/FailingTest.scala | 10 ++++++ test_rules_scala.sh | 35 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test_expect_failure/scala_junit_test/specs2/FailingTest.scala diff --git a/src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala b/src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala index 9f4f8e03c..9119d8011 100644 --- a/src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala +++ b/src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala @@ -34,6 +34,15 @@ class Specs2PrefixSuffixTestDiscoveringSuite(suite: Class[Any], runnerBuilder: R override def getName: String = "Aggregate Specs2 Test Suite" + override def getDescription: Description = { + lazy val emptySuiteDescription = { + val description = Description.createSuiteDescription(getName) + description.addChild(Description.EMPTY) + description + } + Try(super.getDescription).getOrElse(emptySuiteDescription) + } + override def getChildren: util.List[Runner] = super.getChildren.asScala .collect { diff --git a/test_expect_failure/scala_junit_test/BUILD b/test_expect_failure/scala_junit_test/BUILD index 32bef98b4..0491df576 100644 --- a/test_expect_failure/scala_junit_test/BUILD +++ b/test_expect_failure/scala_junit_test/BUILD @@ -1,4 +1,4 @@ -load("//scala:scala.bzl", "scala_junit_test") +load("//scala:scala.bzl", "scala_junit_test", "scala_specs2_junit_test") scala_junit_test( name = "failing_test", @@ -16,4 +16,11 @@ scala_junit_test( srcs = ["JunitTest.scala"], suffixes = ["DoesNotMatch"], size = "small", +) + +scala_specs2_junit_test( + name = "specs2_failing_test", + srcs = ["specs2/FailingTest.scala"], + suffixes = ["Test"], + size = "small", ) \ No newline at end of file diff --git a/test_expect_failure/scala_junit_test/specs2/FailingTest.scala b/test_expect_failure/scala_junit_test/specs2/FailingTest.scala new file mode 100644 index 000000000..6999e0016 --- /dev/null +++ b/test_expect_failure/scala_junit_test/specs2/FailingTest.scala @@ -0,0 +1,10 @@ +package scala.test.junit.specs2 + +import org.specs2.mutable.SpecWithJUnit + +class FailingTest extends SpecWithJUnit { + + val boom: String = { throw new Exception("Boom") } + + "some test" >> { boom must beEmpty } +} \ No newline at end of file diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 3dec143b7..47e69ce74 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -46,6 +46,32 @@ test_scala_library_suite() { action_should_fail build test_expect_failure/scala_library_suite:library_suite_dep_on_children } +test_expect_failure_with_message() { + set +e + + expected_message=$1 + test_filter=$2 + test_command=$3 + + command="bazel test --nocache_test_results --test_output=streamed ${test_filter} ${test_command}" + output=$(${command} 2>&1) + + echo ${output} | grep "$expected_message" + if [ $? -ne 0 ]; then + echo "'bazel test ${test_command}' should have logged \"${expected_message}\"." + exit 1 + fi + if [ "${additional_expected_message}" != "" ]; then + echo ${output} | grep "$additional_expected_message" + if [ $? -ne 0 ]; then + echo "'bazel test ${test_command}' should have logged \"${additional_expected_message}\"." + exit 1 + fi + fi + + set -e +} + test_expect_failure_or_warning_on_missing_direct_deps_with_expected_message() { set +e @@ -571,6 +597,14 @@ scala_specs2_junit_test_test_filter_match_multiple_methods(){ done } + +scala_specs2_exception_in_initializer_without_filter(){ + expected_message="org.specs2.control.UserException: cannot create an instance for class scala.test.junit.specs2.FailingTest" + test_command="test_expect_failure/scala_junit_test:specs2_failing_test" + + test_expect_failure_with_message "$expected_message" $test_filter $test_command +} + scalac_jvm_flags_are_configured(){ action_should_fail build //test_expect_failure/compilers_jvm_flags:can_configure_jvm_flags_for_scalac } @@ -775,6 +809,7 @@ $runner scala_specs2_junit_test_test_filter_exact_match $runner scala_specs2_junit_test_test_filter_exact_match_unsafe_characters $runner scala_specs2_junit_test_test_filter_exact_match_escaped_and_sanitized $runner scala_specs2_junit_test_test_filter_match_multiple_methods +$runner scala_specs2_exception_in_initializer_without_filter $runner scalac_jvm_flags_are_configured $runner javac_jvm_flags_are_configured $runner javac_jvm_flags_via_javacopts_are_configured From 5340847e372d3e2fcf56e2b7521118d95384e057 Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sat, 2 Jun 2018 22:38:28 +0300 Subject: [PATCH 22/29] expose scala binary jars in build even protocol --- scala/private/rule_impls.bzl | 1 - test_rules_scala.sh | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 4c5e989d7..095e8d4d8 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -594,7 +594,6 @@ def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2l java_provider = create_java_provider(scalaattr, transitive_compile_time_jars) return struct( - files=depset([ctx.outputs.executable]), providers = [java_provider], scala = scalaattr, transitive_rjars = rjars, #calling rules need this for the classpath in the launcher diff --git a/test_rules_scala.sh b/test_rules_scala.sh index 47e69ce74..fcc667730 100755 --- a/test_rules_scala.sh +++ b/test_rules_scala.sh @@ -761,6 +761,34 @@ test_scala_classpath_resources_expect_warning_on_namespace_conflict() { fi } +scala_binary_common_jar_is_exposed_in_build_event_protocol() { + local target=$1 + set +e + bazel build test:$target --build_event_text_file=$target_bes.txt + cat $target_bes.txt | grep "test/$target.jar" + if [ $? -ne 0 ]; then + echo "test/$target.jar was not found in build event protocol:" + cat $target_bes.txt + rm $target_bes.txt + exit 1 + fi + + rm $target_bes.txt + set -e +} + +scala_binary_jar_is_exposed_in_build_event_protocol() { + scala_binary_common_jar_is_exposed_in_build_event_protocol ScalaLibBinary +} + +scala_test_jar_is_exposed_in_build_event_protocol() { + scala_binary_common_jar_is_exposed_in_build_event_protocol HelloLibTest +} + +scala_junit_test_jar_is_exposed_in_build_event_protocol() { + scala_binary_common_jar_is_exposed_in_build_event_protocol JunitTestWithDeps +} + dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) # shellcheck source=./test_runner.sh . "${dir}"/test_runner.sh @@ -840,4 +868,7 @@ $runner test_scala_import_library_passes_labels_of_direct_deps $runner java_toolchain_javacopts_are_used $runner bazel run test/src/main/scala/scala/test/classpath_resources:classpath_resource $runner test_scala_classpath_resources_expect_warning_on_namespace_conflict -$runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off \ No newline at end of file +$runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off +$runner scala_binary_jar_is_exposed_in_build_event_protocol +$runner scala_test_jar_is_exposed_in_build_event_protocol +$runner scala_junit_test_jar_is_exposed_in_build_event_protocol \ No newline at end of file From a5515d78dd1d2f8b97755386ee5e34befa6985da Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Fri, 8 Jun 2018 12:27:15 +0300 Subject: [PATCH 23/29] update protobuf version (#507) * update protobuf version * Update WORKSPACE * Update WORKSPACE --- WORKSPACE | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index aa10fc7cd..31e23dbc9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -58,16 +58,16 @@ maven_jar( http_archive( name = "com_google_protobuf", - urls = ["https://github.com/google/protobuf/archive/b04e5cba356212e4e8c66c61bbe0c3a20537c5b9.zip"], - strip_prefix = "protobuf-b04e5cba356212e4e8c66c61bbe0c3a20537c5b9", - sha256 = "cf4a434ac3a83040e9f65be92e153d00d075d8cd25e3f6c6d8670879f5796aa0", + urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], + strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", + sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163", ) http_archive( name = "com_google_protobuf_java", - urls = ["https://github.com/google/protobuf/archive/b04e5cba356212e4e8c66c61bbe0c3a20537c5b9.zip"], - strip_prefix = "protobuf-b04e5cba356212e4e8c66c61bbe0c3a20537c5b9", - sha256 = "cf4a434ac3a83040e9f65be92e153d00d075d8cd25e3f6c6d8670879f5796aa0", + urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], + strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", + sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163", ) new_local_repository( From 52813b7d25679a0b6a521271ba15b02ff1e2134c Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Fri, 8 Jun 2018 13:10:48 +0300 Subject: [PATCH 24/29] Update Travis to run with Bazel 0.13.0 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09da269d0..dac0c3d6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ os: env: # we want to test the last release - - V=0.12.0 TEST_SCRIPT=test_rules_scala.sh - - V=0.12.0 TEST_SCRIPT=test_intellij_aspect.sh - - V=0.12.0 TEST_SCRIPT=test_reproducibility.sh + - V=0.13.0 TEST_SCRIPT=test_rules_scala.sh + - V=0.13.0 TEST_SCRIPT=test_intellij_aspect.sh + - V=0.13.0 TEST_SCRIPT=test_reproducibility.sh before_install: - | From 40151843d9be877048f187fd2f627c1eccfb3b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Mon, 11 Jun 2018 21:52:17 -0700 Subject: [PATCH 25/29] Format BUILD files and check format during CI (#489) * Add lint script from bazel-integrationtesting * Check linting in Travis * Ignore git directories and skip skylint in linter * Apply formatting fixes * Add linting details to contributor notes --- .travis.yml | 1 + CONTRIBUTING.md | 14 +- README.md | 4 + WORKSPACE | 71 +- jmh/jmh.bzl | 52 +- junit/junit.bzl | 10 +- lint.sh | 293 +++++ private/BUILD | 5 + private/format.bzl | 90 ++ scala/BUILD | 18 +- scala/private/common.bzl | 131 +- scala/private/rule_impls.bzl | 1062 ++++++++-------- scala/providers.bzl | 50 +- scala/scala.bzl | 500 +++++--- scala/scala_cross_version.bzl | 1 - scala/scala_import.bzl | 122 +- scala/scala_maven_import_external.bzl | 131 +- scala/scala_toolchain.bzl | 12 +- scala/support/BUILD | 41 +- scala/toolchains.bzl | 3 +- scala_proto/scala_proto.bzl | 811 ++++++------ specs2/BUILD | 21 +- specs2/specs2.bzl | 21 +- specs2/specs2_junit.bzl | 18 +- src/java/com/google/devtools/build/lib/BUILD | 8 +- .../devtools/build/lib/WorkerProtocol.java | 1085 +++++++++-------- src/java/io/bazel/rulesscala/io_utils/BUILD | 2 +- .../io_utils/DeleteRecursively.java | 31 +- src/java/io/bazel/rulesscala/jar/BUILD | 24 +- .../io/bazel/rulesscala/jar/JarCreator.java | 85 +- .../io/bazel/rulesscala/jar/JarHelper.java | 14 +- .../bazel/rulesscala/scala_test/Runner.java | 55 +- src/java/io/bazel/rulesscala/scalac/BUILD | 10 +- .../rulesscala/scalac/CompileOptions.java | 101 +- .../rulesscala/scalac/ScalaCInvoker.java | 13 +- .../rulesscala/scalac/ScalacProcessor.java | 208 ++-- src/java/io/bazel/rulesscala/specs2/BUILD | 15 +- .../io/bazel/rulesscala/test_discovery/BUILD | 3 +- src/java/io/bazel/rulesscala/worker/BUILD | 19 +- .../rulesscala/worker/GenericWorker.java | 33 +- src/scala/scripts/BUILD | 6 +- test/BUILD | 226 ++-- test/aspect/aspect.bzl | 108 +- test/check_statsfile.bzl | 32 +- test/data/BUILD | 6 +- test/gen_src/BUILD | 12 +- test/jar_lister.py | 2 +- test/jmh/BUILD | 10 +- test/jmh/JavaType.java | 4 +- test/proto/BUILD | 35 +- test/src/main/resources/scala/test/BUILD | 8 +- .../scala/test/classpath_resource1/BUILD | 2 +- .../scala/test/classpath_resource2/BUILD | 2 +- .../scala/test/classpath_resources/BUILD | 10 +- test/src/main/scala/scala/test/ijar/BUILD | 18 +- test/src/main/scala/scala/test/ijar/C.java | 12 +- .../scala/test/junit/JunitCustomRunner.java | 23 +- .../scala/scala/test/junit/JunitJavaTest.java | 5 +- .../scala/scala/test/large_classpath/BUILD | 12 +- .../scala/test/large_classpath/helper.bzl | 6 +- .../scala/scala/test/mix_java_scala/Baz.java | 3 +- .../scala/test/mix_java_scala/FooBar.java | 3 +- .../scala/scala/test/only_java/Alpha.java | 9 +- .../src/main/scala/scala/test/resources/BUILD | 27 +- .../scala/scala/test/resources/strip/BUILD | 12 +- .../main/scala/scala/test/scala_import/BUILD | 72 +- .../scala/test/sources_jars_in_deps/BUILD | 10 +- test/src/main/scala/scala/test/srcjars/BUILD | 18 +- .../scala/scala/test/srcjars_with_java/BUILD | 2 +- .../test/srcjars_with_java/JavaSource.java | 4 +- .../test/strict_deps/no_recompilation/BUILD | 23 +- .../scala/scala/test/twitter_scrooge/BUILD | 211 ++-- .../twitter_scrooge/prefix_test/a/b/c/d/BUILD | 18 +- .../prefix_test/e/f/b/c/d/BUILD | 25 +- .../scala/test/twitter_scrooge/thrift/BUILD | 23 +- .../thrift/bare_jar_thrifts/BUILD | 20 +- .../thrift/bare_jar_thrifts/bare_jar_1/BUILD | 12 +- .../thrift/bare_jar_thrifts/bare_jar_2/BUILD | 12 +- .../test/twitter_scrooge/thrift/thrift2/BUILD | 18 +- .../thrift/thrift2/thrift3/BUILD | 8 +- .../thrift/thrift2/thrift4/BUILD | 14 +- .../scala/test/utf8/JavaClassWithUtf8.java | 2 +- test/tut/BUILD | 6 +- .../compilers_javac_opts/BUILD | 14 +- ...inceJavaToolchainAddsAnInvalidJvmFlag.java | 3 +- test_expect_failure/compilers_jvm_flags/BUILD | 48 +- .../WillNotCompileJavaSinceXmxTooLow.java | 2 +- test_expect_failure/disappearing_class/BUILD | 1 - .../mismatching_resource_strip_prefix/BUILD | 6 +- .../missing_direct_deps/external_deps/BUILD | 27 +- .../missing_direct_deps/internal_deps/BUILD | 77 +- ...ibraryHasCustomJavaProviderDependency.java | 3 +- .../internal_deps/Placeholder.java | 4 +- .../internal_deps/User.java | 9 +- .../internal_deps/custom-jvm-rule.bzl | 25 +- .../proto_source_root/user/BUILD | 10 +- test_expect_failure/scala_import/BUILD | 46 +- test_expect_failure/scala_junit_test/BUILD | 12 +- test_expect_failure/scala_library_suite/BUILD | 1 + .../scalacopts_from_toolchain/BUILD | 10 +- .../transitive/java_to_scala/BUILD | 6 +- .../transitive/java_to_scala/D.java | 6 +- .../transitive/scala_to_java/BUILD | 4 +- .../transitive/scala_to_scala/BUILD | 4 +- test_lint.sh | 5 + third_party/plugin/src/main/BUILD | 9 +- third_party/plugin/src/test/BUILD | 37 +- thrift/thrift.bzl | 136 ++- tut_rule/tut.bzl | 29 +- twitter_scrooge/twitter_scrooge.bzl | 260 ++-- 110 files changed, 3923 insertions(+), 3150 deletions(-) create mode 100755 lint.sh create mode 100644 private/BUILD create mode 100644 private/format.bzl create mode 100755 test_lint.sh diff --git a/.travis.yml b/.travis.yml index dac0c3d6b..4714ca432 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ os: env: # we want to test the last release + - V=0.13.0 TEST_SCRIPT=test_lint.sh - V=0.13.0 TEST_SCRIPT=test_rules_scala.sh - V=0.13.0 TEST_SCRIPT=test_intellij_aspect.sh - V=0.13.0 TEST_SCRIPT=test_reproducibility.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15fd53d60..b519c2cd9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,4 +27,16 @@ the one above, the [Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). ### Working with Intellij bazel plugin -For your convenience, you can use [this](scripts/ij.bazelproject) .bazelproject file when you setup the bazel plugin in Intellij \ No newline at end of file +For your convenience, you can use [this](scripts/ij.bazelproject) .bazelproject file when you setup the bazel plugin in Intellij + +### Formatting Fixes +Code formatting is checked as part of the CI pipeline. To check/fix formatting +you can use the `lint.sh` script: + +``` +./ling.sh check # check formatting +./lint.sh fix # fix formatting +``` + +Note that Skylint failures are ignored and that the fix +command will modify your files in place. diff --git a/README.md b/README.md index be68a026d..1dd94a715 100644 --- a/README.md +++ b/README.md @@ -628,3 +628,7 @@ bazel test //test/... ``` Note `bazel test //...` will not work since we have a sub-folder on the root folder which is meant to be used in a failure scenario in the integration tests. Similarly to only build you should use `bazel build //src/...` due to that folder. + +## Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md) for more info. diff --git a/WORKSPACE b/WORKSPACE index 31e23dbc9..4b587eb66 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,98 +1,104 @@ workspace(name = "io_bazel_rules_scala") - - load("//scala:scala.bzl", "scala_repositories") + scala_repositories() load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge", "scrooge_scala_library") + twitter_scrooge() load("//tut_rule:tut.bzl", "tut_repositories") + tut_repositories() load("//jmh:jmh.bzl", "jmh_repositories") + jmh_repositories() load("//scala_proto:scala_proto.bzl", "scala_proto_repositories") + scala_proto_repositories() -load("//specs2:specs2_junit.bzl","specs2_junit_repositories") +load("//specs2:specs2_junit.bzl", "specs2_junit_repositories") + specs2_junit_repositories() load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") # test adding a scala jar: maven_jar( - name = "com_twitter__scalding_date", - artifact = scala_mvn_artifact("com.twitter:scalding-date:0.17.0"), - sha1 = "420fb0c4f737a24b851c4316ee0362095710caa5" + name = "com_twitter__scalding_date", + artifact = scala_mvn_artifact("com.twitter:scalding-date:0.17.0"), + 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"), - sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314" + name = "org_typelevel__cats_core", + artifact = scala_mvn_artifact("org.typelevel:cats-core:0.9.0"), + sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314", ) - # test of a plugin maven_jar( - name = "org_psywerx_hairyfotr__linter", - artifact = scala_mvn_artifact("org.psywerx.hairyfotr:linter:0.1.13"), - sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4") + name = "org_psywerx_hairyfotr__linter", + artifact = scala_mvn_artifact("org.psywerx.hairyfotr:linter:0.1.13"), + sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4", +) # test of strict deps (scalac plugin UT + E2E) maven_jar( name = "com_google_guava_guava_21_0_with_file", artifact = "com.google.guava:guava:21.0", - sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709" + sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709", ) maven_jar( name = "org_apache_commons_commons_lang_3_5", artifact = "org.apache.commons:commons-lang3:3.5", - sha1 = "6c6c702c89bfff3cd9e80b04d668c5e190d588c6" + sha1 = "6c6c702c89bfff3cd9e80b04d668c5e190d588c6", ) http_archive( name = "com_google_protobuf", - urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], - strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163", + strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", + urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], ) http_archive( name = "com_google_protobuf_java", - urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], - strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163", + strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457", + urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"], ) new_local_repository( name = "test_new_local_repo", - path = "third_party/test/new_local_repo", - build_file_content = -""" + build_file_content = + """ filegroup( name = "data", srcs = glob(["**/*.txt"]), visibility = ["//visibility:public"], ) -""" +""", + path = "third_party/test/new_local_repo", ) -load("@io_bazel_rules_scala//scala:toolchains.bzl","scala_register_toolchains") +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") + scala_register_toolchains() load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external", "java_import_external") + scala_maven_import_external( name = "com_google_guava_guava_21_0", - licenses = ["notice"], # Apache 2.0 artifact = "com.google.guava:guava:21.0", - server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], jar_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480", + licenses = ["notice"], # Apache 2.0 + server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], ) # bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external @@ -100,11 +106,18 @@ scala_maven_import_external( # the 3rd-party dependency below is using the java_import_external macro # in order to make sure no regression with the original java_import_external load("//scala:scala_maven_import_external.bzl", "java_import_external") + java_import_external( name = "org_apache_commons_commons_lang_3_5_without_file", - licenses = ["notice"], # Apache 2.0 - jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"], + generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file", jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c", + jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"], + licenses = ["notice"], # Apache 2.0 neverlink = True, - generated_linkable_rule_name="linkable_org_apache_commons_commons_lang_3_5_without_file", ) + +## Linting + +load("//private:format.bzl", "format_repositories") + +format_repositories() diff --git a/jmh/jmh.bzl b/jmh/jmh.bzl index 8eeadf6a2..440cd42a7 100644 --- a/jmh/jmh.bzl +++ b/jmh/jmh.bzl @@ -20,13 +20,14 @@ def jmh_repositories(): actual = '@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_asm//jar', ) native.maven_jar( - name = "io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection", - artifact = "org.openjdk.jmh:jmh-generator-reflection:1.20", - sha1 = "f2154437b42426a48d5dac0b3df59002f86aed26", + name = "io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection", + artifact = "org.openjdk.jmh:jmh-generator-reflection:1.20", + sha1 = "f2154437b42426a48d5dac0b3df59002f86aed26", ) native.bind( - name = 'io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection', - actual = '@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection//jar', + name = 'io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection', + actual = + '@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection//jar', ) native.maven_jar( name = "io_bazel_rules_scala_org_ows2_asm_asm", @@ -43,7 +44,8 @@ def jmh_repositories(): sha1 = "cdd846cfc4e0f7eefafc02c0f5dce32b9303aa2a", ) native.bind( - name = "io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple", + name = + "io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple", actual = '@io_bazel_rules_scala_net_sf_jopt_simple_jopt_simple//jar', ) native.maven_jar( @@ -52,7 +54,8 @@ def jmh_repositories(): sha1 = "e4ba98f1d4b3c80ec46392f25e094a6a2e58fcbf", ) native.bind( - name = "io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3", + name = + "io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3", actual = '@io_bazel_rules_scala_org_apache_commons_commons_math3//jar', ) @@ -73,16 +76,26 @@ def _scala_generate_benchmark(ctx): outputs = [ctx.outputs.src_jar, ctx.outputs.resource_jar], inputs = depset([class_jar], transitive = [classpath]), executable = ctx.executable._generator, - arguments = [ctx.attr.generator_type] + [f.path for f in [class_jar, ctx.outputs.src_jar, ctx.outputs.resource_jar] + classpath.to_list()], + arguments = [ctx.attr.generator_type] + [ + f.path + for f in [class_jar, ctx.outputs.src_jar, ctx.outputs.resource_jar] + + classpath.to_list() + ], progress_message = "Generating benchmark code for %s" % ctx.label, ) scala_generate_benchmark = rule( implementation = _scala_generate_benchmark, attrs = { - "src": attr.label(allow_single_file=True, mandatory=True), - "generator_type": attr.string(default='reflection', mandatory=False), - "_generator": attr.label(executable=True, cfg="host", default=Label("//src/scala/io/bazel/rules_scala/jmh_support:benchmark_generator")) + "src": attr.label(allow_single_file = True, mandatory = True), + "generator_type": attr.string( + default = 'reflection', mandatory = False), + "_generator": attr.label( + executable = True, + cfg = "host", + default = Label( + "//src/scala/io/bazel/rules_scala/jmh_support:benchmark_generator" + )) }, outputs = { "src_jar": "%{name}.srcjar", @@ -112,7 +125,8 @@ def scala_benchmark_jmh(**kw): ) codegen = name + "_codegen" - scala_generate_benchmark(name=codegen, src=lib, generator_type=generator_type) + scala_generate_benchmark( + name = codegen, src = lib, generator_type = generator_type) compiled_lib = name + "_compiled_benchmark_lib" scala_library( name = compiled_lib, @@ -124,11 +138,11 @@ def scala_benchmark_jmh(**kw): resource_jars = ["%s_resources.jar" % codegen], ) scala_binary( - name = name, - deps = [ - "//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple", - "//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3", - compiled_lib, - ], - main_class = main_class, + name = name, + deps = [ + "//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple", + "//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3", + compiled_lib, + ], + main_class = main_class, ) diff --git a/junit/junit.bzl b/junit/junit.bzl index c41c4e9cf..b6774c5b5 100644 --- a/junit/junit.bzl +++ b/junit/junit.bzl @@ -4,11 +4,15 @@ def junit_repositories(): artifact = "junit:junit:4.12", sha1 = "2973d150c0dc1fefe998f834810d68f278ea58ec", ) - native.bind(name = 'io_bazel_rules_scala/dependency/junit/junit', actual = '@io_bazel_rules_scala_junit_junit//jar') - + native.bind( + name = 'io_bazel_rules_scala/dependency/junit/junit', + actual = '@io_bazel_rules_scala_junit_junit//jar') + native.maven_jar( name = "io_bazel_rules_scala_org_hamcrest_hamcrest_core", artifact = "org.hamcrest:hamcrest-core:1.3", sha1 = "42a25dc3219429f0e5d060061f71acb49bf010a0", ) - native.bind(name = 'io_bazel_rules_scala/dependency/hamcrest/hamcrest_core', actual = '@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar') + native.bind( + name = 'io_bazel_rules_scala/dependency/hamcrest/hamcrest_core', + actual = '@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar') diff --git a/lint.sh b/lint.sh new file mode 100755 index 000000000..f3fbf7026 --- /dev/null +++ b/lint.sh @@ -0,0 +1,293 @@ +#!/bin/bash +# Copyright 2018 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. + +set -eou pipefail + +# Usage +# ===== +# +# - to lint/check conformance to style and best practice of all the files in +# the current working directory: "./lint.sh" or "./lint.sh check". +# - to fix what can be fixed automatically: "./lint.sh fix". +# - to skip a step, e.g. Skylark linting: "FMT_SKYLINT=false ./lint.sh check". +# +# +# Linters/formatters featured here +# ================================ +# +# - google-java-format: Java code +# - buildifier: BUILD/WORKSPACE files +# - skylint: Skylark files (*.bzl) - check only +# - yapf: Skylark and Python files +# +# +# An important note concerning trailing commas +# ============================================ +# +# Yapf could generate during fixing this Skylark one-liner: +# ``` +# foo = rule(attrs = {"hello": attr.string()}, implementation = _impl) +# ``` +# from some perfectly normal-looking code: +# ``` +# foo = rule( +# implementation = _impl, +# attrs = { +# "hello": attr.string() +# } +# ) +# ``` +# but this reformatting is not expected to pass validation. What is missing +# is trailing commas, after the last argument to `rule` and after the last +# element of the dictionary. If those are put: +# ``` +# foo = rule( +# implementation = _impl, +# attrs = { +# "hello": attr.string(), +# }, +# ) +# ``` +# then our configuration of Yapf won't touch anything. +# +# +# Implementation details: Why we need Buildifier, Skylint and Yapf +# ================================================================ +# +# Why do we need Buildifier, Skylint and Yapf to validate Bazel/Skylark files? +# Skylark is after all only a dialect of Python! The reasons are as follows: +# +# - Buildifier can fix BUILD/WORKSPACE files but breaks *.bzl files when it attempts +# to fix them. +# +# - Yapf is the only utility used here that can fix *.bzl files because it understands Python +# fully and not only a special subset of it. +# +# - However, Yapf does not enforce certain conventions that people have in *.bzl files, +# related to the fact that they are used to enrich BUILD files. That's where +# Buildifier comes in handy. For instance, Yapf could generate this one-liner: +# ``` +# foo = rule(implementation = _impl, attrs = {"hello": attr.string()}) +# ``` +# but this is an error for Buildifier, as it expects every keyword argument +# to be on their own line as well as the attribute dictionary to be split, and the +# `attrs` argument to come before the `implementation` argument (alphabetical order). +# By running Buildifier after Yapf, we ensure that these conventions are respected. +# Here, to force Yapf to split the arguments and the dictionary, we can add a comma after +# the last argument/element. Moreover, Yapf does not reorder keywords. Overall, +# if we supply this snippet to Yapf: +# ``` +# foo = rule(attrs = {"hello": attr.string(),}, implementation = _impl,) +# ``` +# we'll end up, after fixing, with: +# ``` +# foo = rule( +# attrs = { +# "hello": attr.string(), +# }, +# implementation = _impl, +# ) +# ``` +# which passes the Buildifier validation. +# +# - Buildifier only validates *.bzl files with respect to their likeness to BUILD files. +# To validate the semantic specific to Skylark files and ensure good practices are followed +# (documentation, unused imports, ...), Skylint can be used. Skylint only operates in "check" +# mode, it cannot fix anything on its own. (On an unrelated note, Pylint gives meaningless +# results when applied to Skylark files, so that's why Skylint is used here.) +# +# - Overall, this sauce has been chosen because it gives an automatic formatting and +# linting warnings that feel natural for Skylark. + +BASE="$(pwd)" +MODE="${1:-check}" + +if [ "$MODE" = "check" ]; then + JAVA_OPTIONS=--dry-run + BUILDIFIER_MODE=check + YAPF_OPTIONS=--diff +else + YAPF_OPTIONS=--in-place + JAVA_OPTIONS=--replace + BUILDIFIER_MODE=fix +fi + +BAZEL_BIN=$(bazel info bazel-bin) +BAZEL_OUTPUT_BASE=$(bazel info output_base) + +function build() { + # NOTE: if and when the Skylink target becomes public, use a sh_binary instead + # of building everything here? + bazel build --color=yes --show_progress_rate_limit=30 \ + @io_bazel//src/tools/skylark/java/com/google/devtools/skylark/skylint:Skylint \ + //private:java_format \ + @com_github_google_yapf//:yapf \ + @io_bazel_buildifier_linux//file \ + @io_bazel_buildifier_darwin//file +} + +function format_py_like() { + local PATTERN=$1 + local STYLE=$(cat) + local OUTPUT + + OUTPUT=$(find "$BASE" \ + -not \( -path $BASE/.git -prune \) \ + -name "$PATTERN" -exec "$BAZEL_BIN/external/com_github_google_yapf/yapf/yapf" \ + $YAPF_OPTIONS \ + "--style=$STYLE" \ + {} \;) + if [ $? != 0 ]; then + return 1 + fi + if [ "$MODE" = "check" ] && [ ! -z "$OUTPUT" ]; then + echo "$OUTPUT" + return 1 + fi +} + +function format_skylark() { + format_py_like "*.bzl" <<'EOF' +{ + based_on_style: google, + spaces_around_default_or_named_assign: True, + blank_lines_around_top_level_definition: 1, + indent_width: 2, + allow_split_before_dict_value: False, + each_dict_entry_on_separate_line: True, + split_arguments_when_comma_terminated: True, +} +EOF +} + +function format_python() { + format_py_like "*.py" <<'EOF' +{ + based_on_style: google, + spaces_around_default_or_named_assign: True, + blank_lines_around_top_level_definition: 2, + indent_width: 2, + indent_dictionary_value: True +} +EOF +} + +function format_bazel() { + if [ "$(uname)" = "Darwin" ]; then + BUILDIFIER=$BAZEL_OUTPUT_BASE/external/io_bazel_buildifier_darwin/file/downloaded + else + BUILDIFIER=$BAZEL_OUTPUT_BASE/external/io_bazel_buildifier_linux/file/downloaded + fi + + ERRORS=0 + $BUILDIFIER -mode=$BUILDIFIER_MODE $( + find "$BASE" \ + -not \( -path $BASE/.git -prune \) \ + -name BUILD -type f) + ERRORS=$((ERRORS+$?)) + $BUILDIFIER -mode=$BUILDIFIER_MODE $( + find "$BASE" \ + -not \( -path $BASE/.git -prune \) \ + -name WORKSPACE -type f) + ERRORS=$((ERRORS+$?)) + + # (buildifier cannot format *.bzl files) + if [ "$MODE" = "check" ] && ! $BUILDIFIER -mode=check $(find "$BASE" -not \( -path $BASE/.git -prune \) -name "*.bzl" -type f) >/dev/null; then + echo "*.bzl BUILDIFIER ERRORS:" + for f in $(find "$BASE" -not \( -path $BASE/.git -prune \) -name "*.bzl" -type f); do + OUTPUT=$($BUILDIFIER -mode=diff $f) + if [ ! -z "$OUTPUT" ]; then + echo "$f" + echo "$OUTPUT" + fi + done + # Some errors are false positives. + echo "(buildifier on *.bzl files: not enforced)" + fi + + if [ $ERRORS != 0 ]; then + echo "Errors: $ERRORS" + return 1 + fi +} + +function format_java() { + local OUTPUT + + OUTPUT=$("$BAZEL_BIN/private/java_format" $JAVA_OPTIONS $( + find "$BASE" \ + -not \( -path $BASE/.git -prune \) \ + -name "*.java" -type f)) + + if [ "$MODE" = "check" ] && [ ! -z "$OUTPUT" ]; then + echo "$OUTPUT" + return 1 + fi +} + +# Skylint only operates in "check" mode, it is a no-op in "fix" mode. +function skylint() { + local OUTPUT + + OUTPUT=$( + find "$BASE" \ + -not \( -path $BASE/.git -prune \) \ + -type f -name "*.bzl" -exec \ + "$BAZEL_BIN/external/io_bazel/src/tools/skylark/java/com/google/devtools/skylark/skylint/Skylint" \ + {} \; + ) + if [ "$MODE" = "check" ] && [ ! -z "$OUTPUT" ]; then + echo "$OUTPUT" + return 1 + fi +} + +SUMMARY="" +OVERALL_RESULT=0 + +function record() { + local SECTION_NAME=$1 + local FUNC=$2 + local DO=$3 + local STATUS + + if ! $DO; then + STATUS="Skipped" + elif eval "$FUNC"; then + STATUS="Ok" + else + STATUS="Failure" + OVERALL_RESULT=1 + fi + + SUMMARY+="$SECTION_NAME $STATUS"$'\n' +} + +function summarize() { + echo "============ SUMMARY ============" + echo "$SUMMARY" + return $OVERALL_RESULT +} + +if "${FMT_PREPARE:-true}"; then + build +fi +record skylark format_skylark "${FMT_SKYLARK:-true}" +record python format_python "${FMT_PYTHON:-true}" +record bazel format_bazel "${FMT_BAZEL:-true}" +record java format_java "${FMT_JAVA:-true}" +SKYLINT="${FMT_SKYLINT:-true}" && [ "$MODE" = "check" ] +record skylint skylint "$SKYLINT" +summarize diff --git a/private/BUILD b/private/BUILD new file mode 100644 index 000000000..e0235a43d --- /dev/null +++ b/private/BUILD @@ -0,0 +1,5 @@ +java_binary( + name = "java_format", + main_class = "com.google.googlejavaformat.java.Main", + runtime_deps = ["@google_java_format"], +) diff --git a/private/format.bzl b/private/format.bzl new file mode 100644 index 000000000..8c4ff6bc0 --- /dev/null +++ b/private/format.bzl @@ -0,0 +1,90 @@ +# Copyright 2018 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. +""" Dependencies for linting/formatting. +""" + +load( + "@bazel_tools//tools/build_defs/repo:http.bzl", + "http_archive", + "http_file", +) +load( + "@bazel_tools//tools/build_defs/repo:java.bzl", + "java_import_external", +) + +def _com_github_google_yapf_repository_impl(rctx): + rctx.download_and_extract( + url = "https://github.com/google/yapf/archive/v0.21.0.tar.gz", + stripPrefix = "yapf-0.21.0") + rctx.file("BUILD", """ +alias( + name="yapf", + actual="//yapf:yapf", + visibility = ["//visibility:public"], +) +""") + rctx.file("yapf/BUILD", """ +py_binary( + name="yapf", + srcs=glob(["**/*.py"]), + main="__main__.py", + visibility = ["//visibility:public"], +)""") + +_com_github_google_yapf_repository = repository_rule( + attrs = {}, + implementation = _com_github_google_yapf_repository_impl, +) + +def format_repositories(): + _com_github_google_yapf_repository(name = "com_github_google_yapf") + + http_archive( + name = "io_bazel", + urls = [ + "https://github.com/bazelbuild/bazel/releases/download/0.11.1/bazel-0.11.1-dist.zip" + ], + sha256 = ( + "e8d762bcc01566fa50952c8028e95cfbe7545a39b8ceb3a0d0d6df33b25b333f"), + ) + + java_import_external( + name = "google_java_format", + licenses = ["notice"], # Apache 2.0 + jar_urls = [ + "https://github.com/google/google-java-format/releases/download/google-java-format-1.5/google-java-format-1.5-all-deps.jar" + ], + jar_sha256 = ("7b839bb7534a173f0ed0cd0e9a583181d20850fcec8cf6e3800e4420a1fad184"), + ) + + http_file( + name = "io_bazel_buildifier_linux", + urls = [ + "https://github.com/bazelbuild/buildtools/releases/download/0.11.1/buildifier" + ], + sha256 = ( + "d7d41def74991a34dfd2ac8a73804ff11c514c024a901f64ab07f45a3cf0cfef"), + executable = True, + ) + + http_file( + name = "io_bazel_buildifier_darwin", + urls = [ + "https://github.com/bazelbuild/buildtools/releases/download/0.11.1/buildifier.osx" + ], + sha256 = ( + "3cbd708ff77f36413cfaef89cd5790a1137da5dfc3d9b3b3ca3fac669fbc298b"), + executable = True, + ) diff --git a/scala/BUILD b/scala/BUILD index f10a1f8a4..06dbacbbf 100644 --- a/scala/BUILD +++ b/scala/BUILD @@ -2,20 +2,18 @@ load("//scala:scala_toolchain.bzl", "scala_toolchain") toolchain_type( name = "toolchain_type", - visibility = ["//visibility:public"] + visibility = ["//visibility:public"], ) - scala_toolchain( - name = 'default_toolchain_impl', - scalacopts = [], - visibility = ["//visibility:public"] + name = "default_toolchain_impl", + scalacopts = [], + visibility = ["//visibility:public"], ) - toolchain( - name = 'default_toolchain', - toolchain_type = '@io_bazel_rules_scala//scala:toolchain_type', - toolchain = ':default_toolchain_impl', - visibility = ["//visibility:public"] + name = "default_toolchain", + toolchain = ":default_toolchain_impl", + toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", + visibility = ["//visibility:public"], ) diff --git a/scala/private/common.bzl b/scala/private/common.bzl index 761dd5f57..c8049cb19 100644 --- a/scala/private/common.bzl +++ b/scala/private/common.bzl @@ -1,27 +1,25 @@ def write_manifest(ctx): - # TODO(bazel-team): I don't think this classpath is what you want - manifest = "Class-Path: \n" - if getattr(ctx.attr, "main_class", ""): - manifest += "Main-Class: %s\n" % ctx.attr.main_class + # TODO(bazel-team): I don't think this classpath is what you want + manifest = "Class-Path: \n" + if getattr(ctx.attr, "main_class", ""): + manifest += "Main-Class: %s\n" % ctx.attr.main_class - ctx.actions.write( - output=ctx.outputs.manifest, - content=manifest) + ctx.actions.write(output = ctx.outputs.manifest, content = manifest) def collect_srcjars(targets): - srcjars = [] - for target in targets: - if hasattr(target, "srcjars"): - srcjars.append(target.srcjars.srcjar) - return depset(srcjars) + srcjars = [] + for target in targets: + if hasattr(target, "srcjars"): + srcjars.append(target.srcjars.srcjar) + return depset(srcjars) def collect_jars(dep_targets, dependency_analyzer_is_off = True): - """Compute the runtime and compile-time dependencies from the given targets""" # noqa + """Compute the runtime and compile-time dependencies from the given targets""" # noqa - if dependency_analyzer_is_off: - return _collect_jars_when_dependency_analyzer_is_off(dep_targets) - else: - return _collect_jars_when_dependency_analyzer_is_on(dep_targets) + if dependency_analyzer_is_off: + return _collect_jars_when_dependency_analyzer_is_off(dep_targets) + else: + return _collect_jars_when_dependency_analyzer_is_on(dep_targets) def _collect_jars_when_dependency_analyzer_is_off(dep_targets): compile_jars = [] @@ -29,16 +27,17 @@ def _collect_jars_when_dependency_analyzer_is_off(dep_targets): for dep_target in dep_targets: if JavaInfo in dep_target: - java_provider = dep_target[JavaInfo] - compile_jars.append(java_provider.compile_jars) - runtime_jars.append(java_provider.transitive_runtime_jars) + java_provider = dep_target[JavaInfo] + compile_jars.append(java_provider.compile_jars) + runtime_jars.append(java_provider.transitive_runtime_jars) else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - compile_jars.append(filter_not_sources(dep_target.files)) - runtime_jars.append(filter_not_sources(dep_target.files)) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + compile_jars.append(filter_not_sources(dep_target.files)) + runtime_jars.append(filter_not_sources(dep_target.files)) - return struct(compile_jars = depset(transitive = compile_jars), + return struct( + compile_jars = depset(transitive = compile_jars), transitive_runtime_jars = depset(transitive = runtime_jars), jars2labels = {}, transitive_compile_jars = depset()) @@ -54,25 +53,28 @@ def _collect_jars_when_dependency_analyzer_is_on(dep_targets): current_dep_transitive_compile_jars = None if JavaInfo in dep_target: - java_provider = dep_target[JavaInfo] - current_dep_compile_jars = java_provider.compile_jars - current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars - runtime_jars.append(java_provider.transitive_runtime_jars) + java_provider = dep_target[JavaInfo] + current_dep_compile_jars = java_provider.compile_jars + current_dep_transitive_compile_jars = java_provider.transitive_compile_time_jars + runtime_jars.append(java_provider.transitive_runtime_jars) else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - current_dep_compile_jars = filter_not_sources(dep_target.files) - current_dep_transitive_compile_jars = filter_not_sources(dep_target.files) - runtime_jars.append(filter_not_sources(dep_target.files)) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + current_dep_compile_jars = filter_not_sources(dep_target.files) + current_dep_transitive_compile_jars = filter_not_sources(dep_target.files) + runtime_jars.append(filter_not_sources(dep_target.files)) compile_jars.append(current_dep_compile_jars) transitive_compile_jars.append(current_dep_transitive_compile_jars) - add_labels_of_jars_to(jars2labels, dep_target, current_dep_transitive_compile_jars.to_list(), current_dep_compile_jars.to_list()) + add_labels_of_jars_to(jars2labels, dep_target, + current_dep_transitive_compile_jars.to_list(), + current_dep_compile_jars.to_list()) - return struct(compile_jars = depset(transitive = compile_jars), - transitive_runtime_jars = depset(transitive = runtime_jars), - jars2labels = jars2labels, - transitive_compile_jars = depset(transitive = transitive_compile_jars)) + return struct( + compile_jars = depset(transitive = compile_jars), + transitive_runtime_jars = depset(transitive = runtime_jars), + jars2labels = jars2labels, + transitive_compile_jars = depset(transitive = transitive_compile_jars)) # When import mavan_jar's for scala macros we have to use the jar:file requirement # since bazel 0.6.0 this brings in the source jar too @@ -86,43 +88,46 @@ def not_sources_jar(name): return "-sources.jar" not in name def filter_not_sources(deps): - return depset([dep for dep in deps.to_list() if not_sources_jar(dep.basename) ]) + return depset( + [dep for dep in deps.to_list() if not_sources_jar(dep.basename)]) def add_labels_of_jars_to(jars2labels, dependency, all_jars, direct_jars): for jar in direct_jars: - _add_label_of_direct_jar_to(jars2labels, dependency, jar) + _add_label_of_direct_jar_to(jars2labels, dependency, jar) for jar in all_jars: - _add_label_of_indirect_jar_to(jars2labels, dependency, jar) + _add_label_of_indirect_jar_to(jars2labels, dependency, jar) def _add_label_of_direct_jar_to(jars2labels, dependency, jar): - jars2labels[jar.path] = dependency.label + jars2labels[jar.path] = dependency.label def _add_label_of_indirect_jar_to(jars2labels, dependency, jar): - if _label_already_exists(jars2labels, jar): - return - - # skylark exposes only labels of direct dependencies. - # to get labels of indirect dependencies we collect them from the providers transitively - if _provider_of_dependency_contains_label_of(dependency, jar): - jars2labels[jar.path] = dependency.jars_to_labels[jar.path] - else: - jars2labels[jar.path] = "Unknown label of file {jar_path} which came from {dependency_label}".format( - jar_path = jar.path, - dependency_label = dependency.label - ) + if _label_already_exists(jars2labels, jar): + return + + # skylark exposes only labels of direct dependencies. + # to get labels of indirect dependencies we collect them from the providers transitively + if _provider_of_dependency_contains_label_of(dependency, jar): + jars2labels[jar.path] = dependency.jars_to_labels[jar.path] + else: + jars2labels[ + jar. + path] = "Unknown label of file {jar_path} which came from {dependency_label}".format( + jar_path = jar.path, dependency_label = dependency.label) def _label_already_exists(jars2labels, jar): return jar.path in jars2labels def _provider_of_dependency_contains_label_of(dependency, jar): - return hasattr(dependency, "jars_to_labels") and jar.path in dependency.jars_to_labels + return hasattr(dependency, + "jars_to_labels") and jar.path in dependency.jars_to_labels # TODO this seems to have limited value now that JavaInfo has everything def create_java_provider(scalaattr, transitive_compile_time_jars): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = scalaattr.compile_jars, - runtime_jars = scalaattr.transitive_runtime_jars, - transitive_compile_time_jars = depset(transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), - transitive_runtime_jars = scalaattr.transitive_runtime_jars, - ) + return java_common.create_provider( + use_ijar = False, + compile_time_jars = scalaattr.compile_jars, + runtime_jars = scalaattr.transitive_runtime_jars, + transitive_compile_time_jars = depset( + transitive = [transitive_compile_time_jars, scalaattr.compile_jars]), + transitive_runtime_jars = scalaattr.transitive_runtime_jars, + ) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 095e8d4d8..21ec1c82b 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -11,18 +11,18 @@ # 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. - """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(":common.bzl", - "add_labels_of_jars_to", - "create_java_provider", - "collect_jars", - "collect_srcjars", - "filter_not_sources", - "not_sources_jar", - "write_manifest", +load( + ":common.bzl", + "add_labels_of_jars_to", + "create_java_provider", + "collect_jars", + "collect_srcjars", + "filter_not_sources", + "not_sources_jar", + "write_manifest", ) _jar_filetype = FileType([".jar"]) @@ -31,170 +31,164 @@ _scala_filetype = FileType([".scala"]) _srcjar_filetype = FileType([".srcjar"]) def _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix): - if not path.startswith(resource_strip_prefix): - fail("Resource file %s is not under the specified prefix to strip" % path) + if not path.startswith(resource_strip_prefix): + fail("Resource file %s is not under the specified prefix to strip" % path) - clean_path = path[len(resource_strip_prefix):] - return resource_strip_prefix, clean_path + clean_path = path[len(resource_strip_prefix):] + return resource_strip_prefix, clean_path def _adjust_resources_path_by_default_prefixes(path): - # Here we are looking to find out the offset of this resource inside - # any resources folder. We want to return the root to the resources folder - # and then the sub path inside it - dir_1, dir_2, rel_path = path.partition("resources") - if rel_path: - return dir_1 + dir_2, rel_path + # Here we are looking to find out the offset of this resource inside + # any resources folder. We want to return the root to the resources folder + # and then the sub path inside it + dir_1, dir_2, rel_path = path.partition("resources") + if rel_path: + return dir_1 + dir_2, rel_path - # The same as the above but just looking for java - (dir_1, dir_2, rel_path) = path.partition("java") - if rel_path: - return dir_1 + dir_2, rel_path + # The same as the above but just looking for java + (dir_1, dir_2, rel_path) = path.partition("java") + if rel_path: + return dir_1 + dir_2, rel_path - return "", path + return "", path def _adjust_resources_path(path, resource_strip_prefix): - if resource_strip_prefix: - return _adjust_resources_path_by_strip_prefix(path,resource_strip_prefix) - else: - return _adjust_resources_path_by_default_prefixes(path) + if resource_strip_prefix: + return _adjust_resources_path_by_strip_prefix(path, resource_strip_prefix) + else: + return _adjust_resources_path_by_default_prefixes(path) def _add_resources_cmd(ctx): - res_cmd = [] - for f in ctx.files.resources: - c_dir, res_path = _adjust_resources_path(f.short_path, ctx.attr.resource_strip_prefix) - target_path = res_path - if target_path[0] == "/": - target_path = target_path[1:] - line = "{target_path}={c_dir}{res_path}\n".format( - res_path=res_path, - target_path=target_path, - c_dir=c_dir) - res_cmd.extend([line]) - return "".join(res_cmd) + res_cmd = [] + for f in ctx.files.resources: + c_dir, res_path = _adjust_resources_path(f.short_path, + ctx.attr.resource_strip_prefix) + target_path = res_path + if target_path[0] == "/": + target_path = target_path[1:] + line = "{target_path}={c_dir}{res_path}\n".format( + res_path = res_path, target_path = target_path, c_dir = c_dir) + res_cmd.extend([line]) + return "".join(res_cmd) def _build_nosrc_jar(ctx, buildijar): - resources = _add_resources_cmd(ctx) - ijar_cmd = "" - if buildijar: - ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format( - jar_output=ctx.outputs.jar.path, - ijar_output=ctx.outputs.ijar.path) - - # this ensures the file is not empty - resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path - - zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name) - ctx.actions.write(zipper_arg_path, resources) - cmd = """ + resources = _add_resources_cmd(ctx) + ijar_cmd = "" + if buildijar: + ijar_cmd = "\ncp {jar_output} {ijar_output}\n".format( + jar_output = ctx.outputs.jar.path, ijar_output = ctx.outputs.ijar.path) + + # this ensures the file is not empty + resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path + + zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name) + ctx.actions.write(zipper_arg_path, resources) + cmd = """ rm -f {jar_output} {zipper} c {jar_output} @{path} # ensures that empty src targets still emit a statsfile touch {statsfile} """ + ijar_cmd - cmd = cmd.format( - path = zipper_arg_path.path, - jar_output=ctx.outputs.jar.path, - zipper=ctx.executable._zipper.path, - statsfile=ctx.outputs.statsfile.path, - ) - - outs = [ctx.outputs.jar, ctx.outputs.statsfile] - if buildijar: - outs.extend([ctx.outputs.ijar]) + cmd = cmd.format( + path = zipper_arg_path.path, + jar_output = ctx.outputs.jar.path, + zipper = ctx.executable._zipper.path, + statsfile = ctx.outputs.statsfile.path, + ) - inputs = ctx.files.resources + [ - ctx.outputs.manifest, - ctx.executable._zipper, - zipper_arg_path - ] + outs = [ctx.outputs.jar, ctx.outputs.statsfile] + if buildijar: + outs.extend([ctx.outputs.ijar]) - ctx.actions.run_shell( - inputs=inputs, - outputs=outs, - command=cmd, - progress_message="scala %s" % ctx.label, - arguments=[]) + inputs = ctx.files.resources + [ + ctx.outputs.manifest, ctx.executable._zipper, zipper_arg_path + ] + ctx.actions.run_shell( + inputs = inputs, + outputs = outs, + command = cmd, + progress_message = "scala %s" % ctx.label, + arguments = []) def _collect_plugin_paths(plugins): - paths = [] - for p in plugins: - if hasattr(p, "path"): - paths.append(p) - elif hasattr(p, "scala"): - paths.append(p.scala.outputs.jar) - elif hasattr(p, "java"): - paths.extend([j.class_jar for j in p.java.outputs.jars]) - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - elif hasattr(p, "files"): - paths.extend([f for f in p.files if not_sources_jar(f.basename)]) - return depset(paths) - + paths = [] + for p in plugins: + if hasattr(p, "path"): + paths.append(p) + elif hasattr(p, "scala"): + paths.append(p.scala.outputs.jar) + elif hasattr(p, "java"): + paths.extend([j.class_jar for j in p.java.outputs.jars]) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + elif hasattr(p, "files"): + paths.extend([f for f in p.files if not_sources_jar(f.basename)]) + return depset(paths) def _expand_location(ctx, flags): return [ctx.expand_location(f, ctx.attr.data) for f in flags] -def _join_path(args, sep=","): - return sep.join([f.path for f in args]) - -def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels, implicit_junit_deps_needed_for_java_compilation): - ijar_output_path = "" - ijar_cmd_path = "" - if buildijar: - ijar_output_path = ctx.outputs.ijar.path - ijar_cmd_path = ctx.executable._ijar.path - - java_srcs = _java_filetype.filter(ctx.files.srcs) - sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs - srcjars = _srcjar_filetype.filter(ctx.files.srcs) - all_srcjars = depset(srcjars, transitive = [dep_srcjars]) - # look for any plugins: - plugins = _collect_plugin_paths(ctx.attr.plugins) - dependency_analyzer_plugin_jars = [] - dependency_analyzer_mode = "off" - compiler_classpath_jars = cjars - optional_scalac_args = "" - classpath_resources = [] - if (hasattr(ctx.files, "classpath_resources")): - classpath_resources = ctx.files.classpath_resources - - if is_dependency_analyzer_on(ctx): +def _join_path(args, sep = ","): + return sep.join([f.path for f in args]) + +def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, + labels, implicit_junit_deps_needed_for_java_compilation): + ijar_output_path = "" + ijar_cmd_path = "" + if buildijar: + ijar_output_path = ctx.outputs.ijar.path + ijar_cmd_path = ctx.executable._ijar.path + + java_srcs = _java_filetype.filter(ctx.files.srcs) + sources = _scala_filetype.filter(ctx.files.srcs) + java_srcs + srcjars = _srcjar_filetype.filter(ctx.files.srcs) + all_srcjars = depset(srcjars, transitive = [dep_srcjars]) + # look for any plugins: + plugins = _collect_plugin_paths(ctx.attr.plugins) + dependency_analyzer_plugin_jars = [] + dependency_analyzer_mode = "off" + compiler_classpath_jars = cjars + optional_scalac_args = "" + classpath_resources = [] + if (hasattr(ctx.files, "classpath_resources")): + classpath_resources = ctx.files.classpath_resources + + if is_dependency_analyzer_on(ctx): # "off" mode is used as a feature toggle, that preserves original behaviour - dependency_analyzer_mode = ctx.fragments.java.strict_java_deps - dep_plugin = ctx.attr._dependency_analyzer_plugin - plugins = depset(transitive = [plugins, dep_plugin.files]) - dependency_analyzer_plugin_jars = ctx.files._dependency_analyzer_plugin - compiler_classpath_jars = transitive_compile_jars - - direct_jars = _join_path(cjars.to_list()) - transitive_cjars_list = transitive_compile_jars.to_list() - indirect_jars = _join_path(transitive_cjars_list) - indirect_targets = ",".join([labels[j.path] for j in transitive_cjars_list]) - current_target = str(ctx.label) - - optional_scalac_args = """ + dependency_analyzer_mode = ctx.fragments.java.strict_java_deps + dep_plugin = ctx.attr._dependency_analyzer_plugin + plugins = depset(transitive = [plugins, dep_plugin.files]) + dependency_analyzer_plugin_jars = ctx.files._dependency_analyzer_plugin + compiler_classpath_jars = transitive_compile_jars + + direct_jars = _join_path(cjars.to_list()) + transitive_cjars_list = transitive_compile_jars.to_list() + indirect_jars = _join_path(transitive_cjars_list) + indirect_targets = ",".join([labels[j.path] for j in transitive_cjars_list]) + current_target = str(ctx.label) + + optional_scalac_args = """ DirectJars: {direct_jars} IndirectJars: {indirect_jars} IndirectTargets: {indirect_targets} CurrentTarget: {current_target} """.format( - direct_jars=direct_jars, - indirect_jars=indirect_jars, - indirect_targets=indirect_targets, - current_target = current_target - ) + direct_jars = direct_jars, + indirect_jars = indirect_jars, + indirect_targets = indirect_targets, + current_target = current_target) - plugin_arg = _join_path(plugins.to_list()) + plugin_arg = _join_path(plugins.to_list()) - separator = ctx.configuration.host_path_separator - compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) + separator = ctx.configuration.host_path_separator + compiler_classpath = _join_path(compiler_classpath_jars.to_list(), separator) - toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type'] - scalacopts = toolchain.scalacopts + ctx.attr.scalacopts + toolchain = ctx.toolchains['@io_bazel_rules_scala//scala:toolchain_type'] + scalacopts = toolchain.scalacopts + ctx.attr.scalacopts - scalac_args = """ + scalac_args = """ Classpath: {cp} ClasspathResourceSrcs: {classpath_resource_src} EnableIjar: {enableijar} @@ -216,268 +210,269 @@ SourceJars: {srcjars} DependencyAnalyzerMode: {dependency_analyzer_mode} StatsfileOutput: {statsfile_output} """.format( - out=ctx.outputs.jar.path, - manifest=ctx.outputs.manifest.path, - scala_opts=",".join(scalacopts), - print_compile_time=ctx.attr.print_compile_time, - plugin_arg=plugin_arg, - cp=compiler_classpath, - classpath_resource_src=_join_path(classpath_resources), - files=_join_path(sources), - enableijar=buildijar, - ijar_out=ijar_output_path, - ijar_cmd_path=ijar_cmd_path, - srcjars=_join_path(all_srcjars.to_list()), - java_files=_join_path(java_srcs), - # the resource paths need to be aligned in order - resource_src=",".join([f.path for f in ctx.files.resources]), - resource_short_paths=",".join([f.short_path for f in ctx.files.resources]), - resource_dest=",".join( - [_adjust_resources_path_by_default_prefixes(f.short_path)[1] for f in ctx.files.resources] - ), - resource_strip_prefix=ctx.attr.resource_strip_prefix, - resource_jars=_join_path(ctx.files.resource_jars), - dependency_analyzer_mode = dependency_analyzer_mode, - statsfile_output = ctx.outputs.statsfile.path - ) - argfile = ctx.actions.declare_file( - "%s_worker_input" % ctx.label.name, - sibling = ctx.outputs.jar - ) - - ctx.actions.write(output=argfile, content=scalac_args + optional_scalac_args) - - outs = [ctx.outputs.jar, ctx.outputs.statsfile] - if buildijar: - outs.extend([ctx.outputs.ijar]) - ins = (compiler_classpath_jars.to_list() + - dep_srcjars.to_list() + - list(srcjars) + - list(sources) + - ctx.files.srcs + - ctx.files.plugins + - dependency_analyzer_plugin_jars + - classpath_resources + - ctx.files.resources + - ctx.files.resource_jars + - ctx.files._java_runtime + - [ctx.outputs.manifest, - ctx.executable._ijar, - argfile]) - ctx.actions.run( - inputs=ins, - outputs=outs, - executable=ctx.executable._scalac, - mnemonic="Scalac", - progress_message="scala %s" % ctx.label, - execution_requirements={"supports-workers": "1"}, - # when we run with a worker, the `@argfile.path` is removed and passed - # line by line as arguments in the protobuf. In that case, - # the rest of the arguments are passed to the process that - # starts up and stays resident. - - # In either case (worker or not), they will be jvm flags which will - # be correctly handled since the executable is a jvm app that will - # consume the flags on startup. - - arguments=["--jvm_flag=%s" % f for f in _expand_location(ctx, ctx.attr.scalac_jvm_flags)] + ["@" + argfile.path], - ) - - if buildijar: - scala_output = ctx.outputs.ijar - else: - scala_output = ctx.outputs.jar - java_jar = try_to_compile_java_jar(ctx, - scala_output, - all_srcjars, - java_srcs, - implicit_junit_deps_needed_for_java_compilation) - return java_jar + out = ctx.outputs.jar.path, + manifest = ctx.outputs.manifest.path, + scala_opts = ",".join(scalacopts), + print_compile_time = ctx.attr.print_compile_time, + plugin_arg = plugin_arg, + cp = compiler_classpath, + classpath_resource_src = _join_path(classpath_resources), + files = _join_path(sources), + enableijar = buildijar, + ijar_out = ijar_output_path, + ijar_cmd_path = ijar_cmd_path, + srcjars = _join_path(all_srcjars.to_list()), + java_files = _join_path(java_srcs), + # the resource paths need to be aligned in order + resource_src = ",".join([f.path for f in ctx.files.resources]), + resource_short_paths = ",".join( + [f.short_path for f in ctx.files.resources]), + resource_dest = ",".join([ + _adjust_resources_path_by_default_prefixes(f.short_path)[1] + for f in ctx.files.resources + ]), + resource_strip_prefix = ctx.attr.resource_strip_prefix, + resource_jars = _join_path(ctx.files.resource_jars), + dependency_analyzer_mode = dependency_analyzer_mode, + statsfile_output = ctx.outputs.statsfile.path) + argfile = ctx.actions.declare_file( + "%s_worker_input" % ctx.label.name, sibling = ctx.outputs.jar) + + ctx.actions.write( + output = argfile, content = scalac_args + optional_scalac_args) + + outs = [ctx.outputs.jar, ctx.outputs.statsfile] + if buildijar: + outs.extend([ctx.outputs.ijar]) + ins = (compiler_classpath_jars.to_list() + dep_srcjars.to_list() + + list(srcjars) + list(sources) + ctx.files.srcs + ctx.files.plugins + + dependency_analyzer_plugin_jars + classpath_resources + + ctx.files.resources + ctx.files.resource_jars + ctx.files._java_runtime + + [ctx.outputs.manifest, ctx.executable._ijar, argfile]) + ctx.actions.run( + inputs = ins, + outputs = outs, + executable = ctx.executable._scalac, + mnemonic = "Scalac", + progress_message = "scala %s" % ctx.label, + execution_requirements = {"supports-workers": "1"}, + # when we run with a worker, the `@argfile.path` is removed and passed + # line by line as arguments in the protobuf. In that case, + # the rest of the arguments are passed to the process that + # starts up and stays resident. + + # In either case (worker or not), they will be jvm flags which will + # be correctly handled since the executable is a jvm app that will + # consume the flags on startup. + arguments = [ + "--jvm_flag=%s" % f + for f in _expand_location(ctx, ctx.attr.scalac_jvm_flags) + ] + ["@" + argfile.path], + ) + if buildijar: + scala_output = ctx.outputs.ijar + else: + scala_output = ctx.outputs.jar + java_jar = try_to_compile_java_jar( + ctx, scala_output, all_srcjars, java_srcs, + implicit_junit_deps_needed_for_java_compilation) + return java_jar def _interim_java_provider_for_java_compilation(scala_output): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = [scala_output], - runtime_jars = [], - ) + return java_common.create_provider( + use_ijar = False, + compile_time_jars = [scala_output], + runtime_jars = [], + ) -def try_to_compile_java_jar(ctx, - scala_output, - all_srcjars, - java_srcs, +def try_to_compile_java_jar(ctx, scala_output, all_srcjars, java_srcs, implicit_junit_deps_needed_for_java_compilation): - if not java_srcs and not all_srcjars: - return False - - providers_of_dependencies = collect_java_providers_of(ctx.attr.deps) - providers_of_dependencies += collect_java_providers_of(implicit_junit_deps_needed_for_java_compilation) - scala_sources_java_provider = _interim_java_provider_for_java_compilation(scala_output) - providers_of_dependencies += [scala_sources_java_provider] - - full_java_jar = ctx.actions.declare_file(ctx.label.name + "_java.jar") - - provider = java_common.compile( - ctx, - source_jars = all_srcjars.to_list(), - source_files = java_srcs, - output = full_java_jar, - javac_opts = _expand_location(ctx, ctx.attr.javacopts + ctx.attr.javac_jvm_flags + java_common.default_javac_opts(ctx, java_toolchain_attr = "_java_toolchain")), - deps = providers_of_dependencies, - #exports can be empty since the manually created provider exposes exports - #needs to be empty since we want the provider.compile_jars to only contain the sources ijar - #workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved - exports = [], - java_toolchain = ctx.attr._java_toolchain, - host_javabase = ctx.attr._host_javabase, - strict_deps = ctx.fragments.java.strict_java_deps, - ) - return struct(jar = full_java_jar, ijar = provider.compile_jars.to_list().pop()) + if not java_srcs and not all_srcjars: + return False + + providers_of_dependencies = collect_java_providers_of(ctx.attr.deps) + providers_of_dependencies += collect_java_providers_of( + implicit_junit_deps_needed_for_java_compilation) + scala_sources_java_provider = _interim_java_provider_for_java_compilation( + scala_output) + providers_of_dependencies += [scala_sources_java_provider] + + full_java_jar = ctx.actions.declare_file(ctx.label.name + "_java.jar") + + provider = java_common.compile( + ctx, + source_jars = all_srcjars.to_list(), + source_files = java_srcs, + output = full_java_jar, + javac_opts = _expand_location( + ctx, ctx.attr.javacopts + ctx.attr.javac_jvm_flags + + java_common.default_javac_opts( + ctx, java_toolchain_attr = "_java_toolchain")), + deps = providers_of_dependencies, + #exports can be empty since the manually created provider exposes exports + #needs to be empty since we want the provider.compile_jars to only contain the sources ijar + #workaround until https://github.com/bazelbuild/bazel/issues/3528 is resolved + exports = [], + java_toolchain = ctx.attr._java_toolchain, + host_javabase = ctx.attr._host_javabase, + strict_deps = ctx.fragments.java.strict_java_deps, + ) + return struct( + jar = full_java_jar, ijar = provider.compile_jars.to_list().pop()) def collect_java_providers_of(deps): - providers = [] - for dep in deps: - if JavaInfo in dep: - providers.append(dep[JavaInfo]) - return providers - -def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation): - # We assume that if a srcjar is present, it is not empty - if len(ctx.files.srcs) + len(srcjars.to_list()) == 0: - _build_nosrc_jar(ctx, buildijar) - # no need to build ijar when empty - return struct(ijar=ctx.outputs.jar, - class_jar=ctx.outputs.jar, - java_jar=False, - full_jars=[ctx.outputs.jar], - ijars=[ctx.outputs.jar]) + providers = [] + for dep in deps: + if JavaInfo in dep: + providers.append(dep[JavaInfo]) + return providers + +def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, + jars2labels, + implicit_junit_deps_needed_for_java_compilation): + # We assume that if a srcjar is present, it is not empty + if len(ctx.files.srcs) + len(srcjars.to_list()) == 0: + _build_nosrc_jar(ctx, buildijar) + # no need to build ijar when empty + return struct( + ijar = ctx.outputs.jar, + class_jar = ctx.outputs.jar, + java_jar = False, + full_jars = [ctx.outputs.jar], + ijars = [ctx.outputs.jar]) + else: + java_jar = _compile(ctx, jars, srcjars, buildijar, transitive_compile_jars, + jars2labels, + implicit_junit_deps_needed_for_java_compilation) + ijar = None + if buildijar: + ijar = ctx.outputs.ijar else: - java_jar = _compile(ctx, jars, srcjars, buildijar, transitive_compile_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) - ijar = None - if buildijar: - ijar = ctx.outputs.ijar - else: - # macro code needs to be available at compile-time, - # so set ijar == jar - ijar = ctx.outputs.jar - full_jars = [ctx.outputs.jar] - ijars = [ijar] - if java_jar: - full_jars += [java_jar.jar] - ijars += [java_jar.ijar] - return struct(ijar=ijar, - class_jar=ctx.outputs.jar, - java_jar=java_jar, - full_jars=full_jars, - ijars=ijars) + # macro code needs to be available at compile-time, + # so set ijar == jar + ijar = ctx.outputs.jar + full_jars = [ctx.outputs.jar] + ijars = [ijar] + if java_jar: + full_jars += [java_jar.jar] + ijars += [java_jar.ijar] + return struct( + ijar = ijar, + class_jar = ctx.outputs.jar, + java_jar = java_jar, + full_jars = full_jars, + ijars = ijars) def _build_deployable(ctx, jars_list): - # This calls bazels singlejar utility. - # For a full list of available command line options see: - # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 - args = ["--normalize", "--sources"] - args.extend([j.path for j in jars_list]) - if getattr(ctx.attr, "main_class", ""): - args.extend(["--main_class", ctx.attr.main_class]) - args.extend(["--output", ctx.outputs.deploy_jar.path]) - ctx.actions.run( - inputs=jars_list, - outputs=[ctx.outputs.deploy_jar], - executable=ctx.executable._singlejar, - mnemonic="ScalaDeployJar", - progress_message="scala deployable %s" % ctx.label, - arguments=args) + # This calls bazels singlejar utility. + # For a full list of available command line options see: + # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311 + args = ["--normalize", "--sources"] + args.extend([j.path for j in jars_list]) + if getattr(ctx.attr, "main_class", ""): + args.extend(["--main_class", ctx.attr.main_class]) + args.extend(["--output", ctx.outputs.deploy_jar.path]) + ctx.actions.run( + inputs = jars_list, + outputs = [ctx.outputs.deploy_jar], + executable = ctx.executable._singlejar, + mnemonic = "ScalaDeployJar", + progress_message = "scala deployable %s" % ctx.label, + arguments = args) def _path_is_absolute(path): - # Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e., - # 'X:\' or 'X:/' where 'X' is a letter), false otherwise. - if len(path) >= 1 and path[0] == "/": - return True - if len(path) >= 3 \ - and path[0].isalpha() \ - and path[1] == ":" \ - and (path[2] == "/" or path[2] == "\\"): - return True + # Returns true for absolute path in Linux/Mac (i.e., '/') or Windows (i.e., + # 'X:\' or 'X:/' where 'X' is a letter), false otherwise. + if len(path) >= 1 and path[0] == "/": + return True + if len(path) >= 3 \ + and path[0].isalpha() \ + and path[1] == ":" \ + and (path[2] == "/" or path[2] == "\\"): + return True - return False + return False def _runfiles_root(ctx): - return "${TEST_SRCDIR}/%s" % ctx.workspace_name + return "${TEST_SRCDIR}/%s" % ctx.workspace_name -def _write_java_wrapper(ctx, args="", wrapper_preamble=""): - """This creates a wrapper that sets up the correct path +def _write_java_wrapper(ctx, args = "", wrapper_preamble = ""): + """This creates a wrapper that sets up the correct path to stand in for the java command.""" - java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_runfiles_path) - if _path_is_absolute(java_path): - javabin = java_path - else: - runfiles_root = _runfiles_root(ctx) - javabin = "%s/%s" % (runfiles_root, java_path) - - - exec_str = "" - if wrapper_preamble == "": - exec_str = "exec " - - wrapper = ctx.actions.declare_file(ctx.label.name + "_wrapper.sh") - ctx.actions.write( - output = wrapper, - content = """#!/bin/bash + java_path = str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo] + .java_executable_runfiles_path) + if _path_is_absolute(java_path): + javabin = java_path + else: + runfiles_root = _runfiles_root(ctx) + javabin = "%s/%s" % (runfiles_root, java_path) + + exec_str = "" + if wrapper_preamble == "": + exec_str = "exec " + + wrapper = ctx.actions.declare_file(ctx.label.name + "_wrapper.sh") + ctx.actions.write( + output = wrapper, + content = """#!/bin/bash {preamble} {exec_str}{javabin} "$@" {args} """.format( - preamble=wrapper_preamble, - exec_str=exec_str, - javabin=javabin, - args=args, - ), - is_executable = True - ) - return wrapper + preamble = wrapper_preamble, + exec_str = exec_str, + javabin = javabin, + args = args, + ), + is_executable = True) + return wrapper def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper): - template = ctx.attr._java_stub_template.files.to_list()[0] - # RUNPATH is defined here: - # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227 - classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()]) - jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags]) - ctx.actions.expand_template( - template = template, - output = ctx.outputs.executable, - substitutions = { - "%classpath%": classpath, - "%java_start_class%": main_class, - "%javabin%": "JAVABIN=%s/%s" % (_runfiles_root(ctx), wrapper.short_path), - "%jvm_flags%": jvm_flags, - "%needs_runfiles%": "", - "%runfiles_manifest_only%": "", - "%set_jacoco_metadata%": "", - "%workspace_prefix%": ctx.workspace_name + "/", - }, - is_executable = True, - ) + template = ctx.attr._java_stub_template.files.to_list()[0] + # RUNPATH is defined here: + # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227 + classpath = ":".join( + ["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()]) + jvm_flags = " ".join( + [ctx.expand_location(f, ctx.attr.data) for f in jvm_flags]) + ctx.actions.expand_template( + template = template, + output = ctx.outputs.executable, + substitutions = { + "%classpath%": classpath, + "%java_start_class%": main_class, + "%javabin%": "JAVABIN=%s/%s" % (_runfiles_root(ctx), + wrapper.short_path), + "%jvm_flags%": jvm_flags, + "%needs_runfiles%": "", + "%runfiles_manifest_only%": "", + "%set_jacoco_metadata%": "", + "%workspace_prefix%": ctx.workspace_name + "/", + }, + is_executable = True, + ) def _collect_runtime_jars(dep_targets): runtime_jars = [] for dep_target in dep_targets: if JavaInfo in dep_target: - runtime_jars.append(dep_target[JavaInfo].transitive_runtime_jars) + runtime_jars.append(dep_target[JavaInfo].transitive_runtime_jars) else: - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - runtime_jars.append(filter_not_sources(dep_target.files)) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + runtime_jars.append(filter_not_sources(dep_target.files)) return runtime_jars def is_dependency_analyzer_on(ctx): - if (hasattr(ctx.attr,"_dependency_analyzer_plugin") - # when the strict deps FT is removed the "default" check - # will be removed since "default" will mean it's turned on - and ctx.fragments.java.strict_java_deps != "default" - and ctx.fragments.java.strict_java_deps != "off"): + if (hasattr(ctx.attr, "_dependency_analyzer_plugin") + # when the strict deps FT is removed the "default" check + # will be removed since "default" will mean it's turned on + and ctx.fragments.java.strict_java_deps != "default" + and ctx.fragments.java.strict_java_deps != "off"): return True def is_dependency_analyzer_off(ctx): @@ -486,76 +481,91 @@ 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 = [], extra_runtime_deps = []): +def _collect_jars_from_common_ctx(ctx, extra_deps = [], + extra_runtime_deps = []): - dependency_analyzer_is_off = is_dependency_analyzer_off(ctx) + 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, dependency_analyzer_is_off) - (cjars, transitive_rjars, jars2labels, transitive_compile_jars) = (deps_jars.compile_jars, deps_jars.transitive_runtime_jars, deps_jars.jars2labels, deps_jars.transitive_compile_jars) + # Get jars from deps + auto_deps = [ctx.attr._scalalib, ctx.attr._scalareflect] + deps_jars = collect_jars(ctx.attr.deps + auto_deps + extra_deps, + dependency_analyzer_is_off) + (cjars, transitive_rjars, jars2labels, + transitive_compile_jars) = (deps_jars.compile_jars, + deps_jars.transitive_runtime_jars, + deps_jars.jars2labels, + deps_jars.transitive_compile_jars) - transitive_rjars = depset(transitive = [transitive_rjars] + _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps)) + transitive_rjars = depset( + transitive = [transitive_rjars] + + _collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps)) - return struct(compile_jars = cjars, transitive_runtime_jars = transitive_rjars, jars2labels=jars2labels, transitive_compile_jars = transitive_compile_jars) + return struct( + compile_jars = cjars, + transitive_runtime_jars = transitive_rjars, + jars2labels = jars2labels, + transitive_compile_jars = transitive_compile_jars) def _lib(ctx, non_macro_lib): - # Build up information from dependency-like attributes + # 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) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - - write_manifest(ctx) - outputs = _compile_or_empty(ctx, cjars, srcjars, non_macro_lib, jars.transitive_compile_jars, jars.jars2labels, []) + # 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) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) + write_manifest(ctx) + outputs = _compile_or_empty(ctx, cjars, srcjars, non_macro_lib, + jars.transitive_compile_jars, jars.jars2labels, + []) - _build_deployable(ctx, transitive_rjars.to_list()) + transitive_rjars = depset(outputs.full_jars, transitive = [transitive_rjars]) - # Using transitive_files since transitive_rjars a depset and avoiding linearization - runfiles = ctx.runfiles( - transitive_files = transitive_rjars, - collect_data = True, - ) + _build_deployable(ctx, transitive_rjars.to_list()) - # Add information from exports (is key that AFTER all build actions/runfiles analysis) - # Since after, will not show up in deploy_jar or old jars runfiles - # Notice that compile_jars is intentionally transitive for exports - exports_jars = collect_jars(ctx.attr.exports) - transitive_rjars = depset(transitive = [transitive_rjars, exports_jars.transitive_runtime_jars]) + # Using transitive_files since transitive_rjars a depset and avoiding linearization + runfiles = ctx.runfiles( + transitive_files = transitive_rjars, + collect_data = True, + ) - scalaattr = create_scala_provider( - ijar = outputs.ijar, - class_jar = outputs.class_jar, - compile_jars = depset(outputs.ijars, transitive = [exports_jars.compile_jars]), - transitive_runtime_jars = transitive_rjars, - deploy_jar = ctx.outputs.deploy_jar, - full_jars = outputs.full_jars, - statsfile = ctx.outputs.statsfile) + # Add information from exports (is key that AFTER all build actions/runfiles analysis) + # Since after, will not show up in deploy_jar or old jars runfiles + # Notice that compile_jars is intentionally transitive for exports + exports_jars = collect_jars(ctx.attr.exports) + transitive_rjars = depset( + transitive = [transitive_rjars, exports_jars.transitive_runtime_jars]) - java_provider = create_java_provider(scalaattr, jars.transitive_compile_jars) + scalaattr = create_scala_provider( + ijar = outputs.ijar, + class_jar = outputs.class_jar, + compile_jars = depset( + outputs.ijars, transitive = [exports_jars.compile_jars]), + transitive_runtime_jars = transitive_rjars, + deploy_jar = ctx.outputs.deploy_jar, + full_jars = outputs.full_jars, + statsfile = ctx.outputs.statsfile) - return struct( - files = depset([ctx.outputs.jar]), # Here is the default output - scala = scalaattr, - providers = [java_provider], - runfiles = runfiles, - # This is a free monoid given to the graph for the purpose of - # extensibility. This is necessary when one wants to create - # new targets which want to leverage a scala_library. For example, - # new_target1 -> scala_library -> new_target2. There might be - # information that new_target2 needs to get from new_target1, - # but we do not want to have to change scala_library to pass - # this information through. extra_information allows passing - # this information through, and it is up to the new_targets - # to filter and make sense of this information. - extra_information=_collect_extra_information(ctx.attr.deps), - jars_to_labels = jars.jars2labels, - ) + java_provider = create_java_provider(scalaattr, jars.transitive_compile_jars) + return struct( + files = depset([ctx.outputs.jar]), # Here is the default output + scala = scalaattr, + providers = [java_provider], + runfiles = runfiles, + # This is a free monoid given to the graph for the purpose of + # extensibility. This is necessary when one wants to create + # new targets which want to leverage a scala_library. For example, + # new_target1 -> scala_library -> new_target2. There might be + # information that new_target2 needs to get from new_target1, + # but we do not want to have to change scala_library to pass + # this information through. extra_information allows passing + # this information through, and it is up to the new_targets + # to filter and make sense of this information. + extra_information=_collect_extra_information(ctx.attr.deps), + jars_to_labels = jars.jars2labels, + ) def _collect_extra_information(targets): r = [] @@ -571,19 +581,30 @@ def scala_macro_library_impl(ctx): return _lib(ctx, False) # don't build the ijar for macros # Common code shared by all scala binary implementations. -def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2labels, java_wrapper, implicit_junit_deps_needed_for_java_compilation = []): +def _scala_binary_common(ctx, + cjars, + rjars, + transitive_compile_time_jars, + jars2labels, + java_wrapper, + implicit_junit_deps_needed_for_java_compilation = []): write_manifest(ctx) - outputs = _compile_or_empty(ctx, cjars, depset(), False, transitive_compile_time_jars, jars2labels, implicit_junit_deps_needed_for_java_compilation) # no need to build an ijar for an executable + outputs = _compile_or_empty(ctx, cjars, depset(), False, + transitive_compile_time_jars, jars2labels, + implicit_junit_deps_needed_for_java_compilation + ) # no need to build an ijar for an executable rjars = depset(outputs.full_jars, transitive = [rjars]) _build_deployable(ctx, rjars.to_list()) runfiles = ctx.runfiles( - transitive_files = depset([ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, transitive = [rjars]), + transitive_files = depset( + [ctx.outputs.executable, java_wrapper] + ctx.files._java_runtime, + transitive = [rjars]), collect_data = True) scalaattr = create_scala_provider( - ijar = outputs.class_jar, # we aren't using ijar here + ijar = outputs.class_jar, # we aren't using ijar here class_jar = outputs.class_jar, compile_jars = depset(outputs.ijars), transitive_runtime_jars = rjars, @@ -596,32 +617,38 @@ def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2l return struct( providers = [java_provider], scala = scalaattr, - transitive_rjars = rjars, #calling rules need this for the classpath in the launcher + transitive_rjars = + rjars, #calling rules need this for the classpath in the launcher jars_to_labels = jars2labels, - runfiles=runfiles) + runfiles = runfiles) def scala_binary_impl(ctx): jars = _collect_jars_from_common_ctx(ctx) (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) wrapper = _write_java_wrapper(ctx, "", "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) + out = _scala_binary_common(ctx, cjars, transitive_rjars, + jars.transitive_compile_jars, jars.jars2labels, + wrapper) _write_executable( ctx = ctx, rjars = out.transitive_rjars, main_class = ctx.attr.main_class, jvm_flags = ctx.attr.jvm_flags, - wrapper = wrapper - ) + wrapper = wrapper) return out def scala_repl_impl(ctx): # need scala-compiler for MainGenericRunner below - jars = _collect_jars_from_common_ctx(ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) + jars = _collect_jars_from_common_ctx( + ctx, extra_runtime_deps = [ctx.attr._scalacompiler]) (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) args = " ".join(ctx.attr.scalacopts) - wrapper = _write_java_wrapper(ctx, args, wrapper_preamble = """ + wrapper = _write_java_wrapper( + ctx, + args, + wrapper_preamble = """ # save stty like in bin/scala saved_stty=$(stty -g 2>/dev/null) if [[ ! $? ]]; then @@ -636,100 +663,123 @@ function finish() { trap finish EXIT """) - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper) + out = _scala_binary_common(ctx, cjars, transitive_rjars, + jars.transitive_compile_jars, jars.jars2labels, + wrapper) _write_executable( ctx = ctx, rjars = out.transitive_rjars, main_class = "scala.tools.nsc.MainGenericRunner", jvm_flags = ["-Dscala.usejavacp=true"] + ctx.attr.jvm_flags, - wrapper = wrapper - ) + wrapper = wrapper) return out def _scala_test_flags(ctx): - # output report test duration - flags = "-oD" - if ctx.attr.full_stacktraces: - flags += "F" - else: - flags += "S" - if not ctx.attr.colors: - flags += "W" - return flags + # output report test duration + flags = "-oD" + if ctx.attr.full_stacktraces: + flags += "F" + else: + flags += "S" + if not ctx.attr.colors: + flags += "W" + return flags def scala_test_impl(ctx): - if len(ctx.attr.suites) != 0: - print( - "suites attribute is deprecated. All scalatest test suites are run" - ) - jars = _collect_jars_from_common_ctx(ctx, - extra_runtime_deps = [ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner], - ) - (cjars, transitive_rjars, transitive_compile_jars, jars_to_labels) = (jars.compile_jars, jars.transitive_runtime_jars, - jars.transitive_compile_jars, jars.jars2labels) - # _scalatest is an http_jar, so its compile jar is run through ijar - # however, contains macros, so need to handle separately - scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars - cjars = depset(transitive = [cjars, scalatest_jars]) - transitive_rjars = depset(transitive = [transitive_rjars, scalatest_jars]) - - if is_dependency_analyzer_on(ctx): - transitive_compile_jars = depset(transitive = [scalatest_jars, transitive_compile_jars]) - scalatest_jars_list = scalatest_jars.to_list() - add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, scalatest_jars_list, scalatest_jars_list) - - args = " ".join([ - "-R \"{path}\"".format(path=ctx.outputs.jar.short_path), - _scala_test_flags(ctx), - "-C io.bazel.rules.scala.JUnitXmlReporter ", - ]) - # main_class almost has to be "org.scalatest.tools.Runner" due to args.... - wrapper = _write_java_wrapper(ctx, args, "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, transitive_compile_jars, jars_to_labels, wrapper) - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = ctx.attr.main_class, - jvm_flags = ctx.attr.jvm_flags, - wrapper = wrapper - ) - return out + if len(ctx.attr.suites) != 0: + print("suites attribute is deprecated. All scalatest test suites are run") + jars = _collect_jars_from_common_ctx( + ctx, + extra_runtime_deps = [ + ctx.attr._scalatest_reporter, ctx.attr._scalatest_runner + ], + ) + (cjars, transitive_rjars, transitive_compile_jars, + jars_to_labels) = (jars.compile_jars, jars.transitive_runtime_jars, + jars.transitive_compile_jars, jars.jars2labels) + # _scalatest is an http_jar, so its compile jar is run through ijar + # however, contains macros, so need to handle separately + scalatest_jars = collect_jars([ctx.attr._scalatest]).transitive_runtime_jars + cjars = depset(transitive = [cjars, scalatest_jars]) + transitive_rjars = depset(transitive = [transitive_rjars, scalatest_jars]) + + if is_dependency_analyzer_on(ctx): + transitive_compile_jars = depset( + transitive = [scalatest_jars, transitive_compile_jars]) + scalatest_jars_list = scalatest_jars.to_list() + add_labels_of_jars_to(jars_to_labels, ctx.attr._scalatest, + scalatest_jars_list, scalatest_jars_list) + + args = " ".join([ + "-R \"{path}\"".format(path = ctx.outputs.jar.short_path), + _scala_test_flags(ctx), + "-C io.bazel.rules.scala.JUnitXmlReporter ", + ]) + # main_class almost has to be "org.scalatest.tools.Runner" due to args.... + wrapper = _write_java_wrapper(ctx, args, "") + out = _scala_binary_common(ctx, cjars, transitive_rjars, + transitive_compile_jars, jars_to_labels, wrapper) + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = ctx.attr.main_class, + jvm_flags = ctx.attr.jvm_flags, + wrapper = wrapper) + return out def _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, archives): - serialized_archives = _serialize_archives_short_path(archives) - return struct( - testSuiteFlag = "-Dbazel.test_suite=%s" % ctx.attr.suite_class, - archiveFlag = "-Dbazel.discover.classes.archives.file.paths=%s" % serialized_archives, - prefixesFlag = "-Dbazel.discover.classes.prefixes=%s" % ",".join(ctx.attr.prefixes), - suffixesFlag = "-Dbazel.discover.classes.suffixes=%s" % ",".join(ctx.attr.suffixes), - printFlag = "-Dbazel.discover.classes.print.discovered=%s" % ctx.attr.print_discovered_classes) + serialized_archives = _serialize_archives_short_path(archives) + return struct( + testSuiteFlag = "-Dbazel.test_suite=%s" % ctx.attr.suite_class, + archiveFlag = "-Dbazel.discover.classes.archives.file.paths=%s" % + serialized_archives, + prefixesFlag = "-Dbazel.discover.classes.prefixes=%s" % ",".join( + ctx.attr.prefixes), + suffixesFlag = "-Dbazel.discover.classes.suffixes=%s" % ",".join( + ctx.attr.suffixes), + printFlag = "-Dbazel.discover.classes.print.discovered=%s" % + ctx.attr.print_discovered_classes) def _serialize_archives_short_path(archives): archives_short_path = "" - for archive in archives: archives_short_path += archive.class_jar.short_path + "," - return archives_short_path[:-1] #remove redundant comma + for archive in archives: + archives_short_path += archive.class_jar.short_path + "," + return archives_short_path[:-1] #remove redundant comma def scala_junit_test_impl(ctx): - if (not(ctx.attr.prefixes) and not(ctx.attr.suffixes)): - fail("Setting at least one of the attributes ('prefixes','suffixes') is required") - jars = _collect_jars_from_common_ctx(ctx, - extra_deps = [ctx.attr._junit, ctx.attr._hamcrest, ctx.attr.suite_label, ctx.attr._bazel_test_runner], - ) - (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) - implicit_junit_deps_needed_for_java_compilation = [ctx.attr._junit, ctx.attr._hamcrest] - - wrapper = _write_java_wrapper(ctx, "", "") - out = _scala_binary_common(ctx, cjars, transitive_rjars, jars.transitive_compile_jars, jars.jars2labels, wrapper, implicit_junit_deps_needed_for_java_compilation) - test_suite = _gen_test_suite_flags_based_on_prefixes_and_suffixes(ctx, out.scala.outputs.jars) - launcherJvmFlags = ["-ea", test_suite.archiveFlag, test_suite.prefixesFlag, test_suite.suffixesFlag, test_suite.printFlag, test_suite.testSuiteFlag] - _write_executable( - ctx = ctx, - rjars = out.transitive_rjars, - main_class = "com.google.testing.junit.runner.BazelTestRunner", - jvm_flags = launcherJvmFlags + ctx.attr.jvm_flags, - wrapper = wrapper + if (not (ctx.attr.prefixes) and not (ctx.attr.suffixes)): + fail( + "Setting at least one of the attributes ('prefixes','suffixes') is required" ) + jars = _collect_jars_from_common_ctx( + ctx, + extra_deps = [ + ctx.attr._junit, ctx.attr._hamcrest, ctx.attr.suite_label, + ctx.attr._bazel_test_runner + ], + ) + (cjars, transitive_rjars) = (jars.compile_jars, jars.transitive_runtime_jars) + implicit_junit_deps_needed_for_java_compilation = [ + ctx.attr._junit, ctx.attr._hamcrest + ] - return out + wrapper = _write_java_wrapper(ctx, "", "") + out = _scala_binary_common(ctx, cjars, transitive_rjars, + jars.transitive_compile_jars, jars.jars2labels, + wrapper, + implicit_junit_deps_needed_for_java_compilation) + test_suite = _gen_test_suite_flags_based_on_prefixes_and_suffixes( + ctx, out.scala.outputs.jars) + launcherJvmFlags = [ + "-ea", test_suite.archiveFlag, test_suite.prefixesFlag, + test_suite.suffixesFlag, test_suite.printFlag, test_suite.testSuiteFlag + ] + _write_executable( + ctx = ctx, + rjars = out.transitive_rjars, + main_class = "com.google.testing.junit.runner.BazelTestRunner", + jvm_flags = launcherJvmFlags + ctx.attr.jvm_flags, + wrapper = wrapper) + return out diff --git a/scala/providers.bzl b/scala/providers.bzl index f275d5ef2..1d68dd49a 100644 --- a/scala/providers.bzl +++ b/scala/providers.bzl @@ -1,32 +1,26 @@ # TODO: this should really be a bazel provider, but we are using old-style rule outputs # we need to document better what the intellij dependencies on this code actually are -def create_scala_provider( - ijar, - class_jar, - compile_jars, - transitive_runtime_jars, - deploy_jar, - full_jars, - statsfile): +def create_scala_provider(ijar, class_jar, compile_jars, + transitive_runtime_jars, deploy_jar, full_jars, + statsfile): - formatted_for_intellij = [struct( - class_jar = jar, - ijar = None, - source_jar = None, - source_jars = []) for jar in full_jars] + formatted_for_intellij = [ + struct(class_jar = jar, ijar = None, source_jar = None, source_jars = []) + for jar in full_jars + ] - rule_outputs = struct( - ijar = ijar, - class_jar = class_jar, - deploy_jar = deploy_jar, - jars = formatted_for_intellij, - statsfile = statsfile, - ) - # Note that, internally, rules only care about compile_jars and transitive_runtime_jars - # in a similar manner as the java_library and JavaProvider - return struct( - outputs = rule_outputs, - compile_jars = compile_jars, - transitive_runtime_jars = transitive_runtime_jars, - transitive_exports = [] #needed by intellij plugin - ) + rule_outputs = struct( + ijar = ijar, + class_jar = class_jar, + deploy_jar = deploy_jar, + jars = formatted_for_intellij, + statsfile = statsfile, + ) + # Note that, internally, rules only care about compile_jars and transitive_runtime_jars + # in a similar manner as the java_library and JavaProvider + return struct( + outputs = rule_outputs, + compile_jars = compile_jars, + transitive_runtime_jars = transitive_runtime_jars, + transitive_exports = [] #needed by intellij plugin + ) diff --git a/scala/scala.bzl b/scala/scala.bzl index 69d16f66d..8b373478a 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -1,102 +1,153 @@ -load("@io_bazel_rules_scala//scala/private:rule_impls.bzl", - _scala_library_impl = "scala_library_impl", - _scala_macro_library_impl = "scala_macro_library_impl", - _scala_binary_impl = "scala_binary_impl", - _scala_test_impl = "scala_test_impl", - _scala_repl_impl = "scala_repl_impl", - _scala_junit_test_impl = "scala_junit_test_impl", +load( + "@io_bazel_rules_scala//scala/private:rule_impls.bzl", + _scala_library_impl = "scala_library_impl", + _scala_macro_library_impl = "scala_macro_library_impl", + _scala_binary_impl = "scala_binary_impl", + _scala_test_impl = "scala_test_impl", + _scala_repl_impl = "scala_repl_impl", + _scala_junit_test_impl = "scala_junit_test_impl", ) load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", - _specs2_junit_dependencies = "specs2_junit_dependencies" -) + _specs2_junit_dependencies = "specs2_junit_dependencies") _jar_filetype = FileType([".jar"]) _launcher_template = { - "_java_stub_template": attr.label(default=Label("@java_stub_template//file")), + "_java_stub_template": attr.label( + default = Label("@java_stub_template//file")), } _implicit_deps = { - "_singlejar": attr.label(executable=True, cfg="host", default=Label("@bazel_tools//tools/jdk:singlejar"), allow_files=True), - "_ijar": attr.label(executable=True, cfg="host", default=Label("@bazel_tools//tools/jdk:ijar"), 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", default=Label("@bazel_tools//tools/zip:zipper"), allow_files=True), - "_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_toolchain")), - "_host_javabase": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_runtime"), cfg="host"), - "_java_runtime": attr.label(default = Label("@bazel_tools//tools/jdk:current_java_runtime")) + "_singlejar": attr.label( + executable = True, + cfg = "host", + default = Label("@bazel_tools//tools/jdk:singlejar"), + allow_files = True), + "_ijar": attr.label( + executable = True, + cfg = "host", + default = Label("@bazel_tools//tools/jdk:ijar"), + 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", + default = Label("@bazel_tools//tools/zip:zipper"), + allow_files = True), + "_java_toolchain": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_toolchain")), + "_host_javabase": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + cfg = "host"), + "_java_runtime": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime")) } # Single dep to allow IDEs to pickup all the implicit dependencies. _resolve_deps = { - "_scala_toolchain" : attr.label_list(default=[ - Label("//external:io_bazel_rules_scala/dependency/scala/scala_library"), - ], allow_files=False), + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library" + ), + ], + allow_files = False), } _test_resolve_deps = { - "_scala_toolchain" : attr.label_list(default=[ - Label("//external:io_bazel_rules_scala/dependency/scala/scala_library"), - Label("//external:io_bazel_rules_scala/dependency/scalatest/scalatest"), - ], allow_files=False), + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library" + ), + Label( + "//external:io_bazel_rules_scala/dependency/scalatest/scalatest" + ), + ], + allow_files = False), } _junit_resolve_deps = { - "_scala_toolchain" : attr.label_list(default=[ - Label("//external:io_bazel_rules_scala/dependency/scala/scala_library"), - Label("//external:io_bazel_rules_scala/dependency/junit/junit"), - Label("//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core"), - ], allow_files=False), + "_scala_toolchain": attr.label_list( + default = [ + Label( + "//external:io_bazel_rules_scala/dependency/scala/scala_library" + ), + Label("//external:io_bazel_rules_scala/dependency/junit/junit"), + Label( + "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core" + ), + ], + allow_files = False), } # Common attributes reused across multiple rules. _common_attrs_for_plugin_bootstrapping = { - "srcs": attr.label_list( - allow_files=FileType([".scala", ".srcjar", ".java"])), - "deps": attr.label_list(), - "plugins": attr.label_list(allow_files=FileType([".jar"])), - "runtime_deps": attr.label_list(), - "data": attr.label_list(allow_files=True, cfg="data"), - "resources": attr.label_list(allow_files=True), - "resource_strip_prefix": attr.string(), - "resource_jars": attr.label_list(allow_files=True), - "scalacopts":attr.string_list(), - "javacopts":attr.string_list(), - "jvm_flags": attr.string_list(), - "scalac_jvm_flags": attr.string_list(), - "javac_jvm_flags": attr.string_list(), - "print_compile_time": attr.bool(default=False, mandatory=False), + "srcs": attr.label_list( + allow_files = FileType([".scala", ".srcjar", ".java"])), + "deps": attr.label_list(), + "plugins": attr.label_list(allow_files = FileType([".jar"])), + "runtime_deps": attr.label_list(), + "data": attr.label_list(allow_files = True, cfg = "data"), + "resources": attr.label_list(allow_files = True), + "resource_strip_prefix": attr.string(), + "resource_jars": attr.label_list(allow_files = True), + "scalacopts": attr.string_list(), + "javacopts": attr.string_list(), + "jvm_flags": attr.string_list(), + "scalac_jvm_flags": attr.string_list(), + "javac_jvm_flags": attr.string_list(), + "print_compile_time": attr.bool(default = False, mandatory = False), } _common_attrs = {} _common_attrs.update(_common_attrs_for_plugin_bootstrapping) _common_attrs.update({ - # using stricts scala deps is done by using command line flag called 'strict_java_deps' - # switching mode to "on" means that ANY API change in a target's transitive dependencies will trigger a recompilation of that target, - # on the other hand any internal change (i.e. on code that ijar omits) WON’T trigger recompilation by transitive dependencies - "_dependency_analyzer_plugin": attr.label(default=Label("@io_bazel_rules_scala//third_party/plugin/src/main:dependency_analyzer"), allow_files=_jar_filetype, mandatory=False), + # using stricts scala deps is done by using command line flag called 'strict_java_deps' + # switching mode to "on" means that ANY API change in a target's transitive dependencies will trigger a recompilation of that target, + # on the other hand any internal change (i.e. on code that ijar omits) WON’T trigger recompilation by transitive dependencies + "_dependency_analyzer_plugin": attr.label( + default = Label( + "@io_bazel_rules_scala//third_party/plugin/src/main:dependency_analyzer" + ), + allow_files = _jar_filetype, + mandatory = False), }) _library_attrs = { - "main_class": attr.string(), - "exports": attr.label_list(allow_files=False), + "main_class": attr.string(), + "exports": attr.label_list(allow_files = False), } _common_outputs = { - "jar": "%{name}.jar", - "deploy_jar": "%{name}_deploy.jar", - "manifest": "%{name}_MANIFEST.MF", - "statsfile": "%{name}.statsfile", + "jar": "%{name}.jar", + "deploy_jar": "%{name}_deploy.jar", + "manifest": "%{name}_MANIFEST.MF", + "statsfile": "%{name}.statsfile", } _library_outputs = {} _library_outputs.update(_common_outputs) _library_outputs.update({ - "ijar": "%{name}_ijar.jar", + "ijar": "%{name}_ijar.jar", }) _scala_library_attrs = {} @@ -106,11 +157,11 @@ _scala_library_attrs.update(_library_attrs) _scala_library_attrs.update(_resolve_deps) scala_library = rule( - implementation =_scala_library_impl, - attrs = _scala_library_attrs, - outputs = _library_outputs, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_library_impl, + attrs = _scala_library_attrs, + outputs = _library_outputs, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) # the scala compiler plugin used for dependency analysis is compiled using `scala_library`. @@ -120,69 +171,79 @@ _scala_library_for_plugin_bootstrapping_attrs = {} _scala_library_for_plugin_bootstrapping_attrs.update(_implicit_deps) _scala_library_for_plugin_bootstrapping_attrs.update(_library_attrs) _scala_library_for_plugin_bootstrapping_attrs.update(_resolve_deps) -_scala_library_for_plugin_bootstrapping_attrs.update(_common_attrs_for_plugin_bootstrapping) +_scala_library_for_plugin_bootstrapping_attrs.update( + _common_attrs_for_plugin_bootstrapping) scala_library_for_plugin_bootstrapping = rule( - implementation = _scala_library_impl, - attrs = _scala_library_for_plugin_bootstrapping_attrs, - outputs = _library_outputs, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_library_impl, + attrs = _scala_library_for_plugin_bootstrapping_attrs, + outputs = _library_outputs, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) _scala_macro_library_attrs = { "main_class": attr.string(), - "exports": attr.label_list(allow_files=False), + "exports": attr.label_list(allow_files = False), } _scala_macro_library_attrs.update(_implicit_deps) _scala_macro_library_attrs.update(_common_attrs) _scala_macro_library_attrs.update(_library_attrs) _scala_macro_library_attrs.update(_resolve_deps) scala_macro_library = rule( - implementation = _scala_macro_library_impl, - attrs = _scala_macro_library_attrs, - outputs = _common_outputs, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_macro_library_impl, + attrs = _scala_macro_library_attrs, + outputs = _common_outputs, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) _scala_binary_attrs = { - "main_class": attr.string(mandatory=True), - "classpath_resources": attr.label_list(allow_files=True), + "main_class": attr.string(mandatory = True), + "classpath_resources": attr.label_list(allow_files = True), } _scala_binary_attrs.update(_launcher_template) _scala_binary_attrs.update(_implicit_deps) _scala_binary_attrs.update(_common_attrs) _scala_binary_attrs.update(_resolve_deps) scala_binary = rule( - implementation = _scala_binary_impl, - attrs= _scala_binary_attrs, - outputs = _common_outputs, - executable = True, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_binary_impl, + attrs = _scala_binary_attrs, + outputs = _common_outputs, + executable = True, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) _scala_test_attrs = { - "main_class": attr.string(default="io.bazel.rulesscala.scala_test.Runner"), + "main_class": attr.string( + default = "io.bazel.rulesscala.scala_test.Runner"), "suites": attr.string_list(), - "colors": attr.bool(default=True), - "full_stacktraces": attr.bool(default=True), - "_scalatest": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/scalatest/scalatest"), allow_files=True), - "_scalatest_runner": attr.label(executable=True, cfg="host", default=Label("//src/java/io/bazel/rulesscala/scala_test:runner.jar"), allow_files=True), - "_scalatest_reporter": attr.label(default=Label("//scala/support:test_reporter")), + "colors": attr.bool(default = True), + "full_stacktraces": attr.bool(default = True), + "_scalatest": attr.label( + default = Label( + "//external:io_bazel_rules_scala/dependency/scalatest/scalatest"), + allow_files = True), + "_scalatest_runner": attr.label( + executable = True, + cfg = "host", + default = Label("//src/java/io/bazel/rulesscala/scala_test:runner.jar"), + allow_files = True), + "_scalatest_reporter": attr.label( + default = Label("//scala/support:test_reporter")), } _scala_test_attrs.update(_launcher_template) _scala_test_attrs.update(_implicit_deps) _scala_test_attrs.update(_common_attrs) _scala_test_attrs.update(_test_resolve_deps) scala_test = rule( - implementation =_scala_test_impl, - attrs = _scala_test_attrs, - outputs = _common_outputs, - executable = True, - test = True, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_test_impl, + attrs = _scala_test_attrs, + outputs = _common_outputs, + executable = True, + test = True, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) _scala_repl_attrs = {} @@ -191,12 +252,12 @@ _scala_repl_attrs.update(_implicit_deps) _scala_repl_attrs.update(_common_attrs) _scala_repl_attrs.update(_resolve_deps) scala_repl = rule( - implementation =_scala_repl_impl, - attrs = _scala_repl_attrs, - outputs = _common_outputs, - executable = True, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], + implementation = _scala_repl_impl, + attrs = _scala_repl_attrs, + outputs = _common_outputs, + executable = True, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'], ) _SCALA_BUILD_FILE = """ @@ -234,30 +295,33 @@ java_import( def scala_repositories(): native.new_http_archive( - name = "scala", - strip_prefix = "scala-2.11.11", - sha256 = "12037ca64c68468e717e950f47fc77d5ceae5e74e3bdca56f6d02fd5bfd6900b", - url = "https://downloads.lightbend.com/scala/2.11.11/scala-2.11.11.tgz", - build_file_content = _SCALA_BUILD_FILE, + name = "scala", + strip_prefix = "scala-2.11.11", + sha256 = + "12037ca64c68468e717e950f47fc77d5ceae5e74e3bdca56f6d02fd5bfd6900b", + url = "https://downloads.lightbend.com/scala/2.11.11/scala-2.11.11.tgz", + build_file_content = _SCALA_BUILD_FILE, ) # 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", + 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", ) native.maven_server( - name = "scalac_deps_maven_server", - url = "https://mirror.bazel.build/repo1.maven.org/maven2/", + name = "scalac_deps_maven_server", + url = "https://mirror.bazel.build/repo1.maven.org/maven2/", ) native.maven_jar( - name = "scalac_rules_protobuf_java", - artifact = "com.google.protobuf:protobuf-java:3.1.0", - sha1 = "e13484d9da178399d32d2d27ee21a77cfb4b7873", - server = "scalac_deps_maven_server", + name = "scalac_rules_protobuf_java", + artifact = "com.google.protobuf:protobuf-java:3.1.0", + sha1 = "e13484d9da178399d32d2d27ee21a77cfb4b7873", + server = "scalac_deps_maven_server", ) # used by ScalacProcessor @@ -266,59 +330,99 @@ def scala_repositories(): artifact = "commons-io:commons-io:2.6", sha1 = "815893df5f31da2ece4040fe0a12fd44b577afaf", # bazel maven mirror doesn't have the commons_io artifact -# server = "scalac_deps_maven_server", - ) + # server = "scalac_deps_maven_server", + ) # Template for binary launcher BAZEL_JAVA_LAUNCHER_VERSION = "0.4.5" - java_stub_template_url = ("raw.githubusercontent.com/bazelbuild/bazel/" + - BAZEL_JAVA_LAUNCHER_VERSION + - "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + - "java_stub_template.txt") + java_stub_template_url = ( + "raw.githubusercontent.com/bazelbuild/bazel/" + + BAZEL_JAVA_LAUNCHER_VERSION + + "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + + "java_stub_template.txt") native.http_file( - name = "java_stub_template", - urls = ["https://mirror.bazel.build/%s" % java_stub_template_url, - "https://%s" % java_stub_template_url], - sha256 = "f09d06d55cd25168427a323eb29d32beca0ded43bec80d76fc6acd8199a24489", + name = "java_stub_template", + urls = [ + "https://mirror.bazel.build/%s" % java_stub_template_url, + "https://%s" % java_stub_template_url + ], + sha256 = + "f09d06d55cd25168427a323eb29d32beca0ded43bec80d76fc6acd8199a24489", ) - native.bind(name = "io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", actual = "@scalac_rules_protobuf_java//jar") + native.bind( + name = "io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", + actual = "@scalac_rules_protobuf_java//jar") - native.bind(name = "io_bazel_rules_scala/dependency/commons_io/commons_io", actual = "@scalac_rules_commons_io//jar") + native.bind( + 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/parser_combinators", + actual = "@scala//:scala-parser-combinators") - native.bind(name = "io_bazel_rules_scala/dependency/scala/scala_compiler", actual = "@scala//:scala-compiler") + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_compiler", + actual = "@scala//:scala-compiler") - native.bind(name = "io_bazel_rules_scala/dependency/scala/scala_library", actual = "@scala//:scala-library") + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_library", + actual = "@scala//:scala-library") - native.bind(name = "io_bazel_rules_scala/dependency/scala/scala_reflect", actual = "@scala//:scala-reflect") + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_reflect", + actual = "@scala//:scala-reflect") - native.bind(name = "io_bazel_rules_scala/dependency/scala/scala_xml", actual = "@scala//:scala-xml") + native.bind( + name = "io_bazel_rules_scala/dependency/scala/scala_xml", + actual = "@scala//:scala-xml") - native.bind(name = "io_bazel_rules_scala/dependency/scalatest/scalatest", actual = "@scalatest//jar") + native.bind( + name = "io_bazel_rules_scala/dependency/scalatest/scalatest", + actual = "@scalatest//jar") def _sanitize_string_for_usage(s): - res_array = [] - for idx in range(len(s)): - c = s[idx] - if c.isalnum() or c == ".": - res_array.append(c) - else: - res_array.append("_") - return "".join(res_array) + res_array = [] + for idx in range(len(s)): + c = s[idx] + if c.isalnum() or c == ".": + res_array.append(c) + else: + res_array.append("_") + return "".join(res_array) # This auto-generates a test suite based on the passed set of targets # we will add a root test_suite with the name of the passed name -def scala_test_suite(name, srcs = [], deps = [], runtime_deps = [], data = [], resources = [], - scalacopts = [], jvm_flags = [], visibility = None, size = None, - colors=True, full_stacktraces=True): - ts = [] - for test_file in srcs: - n = "%s_test_suite_%s" % (name, _sanitize_string_for_usage(test_file)) - scala_test(name = n, srcs = [test_file], deps = deps, runtime_deps = runtime_deps, resources=resources, scalacopts=scalacopts, jvm_flags=jvm_flags, visibility=visibility, size=size, colors=colors, full_stacktraces=full_stacktraces) - ts.append(n) - native.test_suite(name = name, tests = ts, visibility = visibility) +def scala_test_suite(name, + srcs = [], + deps = [], + runtime_deps = [], + data = [], + resources = [], + scalacopts = [], + jvm_flags = [], + visibility = None, + size = None, + colors = True, + full_stacktraces = True): + ts = [] + for test_file in srcs: + n = "%s_test_suite_%s" % (name, _sanitize_string_for_usage(test_file)) + scala_test( + name = n, + srcs = [test_file], + deps = deps, + runtime_deps = runtime_deps, + resources = resources, + scalacopts = scalacopts, + jvm_flags = jvm_flags, + visibility = visibility, + size = size, + colors = colors, + full_stacktraces = full_stacktraces) + ts.append(n) + native.test_suite(name = name, tests = ts, visibility = visibility) # Scala library suite generates a series of scala libraries # then it depends on them with a meta one which exports all the sub targets @@ -335,56 +439,66 @@ def scala_library_suite(name, javacopts = [], jvm_flags = [], print_compile_time = False, - visibility = None - ): - ts = [] - for src_file in srcs: - n = "%s_lib_%s" % (name, _sanitize_string_for_usage(src_file)) - scala_library(name = n, - srcs = [src_file], - deps = deps, - plugins = plugins, - runtime_deps = runtime_deps, - data = data, - resources=resources, - resource_strip_prefix = resource_strip_prefix, - scalacopts = scalacopts, - javacopts = javacopts, - jvm_flags = jvm_flags, - print_compile_time = print_compile_time, - visibility=visibility, - exports=exports - ) - ts.append(n) - scala_library(name = name, deps = ts, exports = exports + ts, visibility = visibility) + visibility = None): + ts = [] + for src_file in srcs: + n = "%s_lib_%s" % (name, _sanitize_string_for_usage(src_file)) + scala_library( + name = n, + srcs = [src_file], + deps = deps, + plugins = plugins, + runtime_deps = runtime_deps, + data = data, + resources = resources, + resource_strip_prefix = resource_strip_prefix, + scalacopts = scalacopts, + javacopts = javacopts, + jvm_flags = jvm_flags, + print_compile_time = print_compile_time, + visibility = visibility, + exports = exports) + ts.append(n) + scala_library( + name = name, deps = ts, exports = exports + ts, visibility = visibility) _scala_junit_test_attrs = { - "prefixes": attr.string_list(default=[]), - "suffixes": attr.string_list(default=[]), - "suite_label": attr.label(default=Label("//src/java/io/bazel/rulesscala/test_discovery:test_discovery")), - "suite_class": attr.string(default="io.bazel.rulesscala.test_discovery.DiscoveredTestSuite"), - "print_discovered_classes": attr.bool(default=False, mandatory=False), - "_junit": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/junit/junit")), - "_hamcrest": attr.label(default=Label("//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core")), - "_bazel_test_runner": attr.label(default=Label("@bazel_tools//tools/jdk:TestRunner_deploy.jar"), allow_files=True), + "prefixes": attr.string_list(default = []), + "suffixes": attr.string_list(default = []), + "suite_label": attr.label( + default = Label( + "//src/java/io/bazel/rulesscala/test_discovery:test_discovery")), + "suite_class": attr.string( + default = "io.bazel.rulesscala.test_discovery.DiscoveredTestSuite"), + "print_discovered_classes": attr.bool(default = False, mandatory = False), + "_junit": attr.label( + default = Label( + "//external:io_bazel_rules_scala/dependency/junit/junit")), + "_hamcrest": attr.label( + default = Label( + "//external:io_bazel_rules_scala/dependency/hamcrest/hamcrest_core") + ), + "_bazel_test_runner": attr.label( + default = Label("@bazel_tools//tools/jdk:TestRunner_deploy.jar"), + allow_files = True), } _scala_junit_test_attrs.update(_launcher_template) _scala_junit_test_attrs.update(_implicit_deps) _scala_junit_test_attrs.update(_common_attrs) _scala_junit_test_attrs.update(_junit_resolve_deps) scala_junit_test = rule( - implementation = _scala_junit_test_impl, - attrs = _scala_junit_test_attrs, - outputs = _common_outputs, - test = True, - fragments = ["java"], - toolchains = ['@io_bazel_rules_scala//scala:toolchain_type'] -) + implementation = _scala_junit_test_impl, + attrs = _scala_junit_test_attrs, + outputs = _common_outputs, + test = True, + fragments = ["java"], + toolchains = ['@io_bazel_rules_scala//scala:toolchain_type']) def scala_specs2_junit_test(name, **kwargs): scala_junit_test( - name = name, - deps = _specs2_junit_dependencies() + kwargs.pop("deps",[]), - suite_label = Label("//src/java/io/bazel/rulesscala/specs2:specs2_test_discovery"), - suite_class = "io.bazel.rulesscala.specs2.Specs2DiscoveredTestSuite", - **kwargs) + name = name, + deps = _specs2_junit_dependencies() + kwargs.pop("deps", []), + suite_label = Label( + "//src/java/io/bazel/rulesscala/specs2:specs2_test_discovery"), + suite_class = "io.bazel.rulesscala.specs2.Specs2DiscoveredTestSuite", + **kwargs) diff --git a/scala/scala_cross_version.bzl b/scala/scala_cross_version.bzl index 23b459570..3895296c0 100644 --- a/scala/scala_cross_version.bzl +++ b/scala/scala_cross_version.bzl @@ -11,7 +11,6 @@ # 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. - """Helper functions for Scala cross-version support. Encapsulates the logic of abstracting over Scala major version (2.11, 2.12, etc) for dependency resolution.""" diff --git a/scala/scala_import.bzl b/scala/scala_import.bzl index c51221752..328cc88e3 100644 --- a/scala/scala_import.bzl +++ b/scala/scala_import.bzl @@ -2,34 +2,45 @@ #if you change make sure to manually re-import an intellij project and see imports #are resolved (not red) and clickable def _scala_import_impl(ctx): - target_data = _code_jars_and_intellij_metadata_from(ctx.attr.jars) - (current_target_compile_jars, intellij_metadata) = (target_data.code_jars, target_data.intellij_metadata) - current_jars = depset(current_target_compile_jars) - exports = _collect(ctx.attr.exports) - transitive_runtime_jars = _collect_runtime(ctx.attr.runtime_deps) - jars = _collect(ctx.attr.deps) - jars2labels = {} - _collect_labels(ctx.attr.deps, jars2labels) - _collect_labels(ctx.attr.exports, jars2labels) #untested - _add_labels_of_current_code_jars(depset(transitive=[current_jars, exports.compile_jars]), ctx.label, jars2labels) #last to override the label of the export compile jars to the current target - return struct( - scala = struct( - outputs = struct ( - jars = intellij_metadata - ), - ), - jars_to_labels = jars2labels, - providers = [ - _create_provider(current_jars, transitive_runtime_jars, jars, exports) - ], - ) -def _create_provider(current_target_compile_jars, transitive_runtime_jars, jars, exports): - return java_common.create_provider( - use_ijar = False, - compile_time_jars = depset(transitive = [current_target_compile_jars, exports.compile_jars]), - transitive_compile_time_jars = depset(transitive = [jars.transitive_compile_jars, current_target_compile_jars, exports.transitive_compile_jars]) , - transitive_runtime_jars = depset(transitive = [transitive_runtime_jars, jars.transitive_runtime_jars, current_target_compile_jars, exports.transitive_runtime_jars]) , - ) + target_data = _code_jars_and_intellij_metadata_from(ctx.attr.jars) + (current_target_compile_jars, + intellij_metadata) = (target_data.code_jars, target_data.intellij_metadata) + current_jars = depset(current_target_compile_jars) + exports = _collect(ctx.attr.exports) + transitive_runtime_jars = _collect_runtime(ctx.attr.runtime_deps) + jars = _collect(ctx.attr.deps) + jars2labels = {} + _collect_labels(ctx.attr.deps, jars2labels) + _collect_labels(ctx.attr.exports, jars2labels) #untested + _add_labels_of_current_code_jars( + depset(transitive = [current_jars, exports.compile_jars]), + ctx.label, + jars2labels + ) #last to override the label of the export compile jars to the current target + return struct( + scala = struct(outputs = struct(jars = intellij_metadata), + ), + jars_to_labels = jars2labels, + providers = [ + _create_provider(current_jars, transitive_runtime_jars, jars, exports) + ], + ) + +def _create_provider(current_target_compile_jars, transitive_runtime_jars, jars, + exports): + return java_common.create_provider( + use_ijar = False, + compile_time_jars = depset( + transitive = [current_target_compile_jars, exports.compile_jars]), + transitive_compile_time_jars = depset(transitive = [ + jars.transitive_compile_jars, current_target_compile_jars, + exports.transitive_compile_jars + ]), + transitive_runtime_jars = depset(transitive = [ + transitive_runtime_jars, jars.transitive_runtime_jars, + current_target_compile_jars, exports.transitive_runtime_jars + ]), + ) def _add_labels_of_current_code_jars(code_jars, label, jars2labels): for jar in code_jars.to_list(): @@ -41,14 +52,14 @@ def _code_jars_and_intellij_metadata_from(jars): for jar in jars: current_jar_code_jars = _filter_out_non_code_jars(jar.files) code_jars += current_jar_code_jars - for current_class_jar in current_jar_code_jars: #intellij, untested - intellij_metadata.append(struct( - ijar = None, - class_jar = current_class_jar, - source_jar = None, - source_jars = [], - ) - ) + for current_class_jar in current_jar_code_jars: #intellij, untested + intellij_metadata.append( + struct( + ijar = None, + class_jar = current_class_jar, + source_jar = None, + source_jars = [], + )) return struct(code_jars = code_jars, intellij_metadata = intellij_metadata) def _filter_out_non_code_jars(files): @@ -64,19 +75,20 @@ def _collect(deps): compile_jars = [] for dep_target in deps: - java_provider = dep_target[JavaInfo] - compile_jars.append(java_provider.compile_jars) - transitive_compile_jars.append(java_provider.transitive_compile_time_jars) - runtime_jars.append(java_provider.transitive_runtime_jars) + java_provider = dep_target[JavaInfo] + compile_jars.append(java_provider.compile_jars) + transitive_compile_jars.append(java_provider.transitive_compile_time_jars) + runtime_jars.append(java_provider.transitive_runtime_jars) - return struct(transitive_runtime_jars = depset(transitive = runtime_jars), - transitive_compile_jars = depset(transitive = transitive_compile_jars), - compile_jars = depset(transitive = compile_jars)) + return struct( + transitive_runtime_jars = depset(transitive = runtime_jars), + transitive_compile_jars = depset(transitive = transitive_compile_jars), + compile_jars = depset(transitive = compile_jars)) def _collect_labels(deps, jars2labels): for dep_target in deps: - java_provider = dep_target[JavaInfo] - _transitively_accumulate_labels(dep_target, java_provider,jars2labels) + java_provider = dep_target[JavaInfo] + _transitively_accumulate_labels(dep_target, java_provider, jars2labels) def _transitively_accumulate_labels(dep_target, java_provider, jars2labels): if hasattr(dep_target, "jars_to_labels"): @@ -88,17 +100,19 @@ def _transitively_accumulate_labels(dep_target, java_provider, jars2labels): def _collect_runtime(runtime_deps): jar_deps = [] for dep_target in runtime_deps: - java_provider = dep_target[JavaInfo] - jar_deps.append(java_provider.transitive_runtime_jars) + java_provider = dep_target[JavaInfo] + jar_deps.append(java_provider.transitive_runtime_jars) return depset(transitive = jar_deps) scala_import = rule( - implementation=_scala_import_impl, - attrs={ - "jars": attr.label_list(allow_files=True), #current hidden assumption is that these point to full, not ijar'd jars - "deps": attr.label_list(), - "runtime_deps": attr.label_list(), - "exports": attr.label_list() - }, + implementation = _scala_import_impl, + attrs = { + "jars": attr.label_list( + allow_files = True + ), #current hidden assumption is that these point to full, not ijar'd jars + "deps": attr.label_list(), + "runtime_deps": attr.label_list(), + "exports": attr.label_list() + }, ) diff --git a/scala/scala_maven_import_external.bzl b/scala/scala_maven_import_external.bzl index c4fcc5358..68e323084 100644 --- a/scala/scala_maven_import_external.bzl +++ b/scala/scala_maven_import_external.bzl @@ -11,7 +11,6 @@ # 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. - """ 'jvm_import_external' offers additional functionality above what maven_jar has to offer. In addition to downloading the jars, it allows to define this jar's dependencies. @@ -72,23 +71,23 @@ def _jvm_import_external(repository_ctx): lines.append(repository_ctx.attr.rule_load) lines.append("") if repository_ctx.attr.default_visibility: - lines.append("package(default_visibility = %s)" % ( - repository_ctx.attr.default_visibility)) + lines.append("package(default_visibility = %s)" % + (repository_ctx.attr.default_visibility)) lines.append("") lines.append("licenses(%s)" % repr(repository_ctx.attr.licenses)) lines.append("") - lines.extend(_serialize_given_rule_import( - repository_ctx.attr.rule_name, name, path, srcpath, repository_ctx.attr, _PASS_PROPS, repository_ctx.attr.additional_rule_attrs)) + lines.extend( + _serialize_given_rule_import(repository_ctx.attr.rule_name, name, path, + srcpath, repository_ctx.attr, _PASS_PROPS, + repository_ctx.attr.additional_rule_attrs)) if (repository_ctx.attr.neverlink and repository_ctx.attr.generated_linkable_rule_name): - lines.extend(_serialize_given_rule_import( - repository_ctx.attr.rule_name, - repository_ctx.attr.generated_linkable_rule_name, - path, - srcpath, - repository_ctx.attr, - [p for p in _PASS_PROPS if p != "neverlink"], - repository_ctx.attr.additional_rule_attrs)) + lines.extend( + _serialize_given_rule_import( + repository_ctx.attr.rule_name, + repository_ctx.attr.generated_linkable_rule_name, path, srcpath, + repository_ctx.attr, [p for p in _PASS_PROPS if p != "neverlink"], + repository_ctx.attr.additional_rule_attrs)) extra = repository_ctx.attr.extra_build_file_content if extra: lines.append(extra) @@ -101,9 +100,9 @@ def _jvm_import_external(repository_ctx): repository_ctx.file("jar/BUILD", "\n".join([ _HEADER, "", - "package(default_visibility = %r)" % ( - repository_ctx.attr.visibility or - repository_ctx.attr.default_visibility), + "package(default_visibility = %r)" % + (repository_ctx.attr.visibility or + repository_ctx.attr.default_visibility), "", "alias(", " name = \"jar\",", @@ -113,26 +112,26 @@ def _jvm_import_external(repository_ctx): ])) def _convert_to_url(artifact, server_urls): - parts = artifact.split(":") - group_id_part = parts[0].replace(".","/") - artifact_id = parts[1] - version = parts[2] - packaging = "jar" - classifier_part = "" - if len(parts) == 4: - packaging = parts[2] - version = parts[3] - elif len(parts) == 5: - packaging = parts[2] - classifier_part = "-"+parts[3] - version = parts[4] - - final_name = artifact_id + "-" + version + classifier_part + "." + packaging - url_suffix = group_id_part+"/"+artifact_id + "/" + version + "/" + final_name - urls = [] - for server_url in server_urls: - urls.append(_concat_with_needed_slash(server_url, url_suffix)) - return urls + parts = artifact.split(":") + group_id_part = parts[0].replace(".", "/") + artifact_id = parts[1] + version = parts[2] + packaging = "jar" + classifier_part = "" + if len(parts) == 4: + packaging = parts[2] + version = parts[3] + elif len(parts) == 5: + packaging = parts[2] + classifier_part = "-" + parts[3] + version = parts[4] + + final_name = artifact_id + "-" + version + classifier_part + "." + packaging + url_suffix = group_id_part + "/" + artifact_id + "/" + version + "/" + final_name + urls = [] + for server_url in server_urls: + urls.append(_concat_with_needed_slash(server_url, url_suffix)) + return urls def _concat_with_needed_slash(server_url, url_suffix): if server_url.endswith("/"): @@ -140,7 +139,8 @@ def _concat_with_needed_slash(server_url, url_suffix): else: return server_url + "/" + url_suffix -def _serialize_given_rule_import(rule_name, name, path, srcpath, attrs, props, additional_rule_attrs): +def _serialize_given_rule_import(rule_name, name, path, srcpath, attrs, props, + additional_rule_attrs): lines = [ "%s(" % rule_name, " name = %s," % repr(name), @@ -161,11 +161,11 @@ def _serialize_given_rule_import(rule_name, name, path, srcpath, attrs, props, a return lines jvm_import_external = repository_rule( - implementation=_jvm_import_external, - attrs={ - "rule_name": attr.string(mandatory=True), - "licenses": attr.string_list(mandatory=True, allow_empty=False), - "jar_urls": attr.string_list(mandatory=True, allow_empty=False), + implementation = _jvm_import_external, + attrs = { + "rule_name": attr.string(mandatory = True), + "licenses": attr.string_list(mandatory = True, allow_empty = False), + "jar_urls": attr.string_list(mandatory = True, allow_empty = False), "jar_sha256": attr.string(), "rule_load": attr.string(), "additional_rule_attrs": attr.string_dict(), @@ -178,37 +178,34 @@ jvm_import_external = repository_rule( "neverlink": attr.bool(), "generated_rule_name": attr.string(), "generated_linkable_rule_name": attr.string(), - "default_visibility": attr.string_list(default=["//visibility:public"]), + "default_visibility": attr.string_list( + default = ["//visibility:public"]), "extra_build_file_content": attr.string(), }) -def scala_maven_import_external(artifact, - server_urls, - rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", - **kwargs): +def scala_maven_import_external( + artifact, + server_urls, + rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", + **kwargs): jvm_maven_import_external( - rule_name = "scala_import", - rule_load = rule_load, - artifact = artifact, - server_urls = server_urls, -#additional string attributes' values have to be escaped in order to accomodate non-string types -# additional_rule_attrs = {"foo": "'bar'"}, - **kwargs - ) + rule_name = "scala_import", + rule_load = rule_load, + artifact = artifact, + server_urls = server_urls, + #additional string attributes' values have to be escaped in order to accomodate non-string types + # additional_rule_attrs = {"foo": "'bar'"}, + **kwargs) def jvm_maven_import_external(artifact, server_urls, **kwargs): jvm_import_external( - jar_urls = _convert_to_url(artifact, server_urls), - **kwargs - ) + jar_urls = _convert_to_url(artifact, server_urls), **kwargs) -def scala_import_external(rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", - **kwargs): +def scala_import_external( + rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", + **kwargs): jvm_import_external( - rule_name = "scala_import", - rule_load = rule_load, - **kwargs - ) + rule_name = "scala_import", rule_load = rule_load, **kwargs) """Rules for defining external Java dependencies. @@ -365,9 +362,7 @@ attribute. This should be used in rare circumstances when a distributed jar will be loaded into a runtime environment where certain dependencies can be reasonably expected to already be provided. """ + def java_import_external(jar_sha256, **kwargs): jvm_import_external( - rule_name = "java_import", - jar_sha256 = jar_sha256, - **kwargs - ) + rule_name = "java_import", jar_sha256 = jar_sha256, **kwargs) diff --git a/scala/scala_toolchain.bzl b/scala/scala_toolchain.bzl index fa3ff689c..be6fabc2d 100644 --- a/scala/scala_toolchain.bzl +++ b/scala/scala_toolchain.bzl @@ -1,12 +1,8 @@ def _scala_toolchain_impl(ctx): - toolchain = platform_common.ToolchainInfo( - scalacopts = ctx.attr.scalacopts, - ) + toolchain = platform_common.ToolchainInfo(scalacopts = ctx.attr.scalacopts,) return [toolchain] scala_toolchain = rule( - _scala_toolchain_impl, - attrs = { - 'scalacopts': attr.string_list(), - } -) \ No newline at end of file + _scala_toolchain_impl, attrs = { + 'scalacopts': attr.string_list(), + }) diff --git a/scala/support/BUILD b/scala/support/BUILD index d4d4e786b..2f70647da 100644 --- a/scala/support/BUILD +++ b/scala/support/BUILD @@ -3,27 +3,28 @@ load("//scala:scala.bzl", "scala_library") scala_library( name = "test_reporter", srcs = ["JUnitXmlReporter.scala"], + scalacopts = [ + "-deprecation:true", + "-encoding", + "UTF-8", + "-feature", + "-language:existentials", + "-language:higherKinds", + "-language:implicitConversions", + "-unchecked", + "-Xfatal-warnings", + "-Xlint", + "-Yno-adapted-args", + "-Ywarn-dead-code", + "-Ywarn-numeric-widen", + "-Ywarn-value-discard", + "-Xfuture", + "-Ywarn-unused-import", + "-Ypartial-unification", + ], visibility = ["//visibility:public"], deps = [ - '//external:io_bazel_rules_scala/dependency/scala/scala_xml', - '//external:io_bazel_rules_scala/dependency/scalatest/scalatest' + "//external:io_bazel_rules_scala/dependency/scala/scala_xml", + "//external:io_bazel_rules_scala/dependency/scalatest/scalatest", ], - scalacopts = [ - "-deprecation:true", - "-encoding", "UTF-8", - "-feature", - "-language:existentials", - "-language:higherKinds", - "-language:implicitConversions", - "-unchecked", - "-Xfatal-warnings", - "-Xlint", - "-Yno-adapted-args", - "-Ywarn-dead-code", - "-Ywarn-numeric-widen", - "-Ywarn-value-discard", - "-Xfuture", - "-Ywarn-unused-import", - "-Ypartial-unification", - ] ) diff --git a/scala/toolchains.bzl b/scala/toolchains.bzl index 5e5f78b81..7afd76999 100644 --- a/scala/toolchains.bzl +++ b/scala/toolchains.bzl @@ -1,3 +1,2 @@ - def scala_register_toolchains(): - native.register_toolchains("@io_bazel_rules_scala//scala:default_toolchain") \ No newline at end of file + native.register_toolchains("@io_bazel_rules_scala//scala:default_toolchain") diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index d22e22c90..5428abc50 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -1,403 +1,386 @@ -load("//scala:scala.bzl", - "scala_library", +load( + "//scala:scala.bzl", + "scala_library", ) -load("//scala:scala_cross_version.bzl", - "scala_mvn_artifact", +load( + "//scala:scala_cross_version.bzl", + "scala_mvn_artifact", ) -load("//scala/private:common.bzl", - "collect_jars", - "create_java_provider", +load( + "//scala/private:common.bzl", + "collect_jars", + "create_java_provider", ) def scala_proto_repositories(): - native.maven_server( - name = "scala_proto_deps_maven_server", - url = "http://central.maven.org/maven2/", - ) - - native.maven_jar( - name = "scala_proto_rules_protoc_jar", - artifact = "com.github.os72:protoc-jar:3.2.0", - sha1 = "7c06b12068193bd2080caf45580b0a00d2a31638", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/protoc', - actual = '@scala_proto_rules_protoc_jar//jar' - ) - - native.maven_jar( - 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", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapb_plugin', - actual = '@scala_proto_rules_scalapb_plugin//jar' - ) - - native.maven_jar( - 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", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/protoc_bridge', - actual = '@scala_proto_rules_protoc_bridge//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_scalapbc", - artifact = scala_mvn_artifact("com.trueaccord.scalapb:scalapbc:0.6.5"), - sha1 = "b204d6d56a042b973af5b6fe28f81ece232d1fe4", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapbc', - actual = '@scala_proto_rules_scalapbc//jar' - ) - - native.maven_jar( - 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", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime', - actual = '@scala_proto_rules_scalapb_runtime//jar' - ) - - native.maven_jar( - 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", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime_grpc', - actual = '@scala_proto_rules_scalapb_runtime_grpc//jar' - ) - - native.maven_jar( - 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", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapb_lenses', - actual = '@scala_proto_rules_scalapb_lenses//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_scalapb_fastparse", - artifact = scala_mvn_artifact("com.lihaoyi:fastparse:0.4.4"), - sha1 = "f065fe0afe6fd2b4557d985c37362c36f08f9947", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/scalapb_fastparse', - actual = '@scala_proto_rules_scalapb_fastparse//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_grpc_core", - artifact = "io.grpc:grpc-core:1.3.1", - sha1 = "a9b38b4a19af3ef208f4f6bf7871876d959c5eb1", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/grpc_core', - actual = '@scala_proto_rules_grpc_core//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_grpc_stub", - artifact = "io.grpc:grpc-stub:1.3.1", - sha1 = "60bdfa9d8c664a9d87ae461106eff6eed8da6c54", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/grpc_stub', - actual = '@scala_proto_rules_grpc_stub//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_grpc_protobuf", - artifact = "io.grpc:grpc-protobuf:1.3.1", - sha1 = "9562e977cacd6e128a31686c3e6948d61873c496", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/grpc_protobuf', - actual = '@scala_proto_rules_grpc_protobuf//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_grpc_netty", - artifact = "io.grpc:grpc-netty:1.3.1", - sha1 = "cc3831fccb76cfe21445f75cc055b5ffd979dc54", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/grpc_netty', - actual = '@scala_proto_rules_grpc_netty//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_grpc_context", - artifact = "io.grpc:grpc-context:1.3.1", - sha1 = "28accd419b18d59055b8999f78f5cb7767c7bde8", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/grpc_context', - actual = '@scala_proto_rules_grpc_context//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_guava", - artifact = "com.google.guava:guava:19.0", - sha1 = "6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/guava', - actual = '@scala_proto_rules_guava//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_google_instrumentation", - artifact = "com.google.instrumentation:instrumentation-api:0.3.0", - sha1 = "a2e145e7a7567c6372738f5c5a6f3ba6407ac354", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/google_instrumentation', - actual = '@scala_proto_rules_google_instrumentation//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_codec", - artifact = "io.netty:netty-codec:4.1.8.Final", - sha1 = "1bd0a2d032e5c7fc3f42c1b483d0f4c57eb516a3", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_codec', - actual = '@scala_proto_rules_netty_codec//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_codec_http", - artifact = "io.netty:netty-codec-http:4.1.8.Final", - sha1 = "1e88617c4a6c88da7e86fdbbd9494d22a250c879", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_codec_http', - actual = '@scala_proto_rules_netty_codec_http//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_codec_socks", - artifact = "io.netty:netty-codec-socks:4.1.8.Final", - sha1 = "7f7c5f5b154646d7c571f8ca944fb813f71b1d51", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_codec_socks', - actual = '@scala_proto_rules_netty_codec_socks//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_codec_http2", - artifact = "io.netty:netty-codec-http2:4.1.8.Final", - sha1 = "105a99ee5767463370ccc3d2e16800bd99f5648e", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_codec_http2', - actual = '@scala_proto_rules_netty_codec_http2//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_handler", - artifact = "io.netty:netty-handler:4.1.8.Final", - sha1 = "db01139bfb11afd009a695eef55b43bbf22c4ef5", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_handler', - actual = '@scala_proto_rules_netty_handler//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_buffer", - artifact = "io.netty:netty-buffer:4.1.8.Final", - sha1 = "43292c2622e340a0d07178c341ca3bdf3d662034", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_buffer', - actual = '@scala_proto_rules_netty_buffer//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_transport", - artifact = "io.netty:netty-transport:4.1.8.Final", - sha1 = "905b5dadce881c9824b3039c0df36dabbb7b6a07", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_transport', - actual = '@scala_proto_rules_netty_transport//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_resolver", - artifact = "io.netty:netty-resolver:4.1.8.Final", - sha1 = "2e116cdd5edc01b2305072b1dbbd17c0595dbfef", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_resolver', - actual = '@scala_proto_rules_netty_resolver//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_common", - artifact = "io.netty:netty-common:4.1.8.Final", - sha1 = "ee62c80318413d2375d145e51e48d7d35c901324", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_common', - actual = '@scala_proto_rules_netty_common//jar' - ) - - native.maven_jar( - name = "scala_proto_rules_netty_handler_proxy", - artifact = "io.netty:netty-handler-proxy:4.1.8.Final", - sha1 = "c4d22e8b9071a0ea8d75766d869496c32648a758", - server = "scala_proto_deps_maven_server", - ) - - native.bind( - name = 'io_bazel_rules_scala/dependency/proto/netty_handler_proxy', - actual = '@scala_proto_rules_netty_handler_proxy//jar' - ) + native.maven_server( + name = "scala_proto_deps_maven_server", + url = "http://central.maven.org/maven2/", + ) + + native.maven_jar( + name = "scala_proto_rules_protoc_jar", + artifact = "com.github.os72:protoc-jar:3.2.0", + sha1 = "7c06b12068193bd2080caf45580b0a00d2a31638", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/protoc', + actual = '@scala_proto_rules_protoc_jar//jar') + + native.maven_jar( + 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", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapb_plugin', + actual = '@scala_proto_rules_scalapb_plugin//jar') + + native.maven_jar( + 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", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/protoc_bridge', + actual = '@scala_proto_rules_protoc_bridge//jar') + + native.maven_jar( + name = "scala_proto_rules_scalapbc", + artifact = scala_mvn_artifact("com.trueaccord.scalapb:scalapbc:0.6.5"), + sha1 = "b204d6d56a042b973af5b6fe28f81ece232d1fe4", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapbc', + actual = '@scala_proto_rules_scalapbc//jar') + + native.maven_jar( + 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", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime', + actual = '@scala_proto_rules_scalapb_runtime//jar') + + native.maven_jar( + 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", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapb_runtime_grpc', + actual = '@scala_proto_rules_scalapb_runtime_grpc//jar') + + native.maven_jar( + 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", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapb_lenses', + actual = '@scala_proto_rules_scalapb_lenses//jar') + + native.maven_jar( + name = "scala_proto_rules_scalapb_fastparse", + artifact = scala_mvn_artifact("com.lihaoyi:fastparse:0.4.4"), + sha1 = "f065fe0afe6fd2b4557d985c37362c36f08f9947", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/scalapb_fastparse', + actual = '@scala_proto_rules_scalapb_fastparse//jar') + + native.maven_jar( + name = "scala_proto_rules_grpc_core", + artifact = "io.grpc:grpc-core:1.3.1", + sha1 = "a9b38b4a19af3ef208f4f6bf7871876d959c5eb1", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/grpc_core', + actual = '@scala_proto_rules_grpc_core//jar') + + native.maven_jar( + name = "scala_proto_rules_grpc_stub", + artifact = "io.grpc:grpc-stub:1.3.1", + sha1 = "60bdfa9d8c664a9d87ae461106eff6eed8da6c54", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/grpc_stub', + actual = '@scala_proto_rules_grpc_stub//jar') + + native.maven_jar( + name = "scala_proto_rules_grpc_protobuf", + artifact = "io.grpc:grpc-protobuf:1.3.1", + sha1 = "9562e977cacd6e128a31686c3e6948d61873c496", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/grpc_protobuf', + actual = '@scala_proto_rules_grpc_protobuf//jar') + + native.maven_jar( + name = "scala_proto_rules_grpc_netty", + artifact = "io.grpc:grpc-netty:1.3.1", + sha1 = "cc3831fccb76cfe21445f75cc055b5ffd979dc54", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/grpc_netty', + actual = '@scala_proto_rules_grpc_netty//jar') + + native.maven_jar( + name = "scala_proto_rules_grpc_context", + artifact = "io.grpc:grpc-context:1.3.1", + sha1 = "28accd419b18d59055b8999f78f5cb7767c7bde8", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/grpc_context', + actual = '@scala_proto_rules_grpc_context//jar') + + native.maven_jar( + name = "scala_proto_rules_guava", + artifact = "com.google.guava:guava:19.0", + sha1 = "6ce200f6b23222af3d8abb6b6459e6c44f4bb0e9", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/guava', + actual = '@scala_proto_rules_guava//jar') + + native.maven_jar( + name = "scala_proto_rules_google_instrumentation", + artifact = "com.google.instrumentation:instrumentation-api:0.3.0", + sha1 = "a2e145e7a7567c6372738f5c5a6f3ba6407ac354", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/google_instrumentation', + actual = '@scala_proto_rules_google_instrumentation//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_codec", + artifact = "io.netty:netty-codec:4.1.8.Final", + sha1 = "1bd0a2d032e5c7fc3f42c1b483d0f4c57eb516a3", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_codec', + actual = '@scala_proto_rules_netty_codec//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_codec_http", + artifact = "io.netty:netty-codec-http:4.1.8.Final", + sha1 = "1e88617c4a6c88da7e86fdbbd9494d22a250c879", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_codec_http', + actual = '@scala_proto_rules_netty_codec_http//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_codec_socks", + artifact = "io.netty:netty-codec-socks:4.1.8.Final", + sha1 = "7f7c5f5b154646d7c571f8ca944fb813f71b1d51", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_codec_socks', + actual = '@scala_proto_rules_netty_codec_socks//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_codec_http2", + artifact = "io.netty:netty-codec-http2:4.1.8.Final", + sha1 = "105a99ee5767463370ccc3d2e16800bd99f5648e", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_codec_http2', + actual = '@scala_proto_rules_netty_codec_http2//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_handler", + artifact = "io.netty:netty-handler:4.1.8.Final", + sha1 = "db01139bfb11afd009a695eef55b43bbf22c4ef5", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_handler', + actual = '@scala_proto_rules_netty_handler//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_buffer", + artifact = "io.netty:netty-buffer:4.1.8.Final", + sha1 = "43292c2622e340a0d07178c341ca3bdf3d662034", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_buffer', + actual = '@scala_proto_rules_netty_buffer//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_transport", + artifact = "io.netty:netty-transport:4.1.8.Final", + sha1 = "905b5dadce881c9824b3039c0df36dabbb7b6a07", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_transport', + actual = '@scala_proto_rules_netty_transport//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_resolver", + artifact = "io.netty:netty-resolver:4.1.8.Final", + sha1 = "2e116cdd5edc01b2305072b1dbbd17c0595dbfef", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_resolver', + actual = '@scala_proto_rules_netty_resolver//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_common", + artifact = "io.netty:netty-common:4.1.8.Final", + sha1 = "ee62c80318413d2375d145e51e48d7d35c901324", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_common', + actual = '@scala_proto_rules_netty_common//jar') + + native.maven_jar( + name = "scala_proto_rules_netty_handler_proxy", + artifact = "io.netty:netty-handler-proxy:4.1.8.Final", + sha1 = "c4d22e8b9071a0ea8d75766d869496c32648a758", + server = "scala_proto_deps_maven_server", + ) + + native.bind( + name = 'io_bazel_rules_scala/dependency/proto/netty_handler_proxy', + actual = '@scala_proto_rules_netty_handler_proxy//jar') def _root_path(f): - if f.is_source: - return f.owner.workspace_root - return '/'.join([f.root.path, f.owner.workspace_root]) + if f.is_source: + return f.owner.workspace_root + return '/'.join([f.root.path, f.owner.workspace_root]) def _colon_paths(data): - return ':'.join(["{root},{path}".format(root=_root_path(f), path=f.path) for f in data]) + return ':'.join([ + "{root},{path}".format(root = _root_path(f), path = f.path) for f in data + ]) def _gen_proto_srcjar_impl(ctx): - acc_imports = [] - transitive_proto_paths = [] - - jvm_deps = [] - for target in ctx.attr.deps: - if hasattr(target, 'proto'): - acc_imports.append(target.proto.transitive_sources) - #inline this if after 0.12.0 is the oldest supported version - if hasattr(target.proto, 'transitive_proto_path'): - transitive_proto_paths.append(target.proto.transitive_proto_path) - else: - jvm_deps.append(target) - - acc_imports = depset(transitive = acc_imports) - if "java_conversions" in ctx.attr.flags and len(jvm_deps) == 0: - fail("must have at least one jvm dependency if with_java is True (java_conversions is turned on)") - - deps_jars = collect_jars(jvm_deps) - - worker_content = "{output}\n{paths}\n{flags_arg}\n{packages}".format( - output = ctx.outputs.srcjar.path, - paths = _colon_paths(acc_imports.to_list()), - # Command line args to worker cannot be empty so using padding - flags_arg = "-" + ",".join(ctx.attr.flags), - # Command line args to worker cannot be empty so using padding - packages = "-" + ":".join(depset(transitive = transitive_proto_paths).to_list()) - ) - argfile = ctx.actions.declare_file("%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) - ctx.actions.write(output=argfile, content=worker_content) - ctx.actions.run( - executable = ctx.executable.generator, - inputs = depset([argfile], transitive = [acc_imports]), - outputs = [ctx.outputs.srcjar], - mnemonic="ProtoScalaPBRule", - progress_message = "creating scalapb files %s" % ctx.label, - execution_requirements={"supports-workers": "1"}, - arguments=["@" + argfile.path], - ) - srcjarsattr = struct( - srcjar = ctx.outputs.srcjar, - ) - scalaattr = struct( + acc_imports = [] + transitive_proto_paths = [] + + jvm_deps = [] + for target in ctx.attr.deps: + if hasattr(target, 'proto'): + acc_imports.append(target.proto.transitive_sources) + #inline this if after 0.12.0 is the oldest supported version + if hasattr(target.proto, 'transitive_proto_path'): + transitive_proto_paths.append(target.proto.transitive_proto_path) + else: + jvm_deps.append(target) + + acc_imports = depset(transitive = acc_imports) + if "java_conversions" in ctx.attr.flags and len(jvm_deps) == 0: + fail( + "must have at least one jvm dependency if with_java is True (java_conversions is turned on)" + ) + + deps_jars = collect_jars(jvm_deps) + + worker_content = "{output}\n{paths}\n{flags_arg}\n{packages}".format( + output = ctx.outputs.srcjar.path, + paths = _colon_paths(acc_imports.to_list()), + # Command line args to worker cannot be empty so using padding + flags_arg = "-" + ",".join(ctx.attr.flags), + # Command line args to worker cannot be empty so using padding + packages = "-" + + ":".join(depset(transitive = transitive_proto_paths).to_list())) + argfile = ctx.actions.declare_file( + "%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) + ctx.actions.write(output = argfile, content = worker_content) + ctx.actions.run( + executable = ctx.executable.generator, + inputs = depset([argfile], transitive = [acc_imports]), + outputs = [ctx.outputs.srcjar], + mnemonic = "ProtoScalaPBRule", + progress_message = "creating scalapb files %s" % ctx.label, + execution_requirements = {"supports-workers": "1"}, + arguments = ["@" + argfile.path], + ) + srcjarsattr = struct(srcjar = ctx.outputs.srcjar,) + scalaattr = struct( outputs = None, - compile_jars = deps_jars.compile_jars, + compile_jars = deps_jars.compile_jars, transitive_runtime_jars = deps_jars.transitive_runtime_jars, - ) - java_provider = create_java_provider(scalaattr, depset()) - return struct( - scala = scalaattr, - providers = [java_provider], - srcjars=srcjarsattr, - extra_information=[struct( - srcjars=srcjarsattr, - )], - ) + ) + java_provider = create_java_provider(scalaattr, depset()) + return struct( + scala = scalaattr, + providers = [java_provider], + srcjars = srcjarsattr, + extra_information = [struct(srcjars = srcjarsattr, + )], + ) scala_proto_srcjar = rule( _gen_proto_srcjar_impl, - attrs={ + attrs = { "deps": attr.label_list( - mandatory=True, - allow_rules=["proto_library", "java_proto_library", "java_library", "scala_library"] - ), - "flags": attr.string_list(default=[]), + mandatory = True, + allow_rules = [ + "proto_library", "java_proto_library", "java_library", + "scala_library" + ]), + "flags": attr.string_list(default = []), "generator": attr.label( - executable=True, - cfg="host", - allow_files=True - ), + executable = True, cfg = "host", allow_files = True), }, - outputs={ - "srcjar": "lib%{name}.srcjar", + outputs = { + "srcjar": "lib%{name}.srcjar", }, ) @@ -428,7 +411,6 @@ GRPC_DEPS = [ "//external:io_bazel_rules_scala/dependency/proto/netty_common", "//external:io_bazel_rules_scala/dependency/proto/netty_handler_proxy", ] - """Generate scalapb bindings for a set of proto_library targets. Example: @@ -450,38 +432,39 @@ Outputs: A scala_library rule that includes the generated scalapb bindings, as well as any library dependencies needed to compile and use these. """ -def scalapb_proto_library( - name, - deps = [], - with_grpc = False, - with_java = False, - with_flat_package = False, - with_single_line_to_string = False, - visibility = None): - - srcjar = name + '_srcjar' - flags = [] - if with_grpc: - flags.append("grpc") - if with_java: - flags.append("java_conversions") - if with_flat_package: - flags.append("flat_package") - if with_single_line_to_string: - flags.append("single_line_to_string") - scala_proto_srcjar( - name = srcjar, - flags = flags, - generator = "@io_bazel_rules_scala//src/scala/scripts:scalapb_generator", - deps = deps, - visibility = visibility, - ) - - external_deps = list(SCALAPB_DEPS + GRPC_DEPS if (with_grpc) else SCALAPB_DEPS) - scala_library( - name = name, - deps = [srcjar] + external_deps, - exports = external_deps, - visibility = visibility, - ) +def scalapb_proto_library(name, + deps = [], + with_grpc = False, + with_java = False, + with_flat_package = False, + with_single_line_to_string = False, + visibility = None): + + srcjar = name + '_srcjar' + flags = [] + if with_grpc: + flags.append("grpc") + if with_java: + flags.append("java_conversions") + if with_flat_package: + flags.append("flat_package") + if with_single_line_to_string: + flags.append("single_line_to_string") + scala_proto_srcjar( + name = srcjar, + flags = flags, + generator = "@io_bazel_rules_scala//src/scala/scripts:scalapb_generator", + deps = deps, + visibility = visibility, + ) + + external_deps = list(SCALAPB_DEPS + GRPC_DEPS if ( + with_grpc) else SCALAPB_DEPS) + + scala_library( + name = name, + deps = [srcjar] + external_deps, + exports = external_deps, + visibility = visibility, + ) diff --git a/specs2/BUILD b/specs2/BUILD index 542000644..3b73536df 100644 --- a/specs2/BUILD +++ b/specs2/BUILD @@ -1,18 +1,19 @@ package(default_visibility = ["//visibility:public"]) + java_import( name = "specs2", jars = [], exports = [ - "@io_bazel_rules_scala_org_specs2_specs2_core//jar", - "@io_bazel_rules_scala_org_specs2_specs2_common//jar", - "@io_bazel_rules_scala_org_specs2_specs2_matcher//jar", - "@io_bazel_rules_scala_org_scalaz_scalaz_effect//jar", - "@io_bazel_rules_scala_org_scalaz_scalaz_core//jar", + "@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", ], deps = [ - "//external:io_bazel_rules_scala/dependency/scala/scala_xml", - "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "//external:io_bazel_rules_scala/dependency/scala/scala_reflect" - ] + "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_xml", + ], ) diff --git a/specs2/specs2.bzl b/specs2/specs2.bzl index 85b577080..260b34f18 100644 --- a/specs2/specs2.bzl +++ b/specs2/specs2.bzl @@ -1,26 +1,31 @@ -load("//scala:scala_cross_version.bzl", - "scala_mvn_artifact", - ) +load( + "//scala:scala_cross_version.bzl", + "scala_mvn_artifact", +) def specs2_version(): return "3.8.8" + def specs2_repositories(): native.maven_jar( name = "io_bazel_rules_scala_org_specs2_specs2_core", - artifact = scala_mvn_artifact("org.specs2:specs2-core:" + specs2_version()), + artifact = scala_mvn_artifact( + "org.specs2:specs2-core:" + specs2_version()), sha1 = "495bed00c73483f4f5f43945fde63c615d03e637", ) native.maven_jar( name = "io_bazel_rules_scala_org_specs2_specs2_common", - artifact = scala_mvn_artifact("org.specs2:specs2-common:" + specs2_version()), + artifact = scala_mvn_artifact( + "org.specs2:specs2-common:" + specs2_version()), sha1 = "15bc009eaae3a574796c0f558d8696b57ae903c3", ) native.maven_jar( name = "io_bazel_rules_scala_org_specs2_specs2_matcher", - artifact = scala_mvn_artifact("org.specs2:specs2-matcher:" + specs2_version()), + artifact = scala_mvn_artifact( + "org.specs2:specs2-matcher:" + specs2_version()), sha1 = "d2e967737abef7421e47b8994a8c92784e624d62", ) @@ -36,7 +41,9 @@ def specs2_repositories(): sha1 = "ebf85118d0bf4ce18acebf1d8475ee7deb7f19f1", ) - native.bind(name = 'io_bazel_rules_scala/dependency/specs2/specs2', actual = "@io_bazel_rules_scala//specs2:specs2") + native.bind( + name = 'io_bazel_rules_scala/dependency/specs2/specs2', + actual = "@io_bazel_rules_scala//specs2:specs2") def specs2_dependencies(): return ["//external:io_bazel_rules_scala/dependency/specs2/specs2"] diff --git a/specs2/specs2_junit.bzl b/specs2/specs2_junit.bzl index 5d3dbb819..771e86f48 100644 --- a/specs2/specs2_junit.bzl +++ b/specs2/specs2_junit.bzl @@ -1,17 +1,23 @@ -load("//specs2:specs2.bzl", "specs2_repositories", "specs2_dependencies", "specs2_version") +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() + specs2_repositories() junit_repositories() # 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()), + artifact = scala_mvn_artifact( + "org.specs2:specs2-junit:" + specs2_version()), sha1 = "1dc9e43970557c308ee313842d84094bc6c1c1b5", ) - native.bind(name = 'io_bazel_rules_scala/dependency/specs2/specs2_junit', actual = '@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar') + native.bind( + name = 'io_bazel_rules_scala/dependency/specs2/specs2_junit', + actual = '@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar') def specs2_junit_dependencies(): - return specs2_dependencies() + ["//external:io_bazel_rules_scala/dependency/specs2/specs2_junit"] + return specs2_dependencies() + [ + "//external:io_bazel_rules_scala/dependency/specs2/specs2_junit" + ] diff --git a/src/java/com/google/devtools/build/lib/BUILD b/src/java/com/google/devtools/build/lib/BUILD index 788aab5d0..971837d85 100644 --- a/src/java/com/google/devtools/build/lib/BUILD +++ b/src/java/com/google/devtools/build/lib/BUILD @@ -2,10 +2,10 @@ java_library( name = "worker", srcs = ["WorkerProtocol.java"], visibility = ["//visibility:public"], - deps = [ - "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java" - ], exports = [ - "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java" + "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", + ], + deps = [ + "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", ], ) diff --git a/src/java/com/google/devtools/build/lib/WorkerProtocol.java b/src/java/com/google/devtools/build/lib/WorkerProtocol.java index cc2de448d..3db880a94 100644 --- a/src/java/com/google/devtools/build/lib/WorkerProtocol.java +++ b/src/java/com/google/devtools/build/lib/WorkerProtocol.java @@ -1,14 +1,16 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// source: bazel-out/local-fastbuild/bin/external/io_bazel/src/main/protobuf/libworker_protocol_java_proto_srcjar.srcjar.preprocessed/worker_protocol.proto +// source: +// bazel-out/local-fastbuild/bin/external/io_bazel/src/main/protobuf/libworker_protocol_java_proto_srcjar.srcjar.preprocessed/worker_protocol.proto package com.google.devtools.build.lib.worker; public final class WorkerProtocol { private WorkerProtocol() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface InputOrBuilder extends + + public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {} + + public interface InputOrBuilder + extends // @@protoc_insertion_point(interface_extends:blaze.worker.Input) com.google.protobuf.MessageOrBuilder { @@ -33,8 +35,7 @@ public interface InputOrBuilder extends * absolute path. * */ - com.google.protobuf.ByteString - getPathBytes(); + com.google.protobuf.ByteString getPathBytes(); /** * optional bytes digest = 2; @@ -53,24 +54,25 @@ public interface InputOrBuilder extends * An input file. * */ - public static final class Input extends - com.google.protobuf.GeneratedMessage implements + public static final class Input extends com.google.protobuf.GeneratedMessage + implements // @@protoc_insertion_point(message_implements:blaze.worker.Input) InputOrBuilder { // Use Input.newBuilder() to construct. private Input(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); } + private Input() { path_ = ""; digest_ = com.google.protobuf.ByteString.EMPTY; } @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + private Input( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) { @@ -84,45 +86,49 @@ private Input( case 0: done = true; break; - default: { - if (!input.skipField(tag)) { - done = true; + default: + { + if (!input.skipField(tag)) { + done = true; + } + break; } - break; - } - case 10: { - String s = input.readStringRequireUtf8(); - - path_ = s; - break; - } - case 18: { + case 10: + { + String s = input.readStringRequireUtf8(); - digest_ = input.readBytes(); - break; - } + path_ = s; + break; + } + case 18: + { + digest_ = input.readBytes(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { throw new RuntimeException(e.setUnfinishedMessage(this)); } catch (java.io.IOException e) { throw new RuntimeException( - new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this)); + new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()) + .setUnfinishedMessage(this)); } finally { makeExtensionsImmutable(); } } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_Input_descriptor; + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_Input_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_Input_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.Input.class, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder.class); + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_Input_fieldAccessorTable.ensureFieldAccessorsInitialized( + com.google.devtools.build.lib.worker.WorkerProtocol.Input.class, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder.class); } public static final int PATH_FIELD_NUMBER = 1; @@ -142,8 +148,7 @@ public java.lang.String getPath() { if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); path_ = s; return s; @@ -159,13 +164,11 @@ public java.lang.String getPath() { * absolute path. * */ - public com.google.protobuf.ByteString - getPathBytes() { + public com.google.protobuf.ByteString getPathBytes() { java.lang.Object ref = path_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); path_ = b; return b; } else { @@ -188,6 +191,7 @@ public com.google.protobuf.ByteString getDigest() { } private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; @@ -197,8 +201,7 @@ public final boolean isInitialized() { return true; } - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!getPathBytes().isEmpty()) { com.google.protobuf.GeneratedMessage.writeString(output, 1, path_); } @@ -216,60 +219,65 @@ public int getSerializedSize() { size += com.google.protobuf.GeneratedMessage.computeStringSize(1, path_); } if (!digest_.isEmpty()) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(2, digest_); + size += com.google.protobuf.CodedOutputStream.computeBytesSize(2, digest_); } memoizedSize = size; return size; } private static final long serialVersionUID = 0L; + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( + java.io.InputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseFrom(input, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseDelimitedFrom( + java.io.InputStream input) throws java.io.IOException { return PARSER.parseDelimitedFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseDelimitedFrom(input, extensionRegistry); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { + com.google.protobuf.CodedInputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) @@ -277,21 +285,25 @@ public static com.google.devtools.build.lib.worker.WorkerProtocol.Input parseFro return PARSER.parseFrom(input, extensionRegistry); } - public Builder newBuilderForType() { return newBuilder(); } + public Builder newBuilderForType() { + return newBuilder(); + } + public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } - public static Builder newBuilder(com.google.devtools.build.lib.worker.WorkerProtocol.Input prototype) { + + public static Builder newBuilder( + com.google.devtools.build.lib.worker.WorkerProtocol.Input prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } + public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); } @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -302,20 +314,21 @@ protected Builder newBuilderForType( * An input file. * */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder + implements // @@protoc_insertion_point(builder_implements:blaze.worker.Input) com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_Input_descriptor; + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_Input_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_Input_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.Input.class, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder.class); + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_Input_fieldAccessorTable.ensureFieldAccessorsInitialized( + com.google.devtools.build.lib.worker.WorkerProtocol.Input.class, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder.class); } // Construct using com.google.devtools.build.lib.worker.WorkerProtocol.Input.newBuilder() @@ -323,15 +336,15 @@ private Builder() { maybeForceBuilderInitialization(); } - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } + private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {} } + public Builder clear() { super.clear(); path_ = ""; @@ -341,9 +354,9 @@ public Builder clear() { return this; } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_Input_descriptor; + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_Input_descriptor; } public com.google.devtools.build.lib.worker.WorkerProtocol.Input getDefaultInstanceForType() { @@ -359,7 +372,8 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input build() { } public com.google.devtools.build.lib.worker.WorkerProtocol.Input buildPartial() { - com.google.devtools.build.lib.worker.WorkerProtocol.Input result = new com.google.devtools.build.lib.worker.WorkerProtocol.Input(this); + com.google.devtools.build.lib.worker.WorkerProtocol.Input result = + new com.google.devtools.build.lib.worker.WorkerProtocol.Input(this); result.path_ = path_; result.digest_ = digest_; onBuilt(); @@ -368,7 +382,7 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input buildPartial() public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.devtools.build.lib.worker.WorkerProtocol.Input) { - return mergeFrom((com.google.devtools.build.lib.worker.WorkerProtocol.Input)other); + return mergeFrom((com.google.devtools.build.lib.worker.WorkerProtocol.Input) other); } else { super.mergeFrom(other); return this; @@ -376,7 +390,8 @@ public Builder mergeFrom(com.google.protobuf.Message other) { } public Builder mergeFrom(com.google.devtools.build.lib.worker.WorkerProtocol.Input other) { - if (other == com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()) return this; + if (other == com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()) + return this; if (!other.getPath().isEmpty()) { path_ = other.path_; onChanged(); @@ -400,7 +415,8 @@ public Builder mergeFrom( try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.google.devtools.build.lib.worker.WorkerProtocol.Input) e.getUnfinishedMessage(); + parsedMessage = + (com.google.devtools.build.lib.worker.WorkerProtocol.Input) e.getUnfinishedMessage(); throw e; } finally { if (parsedMessage != null) { @@ -424,8 +440,7 @@ public Builder mergeFrom( public java.lang.String getPath() { java.lang.Object ref = path_; if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); path_ = s; return s; @@ -443,13 +458,11 @@ public java.lang.String getPath() { * absolute path. * */ - public com.google.protobuf.ByteString - getPathBytes() { + public com.google.protobuf.ByteString getPathBytes() { java.lang.Object ref = path_; if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); path_ = b; return b; } else { @@ -466,12 +479,11 @@ public java.lang.String getPath() { * absolute path. * */ - public Builder setPath( - java.lang.String value) { + public Builder setPath(java.lang.String value) { if (value == null) { - throw new NullPointerException(); - } - + throw new NullPointerException(); + } + path_ = value; onChanged(); return this; @@ -487,7 +499,7 @@ public Builder setPath( * */ public Builder clearPath() { - + path_ = getDefaultInstance().getPath(); onChanged(); return this; @@ -502,13 +514,12 @@ public Builder clearPath() { * absolute path. * */ - public Builder setPathBytes( - com.google.protobuf.ByteString value) { + public Builder setPathBytes(com.google.protobuf.ByteString value) { if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + path_ = value; onChanged(); return this; @@ -536,9 +547,9 @@ public com.google.protobuf.ByteString getDigest() { */ public Builder setDigest(com.google.protobuf.ByteString value) { if (value == null) { - throw new NullPointerException(); - } - + throw new NullPointerException(); + } + digest_ = value; onChanged(); return this; @@ -552,11 +563,12 @@ public Builder setDigest(com.google.protobuf.ByteString value) { * */ public Builder clearDigest() { - + digest_ = getDefaultInstance().getDigest(); onChanged(); return this; } + public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; @@ -567,12 +579,12 @@ public final Builder mergeUnknownFields( return this; } - // @@protoc_insertion_point(builder_scope:blaze.worker.Input) } // @@protoc_insertion_point(class_scope:blaze.worker.Input) private static final com.google.devtools.build.lib.worker.WorkerProtocol.Input DEFAULT_INSTANCE; + static { DEFAULT_INSTANCE = new com.google.devtools.build.lib.worker.WorkerProtocol.Input(); } @@ -581,24 +593,22 @@ public static com.google.devtools.build.lib.worker.WorkerProtocol.Input getDefau return DEFAULT_INSTANCE; } - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Input parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - try { - return new Input(input, extensionRegistry); - } catch (RuntimeException e) { - if (e.getCause() instanceof - com.google.protobuf.InvalidProtocolBufferException) { - throw (com.google.protobuf.InvalidProtocolBufferException) - e.getCause(); + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public Input parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new Input(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) e.getCause(); + } + throw e; + } } - throw e; - } - } - }; + }; public static com.google.protobuf.Parser parser() { return PARSER; @@ -612,31 +622,21 @@ public com.google.protobuf.Parser getParserForType() { public com.google.devtools.build.lib.worker.WorkerProtocol.Input getDefaultInstanceForType() { return DEFAULT_INSTANCE; } - } - public interface WorkRequestOrBuilder extends + public interface WorkRequestOrBuilder + extends // @@protoc_insertion_point(interface_extends:blaze.worker.WorkRequest) com.google.protobuf.MessageOrBuilder { - /** - * repeated string arguments = 1; - */ - com.google.protobuf.ProtocolStringList - getArgumentsList(); - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ + com.google.protobuf.ProtocolStringList getArgumentsList(); + /** repeated string arguments = 1; */ int getArgumentsCount(); - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ java.lang.String getArguments(int index); - /** - * repeated string arguments = 1; - */ - com.google.protobuf.ByteString - getArgumentsBytes(int index); + /** repeated string arguments = 1; */ + com.google.protobuf.ByteString getArgumentsBytes(int index); /** * repeated .blaze.worker.Input inputs = 2; @@ -646,8 +646,7 @@ public interface WorkRequestOrBuilder extends * request. * */ - java.util.List - getInputsList(); + java.util.List getInputsList(); /** * repeated .blaze.worker.Input inputs = 2; * @@ -674,7 +673,7 @@ public interface WorkRequestOrBuilder extends * request. * */ - java.util.List + java.util.List getInputsOrBuilderList(); /** * repeated .blaze.worker.Input inputs = 2; @@ -694,24 +693,25 @@ com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder getInputsOrBu * This represents a single work unit that Blaze sends to the worker. * */ - public static final class WorkRequest extends - com.google.protobuf.GeneratedMessage implements + public static final class WorkRequest extends com.google.protobuf.GeneratedMessage + implements // @@protoc_insertion_point(message_implements:blaze.worker.WorkRequest) WorkRequestOrBuilder { // Use WorkRequest.newBuilder() to construct. private WorkRequest(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); } + private WorkRequest() { arguments_ = com.google.protobuf.LazyStringArrayList.EMPTY; inputs_ = java.util.Collections.emptyList(); } @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + private WorkRequest( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) { @@ -725,37 +725,45 @@ private WorkRequest( case 0: done = true; break; - default: { - if (!input.skipField(tag)) { - done = true; + default: + { + if (!input.skipField(tag)) { + done = true; + } + break; } - break; - } - case 10: { - String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - arguments_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; + case 10: + { + String s = input.readStringRequireUtf8(); + if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { + arguments_ = new com.google.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000001; + } + arguments_.add(s); + break; } - arguments_.add(s); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - inputs_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000002; + case 18: + { + if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { + inputs_ = + new java.util.ArrayList< + com.google.devtools.build.lib.worker.WorkerProtocol.Input>(); + mutable_bitField0_ |= 0x00000002; + } + inputs_.add( + input.readMessage( + com.google.devtools.build.lib.worker.WorkerProtocol.Input.parser(), + extensionRegistry)); + break; } - inputs_.add(input.readMessage(com.google.devtools.build.lib.worker.WorkerProtocol.Input.parser(), extensionRegistry)); - break; - } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { throw new RuntimeException(e.setUnfinishedMessage(this)); } catch (java.io.IOException e) { throw new RuntimeException( - new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this)); + new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()) + .setUnfinishedMessage(this)); } finally { if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { arguments_ = arguments_.getUnmodifiableView(); @@ -766,44 +774,37 @@ private WorkRequest( makeExtensionsImmutable(); } } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkRequest_descriptor; + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkRequest_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkRequest_fieldAccessorTable + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.class, com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.Builder.class); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.class, + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.Builder.class); } public static final int ARGUMENTS_FIELD_NUMBER = 1; private com.google.protobuf.LazyStringList arguments_; - /** - * repeated string arguments = 1; - */ - public com.google.protobuf.ProtocolStringList - getArgumentsList() { + /** repeated string arguments = 1; */ + public com.google.protobuf.ProtocolStringList getArgumentsList() { return arguments_; } - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ public int getArgumentsCount() { return arguments_.size(); } - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ public java.lang.String getArguments(int index) { return arguments_.get(index); } - /** - * repeated string arguments = 1; - */ - public com.google.protobuf.ByteString - getArgumentsBytes(int index) { + /** repeated string arguments = 1; */ + public com.google.protobuf.ByteString getArgumentsBytes(int index) { return arguments_.getByteString(index); } @@ -817,7 +818,8 @@ public java.lang.String getArguments(int index) { * request. * */ - public java.util.List getInputsList() { + public java.util.List + getInputsList() { return inputs_; } /** @@ -828,7 +830,8 @@ public java.util.List * request. * */ - public java.util.List + public java.util.List< + ? extends com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> getInputsOrBuilderList() { return inputs_; } @@ -868,6 +871,7 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder getInp } private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; @@ -877,8 +881,7 @@ public final boolean isInitialized() { return true; } - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { for (int i = 0; i < arguments_.size(); i++) { com.google.protobuf.GeneratedMessage.writeString(output, 1, arguments_.getRaw(i)); } @@ -901,60 +904,66 @@ public int getSerializedSize() { size += 1 * getArgumentsList().size(); } for (int i = 0; i < inputs_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, inputs_.get(i)); + size += com.google.protobuf.CodedOutputStream.computeMessageSize(2, inputs_.get(i)); } memoizedSize = size; return size; } private static final long serialVersionUID = 0L; + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( + byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( + java.io.InputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseFrom(input, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return PARSER.parseDelimitedFrom(input); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { return PARSER.parseDelimitedFrom(input, extensionRegistry); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { + com.google.protobuf.CodedInputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) @@ -962,21 +971,25 @@ public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest pa return PARSER.parseFrom(input, extensionRegistry); } - public Builder newBuilderForType() { return newBuilder(); } + public Builder newBuilderForType() { + return newBuilder(); + } + public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } - public static Builder newBuilder(com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest prototype) { + + public static Builder newBuilder( + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } + public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); } @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -987,37 +1000,41 @@ protected Builder newBuilderForType( * This represents a single work unit that Blaze sends to the worker. * */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder + implements // @@protoc_insertion_point(builder_implements:blaze.worker.WorkRequest) com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkRequest_descriptor; + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkRequest_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkRequest_fieldAccessorTable + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkRequest_fieldAccessorTable .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.class, com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.Builder.class); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.class, + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.Builder.class); } - // Construct using com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.newBuilder() + // Construct using + // com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.newBuilder() private Builder() { maybeForceBuilderInitialization(); } - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } + private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { getInputsFieldBuilder(); } } + public Builder clear() { super.clear(); arguments_ = com.google.protobuf.LazyStringArrayList.EMPTY; @@ -1031,12 +1048,13 @@ public Builder clear() { return this; } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkRequest_descriptor; + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkRequest_descriptor; } - public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest getDefaultInstanceForType() { + public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + getDefaultInstanceForType() { return com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.getDefaultInstance(); } @@ -1049,7 +1067,8 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest build() { } public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest buildPartial() { - com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest result = new com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest(this); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest result = + new com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest(this); int from_bitField0_ = bitField0_; if (((bitField0_ & 0x00000001) == 0x00000001)) { arguments_ = arguments_.getUnmodifiableView(); @@ -1071,15 +1090,18 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest buildPart public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest) { - return mergeFrom((com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest)other); + return mergeFrom((com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest) other); } else { super.mergeFrom(other); return this; } } - public Builder mergeFrom(com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest other) { - if (other == com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.getDefaultInstance()) return this; + public Builder mergeFrom( + com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest other) { + if (other + == com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest.getDefaultInstance()) + return this; if (!other.arguments_.isEmpty()) { if (arguments_.isEmpty()) { arguments_ = other.arguments_; @@ -1108,9 +1130,10 @@ public Builder mergeFrom(com.google.devtools.build.lib.worker.WorkerProtocol.Wor inputsBuilder_ = null; inputs_ = other.inputs_; bitField0_ = (bitField0_ & ~0x00000002); - inputsBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getInputsFieldBuilder() : null; + inputsBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders + ? getInputsFieldBuilder() + : null; } else { inputsBuilder_.addAllMessages(other.inputs_); } @@ -1132,7 +1155,9 @@ public Builder mergeFrom( try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest) e.getUnfinishedMessage(); + parsedMessage = + (com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest) + e.getUnfinishedMessage(); throw e; } finally { if (parsedMessage != null) { @@ -1141,96 +1166,74 @@ public Builder mergeFrom( } return this; } + private int bitField0_; - private com.google.protobuf.LazyStringList arguments_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private com.google.protobuf.LazyStringList arguments_ = + com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureArgumentsIsMutable() { if (!((bitField0_ & 0x00000001) == 0x00000001)) { arguments_ = new com.google.protobuf.LazyStringArrayList(arguments_); bitField0_ |= 0x00000001; - } + } } - /** - * repeated string arguments = 1; - */ - public com.google.protobuf.ProtocolStringList - getArgumentsList() { + /** repeated string arguments = 1; */ + public com.google.protobuf.ProtocolStringList getArgumentsList() { return arguments_.getUnmodifiableView(); } - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ public int getArgumentsCount() { return arguments_.size(); } - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ public java.lang.String getArguments(int index) { return arguments_.get(index); } - /** - * repeated string arguments = 1; - */ - public com.google.protobuf.ByteString - getArgumentsBytes(int index) { + /** repeated string arguments = 1; */ + public com.google.protobuf.ByteString getArgumentsBytes(int index) { return arguments_.getByteString(index); } - /** - * repeated string arguments = 1; - */ - public Builder setArguments( - int index, java.lang.String value) { + /** repeated string arguments = 1; */ + public Builder setArguments(int index, java.lang.String value) { if (value == null) { - throw new NullPointerException(); - } - ensureArgumentsIsMutable(); + throw new NullPointerException(); + } + ensureArgumentsIsMutable(); arguments_.set(index, value); onChanged(); return this; } - /** - * repeated string arguments = 1; - */ - public Builder addArguments( - java.lang.String value) { + /** repeated string arguments = 1; */ + public Builder addArguments(java.lang.String value) { if (value == null) { - throw new NullPointerException(); - } - ensureArgumentsIsMutable(); + throw new NullPointerException(); + } + ensureArgumentsIsMutable(); arguments_.add(value); onChanged(); return this; } - /** - * repeated string arguments = 1; - */ - public Builder addAllArguments( - java.lang.Iterable values) { + /** repeated string arguments = 1; */ + public Builder addAllArguments(java.lang.Iterable values) { ensureArgumentsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, arguments_); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, arguments_); onChanged(); return this; } - /** - * repeated string arguments = 1; - */ + /** repeated string arguments = 1; */ public Builder clearArguments() { arguments_ = com.google.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } - /** - * repeated string arguments = 1; - */ - public Builder addArgumentsBytes( - com.google.protobuf.ByteString value) { + /** repeated string arguments = 1; */ + public Builder addArgumentsBytes(com.google.protobuf.ByteString value) { if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); ensureArgumentsIsMutable(); arguments_.add(value); onChanged(); @@ -1238,16 +1241,22 @@ public Builder addArgumentsBytes( } private java.util.List inputs_ = - java.util.Collections.emptyList(); + java.util.Collections.emptyList(); + private void ensureInputsIsMutable() { if (!((bitField0_ & 0x00000002) == 0x00000002)) { - inputs_ = new java.util.ArrayList(inputs_); + inputs_ = + new java.util.ArrayList( + inputs_); bitField0_ |= 0x00000002; - } + } } private com.google.protobuf.RepeatedFieldBuilder< - com.google.devtools.build.lib.worker.WorkerProtocol.Input, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> inputsBuilder_; + com.google.devtools.build.lib.worker.WorkerProtocol.Input, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, + com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> + inputsBuilder_; /** * repeated .blaze.worker.Input inputs = 2; @@ -1257,7 +1266,8 @@ private void ensureInputsIsMutable() { * request. * */ - public java.util.List getInputsList() { + public java.util.List + getInputsList() { if (inputsBuilder_ == null) { return java.util.Collections.unmodifiableList(inputs_); } else { @@ -1325,7 +1335,8 @@ public Builder setInputs( * */ public Builder setInputs( - int index, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder builderForValue) { + int index, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder builderForValue) { if (inputsBuilder_ == null) { ensureInputsIsMutable(); inputs_.set(index, builderForValue.build()); @@ -1406,7 +1417,8 @@ public Builder addInputs( * */ public Builder addInputs( - int index, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder builderForValue) { + int index, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder builderForValue) { if (inputsBuilder_ == null) { ensureInputsIsMutable(); inputs_.add(index, builderForValue.build()); @@ -1425,11 +1437,11 @@ public Builder addInputs( * */ public Builder addAllInputs( - java.lang.Iterable values) { + java.lang.Iterable + values) { if (inputsBuilder_ == null) { ensureInputsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, inputs_); + com.google.protobuf.AbstractMessageLite.Builder.addAll(values, inputs_); onChanged(); } else { inputsBuilder_.addAllMessages(values); @@ -1495,7 +1507,8 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder getInpu public com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder getInputsOrBuilder( int index) { if (inputsBuilder_ == null) { - return inputs_.get(index); } else { + return inputs_.get(index); + } else { return inputsBuilder_.getMessageOrBuilder(index); } } @@ -1507,8 +1520,9 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder getInp * request. * */ - public java.util.List - getInputsOrBuilderList() { + public java.util.List< + ? extends com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> + getInputsOrBuilderList() { if (inputsBuilder_ != null) { return inputsBuilder_.getMessageOrBuilderList(); } else { @@ -1524,8 +1538,9 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder getInp * */ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder addInputsBuilder() { - return getInputsFieldBuilder().addBuilder( - com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()); + return getInputsFieldBuilder() + .addBuilder( + com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()); } /** * repeated .blaze.worker.Input inputs = 2; @@ -1537,8 +1552,10 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder addInpu */ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder addInputsBuilder( int index) { - return getInputsFieldBuilder().addBuilder( - index, com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()); + return getInputsFieldBuilder() + .addBuilder( + index, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.getDefaultInstance()); } /** * repeated .blaze.worker.Input inputs = 2; @@ -1548,16 +1565,22 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder addInpu * request. * */ - public java.util.List - getInputsBuilderList() { + public java.util.List + getInputsBuilderList() { return getInputsFieldBuilder().getBuilderList(); } + private com.google.protobuf.RepeatedFieldBuilder< - com.google.devtools.build.lib.worker.WorkerProtocol.Input, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> + com.google.devtools.build.lib.worker.WorkerProtocol.Input, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, + com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder> getInputsFieldBuilder() { if (inputsBuilder_ == null) { - inputsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< - com.google.devtools.build.lib.worker.WorkerProtocol.Input, com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder>( + inputsBuilder_ = + new com.google.protobuf.RepeatedFieldBuilder< + com.google.devtools.build.lib.worker.WorkerProtocol.Input, + com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder, + com.google.devtools.build.lib.worker.WorkerProtocol.InputOrBuilder>( inputs_, ((bitField0_ & 0x00000002) == 0x00000002), getParentForChildren(), @@ -1566,6 +1589,7 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.Input.Builder addInpu } return inputsBuilder_; } + public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; @@ -1576,38 +1600,38 @@ public final Builder mergeUnknownFields( return this; } - // @@protoc_insertion_point(builder_scope:blaze.worker.WorkRequest) } // @@protoc_insertion_point(class_scope:blaze.worker.WorkRequest) - private static final com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest DEFAULT_INSTANCE; + private static final com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + DEFAULT_INSTANCE; + static { DEFAULT_INSTANCE = new com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest(); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest getDefaultInstance() { + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + getDefaultInstance() { return DEFAULT_INSTANCE; } - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public WorkRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - try { - return new WorkRequest(input, extensionRegistry); - } catch (RuntimeException e) { - if (e.getCause() instanceof - com.google.protobuf.InvalidProtocolBufferException) { - throw (com.google.protobuf.InvalidProtocolBufferException) - e.getCause(); + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public WorkRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new WorkRequest(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) e.getCause(); + } + throw e; + } } - throw e; - } - } - }; + }; public static com.google.protobuf.Parser parser() { return PARSER; @@ -1618,19 +1642,18 @@ public com.google.protobuf.Parser getParserForType() { return PARSER; } - public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest getDefaultInstanceForType() { + public com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest + getDefaultInstanceForType() { return DEFAULT_INSTANCE; } - } - public interface WorkResponseOrBuilder extends + public interface WorkResponseOrBuilder + extends // @@protoc_insertion_point(interface_extends:blaze.worker.WorkResponse) com.google.protobuf.MessageOrBuilder { - /** - * optional int32 exit_code = 1; - */ + /** optional int32 exit_code = 1; */ int getExitCode(); /** @@ -1652,8 +1675,7 @@ public interface WorkResponseOrBuilder extends * encoding. * */ - com.google.protobuf.ByteString - getOutputBytes(); + com.google.protobuf.ByteString getOutputBytes(); } /** * Protobuf type {@code blaze.worker.WorkResponse} @@ -1662,24 +1684,25 @@ public interface WorkResponseOrBuilder extends * The worker sends this message to Blaze when it finished its work on the WorkRequest message. * */ - public static final class WorkResponse extends - com.google.protobuf.GeneratedMessage implements + public static final class WorkResponse extends com.google.protobuf.GeneratedMessage + implements // @@protoc_insertion_point(message_implements:blaze.worker.WorkResponse) WorkResponseOrBuilder { // Use WorkResponse.newBuilder() to construct. private WorkResponse(com.google.protobuf.GeneratedMessage.Builder builder) { super(builder); } + private WorkResponse() { exitCode_ = 0; output_ = ""; } @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { + public final com.google.protobuf.UnknownFieldSet getUnknownFields() { return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + private WorkResponse( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) { @@ -1693,52 +1716,55 @@ private WorkResponse( case 0: done = true; break; - default: { - if (!input.skipField(tag)) { - done = true; + default: + { + if (!input.skipField(tag)) { + done = true; + } + break; } - break; - } - case 8: { - - exitCode_ = input.readInt32(); - break; - } - case 18: { - String s = input.readStringRequireUtf8(); + case 8: + { + exitCode_ = input.readInt32(); + break; + } + case 18: + { + String s = input.readStringRequireUtf8(); - output_ = s; - break; - } + output_ = s; + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { throw new RuntimeException(e.setUnfinishedMessage(this)); } catch (java.io.IOException e) { throw new RuntimeException( - new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this)); + new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()) + .setUnfinishedMessage(this)); } finally { makeExtensionsImmutable(); } } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkResponse_descriptor; + + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkResponse_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkResponse_fieldAccessorTable + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.class, com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.Builder.class); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.class, + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.Builder.class); } public static final int EXIT_CODE_FIELD_NUMBER = 1; private int exitCode_; - /** - * optional int32 exit_code = 1; - */ + /** optional int32 exit_code = 1; */ public int getExitCode() { return exitCode_; } @@ -1759,8 +1785,7 @@ public java.lang.String getOutput() { if (ref instanceof java.lang.String) { return (java.lang.String) ref; } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); output_ = s; return s; @@ -1775,13 +1800,11 @@ public java.lang.String getOutput() { * encoding. * */ - public com.google.protobuf.ByteString - getOutputBytes() { + public com.google.protobuf.ByteString getOutputBytes() { java.lang.Object ref = output_; if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); output_ = b; return b; } else { @@ -1790,6 +1813,7 @@ public java.lang.String getOutput() { } private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized == 1) return true; @@ -1799,8 +1823,7 @@ public final boolean isInitialized() { return true; } - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { + public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (exitCode_ != 0) { output.writeInt32(1, exitCode_); } @@ -1815,8 +1838,7 @@ public int getSerializedSize() { size = 0; if (exitCode_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, exitCode_); + size += com.google.protobuf.CodedOutputStream.computeInt32Size(1, exitCode_); } if (!getOutputBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessage.computeStringSize(2, output_); @@ -1826,52 +1848,59 @@ public int getSerializedSize() { } private static final long serialVersionUID = 0L; + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( + byte[] data) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException { return PARSER.parseFrom(data, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( + java.io.InputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { return PARSER.parseFrom(input, extensionRegistry); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException { return PARSER.parseDelimitedFrom(input); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { + + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + parseDelimitedFrom( + java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { return PARSER.parseDelimitedFrom(input, extensionRegistry); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { + com.google.protobuf.CodedInputStream input) throws java.io.IOException { return PARSER.parseFrom(input); } + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse parseFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) @@ -1879,21 +1908,25 @@ public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse p return PARSER.parseFrom(input, extensionRegistry); } - public Builder newBuilderForType() { return newBuilder(); } + public Builder newBuilderForType() { + return newBuilder(); + } + public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } - public static Builder newBuilder(com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse prototype) { + + public static Builder newBuilder( + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } + public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); + return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); } @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } @@ -1904,36 +1937,39 @@ protected Builder newBuilderForType( * The worker sends this message to Blaze when it finished its work on the WorkRequest message. * */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements + public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder + implements // @@protoc_insertion_point(builder_implements:blaze.worker.WorkResponse) com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkResponse_descriptor; + public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkResponse_descriptor; } protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkResponse_fieldAccessorTable + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkResponse_fieldAccessorTable .ensureFieldAccessorsInitialized( - com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.class, com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.Builder.class); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.class, + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.Builder.class); } - // Construct using com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.newBuilder() + // Construct using + // com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.newBuilder() private Builder() { maybeForceBuilderInitialization(); } - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { + private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } + private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {} } + public Builder clear() { super.clear(); exitCode_ = 0; @@ -1943,13 +1979,15 @@ public Builder clear() { return this; } - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.google.devtools.build.lib.worker.WorkerProtocol.internal_static_blaze_worker_WorkResponse_descriptor; + public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { + return com.google.devtools.build.lib.worker.WorkerProtocol + .internal_static_blaze_worker_WorkResponse_descriptor; } - public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse getDefaultInstanceForType() { - return com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.getDefaultInstance(); + public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + getDefaultInstanceForType() { + return com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + .getDefaultInstance(); } public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse build() { @@ -1961,7 +1999,8 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse build() } public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse buildPartial() { - com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse result = new com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse(this); + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse result = + new com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse(this); result.exitCode_ = exitCode_; result.output_ = output_; onBuilt(); @@ -1970,15 +2009,19 @@ public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse buildPar public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse) { - return mergeFrom((com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse)other); + return mergeFrom( + (com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse) other); } else { super.mergeFrom(other); return this; } } - public Builder mergeFrom(com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse other) { - if (other == com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse.getDefaultInstance()) return this; + public Builder mergeFrom( + com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse other) { + if (other + == com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + .getDefaultInstance()) return this; if (other.getExitCode() != 0) { setExitCode(other.getExitCode()); } @@ -2002,7 +2045,9 @@ public Builder mergeFrom( try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse) e.getUnfinishedMessage(); + parsedMessage = + (com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse) + e.getUnfinishedMessage(); throw e; } finally { if (parsedMessage != null) { @@ -2012,27 +2057,21 @@ public Builder mergeFrom( return this; } - private int exitCode_ ; - /** - * optional int32 exit_code = 1; - */ + private int exitCode_; + /** optional int32 exit_code = 1; */ public int getExitCode() { return exitCode_; } - /** - * optional int32 exit_code = 1; - */ + /** optional int32 exit_code = 1; */ public Builder setExitCode(int value) { - + exitCode_ = value; onChanged(); return this; } - /** - * optional int32 exit_code = 1; - */ + /** optional int32 exit_code = 1; */ public Builder clearExitCode() { - + exitCode_ = 0; onChanged(); return this; @@ -2051,8 +2090,7 @@ public Builder clearExitCode() { public java.lang.String getOutput() { java.lang.Object ref = output_; if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; + com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; java.lang.String s = bs.toStringUtf8(); output_ = s; return s; @@ -2069,13 +2107,11 @@ public java.lang.String getOutput() { * encoding. * */ - public com.google.protobuf.ByteString - getOutputBytes() { + public com.google.protobuf.ByteString getOutputBytes() { java.lang.Object ref = output_; if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); output_ = b; return b; } else { @@ -2091,12 +2127,11 @@ public java.lang.String getOutput() { * encoding. * */ - public Builder setOutput( - java.lang.String value) { + public Builder setOutput(java.lang.String value) { if (value == null) { - throw new NullPointerException(); - } - + throw new NullPointerException(); + } + output_ = value; onChanged(); return this; @@ -2111,7 +2146,7 @@ public Builder setOutput( * */ public Builder clearOutput() { - + output_ = getDefaultInstance().getOutput(); onChanged(); return this; @@ -2125,17 +2160,17 @@ public Builder clearOutput() { * encoding. * */ - public Builder setOutputBytes( - com.google.protobuf.ByteString value) { + public Builder setOutputBytes(com.google.protobuf.ByteString value) { if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + output_ = value; onChanged(); return this; } + public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { return this; @@ -2146,38 +2181,38 @@ public final Builder mergeUnknownFields( return this; } - // @@protoc_insertion_point(builder_scope:blaze.worker.WorkResponse) } // @@protoc_insertion_point(class_scope:blaze.worker.WorkResponse) - private static final com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse DEFAULT_INSTANCE; + private static final com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + DEFAULT_INSTANCE; + static { DEFAULT_INSTANCE = new com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse(); } - public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse getDefaultInstance() { + public static com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + getDefaultInstance() { return DEFAULT_INSTANCE; } - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public WorkResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - try { - return new WorkResponse(input, extensionRegistry); - } catch (RuntimeException e) { - if (e.getCause() instanceof - com.google.protobuf.InvalidProtocolBufferException) { - throw (com.google.protobuf.InvalidProtocolBufferException) - e.getCause(); + private static final com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public WorkResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + try { + return new WorkResponse(input, extensionRegistry); + } catch (RuntimeException e) { + if (e.getCause() instanceof com.google.protobuf.InvalidProtocolBufferException) { + throw (com.google.protobuf.InvalidProtocolBufferException) e.getCause(); + } + throw e; + } } - throw e; - } - } - }; + }; public static com.google.protobuf.Parser parser() { return PARSER; @@ -2188,77 +2223,75 @@ public com.google.protobuf.Parser getParserForType() { return PARSER; } - public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse getDefaultInstanceForType() { + public com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse + getDefaultInstanceForType() { return DEFAULT_INSTANCE; } - } private static com.google.protobuf.Descriptors.Descriptor - internal_static_blaze_worker_Input_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_blaze_worker_Input_descriptor; + private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_blaze_worker_Input_fieldAccessorTable; private static com.google.protobuf.Descriptors.Descriptor - internal_static_blaze_worker_WorkRequest_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_blaze_worker_WorkRequest_descriptor; + private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_blaze_worker_WorkRequest_fieldAccessorTable; private static com.google.protobuf.Descriptors.Descriptor - internal_static_blaze_worker_WorkResponse_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_blaze_worker_WorkResponse_descriptor; + private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_blaze_worker_WorkResponse_fieldAccessorTable; - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { + public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { return descriptor; } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; + + private static com.google.protobuf.Descriptors.FileDescriptor descriptor; + static { java.lang.String[] descriptorData = { - "\n\220\001bazel-out/local-fastbuild/bin/externa" + - "l/io_bazel/src/main/protobuf/libworker_p" + - "rotocol_java_proto_srcjar.srcjar.preproc" + - "essed/worker_protocol.proto\022\014blaze.worke" + - "r\"%\n\005Input\022\014\n\004path\030\001 \001(\t\022\016\n\006digest\030\002 \001(\014" + - "\"E\n\013WorkRequest\022\021\n\targuments\030\001 \003(\t\022#\n\006in" + - "puts\030\002 \003(\0132\023.blaze.worker.Input\"1\n\014WorkR" + - "esponse\022\021\n\texit_code\030\001 \001(\005\022\016\n\006output\030\002 \001" + - "(\tB&\n$com.google.devtools.build.lib.work" + - "erb\006proto3" + "\n\220\001bazel-out/local-fastbuild/bin/externa" + + "l/io_bazel/src/main/protobuf/libworker_p" + + "rotocol_java_proto_srcjar.srcjar.preproc" + + "essed/worker_protocol.proto\022\014blaze.worke" + + "r\"%\n\005Input\022\014\n\004path\030\001 \001(\t\022\016\n\006digest\030\002 \001(\014" + + "\"E\n\013WorkRequest\022\021\n\targuments\030\001 \003(\t\022#\n\006in" + + "puts\030\002 \003(\0132\023.blaze.worker.Input\"1\n\014WorkR" + + "esponse\022\021\n\texit_code\030\001 \001(\005\022\016\n\006output\030\002 \001" + + "(\tB&\n$com.google.devtools.build.lib.work" + + "erb\006proto3" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { public com.google.protobuf.ExtensionRegistry assignDescriptors( com.google.protobuf.Descriptors.FileDescriptor root) { descriptor = root; return null; } }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_blaze_worker_Input_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_blaze_worker_Input_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_blaze_worker_Input_descriptor, - new java.lang.String[] { "Path", "Digest", }); - internal_static_blaze_worker_WorkRequest_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_blaze_worker_WorkRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_blaze_worker_WorkRequest_descriptor, - new java.lang.String[] { "Arguments", "Inputs", }); - internal_static_blaze_worker_WorkResponse_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_blaze_worker_WorkResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_blaze_worker_WorkResponse_descriptor, - new java.lang.String[] { "ExitCode", "Output", }); + com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( + descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner); + internal_static_blaze_worker_Input_descriptor = getDescriptor().getMessageTypes().get(0); + internal_static_blaze_worker_Input_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_blaze_worker_Input_descriptor, + new java.lang.String[] { + "Path", "Digest", + }); + internal_static_blaze_worker_WorkRequest_descriptor = getDescriptor().getMessageTypes().get(1); + internal_static_blaze_worker_WorkRequest_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_blaze_worker_WorkRequest_descriptor, + new java.lang.String[] { + "Arguments", "Inputs", + }); + internal_static_blaze_worker_WorkResponse_descriptor = getDescriptor().getMessageTypes().get(2); + internal_static_blaze_worker_WorkResponse_fieldAccessorTable = + new com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_blaze_worker_WorkResponse_descriptor, + new java.lang.String[] { + "ExitCode", "Output", + }); } // @@protoc_insertion_point(outer_class_scope) diff --git a/src/java/io/bazel/rulesscala/io_utils/BUILD b/src/java/io/bazel/rulesscala/io_utils/BUILD index 44dfc89ce..3d72bd8e1 100644 --- a/src/java/io/bazel/rulesscala/io_utils/BUILD +++ b/src/java/io/bazel/rulesscala/io_utils/BUILD @@ -2,4 +2,4 @@ java_library( name = "io_utils", srcs = glob(["*.java"]), visibility = ["//visibility:public"], - ) +) diff --git a/src/java/io/bazel/rulesscala/io_utils/DeleteRecursively.java b/src/java/io/bazel/rulesscala/io_utils/DeleteRecursively.java index bb1fba702..a9e4bafd3 100644 --- a/src/java/io/bazel/rulesscala/io_utils/DeleteRecursively.java +++ b/src/java/io/bazel/rulesscala/io_utils/DeleteRecursively.java @@ -1,23 +1,26 @@ package io.bazel.rulesscala.io_utils; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.*; import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; public class DeleteRecursively { public static void run(Path path) throws IOException { - Files.walkFileTree(path, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } + Files.walkFileTree( + path, + new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }); + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); } } diff --git a/src/java/io/bazel/rulesscala/jar/BUILD b/src/java/io/bazel/rulesscala/jar/BUILD index f8e6c90ed..173484d19 100644 --- a/src/java/io/bazel/rulesscala/jar/BUILD +++ b/src/java/io/bazel/rulesscala/jar/BUILD @@ -1,13 +1,17 @@ -java_library(name = "jar", - srcs = ["JarCreator.java", "JarHelper.java"], - visibility = ["//visibility:public"], +java_library( + name = "jar", + srcs = [ + "JarCreator.java", + "JarHelper.java", + ], + visibility = ["//visibility:public"], ) - -java_binary(name = "binary", - runtime_deps = [ - ":jar", - ], - main_class = "io.bazel.rulesscala.jar.JarCreator", - visibility = ["//visibility:public"], +java_binary( + name = "binary", + main_class = "io.bazel.rulesscala.jar.JarCreator", + visibility = ["//visibility:public"], + runtime_deps = [ + ":jar", + ], ) diff --git a/src/java/io/bazel/rulesscala/jar/JarCreator.java b/src/java/io/bazel/rulesscala/jar/JarCreator.java index 6b6fdb1bb..12a92f078 100644 --- a/src/java/io/bazel/rulesscala/jar/JarCreator.java +++ b/src/java/io/bazel/rulesscala/jar/JarCreator.java @@ -69,9 +69,9 @@ public boolean addEntry(String entryName, Path path) { if (entryName.startsWith("/")) { entryName = entryName.substring(1); } else if (entryName.length() >= 3 - && Character.isLetter(entryName.charAt(0)) - && entryName.charAt(1) == ':' - && (entryName.charAt(2) == '\\' || entryName.charAt(2) == '/')) { + && Character.isLetter(entryName.charAt(0)) + && entryName.charAt(1) == ':' + && (entryName.charAt(2) == '\\' || entryName.charAt(2) == '/')) { // Windows absolute path, e.g. "D:\foo" or "e:/blah". // Windows paths are case-insensitive, and support both backslashes and forward slashes. entryName = entryName.substring(3); @@ -116,44 +116,44 @@ public void addDirectory(Path directory) { } try { Files.walkFileTree( - directory, - new SimpleFileVisitor() { + directory, + new SimpleFileVisitor() { - @Override - public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) - throws IOException { - if (!path.equals(directory)) { - // For consistency with legacy behaviour, include entries for directories except for - // the root. - addEntry(path, /* isDirectory= */ true); - } - return FileVisitResult.CONTINUE; - } + @Override + public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) + throws IOException { + if (!path.equals(directory)) { + // For consistency with legacy behaviour, include entries for directories except for + // the root. + addEntry(path, /* isDirectory= */ true); + } + return FileVisitResult.CONTINUE; + } - @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) - throws IOException { - addEntry(path, /* isDirectory= */ false); - return FileVisitResult.CONTINUE; - } + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) + throws IOException { + addEntry(path, /* isDirectory= */ false); + return FileVisitResult.CONTINUE; + } - void addEntry(Path path, boolean isDirectory) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Path entry : directory.relativize(path)) { - if (!first) { - // use `/` as the directory separator for jar paths, even on Windows - sb.append('/'); - } - sb.append(entry.getFileName()); - first = false; - } - if (isDirectory) { - sb.append('/'); - } - jarEntries.put(sb.toString(), path); + void addEntry(Path path, boolean isDirectory) { + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (Path entry : directory.relativize(path)) { + if (!first) { + // use `/` as the directory separator for jar paths, even on Windows + sb.append('/'); } - }); + sb.append(entry.getFileName()); + first = false; + } + if (isDirectory) { + sb.append('/'); + } + jarEntries.put(sb.toString(), path); + } + }); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -241,8 +241,8 @@ private byte[] manifestContentImpl(Manifest manifest) throws IOException { */ public void execute() throws IOException { try (OutputStream os = Files.newOutputStream(jarPath); - BufferedOutputStream bos = new BufferedOutputStream(os); - JarOutputStream out = new JarOutputStream(bos)) { + BufferedOutputStream bos = new BufferedOutputStream(os); + JarOutputStream out = new JarOutputStream(bos)) { // Create the manifest entry in the Jar file writeManifestEntry(out, manifestContent()); @@ -268,13 +268,12 @@ public static void buildJar(String[] args) throws IOException { String output = args[idx]; JarCreator createJar = new JarCreator(output); createJar.setManifestFile(manifestFile); - for (int i = (idx+1); i < args.length; i++) { + for (int i = (idx + 1); i < args.length; i++) { String thisName = args[i]; Path f = Paths.get(thisName); if (JarHelper.isJar(f)) { createJar.addJar(f); - } - else { + } else { createJar.addDirectory(f); } } @@ -295,4 +294,4 @@ public static void main(String[] args) { long stop = System.currentTimeMillis(); System.err.println((stop - start) + "ms."); } -} \ No newline at end of file +} diff --git a/src/java/io/bazel/rulesscala/jar/JarHelper.java b/src/java/io/bazel/rulesscala/jar/JarHelper.java index abea4cd9e..bc0da857d 100644 --- a/src/java/io/bazel/rulesscala/jar/JarHelper.java +++ b/src/java/io/bazel/rulesscala/jar/JarHelper.java @@ -43,15 +43,15 @@ public class JarHelper { /** Normalize timestamps. */ public static final long DEFAULT_TIMESTAMP = - LocalDateTime.of(2010, 1, 1, 0, 0, 0) - .atZone(ZoneId.systemDefault()) - .toInstant() - .toEpochMilli(); + LocalDateTime.of(2010, 1, 1, 0, 0, 0) + .atZone(ZoneId.systemDefault()) + .toInstant() + .toEpochMilli(); // These attributes are used by JavaBuilder, Turbine, and ijar. // They must all be kept in sync. public static final Attributes.Name TARGET_LABEL = new Attributes.Name("Target-Label"); public static final Attributes.Name INJECTING_RULE_KIND = - new Attributes.Name("Injecting-Rule-Kind"); + new Attributes.Name("Injecting-Rule-Kind"); public static final long DOS_EPOCH_IN_JAVA_TIME = 315561600000L; @@ -206,7 +206,7 @@ protected void copyEntry(JarOutputStream out, String name, Path path) throws IOE long size = isDirectory ? 0 : Files.size(path); JarEntry outEntry = new JarEntry(name); long newtime = - normalize ? normalizedTimestamp(name) : Files.getLastModifiedTime(path).toMillis(); + normalize ? normalizedTimestamp(name) : Files.getLastModifiedTime(path).toMillis(); outEntry.setTime(newtime); outEntry.setSize(size); if (size == 0L) { @@ -235,4 +235,4 @@ protected void copyEntry(JarOutputStream out, String name, Path path) throws IOE } } } -} \ No newline at end of file +} diff --git a/src/java/io/bazel/rulesscala/scala_test/Runner.java b/src/java/io/bazel/rulesscala/scala_test/Runner.java index 6ed2dc6e9..14cfe549f 100644 --- a/src/java/io/bazel/rulesscala/scala_test/Runner.java +++ b/src/java/io/bazel/rulesscala/scala_test/Runner.java @@ -1,41 +1,34 @@ package io.bazel.rulesscala.scala_test; -import java.util.Arrays; -import java.util.List; import java.util.Map; -/** - * This exists only as a proxy for scala tests's runner to provide - * access to env variables - */ +/** This exists only as a proxy for scala tests's runner to provide access to env variables */ public class Runner { - /** - * This is the name of the env var set by bazel when a user provides - * a `--test_filter` test option - */ - private static final String TESTBRIDGE_TEST_ONLY = "TESTBRIDGE_TEST_ONLY"; + /** + * This is the name of the env var set by bazel when a user provides a `--test_filter` test option + */ + private static final String TESTBRIDGE_TEST_ONLY = "TESTBRIDGE_TEST_ONLY"; - public static void main(String[] args) { - org.scalatest.tools.Runner.main(extendArgs(args, System.getenv())); - } - - private static String[] extendArgs(String[] args, Map env) { - return extendFromEnvVar(args, env, TESTBRIDGE_TEST_ONLY, "-s"); - } + public static void main(String[] args) { + org.scalatest.tools.Runner.main(extendArgs(args, System.getenv())); + } - private static String[] extendFromEnvVar(String[] args, Map env, String varName, String flagName) { - String value = env.get(varName); - if (value == null) { - return args; - }; - String[] flag = new String[] { - flagName, - value - }; - String[] result = new String[args.length + flag.length]; - System.arraycopy(args, 0, result, 0, args.length); - System.arraycopy(flag, 0, result, args.length, flag.length); + private static String[] extendArgs(String[] args, Map env) { + return extendFromEnvVar(args, env, TESTBRIDGE_TEST_ONLY, "-s"); + } - return result; + private static String[] extendFromEnvVar( + String[] args, Map env, String varName, String flagName) { + String value = env.get(varName); + if (value == null) { + return args; } + ; + String[] flag = new String[] {flagName, value}; + String[] result = new String[args.length + flag.length]; + System.arraycopy(args, 0, result, 0, args.length); + System.arraycopy(flag, 0, result, args.length, flag.length); + + return result; + } } diff --git a/src/java/io/bazel/rulesscala/scalac/BUILD b/src/java/io/bazel/rulesscala/scalac/BUILD index 417849884..2084c3019 100644 --- a/src/java/io/bazel/rulesscala/scalac/BUILD +++ b/src/java/io/bazel/rulesscala/scalac/BUILD @@ -2,19 +2,19 @@ java_binary( name = "scalac", srcs = [ "CompileOptions.java", + "Resource.java", "ScalaCInvoker.java", "ScalacProcessor.java", - "Resource.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", - '//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', ], ) diff --git a/src/java/io/bazel/rulesscala/scalac/CompileOptions.java b/src/java/io/bazel/rulesscala/scalac/CompileOptions.java index 7da2b96ae..9d3016530 100644 --- a/src/java/io/bazel/rulesscala/scalac/CompileOptions.java +++ b/src/java/io/bazel/rulesscala/scalac/CompileOptions.java @@ -5,28 +5,28 @@ import java.util.Map; public class CompileOptions { - final public String outputName; - final public String manifestPath; - final public String[] scalaOpts; - final public boolean printCompileTime; - final public String[] pluginArgs; - final public String classpath; - final public String[] files; - final public String[] sourceJars; - final public boolean iJarEnabled; - final public String ijarOutput; - final public String ijarCmdPath; - final public String[] javaFiles; - final public Map resourceFiles; - final public String resourceStripPrefix; - final public String[] resourceJars; - final public String[] classpathResourceFiles; - final public String[] directJars; - final public String[] indirectJars; - final public String[] indirectTargets; - final public String dependencyAnalyzerMode; - final public String currentTarget; - final public String statsfile; + public final String outputName; + public final String manifestPath; + public final String[] scalaOpts; + public final boolean printCompileTime; + public final String[] pluginArgs; + public final String classpath; + public final String[] files; + public final String[] sourceJars; + public final boolean iJarEnabled; + public final String ijarOutput; + public final String ijarCmdPath; + public final String[] javaFiles; + public final Map resourceFiles; + public final String resourceStripPrefix; + public final String[] resourceJars; + public final String[] classpathResourceFiles; + public final String[] directJars; + public final String[] indirectJars; + public final String[] indirectTargets; + public final String dependencyAnalyzerMode; + public final String currentTarget; + public final String statsfile; public CompileOptions(List args) { Map argMap = buildArgMap(args); @@ -44,11 +44,12 @@ public CompileOptions(List args) { sourceJars = getCommaList(argMap, "SourceJars"); iJarEnabled = booleanGetOrFalse(argMap, "EnableIjar"); - if(iJarEnabled) { - ijarOutput = getOrError(argMap, "IjarOutput", "Missing required arg ijarOutput when ijar enabled"); - ijarCmdPath = getOrError(argMap, "IjarCmdPath", "Missing required arg ijarCmdPath when ijar enabled"); - } - else { + if (iJarEnabled) { + ijarOutput = + getOrError(argMap, "IjarOutput", "Missing required arg ijarOutput when ijar enabled"); + ijarCmdPath = + getOrError(argMap, "IjarCmdPath", "Missing required arg ijarCmdPath when ijar enabled"); + } else { ijarOutput = null; ijarCmdPath = null; } @@ -73,15 +74,19 @@ private static Map getResources(Map args) { String[] shortPaths = getCommaList(args, "ResourceShortPaths"); if (keys.length != dests.length) - throw new RuntimeException(String.format("mismatch in resources: keys: %s dests: %s", - getOrEmpty(args, "ResourceSrcs"), getOrEmpty(args, "ResourceDests"))); + throw new RuntimeException( + String.format( + "mismatch in resources: keys: %s dests: %s", + getOrEmpty(args, "ResourceSrcs"), getOrEmpty(args, "ResourceDests"))); if (keys.length != shortPaths.length) - throw new RuntimeException(String.format("mismatch in resources: keys: %s shortPaths: %s", - getOrEmpty(args, "ResourceSrcs"), getOrEmpty(args, "ResourceShortPaths"))); + throw new RuntimeException( + String.format( + "mismatch in resources: keys: %s shortPaths: %s", + getOrEmpty(args, "ResourceSrcs"), getOrEmpty(args, "ResourceShortPaths"))); HashMap res = new HashMap(); - for(int idx = 0; idx < keys.length; idx++) { + for (int idx = 0; idx < keys.length; idx++) { Resource resource = new Resource(dests[idx], shortPaths[idx]); res.put(keys[idx], resource); } @@ -90,12 +95,12 @@ private static Map getResources(Map args) { private static HashMap buildArgMap(List lines) { HashMap hm = new HashMap(); - for(String line: lines) { + for (String line : lines) { String[] lSplit = line.split(": "); - if(lSplit.length > 2) { + if (lSplit.length > 2) { throw new RuntimeException("Bad arg, should have at most 1 space/2 spans. arg: " + line); } - if(lSplit.length > 1) { + if (lSplit.length > 1) { hm.put(lSplit[0], lSplit[1]); } } @@ -103,16 +108,15 @@ private static HashMap buildArgMap(List lines) { } private static String[] getCommaList(Map m, String k) { - if(m.containsKey(k)) { + if (m.containsKey(k)) { String v = m.get(k); if ("".equals(v)) { - return new String[]{}; - } - else { + return new String[] {}; + } else { return v.split(","); } } else { - return new String[]{}; + return new String[] {}; } } @@ -121,7 +125,7 @@ private static String getOrEmpty(Map m, String k) { } private static String getOrElse(Map attrs, String key, String defaultValue) { - if(attrs.containsKey(key)) { + if (attrs.containsKey(key)) { return attrs.get(key); } else { return defaultValue; @@ -129,7 +133,7 @@ private static String getOrElse(Map attrs, String key, String de } private static String getOrError(Map m, String k, String errorMessage) { - if(m.containsKey(k)) { + if (m.containsKey(k)) { return m.get(k); } else { throw new RuntimeException(errorMessage); @@ -137,27 +141,28 @@ private static String getOrError(Map m, String k, String errorMe } private static boolean booleanGetOrFalse(Map m, String k) { - if(m.containsKey(k)) { + if (m.containsKey(k)) { String v = m.get(k); - if(v.trim().equals("True") || v.trim().equals("true")) { + if (v.trim().equals("True") || v.trim().equals("true")) { return true; } } return false; } + public static String[] buildPluginArgs(String packedPlugins) { String[] pluginElements = packedPlugins.split(","); int numPlugins = 0; - for(int i =0; i< pluginElements.length; i++){ - if(pluginElements[i].length() > 0) { + for (int i = 0; i < pluginElements.length; i++) { + if (pluginElements[i].length() > 0) { numPlugins += 1; } } String[] result = new String[numPlugins]; int idx = 0; - for(int i =0; i< pluginElements.length; i++){ - if(pluginElements[i].length() > 0) { + for (int i = 0; i < pluginElements.length; i++) { + if (pluginElements[i].length() > 0) { result[idx] = "-Xplugin:" + pluginElements[i]; idx += 1; } diff --git a/src/java/io/bazel/rulesscala/scalac/ScalaCInvoker.java b/src/java/io/bazel/rulesscala/scalac/ScalaCInvoker.java index ad5a95096..ab60f95f0 100644 --- a/src/java/io/bazel/rulesscala/scalac/ScalaCInvoker.java +++ b/src/java/io/bazel/rulesscala/scalac/ScalaCInvoker.java @@ -14,33 +14,32 @@ package io.bazel.rulesscala.scalac; -import java.io.PrintStream; import io.bazel.rulesscala.worker.GenericWorker; +import java.io.PrintStream; import scala.Console$; /** - * This is our entry point to producing a scala target - * this can act as one of Bazel's persistant workers. + * This is our entry point to producing a scala target this can act as one of Bazel's persistant + * workers. */ public class ScalaCInvoker extends GenericWorker { public ScalaCInvoker() { super(new ScalacProcessor()); } - @Override protected void setupOutput(PrintStream ps) { + @Override + protected void setupOutput(PrintStream ps) { System.setOut(ps); System.setErr(ps); Console$.MODULE$.setErrDirect(ps); Console$.MODULE$.setOutDirect(ps); } - public static void main(String[] args) { try { GenericWorker w = new ScalaCInvoker(); w.run(args); - } - catch (Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } diff --git a/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java b/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java index d25423b7f..f27032c8f 100644 --- a/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java +++ b/src/java/io/bazel/rulesscala/scalac/ScalacProcessor.java @@ -3,7 +3,6 @@ import io.bazel.rulesscala.jar.JarCreator; import io.bazel.rulesscala.worker.GenericWorker; import io.bazel.rulesscala.worker.Processor; - import java.io.*; import java.lang.reflect.Field; import java.nio.file.FileSystems; @@ -17,23 +16,20 @@ import java.util.Map.Entry; import java.util.jar.JarEntry; import java.util.jar.JarFile; - import org.apache.commons.io.IOUtils; import scala.tools.nsc.Driver; import scala.tools.nsc.MainClass; import scala.tools.nsc.reporters.ConsoleReporter; class ScalacProcessor implements Processor { - /** - * This is the reporter field for scalac, which we want to access - */ + /** This is the reporter field for scalac, which we want to access */ private static Field reporterField; + static { try { - reporterField = Driver.class.getDeclaredField("reporter"); //NoSuchFieldException + reporterField = Driver.class.getDeclaredField("reporter"); // NoSuchFieldException reporterField.setAccessible(true); - } - catch (NoSuchFieldException ex) { + } catch (NoSuchFieldException ex) { throw new RuntimeException("could not access reporter field on Driver", ex); } } @@ -59,66 +55,52 @@ public void processRequest(List args) throws Exception { } /** - * Compile scala sources if available (if there are none, we will simply - * compile java sources). + * Compile scala sources if available (if there are none, we will simply compile java + * sources). */ if (scalaSources.length > 0) { compileScalaSources(ops, scalaSources, tmpPath); } - /** - * Copy the resources - */ + /** Copy the resources */ copyResources(ops.resourceFiles, ops.resourceStripPrefix, tmpPath); - /** - * Extract and copy resources from resource jars - */ + /** Extract and copy resources from resource jars */ copyResourceJars(ops.resourceJars, tmpPath); - /** - * Copy classpath resources to root of jar - */ + /** Copy classpath resources to root of jar */ copyClasspathResourcesToRoot(ops.classpathResourceFiles, tmpPath); - /** - * Now build the output jar - */ - String[] jarCreatorArgs = { - "-m", - ops.manifestPath, - outputPath.toString(), - tmpPath.toString() - }; + /** Now build the output jar */ + String[] jarCreatorArgs = {"-m", ops.manifestPath, outputPath.toString(), tmpPath.toString()}; JarCreator.main(jarCreatorArgs); - /** - * Now build the output ijar - */ - if(ops.iJarEnabled) { - Process iostat = new ProcessBuilder() - .command(ops.ijarCmdPath, ops.outputName, ops.ijarOutput) - .inheritIO() - .start(); + /** Now build the output ijar */ + if (ops.iJarEnabled) { + Process iostat = + new ProcessBuilder() + .command(ops.ijarCmdPath, ops.outputName, ops.ijarOutput) + .inheritIO() + .start(); int exitCode = iostat.waitFor(); - if(exitCode != 0) { + if (exitCode != 0) { throw new RuntimeException("ijar process failed!"); } } - } - finally { + } finally { removeTmp(tmpPath); } } - private static String[] collectSrcJarSources(String[] files, List scalaJarFiles, List javaJarFiles) { + private static String[] collectSrcJarSources( + String[] files, List scalaJarFiles, List javaJarFiles) { String[] scalaSources = GenericWorker.appendToString(files, scalaJarFiles); return GenericWorker.appendToString(scalaSources, javaJarFiles); } private static List filterFilesByExtension(List files, String extension) { List filtered = new ArrayList(); - for (File f: files) { + for (File f : files) { if (f.toString().endsWith(extension)) { filtered.add(f); } @@ -126,12 +108,14 @@ private static List filterFilesByExtension(List files, String extens return filtered; } - static private String[] sourceExtensions = {".scala", ".java"}; - static private List extractSourceJars(CompileOptions opts, Path tmpParent) throws IOException { + private static String[] sourceExtensions = {".scala", ".java"}; + + private static List extractSourceJars(CompileOptions opts, Path tmpParent) + throws IOException { List sourceFiles = new ArrayList(); - for(String jarPath : opts.sourceJars) { - if (jarPath.length() > 0){ + for (String jarPath : opts.sourceJars) { + if (jarPath.length() > 0) { Path tmpPath = Files.createTempDirectory(tmpParent, "tmp"); sourceFiles.addAll(extractJar(jarPath, tmpPath.toString(), sourceExtensions)); } @@ -140,9 +124,8 @@ static private List extractSourceJars(CompileOptions opts, Path tmpParent) return sourceFiles; } - private static List extractJar(String jarPath, - String outputFolder, - String[] extensions) throws IOException, FileNotFoundException { + private static List extractJar(String jarPath, String outputFolder, String[] extensions) + throws IOException, FileNotFoundException { List outputPaths = new ArrayList(); JarFile jar = new JarFile(jarPath); @@ -173,7 +156,7 @@ private static List extractJar(String jarPath, } private static boolean matchesFileExtensions(String fileName, String[] extensions) { - for (String e: extensions) { + for (String e : extensions) { if (fileName.endsWith(e)) { return true; } @@ -182,9 +165,7 @@ private static boolean matchesFileExtensions(String fileName, String[] extension } private static String[] encodeBazelTargets(String[] targets) { - return Arrays.stream(targets) - .map(ScalacProcessor::encodeBazelTarget) - .toArray(String[]::new); + return Arrays.stream(targets).map(ScalacProcessor::encodeBazelTarget).toArray(String[]::new); } private static String encodeBazelTarget(String target) { @@ -203,11 +184,11 @@ private static String[] getPluginParamsFrom(CompileOptions ops) { String currentTarget = encodeBazelTarget(ops.currentTarget); String[] pluginParamsInUse = { - "-P:dependency-analyzer:direct-jars:" + String.join(":", ops.directJars), - "-P:dependency-analyzer:indirect-jars:" + String.join(":", ops.indirectJars), - "-P:dependency-analyzer:indirect-targets:" + String.join(":", targets), - "-P:dependency-analyzer:mode:" + ops.dependencyAnalyzerMode, - "-P:dependency-analyzer:current-target:" + currentTarget, + "-P:dependency-analyzer:direct-jars:" + String.join(":", ops.directJars), + "-P:dependency-analyzer:indirect-jars:" + String.join(":", ops.indirectJars), + "-P:dependency-analyzer:indirect-targets:" + String.join(":", targets), + "-P:dependency-analyzer:mode:" + ops.dependencyAnalyzerMode, + "-P:dependency-analyzer:current-target:" + currentTarget, }; pluginParams = pluginParamsInUse; } else { @@ -216,23 +197,15 @@ private static String[] getPluginParamsFrom(CompileOptions ops) { return pluginParams; } - private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path tmpPath) throws IllegalAccessException { + private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path tmpPath) + throws IllegalAccessException { String[] pluginParams = getPluginParamsFrom(ops); - String[] constParams = { - "-classpath", - ops.classpath, - "-d", - tmpPath.toString() - }; + String[] constParams = {"-classpath", ops.classpath, "-d", tmpPath.toString()}; - String[] compilerArgs = GenericWorker.merge( - ops.scalaOpts, - ops.pluginArgs, - constParams, - pluginParams, - scalaSources); + String[] compilerArgs = + GenericWorker.merge(ops.scalaOpts, ops.pluginArgs, constParams, pluginParams, scalaSources); MainClass comp = new MainClass(); long start = System.currentTimeMillis(); @@ -251,11 +224,10 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource } try { - Files.write(Paths.get(ops.statsfile), Arrays.asList( - "build_time=" + Long.toString(stop - start))); + Files.write( + Paths.get(ops.statsfile), Arrays.asList("build_time=" + Long.toString(stop - start))); } catch (IOException ex) { - throw new RuntimeException( - "Unable to write statsfile to " + ops.statsfile, ex); + throw new RuntimeException("Unable to write statsfile to " + ops.statsfile, ex); } ConsoleReporter reporter = (ConsoleReporter) reporterField.get(comp); @@ -269,42 +241,44 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource private static void removeTmp(Path tmp) throws IOException { if (tmp != null) { - Files.walkFileTree(tmp, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }); + Files.walkFileTree( + tmp, + new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) + throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) + throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); } } private static void copyResources( - Map resources, - String resourceStripPrefix, - Path dest) throws IOException { - for(Entry e : resources.entrySet()) { + Map resources, String resourceStripPrefix, Path dest) throws IOException { + for (Entry e : resources.entrySet()) { Path source = Paths.get(e.getKey()); Resource resource = e.getValue(); Path shortPath = Paths.get(resource.shortPath); String dstr; // Check if we need to modify resource destination path if (!"".equals(resourceStripPrefix)) { - /** - * NOTE: We are not using the Resource Hash Value as the destination path - * when `resource_strip_prefix` present. The path in the hash value is computed - * by the `_adjust_resources_path` in `scala.bzl`. These are the default paths, - * ie, path that are automatically computed when there is no `resource_strip_prefix` - * present. But when `resource_strip_prefix` is present, we need to strip the prefix - * from the Source Path and use that as the new destination path - * Refer Bazel -> BazelJavaRuleClasses.java#L227 for details - */ + /** + * NOTE: We are not using the Resource Hash Value as the destination path when + * `resource_strip_prefix` present. The path in the hash value is computed by the + * `_adjust_resources_path` in `scala.bzl`. These are the default paths, ie, path that are + * automatically computed when there is no `resource_strip_prefix` present. But when + * `resource_strip_prefix` is present, we need to strip the prefix from the Source Path and + * use that as the new destination path Refer Bazel -> BazelJavaRuleClasses.java#L227 for + * details + */ dstr = getResourcePath(shortPath, resourceStripPrefix); } else { dstr = resource.destination; @@ -328,42 +302,42 @@ private static void copyResources( } } - private static void copyClasspathResourcesToRoot( - String[] classpathResourceFiles, - Path dest - ) throws IOException { - for(String s : classpathResourceFiles) { + private static void copyClasspathResourcesToRoot(String[] classpathResourceFiles, Path dest) + throws IOException { + for (String s : classpathResourceFiles) { Path source = Paths.get(s); Path target = dest.resolve(source.getFileName()); - if(Files.exists(target)) { + if (Files.exists(target)) { System.err.println( - "Classpath resource file " + source.getFileName() - + " has a namespace conflict with another file: " + target.getFileName() - ); + "Classpath resource file " + + source.getFileName() + + " has a namespace conflict with another file: " + + target.getFileName()); } else { Files.copy(source, target); } } } - private static String getResourcePath( - Path source, - String resourceStripPrefix) throws RuntimeException { + private static String getResourcePath(Path source, String resourceStripPrefix) + throws RuntimeException { String sourcePath = source.toString(); // check if the Resource file is under the specified prefix to strip if (!sourcePath.startsWith(resourceStripPrefix)) { // Resource File is not under the specified prefix to strip - throw new RuntimeException("Resource File " - + sourcePath - + " is not under the specified strip prefix " - + resourceStripPrefix); + throw new RuntimeException( + "Resource File " + + sourcePath + + " is not under the specified strip prefix " + + resourceStripPrefix); } String newResPath = sourcePath.substring(resourceStripPrefix.length()); return newResPath; } + private static void copyResourceJars(String[] resourceJars, Path dest) throws IOException { - for (String jarPath: resourceJars) { + for (String jarPath : resourceJars) { extractJar(jarPath, dest.toString(), null); } } diff --git a/src/java/io/bazel/rulesscala/specs2/BUILD b/src/java/io/bazel/rulesscala/specs2/BUILD index 294caf10f..d68cf4a57 100644 --- a/src/java/io/bazel/rulesscala/specs2/BUILD +++ b/src/java/io/bazel/rulesscala/specs2/BUILD @@ -8,10 +8,11 @@ scala_library( "package.scala", ], visibility = ["//visibility:public"], - deps = ["//src/java/io/bazel/rulesscala/test_discovery:test_discovery", - "//external:io_bazel_rules_scala/dependency/junit/junit", - "//external:io_bazel_rules_scala/dependency/specs2/specs2", - "//external:io_bazel_rules_scala/dependency/specs2/specs2_junit", - "//external:io_bazel_rules_scala/dependency/scala/scala_xml", - ] -) \ No newline at end of file + deps = [ + "//external:io_bazel_rules_scala/dependency/junit/junit", + "//external:io_bazel_rules_scala/dependency/scala/scala_xml", + "//external:io_bazel_rules_scala/dependency/specs2/specs2", + "//external:io_bazel_rules_scala/dependency/specs2/specs2_junit", + "//src/java/io/bazel/rulesscala/test_discovery", + ], +) diff --git a/src/java/io/bazel/rulesscala/test_discovery/BUILD b/src/java/io/bazel/rulesscala/test_discovery/BUILD index 87accc658..4b7010c56 100644 --- a/src/java/io/bazel/rulesscala/test_discovery/BUILD +++ b/src/java/io/bazel/rulesscala/test_discovery/BUILD @@ -7,6 +7,5 @@ scala_library( "FilteredRunnerBuilder.scala", ], visibility = ["//visibility:public"], - deps = ["//external:io_bazel_rules_scala/dependency/junit/junit"] - + deps = ["//external:io_bazel_rules_scala/dependency/junit/junit"], ) diff --git a/src/java/io/bazel/rulesscala/worker/BUILD b/src/java/io/bazel/rulesscala/worker/BUILD index 9c16a9f7e..9a6fca96a 100644 --- a/src/java/io/bazel/rulesscala/worker/BUILD +++ b/src/java/io/bazel/rulesscala/worker/BUILD @@ -1,10 +1,11 @@ -java_library(name = "worker", - srcs = [ - "Processor.java", - "GenericWorker.java", - ], - deps = [ - "//src/java/com/google/devtools/build/lib:worker", - ], - visibility = ["//visibility:public"], +java_library( + name = "worker", + srcs = [ + "GenericWorker.java", + "Processor.java", + ], + visibility = ["//visibility:public"], + deps = [ + "//src/java/com/google/devtools/build/lib:worker", + ], ) diff --git a/src/java/io/bazel/rulesscala/worker/GenericWorker.java b/src/java/io/bazel/rulesscala/worker/GenericWorker.java index 9c804dc77..d26bed200 100644 --- a/src/java/io/bazel/rulesscala/worker/GenericWorker.java +++ b/src/java/io/bazel/rulesscala/worker/GenericWorker.java @@ -1,26 +1,19 @@ package io.bazel.rulesscala.worker; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest; import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; -import java.lang.reflect.Field; -import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.Files; -import java.util.ArrayList; +import java.nio.file.Paths; import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; import java.util.List; -import java.util.Map.Entry; -import java.util.Map; -import java.util.TreeMap; -import static java.nio.charset.StandardCharsets.UTF_8; public class GenericWorker { - final protected Processor processor; + protected final Processor processor; public GenericWorker(Processor p) { processor = p; @@ -75,21 +68,22 @@ public static String[] appendToString(String[] init, List rest) { String[] tmp = new String[init.length + rest.size()]; System.arraycopy(init, 0, tmp, 0, init.length); int baseIdx = init.length; - for(T t : rest) { + for (T t : rest) { tmp[baseIdx] = t.toString(); baseIdx += 1; } return tmp; } + public static String[] merge(String[]... arrays) { int totalLength = 0; - for(String[] arr:arrays){ + for (String[] arr : arrays) { totalLength += arr.length; } String[] result = new String[totalLength]; int offset = 0; - for(String[] arr:arrays){ + for (String[] arr : arrays) { System.arraycopy(arr, 0, result, offset, arr.length); offset += arr.length; } @@ -103,24 +97,19 @@ private boolean contains(String[] args, String s) { return false; } - private static List normalize(List args) throws IOException { if (args.size() == 1 && args.get(0).startsWith("@")) { return Files.readAllLines(Paths.get(args.get(0).substring(1)), UTF_8); - } - else { + } else { return args; } } - /** - * This is expected to be called by a main method - */ + /** This is expected to be called by a main method */ public void run(String[] argArray) throws Exception { if (contains(argArray, "--persistent_worker")) { runPersistentWorker(); - } - else { + } else { List args = Arrays.asList(argArray); processor.processRequest(normalize(args)); } diff --git a/src/scala/scripts/BUILD b/src/scala/scripts/BUILD index 820ff0581..7b5e0900e 100644 --- a/src/scala/scripts/BUILD +++ b/src/scala/scripts/BUILD @@ -33,15 +33,15 @@ scala_library( srcs = ["ScalaPBGenerator.scala"], visibility = ["//visibility:public"], deps = [ + ":scala_proto_request_extractor", + "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", "//external:io_bazel_rules_scala/dependency/proto/protoc", - "//external:io_bazel_rules_scala/dependency/proto/scalapb_plugin", "//external:io_bazel_rules_scala/dependency/proto/protoc_bridge", + "//external:io_bazel_rules_scala/dependency/proto/scalapb_plugin", "//external:io_bazel_rules_scala/dependency/proto/scalapbc", - "//external:io_bazel_rules_scala/dependency/com_google_protobuf/protobuf_java", "//src/java/io/bazel/rulesscala/io_utils", "//src/java/io/bazel/rulesscala/jar", "//src/java/io/bazel/rulesscala/worker", - ":scala_proto_request_extractor", ], ) diff --git a/test/BUILD b/test/BUILD index 5b98abd97..4a759faa6 100644 --- a/test/BUILD +++ b/test/BUILD @@ -1,6 +1,7 @@ package(default_testonly = 1) -load("//scala:scala.bzl", +load( + "//scala:scala.bzl", "scala_binary", "scala_library", "scala_test", @@ -9,10 +10,12 @@ load("//scala:scala.bzl", "scala_test_suite", "scala_library_suite", "scala_junit_test", - "scala_specs2_junit_test") - -load("//scala_proto:scala_proto.bzl", - "scalapb_proto_library") + "scala_specs2_junit_test", +) +load( + "//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. @@ -21,16 +24,16 @@ java_binary( name = "JavaBinary", srcs = ["JavaBinary.java"], main_class = "scala.test.JavaBinary", + runtime_deps = [ + ":OtherJavaLib", + "@scala//:scala-library", + ], deps = [ + ":Exported", ":HelloLib", ":OtherLib", - ":Exported", ":Runtime", ], - runtime_deps = [ - ":OtherJavaLib", - "@scala//:scala-library", - ] ) java_binary( @@ -38,9 +41,9 @@ java_binary( srcs = ["JavaBinary.java"], main_class = "scala.test.JavaBinary", deps = [ + ":Exported", ":HelloLib", ":OtherLib", - ":Exported", ":Runtime", ], ) @@ -50,7 +53,10 @@ scala_binary( srcs = ["ScalaBinary.scala"], main_class = "scala.test.ScalaBinary", print_compile_time = True, - deps = [":HelloLib", ":MacroTest"], + deps = [ + ":HelloLib", + ":MacroTest", + ], ) scala_library( @@ -58,16 +64,16 @@ scala_library( srcs = ["HelloLib.scala"], plugins = ["@org_psywerx_hairyfotr__linter//jar"], deps = [ + "Exported", + "MacroTest", "OtherJavaLib", "OtherLib", - "MacroTest", - "Exported" ], ) scala_repl( name = "HelloLibRepl", - deps = [":HelloLib"] + deps = [":HelloLib"], ) scala_test( @@ -83,7 +89,8 @@ scala_test( scala_library( name = "lib_to_test", srcs = ["LibToTest.scala"], - deps = [":HelloLibTest"]) + deps = [":HelloLibTest"], +) scala_test_suite( name = "HelloLibTestSuite", @@ -102,7 +109,8 @@ scala_test( scala_repl( name = "HelloLibTestRepl", - deps = [":HelloLibTest"]) + deps = [":HelloLibTest"], +) scala_library( name = "OtherLib", @@ -113,7 +121,7 @@ scala_library( # Test of library without src scala_library( name = "ExportOnly", - exports = [ "Exported" ], + exports = ["Exported"], ) scala_library( @@ -131,12 +139,12 @@ scala_library_suite( scala_library( name = "ConsumeSuite", srcs = ["SuiteUsage.scala"], - deps = ["SuiteSrcs"] + deps = ["SuiteSrcs"], ) scala_macro_library( - name = "MacroTest", - srcs = ["MacroTest.scala"] + name = "MacroTest", + srcs = ["MacroTest.scala"], ) scala_library( @@ -156,20 +164,20 @@ scala_library( "//test/data:some.txt", "//test/src/main/resources/scala/test:byes", "//test/src/main/resources/scala/test:hellos", - ], + ], ) scala_library( name = "ResourcesStripScalaLib", srcs = ["src/main/scala/scala/test/ResourcesStripScalaLib.scala"], + resource_strip_prefix = "test/", resources = [ - "//test/data:more.txt", "//test/data:foo.txt", - "//test/src/main/resources/scala/test:more-hellos", - "//test/src/main/resources/scala/test:more-byes", + "//test/data:more.txt", "//test/src/main/resources/scala/test:generated-hello", - ], - resource_strip_prefix = "test/", + "//test/src/main/resources/scala/test:more-byes", + "//test/src/main/resources/scala/test:more-hellos", + ], ) scala_binary( @@ -190,32 +198,41 @@ scala_binary( scala_library( name = "lib_to_bin", srcs = ["LibToBin.scala"], - deps = [":ScalaLibBinary"]) + deps = [":ScalaLibBinary"], +) scala_repl( name = "ScalaLibBinaryRepl", - deps = [":ScalaLibBinary"]) + deps = [":ScalaLibBinary"], +) scala_repl( name = "ResourcesStripScalaBinaryRepl", - deps = [":ResourcesStripScalaBinary"]) + deps = [":ResourcesStripScalaBinary"], +) scala_repl( name = "ReplWithSources", - srcs = ["A.scala"]) + srcs = ["A.scala"], +) scala_library( - name = "jar_export", - exports = ["@com_twitter__scalding_date//jar"] + name = "jar_export", + exports = ["@com_twitter__scalding_date//jar"], ) #Mix java scala scala_library( name = "MixJavaScalaLib", - srcs = glob(["src/main/scala/scala/test/mix_java_scala/*.scala"]) + - glob(["src/main/scala/scala/test/mix_java_scala/*.java"]), - jvm_flags = ["-Xms1G", "-Xmx4G"], + srcs = glob(["src/main/scala/scala/test/mix_java_scala/*.scala"]) + glob([ + "src/main/scala/scala/test/mix_java_scala/*.java", + ]), + jvm_flags = [ + "-Xms1G", + "-Xmx4G", + ], ) + #needed to test java sources are compiled scala_binary( name = "MixJavaScalaLibBinary", @@ -228,12 +245,16 @@ scala_binary( scala_library( name = "MixJavaScalaSrcjarLib", srcs = glob([ - "src/main/scala/scala/test/mix_java_scala/*.scala", - # srcjar created with `jar -cfM Baz.srcjar Baz.java` - "src/main/scala/scala/test/mix_java_scala/*.srcjar" + "src/main/scala/scala/test/mix_java_scala/*.scala", + # srcjar created with `jar -cfM Baz.srcjar Baz.java` + "src/main/scala/scala/test/mix_java_scala/*.srcjar", ]), - jvm_flags = ["-Xms1G", "-Xmx4G"], + jvm_flags = [ + "-Xms1G", + "-Xmx4G", + ], ) + #needed to test java sources are compiled scala_binary( name = "MixJavaScalaSrcjarLibBinary", @@ -252,57 +273,70 @@ scala_library( name = "JUnitCompileTimeDep", srcs = ["src/main/scala/scala/test/junit/support/JUnitCompileTimeDep.scala"], ) + scala_library( name = "JUnitRuntimeDep", srcs = ["src/main/scala/scala/test/junit/support/JUnitRuntimeDep.scala"], ) + scala_junit_test( name = "JunitTestWithDeps", + size = "small", srcs = ["src/main/scala/scala/test/junit/JunitTests.scala"], + jvm_flags = ["-XX:HeapDumpPath=/some/custom/path"], suffixes = ["Test"], - size = "small", - deps = [":JUnitCompileTimeDep"], runtime_deps = [":JUnitRuntimeDep"], - jvm_flags = ["-XX:HeapDumpPath=/some/custom/path"], + deps = [":JUnitCompileTimeDep"], ) + scala_junit_test( name = "JunitMultipleSuffixes", - srcs = ["src/main/scala/scala/test/junit/JunitMultipleSuffixes.scala"], size = "small", - suffixes = ["E2E","IT"], - print_discovered_classes = True + srcs = ["src/main/scala/scala/test/junit/JunitMultipleSuffixes.scala"], + print_discovered_classes = True, + suffixes = [ + "E2E", + "IT", + ], ) + scala_junit_test( name = "JunitMultiplePrefixes", - srcs = ["src/main/scala/scala/test/junit/JunitMultiplePrefixes.scala"], size = "small", - prefixes = ["Test","OtherCustomPrefix"], - print_discovered_classes = True + srcs = ["src/main/scala/scala/test/junit/JunitMultiplePrefixes.scala"], + prefixes = [ + "Test", + "OtherCustomPrefix", + ], + print_discovered_classes = True, ) + scala_junit_test( name = "JunitPrefixesAndSuffixes", - srcs = ["src/main/scala/scala/test/junit/JunitMultipleSuffixes.scala", - "src/main/scala/scala/test/junit/JunitMultiplePrefixes.scala"], size = "small", - suffixes = ["E2E"], + srcs = [ + "src/main/scala/scala/test/junit/JunitMultiplePrefixes.scala", + "src/main/scala/scala/test/junit/JunitMultipleSuffixes.scala", + ], prefixes = ["Test"], - print_discovered_classes = True + print_discovered_classes = True, + suffixes = ["E2E"], ) scala_junit_test( name = "JunitJavaTest", + size = "small", srcs = ["src/main/scala/scala/test/junit/JunitJavaTest.java"], suffixes = ["Test"], - size = "small", ) scala_specs2_junit_test( name = "Specs2Tests", - srcs = ["src/main/scala/scala/test/junit/specs2/Specs2Tests.scala"], - deps = [":JUnitCompileTimeDep"], size = "small", + srcs = ["src/main/scala/scala/test/junit/specs2/Specs2Tests.scala"], print_discovered_classes = True, suffixes = ["Test"], + deps = [":JUnitCompileTimeDep"], ) # Make sure scala_binary works in test environment @@ -310,7 +344,7 @@ scala_specs2_junit_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], + data = [binary if (":" in binary) else (":%s" % binary)], ) for binary in [ "JavaBinary", "JavaBinary2", @@ -327,9 +361,9 @@ scala_specs2_junit_test( # Make sure scala_binary works in genrule environment genrule( name = "ScalaBinaryInGenrule", - tools = [":ScalaBinary"], outs = ["scala_binary_out.txt"], cmd = "$(location :ScalaBinary) > $@", + tools = [":ScalaBinary"], ) sh_test( @@ -341,59 +375,59 @@ sh_test( scala_specs2_junit_test( name = "data_location_expansion", - srcs = ["src/main/scala/scala/test/location_expansion/LocationExpansionTest.scala"], size = "small", - suffixes = ["Test"], + srcs = ["src/main/scala/scala/test/location_expansion/LocationExpansionTest.scala"], data = ["//src/java/com/google/devtools/build/lib:worker"], jvm_flags = ["-Dlocation.expanded=$(location //src/java/com/google/devtools/build/lib:worker)"], + suffixes = ["Test"], ) scala_junit_test( name = "JunitFiltersAbstractClassesAndInterfaces", - srcs = ["src/main/scala/scala/test/junit/JunitAbstractClassAndInterface.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitAbstractClassAndInterface.scala"], + print_discovered_classes = True, suffixes = ["Test"], - print_discovered_classes = True ) scala_junit_test( name = "JunitFiltersInnerClasses", - srcs = ["src/main/scala/scala/test/junit/JunitInnerClass.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitInnerClass.scala"], prefixes = ["Test"], - print_discovered_classes = True + print_discovered_classes = True, ) scala_junit_test( name = "JunitFiltersClassesWithoutTests", - srcs = ["src/main/scala/scala/test/junit/JunitNoTests.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitNoTests.scala"], + print_discovered_classes = True, suffixes = ["Test"], - print_discovered_classes = True ) scala_junit_test( name = "JunitIncludesClassesWithTestsFromParent", - srcs = ["src/main/scala/scala/test/junit/JunitIncludesTestHierarchies.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitIncludesTestHierarchies.scala"], + print_discovered_classes = True, suffixes = ["Test"], - print_discovered_classes = True ) scala_junit_test( name = "JunitCustomRunner", - srcs = ["src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitCustomRunnerTest.scala"], suffixes = ["Test"], - deps = [":customJunitRunner"] + deps = [":customJunitRunner"], ) scala_junit_test( name = "JunitIncludesClassesWithRunWith", - srcs = ["src/main/scala/scala/test/junit/JunitIncludesRunWith.scala"], size = "small", + srcs = ["src/main/scala/scala/test/junit/JunitIncludesRunWith.scala"], + print_discovered_classes = True, suffixes = ["Test"], - print_discovered_classes = True ) scala_junit_test( @@ -406,45 +440,61 @@ scala_junit_test( scala_library( name = "filesWithUtf8", - srcs = ["src/main/scala/scala/test/utf8/JavaClassWithUtf8.java", - "src/main/scala/scala/test/utf8/ScalaClassWithUtf8.scala"] + srcs = [ + "src/main/scala/scala/test/utf8/JavaClassWithUtf8.java", + "src/main/scala/scala/test/utf8/ScalaClassWithUtf8.scala", + ], ) scala_library( name = "customJunitRunner", srcs = ["src/main/scala/scala/test/junit/JunitCustomRunner.java"], - deps = ["//external:io_bazel_rules_scala/dependency/junit/junit"] + deps = ["//external:io_bazel_rules_scala/dependency/junit/junit"], ) # make sure making a fat jar strips signatures java_import( name = "fakejar", - jars = ["fake_sig.jar"]) + jars = ["fake_sig.jar"], +) scala_binary( name = "ScalaBinary_with_fake", srcs = ["ScalaBinary.scala"], main_class = "scala.test.ScalaBinary", - deps = [":HelloLib", ":MacroTest", ":fakejar"], + deps = [ + ":HelloLib", + ":MacroTest", + ":fakejar", + ], ) py_binary( name = "jar_lister", - srcs = ["jar_lister.py"] + srcs = ["jar_lister.py"], ) sh_test( - name = "no_sig", - srcs = ["no_sigs.sh"], - args = ["$(location //test:jar_lister)", "$(location //test:ScalaBinary_with_fake_deploy.jar)"], - data = [":ScalaBinary_with_fake_deploy.jar", ":jar_lister"], + name = "no_sig", + srcs = ["no_sigs.sh"], + args = [ + "$(location //test:jar_lister)", + "$(location //test:ScalaBinary_with_fake_deploy.jar)", + ], + data = [ + ":ScalaBinary_with_fake_deploy.jar", + ":jar_lister", + ], ) scala_binary( name = "ScalaBinary_with_service_manifest_srcs", srcs = ["A.scala"], main_class = "scala.test.A", - deps = ["//test/example_jars:example_jar1", "//test/example_jars:example_jar2"] + deps = [ + "//test/example_jars:example_jar1", + "//test/example_jars:example_jar2", + ], ) scala_binary( @@ -457,22 +507,26 @@ scala_binary( scala_library( name = "lib_with_scala_proto_dep", srcs = ["TestServer.scala"], - deps = ["//test/proto:test_proto"] + deps = ["//test/proto:test_proto"], ) scala_binary( name = "test_scala_proto_server", main_class = "test.proto.TestServer", - deps = [":lib_with_scala_proto_dep"] + deps = [":lib_with_scala_proto_dep"], ) scalapb_proto_library( name = "test_proto_scala_dep", - deps = ["//test/proto:test2", ":HelloLib"], visibility = ["//visibility:public"], + deps = [ + ":HelloLib", + "//test/proto:test2", + ], ) load(":check_statsfile.bzl", "check_statsfile") check_statsfile("ScalaBinary") + check_statsfile("ScalaLibBinary") diff --git a/test/aspect/aspect.bzl b/test/aspect/aspect.bzl index 195ad94f7..c37a53601 100644 --- a/test/aspect/aspect.bzl +++ b/test/aspect/aspect.bzl @@ -6,13 +6,13 @@ sure the targets we expect are there. attr_aspects = ["_scala_toolchain", "deps"] def _aspect_impl(target, ctx): - visited = [str(target.label)] - for attr_name in attr_aspects: - if hasattr(ctx.rule.attr, attr_name): - for dep in getattr(ctx.rule.attr, attr_name): - if hasattr(dep, "visited"): - visited += dep.visited - return struct(visited = visited) + visited = [str(target.label)] + for attr_name in attr_aspects: + if hasattr(ctx.rule.attr, attr_name): + for dep in getattr(ctx.rule.attr, attr_name): + if hasattr(dep, "visited"): + visited += dep.visited + return struct(visited = visited) test_aspect = aspect( attr_aspects = attr_aspects, @@ -20,63 +20,63 @@ test_aspect = aspect( ) def _rule_impl(ctx): - expected_deps = { - "scala_library" : [ - "//test/aspect:scala_library", - "@scala//:scala-library", - ], - "scala_test" : [ - "//test/aspect:scala_test", - "@scala//:scala-library", - "@scalatest//jar:jar", - ], - "scala_junit_test" : [ - "//test/aspect:scala_junit_test", - "@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_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", - # From specs2/specs2_junit.bzl:specs2_junit_dependencies() - "@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar:jar", - ], - } - content = "" - for target in ctx.attr.targets: - visited = sorted(target.visited) - expected = sorted(expected_deps[target.label.name]) - if visited != expected: - content += """ + expected_deps = { + "scala_library": [ + "//test/aspect:scala_library", + "@scala//:scala-library", + ], + "scala_test": [ + "//test/aspect:scala_test", + "@scala//:scala-library", + "@scalatest//jar:jar", + ], + "scala_junit_test": [ + "//test/aspect:scala_junit_test", + "@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_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", + # From specs2/specs2_junit.bzl:specs2_junit_dependencies() + "@io_bazel_rules_scala_org_specs2_specs2_junit_2_11//jar:jar", + ], + } + content = "" + for target in ctx.attr.targets: + visited = sorted(target.visited) + expected = sorted(expected_deps[target.label.name]) + if visited != expected: + content += """ echo Expected these deps from {name}: 1>&2 echo {expected}, 1>&2 echo but got these instead: 1>&2 echo {visited} 1>&2 false # test returns 1 (and fails) if this is the final line - """.format(name=target.label.name, - expected=', '.join(expected), - visited=', '.join(visited)) - ctx.actions.write( - output = ctx.outputs.executable, - content = content, - ) - return struct() + """.format( + name = target.label.name, + expected = ', '.join(expected), + visited = ', '.join(visited)) + ctx.actions.write( + output = ctx.outputs.executable, + content = content, + ) + return struct() aspect_test = rule( implementation = _rule_impl, attrs = { # The targets whose dependencies we want to verify. - "targets" : attr.label_list(aspects = [test_aspect]), + "targets": attr.label_list(aspects = [test_aspect]), }, test = True, ) - diff --git a/test/check_statsfile.bzl b/test/check_statsfile.bzl index 714944fe2..6e9a28379 100644 --- a/test/check_statsfile.bzl +++ b/test/check_statsfile.bzl @@ -1,24 +1,22 @@ -def check_statsfile( - target -): - statsfile = ":%s.statsfile" % target - outfile = "%s.statsfile.good" % target +def check_statsfile(target): + statsfile = ":%s.statsfile" % target + outfile = "%s.statsfile.good" % target - cmd = """ + cmd = """ TIME_MS=`awk -F '=' '$$1 == "build_time" {{ print $$2 }}' {statsfile}` if [ ! -z "$$TIME_MS" ]; then touch '{outfile}' fi """ - cmd = cmd.format( - statsfile = "$(location %s)" % statsfile, - outfile = "$(location %s)" % outfile, - ) + cmd = cmd.format( + statsfile = "$(location %s)" % statsfile, + outfile = "$(location %s)" % outfile, + ) - native.genrule( - name = "%s_statsfile" % target, - outs = [outfile], - tools = [statsfile], - cmd = cmd, - visibility = ["//visibility:public"], - ) + native.genrule( + name = "%s_statsfile" % target, + outs = [outfile], + tools = [statsfile], + cmd = cmd, + visibility = ["//visibility:public"], + ) diff --git a/test/data/BUILD b/test/data/BUILD index ccf7043c7..f217a0938 100644 --- a/test/data/BUILD +++ b/test/data/BUILD @@ -1 +1,5 @@ -exports_files(["some.txt", "more.txt", "foo.txt"]) +exports_files([ + "some.txt", + "more.txt", + "foo.txt", +]) diff --git a/test/gen_src/BUILD b/test/gen_src/BUILD index ed0946e3a..72d25ea27 100644 --- a/test/gen_src/BUILD +++ b/test/gen_src/BUILD @@ -1,11 +1,14 @@ -load("//scala:scala.bzl", +load( + "//scala:scala.bzl", "scala_binary", - "scala_library") + "scala_library", +) scala_binary( name = "src_generator", srcs = ["SrcGenerator.scala"], - main_class = "build.bazel.rulesscala.test.srcgen.SrcGenerator") + main_class = "build.bazel.rulesscala.test.srcgen.SrcGenerator", +) genrule( name = "foo", @@ -18,4 +21,5 @@ genrule( scala_binary( name = "uses_gen_file", srcs = ["foo.scala"], - main_class = "Foo") + main_class = "Foo", +) diff --git a/test/jar_lister.py b/test/jar_lister.py index 3c3992bcc..676eb843d 100644 --- a/test/jar_lister.py +++ b/test/jar_lister.py @@ -2,4 +2,4 @@ import sys for n in zipfile.ZipFile(sys.argv[1]).namelist(): - print n + print n diff --git a/test/jmh/BUILD b/test/jmh/BUILD index 1c402f9c2..b8c1d290d 100644 --- a/test/jmh/BUILD +++ b/test/jmh/BUILD @@ -15,9 +15,15 @@ scala_library( scala_library( name = "add_numbers", srcs = ["AddNumbers.scala"], - deps = [":scala_type", ":java_type"], - exports = [":scala_type", ":java_type"], visibility = ["//visibility:public"], + exports = [ + ":java_type", + ":scala_type", + ], + deps = [ + ":java_type", + ":scala_type", + ], ) scala_benchmark_jmh( diff --git a/test/jmh/JavaType.java b/test/jmh/JavaType.java index 1f6582947..81012b07c 100644 --- a/test/jmh/JavaType.java +++ b/test/jmh/JavaType.java @@ -1,5 +1,5 @@ package foo; public class JavaType { - public int i = 0; -} \ No newline at end of file + public int i = 0; +} diff --git a/test/proto/BUILD b/test/proto/BUILD index c21da8c61..2704683e0 100644 --- a/test/proto/BUILD +++ b/test/proto/BUILD @@ -1,49 +1,62 @@ -load("//scala_proto:scala_proto.bzl", - "scalapb_proto_library") +load( + "//scala_proto:scala_proto.bzl", + "scalapb_proto_library", +) proto_library( name = "test2", - deps = ["//test/proto2:test"], srcs = ["test2.proto"], visibility = ["//visibility:public"], + deps = ["//test/proto2:test"], ) proto_library( name = "test3", - deps = ["//test/proto2:test"], srcs = ["test3.proto"], visibility = ["//visibility:public"], + deps = ["//test/proto2:test"], ) proto_library( name = "test_service", - deps = [":test2", ":test3", "//test/proto2:test"], srcs = ["test_service.proto"], visibility = ["//visibility:public"], + deps = [ + ":test2", + ":test3", + "//test/proto2:test", + ], ) scalapb_proto_library( name = "test_proto_nogrpc", - deps = [":test2"], visibility = ["//visibility:public"], + deps = [":test2"], ) java_proto_library( name = "test_proto_java_lib", - deps = [":test2", "//test/proto2:test"], + deps = [ + ":test2", + "//test/proto2:test", + ], ) scalapb_proto_library( name = "test_proto_java_conversions", - deps = [":test2", "//test/proto2:test", ":test_proto_java_lib"], - with_java = True, - with_flat_package = True, visibility = ["//visibility:public"], + with_flat_package = True, + with_java = True, + deps = [ + ":test2", + ":test_proto_java_lib", + "//test/proto2:test", + ], ) scalapb_proto_library( name = "test_proto", + visibility = ["//visibility:public"], with_grpc = True, deps = [":test_service"], - visibility = ["//visibility:public"], ) diff --git a/test/src/main/resources/scala/test/BUILD b/test/src/main/resources/scala/test/BUILD index df2e639f9..c50f6654b 100644 --- a/test/src/main/resources/scala/test/BUILD +++ b/test/src/main/resources/scala/test/BUILD @@ -1,4 +1,10 @@ -exports_files(["byes", "hellos", "hellos-and-byes.jar", "more-byes", "more-hellos"]) +exports_files([ + "byes", + "hellos", + "hellos-and-byes.jar", + "more-byes", + "more-hellos", +]) genrule( name = "generated-hello", diff --git a/test/src/main/resources/scala/test/classpath_resource1/BUILD b/test/src/main/resources/scala/test/classpath_resource1/BUILD index 41dc03701..01bb3389c 100644 --- a/test/src/main/resources/scala/test/classpath_resource1/BUILD +++ b/test/src/main/resources/scala/test/classpath_resource1/BUILD @@ -1 +1 @@ -exports_files(["classpath-resource"]) \ No newline at end of file +exports_files(["classpath-resource"]) diff --git a/test/src/main/resources/scala/test/classpath_resource2/BUILD b/test/src/main/resources/scala/test/classpath_resource2/BUILD index 41dc03701..01bb3389c 100644 --- a/test/src/main/resources/scala/test/classpath_resource2/BUILD +++ b/test/src/main/resources/scala/test/classpath_resource2/BUILD @@ -1 +1 @@ -exports_files(["classpath-resource"]) \ No newline at end of file +exports_files(["classpath-resource"]) diff --git a/test/src/main/scala/scala/test/classpath_resources/BUILD b/test/src/main/scala/scala/test/classpath_resources/BUILD index 6e666bc51..2d1ec6d08 100644 --- a/test/src/main/scala/scala/test/classpath_resources/BUILD +++ b/test/src/main/scala/scala/test/classpath_resources/BUILD @@ -3,22 +3,22 @@ load("//scala:scala.bzl", "scala_binary") scala_binary( name = "classpath_resource", srcs = ["ObjectWithClasspathResources.scala"], - main_class = "scala.test.classpathresources.ObjectWithClasspathResources", - visibility = ["//visibility:public"], classpath_resources = [ "//test/src/main/resources/scala/test:byes", "//test/src/main/resources/scala/test:hellos", "//test/src/main/resources/scala/test:more-byes", - "//test/src/main/resources/scala/test:more-hellos" + "//test/src/main/resources/scala/test:more-hellos", ], + main_class = "scala.test.classpathresources.ObjectWithClasspathResources", + visibility = ["//visibility:public"], ) scala_binary( name = "classpath_resource_duplicates", srcs = ["ObjectWithDuplicateClasspathResources.scala"], - main_class = "scala.test.classpathresources.ObjectWithDuplicateClasspathResources", classpath_resources = [ "//test/src/main/resources/scala/test/classpath_resource1:classpath-resource", "//test/src/main/resources/scala/test/classpath_resource2:classpath-resource", ], -) \ No newline at end of file + main_class = "scala.test.classpathresources.ObjectWithDuplicateClasspathResources", +) diff --git a/test/src/main/scala/scala/test/ijar/BUILD b/test/src/main/scala/scala/test/ijar/BUILD index 726896b63..2b12aab5f 100644 --- a/test/src/main/scala/scala/test/ijar/BUILD +++ b/test/src/main/scala/scala/test/ijar/BUILD @@ -1,17 +1,19 @@ package(default_visibility = ["//visibility:public"]) + load("//scala:scala.bzl", "scala_library", "scala_test", "scala_binary") scala_library( - name="user", - srcs=[ + name = "user", + srcs = [ "A.scala", - ], + ], deps = ["dependency"], ) scala_library( - name="dependency", - srcs=[ - "B.scala", "C.java" - ], -) \ No newline at end of file + name = "dependency", + srcs = [ + "B.scala", + "C.java", + ], +) diff --git a/test/src/main/scala/scala/test/ijar/C.java b/test/src/main/scala/scala/test/ijar/C.java index db48ec799..02895dcb8 100644 --- a/test/src/main/scala/scala/test/ijar/C.java +++ b/test/src/main/scala/scala/test/ijar/C.java @@ -1,11 +1,11 @@ package scala.test.ijar; class C { - public static void foo() { - System.out.println("orig"); - } + public static void foo() { + System.out.println("orig"); + } - public C() { - B$.MODULE$.bar(); - } + public C() { + B$.MODULE$.bar(); + } } diff --git a/test/src/main/scala/scala/test/junit/JunitCustomRunner.java b/test/src/main/scala/scala/test/junit/JunitCustomRunner.java index 78bd23cdb..34dc491d8 100644 --- a/test/src/main/scala/scala/test/junit/JunitCustomRunner.java +++ b/test/src/main/scala/scala/test/junit/JunitCustomRunner.java @@ -1,23 +1,22 @@ package scala.test.junit; +import java.util.List; import org.junit.rules.TestRule; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.InitializationError; -import java.util.List; - public class JunitCustomRunner extends BlockJUnit4ClassRunner { - public JunitCustomRunner(Class aClass) throws InitializationError { - super(aClass); - } + public JunitCustomRunner(Class aClass) throws InitializationError { + super(aClass); + } - public static final String EXPECTED_MESSAGE = "Hello from getTestRules!"; - public static String message; + public static final String EXPECTED_MESSAGE = "Hello from getTestRules!"; + public static String message; - @Override - protected List getTestRules(Object target) { - message = EXPECTED_MESSAGE; - return super.getTestRules(target); - } + @Override + protected List getTestRules(Object target) { + message = EXPECTED_MESSAGE; + return super.getTestRules(target); + } } diff --git a/test/src/main/scala/scala/test/junit/JunitJavaTest.java b/test/src/main/scala/scala/test/junit/JunitJavaTest.java index 95e59dfd9..d6c18a6ac 100644 --- a/test/src/main/scala/scala/test/junit/JunitJavaTest.java +++ b/test/src/main/scala/scala/test/junit/JunitJavaTest.java @@ -3,7 +3,6 @@ import org.junit.Test; public class JunitJavaTest { - @Test - public void someTest() { - } + @Test + public void someTest() {} } diff --git a/test/src/main/scala/scala/test/large_classpath/BUILD b/test/src/main/scala/scala/test/large_classpath/BUILD index dd230fd5f..a43509cce 100644 --- a/test/src/main/scala/scala/test/large_classpath/BUILD +++ b/test/src/main/scala/scala/test/large_classpath/BUILD @@ -2,10 +2,16 @@ load("//scala:scala.bzl", "scala_binary") load(":helper.bzl", "create_dependencies", "get_dependency_labels") scala_binary( - main_class = "scala.test.large_classpath.ObjectWithLargeClasspath", name = "largeClasspath", srcs = ["ObjectWithLargeClasspath.scala"], - deps = get_dependency_labels(amount = 250, length = 20), + main_class = "scala.test.large_classpath.ObjectWithLargeClasspath", + deps = get_dependency_labels( + amount = 250, + length = 20, + ), ) -create_dependencies(amount = 250, length = 20) +create_dependencies( + amount = 250, + length = 20, +) diff --git a/test/src/main/scala/scala/test/large_classpath/helper.bzl b/test/src/main/scala/scala/test/large_classpath/helper.bzl index fd1d12a1e..05cc6d3e2 100644 --- a/test/src/main/scala/scala/test/large_classpath/helper.bzl +++ b/test/src/main/scala/scala/test/large_classpath/helper.bzl @@ -1,8 +1,8 @@ load("//scala:scala.bzl", "scala_library") def create_dependencies(amount, length): - for i in range(amount): - scala_library(name = "dependency_" * length + str(i)) + for i in range(amount): + scala_library(name = "dependency_" * length + str(i)) def get_dependency_labels(amount, length): - return [":" + "dependency_" * length + str(i) for i in range(amount)] + return [":" + "dependency_" * length + str(i) for i in range(amount)] diff --git a/test/src/main/scala/scala/test/mix_java_scala/Baz.java b/test/src/main/scala/scala/test/mix_java_scala/Baz.java index 34fb7d6b3..72797a4a4 100644 --- a/test/src/main/scala/scala/test/mix_java_scala/Baz.java +++ b/test/src/main/scala/scala/test/mix_java_scala/Baz.java @@ -1,4 +1,3 @@ package scala.test; -public class Baz extends Foo { -} \ No newline at end of file +public class Baz extends Foo {} diff --git a/test/src/main/scala/scala/test/mix_java_scala/FooBar.java b/test/src/main/scala/scala/test/mix_java_scala/FooBar.java index 7dc0f96de..6805942a5 100644 --- a/test/src/main/scala/scala/test/mix_java_scala/FooBar.java +++ b/test/src/main/scala/scala/test/mix_java_scala/FooBar.java @@ -1,4 +1,3 @@ package scala.test; -public class FooBar extends Foo { -} +public class FooBar extends Foo {} diff --git a/test/src/main/scala/scala/test/only_java/Alpha.java b/test/src/main/scala/scala/test/only_java/Alpha.java index 944a6a7d8..b6292878a 100644 --- a/test/src/main/scala/scala/test/only_java/Alpha.java +++ b/test/src/main/scala/scala/test/only_java/Alpha.java @@ -1,6 +1,7 @@ package scala.test; + public class Alpha { - public static void main(String[] args) { - return; //we just want this to be compiled and run - } -} \ No newline at end of file + public static void main(String[] args) { + return; // we just want this to be compiled and run + } +} diff --git a/test/src/main/scala/scala/test/resources/BUILD b/test/src/main/scala/scala/test/resources/BUILD index ece508f55..6200a35cd 100644 --- a/test/src/main/scala/scala/test/resources/BUILD +++ b/test/src/main/scala/scala/test/resources/BUILD @@ -1,48 +1,47 @@ - -load("//scala:scala.bzl", "scala_library", "scala_specs2_junit_test", "scala_test",) +load("//scala:scala.bzl", "scala_library", "scala_specs2_junit_test", "scala_test") scala_library( - name = "noSrcsWithDirectFileResources", - resources = ["resource.txt"] + name = "noSrcsWithDirectFileResources", + resources = ["resource.txt"], ) scala_library( - name = "noSrcsWithFilegroupResources", - resources = [":resource-fg"] + name = "noSrcsWithFilegroupResources", + resources = [":resource-fg"], ) filegroup( - name="resource-fg", - srcs=glob(["**/*.txt"]) + name = "resource-fg", + srcs = glob(["**/*.txt"]), ) scala_specs2_junit_test( name = "TestScalaLibOnlyResources", - srcs = ["ScalaLibOnlyResourcesTest.scala"], - deps = [":noSrcsWithDirectFileResources"], size = "small", + srcs = ["ScalaLibOnlyResourcesTest.scala"], suffixes = ["Test"], + deps = [":noSrcsWithDirectFileResources"], ) scala_specs2_junit_test( name = "TestScalaLibOnlyFilegroupResources", - srcs = ["ScalaLibOnlyResourcesFilegroupTest.scala"], - deps = [":noSrcsWithFilegroupResources"], size = "small", + srcs = ["ScalaLibOnlyResourcesFilegroupTest.scala"], suffixes = ["Test"], + deps = [":noSrcsWithFilegroupResources"], ) scala_specs2_junit_test( name = "TestScalaLibResourcesFromExternalDep", + size = "small", srcs = ["ScalaLibResourcesFromExternalDepTest.scala"], resources = ["@test_new_local_repo//:data"], - size = "small", suffixes = ["Test"], ) scala_test( name = "TestScalaLibResourcesFromExternalScalaTest", + size = "small", srcs = ["ScalaLibResourcesFromExternalScalaTest.scala"], resources = ["@test_new_local_repo//:data"], - size = "small", ) diff --git a/test/src/main/scala/scala/test/resources/strip/BUILD b/test/src/main/scala/scala/test/resources/strip/BUILD index 88ba4c3bd..e8d114f6d 100644 --- a/test/src/main/scala/scala/test/resources/strip/BUILD +++ b/test/src/main/scala/scala/test/resources/strip/BUILD @@ -1,15 +1,15 @@ -load("//scala:scala.bzl", "scala_library","scala_specs2_junit_test") +load("//scala:scala.bzl", "scala_library", "scala_specs2_junit_test") scala_library( - name = "noSrcsWithResources", - resource_strip_prefix="test/src/main/scala/scala/test/resources/strip", - resources = ["nosrc_jar_resource.txt"] + name = "noSrcsWithResources", + resource_strip_prefix = "test/src/main/scala/scala/test/resources/strip", + resources = ["nosrc_jar_resource.txt"], ) scala_specs2_junit_test( name = "resouceStripPrefixTest", - srcs = ["ResourceStripPrefixTest.scala"], - deps = [":noSrcsWithResources"], size = "small", + srcs = ["ResourceStripPrefixTest.scala"], suffixes = ["Test"], + deps = [":noSrcsWithResources"], ) diff --git a/test/src/main/scala/scala/test/scala_import/BUILD b/test/src/main/scala/scala/test/scala_import/BUILD index 510d77627..ddfbb162f 100644 --- a/test/src/main/scala/scala/test/scala_import/BUILD +++ b/test/src/main/scala/scala/test/scala_import/BUILD @@ -1,103 +1,111 @@ -load("//scala:scala.bzl", "scala_library","scala_specs2_junit_test") +load("//scala:scala.bzl", "scala_library", "scala_specs2_junit_test") load("//scala:scala_import.bzl", "scala_import") #Many jars scala_import( - name = "guava_and_commons_lang", - jars = ["@com_google_guava_guava_21_0_with_file//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], + name = "guava_and_commons_lang", + jars = [ + "@com_google_guava_guava_21_0_with_file//jar:file", + "@org_apache_commons_commons_lang_3_5//jar:file", + ], ) # Jars as files scala_import( name = "relate", jars = [ - "relate_2.11-2.1.1.jar", + "relate_2.11-2.1.1.jar", ], ) scala_specs2_junit_test( name = "scala_import_exposes_jars", - srcs = ["ScalaImportExposesJarsTest.scala"], - deps = [":guava_and_commons_lang"], size = "small", + srcs = ["ScalaImportExposesJarsTest.scala"], suffixes = ["Test"], + deps = [":guava_and_commons_lang"], ) scala_specs2_junit_test( name = "scala_import_exposes_file_jars", - srcs = ["ScalaImportExposesFileJarsTest.scala"], - deps = [":relate"], size = "small", + srcs = ["ScalaImportExposesFileJarsTest.scala"], suffixes = ["Test"], + deps = [":relate"], ) #filter source jars scala_import( - name = "cats", - jars = ["@org_typelevel__cats_core//jar:file"], + name = "cats", + jars = ["@org_typelevel__cats_core//jar:file"], ) scala_library( - name = "source_jar_not_oncp", - srcs = ["ReferCatsImplicits.scala"], - deps = [":cats"] + name = "source_jar_not_oncp", + srcs = ["ReferCatsImplicits.scala"], + deps = [":cats"], ) ##Runtime deps scala_import( - name = "indirection_for_transitive_runtime_deps", - jars = [], - runtime_deps = [":cats"] + name = "indirection_for_transitive_runtime_deps", + jars = [], + runtime_deps = [":cats"], ) scala_import( - name = "cats_and_guava_and_commons_lang_as_runtime_deps", - jars = [], - runtime_deps = [":guava_and_commons_lang", ":indirection_for_transitive_runtime_deps"] + name = "cats_and_guava_and_commons_lang_as_runtime_deps", + jars = [], + runtime_deps = [ + ":guava_and_commons_lang", + ":indirection_for_transitive_runtime_deps", + ], ) - scala_specs2_junit_test( name = "scala_import_propagates_runtime_deps", - srcs = ["ScalaImportPropagatesRuntimeDepsTest.scala"], - runtime_deps = [":cats_and_guava_and_commons_lang_as_runtime_deps"], size = "small", + srcs = ["ScalaImportPropagatesRuntimeDepsTest.scala"], suffixes = ["Test"], + runtime_deps = [":cats_and_guava_and_commons_lang_as_runtime_deps"], ) java_import( - name = "guava_and_commons_lang_java_import", - jars = ["@com_google_guava_guava_21_0_with_file//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], + name = "guava_and_commons_lang_java_import", + jars = [ + "@com_google_guava_guava_21_0_with_file//jar:file", + "@org_apache_commons_commons_lang_3_5//jar:file", + ], ) #Exports scala_import( - name = "guava_and_commons_lang_as_exports", - exports = [":guava_and_commons_lang"], + name = "guava_and_commons_lang_as_exports", + exports = [":guava_and_commons_lang"], ) # we're testing the scenario: # jar <- java_import <- scala_import (exports) <- scala_specs2_junit_test # see for details https://github.com/bazelbuild/rules_scala/issues/354 scala_import( - name = "guava_and_commons_lang_as_exports_from_java_import", - exports = [":guava_and_commons_lang_java_import"], + name = "guava_and_commons_lang_as_exports_from_java_import", + exports = [":guava_and_commons_lang_java_import"], ) scala_specs2_junit_test( name = "scala_import_exports_targets", - srcs = ["ScalaImportExposesJarsTest.scala"], - deps = [":guava_and_commons_lang_as_exports"], size = "small", + srcs = ["ScalaImportExposesJarsTest.scala"], suffixes = ["Test"], + deps = [":guava_and_commons_lang_as_exports"], ) # same as above but deps are routed via java_import instead of # scala_import scala_specs2_junit_test( name = "scala_import_exports_java_import_targets", - srcs = ["ScalaImportExposesJarsTest.scala"], - deps = [":guava_and_commons_lang_as_exports"], size = "small", + srcs = ["ScalaImportExposesJarsTest.scala"], suffixes = ["Test"], + deps = [":guava_and_commons_lang_as_exports"], ) diff --git a/test/src/main/scala/scala/test/sources_jars_in_deps/BUILD b/test/src/main/scala/scala/test/sources_jars_in_deps/BUILD index 11a9cf8c3..29f73c471 100644 --- a/test/src/main/scala/scala/test/sources_jars_in_deps/BUILD +++ b/test/src/main/scala/scala/test/sources_jars_in_deps/BUILD @@ -1,9 +1,9 @@ load("//scala:scala.bzl", "scala_library") scala_library( - name = "source_jar_not_oncp", - srcs = ["ReferCatsImplicits.scala"], - deps = [ - "@org_typelevel__cats_core//jar:file", - ] + name = "source_jar_not_oncp", + srcs = ["ReferCatsImplicits.scala"], + deps = [ + "@org_typelevel__cats_core//jar:file", + ], ) diff --git a/test/src/main/scala/scala/test/srcjars/BUILD b/test/src/main/scala/scala/test/srcjars/BUILD index 9d9129d51..378ffb51a 100644 --- a/test/src/main/scala/scala/test/srcjars/BUILD +++ b/test/src/main/scala/scala/test/srcjars/BUILD @@ -5,15 +5,15 @@ load("//scala:scala.bzl", "scala_library") # and use_source_jar should depend on that internally scala_library( - name = "source_jar", - # SourceJar1.jar was created by: - # jar -cfM test/src/main/scala/scala/test/srcjars/SourceJar1.srcjar \ - # test/src/main/scala/scala/test/srcjars/SourceJar1.scala - srcs = ["SourceJar1.srcjar"], + name = "source_jar", + # SourceJar1.jar was created by: + # jar -cfM test/src/main/scala/scala/test/srcjars/SourceJar1.srcjar \ + # test/src/main/scala/scala/test/srcjars/SourceJar1.scala + srcs = ["SourceJar1.srcjar"], ) scala_library( - name = "use_source_jar", - srcs = ["SourceJar2.scala"], - deps = [":source_jar"], -) \ No newline at end of file + name = "use_source_jar", + srcs = ["SourceJar2.scala"], + deps = [":source_jar"], +) diff --git a/test/src/main/scala/scala/test/srcjars_with_java/BUILD b/test/src/main/scala/scala/test/srcjars_with_java/BUILD index 126438e39..e1a38f695 100644 --- a/test/src/main/scala/scala/test/srcjars_with_java/BUILD +++ b/test/src/main/scala/scala/test/srcjars_with_java/BUILD @@ -24,4 +24,4 @@ scala_library( name = "java_dependent", srcs = ["JavaDependent.scala"], deps = [":java_source_jar"], -) \ No newline at end of file +) diff --git a/test/src/main/scala/scala/test/srcjars_with_java/JavaSource.java b/test/src/main/scala/scala/test/srcjars_with_java/JavaSource.java index 0bb090cff..187cc4018 100644 --- a/test/src/main/scala/scala/test/srcjars_with_java/JavaSource.java +++ b/test/src/main/scala/scala/test/srcjars_with_java/JavaSource.java @@ -1,5 +1,5 @@ package fish; public class JavaSource { - public static final String line = "one fish, two fish"; -} \ No newline at end of file + public static final String line = "one fish, two fish"; +} diff --git a/test/src/main/scala/scala/test/strict_deps/no_recompilation/BUILD b/test/src/main/scala/scala/test/strict_deps/no_recompilation/BUILD index d709ea65a..b997b9ccf 100644 --- a/test/src/main/scala/scala/test/strict_deps/no_recompilation/BUILD +++ b/test/src/main/scala/scala/test/strict_deps/no_recompilation/BUILD @@ -1,25 +1,26 @@ package(default_visibility = ["//visibility:public"]) + load("//scala:scala.bzl", "scala_library", "scala_test", "scala_binary") scala_library( - name="transitive_dependency_user", - srcs=[ + name = "transitive_dependency_user", + srcs = [ "A.scala", - ], - deps = ["direct_dependency"], + ], + deps = ["direct_dependency"], ) scala_library( - name="direct_dependency", - srcs=[ + name = "direct_dependency", + srcs = [ "B.scala", - ], + ], deps = ["transitive_dependency"], ) scala_library( - name="transitive_dependency", - srcs=[ + name = "transitive_dependency", + srcs = [ "C.scala", - ], -) \ No newline at end of file + ], +) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/BUILD index e369ab722..7d7a96743 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/BUILD @@ -2,179 +2,180 @@ load("//scala:scala.bzl", "scala_binary", "scala_library") load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") scrooge_scala_library( - name = "scrooge1", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift", - ":scrooge2_a", - ":scrooge2_b", - ":scrooge3", - ], - visibility = ["//visibility:public"], + name = "scrooge1", + visibility = ["//visibility:public"], + deps = [ + ":scrooge2_a", + ":scrooge2_b", + ":scrooge3", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift", + ], ) scrooge_scala_library( - name = "scrooge2_a", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", - ":scrooge3", - ], - visibility = ["//visibility:public"], + name = "scrooge2_a", + visibility = ["//visibility:public"], + deps = [ + ":scrooge3", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", + ], ) scrooge_scala_library( - name = "scrooge2_b", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", - ":scrooge3", - ], - visibility = ["//visibility:public"], + name = "scrooge2_b", + visibility = ["//visibility:public"], + deps = [ + ":scrooge3", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], ) scrooge_scala_library( - name = "scrooge3", - deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], - visibility = ["//visibility:public"], + name = "scrooge3", + visibility = ["//visibility:public"], + deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], ) scrooge_scala_library( - name = "scrooge2", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", - ":scrooge3", - ], - visibility = ["//visibility:public"], + name = "scrooge2", + visibility = ["//visibility:public"], + deps = [ + ":scrooge3", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], ) scrooge_scala_library( - name = "scrooge4", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4:thrift4", - ":scrooge2" + name = "scrooge4", + visibility = ["//visibility:public"], + deps = [ + ":scrooge2", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4", ], - visibility = ["//visibility:public"], ) + scrooge_scala_library( - name = "scrooge4a", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4:thrift4a", - ":scrooge4" + name = "scrooge4a", + visibility = ["//visibility:public"], + deps = [ + ":scrooge4", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4:thrift4a", ], - visibility = ["//visibility:public"], ) scrooge_scala_library( - name = "scroogebarejar1", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", - ], - visibility = ["//visibility:public"], + name = "scroogebarejar1", + visibility = ["//visibility:public"], + deps = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", + ], ) scrooge_scala_library( - name = "scroogebarejar2", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", - ], - visibility = ["//visibility:public"], + name = "scroogebarejar2", + visibility = ["//visibility:public"], + deps = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", + ], ) scrooge_scala_library( - name = "bare_thrift_scrooge", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts", - ":scroogebarejar1", - ":scroogebarejar2", - ], - visibility = ["//visibility:public"], + name = "bare_thrift_scrooge", + visibility = ["//visibility:public"], + deps = [ + ":scroogebarejar1", + ":scroogebarejar2", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts", + ], ) scala_library( - name = "justscrooge1", - srcs = ["JustScrooge1.scala"], - deps = [":scrooge1"], - exports = [":scrooge1"] + name = "justscrooge1", + srcs = ["JustScrooge1.scala"], + exports = [":scrooge1"], + deps = [":scrooge1"], ) scala_library( - name = "justscrooge2a", - srcs = ["JustScrooge2a.scala"], - deps = [":scrooge2_a"], + name = "justscrooge2a", + srcs = ["JustScrooge2a.scala"], + deps = [":scrooge2_a"], ) scala_library( - name = "justscrooge2b", - srcs = ["JustScrooge2b.scala"], - deps = [":scrooge2_b"], + name = "justscrooge2b", + srcs = ["JustScrooge2b.scala"], + deps = [":scrooge2_b"], ) scala_library( - name = "justscrooge3", - srcs = ["JustScrooge3.scala"], - deps = [":scrooge3"], - exports = [":scrooge3"], + name = "justscrooge3", + srcs = ["JustScrooge3.scala"], + exports = [":scrooge3"], + deps = [":scrooge3"], ) scala_library( - name = "scrooge2_both", - srcs = ["Scrooge2.scala"], - deps = [":scrooge2"], + name = "scrooge2_both", + srcs = ["Scrooge2.scala"], + deps = [":scrooge2"], ) scala_library( - name = "mixed", - srcs = ["Mixed.scala"], - deps = [ - ":justscrooge1", - ":justscrooge2a", - ":justscrooge2b", - ":justscrooge3", - ], + name = "mixed", + srcs = ["Mixed.scala"], + deps = [ + ":justscrooge1", + ":justscrooge2a", + ":justscrooge2b", + ":justscrooge3", + ], ) scala_library( - name = "twodeep", - srcs = ["Twodeep.scala"], - deps = [":justscrooge3"], + name = "twodeep", + srcs = ["Twodeep.scala"], + deps = [":justscrooge3"], ) scala_binary( - name = "twodeep_binary", - deps = [":twodeep"], - main_class = "scala.test.twitter_scrooge.Twodeep", + name = "twodeep_binary", + main_class = "scala.test.twitter_scrooge.Twodeep", + deps = [":twodeep"], ) scala_binary( - name = "justscrooge2b_binary", - deps = [":justscrooge2b"], - main_class = "scala.test.twitter_scrooge.JustScrooge2b" + name = "justscrooge2b_binary", + main_class = "scala.test.twitter_scrooge.JustScrooge2b", + deps = [":justscrooge2b"], ) scala_library( - name = "allscrooges", - exports = [ - ":scrooge1", - ":scrooge2_a", - ":scrooge2_b", - ":scrooge3", - ], + name = "allscrooges", + exports = [ + ":scrooge1", + ":scrooge2_a", + ":scrooge2_b", + ":scrooge3", + ], ) scala_binary( name = "justscrooges", srcs = ["JustScrooge1.scala"], - deps = [":allscrooges"], main_class = "scala.test.twitter_scrooge.JustScrooge1", + deps = [":allscrooges"], ) scala_library( - name = "barethriftslib", - srcs = ["BareThrifts.scala"], - deps = [":bare_thrift_scrooge"], + name = "barethriftslib", + srcs = ["BareThrifts.scala"], + deps = [":bare_thrift_scrooge"], ) scala_binary( - name = "barethrifts", - deps = [":bare_thrift_scrooge"], - main_class = "scala.test.twitter_scrooge.BareThrifts", + name = "barethrifts", + main_class = "scala.test.twitter_scrooge.BareThrifts", + deps = [":bare_thrift_scrooge"], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD index 425a62b42..47cca3670 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d/BUILD @@ -2,16 +2,16 @@ load("//thrift:thrift.bzl", "thrift_library") load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") thrift_library( - name = "a_thrift", - srcs = ["A.thrift"], - absolute_prefix = "prefix_test/a", - visibility = ["//visibility:public"], + name = "a_thrift", + srcs = ["A.thrift"], + absolute_prefix = "prefix_test/a", + visibility = ["//visibility:public"], ) scrooge_scala_library( - name = "d", - deps = [ - ":a_thrift" - ], - visibility = ["//visibility:public"], + name = "d", + visibility = ["//visibility:public"], + deps = [ + ":a_thrift", + ], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD index 531692b63..6c6289f27 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/prefix_test/e/f/b/c/d/BUILD @@ -2,18 +2,21 @@ load("//thrift:thrift.bzl", "thrift_library") load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library") thrift_library( - name = "b_thrift", - srcs = ["B.thrift"], - deps = ["//test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d:a_thrift"], - absolute_prefixes = ["prefix_test/a", "prefix_test/e/f"], - visibility = ["//visibility:public"], + name = "b_thrift", + srcs = ["B.thrift"], + absolute_prefixes = [ + "prefix_test/a", + "prefix_test/e/f", + ], + visibility = ["//visibility:public"], + deps = ["//test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d:a_thrift"], ) scrooge_scala_library( - name = "d", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d", - ":b_thrift", - ], - visibility = ["//visibility:public"], + name = "d", + visibility = ["//visibility:public"], + deps = [ + ":b_thrift", + "//test/src/main/scala/scala/test/twitter_scrooge/prefix_test/a/b/c/d", + ], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/BUILD index d215a2e91..b3c3b5096 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/BUILD @@ -1,17 +1,20 @@ load("//thrift:thrift.bzl", "thrift_library") thrift_library( - name = "thrift", - srcs = ["Thrift1.thrift"], - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", - ], - visibility = ["//visibility:public"], + name = "thrift", + srcs = ["Thrift1.thrift"], + visibility = ["//visibility:public"], + deps = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_a", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2:thrift2_b", + ], ) thrift_library( - name = "thrift_many", - srcs = ["ThriftMany1.thrift", "ThriftMany2.thrift"], - visibility = ["//visibility:public"], + name = "thrift_many", + srcs = [ + "ThriftMany1.thrift", + "ThriftMany2.thrift", + ], + visibility = ["//visibility:public"], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD index c909f5fb1..e7a7b4303 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD @@ -1,17 +1,17 @@ load("//thrift:thrift.bzl", "thrift_library") filegroup( - name = "barejar", - srcs= ["bare-thrift.jar"], - visibility = ["//visibility:public"], + name = "barejar", + srcs = ["bare-thrift.jar"], + visibility = ["//visibility:public"], ) thrift_library( - name = "bare_jar_thrifts", - deps = [ - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", - "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", - ], - visibility = ["//visibility:public"], - external_jars = [":barejar"], + name = "bare_jar_thrifts", + external_jars = [":barejar"], + visibility = ["//visibility:public"], + deps = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1", + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", + ], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD index 0b39f020d..e9a523805 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_1/BUILD @@ -1,13 +1,13 @@ load("//thrift:thrift.bzl", "thrift_library") filegroup( - name = "barejar1", - srcs= ["bare-thrift-1.jar"], - visibility = ["//visibility:public"], + name = "barejar1", + srcs = ["bare-thrift-1.jar"], + visibility = ["//visibility:public"], ) thrift_library( - name = "bare_jar_1", - external_jars = [":barejar1"], - visibility = ["//visibility:public"], + name = "bare_jar_1", + external_jars = [":barejar1"], + visibility = ["//visibility:public"], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD index c4331dc71..5d794d139 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2/BUILD @@ -1,13 +1,13 @@ load("//thrift:thrift.bzl", "thrift_library") filegroup( - name = "barejar2", - srcs= ["bare-thrift-2.jar"], - visibility = ["//visibility:public"], + name = "barejar2", + srcs = ["bare-thrift-2.jar"], + visibility = ["//visibility:public"], ) thrift_library( - name = "bare_jar_2", - external_jars = [":barejar2"], - visibility = ["//visibility:public"], + name = "bare_jar_2", + external_jars = [":barejar2"], + visibility = ["//visibility:public"], ) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/BUILD index d6a12e221..4d93cff28 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/BUILD @@ -1,15 +1,15 @@ load("//thrift:thrift.bzl", "thrift_library") thrift_library( - name = "thrift2_a", - srcs = ["Thrift2_A.thrift"], - deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], - visibility = ["//visibility:public"], + name = "thrift2_a", + srcs = ["Thrift2_A.thrift"], + visibility = ["//visibility:public"], + deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], ) thrift_library( - name = "thrift2_b", - srcs = ["Thrift2_B.thrift"], - deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], - visibility = ["//visibility:public"], -) \ No newline at end of file + name = "thrift2_b", + srcs = ["Thrift2_B.thrift"], + visibility = ["//visibility:public"], + deps = ["//test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3"], +) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD index 09c9b9c10..b117f4dce 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift3/BUILD @@ -1,7 +1,7 @@ load("//thrift:thrift.bzl", "thrift_library") thrift_library( - name = "thrift3", - srcs = ["Thrift3.thrift"], - visibility = ["//visibility:public"], -) \ No newline at end of file + name = "thrift3", + srcs = ["Thrift3.thrift"], + visibility = ["//visibility:public"], +) diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD index 919ee0510..7eb9a0e16 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/thrift2/thrift4/BUILD @@ -1,14 +1,14 @@ load("//thrift:thrift.bzl", "thrift_library") thrift_library( - name = "thrift4", - srcs = ["Thrift4.thrift"], - visibility = ["//visibility:public"], + name = "thrift4", + srcs = ["Thrift4.thrift"], + visibility = ["//visibility:public"], ) thrift_library( - name = "thrift4a", - srcs = ["Thrift4a.thrift"], - deps = [":thrift4"], - visibility = ["//visibility:public"], + name = "thrift4a", + srcs = ["Thrift4a.thrift"], + visibility = ["//visibility:public"], + deps = [":thrift4"], ) diff --git a/test/src/main/scala/scala/test/utf8/JavaClassWithUtf8.java b/test/src/main/scala/scala/test/utf8/JavaClassWithUtf8.java index 4334bf2b5..577337d25 100644 --- a/test/src/main/scala/scala/test/utf8/JavaClassWithUtf8.java +++ b/test/src/main/scala/scala/test/utf8/JavaClassWithUtf8.java @@ -1,5 +1,5 @@ package scala.test.utf8; class JavaClassWithUtf8 { - public static final String UTF_8_STR = "‡"; + public static final String UTF_8_STR = "‡"; } diff --git a/test/tut/BUILD b/test/tut/BUILD index 635bea33c..35005cb88 100644 --- a/test/tut/BUILD +++ b/test/tut/BUILD @@ -3,9 +3,11 @@ load("//scala:scala.bzl", "scala_library") scala_library( name = "test_dep", - srcs = ["TestDep.scala"]) + srcs = ["TestDep.scala"], +) scala_tut_doc( name = "some_example", src = "SomeExample.md", - deps = [":test_dep"]) + deps = [":test_dep"], +) diff --git a/test_expect_failure/compilers_javac_opts/BUILD b/test_expect_failure/compilers_javac_opts/BUILD index d4c552d9b..922e69b9c 100644 --- a/test_expect_failure/compilers_javac_opts/BUILD +++ b/test_expect_failure/compilers_javac_opts/BUILD @@ -2,17 +2,17 @@ load("//scala:scala.bzl", "scala_library") load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain") scala_library( - name = "can_configure_jvm_flags_for_javac_via_javacopts", - srcs = ["WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java"] + name = "can_configure_jvm_flags_for_javac_via_javacopts", + srcs = ["WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java"], ) default_java_toolchain( name = "a_java_toolchain", - jvm_opts = ["-Xbootclasspath/p:$(location @bazel_tools//third_party/java/jdk/langtools:javac_jar)",], - javac = ["@bazel_tools//third_party/java/jdk/langtools:javac_jar",], - bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar",], - visibility = ["//visibility:public",], + bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"], + javac = ["@bazel_tools//third_party/java/jdk/langtools:javac_jar"], + jvm_opts = ["-Xbootclasspath/p:$(location @bazel_tools//third_party/java/jdk/langtools:javac_jar)"], misc = [ - "-InvalidFlag" + "-InvalidFlag", ], + visibility = ["//visibility:public"], ) diff --git a/test_expect_failure/compilers_javac_opts/WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java b/test_expect_failure/compilers_javac_opts/WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java index fa0281511..299094b5f 100644 --- a/test_expect_failure/compilers_javac_opts/WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java +++ b/test_expect_failure/compilers_javac_opts/WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag.java @@ -1,4 +1,3 @@ package test_expect_failure.compilers_javac_opts; -public class WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag { -} +public class WillNotCompileSinceJavaToolchainAddsAnInvalidJvmFlag {} diff --git a/test_expect_failure/compilers_jvm_flags/BUILD b/test_expect_failure/compilers_jvm_flags/BUILD index cb659aa89..f25998c8d 100644 --- a/test_expect_failure/compilers_jvm_flags/BUILD +++ b/test_expect_failure/compilers_jvm_flags/BUILD @@ -1,36 +1,42 @@ load("//scala:scala.bzl", "scala_library") + scala_library( - name = "can_configure_jvm_flags_for_scalac", - srcs = ["WillNotCompileScalaSinceXmxTooLow.scala"], - scalac_jvm_flags = ["-Xmx1M"], + name = "can_configure_jvm_flags_for_scalac", + srcs = ["WillNotCompileScalaSinceXmxTooLow.scala"], + scalac_jvm_flags = ["-Xmx1M"], ) + scala_library( - name = "can_configure_jvm_flags_for_javac", - srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], - javac_jvm_flags = ["-Xmx1M"], + name = "can_configure_jvm_flags_for_javac", + srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], + javac_jvm_flags = ["-Xmx1M"], ) + scala_library( - name = "can_configure_jvm_flags_for_javac_via_javacopts", - srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], - javacopts = ["-Xmx1M"], + name = "can_configure_jvm_flags_for_javac_via_javacopts", + srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], + javacopts = ["-Xmx1M"], ) exports_files(["args.txt"]) + scala_library( - name = "can_expand_jvm_flags_for_scalac", - srcs = ["WillNotCompileScalaSinceXmxTooLow.scala"], - scalac_jvm_flags = ["$(location :args.txt)"], - data = [":args.txt"], + name = "can_expand_jvm_flags_for_scalac", + srcs = ["WillNotCompileScalaSinceXmxTooLow.scala"], + data = [":args.txt"], + scalac_jvm_flags = ["$(location :args.txt)"], ) + scala_library( - name = "can_expand_jvm_flags_for_javac", - srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], - javac_jvm_flags = ["$(location :args.txt)"], - data = [":args.txt"], + name = "can_expand_jvm_flags_for_javac", + srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], + data = [":args.txt"], + javac_jvm_flags = ["$(location :args.txt)"], ) + scala_library( - name = "can_expand_jvm_flags_for_javac_via_javacopts", - srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], - javacopts = ["$(location :args.txt)"], - data = [":args.txt"], + name = "can_expand_jvm_flags_for_javac_via_javacopts", + srcs = ["WillNotCompileJavaSinceXmxTooLow.java"], + data = [":args.txt"], + javacopts = ["$(location :args.txt)"], ) diff --git a/test_expect_failure/compilers_jvm_flags/WillNotCompileJavaSinceXmxTooLow.java b/test_expect_failure/compilers_jvm_flags/WillNotCompileJavaSinceXmxTooLow.java index 62d76d842..f7f2d99df 100644 --- a/test_expect_failure/compilers_jvm_flags/WillNotCompileJavaSinceXmxTooLow.java +++ b/test_expect_failure/compilers_jvm_flags/WillNotCompileJavaSinceXmxTooLow.java @@ -1 +1 @@ -class WillNotCompileJavaSinceXmxTooLow {} \ No newline at end of file +class WillNotCompileJavaSinceXmxTooLow {} diff --git a/test_expect_failure/disappearing_class/BUILD b/test_expect_failure/disappearing_class/BUILD index f4972f92d..bcee04a4d 100644 --- a/test_expect_failure/disappearing_class/BUILD +++ b/test_expect_failure/disappearing_class/BUILD @@ -6,7 +6,6 @@ scala_library( deps = [":class_provider"], ) - scala_library( name = "class_provider", srcs = ["ClassProvider.scala"], diff --git a/test_expect_failure/mismatching_resource_strip_prefix/BUILD b/test_expect_failure/mismatching_resource_strip_prefix/BUILD index f56000614..c870d29e1 100644 --- a/test_expect_failure/mismatching_resource_strip_prefix/BUILD +++ b/test_expect_failure/mismatching_resource_strip_prefix/BUILD @@ -1,7 +1,7 @@ load("//scala:scala.bzl", "scala_library") scala_library( - name = "noSrcsJarWithWrongStripPrefix", - resource_strip_prefix="wrong_prefix", - resources = ["resource.txt"] + name = "noSrcsJarWithWrongStripPrefix", + resource_strip_prefix = "wrong_prefix", + resources = ["resource.txt"], ) diff --git a/test_expect_failure/missing_direct_deps/external_deps/BUILD b/test_expect_failure/missing_direct_deps/external_deps/BUILD index 3fb0165a6..363e40774 100644 --- a/test_expect_failure/missing_direct_deps/external_deps/BUILD +++ b/test_expect_failure/missing_direct_deps/external_deps/BUILD @@ -1,34 +1,35 @@ package(default_visibility = ["//visibility:public"]) + load("//scala:scala.bzl", "scala_library", "scala_test") scala_library( - name="transitive_external_dependency_user", - srcs=[ + name = "transitive_external_dependency_user", + srcs = [ "A.scala", - ], + ], deps = ["external_dependency_user"], ) scala_library( - name="external_dependency_user", - srcs=[ + name = "external_dependency_user", + srcs = [ "B.scala", - ], + ], deps = ["@com_google_guava_guava_21_0//jar"], ) scala_library( - name="transitive_external_dependency_user_file_group", - srcs=[ + name = "transitive_external_dependency_user_file_group", + srcs = [ "A.scala", - ], + ], deps = ["external_dependency_user_file_group"], ) scala_library( - name="external_dependency_user_file_group", - srcs=[ + name = "external_dependency_user_file_group", + srcs = [ "B.scala", - ], + ], deps = ["@com_google_guava_guava_21_0_with_file//jar:file"], -) \ No newline at end of file +) diff --git a/test_expect_failure/missing_direct_deps/internal_deps/BUILD b/test_expect_failure/missing_direct_deps/internal_deps/BUILD index c3ee9c4c1..b249991d3 100644 --- a/test_expect_failure/missing_direct_deps/internal_deps/BUILD +++ b/test_expect_failure/missing_direct_deps/internal_deps/BUILD @@ -1,96 +1,97 @@ package(default_visibility = ["//visibility:public"]) + load("//scala:scala.bzl", "scala_library", "scala_test", "scala_binary") load(":custom-jvm-rule.bzl", "custom_jvm") scala_library( - name="transitive_dependency_user", - srcs=[ + name = "transitive_dependency_user", + srcs = [ "A.scala", - ], - deps = ["direct_dependency"], + ], + deps = ["direct_dependency"], ) scala_library( - name="transitive_dependency_java_user", - srcs=[ + name = "transitive_dependency_java_user", + srcs = [ "User.java", - ], - deps = ["direct_dependency"], + ], + deps = ["direct_dependency"], ) scala_library( - name="direct_dependency", - srcs=[ + name = "direct_dependency", + srcs = [ "B.scala", - ], + ], deps = ["transitive_dependency"], ) scala_library( - name="transitive_dependency", - srcs=[ + name = "transitive_dependency", + srcs = [ "C.scala", - ], + ], ) scala_library( - name="dependent_on_some_java_provider", - srcs=[ + name = "dependent_on_some_java_provider", + srcs = [ "HasCustomJavaProviderDependency.scala", - ], - deps = ["direct_java_provider_dependency"], + ], + deps = ["direct_java_provider_dependency"], ) custom_jvm( - name="direct_java_provider_dependency", + name = "direct_java_provider_dependency", deps = ["transitive_dependency"], ) scala_binary( - name="direct_binary_dependency", - main_class="B", - srcs=[ + name = "direct_binary_dependency", + srcs = [ "B.scala", - ], + ], + main_class = "B", deps = ["transitive_dependency"], ) scala_binary( - name="user_binary", - main_class="A", - srcs=[ + name = "user_binary", + srcs = [ "A.scala", - ], + ], + main_class = "A", deps = ["direct_dependency"], ) scala_binary( - name="binary_user_of_binary", - main_class="D", - srcs=[ + name = "binary_user_of_binary", + srcs = [ "D.scala", - ], + ], + main_class = "D", deps = ["direct_binary_dependency"], ) java_library( - name="java_library_dependent_on_some_java_provider", - srcs=[ + name = "java_library_dependent_on_some_java_provider", + srcs = [ "JavaLibraryHasCustomJavaProviderDependency.java", - ], + ], deps = ["direct_java_provider_dependency"], ) java_library( - name="java_library_dependent_on_java_library", - srcs=[ + name = "java_library_dependent_on_java_library", + srcs = [ "JavaLibraryHasCustomJavaProviderDependency.java", - ], + ], deps = ["direct_java_library_dependency"], ) java_library( - name="direct_java_library_dependency", + name = "direct_java_library_dependency", srcs = ["Placeholder.java"], deps = ["transitive_dependency"], ) diff --git a/test_expect_failure/missing_direct_deps/internal_deps/JavaLibraryHasCustomJavaProviderDependency.java b/test_expect_failure/missing_direct_deps/internal_deps/JavaLibraryHasCustomJavaProviderDependency.java index 33272e15c..35533d73d 100644 --- a/test_expect_failure/missing_direct_deps/internal_deps/JavaLibraryHasCustomJavaProviderDependency.java +++ b/test_expect_failure/missing_direct_deps/internal_deps/JavaLibraryHasCustomJavaProviderDependency.java @@ -2,7 +2,6 @@ public class JavaLibraryHasCustomJavaProviderDependency { public void foo() { - C.foo(); + C.foo(); } - } diff --git a/test_expect_failure/missing_direct_deps/internal_deps/Placeholder.java b/test_expect_failure/missing_direct_deps/internal_deps/Placeholder.java index a849127fe..ae7d02ec0 100644 --- a/test_expect_failure/missing_direct_deps/internal_deps/Placeholder.java +++ b/test_expect_failure/missing_direct_deps/internal_deps/Placeholder.java @@ -1,5 +1,3 @@ package test_expect_failure.missing_direct_deps.internal_deps; -public class Placeholder { - -} +public class Placeholder {} diff --git a/test_expect_failure/missing_direct_deps/internal_deps/User.java b/test_expect_failure/missing_direct_deps/internal_deps/User.java index 70dcf8b24..e1b7e0a12 100644 --- a/test_expect_failure/missing_direct_deps/internal_deps/User.java +++ b/test_expect_failure/missing_direct_deps/internal_deps/User.java @@ -2,9 +2,8 @@ public class User { - public void foo() { - B.foo(); - C.foo(); - } - + public void foo() { + B.foo(); + C.foo(); + } } diff --git a/test_expect_failure/missing_direct_deps/internal_deps/custom-jvm-rule.bzl b/test_expect_failure/missing_direct_deps/internal_deps/custom-jvm-rule.bzl index d2b7a2efd..d20515454 100644 --- a/test_expect_failure/missing_direct_deps/internal_deps/custom-jvm-rule.bzl +++ b/test_expect_failure/missing_direct_deps/internal_deps/custom-jvm-rule.bzl @@ -1,23 +1,24 @@ def _custom_jvm_impl(ctx): - print(ctx.label) - transitive_compile_jars = _collect(ctx.attr.deps) - return struct( - providers = [ + print(ctx.label) + transitive_compile_jars = _collect(ctx.attr.deps) + return struct( + providers = [ java_common.create_provider( transitive_compile_time_jars = transitive_compile_jars, ) - ], - ) + ], + ) def _collect(deps): transitive_compile_jars = depset() for dep_target in deps: - transitive_compile_jars += dep_target[java_common.provider].transitive_compile_time_jars + transitive_compile_jars += dep_target[ + java_common.provider].transitive_compile_time_jars return transitive_compile_jars custom_jvm = rule( - implementation=_custom_jvm_impl, - attrs={ - "deps": attr.label_list(), - }, -) \ No newline at end of file + implementation = _custom_jvm_impl, + attrs = { + "deps": attr.label_list(), + }, +) diff --git a/test_expect_failure/proto_source_root/user/BUILD b/test_expect_failure/proto_source_root/user/BUILD index e7783eec6..fae72ff1c 100644 --- a/test_expect_failure/proto_source_root/user/BUILD +++ b/test_expect_failure/proto_source_root/user/BUILD @@ -1,15 +1,17 @@ -load("//scala_proto:scala_proto.bzl", - "scalapb_proto_library") +load( + "//scala_proto:scala_proto.bzl", + "scalapb_proto_library", +) proto_library( name = "user", srcs = glob(["*.proto"]), - deps = ["//test_expect_failure/proto_source_root/dependency"], proto_source_root = package_name(), + deps = ["//test_expect_failure/proto_source_root/dependency"], ) scalapb_proto_library( name = "user_scala", - deps = [":user"], visibility = ["//visibility:public"], + deps = [":user"], ) diff --git a/test_expect_failure/scala_import/BUILD b/test_expect_failure/scala_import/BUILD index b0d037042..49fa45764 100644 --- a/test_expect_failure/scala_import/BUILD +++ b/test_expect_failure/scala_import/BUILD @@ -1,59 +1,61 @@ -load("//scala:scala.bzl", "scala_library","scala_specs2_junit_test") +load("//scala:scala.bzl", "scala_library", "scala_specs2_junit_test") load("//scala:scala_import.bzl", "scala_import") #deps, transitive_deps and propagation of deps as transitive_runtime_deps #also labels handling- transitive and transitive-transitive scala_import( - name = "dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage", - jars = ["@org_psywerx_hairyfotr__linter//jar:file"], + name = "dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage", + jars = ["@org_psywerx_hairyfotr__linter//jar:file"], ) scala_import( - name = "guava", - jars = ["@com_google_guava_guava_21_0_with_file//jar:file"], - deps = [":dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage"] + name = "guava", + jars = ["@com_google_guava_guava_21_0_with_file//jar:file"], + deps = [":dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage"], ) scala_import( - name = "cats", - jars = ["@org_typelevel__cats_core//jar:file"], + name = "cats", + jars = ["@org_typelevel__cats_core//jar:file"], ) scala_import( - name = "indirection_for_transitive_compile_deps", - jars = [], - deps = [":cats"] + name = "indirection_for_transitive_compile_deps", + jars = [], + deps = [":cats"], ) scala_import( - name = "commons_lang_as_imported_jar_cats_and_guava_as_compile_deps", - jars = ["@org_apache_commons_commons_lang_3_5//jar:file"], - deps = [":guava", ":indirection_for_transitive_compile_deps"] + name = "commons_lang_as_imported_jar_cats_and_guava_as_compile_deps", + jars = ["@org_apache_commons_commons_lang_3_5//jar:file"], + deps = [ + ":guava", + ":indirection_for_transitive_compile_deps", + ], ) scala_specs2_junit_test( name = "scala_import_propagates_compile_deps", - srcs = ["ScalaImportPropagatesCompileDepsTest.scala"], - deps = [":commons_lang_as_imported_jar_cats_and_guava_as_compile_deps"], size = "small", + srcs = ["ScalaImportPropagatesCompileDepsTest.scala"], suffixes = ["Test"], + deps = [":commons_lang_as_imported_jar_cats_and_guava_as_compile_deps"], ) scala_library( name = "leaf_for_scala_import_passes_labels_of_direct_deps", + srcs = ["LeafScalaImportPassesLabelsDirectDeps.scala"], deps = [":middle_for_scala_import_passes_labels_of_direct_deps"], - srcs = ["LeafScalaImportPassesLabelsDirectDeps.scala"] ) scala_import( - name = "middle_for_scala_import_passes_labels_of_direct_deps", - jars = [], - deps = [":root_for_scala_import_passes_labels_of_direct_deps"] + name = "middle_for_scala_import_passes_labels_of_direct_deps", + jars = [], + deps = [":root_for_scala_import_passes_labels_of_direct_deps"], ) scala_library( name = "root_for_scala_import_passes_labels_of_direct_deps", - srcs = ["RootScalaImportPassesLabelsDirectDeps.scala"] + srcs = ["RootScalaImportPassesLabelsDirectDeps.scala"], ) - diff --git a/test_expect_failure/scala_junit_test/BUILD b/test_expect_failure/scala_junit_test/BUILD index 0491df576..2f91acad5 100644 --- a/test_expect_failure/scala_junit_test/BUILD +++ b/test_expect_failure/scala_junit_test/BUILD @@ -2,25 +2,27 @@ load("//scala:scala.bzl", "scala_junit_test", "scala_specs2_junit_test") scala_junit_test( name = "failing_test", + size = "small", srcs = ["JunitFailureTest.scala"], suffixes = ["Test"], - size = "small", ) + scala_junit_test( name = "no_prefix_or_suffix", - srcs = ["JunitTest.scala"], size = "small", + srcs = ["JunitTest.scala"], ) + scala_junit_test( name = "no_tests_found", + size = "small", srcs = ["JunitTest.scala"], suffixes = ["DoesNotMatch"], - size = "small", ) scala_specs2_junit_test( name = "specs2_failing_test", + size = "small", srcs = ["specs2/FailingTest.scala"], suffixes = ["Test"], - size = "small", -) \ No newline at end of file +) diff --git a/test_expect_failure/scala_library_suite/BUILD b/test_expect_failure/scala_library_suite/BUILD index ec234ca36..402a37ffa 100644 --- a/test_expect_failure/scala_library_suite/BUILD +++ b/test_expect_failure/scala_library_suite/BUILD @@ -1,4 +1,5 @@ load("//scala:scala.bzl", "scala_library_suite") + scala_library_suite( name = "library_suite_dep_on_children", srcs = glob(["Data*.scala"]), diff --git a/test_expect_failure/scalacopts_from_toolchain/BUILD b/test_expect_failure/scalacopts_from_toolchain/BUILD index 4bdc92487..d1562c994 100644 --- a/test_expect_failure/scalacopts_from_toolchain/BUILD +++ b/test_expect_failure/scalacopts_from_toolchain/BUILD @@ -4,18 +4,18 @@ load("//scala:scala.bzl", "scala_library") scala_toolchain( name = "failing_toolchain_impl", scalacopts = ["-Ywarn-unused"], - visibility = ["//visibility:public"] + visibility = ["//visibility:public"], ) toolchain( name = "failing_scala_toolchain", - toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", toolchain = "failing_toolchain_impl", - visibility = ["//visibility:public"] + toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type", + visibility = ["//visibility:public"], ) scala_library( name = "failing_build", srcs = ["ClassWithUnused.scala"], - scalacopts = ["-Xfatal-warnings"] -) \ No newline at end of file + scalacopts = ["-Xfatal-warnings"], +) diff --git a/test_expect_failure/transitive/java_to_scala/BUILD b/test_expect_failure/transitive/java_to_scala/BUILD index 25721b906..cf77eab4e 100644 --- a/test_expect_failure/transitive/java_to_scala/BUILD +++ b/test_expect_failure/transitive/java_to_scala/BUILD @@ -2,13 +2,13 @@ load("//scala:scala.bzl", "scala_library", "scala_export_to_java") scala_library( name = "a", - srcs = ["A.scala"] + srcs = ["A.scala"], ) scala_export_to_java( name = "b", exports = [":a"], - runtime_deps = [] + runtime_deps = [], ) java_library( @@ -20,6 +20,6 @@ java_library( java_library( name = "d", srcs = ["D.java"], - deps = [":c"], tags = ["manual"], + deps = [":c"], ) diff --git a/test_expect_failure/transitive/java_to_scala/D.java b/test_expect_failure/transitive/java_to_scala/D.java index bdaf613de..3eaa3a24a 100644 --- a/test_expect_failure/transitive/java_to_scala/D.java +++ b/test_expect_failure/transitive/java_to_scala/D.java @@ -1,7 +1,7 @@ package example; public class D { - public static void main(String[] args) { - A.foo(); - } + public static void main(String[] args) { + A.foo(); + } } diff --git a/test_expect_failure/transitive/scala_to_java/BUILD b/test_expect_failure/transitive/scala_to_java/BUILD index 187660069..9e2ab1c2b 100644 --- a/test_expect_failure/transitive/scala_to_java/BUILD +++ b/test_expect_failure/transitive/scala_to_java/BUILD @@ -2,7 +2,7 @@ load("//scala:scala.bzl", "scala_library") java_library( name = "a", - srcs = ["A.java"] + srcs = ["A.java"], ) scala_library( @@ -17,7 +17,7 @@ scala_library( scala_library( name = "d", - deps = [":c"], srcs = ["D.scala"], tags = ["manual"], + deps = [":c"], ) diff --git a/test_expect_failure/transitive/scala_to_scala/BUILD b/test_expect_failure/transitive/scala_to_scala/BUILD index 79d695e86..a272ff040 100644 --- a/test_expect_failure/transitive/scala_to_scala/BUILD +++ b/test_expect_failure/transitive/scala_to_scala/BUILD @@ -2,7 +2,7 @@ load("//scala:scala.bzl", "scala_library") scala_library( name = "a", - srcs = ["A.scala"] + srcs = ["A.scala"], ) scala_library( @@ -17,7 +17,7 @@ scala_library( scala_library( name = "d", - deps = [":c"], srcs = ["D.scala"], tags = ["manual"], + deps = [":c"], ) diff --git a/test_lint.sh b/test_lint.sh new file mode 100755 index 000000000..50e7aaa4d --- /dev/null +++ b/test_lint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -eou pipefail + +FMT_SKYLINT=false ./lint.sh check diff --git a/third_party/plugin/src/main/BUILD b/third_party/plugin/src/main/BUILD index bd9b4ab36..c9b712921 100644 --- a/third_party/plugin/src/main/BUILD +++ b/third_party/plugin/src/main/BUILD @@ -4,11 +4,12 @@ load("//scala:scala.bzl", "scala_library", "scala_library_for_plugin_bootstrappi scala_library_for_plugin_bootstrapping( name = "dependency_analyzer", - srcs = ["io/bazel/rulesscala/dependencyanalyzer/DependencyAnalyzer.scala", - ], + srcs = [ + "io/bazel/rulesscala/dependencyanalyzer/DependencyAnalyzer.scala", + ], resources = ["resources/scalac-plugin.xml"], visibility = ["//visibility:public"], deps = [ - "//external:io_bazel_rules_scala/dependency/scala/scala_compiler" + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", ], -) \ No newline at end of file +) diff --git a/third_party/plugin/src/test/BUILD b/third_party/plugin/src/test/BUILD index 6df6f27f3..68dd168ba 100644 --- a/third_party/plugin/src/test/BUILD +++ b/third_party/plugin/src/test/BUILD @@ -3,19 +3,24 @@ licenses(["notice"]) # 3-clause BSD load("//scala:scala.bzl", "scala_junit_test") scala_junit_test( - name = "dependency_analyzer_test", - srcs = ["io/bazel/rulesscala/dependencyanalyzer/DependencyAnalyzerTest.scala", - "io/bazel/rulesscala/dependencyanalyzer/TestUtil.scala"], - suffixes = ["Test"], - size = "small", - deps = ["//third_party/plugin/src/main:dependency_analyzer", - "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", - "//external:io_bazel_rules_scala/dependency/scala/scala_library", - "@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" - ], - jvm_flags = ["-Dplugin.jar.location=$(location //third_party/plugin/src/main:dependency_analyzer)", - "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", - "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", - "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)"], -) \ No newline at end of file + name = "dependency_analyzer_test", + size = "small", + srcs = [ + "io/bazel/rulesscala/dependencyanalyzer/DependencyAnalyzerTest.scala", + "io/bazel/rulesscala/dependencyanalyzer/TestUtil.scala", + ], + jvm_flags = [ + "-Dplugin.jar.location=$(location //third_party/plugin/src/main:dependency_analyzer)", + "-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)", + "-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)", + "-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)", + ], + suffixes = ["Test"], + deps = [ + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//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/thrift/thrift.bzl b/thrift/thrift.bzl index 8a8de26d3..c1b8a60ac 100644 --- a/thrift/thrift.bzl +++ b/thrift/thrift.bzl @@ -2,13 +2,12 @@ _thrift_filetype = FileType([".thrift"]) -ThriftInfo = provider( - fields=[ - "srcs", # The source files in this rule - "transitive_srcs", # the transitive version of the above - "external_jars", # external jars of thrift files - "transitive_external_jars" # transitive version of the above - ]) +ThriftInfo = provider(fields = [ + "srcs", # The source files in this rule + "transitive_srcs", # the transitive version of the above + "external_jars", # external jars of thrift files + "transitive_external_jars" # transitive version of the above +]) def _common_prefix(strings): pref = None @@ -27,7 +26,10 @@ def _common_prefix(strings): return pref def _thrift_library_impl(ctx): - prefixes = [p for p in ctx.attr.absolute_prefixes + [ctx.attr.absolute_prefix] if p != ''] + prefixes = [ + p for p in ctx.attr.absolute_prefixes + [ctx.attr.absolute_prefix] + if p != '' + ] src_paths = [f.path for f in ctx.files.srcs] if len(src_paths) <= 0 and len(ctx.attr.external_jars) <= 0: @@ -39,22 +41,26 @@ def _thrift_library_impl(ctx): found_prefixes = [p for p in prefixes if common_prefix.find(p) >= 0] if len(found_prefixes) == 0: - fail("could not find prefix from available prefixes: {prefixes} in the common prefix: {common_prefix}".format( - prefixes = ",".join(prefixes), - common_prefix = common_prefix)) + fail( + "could not find prefix from available prefixes: {prefixes} in the common prefix: {common_prefix}". + format(prefixes = ",".join(prefixes), common_prefix = common_prefix)) elif len(found_prefixes) > 1: - fail("Too many not prefixes found, matched: {found_prefixes} in the common prefix: {common_prefix}".format( - found_prefixes = ",".join(found_prefixes), - common_prefix = common_prefix)) + fail( + "Too many not prefixes found, matched: {found_prefixes} in the common prefix: {common_prefix}". + format( + found_prefixes = ",".join(found_prefixes), + common_prefix = common_prefix)) else: prefix = found_prefixes[0] pos = common_prefix.find(prefix) endpos = pos + len(prefix) actual_prefix = common_prefix[0:endpos] - zipper_args = "\n".join([ "%s=%s" % (src[endpos+1:], src) for src in src_paths ]) + "\n" + zipper_args = "\n".join( + ["%s=%s" % (src[endpos + 1:], src) for src in src_paths]) + "\n" if len(src_paths) > 0: - zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.outputs.libarchive.path) + zipper_arg_path = ctx.actions.declare_file( + "%s_zipper_args" % ctx.outputs.libarchive.path) ctx.actions.write(zipper_arg_path, zipper_args) _valid_thrift_deps(ctx.attr.deps) # We move the files and touch them so that the output file is a purely deterministic @@ -64,32 +70,35 @@ rm -f {out} {zipper} c {out} @{path} """ - cmd = cmd.format(out=ctx.outputs.libarchive.path, - path=zipper_arg_path.path, - zipper=ctx.executable._zipper.path) + cmd = cmd.format( + out = ctx.outputs.libarchive.path, + path = zipper_arg_path.path, + zipper = ctx.executable._zipper.path) ctx.actions.run_shell( - inputs = ctx.files.srcs + [ctx.executable._zipper, zipper_arg_path], - outputs = [ctx.outputs.libarchive], - command = cmd, - progress_message = "making thrift archive %s (%s files)" % (ctx.label, len(src_paths)), + inputs = ctx.files.srcs + [ctx.executable._zipper, zipper_arg_path], + outputs = [ctx.outputs.libarchive], + command = cmd, + progress_message = "making thrift archive %s (%s files)" % + (ctx.label, len(src_paths)), ) else: # we still have to create the output we declared ctx.actions.run_shell( - inputs = [ctx.executable._zipper], - outputs = [ctx.outputs.libarchive], - command = """ + inputs = [ctx.executable._zipper], + outputs = [ctx.outputs.libarchive], + command = """ echo "empty" > {out}.contents rm -f {out} {zipper} c {out} {out}.contents rm {out}.contents -""".format(out=ctx.outputs.libarchive.path, - zipper=ctx.executable._zipper.path), - progress_message = "making empty thrift archive %s" % ctx.label, +""".format(out = ctx.outputs.libarchive.path, + zipper = ctx.executable._zipper.path), + progress_message = "making empty thrift archive %s" % ctx.label, ) - - transitive_srcs = depset([ctx.outputs.libarchive], transitive = _collect_thrift_srcs(ctx.attr.deps)) + transitive_srcs = depset( + [ctx.outputs.libarchive], + transitive = _collect_thrift_srcs(ctx.attr.deps)) jarfiles = _collect_thrift_external_jars(ctx.attr.deps) for jar in ctx.attr.external_jars: jarfiles.append(depset(jar.files)) @@ -97,11 +106,12 @@ rm {out}.contents return [ ThriftInfo( - srcs = ctx.outputs.libarchive, - transitive_srcs = transitive_srcs, - external_jars = ctx.attr.external_jars, - transitive_external_jars = transitive_external_jars, - )] + srcs = ctx.outputs.libarchive, + transitive_srcs = transitive_srcs, + external_jars = ctx.attr.external_jars, + transitive_external_jars = transitive_external_jars, + ) + ] def _collect_thrift_srcs(targets): ds = [] @@ -129,29 +139,33 @@ def _valid_thrift_deps(targets): # different code generation targets, we don't need to have a whole separate # tree of targets organizing the thrifts per code gen paradigm. thrift_library = rule( - implementation = _thrift_library_impl, - attrs = { - "srcs": attr.label_list(allow_files=_thrift_filetype), - "deps": attr.label_list(), - #TODO this is not necessarily the best way to do this... the goal - # is that we want thrifts to be able to be imported via an absolute - # path. But the thrift files have no clue what part of their path - # should serve as the base for the import... for example, if a file is - # in src/main/thrift/com/hello/World.thrift, if something depends on that - # via "include 'com/hello/World.thrift'", there is no way to know what - # path that should be relative to. One option is to just search for anything - # that matches that, but that could create correctness issues if there are more - # than one in different parts of the tree. Another option is to take an argument - # that references namespace, and base the tree off of that. The downside - # to that is that thrift_library then gets enmeshed in the details of code - # generation. This could also be something punted to scrooge_scala_library - # or whatever, but I think that we should make it such that the archive - # created by this is created in such a way that absolute imports work... - "absolute_prefix": attr.string(default='', mandatory=False), - "absolute_prefixes": attr.string_list(), - # This is a list of JARs which only contain Thrift files - "external_jars": attr.label_list(), - "_zipper": attr.label(executable=True, cfg="host", default=Label("@bazel_tools//tools/zip:zipper"), allow_files=True) - }, - outputs={"libarchive": "lib%{name}.jar"}, + implementation = _thrift_library_impl, + attrs = { + "srcs": attr.label_list(allow_files = _thrift_filetype), + "deps": attr.label_list(), + #TODO this is not necessarily the best way to do this... the goal + # is that we want thrifts to be able to be imported via an absolute + # path. But the thrift files have no clue what part of their path + # should serve as the base for the import... for example, if a file is + # in src/main/thrift/com/hello/World.thrift, if something depends on that + # via "include 'com/hello/World.thrift'", there is no way to know what + # path that should be relative to. One option is to just search for anything + # that matches that, but that could create correctness issues if there are more + # than one in different parts of the tree. Another option is to take an argument + # that references namespace, and base the tree off of that. The downside + # to that is that thrift_library then gets enmeshed in the details of code + # generation. This could also be something punted to scrooge_scala_library + # or whatever, but I think that we should make it such that the archive + # created by this is created in such a way that absolute imports work... + "absolute_prefix": attr.string(default = '', mandatory = False), + "absolute_prefixes": attr.string_list(), + # This is a list of JARs which only contain Thrift files + "external_jars": attr.label_list(), + "_zipper": attr.label( + executable = True, + cfg = "host", + default = Label("@bazel_tools//tools/zip:zipper"), + allow_files = True) + }, + outputs = {"libarchive": "lib%{name}.jar"}, ) diff --git a/tut_rule/tut.bzl b/tut_rule/tut.bzl index 402fab2b6..92252021d 100644 --- a/tut_rule/tut.bzl +++ b/tut_rule/tut.bzl @@ -3,17 +3,19 @@ load("//scala:scala_cross_version.bzl", "scala_mvn_artifact") def tut_repositories(): native.maven_server( - name = "tut_repositories_maven_server", - url = "https://dl.bintray.com/tpolecat/maven/", + name = "tut_repositories_maven_server", + url = "https://dl.bintray.com/tpolecat/maven/", ) native.maven_jar( - 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", + 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", ) - native.bind(name = 'io_bazel_rules_scala/dependency/tut/tut_core', actual = '@io_bazel_rules_scala_org_tpolecat_tut_core//jar') + native.bind( + name = 'io_bazel_rules_scala/dependency/tut/tut_core', + actual = '@io_bazel_rules_scala_org_tpolecat_tut_core//jar') def scala_tut_doc(**kw): name = kw["name"] @@ -21,16 +23,15 @@ def scala_tut_doc(**kw): src = kw["src"] tool = "%s_compiler" % name scala_binary( - 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" - ], + 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" + ], ) native.genrule( name = name, srcs = [src], outs = ["%s_tut.md" % name], tools = [tool], - cmd = "./$(location %s) $(location %s) \"$@\"" % (tool, src) - ) + cmd = "./$(location %s) $(location %s) \"$@\"" % (tool, src)) diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index 8b14af7ce..3b5c96532 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -1,16 +1,15 @@ -load("//scala:scala.bzl", - "scala_library", +load( + "//scala:scala.bzl", + "scala_library", ) -load("//scala:scala_cross_version.bzl", - "scala_mvn_artifact", +load( + "//scala:scala_cross_version.bzl", + "scala_mvn_artifact", ) -load("//scala/private:common.bzl", - "write_manifest", - "collect_srcjars", - "collect_jars" -) +load("//scala/private:common.bzl", "write_manifest", "collect_srcjars", + "collect_jars") load("//thrift:thrift.bzl", "ThriftInfo") @@ -18,50 +17,60 @@ _jar_filetype = FileType([".jar"]) def twitter_scrooge(): native.maven_server( - name = "twitter_scrooge_maven_server", - url = "http://mirror.bazel.build/repo1.maven.org/maven2/", + name = "twitter_scrooge_maven_server", + url = "http://mirror.bazel.build/repo1.maven.org/maven2/", ) native.maven_jar( - name = "libthrift", - artifact = "org.apache.thrift:libthrift:0.8.0", - sha1 = "2203b4df04943f4d52c53b9608cef60c08786ef2", - server = "twitter_scrooge_maven_server", + name = "libthrift", + artifact = "org.apache.thrift:libthrift:0.8.0", + sha1 = "2203b4df04943f4d52c53b9608cef60c08786ef2", + server = "twitter_scrooge_maven_server", ) - native.bind(name = 'io_bazel_rules_scala/dependency/thrift/libthrift', actual = '@libthrift//jar') + native.bind( + 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", + name = "scrooge_core", + artifact = scala_mvn_artifact("com.twitter:scrooge-core:4.6.0"), + sha1 = "84b86c2e082aba6e0c780b3c76281703b891a2c8", + server = "twitter_scrooge_maven_server", ) - native.bind(name = 'io_bazel_rules_scala/dependency/thrift/scrooge_core', actual = '@scrooge_core//jar') + native.bind( + name = 'io_bazel_rules_scala/dependency/thrift/scrooge_core', + actual = '@scrooge_core//jar') #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", + name = "scrooge_generator", + artifact = scala_mvn_artifact("com.twitter:scrooge-generator:4.6.0"), + sha1 = "cacf72eedeb5309ca02b2d8325c587198ecaac82", + server = "twitter_scrooge_maven_server", ) - native.bind(name = 'io_bazel_rules_scala/dependency/thrift/scrooge_generator', actual = '@scrooge_generator//jar') + 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", + name = "util_core", + artifact = scala_mvn_artifact("com.twitter:util-core:6.33.0"), + sha1 = "bb49fa66a3ca9b7db8cd764d0b26ce498bbccc83", + server = "twitter_scrooge_maven_server", ) - native.bind(name = 'io_bazel_rules_scala/dependency/thrift/util_core', actual = '@util_core//jar') + 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", + name = "util_logging", + artifact = scala_mvn_artifact("com.twitter:util-logging:6.33.0"), + sha1 = "3d28e46f8ee3b7ad1b98a51b98089fc01c9755dd", + server = "twitter_scrooge_maven_server", ) - native.bind(name = 'io_bazel_rules_scala/dependency/thrift/util_logging', actual = '@util_logging//jar') + native.bind( + name = 'io_bazel_rules_scala/dependency/thrift/util_logging', + actual = '@util_logging//jar') def _collect_transitive_srcs(targets): r = [] @@ -112,8 +121,10 @@ def _assert_set_is_subset(want, have): if e not in have: missing.append(e) if len(missing) > 0: - fail('scrooge_srcjar target must depend on scrooge_srcjar targets sufficient to ' + - 'cover the transitive graph of thrift files. Uncovered sources: ' + str(missing)) + fail( + 'scrooge_srcjar target must depend on scrooge_srcjar targets sufficient to ' + + 'cover the transitive graph of thrift files. Uncovered sources: ' + + str(missing)) def _colon_paths(data): return ':'.join([f.path for f in data]) @@ -147,7 +158,10 @@ def _gen_scrooge_srcjar_impl(ctx): # These are the thrift sources in the dependency graph. They are necessary # to generate the code, but are not "owned" by this target and will not # be in the resultant source jar - transitive_thrift_srcs = depset(transitive = [transitive_owned_srcs, _collect_transitive_srcs(ctx.attr.deps)]).to_list() + transitive_thrift_srcs = depset(transitive = [ + transitive_owned_srcs, + _collect_transitive_srcs(ctx.attr.deps) + ]).to_list() only_transitive_thrift_srcs = [] for src in transitive_thrift_srcs: @@ -156,43 +170,48 @@ def _gen_scrooge_srcjar_impl(ctx): # We want to ensure that the thrift sources which we do not own (but need # in order to generate code) have targets which will compile them. - _assert_set_is_subset(_list_to_map(only_transitive_thrift_srcs), _list_to_map(transitive_owned_srcs.to_list())) + _assert_set_is_subset( + _list_to_map(only_transitive_thrift_srcs), + _list_to_map(transitive_owned_srcs.to_list())) # bazel worker arguments cannot be empty so we pad to ensure non-empty # and drop it off on the other side # https://github.com/bazelbuild/bazel/issues/3329 worker_arg_pad = "_" - path_content = "\n".join([worker_arg_pad + _colon_paths(ps) for ps in [immediate_thrift_srcs, only_transitive_thrift_srcs, remote_jars, external_jars]]) + path_content = "\n".join([ + worker_arg_pad + _colon_paths(ps) for ps in [ + immediate_thrift_srcs, only_transitive_thrift_srcs, remote_jars, + external_jars + ] + ]) worker_content = "{output}\n{paths}\n{flags}".format( - output = ctx.outputs.srcjar.path, - paths = path_content, - flags = worker_arg_pad + ':'.join([ - '--with-finagle' if ctx.attr.with_finagle else '', - ])) - - argfile = ctx.actions.declare_file("%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) - ctx.actions.write(output=argfile, content=worker_content) + output = ctx.outputs.srcjar.path, + paths = path_content, + flags = worker_arg_pad + ':'.join([ + '--with-finagle' if ctx.attr.with_finagle else '', + ])) + + argfile = ctx.actions.declare_file( + "%s_worker_input" % ctx.label.name, sibling = ctx.outputs.srcjar) + ctx.actions.write(output = argfile, content = worker_content) ctx.actions.run( - executable = ctx.executable._pluck_scrooge_scala, - inputs = remote_jars + - only_transitive_thrift_srcs + - external_jars + - immediate_thrift_srcs + - [argfile], - outputs = [ctx.outputs.srcjar], - mnemonic="ScroogeRule", - progress_message = "creating scrooge files %s" % ctx.label, - execution_requirements={"supports-workers": "1"}, - # when we run with a worker, the `@argfile.path` is removed and passed - # line by line as arguments in the protobuf. In that case, - # the rest of the arguments are passed to the process that - # starts up and stays resident. - - # In either case (worker or not), they will be jvm flags which will - # be correctly handled since the executable is a jvm app that will - # consume the flags on startup. - - arguments=["--jvm_flag=%s" % flag for flag in ctx.attr.jvm_flags] + ["@" + argfile.path], + executable = ctx.executable._pluck_scrooge_scala, + inputs = remote_jars + only_transitive_thrift_srcs + external_jars + + immediate_thrift_srcs + [argfile], + outputs = [ctx.outputs.srcjar], + mnemonic = "ScroogeRule", + progress_message = "creating scrooge files %s" % ctx.label, + execution_requirements = {"supports-workers": "1"}, + # when we run with a worker, the `@argfile.path` is removed and passed + # line by line as arguments in the protobuf. In that case, + # the rest of the arguments are passed to the process that + # starts up and stays resident. + + # In either case (worker or not), they will be jvm flags which will + # be correctly handled since the executable is a jvm app that will + # consume the flags on startup. + arguments = ["--jvm_flag=%s" % flag for flag in ctx.attr.jvm_flags] + + ["@" + argfile.path], ) deps_jars = collect_jars(ctx.attr.deps) @@ -203,26 +222,34 @@ def _gen_scrooge_srcjar_impl(ctx): transitive_runtime_jars = deps_jars.transitive_runtime_jars, ) - transitive_srcjars = depset(transitive = [collect_srcjars(ctx.attr.deps), collect_extra_srcjars(ctx.attr.deps)]) + transitive_srcjars = depset(transitive = [ + collect_srcjars(ctx.attr.deps), + collect_extra_srcjars(ctx.attr.deps) + ]) srcjarsattr = struct( - srcjar = ctx.outputs.srcjar, - transitive_srcjars = transitive_srcjars, + srcjar = ctx.outputs.srcjar, + transitive_srcjars = transitive_srcjars, ) return struct( - scala = scalaattr, - srcjars=srcjarsattr, - extra_information=[struct( - srcjars=srcjarsattr, - scrooge_srcjar=struct(transitive_owned_srcs = depset(immediate_thrift_srcs, transitive = [transitive_owned_srcs])), - )], + scala = scalaattr, + srcjars = srcjarsattr, + extra_information = [ + struct( + srcjars = srcjarsattr, + scrooge_srcjar = struct( + transitive_owned_srcs = depset( + immediate_thrift_srcs, + transitive = [transitive_owned_srcs])), + ) + ], ) scrooge_scala_srcjar = rule( _gen_scrooge_srcjar_impl, - attrs={ - "deps": attr.label_list(mandatory=True), + attrs = { + "deps": attr.label_list(mandatory = True), #TODO we should think more about how we want to deal # with these sorts of things... this basically # is saying that we have a jar with a bunch @@ -232,42 +259,47 @@ scrooge_scala_srcjar = rule( # "covered," as well as needing the thrifts to # do the code gen. "remote_jars": attr.label_list(), - "jvm_flags": attr.string_list(), # the jvm flags to use with the generator - "with_finagle": attr.bool(default=False), + "jvm_flags": attr. + string_list(), # the jvm flags to use with the generator + "with_finagle": attr.bool(default = False), "_pluck_scrooge_scala": attr.label( - executable=True, - cfg="host", - default=Label("//src/scala/scripts:generator"), - allow_files=True), + executable = True, + cfg = "host", + default = Label("//src/scala/scripts:generator"), + allow_files = True), }, - outputs={ - "srcjar": "lib%{name}.srcjar", + outputs = { + "srcjar": "lib%{name}.srcjar", }, ) -def scrooge_scala_library(name, deps=[], remote_jars=[], jvm_flags=[], visibility=None, with_finagle=False): - srcjar = name + '_srcjar' - scrooge_scala_srcjar( - name = srcjar, - deps = deps, - remote_jars = remote_jars, - visibility = visibility, - with_finagle = with_finagle, - ) - - # deps from macro invocation would come via srcjar - # however, retained to make dependency analysis via aspects easier - scala_library( - name = name, - deps = deps + remote_jars + [ - srcjar, - "//external:io_bazel_rules_scala/dependency/thrift/libthrift", - "//external:io_bazel_rules_scala/dependency/thrift/scrooge_core" - ], - exports = deps + remote_jars + [ - "//external:io_bazel_rules_scala/dependency/thrift/libthrift", - "//external:io_bazel_rules_scala/dependency/thrift/scrooge_core", - ], - jvm_flags = jvm_flags, - visibility = visibility, - ) +def scrooge_scala_library(name, + deps = [], + remote_jars = [], + jvm_flags = [], + visibility = None, + with_finagle = False): + srcjar = name + '_srcjar' + scrooge_scala_srcjar( + name = srcjar, + deps = deps, + remote_jars = remote_jars, + visibility = visibility, + with_finagle = with_finagle, + ) + + # deps from macro invocation would come via srcjar + # however, retained to make dependency analysis via aspects easier + scala_library( + name = name, + deps = deps + remote_jars + [ + srcjar, "//external:io_bazel_rules_scala/dependency/thrift/libthrift", + "//external:io_bazel_rules_scala/dependency/thrift/scrooge_core" + ], + exports = deps + remote_jars + [ + "//external:io_bazel_rules_scala/dependency/thrift/libthrift", + "//external:io_bazel_rules_scala/dependency/thrift/scrooge_core", + ], + jvm_flags = jvm_flags, + visibility = visibility, + ) From 703c3cb40185312883ff39ffe9a895a68996bba6 Mon Sep 17 00:00:00 2001 From: ianoc-stripe Date: Tue, 12 Jun 2018 13:52:07 -0400 Subject: [PATCH 26/29] Fix the remote jars of the scala rules and make thrift + protobuf more stable (#516) * arg should be a depset * Sort the args from depsets to ensure stability across clean rebuilds * Remove the switching/tolist bit * Add remote jar test * Linting fix --- scala_proto/scala_proto.bzl | 3 ++- test/src/main/scala/scala/test/twitter_scrooge/BUILD | 11 +++++++++++ .../twitter_scrooge/thrift/bare_jar_thrifts/BUILD | 6 ++++++ twitter_scrooge/twitter_scrooge.bzl | 5 +++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scala_proto/scala_proto.bzl b/scala_proto/scala_proto.bzl index 5428abc50..18dbbf71b 100644 --- a/scala_proto/scala_proto.bzl +++ b/scala_proto/scala_proto.bzl @@ -306,7 +306,8 @@ def _root_path(f): def _colon_paths(data): return ':'.join([ - "{root},{path}".format(root = _root_path(f), path = f.path) for f in data + "{root},{path}".format(root = _root_path(f), path = f.path) + for f in sorted(data) ]) def _gen_proto_srcjar_impl(ctx): diff --git a/test/src/main/scala/scala/test/twitter_scrooge/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/BUILD index 7d7a96743..17e9ecd44 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/BUILD @@ -90,6 +90,17 @@ scrooge_scala_library( ], ) +scrooge_scala_library( + name = "thrift_with_remote_jar", + remote_jars = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts:barejar_java_import", + ], + visibility = ["//visibility:public"], + deps = [ + "//test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/bare_jar_2", + ], +) + scala_library( name = "justscrooge1", srcs = ["JustScrooge1.scala"], diff --git a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD index e7a7b4303..2bef3475f 100644 --- a/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD +++ b/test/src/main/scala/scala/test/twitter_scrooge/thrift/bare_jar_thrifts/BUILD @@ -6,6 +6,12 @@ filegroup( visibility = ["//visibility:public"], ) +java_import( + name = "barejar_java_import", + jars = ["bare-thrift.jar"], + visibility = ["//visibility:public"], +) + thrift_library( name = "bare_jar_thrifts", external_jars = [":barejar"], diff --git a/twitter_scrooge/twitter_scrooge.bzl b/twitter_scrooge/twitter_scrooge.bzl index 3b5c96532..6dda175d4 100644 --- a/twitter_scrooge/twitter_scrooge.bzl +++ b/twitter_scrooge/twitter_scrooge.bzl @@ -127,7 +127,7 @@ def _assert_set_is_subset(want, have): str(missing)) def _colon_paths(data): - return ':'.join([f.path for f in data]) + return ':'.join([f.path for f in sorted(data)]) def _list_to_map(items): map_result = {} @@ -138,7 +138,8 @@ def _list_to_map(items): def _gen_scrooge_srcjar_impl(ctx): remote_jars = [] for target in ctx.attr.remote_jars: - remote_jars.append(_jar_filetype.filter(target.files)) + remote_jars.append(depset(_jar_filetype.filter(target.files))) + # deduplicate these remote_jars = depset(transitive = remote_jars).to_list() From a8485f0a19629d34d579e3b30f8f271c664b5995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andy=20g=20scott=20=E2=98=9C?= Date: Tue, 12 Jun 2018 13:09:24 -0700 Subject: [PATCH 27/29] Inline private variable (#518) * Inline private variable * Remove public facing use of deprecated FileType --- scala/private/rule_impls.bzl | 1 - scala/scala.bzl | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 21ec1c82b..cfbb2bca9 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -25,7 +25,6 @@ load( "write_manifest", ) -_jar_filetype = FileType([".jar"]) _java_filetype = FileType([".java"]) _scala_filetype = FileType([".scala"]) _srcjar_filetype = FileType([".srcjar"]) diff --git a/scala/scala.bzl b/scala/scala.bzl index 8b373478a..2d99e1351 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -12,8 +12,6 @@ load( "@io_bazel_rules_scala//specs2:specs2_junit.bzl", _specs2_junit_dependencies = "specs2_junit_dependencies") -_jar_filetype = FileType([".jar"]) - _launcher_template = { "_java_stub_template": attr.label( default = Label("@java_stub_template//file")), @@ -101,10 +99,9 @@ _junit_resolve_deps = { # Common attributes reused across multiple rules. _common_attrs_for_plugin_bootstrapping = { - "srcs": attr.label_list( - allow_files = FileType([".scala", ".srcjar", ".java"])), + "srcs": attr.label_list(allow_files = [".scala", ".srcjar", ".java"]), "deps": attr.label_list(), - "plugins": attr.label_list(allow_files = FileType([".jar"])), + "plugins": attr.label_list(allow_files = [".jar"]), "runtime_deps": attr.label_list(), "data": attr.label_list(allow_files = True, cfg = "data"), "resources": attr.label_list(allow_files = True), @@ -128,7 +125,7 @@ _common_attrs.update({ default = Label( "@io_bazel_rules_scala//third_party/plugin/src/main:dependency_analyzer" ), - allow_files = _jar_filetype, + allow_files = [".jar"], mandatory = False), }) From 1865e6396ff38a9b0c4b435c683d3d7c193c4c0e Mon Sep 17 00:00:00 2001 From: ianoc-stripe Date: Wed, 13 Jun 2018 12:56:58 -0400 Subject: [PATCH 28/29] Fix issue building all outputs rather than just default (#521) * Fix bug in rule outputs * Linting --- scala/private/rule_impls.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index cfbb2bca9..81e823e5b 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -614,6 +614,7 @@ def _scala_binary_common(ctx, java_provider = create_java_provider(scalaattr, transitive_compile_time_jars) return struct( + files = depset([ctx.outputs.executable, ctx.outputs.jar]), providers = [java_provider], scala = scalaattr, transitive_rjars = From 59eed5ae3f8ce80b19700c90a2c62083e778af22 Mon Sep 17 00:00:00 2001 From: ianoc-stripe Date: Sat, 16 Jun 2018 15:24:25 -0400 Subject: [PATCH 29/29] This prints out to stderr on every target :/ (#522) --- src/java/io/bazel/rulesscala/jar/JarCreator.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/java/io/bazel/rulesscala/jar/JarCreator.java b/src/java/io/bazel/rulesscala/jar/JarCreator.java index 12a92f078..bfae66ee7 100644 --- a/src/java/io/bazel/rulesscala/jar/JarCreator.java +++ b/src/java/io/bazel/rulesscala/jar/JarCreator.java @@ -284,14 +284,11 @@ public static void buildJar(String[] args) throws IOException { /** A simple way to create Jar file using the JarCreator class. */ public static void main(String[] args) { - long start = System.currentTimeMillis(); try { buildJar(args); } catch (IOException e) { e.printStackTrace(); System.exit(1); } - long stop = System.currentTimeMillis(); - System.err.println((stop - start) + "ms."); } }