-
Notifications
You must be signed in to change notification settings - Fork 5
java_library: output JNI headers generated by javac
#13
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -4,7 +4,10 @@ def java_library(name:str, srcs:list=None, src_dir:str=None, resources:list=[], | |
| deps:list=[], modular:bool=False, exported_deps:list=None, visibility:list=None, | ||
| test_only:bool&testonly=False, javac_flags:list&javacopts=None, labels:list=[], | ||
| toolchain:str=CONFIG.JAVA_TOOLCHAIN): | ||
| """Compiles Java source to a .jar which can be collected by other rules. | ||
| """Compiles Java source to a .jar which can be collected by other rules. If the source makes use of | ||
| the Java Native Interface (JNI), and the target is included as a dependency of a C/C++ rule, this | ||
| rule instead outputs the JNI headers generated by the Java compiler to allow the source of the | ||
| native-code component to be built. | ||
|
|
||
| Args: | ||
| name (str): Name of the rule | ||
|
|
@@ -87,6 +90,33 @@ def java_library(name:str, srcs:list=None, src_dir:str=None, resources:list=[], | |
|
|
||
| src_dir_label = [] if srcs else ['src_dir:'+src_dir] | ||
|
|
||
| def _jni_header_outputs(name, output): | ||
| for hdr_path in output: | ||
| if hdr_path != "": | ||
| add_out(name, hdr_path) | ||
| add_label(name, "cc:inc:" + join_path(package_name(), dirname(hdr_path))) | ||
|
|
||
| jni_hdrs = build_rule( | ||
| name = name, | ||
| tag = "jni_hdrs", | ||
| srcs = { | ||
| "WORKER": srcs or [src_dir], | ||
| }, | ||
| cmd = " && ".join([ | ||
| "mkdir -p _jni", | ||
| f"{javac_cmd} -h _jni >/dev/null 2>&1", | ||
|
Contributor
Author
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. Silencing the output of |
||
| "find _jni -type f -name '*.h' | sort", | ||
| ]), | ||
| post_build = _jni_header_outputs, | ||
| labels = labels, | ||
| tools = { | ||
| "javac": [javac], | ||
| }, | ||
| test_only = test_only, | ||
| visibility = visibility, | ||
| deps = deps + (exported_deps or []), | ||
| ) | ||
|
|
||
| return build_rule( | ||
| name=name, | ||
| srcs={ | ||
|
|
@@ -102,6 +132,9 @@ def java_library(name:str, srcs:list=None, src_dir:str=None, resources:list=[], | |
| cmd=cmd, | ||
| building_description="Compiling...", | ||
| requires=['java'], | ||
| provides={ | ||
| "cc_hdrs": jni_hdrs, | ||
| }, | ||
| labels = labels + ['rule:java_test_library' if test_only else 'rule:java_library'] + src_dir_label, | ||
| test_only=test_only, | ||
| tools={ | ||
|
|
||
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 just to guard against the command outputting
\nwhen no headers are generated.