Skip to content

Commit

Permalink
Format BUILD files and check format during CI (#489)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andyscott authored and ittaiz committed Jun 12, 2018
1 parent 52813b7 commit 4015184
Show file tree
Hide file tree
Showing 110 changed files with 3,923 additions and 3,150 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -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
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.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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.
71 changes: 42 additions & 29 deletions WORKSPACE
@@ -1,110 +1,123 @@
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
# 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"],
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()
52 changes: 33 additions & 19 deletions jmh/jmh.bzl
Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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',
)

Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
10 changes: 7 additions & 3 deletions junit/junit.bzl
Expand Up @@ -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')

0 comments on commit 4015184

Please sign in to comment.