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

Allow setting :scope via maven coords too #646

Merged
merged 7 commits into from
Jan 19, 2022

Conversation

dmivankov
Copy link
Contributor

Default scope is "compile" but it could be useful to depend on other scopes like "tests"

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Looks great once the comment is addressed. Thank you for the PR!

private/rules/pom_file.bzl Outdated Show resolved Hide resolved
@dmivankov dmivankov requested a review from shs96c January 5, 2022 16:20
Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

The only major thing is that attempting to build a pom file will now fail because of the type/type_ problem.

" <groupId>%s</groupId>\n" % unpacked.groupId,
" <artifactId>%s</artifactId>\n" % unpacked.artifactId,
" <version>%s</version>\n" % unpacked.version,
(" <type>%s</type>\n" % unpacked.type) if unpacked.type and unpacked.type != "jar" else "",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this work? I would expect: "<type>%s</type>\n" % unpacked.type if unpacked.type and unpacked.type != "jar" else "" That is, the closing bracket seems like it's in the wrong place (and it's confusing even if it's the right place :) )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, the struct has a type_ field, and you're using type here, so the code won't work. I'm not sure how this managed to sneak past the CI, but that's my problem to solve :)

</dependency>"""
def _format_dep(unpacked):
return "".join([
" <dependency>\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation goes wrong here. Have you run buildifier -r -lint fix . on this PR? If not, could you please do so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

running on whole repo creates big diff, so applying it only to this file for now

private/rules/pom_file.bzl Show resolved Hide resolved
</dependency>"""
def _unpack_coordinates(coords):
"""Takes a maven coordinate and unpacks it into a struct with fields
groupId, artifactId, version, type_, scope
Copy link
Collaborator

Choose a reason for hiding this comment

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

type_? A quick exploration suggests you'll be fine with type on it's own:

foo = struct(type = "bar")
print("Foo is: %s and dir is %s" % (foo, dir(foo)))

prints Foo is: struct(type = "bar") and dir is ["to_json", "to_proto", "type"]

Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to mark those fields as code (eg. groupId rather than just groupId) so it renders more legibly in the generated docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used type_ just because vim syntax highlighted it as a keyword, but maybe it works, let's try

private/rules/pom_file.bzl Show resolved Hide resolved
@dmivankov
Copy link
Contributor Author

trying to fix test failures with #657

@dmivankov dmivankov requested a review from shs96c January 18, 2022 08:10
Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Looks good, but this fails:

cd examples/java-export
bazel build //:example-export-pom

The output is:

ERROR: /src/rules_jvm_external/examples/java-export/BUILD:10:12: in pom_file rule //:example-export-pom: 
Traceback (most recent call last):
	File "/tmp/_bazel_shs/76cdb8bc63b14507f5041d8c30cccb52/external/rules_jvm_external/private/rules/pom_file.bzl", line 63, column 32, in _pom_file_impl
		ctx.actions.expand_template(
Error in expand_template: got dict<string, NoneType> for 'substitutions', want dict<string, string>
ERROR: Analysis of target '//:example-export-pom' failed; build aborted: Analysis of target '//:example-export-pom' failed

Apparently, our test suite coverage isn't great for building poms, and I apologise for that. I think that if bazel build //... passes in examples/java-export we're good to go.

@dmivankov
Copy link
Contributor Author

dmivankov commented Jan 18, 2022

Thank you for testing, will try to make an update, sometime I rely on tests too much 😅

@shs96c shs96c merged commit ab3090a into bazel-contrib:master Jan 19, 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.

2 participants