-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #2643: Added BUILD.bazel in accessibility package #2668
Fix #2643: Added BUILD.bazel in accessibility package #2668
Conversation
@fsharpasharp I'm facing this error when I build the app
How can I solve this |
Right now I can't seem to build the project with Bazel, but I'll take a look as soon as I can build the project again. |
Sure, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FareesHussain! Left some thoughts.
visibility = ["//visibility:public"], | ||
) | ||
|
||
kt_android_library( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be marked as test only (e.g. with a testonly = True
line) so that it can't be inadvertently included in production builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
":android_accessibility_manager", | ||
":custom_accessibility_manager", | ||
artifact("com.google.dagger:dagger:2.27"), | ||
artifact("javax.inject:javax.inject:1"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here & below for the inject lines (see my comment in your other PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this after #2648 (comment) is resolved
) | ||
|
||
kt_android_library( | ||
name = "custom_accessibility_manager", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the API, and the other two are the implementations for this package. I think we should instead set this up as:
kt_android_library(
name = "accessibility",
visibility = ["//visibility:public"],
srcs = ["CustomAccessibilityManager.kt"],
deps = [":impl"],
)
kt_android_library(
name = "impl",
srcs = ["AndroidAccessibilityModule.kt","AccessibilityModule.kt"],
deps = [...],
)
kt_android_library(
name = "testing", # Could also be called 'fake_accessibility_manager'
visibility = ["//visibility:public"],
srcs = ["FakeAccessibilityManager.kt"],
deps = [...],
)
This is the convention we should be using broadly since it clearly designates the public API as the package-level library, and properly privatizes the implementation & separates out the testing library.
For packages that have multiple public APIs (e.g. general utility packages with a bunch of separate things), in that case we would not have a package-level library and each group of utilities would be in their own packages.
@fsharpasharp FYI since we discussed this today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, instead of accessibility
I've used acc
as it was getting refactored in app/BUILD.bazel. Will change it back after conformation.
utility/BUILD.bazel
Outdated
"//utility/src/main/java/org/oppia/android/util/accessibility:accessibility_module", | ||
"//utility/src/main/java/org/oppia/android/util/accessibility:android_accessibility_manager", | ||
"//utility/src/main/java/org/oppia/android/util/accessibility:custom_accessibility_manager", | ||
"//utility/src/main/java/org/oppia/android/util/accessibility:fake_accessibility_manager", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here & below: this one should only be included in test deps, not production classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@BenHenning PTAL, The error mentioned here #2668 (comment) is not resolved after adding the mentioned targets in app/BUILD.bazel. |
@FareesHussain. First, the accessibility package should depend on impl (impl itself should be private). Naming it 'accessibility' shouldn't change the error. Can you also please share the latest error after making the 2 changes above (e.g. updating impl to be private & changing the accessibility library name)? Please also push those changes so that I can cross-reference the error with your PR. |
Right now I have some problem with Bazel. |
… accessibility-build-bazel � Conflicts: � app/BUILD.bazel � utility/BUILD.bazel
@BenHenning I made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @FareesHussain! Left some thoughts. Not de-assigning myself since I need to think further about how to lay out these files generally elsewhere in the codebase.
app/BUILD.bazel
Outdated
@@ -683,6 +685,8 @@ TEST_DEPS = [ | |||
"//third_party:org_robolectric_annotations", | |||
"//third_party:robolectric_android-all", | |||
"//utility", | |||
"//utility/src/main/java/org/oppia/android/util/accessibility:accessibility", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"//utility/src/main/java/org/oppia/android/util/accessibility:accessibility", | |
"//utility/src/main/java/org/oppia/android/util/accessibility", |
Should be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,32 @@ | |||
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a top-level documentation comment to this file explaining what sorts of files belong to it (e.g. General purposes utilities pertaining to the Android accessibility manager.
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
], | ||
deps = [ | ||
":accessibility", | ||
artifact("com.google.dagger:dagger:2.27"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in chat, prefer using the third party wrappers instead of artifact
since they offer a bunch of benefits (see #2663 for specifics).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
) | ||
|
||
kt_android_library( | ||
name = "impl", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I think I missed the circular dependency that arises here when we try to make accessiblity
depend on impl
. There are a couple of different paths that we can take here, and I need to spend a bit more time thinking about this before proposing a specific solution. @fsharpasharp do you have a specific pattern that you think might work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about introducing a third library that exports the interface and impl? None of the existing libraries will depend on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might unfortunately undermine the value of keeping impl separate (since it then exposes the public classes in impl which should stay private as part of impl). I think we might need to use a similar pattern where we export the modules of the package & have those depend on impl, but I'm not super keen on this pattern since it has its own drawbacks (such as requiring dependencies on all modules in central places like the android_binary or test targets).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's try the module + impl approach and see how that looks. @FareesHussain I suggest changing this to be:
kt_android_library(
name = "accessibility",
visibility = ["//visibility:public"],
... (source is interface only)
)
kt_android_library(
name = "impl",
... (private visibility, source is accessibility module + prod implementation)
)
kt_android_library(
name = "prod_module",
visibility = ["//:oppia_binary_visibility"],
... (source is new prod module -- see below; depends on :impl)
)
kt_android_library(
name = "testing",
visibility = ["//:oppia_testing_visibility"],
testonly = True,
... (source is fake)
)
kt_android_library(
name = "test_module",
visibility = ["//:oppia_testing_visibility"],
testonly = True,
... (source is new test module -- see below; depends on :testing)
)
You may also notice that there are both a test module & prod module. That's because I'm also suggesting that you make a functional change:
- Rename AccessibilityModule to be AccessibilityManagerModule (to clarify it's just for providing the manager)
- Introduce an AccessibilityProdModule that provides a binding of CustomAccessibilityManager to AndroidAccessibilityManager
- Introduce an AccessibilityTestModule that provides a binding of CustomAccessibilityManager to FakeAccessibilityManager
- Update all injections of AndroidAccessibilityModule to instead inject CustomAccessibilityManager so that it properly swaps out the accessibility version (you may be able to simplify some test bindings that are probably replacing the binding with the test version already)
Note also that the above requires introducing two new visibility groups: oppia_binary_visibility & oppia_testing_visibility to simplify visibility management. The former should work as-is, but the latter may not work until we split up the tests (in which case we should introduce the visibility such that it applies to all subpackages, and is later restricted to tests).
The nice thing about this package is that it actually includes all of the pieces we want to demonstrate in the pattern:
- A public API
- A production implementation that is kept private
- A production module that should use the private implementation & be incorporated in the top-level binary (or in tests that want to use the production module)
- A testing module that can optionally be used in tests
- A fake testing library
If you're unsure of all this, let me know. I'll introduce a new PR that replaces this one in that case since it may be easier for me to demonstrate the new pattern more explicitly that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fsharpasharp as well--what do you think of the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BenHenning I'll follow up with your PR regarding this pattern.
utility/BUILD.bazel
Outdated
@@ -45,6 +48,9 @@ TEST_DEPS = [ | |||
"//third_party:org_jetbrains_kotlin_kotlin-test-junit", | |||
"//third_party:org_mockito_mockito-core", | |||
"//third_party:robolectric_android-all", | |||
"//utility/src/main/java/org/oppia/android/util/accessibility:accessibility", | |||
"//utility/src/main/java/org/oppia/android/util/accessibility:impl", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl
should be private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
… accessibility-build-bazel
Thanks @FareesHussain. Will keep this assigned to me until I can duplicate it later in the week with the pattern described in #2668 (comment). Shouldn't take me long, so I might be able to get to it between meetings tomorrow or Wed. |
This has been replaced #2775 so closing this PR now. Thanks for starting it @FareesHussain, it was a really helpful reference when creating #2775. |
Explanation
Fixes #2643
Checklist