Skip to content

Commit

Permalink
Make output class directory unique for java (#26893)
Browse files Browse the repository at this point in the history
* Make output class directory unique for java

* Restyled by gn

* Undo unintentional change

* Do not attempt to compile pure java variant for android (keep only linux and mac generally)

* Fix required jar: tlv now needs copy as the tlv content is not part of controller anymore

* Fix unit test

* Fix typo in jar naming

* Fix javatest classpath now that libraries are properly separated

* Add more lib paths as needed for the controller run

* Restyle

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Jan 19, 2024
1 parent 20a8b45 commit b4ca3ab
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build/chip/java/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ java_path = getenv("JAVA_PATH")
declare_args() {
java_matter_controller_dependent_paths = []
build_java_matter_controller = false
if (java_path != "") {
if (java_path != "" && current_os != "android") {
java_matter_controller_dependent_paths += [ "${java_path}/include/" ]

if (current_os == "mac") {
Expand Down
12 changes: 8 additions & 4 deletions build/chip/java/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ template("java_library") {

# Compiles the given files into a directory and generates a 'class list'
_javac_target_name = target_name + "__javac"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/classes"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/" +
target_name + "/classes"
_class_list_file = "$target_gen_dir/$target_name.classlist"
action(_javac_target_name) {
sources = _java_files
Expand Down Expand Up @@ -284,7 +285,8 @@ template("java_binary") {

# Compiles the given files into a directory and generates a 'class list'
_javac_target_name = target_name + "__javac"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/classes"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/" +
target_name + "/classes"
_class_list_file = "$target_gen_dir/$target_name.classlist"
action(_javac_target_name) {
sources = _java_files
Expand Down Expand Up @@ -441,7 +443,8 @@ template("kotlin_library") {

# Compiles the given files into a directory and generates a 'class list'
_kotlinc_target_name = target_name + "__kotlinc"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/classes"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/" +
target_name + "/classes"
_class_list_file = "$target_gen_dir/$target_name.classlist"
action(_kotlinc_target_name) {
sources = _kotlin_files
Expand Down Expand Up @@ -598,7 +601,8 @@ template("kotlin_binary") {

# Compiles the given files into a directory and generates a 'class list'
_kotlinc_target_name = target_name + "__kotlinc"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/classes"
_class_dir = rebase_path(target_out_dir, root_build_dir) + "/" +
target_name + "/classes"
_class_list_file = "$target_gen_dir/$target_name.classlist"
action(_kotlinc_target_name) {
sources = _kotlin_files
Expand Down
28 changes: 20 additions & 8 deletions scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def validate_build_environment(self):
if not (
os.path.isfile(sdk_manager) and os.access(sdk_manager, os.X_OK)
) and not (
os.path.isfile(new_sdk_manager) and os.access(new_sdk_manager, os.X_OK)
os.path.isfile(new_sdk_manager) and os.access(
new_sdk_manager, os.X_OK)
):
raise Exception(
"'%s' and '%s' is not executable by the current user"
Expand Down Expand Up @@ -227,6 +228,7 @@ def copyToSrcAndroid(self):
"CHIPController.jar": "src/controller/java/CHIPController.jar",
"SetupPayloadParser.jar": "src/setup_payload/java/SetupPayloadParser.jar",
"AndroidPlatform.jar": "src/platform/android/AndroidPlatform.jar",
"libCHIPTlv.jar": "src/controller/java/libCHIPTlv.jar",
}

for jarName in jars.keys():
Expand Down Expand Up @@ -267,7 +269,8 @@ def gradlewBuildSrcAndroid(self):
# App compilation
self._Execute(
[
"%s/examples/android/%s/gradlew" % (self.root, self.app.AppName()),
"%s/examples/android/%s/gradlew" % (
self.root, self.app.AppName()),
"-p",
"%s/examples/android/%s" % (self.root, self.app.AppName()),
"-PmatterBuildSrcDir=%s" % self.output_dir,
Expand Down Expand Up @@ -295,15 +298,17 @@ def gradlewBuildExampleAndroid(self):
"-PbuildDir=%s/%s" % (self.output_dir, module),
":%s:assembleDebug" % module,
],
title="Building Example %s, module %s" % (self.identifier, module),
title="Building Example %s, module %s" % (
self.identifier, module),
)
else:
self._Execute(
[
"%s/examples/%s/android/App/gradlew"
% (self.root, self.app.ExampleName()),
"-p",
"%s/examples/%s/android/App/" % (self.root, self.app.ExampleName()),
"%s/examples/%s/android/App/" % (self.root,
self.app.ExampleName()),
"-PmatterBuildSrcDir=%s" % self.output_dir,
"-PmatterSdkSourceBuild=false",
"-PbuildDir=%s" % self.output_dir,
Expand Down Expand Up @@ -359,7 +364,8 @@ def generate(self):

exampleName = self.app.ExampleName()
if exampleName is not None:
gn_gen += ["--root=%s/examples/%s/android/" % (self.root, exampleName)]
gn_gen += ["--root=%s/examples/%s/android/" %
(self.root, exampleName)]

if self.board.IsIde():
gn_gen += [
Expand All @@ -378,7 +384,8 @@ def generate(self):
)
if os.path.isfile(new_sdk_manager) and os.access(new_sdk_manager, os.X_OK):
self._Execute(
["bash", "-c", "yes | %s --licenses >/dev/null" % new_sdk_manager],
["bash", "-c", "yes | %s --licenses >/dev/null" %
new_sdk_manager],
title="Accepting NDK licenses @ cmdline-tools",
)
else:
Expand Down Expand Up @@ -414,7 +421,8 @@ def _build(self):
# TODO: Android Gradle with module and -PbuildDir= will caused issue, remove -PbuildDir=
self._Execute(
[
"%s/examples/android/%s/gradlew" % (self.root, self.app.AppName()),
"%s/examples/android/%s/gradlew" % (
self.root, self.app.AppName()),
"-p",
"%s/examples/android/%s" % (self.root, self.app.AppName()),
"-PmatterBuildSrcDir=%s" % self.output_dir,
Expand Down Expand Up @@ -470,7 +478,8 @@ def _build(self):
self.root, "examples/", self.app.ExampleName(), "android/App/app/libs"
)

libs = ["libSetupPayloadParser.so", "libc++_shared.so", "libTvApp.so"]
libs = ["libSetupPayloadParser.so",
"libc++_shared.so", "libTvApp.so"]

jars = {
"SetupPayloadParser.jar": "third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar",
Expand Down Expand Up @@ -520,6 +529,9 @@ def build_outputs(self):
"CHIPController.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/CHIPController.jar"
),
"libCHIPTlv.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/libCHIPTlv.jar"
),
"AndroidPlatform.jar": os.path.join(
self.output_dir, "lib", "src/platform/android/AndroidPlatform.jar"
),
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/testdata/dry_run_android-arm64-chip-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ cp {out}/android-arm64-chip-tool/lib/src/setup_payload/java/SetupPayloadParser.j

cp {out}/android-arm64-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/examples/android/CHIPTool/app/libs/AndroidPlatform.jar

cp {out}/android-arm64-chip-tool/lib/src/controller/java/libCHIPTlv.jar {root}/examples/android/CHIPTool/app/libs/libCHIPTlv.jar

# Building APP android-arm64-chip-tool
{root}/examples/android/CHIPTool/gradlew -p {root}/examples/android/CHIPTool -PmatterBuildSrcDir={out}/android-arm64-chip-tool -PmatterSdkSourceBuild=false -PbuildDir={out}/android-arm64-chip-tool assembleDebug
10 changes: 9 additions & 1 deletion scripts/tests/run_java_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args:
DumpProgramOutputToQueue(
log_cooking_threads, Fore.GREEN + "APP " + Style.RESET_ALL, app_process, log_queue)

command = ['java', '-Djava.library.path=' + tool_path + '/lib/jni', '-jar', tool_path + '/bin/java-matter-controller']
command = ['java',
f'-Djava.library.path={tool_path}/lib/jni',
'-cp',
':'.join([
f'{tool_path}/lib/*',
f'{tool_path}/lib/third_party/connectedhomeip/src/controller/java/*',
f'{tool_path}/bin/java-matter-controller',
]),
'com.matter.controller.MainKt']

if tool_cluster == 'pairing':
logging.info("Testing pairing cluster")
Expand Down

0 comments on commit b4ca3ab

Please sign in to comment.