Skip to content

Commit

Permalink
Merge branch 'master' into andyscott/new-test-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
andyscott committed May 29, 2020
2 parents 2abce77 + 8f9f878 commit f112b01
Show file tree
Hide file tree
Showing 176 changed files with 5,402 additions and 3,502 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ hash2
.bazel_cache
.ijwb
.metals
unformatted-*.backup.scala
15 changes: 15 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
align.openParenCallSite = false
align.openParenDefnSite = false
continuationIndent.defnSite = 2
danglingParentheses = true
docstrings = JavaDoc
importSelectors = singleLine
maxColumn = 120
verticalMultiline.newlineBeforeImplicitKW = true
rewrite.redundantBraces.stringInterpolation = true
rewrite.rules = [
RedundantParens,
PreferCurlyFors,
SortImports
]
unindentTopLevelOperators = false
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ jobs:
env: TEST_SCRIPT=test_rules_scala BAZEL_VERSION=2.0.0
- <<: *linux
env: TEST_SCRIPT=test_reproducibility BAZEL_VERSION=2.0.0
- <<: *linux
env: TEST_SCRIPT=test_version BAZEL_VERSION=2.0.0
- <<: *osx
env: TEST_SCRIPT=test_rules_scala BAZEL_VERSION=2.0.0
- <<: *osx
env: TEST_SCRIPT=test_reproducibility BAZEL_VERSION=2.0.0
- <<: *osx
env: TEST_SCRIPT=test_version BAZEL_VERSION=2.0.0

before_install:
- |
Expand Down
Empty file added BUILD
Empty file.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ you can use the `lint.sh` script:

Note that Skylint failures are ignored and that the fix
command will modify your files in place.

### Additional Tests to Run
Some changes reqiring running additional tests which are not currently
part of the CI pipeline.

When editing code in `./third_party`, please run `./dangerous_test_thirdparty_version.sh`
but read the comments at the beginning of the file first.
171 changes: 145 additions & 26 deletions README.md

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ buildifier_dependencies()

load("//scala:scala.bzl", "scala_repositories")

scala_repositories()
scala_repositories(fetch_sources = True)

load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external")
load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library", "twitter_scrooge")

Expand All @@ -40,12 +41,20 @@ load("//specs2:specs2_junit.bzl", "specs2_junit_repositories")

specs2_junit_repositories()

load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories")

scalafmt_default_config()

scalafmt_repositories()

load("//scala:scala_cross_version.bzl", "default_scala_major_version", "scala_mvn_artifact")

MAVEN_SERVER_URLS = [
"https://jcenter.bintray.com",
"https://repo1.maven.org/maven2",
]
MAVEN_SERVER_URLS = default_maven_server_urls()

# needed for the cross repo proto test
load("//test/proto_cross_repo_boundary:repo.bzl", "proto_cross_repo_boundary_repository")

proto_cross_repo_boundary_repository()

# test sbt testing frameworks
scala_maven_import_external(
Expand Down Expand Up @@ -126,9 +135,7 @@ scala_maven_import_external(
artifact_sha256 = "4eb582bc99d96c8df92fc6f0f608fd123d278223982555ba16219bf8be9f75a9",
fetch_sources = True,
licenses = ["notice"],
server_urls = [
"https://repo.maven.apache.org/maven2/",
],
server_urls = MAVEN_SERVER_URLS,
srcjar_sha256 = "5e586357a289f5fe896f7b48759e1c16d9fa419333156b496696887e613d7a19",
)

Expand Down Expand Up @@ -171,10 +178,7 @@ scala_maven_import_external(
artifact_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480",
fetch_sources = True,
licenses = ["notice"], # Apache 2.0
server_urls = [
"https://repo1.maven.org/maven2/",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
server_urls = MAVEN_SERVER_URLS,
srcjar_sha256 = "b186965c9af0a714632fe49b33378c9670f8f074797ab466f49a67e918e116ea",
)

Expand Down Expand Up @@ -244,21 +248,15 @@ scala_maven_import_external(
artifact = "org.springframework:spring-core:5.1.5.RELEASE",
artifact_sha256 = "f771b605019eb9d2cf8f60c25c050233e39487ff54d74c93d687ea8de8b7285a",
licenses = ["notice"], # Apache 2.0
server_urls = [
"https://repo1.maven.org/maven2/",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
server_urls = MAVEN_SERVER_URLS,
)

scala_maven_import_external(
name = "org_springframework_spring_tx",
artifact = "org.springframework:spring-tx:5.1.5.RELEASE",
artifact_sha256 = "666f72b73c7e6b34e5bb92a0d77a14cdeef491c00fcb07a1e89eb62b08500135",
licenses = ["notice"], # Apache 2.0
server_urls = [
"https://repo1.maven.org/maven2/",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
server_urls = MAVEN_SERVER_URLS,
deps = [
"@org_springframework_spring_core",
],
Expand All @@ -274,7 +272,5 @@ scala_maven_import_external(
artifact_sha256 = "897460d4488b7dd6ac9198937d6417b36cc6ec8ab3693fdf2c532652f26c4373",
fetch_sources = False,
licenses = ["notice"],
server_urls = [
"https://repo.maven.apache.org/maven2/",
],
server_urls = MAVEN_SERVER_URLS,
)
148 changes: 148 additions & 0 deletions dangerous_test_thirdparty_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env bash

# This test is dangerous in that it modifies the root rules_scala
# WORKSPACE file. It attempts to restore the existing WORKSPACE file
# but there are risks that it may not be successful.

# Hence when running this test one should be sure that they do not
# have changes in the WORKSPACE file which they cannot recover
# from if the file gets lost.

# Note that due to performance constraints this is purposely not
# part of CI but when modifying the dependency_analyzer plugin,
# this should be run to ensure no regressions.

set -e

replace_workspace() {
sed -i '' \
-e "s|scala_repositories(.*)|$1|" \
$dir/WORKSPACE
}

test_scala_version() {
SCALA_VERSION=$1

SCALA_VERSION_SHAS=''
SCALA_VERSION_SHAS+='"scala_compiler": "'$2'",'
SCALA_VERSION_SHAS+='"scala_library": "'$3'",'
SCALA_VERSION_SHAS+='"scala_reflect": "'$4'"'

cp $dir/WORKSPACE $dir/WORKSPACE.bak
replace_workspace "scala_repositories((\"$SCALA_VERSION\", { $SCALA_VERSION_SHAS }))"

bazel test //third_party/...
RESPONSE_CODE=$?
# Restore old behavior
rm $dir/WORKSPACE
mv $dir/WORKSPACE.bak $dir/WORKSPACE
exit $RESPONSE_CODE

}

dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
test_dir=$dir/test/shell
# shellcheck source=./test_runner.sh
. "${test_dir}"/test_runner.sh
runner=$(get_test_runner "${1:-local}")


# Latest versions of each major version

$runner test_scala_version "2.12.10" \
"cedc3b9c39d215a9a3ffc0cc75a1d784b51e9edc7f13051a1b4ad5ae22cfbc0c" \
"0a57044d10895f8d3dd66ad4286891f607169d948845ac51e17b4c1cf0ab569d" \
"56b609e1bab9144fb51525bfa01ccd72028154fc40a58685a1e9adcbe7835730"


$runner test_scala_version "2.11.12" \
"3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0" \
"0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce" \
"6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04"


# Earliest functioning versions of each major version

$runner test_scala_version "2.12.0" \
"c767f79f9c529cedba2805db910164d5846f1f6d02424c6d7aadfc42ae5dadf1" \
"0e72ec4ea955d0bad7f1a494e8df95163f1631df0ce8ec4f9f278fe4d5fd1824" \
"f56553934378e6d3e8bf1d759a51f8b2fc4c99370774f0aaedaab8619517ccbe"


# Note: 2.11.0-2.11.8 do not work due to an error unrelated to the plugin
# Error is that argument -Ypartial-unification is invalid
# Hence we start with 2.11.9.
$runner test_scala_version "2.11.9" \
"fa01b414674cb38adc90ccf7a2042e82198dbb19dc41faccf0b5941ec08b1998" \
"e435d5ef31cc12dbf66719b7d5ab677ad739c63c3e451757b9688dcbeda0a984" \
"d932f809012d2cf832226b52a8bd82ed35b0257b1471c98968c0cd9ddf5327ab"

# Intermediate versions of 2.12.x

$runner test_scala_version "2.12.1" \
"fdd7679ce8a3fb4e30fbb9eaf9451f42c042f5ac3b5497f0fd01c379a3df9b3f" \
"9dab78f3f205a038f48183b2391f8a593235f794d8129a479e06af3e6bc50ef8" \
"d8a2b9d6d78c7457a40e394dc0c4fa6d6244acf0d156bbbcb311a9d497b85eec"


$runner test_scala_version "2.12.2" \
"b3d41a2887c114821878d45c1cb43cf7576c6854c7a303ef3d7be866dc44de34" \
"dd668b609002b3578f2db83a1a684d706155bba2fc801cd411359fdd48218d00" \
"98f9876d14b39fc7ec863c6b1b73c41a7653f886901b3ead0c4ca9215a688408"


$runner test_scala_version "2.12.3" \
"99d28c90ef1b8569da76a7e04415184cc54b57221ee259ffc55b2fcd64fb2107" \
"a8dd181a996dcc53a8c0bbb554bef7a1a9017ca09a377603167cf15444a85404" \
"93db412846912a1c212dd83c36dd51aa0adb9f39bfa6c4c3d65682afc94366c4"


$runner test_scala_version "2.12.4" \
"8b681302aac584f7234547eed04d2beeeb4a4f00032220e29d40943be6906a01" \
"17824fcee4d3f46cfaa4da84ebad4f58496426c2b9bc9e341f812ab23a667d5d" \
"ea70fe0e550e24d23fc52a18963b2be9c3b24283f4cb18b98327eb72746567cc"


$runner test_scala_version "2.12.5" \
"a113394b6f857e69ef5d95b77114ec3f12cb0e14d9ede32de0bbc9c36d677455" \
"c2636320d6479c82f2da6b8d76a820de9345a61327e648d4298a0048154fb87c" \
"27036d7574afff72294f0e63d54aa13acd8b16b525d51475691118b835e626e7"


$runner test_scala_version "2.12.6" \
"3023b07cc02f2b0217b2c04f8e636b396130b3a8544a8dfad498a19c3e57a863" \
"f81d7144f0ce1b8123335b72ba39003c4be2870767aca15dd0888ba3dab65e98" \
"ffa70d522fc9f9deec14358aa674e6dd75c9dfa39d4668ef15bb52f002ce99fa"


$runner test_scala_version "2.12.7" \
"6e80ef4493127214d31631287a6789170bf6c9a771d6094acd8dc785e8970270" \
"8f3dc6091db688464ad8b1ee6c7343d7aa5940d474ee8b90406c71e45dd74fc0" \
"7427d7ee5771e8c36c1db5a09368fa3078f6eceb77d7c797a322a088c5dddb76"


$runner test_scala_version "2.12.8" \
"f34e9119f45abd41e85b9e121ba19dd9288b3b4af7f7047e86dc70236708d170" \
"321fb55685635c931eba4bc0d7668349da3f2c09aee2de93a70566066ff25c28" \
"4d6405395c4599ce04cea08ba082339e3e42135de9aae2923c9f5367e957315a"


$runner test_scala_version "2.12.9" \
"5fd556459fd189b820db7d7c0a644ea5f7e8e032c421f2ad47038e72247fbf65" \
"364ee6ffd45f4fb8f9de40d1473d266ed5c199a44c1d4e2bdc895b1fbe35c75f" \
"4285ba64044d1a62b19304fe3ddd0088da240649c9fe2a6571c989feda1d0829"


# Intermediate versions of 2.11.x


$runner test_scala_version "2.11.10" \
"b70b748857213efe6f3a47d66acfa014c1bf51af3178b3a946eaae09f709fecc" \
"14a520328ea4ca7f423b30154a54d3df0a531a9c51f5e98eda272c9821bc5331" \
"fd896db4806875f538843ea24411e483ee4d0734710a108d0308ef108e83cf80"


$runner test_scala_version "2.11.11" \
"5f929ed57c515ef9545497374eec88ffd129b8f04079dedb7e32107104325cdd" \
"f2ba1550a39304e5d06caaddfa226cdf0a4cbccee189828fa8c1ddf1110c4872" \
"73aef1a6ccabd3a3c15cc153ec846e12d0f045587a2a1d88cc1b49293f47cb20"
61 changes: 61 additions & 0 deletions docs/coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Coverage support

### Running tests with coverage

rules_scala supports coverage, but it's disabled by default. You need to enable it with an extra toolchain:

```
bazel coverage --extra_toolchains="@io_bazel_rules_scala//scala:code_coverage_toolchain" //...
```

It will produce several .dat files with results for your targets.

You can also add more options to receive a combined coverage report:

```
bazel coverage \
--extra_toolchains="@io_bazel_rules_scala//scala:code_coverage_toolchain" \
--combined_report=lcov \
--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" \
//...
```

This should produce a single `bazel-out/_coverage/_coverage_report.dat` from all coverage files that are generated.

### Processing coverage reports

You can install `lcov` package (that supports the format Bazel uses for coverage reports) to have access to additional tools:

```
# Use your system package manager. E.g. on Ubuntu:
sudo apt install lcov
```

Having `lcov` package installed you can extract information from your coverage reports:

```
# For a summary:
lcov --summary your-coverage-report.dat
# For details:
lcov --list your-coverage-report.dat
```

If you prefer an HTML report, then you can use `genhtml` provided also by the `lcov` package.

An example with a bit of ceremony:

```bash
# Output html reports to a new directory.
destdir="my-coverage-reports"
mkdir -p ${destdir}

# Generate HTML report from the results.
genhtml -o ${destdir} --ignore-errors source bazel-out/_coverage/_coverage_report.dat

echo "coverage report at file://${destdir}/index.html"

```

### Support for testing frameworks

Coverage support has been only tested with [ScalaTest](http://www.scalatest.org/).
34 changes: 31 additions & 3 deletions docs/customizable_phase.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [As a consumer](#as-a-consumer)
* [As a contributor](#as-a-contributor)
* [Phase naming convention](#phase-naming-convention)
* [Cooperation with IntelliJ plugin](#cooperation-with-intellij-plugin)

## Overview
Phases increase configurability. Rule implementations are defined as a list of phases. Each phase defines a specific step, which helps breaking up implementation into smaller and more readable groups. Some phases are independent from others, which means the order doesn't matter. However, some phases depend on outputs of previous phases, in this case, we should make sure it meets all the prerequisites before executing phases.
Expand Down Expand Up @@ -144,9 +145,36 @@ Files in `scala/private/phases/`
- `phase_<PHASE_NAME>.bzl`: phase definition file

Function names in `phase_<PHASE_NAME>.bzl`
- `phase_<RULE_NAME>_<PHASE_NAME>`: function with custom inputs of specific rule
- `phase_common_<PHASE_NAME>`: function without custom inputs
- `_phase_default_<PHASE_NAME>`: private function that takes `_args` for custom inputs
- `phase_<PHASE_NAME>_<RULE_NAME>`: function with custom inputs of specific rule
- `phase_<PHASE_NAME>_common`: function without custom inputs
- `_phase_<PHASE_NAME>_default`: private function that takes `_args` for custom inputs
- `_phase_<PHASE_NAME>`: private function with the actual logic

See `phase_compile.bzl` for example.

## Cooperation with IntelliJ plugin

Bazel IntelliJ plugin has hard-coded the names of rules_scala targets that it detects as Scala targets:

https://github.com/bazelbuild/intellij/blame/22ea25d17ee9368a8c85262231009c5ec0225459/scala/src/com/google/idea/blaze/scala/ScalaBlazeRules.java#L32-L37

If you use custom-named rules, defined by using macros and phases it'll make the IntelliJ plugin not recognize those
as Scala targets. As a consequence e.g. you'll miss external dependency support for Scala in IntelliJ.

```python
ext_add_custom_phase = ... # some definition

# Using this rule won't let you see external dependencies:
custom_scala_binary = make_scala_binary(ext_add_custom_phase)
```

This is tracked in https://github.com/bazelbuild/intellij/issues/1824.

If you need to use custom-named rules and the IntelliJ plugin together, then you have for now mainly two options:
1. name your rules the same way as the IntelliJ plugin has hard-coded them (and use those from your own scope):
```python
scala_binary = make_scala_binary(ext_add_custom_phase)
```
2. use a forked IntelliJ plugin where you extend the list of detected Scala targets

Example: https://github.com/gergelyfabian/intellij/commit/265d3761aeabb60b79cab53a9ae9832899bfc651
Loading

0 comments on commit f112b01

Please sign in to comment.