• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Aspects used to transform certain providers into a TradefedTestInfo.
16
17Tradefed tests require a TradefedTestInfo provider that is not usually
18returned by most rules. Instead of creating custom rules to adapt build
19rule providers, we use Bazel aspects to convert the input rule's provider
20into a suitable type.
21
22See https://docs.bazel.build/versions/main/skylark/aspects.html#aspects
23for more information on how aspects work.
24"""
25
26load("//bazel/rules:soong_prebuilt.bzl", "SoongPrebuiltInfo")
27load("//bazel/rules:tradefed_test_info.bzl", "TradefedTestInfo")
28
29def _soong_prebuilt_tradefed_aspect_impl(target, ctx):
30    test_config_files = []
31    test_binary_files = []
32
33    # Partition files into config files and test binaries.
34    for f in target[SoongPrebuiltInfo].files.to_list():
35        if f.extension == "config" or f.extension == "xml":
36            test_config_files.append(f)
37        else:
38            test_binary_files.append(f)
39
40    return [
41        TradefedTestInfo(
42            module_name = target[SoongPrebuiltInfo].module_name,
43            test_binaries = test_binary_files,
44            test_configs = test_config_files,
45        ),
46    ]
47
48soong_prebuilt_tradefed_test_aspect = aspect(
49    attr_aspects = ["test"],
50    implementation = _soong_prebuilt_tradefed_aspect_impl,
51)
52