Skip to content

Commit 71b3a53

Browse files
committed
Merge branch 'master' into andyscott/new-test-rule
2 parents 2abce77 + 8f9f878 commit 71b3a53

File tree

175 files changed

+5401
-3501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+5401
-3501
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ hash2
77
.bazel_cache
88
.ijwb
99
.metals
10+
unformatted-*.backup.scala

.scalafmt.conf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
align.openParenCallSite = false
2+
align.openParenDefnSite = false
3+
continuationIndent.defnSite = 2
4+
danglingParentheses = true
5+
docstrings = JavaDoc
6+
importSelectors = singleLine
7+
maxColumn = 120
8+
verticalMultiline.newlineBeforeImplicitKW = true
9+
rewrite.redundantBraces.stringInterpolation = true
10+
rewrite.rules = [
11+
RedundantParens,
12+
PreferCurlyFors,
13+
SortImports
14+
]
15+
unindentTopLevelOperators = false

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ jobs:
5252
env: TEST_SCRIPT=test_rules_scala BAZEL_VERSION=2.0.0
5353
- <<: *linux
5454
env: TEST_SCRIPT=test_reproducibility BAZEL_VERSION=2.0.0
55+
- <<: *linux
56+
env: TEST_SCRIPT=test_version BAZEL_VERSION=2.0.0
5557
- <<: *osx
5658
env: TEST_SCRIPT=test_rules_scala BAZEL_VERSION=2.0.0
5759
- <<: *osx
5860
env: TEST_SCRIPT=test_reproducibility BAZEL_VERSION=2.0.0
61+
- <<: *osx
62+
env: TEST_SCRIPT=test_version BAZEL_VERSION=2.0.0
5963

6064
before_install:
6165
- |

BUILD

Whitespace-only changes.

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ you can use the `lint.sh` script:
4646

4747
Note that Skylint failures are ignored and that the fix
4848
command will modify your files in place.
49+
50+
### Additional Tests to Run
51+
Some changes reqiring running additional tests which are not currently
52+
part of the CI pipeline.
53+
54+
When editing code in `./third_party`, please run `./dangerous_test_thirdparty_version.sh`
55+
but read the comments at the beginning of the file first.

README.md

+145-26
Large diffs are not rendered by default.

WORKSPACE

+19-23
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ buildifier_dependencies()
1717

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

20-
scala_repositories()
20+
scala_repositories(fetch_sources = True)
2121

22+
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
2223
load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external")
2324
load("//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library", "twitter_scrooge")
2425

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

4142
specs2_junit_repositories()
4243

44+
load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories")
45+
46+
scalafmt_default_config()
47+
48+
scalafmt_repositories()
49+
4350
load("//scala:scala_cross_version.bzl", "default_scala_major_version", "scala_mvn_artifact")
4451

45-
MAVEN_SERVER_URLS = [
46-
"https://jcenter.bintray.com",
47-
"https://repo1.maven.org/maven2",
48-
]
52+
MAVEN_SERVER_URLS = default_maven_server_urls()
53+
54+
# needed for the cross repo proto test
55+
load("//test/proto_cross_repo_boundary:repo.bzl", "proto_cross_repo_boundary_repository")
56+
57+
proto_cross_repo_boundary_repository()
4958

5059
# test sbt testing frameworks
5160
scala_maven_import_external(
@@ -126,9 +135,7 @@ scala_maven_import_external(
126135
artifact_sha256 = "4eb582bc99d96c8df92fc6f0f608fd123d278223982555ba16219bf8be9f75a9",
127136
fetch_sources = True,
128137
licenses = ["notice"],
129-
server_urls = [
130-
"https://repo.maven.apache.org/maven2/",
131-
],
138+
server_urls = MAVEN_SERVER_URLS,
132139
srcjar_sha256 = "5e586357a289f5fe896f7b48759e1c16d9fa419333156b496696887e613d7a19",
133140
)
134141

@@ -171,10 +178,7 @@ scala_maven_import_external(
171178
artifact_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480",
172179
fetch_sources = True,
173180
licenses = ["notice"], # Apache 2.0
174-
server_urls = [
175-
"https://repo1.maven.org/maven2/",
176-
"https://mirror.bazel.build/repo1.maven.org/maven2",
177-
],
181+
server_urls = MAVEN_SERVER_URLS,
178182
srcjar_sha256 = "b186965c9af0a714632fe49b33378c9670f8f074797ab466f49a67e918e116ea",
179183
)
180184

@@ -244,21 +248,15 @@ scala_maven_import_external(
244248
artifact = "org.springframework:spring-core:5.1.5.RELEASE",
245249
artifact_sha256 = "f771b605019eb9d2cf8f60c25c050233e39487ff54d74c93d687ea8de8b7285a",
246250
licenses = ["notice"], # Apache 2.0
247-
server_urls = [
248-
"https://repo1.maven.org/maven2/",
249-
"https://mirror.bazel.build/repo1.maven.org/maven2",
250-
],
251+
server_urls = MAVEN_SERVER_URLS,
251252
)
252253

253254
scala_maven_import_external(
254255
name = "org_springframework_spring_tx",
255256
artifact = "org.springframework:spring-tx:5.1.5.RELEASE",
256257
artifact_sha256 = "666f72b73c7e6b34e5bb92a0d77a14cdeef491c00fcb07a1e89eb62b08500135",
257258
licenses = ["notice"], # Apache 2.0
258-
server_urls = [
259-
"https://repo1.maven.org/maven2/",
260-
"https://mirror.bazel.build/repo1.maven.org/maven2",
261-
],
259+
server_urls = MAVEN_SERVER_URLS,
262260
deps = [
263261
"@org_springframework_spring_core",
264262
],
@@ -274,7 +272,5 @@ scala_maven_import_external(
274272
artifact_sha256 = "897460d4488b7dd6ac9198937d6417b36cc6ec8ab3693fdf2c532652f26c4373",
275273
fetch_sources = False,
276274
licenses = ["notice"],
277-
server_urls = [
278-
"https://repo.maven.apache.org/maven2/",
279-
],
275+
server_urls = MAVEN_SERVER_URLS,
280276
)

dangerous_test_thirdparty_version.sh

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/usr/bin/env bash
2+
3+
# This test is dangerous in that it modifies the root rules_scala
4+
# WORKSPACE file. It attempts to restore the existing WORKSPACE file
5+
# but there are risks that it may not be successful.
6+
7+
# Hence when running this test one should be sure that they do not
8+
# have changes in the WORKSPACE file which they cannot recover
9+
# from if the file gets lost.
10+
11+
# Note that due to performance constraints this is purposely not
12+
# part of CI but when modifying the dependency_analyzer plugin,
13+
# this should be run to ensure no regressions.
14+
15+
set -e
16+
17+
replace_workspace() {
18+
sed -i '' \
19+
-e "s|scala_repositories(.*)|$1|" \
20+
$dir/WORKSPACE
21+
}
22+
23+
test_scala_version() {
24+
SCALA_VERSION=$1
25+
26+
SCALA_VERSION_SHAS=''
27+
SCALA_VERSION_SHAS+='"scala_compiler": "'$2'",'
28+
SCALA_VERSION_SHAS+='"scala_library": "'$3'",'
29+
SCALA_VERSION_SHAS+='"scala_reflect": "'$4'"'
30+
31+
cp $dir/WORKSPACE $dir/WORKSPACE.bak
32+
replace_workspace "scala_repositories((\"$SCALA_VERSION\", { $SCALA_VERSION_SHAS }))"
33+
34+
bazel test //third_party/...
35+
RESPONSE_CODE=$?
36+
# Restore old behavior
37+
rm $dir/WORKSPACE
38+
mv $dir/WORKSPACE.bak $dir/WORKSPACE
39+
exit $RESPONSE_CODE
40+
41+
}
42+
43+
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
44+
test_dir=$dir/test/shell
45+
# shellcheck source=./test_runner.sh
46+
. "${test_dir}"/test_runner.sh
47+
runner=$(get_test_runner "${1:-local}")
48+
49+
50+
# Latest versions of each major version
51+
52+
$runner test_scala_version "2.12.10" \
53+
"cedc3b9c39d215a9a3ffc0cc75a1d784b51e9edc7f13051a1b4ad5ae22cfbc0c" \
54+
"0a57044d10895f8d3dd66ad4286891f607169d948845ac51e17b4c1cf0ab569d" \
55+
"56b609e1bab9144fb51525bfa01ccd72028154fc40a58685a1e9adcbe7835730"
56+
57+
58+
$runner test_scala_version "2.11.12" \
59+
"3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0" \
60+
"0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce" \
61+
"6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04"
62+
63+
64+
# Earliest functioning versions of each major version
65+
66+
$runner test_scala_version "2.12.0" \
67+
"c767f79f9c529cedba2805db910164d5846f1f6d02424c6d7aadfc42ae5dadf1" \
68+
"0e72ec4ea955d0bad7f1a494e8df95163f1631df0ce8ec4f9f278fe4d5fd1824" \
69+
"f56553934378e6d3e8bf1d759a51f8b2fc4c99370774f0aaedaab8619517ccbe"
70+
71+
72+
# Note: 2.11.0-2.11.8 do not work due to an error unrelated to the plugin
73+
# Error is that argument -Ypartial-unification is invalid
74+
# Hence we start with 2.11.9.
75+
$runner test_scala_version "2.11.9" \
76+
"fa01b414674cb38adc90ccf7a2042e82198dbb19dc41faccf0b5941ec08b1998" \
77+
"e435d5ef31cc12dbf66719b7d5ab677ad739c63c3e451757b9688dcbeda0a984" \
78+
"d932f809012d2cf832226b52a8bd82ed35b0257b1471c98968c0cd9ddf5327ab"
79+
80+
# Intermediate versions of 2.12.x
81+
82+
$runner test_scala_version "2.12.1" \
83+
"fdd7679ce8a3fb4e30fbb9eaf9451f42c042f5ac3b5497f0fd01c379a3df9b3f" \
84+
"9dab78f3f205a038f48183b2391f8a593235f794d8129a479e06af3e6bc50ef8" \
85+
"d8a2b9d6d78c7457a40e394dc0c4fa6d6244acf0d156bbbcb311a9d497b85eec"
86+
87+
88+
$runner test_scala_version "2.12.2" \
89+
"b3d41a2887c114821878d45c1cb43cf7576c6854c7a303ef3d7be866dc44de34" \
90+
"dd668b609002b3578f2db83a1a684d706155bba2fc801cd411359fdd48218d00" \
91+
"98f9876d14b39fc7ec863c6b1b73c41a7653f886901b3ead0c4ca9215a688408"
92+
93+
94+
$runner test_scala_version "2.12.3" \
95+
"99d28c90ef1b8569da76a7e04415184cc54b57221ee259ffc55b2fcd64fb2107" \
96+
"a8dd181a996dcc53a8c0bbb554bef7a1a9017ca09a377603167cf15444a85404" \
97+
"93db412846912a1c212dd83c36dd51aa0adb9f39bfa6c4c3d65682afc94366c4"
98+
99+
100+
$runner test_scala_version "2.12.4" \
101+
"8b681302aac584f7234547eed04d2beeeb4a4f00032220e29d40943be6906a01" \
102+
"17824fcee4d3f46cfaa4da84ebad4f58496426c2b9bc9e341f812ab23a667d5d" \
103+
"ea70fe0e550e24d23fc52a18963b2be9c3b24283f4cb18b98327eb72746567cc"
104+
105+
106+
$runner test_scala_version "2.12.5" \
107+
"a113394b6f857e69ef5d95b77114ec3f12cb0e14d9ede32de0bbc9c36d677455" \
108+
"c2636320d6479c82f2da6b8d76a820de9345a61327e648d4298a0048154fb87c" \
109+
"27036d7574afff72294f0e63d54aa13acd8b16b525d51475691118b835e626e7"
110+
111+
112+
$runner test_scala_version "2.12.6" \
113+
"3023b07cc02f2b0217b2c04f8e636b396130b3a8544a8dfad498a19c3e57a863" \
114+
"f81d7144f0ce1b8123335b72ba39003c4be2870767aca15dd0888ba3dab65e98" \
115+
"ffa70d522fc9f9deec14358aa674e6dd75c9dfa39d4668ef15bb52f002ce99fa"
116+
117+
118+
$runner test_scala_version "2.12.7" \
119+
"6e80ef4493127214d31631287a6789170bf6c9a771d6094acd8dc785e8970270" \
120+
"8f3dc6091db688464ad8b1ee6c7343d7aa5940d474ee8b90406c71e45dd74fc0" \
121+
"7427d7ee5771e8c36c1db5a09368fa3078f6eceb77d7c797a322a088c5dddb76"
122+
123+
124+
$runner test_scala_version "2.12.8" \
125+
"f34e9119f45abd41e85b9e121ba19dd9288b3b4af7f7047e86dc70236708d170" \
126+
"321fb55685635c931eba4bc0d7668349da3f2c09aee2de93a70566066ff25c28" \
127+
"4d6405395c4599ce04cea08ba082339e3e42135de9aae2923c9f5367e957315a"
128+
129+
130+
$runner test_scala_version "2.12.9" \
131+
"5fd556459fd189b820db7d7c0a644ea5f7e8e032c421f2ad47038e72247fbf65" \
132+
"364ee6ffd45f4fb8f9de40d1473d266ed5c199a44c1d4e2bdc895b1fbe35c75f" \
133+
"4285ba64044d1a62b19304fe3ddd0088da240649c9fe2a6571c989feda1d0829"
134+
135+
136+
# Intermediate versions of 2.11.x
137+
138+
139+
$runner test_scala_version "2.11.10" \
140+
"b70b748857213efe6f3a47d66acfa014c1bf51af3178b3a946eaae09f709fecc" \
141+
"14a520328ea4ca7f423b30154a54d3df0a531a9c51f5e98eda272c9821bc5331" \
142+
"fd896db4806875f538843ea24411e483ee4d0734710a108d0308ef108e83cf80"
143+
144+
145+
$runner test_scala_version "2.11.11" \
146+
"5f929ed57c515ef9545497374eec88ffd129b8f04079dedb7e32107104325cdd" \
147+
"f2ba1550a39304e5d06caaddfa226cdf0a4cbccee189828fa8c1ddf1110c4872" \
148+
"73aef1a6ccabd3a3c15cc153ec846e12d0f045587a2a1d88cc1b49293f47cb20"

docs/coverage.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## Coverage support
2+
3+
### Running tests with coverage
4+
5+
rules_scala supports coverage, but it's disabled by default. You need to enable it with an extra toolchain:
6+
7+
```
8+
bazel coverage --extra_toolchains="@io_bazel_rules_scala//scala:code_coverage_toolchain" //...
9+
```
10+
11+
It will produce several .dat files with results for your targets.
12+
13+
You can also add more options to receive a combined coverage report:
14+
15+
```
16+
bazel coverage \
17+
--extra_toolchains="@io_bazel_rules_scala//scala:code_coverage_toolchain" \
18+
--combined_report=lcov \
19+
--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" \
20+
//...
21+
```
22+
23+
This should produce a single `bazel-out/_coverage/_coverage_report.dat` from all coverage files that are generated.
24+
25+
### Processing coverage reports
26+
27+
You can install `lcov` package (that supports the format Bazel uses for coverage reports) to have access to additional tools:
28+
29+
```
30+
# Use your system package manager. E.g. on Ubuntu:
31+
sudo apt install lcov
32+
```
33+
34+
Having `lcov` package installed you can extract information from your coverage reports:
35+
36+
```
37+
# For a summary:
38+
lcov --summary your-coverage-report.dat
39+
# For details:
40+
lcov --list your-coverage-report.dat
41+
```
42+
43+
If you prefer an HTML report, then you can use `genhtml` provided also by the `lcov` package.
44+
45+
An example with a bit of ceremony:
46+
47+
```bash
48+
# Output html reports to a new directory.
49+
destdir="my-coverage-reports"
50+
mkdir -p ${destdir}
51+
52+
# Generate HTML report from the results.
53+
genhtml -o ${destdir} --ignore-errors source bazel-out/_coverage/_coverage_report.dat
54+
55+
echo "coverage report at file://${destdir}/index.html"
56+
57+
```
58+
59+
### Support for testing frameworks
60+
61+
Coverage support has been only tested with [ScalaTest](http://www.scalatest.org/).

docs/customizable_phase.md

+31-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [As a consumer](#as-a-consumer)
77
* [As a contributor](#as-a-contributor)
88
* [Phase naming convention](#phase-naming-convention)
9+
* [Cooperation with IntelliJ plugin](#cooperation-with-intellij-plugin)
910

1011
## Overview
1112
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.
@@ -144,9 +145,36 @@ Files in `scala/private/phases/`
144145
- `phase_<PHASE_NAME>.bzl`: phase definition file
145146

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

152153
See `phase_compile.bzl` for example.
154+
155+
## Cooperation with IntelliJ plugin
156+
157+
Bazel IntelliJ plugin has hard-coded the names of rules_scala targets that it detects as Scala targets:
158+
159+
https://github.com/bazelbuild/intellij/blame/22ea25d17ee9368a8c85262231009c5ec0225459/scala/src/com/google/idea/blaze/scala/ScalaBlazeRules.java#L32-L37
160+
161+
If you use custom-named rules, defined by using macros and phases it'll make the IntelliJ plugin not recognize those
162+
as Scala targets. As a consequence e.g. you'll miss external dependency support for Scala in IntelliJ.
163+
164+
```python
165+
ext_add_custom_phase = ... # some definition
166+
167+
# Using this rule won't let you see external dependencies:
168+
custom_scala_binary = make_scala_binary(ext_add_custom_phase)
169+
```
170+
171+
This is tracked in https://github.com/bazelbuild/intellij/issues/1824.
172+
173+
If you need to use custom-named rules and the IntelliJ plugin together, then you have for now mainly two options:
174+
1. name your rules the same way as the IntelliJ plugin has hard-coded them (and use those from your own scope):
175+
```python
176+
scala_binary = make_scala_binary(ext_add_custom_phase)
177+
```
178+
2. use a forked IntelliJ plugin where you extend the list of detected Scala targets
179+
180+
Example: https://github.com/gergelyfabian/intellij/commit/265d3761aeabb60b79cab53a9ae9832899bfc651

0 commit comments

Comments
 (0)