Skip to content
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

[SNAP FORK] fix aar_import rule #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mauriciogg
Copy link
Contributor

@mauriciogg mauriciogg commented Oct 24, 2022

I think this should fix #39 as well

@mauriciogg
Copy link
Contributor Author

@timpeut @ahumesky

@ted-xie
Copy link
Contributor

ted-xie commented Nov 30, 2022

Hi Mauricio,

Can you elaborate on why ACLs don't work with external dependencies (i.e. what failure are you seeing)?

dont propagate r javas as deps

I'll have to check with internal rule maintainers about how we can handle this. Currently this is causing an internal test to fail, so there might be some projects that rely on this behavior.

@@ -344,7 +344,7 @@ def _process_jars(
),
source_jar = source_jar,
neverlink = False,
deps = r_java_info + java_infos, # TODO(djwhang): Exports are not deps.
deps = java_infos, # TODO(djwhang): Exports are not deps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line specifically is causing the internal test to fail. I will follow up with internal teams to chase down the root cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted. the java_infos being added as deps were exposing r classes as runtime deps which is not correct and was causing issues in our repo. Instead I set r java infos as neverlink.

@mauriciogg mauriciogg force-pushed the pre-alpha-fix-aar branch 4 times, most recently from 0fedda7 to 86ed4c9 Compare January 17, 2023 22:53
@mauriciogg
Copy link
Contributor Author

mauriciogg commented Jan 17, 2023

Hi Mauricio,

Can you elaborate on why ACLs don't work with external dependencies (i.e. what failure are you seeing)?

dont propagate r javas as deps

I'll have to check with internal rule maintainers about how we can handle this. Currently this is causing an internal test to fail, so there might be some projects that rely on this behavior.

The acl code does not support @foo stuff. It will return false for all of those (almost all aars are used through mvn).

filed issue here #68

@mauriciogg mauriciogg force-pushed the pre-alpha-fix-aar branch 2 times, most recently from d855b7c to f2285a0 Compare January 17, 2023 23:20
@mauriciogg mauriciogg requested a review from ted-xie January 17, 2023 23:21
- acls dont work with external dependencies (i.e @foo//)

- Propagate StarlarkAndroidResourcesInfo otherwise starlark rules
  wont be able to see those resources.

- Stop adding library R classes as runtime dependencies:
  This behavior is not correct- the only authoritive r class should be
  the final merged R class. Adding library R classes as runtime
  dependencies creates resources erasures in android_local_test targets
  where each individual R class is added to the test classpath and
  incorrect Ids are used to query the resource table.

- Merge aar library java_info with the resource java_info
  Libraries that directly depend on an AAR can depend as well on the AAR resource class
  so it is not enough to simply return the resource info as a dependency.
  see AarImport.java
  https://github.com/bazelbuild/bazel/blob/e0a9081f/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java#L166
Comment on lines +362 to +363
combined_java_info = java_common.merge([java_info] + r_java_info)
providers.append(combined_java_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently breaking some assumptions in internal tests. I will try to follow up on whether we should change the assumptions or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this some more: if you replace line 349's _acls.in_aar_import_exports_r_java(str(ctx.label)) with True and undo your change from lines 354-364, it makes internal tests pass again. Does that behavior work for your usecase? Merging the r_java_info with the java_info causes internal assumptions about aar_import providers to break (i.e. internally we are expecting only one srcjar to come out of aar_import, whereas your PR seems to generate two), which makes accepting this PR much more difficult.

Comment on lines +362 to +363
combined_java_info = java_common.merge([java_info] + r_java_info)
providers.append(combined_java_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this some more: if you replace line 349's _acls.in_aar_import_exports_r_java(str(ctx.label)) with True and undo your change from lines 354-364, it makes internal tests pass again. Does that behavior work for your usecase? Merging the r_java_info with the java_info causes internal assumptions about aar_import providers to break (i.e. internally we are expecting only one srcjar to come out of aar_import, whereas your PR seems to generate two), which makes accepting this PR much more difficult.

@ted-xie ted-xie changed the base branch from pre-alpha to main June 9, 2023 15:06
@katre
Copy link
Member

katre commented Jun 9, 2023

This should fix #77 if I understand it properly. Thanks!

# JavaInfo is added as a runtime dependency to the JavaInfo. Stop
# adding the R.jar as a runtime dependency.
r_java = None
if resource_files:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why if resource_files shouldn't be if resources_ctx[_R_JAVA], which was the past behavior on line 1696?

ted-xie pushed a commit to ted-xie/rules_android that referenced this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pre-release] Statically linking fails with custom styles that depend on resources in an aar
3 participants