-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break workspace-builds into their own example (#301)
Currently, we are maintaining two build systems --- the `bzlmod` and the workspace-based builds. This PR simplifies our own builds by removing the top-level workspace-based build. It adds a workspace-based example that exercises the gazelle plugin, and the integration with `apple_rules_lint`
- Loading branch information
Showing
20 changed files
with
664 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Workspace-based | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
examples: | ||
strategy: | ||
matrix: | ||
runs-on: | ||
- ubuntu-latest | ||
|
||
runs-on: ${{ matrix.runs-on }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: true | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
|
||
- name: Run Gazelle | ||
run: (cd examples/workspace-based && bazel --bazelrc=../../.github/workflows/ci.bazelrc run gazelle) | ||
|
||
- name: Execute the lint tests | ||
run: (cd examples/workspace-based && bazel --bazelrc=../../.github/workflows/ci.bazelrc test --test_tag_filters=lint //...) | ||
|
||
- name: Execute the passing test | ||
run: (cd examples/workspace-based && bazel --bazelrc=../../.github/workflows/ci.bazelrc test //java/test/com/github/bazelcontrib/rulesjvm/example:PassingTest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1 @@ | ||
workspace(name = "contrib_rules_jvm") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "rules_python", | ||
sha256 = "497ca47374f48c8b067d786b512ac10a276211810f4a580178ee9b9ad139323a", | ||
strip_prefix = "rules_python-0.16.1", | ||
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.16.1.tar.gz", | ||
) | ||
|
||
load("//:repositories.bzl", "contrib_rules_jvm_deps", "contrib_rules_jvm_gazelle_deps") | ||
|
||
contrib_rules_jvm_deps() | ||
|
||
contrib_rules_jvm_gazelle_deps() | ||
|
||
load("@apple_rules_lint//lint:repositories.bzl", "lint_deps") | ||
|
||
lint_deps() | ||
|
||
load("@apple_rules_lint//lint:setup.bzl", "lint_setup") | ||
|
||
lint_setup({ | ||
"java-checkstyle": "//java:checkstyle-default-config", | ||
"java-pmd": "//java:pmd-config", | ||
"java-spotbugs": "//java:spotbugs-default-config", | ||
}) | ||
|
||
load("//:setup.bzl", "contrib_rules_jvm_setup") | ||
|
||
# gazelle:repository_macro third_party/go/repositories.bzl%go_deps | ||
contrib_rules_jvm_setup() | ||
|
||
load("//:gazelle_setup.bzl", "contrib_rules_jvm_gazelle_setup") | ||
|
||
contrib_rules_jvm_gazelle_setup() | ||
|
||
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS") | ||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
load("//third_party:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") | ||
|
||
# These are used for our own tests. | ||
maven_install( | ||
name = "contrib_rules_jvm_tests", | ||
artifacts = [ | ||
# These can be versioned independently of the versions in `repositories.bzl` | ||
# so long as the version numbers are higher. | ||
"org.junit.jupiter:junit-jupiter-engine:5.8.2", | ||
"org.junit.jupiter:junit-jupiter-api:5.8.2", | ||
"org.junit.jupiter:junit-jupiter-params:5.8.2", | ||
"org.junit.platform:junit-platform-launcher:1.8.2", | ||
"org.junit.platform:junit-platform-reporting:1.8.2", | ||
"org.junit.platform:junit-platform-suite:1.8.2", | ||
"org.junit.platform:junit-platform-suite-api:1.8.2", | ||
"org.junit.platform:junit-platform-suite-engine:1.8.2", | ||
"org.junit.vintage:junit-vintage-engine:5.8.2", | ||
"org.mockito:mockito-core:4.8.1", | ||
], | ||
fail_if_repin_required = True, | ||
fetch_sources = True, | ||
maven_install_json = "@//:contrib_rules_jvm_tests_install.json", | ||
repositories = [ | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
|
||
load("@contrib_rules_jvm_tests//:defs.bzl", maven_pmi = "pinned_maven_install") | ||
|
||
maven_pmi() | ||
|
||
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") | ||
|
||
stardoc_repositories() | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
||
go_rules_dependencies() | ||
|
||
go_register_toolchains(version = "1.21.5") | ||
|
||
gazelle_dependencies() | ||
|
||
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") | ||
|
||
rules_proto_dependencies() | ||
|
||
rules_proto_toolchains() | ||
|
||
load("@googleapis//:repository_rules.bzl", "switched_rules_by_language") | ||
|
||
switched_rules_by_language( | ||
name = "com_google_googleapis_imports", | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
common --noenable_bzlmod | ||
|
||
build --java_runtime_version=remotejdk_17 | ||
build --java_language_version=17 | ||
build --tool_java_runtime_version=remotejdk_17 | ||
build --tool_java_language_version=17 | ||
|
||
# Make sure we get something helpful when tests fail | ||
test --verbose_failures | ||
test --test_output=errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") | ||
|
||
# We can choose where the `maven_install` lock file is read from | ||
# | ||
# gazelle:java_maven_install_file java/maven_install.json | ||
|
||
# And this maps common types to the ones from `contrib_rules_jvm`. By | ||
# doing this we can use the integration with `apple_rules_lint`. | ||
# | ||
# gazelle:map_kind java_binary java_binary @contrib_rules_jvm//java:defs.bzl | ||
# gazelle:map_kind java_library java_library @contrib_rules_jvm//java:defs.bzl | ||
# gazelle:map_kind java_test java_test @contrib_rules_jvm//java:defs.bzl | ||
|
||
gazelle( | ||
name = "gazelle", | ||
gazelle = ":gazelle_bin", | ||
) | ||
|
||
gazelle_binary( | ||
name = "gazelle_bin", | ||
languages = DEFAULT_LANGUAGES + [ | ||
"@contrib_rules_jvm//java/gazelle", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Example Workspace-based project | ||
|
||
This is a small example of using the `gazelle` java plugin with a | ||
simple source repository. | ||
|
||
## Steps to use | ||
|
||
1. Run `bazel test //...` and notice that there's almost no tests. | ||
1. `bazel run gazelle` and find the new `BUILD.bazel` files that are created | ||
1. `bazel test //...` | ||
|
||
The final run of `bazel test` will fail, as one of the example tests | ||
is written so it won't pass. Try fixing it! | ||
|
||
This example also shows how you can make use of the linters that are | ||
supplied with `contrib_rules_jvm`. There are directives in the | ||
top-level `BUILD.bazel` that tell the gazelle plugin to use the macros | ||
from `contrib_rules_jvm` and not just `rules_java`. The configuration | ||
of the linters can be found in the `WORKSPACE` file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
workspace(name = "contrib_rules_jvm_workspace_example") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
local_repository( | ||
name = "contrib_rules_jvm", | ||
path = "../..", | ||
) | ||
|
||
http_archive( | ||
name = "apple_rules_lint", | ||
sha256 = "483ea03d73d5fb33275d029da8d36811243fc32dfa4dc73a43acbb6f4b1af621", | ||
strip_prefix = "apple_rules_lint-0.4.0", | ||
url = "https://github.com/apple/apple_rules_lint/releases/download/0.4.0/apple_rules_lint-0.4.0.tar.gz", | ||
) | ||
|
||
load("@apple_rules_lint//lint:repositories.bzl", "lint_deps") | ||
|
||
lint_deps() | ||
|
||
load("@apple_rules_lint//lint:setup.bzl", "lint_setup") | ||
|
||
lint_setup({ | ||
"java-checkstyle": "@contrib_rules_jvm//java:checkstyle-default-config", | ||
"java-pmd": "@contrib_rules_jvm//java:pmd-config", | ||
"java-spotbugs": "@contrib_rules_jvm//java:spotbugs-default-config", | ||
}) | ||
|
||
load("@contrib_rules_jvm//:repositories.bzl", "contrib_rules_jvm_deps", "contrib_rules_jvm_gazelle_deps") | ||
|
||
contrib_rules_jvm_deps() | ||
|
||
load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup") | ||
|
||
contrib_rules_jvm_setup() | ||
|
||
load("@rules_jvm_external//:defs.bzl", "maven_install") | ||
|
||
maven_install( | ||
artifacts = [ | ||
"com.google.guava:guava:33.3.1-jre", | ||
"org.junit.jupiter:junit-jupiter-engine:5.8.2", | ||
"org.junit.jupiter:junit-jupiter-api:5.8.2", | ||
"org.junit.platform:junit-platform-launcher:1.8.2", | ||
"org.junit.platform:junit-platform-reporting:1.8.2", | ||
], | ||
maven_install_json = "//java:maven_install.json", | ||
repositories = [ | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
|
||
load("@maven//:defs.bzl", "pinned_maven_install") | ||
|
||
pinned_maven_install() | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
integrity = "sha256-M6zErg9wUC20uJPJ/B3Xqb+ZjCPn/yxFF3QdQEmpdvg=", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.48.0/rules_go-v0.48.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.48.0/rules_go-v0.48.0.zip", | ||
], | ||
) | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
integrity = "sha256-12v3pg/YsFBEQJDfooN6Tq+YKeEWVhjuNdzspcvfWNU=", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") | ||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
|
||
contrib_rules_jvm_gazelle_deps() | ||
|
||
load("@contrib_rules_jvm//:gazelle_setup.bzl", "contrib_rules_jvm_gazelle_setup") | ||
|
||
contrib_rules_jvm_gazelle_setup() | ||
|
||
go_rules_dependencies() | ||
|
||
go_register_toolchains(version = "1.23.2") | ||
|
||
gazelle_dependencies() |
Empty file.
Oops, something went wrong.