-
Notifications
You must be signed in to change notification settings - Fork 281
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
Single-jar pack_sources should conform to Bazel behavior #1378
Changes from 6 commits
733d4b8
aaae8a0
902a7a6
3652ec4
a70229f
846eef4
f83d7e2
a9c8790
2f5d9fc
151cf8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("@bazel_skylib//lib:new_sets.bzl", "sets") | ||
|
||
# Tests and documents the functionality of phase_compile.bzl's _pack_source_jar | ||
|
||
def _single_source_jar_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
|
||
target_under_test = analysistest.target_under_test(env) | ||
|
||
srcjar_names = sets.make( | ||
[j.basename for j in target_under_test[JavaInfo].source_jars], | ||
) | ||
|
||
# In line with Bazel's java_common.pack_sources, | ||
# We return the initial .srcjar file since there are no source files | ||
# Not sure where the second -src.jar comes from, maybe due to java rules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check if adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does! Thanks for the test case. I added one more to test multiple source jars, adding |
||
expected_names = sets.make([ | ||
"SourceJar1.srcjar", | ||
"source_jar_java-src.jar", | ||
]) | ||
|
||
asserts.set_equals(env, expected = expected_names, actual = srcjar_names) | ||
|
||
return analysistest.end(env) | ||
|
||
single_source_jar_test = analysistest.make(_single_source_jar_test_impl) | ||
|
||
def _multi_source_jar_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
|
||
target_under_test = analysistest.target_under_test(env) | ||
|
||
srcjar_names = sets.make( | ||
[j.basename for j in target_under_test[JavaInfo].source_jars], | ||
) | ||
|
||
expected_names = sets.make([ | ||
"multi_source_jar-src.jar", | ||
"multi_source_jar_java-src.jar", | ||
]) | ||
|
||
asserts.set_equals(env, expected = expected_names, actual = srcjar_names) | ||
|
||
return analysistest.end(env) | ||
|
||
multi_source_jar_test = analysistest.make(_multi_source_jar_test_impl) | ||
|
||
def _source_jar_with_srcs_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
|
||
target_under_test = analysistest.target_under_test(env) | ||
|
||
srcjar_names = sets.make( | ||
[j.basename for j in target_under_test[JavaInfo].source_jars], | ||
) | ||
|
||
# Since we have source files, we don't output a .srcjar | ||
# Instead, we just return the bundle | ||
expected_names = sets.make([ | ||
"use_source_jar-src.jar", | ||
]) | ||
|
||
asserts.set_equals(env, expected = expected_names, actual = srcjar_names) | ||
|
||
return analysistest.end(env) | ||
|
||
source_jar_with_srcs_test = analysistest.make(_source_jar_with_srcs_test_impl) | ||
|
||
def pack_sources_test_suite(name): | ||
single_source_jar_test( | ||
name = "single_source_jar_test", | ||
target_under_test = ":source_jar", | ||
) | ||
multi_source_jar_test( | ||
name = "multi_source_jar_test", | ||
target_under_test = ":multi_source_jar", | ||
) | ||
source_jar_with_srcs_test( | ||
name = "source_jar_with_srcs_test", | ||
target_under_test = ":use_source_jar", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":single_source_jar_test", | ||
":multi_source_jar_test", | ||
":source_jar_with_srcs_test", | ||
], | ||
) |
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.
Not sure if this would make code look better and probably it's a matter of taste but
without_ext
could be calculated asoutput_jar.basename[:-len(output_jar.extension) - 1] if output_jar.extension else output_jar.basename
Please feel free to ignore this comment.
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.
Good suggestion! I ended up with (ironically) a longer implementation. Your suggestion made me realize that we shouldn't expect that output_jar has an extension. Personally, I think that the ternary
if
is too long for one line, so a mutatingif
is fine.