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

Fix resource priority under name collision #1456

Merged

Conversation

tanishiking
Copy link
Contributor

@tanishiking tanishiking commented Dec 7, 2022

Description

This PR adds a failing test for #1455

@liucijus mentioned this issue occurs around here https://github.com/bazelbuild/rules_scala/blob/master/src/java/io/bazel/rulesscala/scalac/ScalacWorker.java#L65-L71 but re-ordering those lines doesn't work (I guess because re-ordering them control the priority of resource, resource_jars, and classpath_resources. It's not about resource name crash with things in JAR files).

My hunch is this is caused because the executable file has a "wrong" order of CLASSPATH.
For example, bazel-bin/test/src/main/scala/scalarules/test/duplicated_resources/child/child (generated by$ bazel build //test/src/main/scala/scalarules/test/duplicated_resources/child) contains the following CLASSPATH order.
(see the definition of the target "child" here )

CLASSPATH="
  ${RUNPATH}test/src/main/scala/scalarules/test/duplicated_resources/parent/parent.jar:
  ${RUNPATH}../io_bazel_rules_scala_scala_library/scala-library-2.12.14.jar:
  ...
  ${RUNPATH}../bazel_tools/tools/java/runfiles/librunfiles.jar
  ${RUNPATH}test/src/main/scala/scalarules/test/duplicated_resources/child/child.jar:
  "

parent.jar is first, and child.jar is last.

I think we can fix this by moving child.jar to the first of CLASSPATH is the fix. Actually, moving child.jar to the place before parent.jar fixed the issue.

What do you think?

Motivation

see #1455

@liucijus
Copy link
Collaborator

liucijus commented Dec 7, 2022

@tanishiking indeed you're right, this is runtime behavior. I would look for problem in collect jars phase.

@tanishiking
Copy link
Contributor Author

tanishiking commented Dec 7, 2022

It looks like the problem is around here in phase_compile

rjars = depset(out.full_jars, transitive = [rjars]),

where out.full_jars is child.jar and rjars contains the rest of dependent jars.
I confirmed depset(out.full_jars, transitive = [rjars], order = "preorder|topological") fixes the issue, but I'm not really sure which order should we use. https://bazel.build/rules/lib/depset
(while topological-sort sounds safer than pre-topological-sort).
Turned out topological doesn't guarantee left-to-right between deps in BUILD and CLASSPATH. As a result of this, the test_multi_service_manifest in test_misc.sh failed because the order of service_manifest.txt reversed.
https://github.com/tanishiking/rules_scala/blob/447dec21affb414c1be18e1735b357b2a6e6c671/test/example_jars/expected_service_manifest.txt#L3

To guarantee the left-to-right order, changed the order to preorder

tanishiking added a commit to tanishiking/rules_scala that referenced this pull request Dec 7, 2022
@tanishiking tanishiking force-pushed the fix-resource-name-crash-priority branch from 2992db9 to c7add52 Compare December 7, 2022 17:13
@tanishiking tanishiking changed the title Add failing test for resource name crash Fix resource priority under name collision Dec 7, 2022
Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

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

Thanks, @tanishiking!

With topological order, there's no left-to-right order guarantee
https://bazel.build/rules/lib/depset

As a result, `test/shell/test_misc`'s `test_multi_service_manifest`
fails because the order of `exepected_service_manifest.txt` reverses.
@tanishiking tanishiking force-pushed the fix-resource-name-crash-priority branch from 447dec2 to ae85cde Compare December 8, 2022 09:20
@tanishiking
Copy link
Contributor Author

Copy link
Collaborator

@simuons simuons left a comment

Choose a reason for hiding this comment

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

Thanks @tanishiking

@simuons simuons merged commit 15f2461 into bazelbuild:master Dec 12, 2022
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.

3 participants