Skip to content

Commit

Permalink
Fix the workspace_defs.bzl configuration and add a CI test.
Browse files Browse the repository at this point in the history
There were a number of things broken in the workspace_defs.bzl configuration due to recent changes in our Hilt processors. This CL fixes those changes and also adds a task to our CI to test the example project that uses the workspace_defs.bzl.

One thing to note is that there is still version skew when testing the example project. We're able to test the local workspace_defs.bzl, but we can only test that configuration against the HEAD-SNAPSHOT artifacts. Ideally, we would test against the LOCAL-SNAPSHOTS, but maven_install doesn't currently allow local repositories (bazel-contrib/rules_jvm_external#305).

Closes google#2514

RELNOTES=N/A
PiperOrigin-RevId: 396881609
  • Loading branch information
bcorso authored and Dagger Team committed Sep 15, 2021
1 parent 4b2c193 commit ca9b2ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jobs:
- name: 'Run Bazel tests'
run: bazel test --test_output=errors //... --keep_going
shell: bash
- name: 'Run Bazel examples'
run: cd examples/bazel; bazel test --test_output=errors //...
shell: bash
- name: 'Install local snapshot'
run: ./util/install-local-snapshot.sh
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion examples/bazel/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
# Load Dagger repository
########################

# TODO(bcorso): Replace with `http_archive` pointing to tagged released.
# In a real project, this repository would use `http_archive` to link to a
# tagged, released version of the Dagger, but we use `local_repository` so that
# CI testing can test local changes to workspace_defs.bzl.
local_repository(
name = "dagger",
path = "../../",
Expand Down
62 changes: 39 additions & 23 deletions workspace_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,43 @@

load("//:build_defs.bzl", "POM_VERSION")

_DAGGER_VERSION = POM_VERSION
_HILT_VERSION = POM_VERSION
# For tagged releases, the POM_VERSION will be set to the version of the release.
# However, for CI testing the POM_VERSION will not be set, so we use the
# HEAD-SNAPSHOT artifacts instead.
# TODO(bcorso): Ideally, we would use the LOCAL-SNAPSHOT artifacts for CI testing;
# however, maven_install doesn't work with local maven repositories
# (See issue: https://github.com/bazelbuild/rules_jvm_external/issues/305).
_VERSION = POM_VERSION if POM_VERSION != "${project.version}" else "HEAD-SNAPSHOT"

DAGGER_ARTIFACTS = [
"com.google.dagger:dagger:" + _DAGGER_VERSION,
"com.google.dagger:dagger-compiler:" + _DAGGER_VERSION,
"com.google.dagger:dagger-producers:" + _DAGGER_VERSION,
"com.google.dagger:dagger-spi:" + _DAGGER_VERSION,
"com.google.dagger:dagger:" + _VERSION,
"com.google.dagger:dagger-compiler:" + _VERSION,
"com.google.dagger:dagger-producers:" + _VERSION,
"com.google.dagger:dagger-spi:" + _VERSION,
]

DAGGER_ANDROID_ARTIFACTS = [
"com.google.dagger:dagger-android-processor:" + _DAGGER_VERSION,
"com.google.dagger:dagger-android-support:" + _DAGGER_VERSION,
"com.google.dagger:dagger-android:" + _DAGGER_VERSION,
"com.google.dagger:dagger-android-processor:" + _VERSION,
"com.google.dagger:dagger-android-support:" + _VERSION,
"com.google.dagger:dagger-android:" + _VERSION,
]

HILT_ANDROID_ARTIFACTS = [
"androidx.test:core:1.1.0", # Export for ApplicationProvider
"javax.annotation:jsr250-api:1.0", # Export for @Generated
"androidx.annotation:annotation:1.1.0", # Export for @CallSuper/@Nullable
"com.google.dagger:dagger:" + _DAGGER_VERSION,
"com.google.dagger:dagger-compiler:" + _DAGGER_VERSION,
"com.google.dagger:hilt-android:" + _HILT_VERSION,
"com.google.dagger:hilt-android-testing:" + _HILT_VERSION,
"com.google.dagger:hilt-android-compiler:" + _HILT_VERSION,
"com.google.dagger:dagger:" + _VERSION,
"com.google.dagger:dagger-compiler:" + _VERSION,
"com.google.dagger:hilt-android:" + _VERSION,
"com.google.dagger:hilt-android-testing:" + _VERSION,
"com.google.dagger:hilt-android-compiler:" + _VERSION,
"com.google.dagger:hilt-core:" + _VERSION,
]

DAGGER_REPOSITORIES = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
"https://oss.sonatype.org/content/repositories/snapshots",
]

DAGGER_ANDROID_REPOSITORIES = DAGGER_REPOSITORIES
Expand Down Expand Up @@ -162,9 +169,11 @@ def hilt_android_rules(repo_name = "@maven"):
":hilt_aggregated_deps_processor",
":hilt_alias_of_processor",
":hilt_define_component_processor",
":hilt_early_entry_points_processor",
":hilt_generates_root_input_processor",
":hilt_originating_element_processor",
":hilt_root_processor",
":hilt_component_tree_deps_processor",
":hilt_view_model_processor",
],
visibility = ["//visibility:public"],
Expand All @@ -173,6 +182,7 @@ def hilt_android_rules(repo_name = "@maven"):
"%s//:javax_inject_javax_inject" % repo_name, # For @Inject
"%s//:androidx_annotation_annotation" % repo_name, # For @CallSuper
"%s//:com_google_dagger_hilt_android" % repo_name,
"%s//:com_google_dagger_hilt_core" % repo_name,
"%s//:javax_annotation_jsr250_api" % repo_name, # For @Generated
],
)
Expand Down Expand Up @@ -216,6 +226,13 @@ def hilt_android_rules(repo_name = "@maven"):
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_early_entry_points_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.earlyentrypoint.EarlyEntryPointProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_generates_root_input_processor",
generates_api = 1,
Expand All @@ -237,6 +254,13 @@ def hilt_android_rules(repo_name = "@maven"):
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_component_tree_deps_processor",
generates_api = 1,
processor_class = "dagger.hilt.processor.internal.root.ComponentTreeDepsProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_view_model_processor",
generates_api = 1,
Expand All @@ -252,7 +276,6 @@ def hilt_android_rules(repo_name = "@maven"):
exported_plugins = [
":hilt_bind_value_processor",
":hilt_custom_test_application_processor",
":hilt_testroot_processor",
":hilt_uninstall_modules_processor",
],
visibility = ["//visibility:public"],
Expand All @@ -277,16 +300,9 @@ def hilt_android_rules(repo_name = "@maven"):
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_testroot_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.testroot.TestRootProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

native.java_plugin(
name = "hilt_uninstall_modules_processor",
generates_api = 1,
processor_class = "dagger.hilt.android.processor.internal.uninstallmodules.UninstallModulesProcessor",
processor_class = "dagger.hilt.processor.internal.uninstallmodules.UninstallModulesProcessor",
deps = ["%s//:com_google_dagger_hilt_android_compiler" % repo_name],
)

0 comments on commit ca9b2ff

Please sign in to comment.