Skip to content

Commit 4015184

Browse files
andyscottittaiz
authored andcommitted
Format BUILD files and check format during CI (bazel-contrib#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
1 parent 52813b7 commit 4015184

File tree

110 files changed

+3923
-3150
lines changed

Some content is hidden

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

110 files changed

+3923
-3150
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ os:
1616

1717
env:
1818
# we want to test the last release
19+
- V=0.13.0 TEST_SCRIPT=test_lint.sh
1920
- V=0.13.0 TEST_SCRIPT=test_rules_scala.sh
2021
- V=0.13.0 TEST_SCRIPT=test_intellij_aspect.sh
2122
- V=0.13.0 TEST_SCRIPT=test_reproducibility.sh

CONTRIBUTING.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ the one above, the
2727
[Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate).
2828

2929
### Working with Intellij bazel plugin
30-
For your convenience, you can use [this](scripts/ij.bazelproject) .bazelproject file when you setup the bazel plugin in Intellij
30+
For your convenience, you can use [this](scripts/ij.bazelproject) .bazelproject file when you setup the bazel plugin in Intellij
31+
32+
### Formatting Fixes
33+
Code formatting is checked as part of the CI pipeline. To check/fix formatting
34+
you can use the `lint.sh` script:
35+
36+
```
37+
./ling.sh check # check formatting
38+
./lint.sh fix # fix formatting
39+
```
40+
41+
Note that Skylint failures are ignored and that the fix
42+
command will modify your files in place.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,7 @@ bazel test //test/...
628628
```
629629
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.
630630
Similarly to only build you should use `bazel build //src/...` due to that folder.
631+
632+
## Contributing
633+
634+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more info.

WORKSPACE

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,123 @@
11
workspace(name = "io_bazel_rules_scala")
22

3-
4-
53
load("//scala:scala.bzl", "scala_repositories")
4+
65
scala_repositories()
76

87
load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge", "scrooge_scala_library")
8+
99
twitter_scrooge()
1010

1111
load("//tut_rule:tut.bzl", "tut_repositories")
12+
1213
tut_repositories()
1314

1415
load("//jmh:jmh.bzl", "jmh_repositories")
16+
1517
jmh_repositories()
1618

1719
load("//scala_proto:scala_proto.bzl", "scala_proto_repositories")
20+
1821
scala_proto_repositories()
1922

20-
load("//specs2:specs2_junit.bzl","specs2_junit_repositories")
23+
load("//specs2:specs2_junit.bzl", "specs2_junit_repositories")
24+
2125
specs2_junit_repositories()
2226

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

2529
# test adding a scala jar:
2630
maven_jar(
27-
name = "com_twitter__scalding_date",
28-
artifact = scala_mvn_artifact("com.twitter:scalding-date:0.17.0"),
29-
sha1 = "420fb0c4f737a24b851c4316ee0362095710caa5"
31+
name = "com_twitter__scalding_date",
32+
artifact = scala_mvn_artifact("com.twitter:scalding-date:0.17.0"),
33+
sha1 = "420fb0c4f737a24b851c4316ee0362095710caa5",
3034
)
3135

3236
# For testing that we don't include sources jars to the classpath
3337
maven_jar(
34-
name = "org_typelevel__cats_core",
35-
artifact = scala_mvn_artifact("org.typelevel:cats-core:0.9.0"),
36-
sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314"
38+
name = "org_typelevel__cats_core",
39+
artifact = scala_mvn_artifact("org.typelevel:cats-core:0.9.0"),
40+
sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314",
3741
)
3842

39-
4043
# test of a plugin
4144
maven_jar(
42-
name = "org_psywerx_hairyfotr__linter",
43-
artifact = scala_mvn_artifact("org.psywerx.hairyfotr:linter:0.1.13"),
44-
sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4")
45+
name = "org_psywerx_hairyfotr__linter",
46+
artifact = scala_mvn_artifact("org.psywerx.hairyfotr:linter:0.1.13"),
47+
sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4",
48+
)
4549

4650
# test of strict deps (scalac plugin UT + E2E)
4751
maven_jar(
4852
name = "com_google_guava_guava_21_0_with_file",
4953
artifact = "com.google.guava:guava:21.0",
50-
sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709"
54+
sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709",
5155
)
5256

5357
maven_jar(
5458
name = "org_apache_commons_commons_lang_3_5",
5559
artifact = "org.apache.commons:commons-lang3:3.5",
56-
sha1 = "6c6c702c89bfff3cd9e80b04d668c5e190d588c6"
60+
sha1 = "6c6c702c89bfff3cd9e80b04d668c5e190d588c6",
5761
)
5862

5963
http_archive(
6064
name = "com_google_protobuf",
61-
urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"],
62-
strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457",
6365
sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163",
66+
strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457",
67+
urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"],
6468
)
6569

6670
http_archive(
6771
name = "com_google_protobuf_java",
68-
urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"],
69-
strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457",
7072
sha256 = "118ac276be0db540ff2a89cecc5dfb9606d4d16e91cc4ea8883ae8160acb5163",
73+
strip_prefix = "protobuf-0456e269ee6505766474aa8d7b8bba7ac047f457",
74+
urls = ["https://github.com/google/protobuf/archive/0456e269ee6505766474aa8d7b8bba7ac047f457.zip"],
7175
)
7276

7377
new_local_repository(
7478
name = "test_new_local_repo",
75-
path = "third_party/test/new_local_repo",
76-
build_file_content =
77-
"""
79+
build_file_content =
80+
"""
7881
filegroup(
7982
name = "data",
8083
srcs = glob(["**/*.txt"]),
8184
visibility = ["//visibility:public"],
8285
)
83-
"""
86+
""",
87+
path = "third_party/test/new_local_repo",
8488
)
8589

86-
load("@io_bazel_rules_scala//scala:toolchains.bzl","scala_register_toolchains")
90+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
91+
8792
scala_register_toolchains()
8893

8994
load("//scala:scala_maven_import_external.bzl", "scala_maven_import_external", "java_import_external")
95+
9096
scala_maven_import_external(
9197
name = "com_google_guava_guava_21_0",
92-
licenses = ["notice"], # Apache 2.0
9398
artifact = "com.google.guava:guava:21.0",
94-
server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"],
9599
jar_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480",
100+
licenses = ["notice"], # Apache 2.0
101+
server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"],
96102
)
97103

98104
# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external
99105
# in order to allow for other jvm-language imports (e.g. scala_import)
100106
# the 3rd-party dependency below is using the java_import_external macro
101107
# in order to make sure no regression with the original java_import_external
102108
load("//scala:scala_maven_import_external.bzl", "java_import_external")
109+
103110
java_import_external(
104111
name = "org_apache_commons_commons_lang_3_5_without_file",
105-
licenses = ["notice"], # Apache 2.0
106-
jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
112+
generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file",
107113
jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c",
114+
jar_urls = ["http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
115+
licenses = ["notice"], # Apache 2.0
108116
neverlink = True,
109-
generated_linkable_rule_name="linkable_org_apache_commons_commons_lang_3_5_without_file",
110117
)
118+
119+
## Linting
120+
121+
load("//private:format.bzl", "format_repositories")
122+
123+
format_repositories()

jmh/jmh.bzl

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def jmh_repositories():
2020
actual = '@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_asm//jar',
2121
)
2222
native.maven_jar(
23-
name = "io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection",
24-
artifact = "org.openjdk.jmh:jmh-generator-reflection:1.20",
25-
sha1 = "f2154437b42426a48d5dac0b3df59002f86aed26",
23+
name = "io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection",
24+
artifact = "org.openjdk.jmh:jmh-generator-reflection:1.20",
25+
sha1 = "f2154437b42426a48d5dac0b3df59002f86aed26",
2626
)
2727
native.bind(
28-
name = 'io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection',
29-
actual = '@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection//jar',
28+
name = 'io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection',
29+
actual =
30+
'@io_bazel_rules_scala_org_openjdk_jmh_jmh_generator_reflection//jar',
3031
)
3132
native.maven_jar(
3233
name = "io_bazel_rules_scala_org_ows2_asm_asm",
@@ -43,7 +44,8 @@ def jmh_repositories():
4344
sha1 = "cdd846cfc4e0f7eefafc02c0f5dce32b9303aa2a",
4445
)
4546
native.bind(
46-
name = "io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
47+
name =
48+
"io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
4749
actual = '@io_bazel_rules_scala_net_sf_jopt_simple_jopt_simple//jar',
4850
)
4951
native.maven_jar(
@@ -52,7 +54,8 @@ def jmh_repositories():
5254
sha1 = "e4ba98f1d4b3c80ec46392f25e094a6a2e58fcbf",
5355
)
5456
native.bind(
55-
name = "io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
57+
name =
58+
"io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
5659
actual = '@io_bazel_rules_scala_org_apache_commons_commons_math3//jar',
5760
)
5861

@@ -73,16 +76,26 @@ def _scala_generate_benchmark(ctx):
7376
outputs = [ctx.outputs.src_jar, ctx.outputs.resource_jar],
7477
inputs = depset([class_jar], transitive = [classpath]),
7578
executable = ctx.executable._generator,
76-
arguments = [ctx.attr.generator_type] + [f.path for f in [class_jar, ctx.outputs.src_jar, ctx.outputs.resource_jar] + classpath.to_list()],
79+
arguments = [ctx.attr.generator_type] + [
80+
f.path
81+
for f in [class_jar, ctx.outputs.src_jar, ctx.outputs.resource_jar] +
82+
classpath.to_list()
83+
],
7784
progress_message = "Generating benchmark code for %s" % ctx.label,
7885
)
7986

8087
scala_generate_benchmark = rule(
8188
implementation = _scala_generate_benchmark,
8289
attrs = {
83-
"src": attr.label(allow_single_file=True, mandatory=True),
84-
"generator_type": attr.string(default='reflection', mandatory=False),
85-
"_generator": attr.label(executable=True, cfg="host", default=Label("//src/scala/io/bazel/rules_scala/jmh_support:benchmark_generator"))
90+
"src": attr.label(allow_single_file = True, mandatory = True),
91+
"generator_type": attr.string(
92+
default = 'reflection', mandatory = False),
93+
"_generator": attr.label(
94+
executable = True,
95+
cfg = "host",
96+
default = Label(
97+
"//src/scala/io/bazel/rules_scala/jmh_support:benchmark_generator"
98+
))
8699
},
87100
outputs = {
88101
"src_jar": "%{name}.srcjar",
@@ -112,7 +125,8 @@ def scala_benchmark_jmh(**kw):
112125
)
113126

114127
codegen = name + "_codegen"
115-
scala_generate_benchmark(name=codegen, src=lib, generator_type=generator_type)
128+
scala_generate_benchmark(
129+
name = codegen, src = lib, generator_type = generator_type)
116130
compiled_lib = name + "_compiled_benchmark_lib"
117131
scala_library(
118132
name = compiled_lib,
@@ -124,11 +138,11 @@ def scala_benchmark_jmh(**kw):
124138
resource_jars = ["%s_resources.jar" % codegen],
125139
)
126140
scala_binary(
127-
name = name,
128-
deps = [
129-
"//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
130-
"//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
131-
compiled_lib,
132-
],
133-
main_class = main_class,
141+
name = name,
142+
deps = [
143+
"//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
144+
"//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
145+
compiled_lib,
146+
],
147+
main_class = main_class,
134148
)

junit/junit.bzl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ def junit_repositories():
44
artifact = "junit:junit:4.12",
55
sha1 = "2973d150c0dc1fefe998f834810d68f278ea58ec",
66
)
7-
native.bind(name = 'io_bazel_rules_scala/dependency/junit/junit', actual = '@io_bazel_rules_scala_junit_junit//jar')
8-
7+
native.bind(
8+
name = 'io_bazel_rules_scala/dependency/junit/junit',
9+
actual = '@io_bazel_rules_scala_junit_junit//jar')
10+
911
native.maven_jar(
1012
name = "io_bazel_rules_scala_org_hamcrest_hamcrest_core",
1113
artifact = "org.hamcrest:hamcrest-core:1.3",
1214
sha1 = "42a25dc3219429f0e5d060061f71acb49bf010a0",
1315
)
14-
native.bind(name = 'io_bazel_rules_scala/dependency/hamcrest/hamcrest_core', actual = '@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar')
16+
native.bind(
17+
name = 'io_bazel_rules_scala/dependency/hamcrest/hamcrest_core',
18+
actual = '@io_bazel_rules_scala_org_hamcrest_hamcrest_core//jar')

0 commit comments

Comments
 (0)