Files
Nelson Li db1e28de76 SOONG_API: Add Java client library and example
This CL implements the Java client library for the Soong API gRPC
service, as proposed in go/snapi-local-library.

The `soong_api_client_java_lib` encapsulates the complexity of:
1. Build Management: Defaults to rebuilding artifacts when a 'lunch'
   environment is detected to ensure data freshness. Falls back to
   existing artifacts if no build environment is present.
2. Custom DB Path: Allows users to provide a custom database path,
   which bypasses all build automation and environment checks.
3. Server Lifecycle: Manages `soong_api_server` using a token-based
   handshake for reliable port discovery and ensures clean shutdown
   via the AutoCloseable interface.
4. gRPC Connection: Automatically establishes and manages the channel
   to the local server instance.

The `soong_api_client_java_example` tool is included to demonstrate
usage, including module and install path queries.

Bug: 471312107
Test: m soong_api_client_java_example && \
      ./out/host/linux-x86/bin/soong_api_client_java_example
Change-Id: I39955a9cc45b3907f3fa587617b083e5aa3a0408
2026-01-16 01:51:09 +00:00

74 lines
2.0 KiB
Plaintext

// Copyright (C) 2026 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package {
default_applicable_licenses: ["Android-Apache-2.0"],
default_team: "trendy_team_build",
}
// Soong API Python Client Library
// Python Library
python_library_host {
name: "soong_api_client_python_lib",
srcs: [
"soong_api_client.py",
":soong_api_python_protoc_gen", // Include generated files
],
libs: [
"libprotobuf-python",
"py-grpcio",
],
}
// Soong API Python Client Example
python_binary_host {
name: "soong_api_client_python_example",
srcs: [
"soong_api_client_example.py",
],
main: "soong_api_client_example.py",
libs: [
"soong_api_client_python_lib",
"libprotobuf-python", // For json_format
],
}
// Soong API Java Client Library
java_library_host {
name: "soong_api_client_java_lib",
srcs: [
"src/main/java/com/android/soong/api/client/SoongApiClient.java",
],
static_libs: [
"soong_api_grpc_proto",
"grpc-java",
"grpc-java-netty-shaded",
"guava",
"jsr305", // For Nullable annotations
],
}
// Soong API Java Client Example
java_binary_host {
name: "soong_api_client_java_example",
srcs: [
"src/main/java/com/android/soong/api/client/SoongApiClientExample.java",
],
main_class: "com.android.soong.api.client.SoongApiClientExample",
static_libs: [
"soong_api_client_java_lib",
"libprotobuf-java-util-full", // For JsonFormat printer
],
}