aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinh Tran <vinhdaitran@google.com>2022-12-02 15:34:07 -0500
committerVinh Tran <vinhdaitran@google.com>2022-12-02 18:00:59 -0500
commitd2e18aa0fb51fa4d18f233faf3420026f88da6e2 (patch)
tree16ef5ec25910b989f911b04c3baea068f1b3af79
parentffc0e7c79154e4481a1c0a1681804bdc7c27e1db (diff)
downloadbazel-d2e18aa0fb51fa4d18f233faf3420026f88da6e2.tar.gz
Support next_version in aidl_interface macro
aidl_interface in Soong has the concept of next version which depends on the unstable prop and the versions specified in versions and versions_with_info props. This commit adds support for next version so that upstream modules can import the +1 version of the aidl interface. When unstable is set in an aidl_interface, its next_version is "". Bug: 261139208 Test: b build //frameworks/av/apex:com.android.media.swcodec --config=android Change-Id: I6a08f632e4c16a7cd95e70c1d3dbc6126422683b
-rw-r--r--rules/aidl/interface.bzl70
-rw-r--r--rules/aidl/interface_test.bzl42
-rw-r--r--rules/test_common/rules.bzl9
3 files changed, 104 insertions, 17 deletions
diff --git a/rules/aidl/interface.bzl b/rules/aidl/interface.bzl
index 87d36d55..9a58291e 100644
--- a/rules/aidl/interface.bzl
+++ b/rules/aidl/interface.bzl
@@ -49,6 +49,22 @@ def _create_latest_version_aliases(name, last_version_name, backend_configs, **k
**kwargs
)
+def versioned_name(name, version):
+ if version == "":
+ return name
+
+ return name + "-V" + version
+
+# https://cs.android.com/android/platform/superproject/+/master:system/tools/aidl/build/aidl_interface.go;l=782-799;drc=5390d9a42f5e4f99ccb3a84068f554d948cb62b9
+def _next_version(versions, unstable):
+ if unstable:
+ return ""
+
+ if versions == None or len(versions) == 0:
+ return "1"
+
+ return str(int(versions[-1]) + 1)
+
def is_config_enabled(config):
return config != None and "enabled" in config and config["enabled"] == True
@@ -66,6 +82,8 @@ def aidl_interface(
# versions prop in favor of versions_with_info prop
versions = None,
versions_with_info = None,
+ unstable = False,
+ # TODO(b/261208761): Support frozen attr
**kwargs):
"""aidl_interface creates a versioned aidl_libraries and language-specific *_aidl_libraries
@@ -94,6 +112,10 @@ def aidl_interface(
if (versions == None and versions_with_info == None and srcs == None):
fail("must specify at least versions, versions_with_info, or srcs")
+ # https://cs.android.com/android/platform/superproject/+/master:system/tools/aidl/build/aidl_interface.go;l=872;drc=5390d9a42f5e4f99ccb3a84068f554d948cb62b9
+ if versions != None and unstable:
+ fail("cannot have versions for unstable interface")
+
aidl_flags = ["--structured"]
if flags != None:
aidl_flags.extend(flags)
@@ -115,16 +137,9 @@ def aidl_interface(
if JAVA in enabled_backend_configs:
enabled_backend_configs.pop(JAVA)
- if srcs != None and len(srcs) > 0:
- create_aidl_binding_for_backends(
- name = name,
- srcs = srcs,
- strip_import_prefix = strip_import_prefix,
- deps = deps,
- backend_configs = enabled_backend_configs,
- aidl_flags = aidl_flags,
- **kwargs
- )
+ # next_version will be the last specified version + 1.
+ # https://cs.android.com/android/platform/superproject/+/master:system/tools/aidl/build/aidl_interface.go;l=791?q=system%2Ftools%2Faidl%2Fbuild%2Faidl_interface.go
+ next_version = None
# versions will be deprecated after all migrated to versions_with_info
if versions_with_info != None and len(versions_with_info) > 0:
@@ -132,6 +147,7 @@ def aidl_interface(
version_with_info["version"]
for version_with_info in versions_with_info
])
+ next_version = _next_version(versions, False)
for version_with_info in versions_with_info:
create_aidl_binding_for_backends(
name = name,
@@ -144,12 +160,13 @@ def aidl_interface(
if len(versions_with_info) > 0:
_create_latest_version_aliases(
name,
- name + "-V" + versions[-1],
+ versioned_name(name, versions[-1]),
enabled_backend_configs,
**kwargs
)
elif versions != None and len(versions) > 0:
versions = _check_versions(versions)
+ next_version = _next_version(versions, False)
for version in versions:
create_aidl_binding_for_backends(
name = name,
@@ -162,10 +179,26 @@ def aidl_interface(
if len(versions) > 0:
_create_latest_version_aliases(
name,
- name + "-V" + versions[-1],
+ versioned_name(name, versions[-1]),
enabled_backend_configs,
**kwargs
)
+ else:
+ next_version = _next_version(None, unstable)
+
+ # https://cs.android.com/android/platform/superproject/+/master:system/tools/aidl/build/aidl_interface.go;l=941;drc=5390d9a42f5e4f99ccb3a84068f554d948cb62b9
+ # Create aidl binding for next_version with srcs
+ if srcs and len(srcs) > 0:
+ create_aidl_binding_for_backends(
+ name = name,
+ version = next_version,
+ srcs = srcs,
+ strip_import_prefix = strip_import_prefix,
+ deps = deps,
+ aidl_flags = aidl_flags,
+ backend_configs = enabled_backend_configs,
+ **kwargs
+ )
def create_aidl_binding_for_backends(name, version = None, srcs = None, strip_import_prefix = "", deps = None, aidl_flags = [], backend_configs = {}, **kwargs):
"""
@@ -181,13 +214,16 @@ def create_aidl_binding_for_backends(name, version = None, srcs = None, strip_im
aidl_flags: List[string], a list of flags to pass to the AIDL compiler
backends: List[string], a list of the languages to generate bindings for
"""
- if version != None and srcs != None:
- fail("Can not set both version and srcs. Srcs is for unversioned AIDL")
+ aidl_library_name = versioned_name(name, version)
- aidl_library_name = name
+ # srcs is None when create_aidl_binding_for_backends is called with a
+ # frozen version specified via versions or versions_with_info.
+ # next_version being equal to "" means this is an unstable version and
+ # we should use srcs instead
+ if srcs == None:
+ if version == "":
+ fail("need srcs for unversioned interface")
- if version:
- aidl_library_name = name + "-V" + version
strip_import_prefix = "aidl_api/{}/{}".format(name, version)
srcs = native.glob([strip_import_prefix + "/**/*.aidl"])
aidl_flags = aidl_flags + ["--version=" + version]
diff --git a/rules/aidl/interface_test.bzl b/rules/aidl/interface_test.bzl
index 3fcaf30f..5cea1d06 100644
--- a/rules/aidl/interface_test.bzl
+++ b/rules/aidl/interface_test.bzl
@@ -14,6 +14,7 @@ limitations under the License.
"""
load("//build/bazel/rules/aidl:interface.bzl", "aidl_interface")
+load("//build/bazel/rules/test_common:rules.bzl", "target_under_test_exist_test")
load("@bazel_skylib//lib:new_sets.bzl", "sets")
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@bazel_skylib//lib:paths.bzl", "paths")
@@ -79,6 +80,7 @@ def _ndk_backend_test():
ndk_config = {
"enabled": True,
},
+ unstable = True,
srcs = ["a/b/Foo.aidl"],
strip_import_prefix = "a",
tags = ["manual"],
@@ -118,6 +120,7 @@ def _ndk_config_test():
aidl_interface(
name = name,
+ unstable = True,
ndk_config = {
"enabled": True,
"min_sdk_version": "30",
@@ -133,6 +136,43 @@ def _ndk_config_test():
return test_name
+def _next_version_for_unversioned_stable_interface_test():
+ name = "unversioned_stable_interface_next_version"
+ test_name = name + "_test"
+ next_version_aidl_library_target = name + "-V1"
+
+ aidl_interface(
+ name = name,
+ srcs = ["Foo.aidl"],
+ tags = ["manual"],
+ )
+
+ target_under_test_exist_test(
+ name = test_name,
+ target_under_test = next_version_aidl_library_target,
+ )
+
+ return test_name
+
+def _next_version_for_versioned_stable_interface_test():
+ name = "versioned_stable_interface_next_version"
+ test_name = name + "_test"
+ next_version_aidl_library_target = name + "-V3"
+
+ aidl_interface(
+ name = name,
+ versions = ["1", "2"],
+ srcs = ["Foo.aidl"],
+ tags = ["manual"],
+ )
+
+ target_under_test_exist_test(
+ name = test_name,
+ target_under_test = next_version_aidl_library_target,
+ )
+
+ return test_name
+
def aidl_interface_test_suite(name):
native.test_suite(
name = name,
@@ -141,5 +181,7 @@ def aidl_interface_test_suite(name):
"//build/bazel/rules/aidl/testing:interface_macro_produces_all_targets_test",
_ndk_backend_test(),
_ndk_config_test(),
+ _next_version_for_unversioned_stable_interface_test(),
+ _next_version_for_versioned_stable_interface_test(),
],
)
diff --git a/rules/test_common/rules.bzl b/rules/test_common/rules.bzl
index 5b9b8228..5d4bc6a5 100644
--- a/rules/test_common/rules.bzl
+++ b/rules/test_common/rules.bzl
@@ -29,3 +29,12 @@ expect_failure_test = analysistest.make(
},
doc = "This test checks that a rule fails with the expected failure_message",
)
+
+def _target_under_test_exist_impl(ctx):
+ env = analysistest.begin(ctx)
+ return analysistest.end(env)
+
+target_under_test_exist_test = analysistest.make(
+ impl = _target_under_test_exist_impl,
+ doc = "This test checks that the target under test exists without failure",
+)