2019-01-26 01:04:11 +01:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
package sh
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-07-30 01:46:49 +02:00
|
|
|
"path/filepath"
|
2019-03-08 20:07:05 +01:00
|
|
|
"strings"
|
2020-06-01 19:45:49 +02:00
|
|
|
|
2023-10-06 21:54:58 +02:00
|
|
|
"android/soong/testing"
|
2024-04-04 02:56:15 +02:00
|
|
|
|
2020-05-30 01:15:32 +02:00
|
|
|
"github.com/google/blueprint"
|
2020-06-01 19:45:49 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-05-30 01:15:32 +02:00
|
|
|
"android/soong/cc"
|
2020-06-03 19:28:47 +02:00
|
|
|
"android/soong/tradefed"
|
2019-01-26 01:04:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// sh_binary is for shell scripts (and batch files) that are installed as
|
|
|
|
// executable files into .../bin/
|
|
|
|
//
|
|
|
|
// Do not use them for prebuilt C/C++/etc files. Use cc_prebuilt_binary
|
|
|
|
// instead.
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
var pctx = android.NewPackageContext("android/soong/sh")
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
func init() {
|
2020-06-01 19:45:49 +02:00
|
|
|
pctx.Import("android/soong/android")
|
|
|
|
|
2021-03-08 16:05:52 +01:00
|
|
|
registerShBuildComponents(android.InitRegistrationContext)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 16:05:52 +01:00
|
|
|
func registerShBuildComponents(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("sh_binary", ShBinaryFactory)
|
|
|
|
ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
|
|
|
|
ctx.RegisterModuleType("sh_test", ShTestFactory)
|
|
|
|
ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test fixture preparer that will register most sh build components.
|
|
|
|
//
|
|
|
|
// Singletons and mutators should only be added here if they are needed for a majority of sh
|
|
|
|
// module types, otherwise they should be added under a separate preparer to allow them to be
|
|
|
|
// selected only when needed to reduce test execution time.
|
|
|
|
//
|
|
|
|
// Module types do not have much of an overhead unless they are used so this should include as many
|
|
|
|
// module types as possible. The exceptions are those module types that require mutators and/or
|
|
|
|
// singletons in order to function in which case they should be kept together in a separate
|
|
|
|
// preparer.
|
|
|
|
var PrepareForTestWithShBuildComponents = android.GroupFixturePreparers(
|
|
|
|
android.FixtureRegisterWithContext(registerShBuildComponents),
|
|
|
|
)
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
type shBinaryProperties struct {
|
|
|
|
// Source file of this prebuilt.
|
2019-03-05 07:35:41 +01:00
|
|
|
Src *string `android:"path,arch_variant"`
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
// optional subdirectory under which this file is installed into
|
|
|
|
Sub_dir *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// optional name for the installed file. If unspecified, name of the module is used as the file name
|
|
|
|
Filename *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// when set to true, and filename property is not set, the name for the installed file
|
|
|
|
// is the same as the file name of the source file.
|
|
|
|
Filename_from_src *bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// Whether this module is directly installable to one of the partitions. Default: true.
|
|
|
|
Installable *bool
|
2019-10-05 05:38:01 +02:00
|
|
|
|
|
|
|
// install symlinks to the binary
|
|
|
|
Symlinks []string `android:"arch_variant"`
|
2020-08-21 23:25:33 +02:00
|
|
|
|
|
|
|
// Make this module available when building for ramdisk.
|
2020-10-26 20:43:12 +01:00
|
|
|
// On device without a dedicated recovery partition, the module is only
|
|
|
|
// available after switching root into
|
|
|
|
// /first_stage_ramdisk. To expose the module before switching root, install
|
|
|
|
// the recovery variant instead.
|
2020-08-21 23:25:33 +02:00
|
|
|
Ramdisk_available *bool
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
// Make this module available when building for vendor ramdisk.
|
2020-10-26 20:43:12 +01:00
|
|
|
// On device without a dedicated recovery partition, the module is only
|
|
|
|
// available after switching root into
|
|
|
|
// /first_stage_ramdisk. To expose the module before switching root, install
|
|
|
|
// the recovery variant instead.
|
2020-10-22 00:17:56 +02:00
|
|
|
Vendor_ramdisk_available *bool
|
|
|
|
|
2020-08-21 23:25:33 +02:00
|
|
|
// Make this module available when building for recovery.
|
|
|
|
Recovery_available *bool
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2019-03-08 20:07:05 +01:00
|
|
|
type TestProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2020-06-10 00:09:22 +02:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2019-05-16 23:58:29 +02:00
|
|
|
|
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test.
|
|
|
|
Data []string `android:"path,arch_variant"`
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2020-05-30 01:15:32 +02:00
|
|
|
|
|
|
|
// list of binary modules that should be installed alongside the test
|
|
|
|
Data_bins []string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
// list of library modules that should be installed alongside the test
|
|
|
|
Data_libs []string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
// list of device binary modules that should be installed alongside the test.
|
|
|
|
// Only available for host sh_test modules.
|
|
|
|
Data_device_bins []string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
// list of device library modules that should be installed alongside the test.
|
|
|
|
// Only available for host sh_test modules.
|
|
|
|
Data_device_libs []string `android:"path,arch_variant"`
|
2021-05-24 21:04:54 +02:00
|
|
|
|
2023-08-25 00:17:56 +02:00
|
|
|
// list of java modules that provide data that should be installed alongside the test.
|
|
|
|
Java_data []string
|
|
|
|
|
2022-02-22 08:33:24 +01:00
|
|
|
// Install the test into a folder named for the module in all test suites.
|
|
|
|
Per_testcase_directory *bool
|
|
|
|
|
2021-05-24 21:04:54 +02:00
|
|
|
// Test options.
|
2022-08-12 12:49:20 +02:00
|
|
|
Test_options android.CommonTestOptions
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
type ShBinary struct {
|
2020-06-01 19:45:49 +02:00
|
|
|
android.ModuleBase
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
properties shBinaryProperties
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
sourceFilePath android.Path
|
|
|
|
outputFilePath android.OutputPath
|
|
|
|
installedFile android.InstallPath
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
var _ android.HostToolProvider = (*ShBinary)(nil)
|
2019-07-30 01:46:49 +02:00
|
|
|
|
2019-03-08 20:07:05 +01:00
|
|
|
type ShTest struct {
|
|
|
|
ShBinary
|
|
|
|
|
|
|
|
testProperties TestProperties
|
2019-05-16 23:58:29 +02:00
|
|
|
|
2020-06-11 02:23:46 +02:00
|
|
|
installDir android.InstallPath
|
|
|
|
|
2023-11-15 21:39:40 +01:00
|
|
|
data []android.DataPath
|
2020-06-03 19:28:47 +02:00
|
|
|
testConfig android.Path
|
2020-05-30 01:15:32 +02:00
|
|
|
|
|
|
|
dataModules map[string]android.Path
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) HostToolPath() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(s.installedFile)
|
2019-07-30 01:46:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) OutputFile() android.OutputPath {
|
2019-01-26 01:04:11 +01:00
|
|
|
return s.outputFilePath
|
|
|
|
}
|
|
|
|
|
2023-08-07 21:03:22 +02:00
|
|
|
func (s *ShBinary) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return android.Paths{s.outputFilePath}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
func (s *ShBinary) SubDir() string {
|
2020-06-01 19:45:49 +02:00
|
|
|
return proptools.String(s.properties.Sub_dir)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-10 22:42:03 +02:00
|
|
|
func (s *ShBinary) RelativeInstallPath() string {
|
|
|
|
return s.SubDir()
|
|
|
|
}
|
2019-01-26 01:04:11 +01:00
|
|
|
func (s *ShBinary) Installable() bool {
|
2020-06-01 19:45:49 +02:00
|
|
|
return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2019-10-05 05:38:01 +02:00
|
|
|
func (s *ShBinary) Symlinks() []string {
|
|
|
|
return s.properties.Symlinks
|
|
|
|
}
|
|
|
|
|
2020-08-21 23:25:33 +02:00
|
|
|
var _ android.ImageInterface = (*ShBinary)(nil)
|
|
|
|
|
|
|
|
func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
|
|
|
|
|
|
|
|
func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-08-21 23:25:33 +02:00
|
|
|
func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
|
2021-01-26 15:18:53 +01:00
|
|
|
if s.properties.Src == nil {
|
|
|
|
ctx.PropertyErrorf("src", "missing prebuilt source file")
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
|
|
|
|
filename := proptools.String(s.properties.Filename)
|
2020-12-21 18:11:10 +01:00
|
|
|
filenameFromSrc := proptools.Bool(s.properties.Filename_from_src)
|
2019-01-26 01:04:11 +01:00
|
|
|
if filename == "" {
|
2020-12-21 18:11:10 +01:00
|
|
|
if filenameFromSrc {
|
2019-01-26 01:04:11 +01:00
|
|
|
filename = s.sourceFilePath.Base()
|
|
|
|
} else {
|
|
|
|
filename = ctx.ModuleName()
|
|
|
|
}
|
2020-12-21 18:11:10 +01:00
|
|
|
} else if filenameFromSrc {
|
2019-01-26 01:04:11 +01:00
|
|
|
ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
|
|
|
|
return
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
// This ensures that outputFilePath has the correct name for others to
|
|
|
|
// use, as the source file may have a different name.
|
2020-06-01 19:45:49 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.CpExecutable,
|
2019-01-26 01:04:11 +01:00
|
|
|
Output: s.outputFilePath,
|
|
|
|
Input: s.sourceFilePath,
|
|
|
|
})
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: []string{s.sourceFilePath.String()}})
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-07-30 01:46:49 +02:00
|
|
|
s.generateAndroidBuildActions(ctx)
|
2020-06-01 19:45:49 +02:00
|
|
|
installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
|
2022-01-12 04:29:17 +01:00
|
|
|
if !s.Installable() {
|
|
|
|
s.SkipInstall()
|
|
|
|
}
|
2019-07-30 01:46:49 +02:00
|
|
|
s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
|
2021-11-10 02:21:14 +01:00
|
|
|
for _, symlink := range s.Symlinks() {
|
|
|
|
ctx.InstallSymlink(installDir, symlink, s.installedFile)
|
|
|
|
}
|
2019-07-30 01:46:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-01-26 01:04:11 +01:00
|
|
|
Class: "EXECUTABLES",
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile: android.OptionalPathForPath(s.outputFilePath),
|
2021-11-12 19:27:58 +01:00
|
|
|
Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
|
2020-06-01 19:45:49 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2019-08-28 02:33:16 +02:00
|
|
|
s.customAndroidMkEntries(entries)
|
2020-06-11 02:23:46 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
|
2022-01-12 04:29:17 +01:00
|
|
|
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !s.Installable())
|
2019-08-28 02:33:16 +02:00
|
|
|
},
|
2019-01-26 01:04:11 +01:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
|
2019-05-16 23:58:29 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_SUFFIX", "")
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
|
2019-10-05 05:38:01 +02:00
|
|
|
if len(s.properties.Symlinks) > 0 {
|
|
|
|
entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
|
|
|
|
}
|
2019-05-16 23:58:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-30 01:15:32 +02:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
shTestDataBinsTag = dependencyTag{name: "dataBins"}
|
|
|
|
shTestDataLibsTag = dependencyTag{name: "dataLibs"}
|
|
|
|
shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
|
|
|
|
shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
|
2023-08-25 00:17:56 +02:00
|
|
|
shTestJavaDataTag = dependencyTag{name: "javaData"}
|
2020-05-30 01:15:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
|
|
|
|
|
|
|
|
func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
s.ShBinary.DepsMutator(ctx)
|
|
|
|
|
|
|
|
ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
|
|
|
|
ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
|
|
|
|
shTestDataLibsTag, s.testProperties.Data_libs...)
|
2022-04-26 15:38:20 +02:00
|
|
|
if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 {
|
2020-10-10 02:25:15 +02:00
|
|
|
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
|
2020-05-30 01:15:32 +02:00
|
|
|
ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
|
|
|
|
ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),
|
|
|
|
shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)
|
2023-08-25 00:17:56 +02:00
|
|
|
|
|
|
|
javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}}
|
|
|
|
ctx.AddVariationDependencies(javaDataVariation, shTestJavaDataTag, s.testProperties.Java_data...)
|
|
|
|
|
2020-05-30 01:15:32 +02:00
|
|
|
} else if ctx.Target().Os.Class != android.Host {
|
|
|
|
if len(s.testProperties.Data_device_bins) > 0 {
|
|
|
|
ctx.PropertyErrorf("data_device_bins", "only available for host modules")
|
|
|
|
}
|
|
|
|
if len(s.testProperties.Data_device_libs) > 0 {
|
|
|
|
ctx.PropertyErrorf("data_device_libs", "only available for host modules")
|
|
|
|
}
|
2023-08-25 00:17:56 +02:00
|
|
|
if len(s.testProperties.Java_data) > 0 {
|
|
|
|
ctx.PropertyErrorf("Java_data", "only available for host modules")
|
|
|
|
}
|
2020-05-30 01:15:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) {
|
|
|
|
if _, exists := s.dataModules[relPath]; exists {
|
|
|
|
ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s",
|
|
|
|
relPath, s.dataModules[relPath].String(), path.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.dataModules[relPath] = path
|
2023-11-15 21:39:40 +01:00
|
|
|
s.data = append(s.data, android.DataPath{SrcPath: path})
|
2020-05-30 01:15:32 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-07-30 01:46:49 +02:00
|
|
|
s.ShBinary.generateAndroidBuildActions(ctx)
|
2023-11-15 21:39:40 +01:00
|
|
|
|
|
|
|
expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
|
|
|
|
// Emulate the data property for java_data dependencies.
|
|
|
|
for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) {
|
|
|
|
expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)
|
|
|
|
}
|
|
|
|
for _, d := range expandedData {
|
|
|
|
s.data = append(s.data, android.DataPath{SrcPath: d})
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:46:49 +02:00
|
|
|
testDir := "nativetest"
|
|
|
|
if ctx.Target().Arch.ArchType.Multilib == "lib64" {
|
|
|
|
testDir = "nativetest64"
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
|
2019-07-30 01:46:49 +02:00
|
|
|
testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
|
|
|
|
} else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
|
|
|
|
testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
|
|
|
|
}
|
2020-06-11 02:23:46 +02:00
|
|
|
if s.SubDir() != "" {
|
|
|
|
// Don't add the module name to the installation path if sub_dir is specified for backward
|
|
|
|
// compatibility.
|
|
|
|
s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
|
|
|
|
} else {
|
|
|
|
s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
|
|
|
|
}
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
var configs []tradefed.Config
|
|
|
|
if Bool(s.testProperties.Require_root) {
|
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
|
|
|
} else {
|
|
|
|
options := []tradefed.Option{{Name: "force-root", Value: "false"}}
|
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
|
|
|
|
}
|
2020-09-28 22:22:57 +02:00
|
|
|
if len(s.testProperties.Data_device_bins) > 0 {
|
|
|
|
moduleName := s.Name()
|
|
|
|
remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/"
|
|
|
|
options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
|
|
|
|
for _, bin := range s.testProperties.Data_device_bins {
|
|
|
|
options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin})
|
|
|
|
}
|
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
|
|
|
|
}
|
2022-12-08 03:18:37 +01:00
|
|
|
s.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
|
|
|
|
TestConfigProp: s.testProperties.Test_config,
|
|
|
|
TestConfigTemplateProp: s.testProperties.Test_config_template,
|
|
|
|
TestSuites: s.testProperties.Test_suites,
|
|
|
|
Config: configs,
|
|
|
|
AutoGenConfig: s.testProperties.Auto_gen_config,
|
|
|
|
OutputFileName: s.outputFilePath.Base(),
|
|
|
|
DeviceTemplate: "${ShellTestConfigTemplate}",
|
|
|
|
HostTemplate: "${ShellTestConfigTemplate}",
|
|
|
|
})
|
2020-05-30 01:15:32 +02:00
|
|
|
|
|
|
|
s.dataModules = make(map[string]android.Path)
|
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
|
|
depTag := ctx.OtherModuleDependencyTag(dep)
|
|
|
|
switch depTag {
|
|
|
|
case shTestDataBinsTag, shTestDataDeviceBinsTag:
|
2020-12-31 14:42:10 +01:00
|
|
|
path := android.OutputFileForModule(ctx, dep, "")
|
|
|
|
s.addToDataModules(ctx, path.Base(), path)
|
2020-05-30 01:15:32 +02:00
|
|
|
case shTestDataLibsTag, shTestDataDeviceLibsTag:
|
|
|
|
if cc, isCc := dep.(*cc.Module); isCc {
|
|
|
|
// Copy to an intermediate output directory to append "lib[64]" to the path,
|
|
|
|
// so that it's compatible with the default rpath values.
|
|
|
|
var relPath string
|
|
|
|
if cc.Arch().ArchType.Multilib == "lib64" {
|
|
|
|
relPath = filepath.Join("lib64", cc.OutputFile().Path().Base())
|
|
|
|
} else {
|
|
|
|
relPath = filepath.Join("lib", cc.OutputFile().Path().Base())
|
|
|
|
}
|
|
|
|
if _, exist := s.dataModules[relPath]; exist {
|
|
|
|
return
|
|
|
|
}
|
2023-11-15 21:39:40 +01:00
|
|
|
relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
|
2020-05-30 01:15:32 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.Cp,
|
|
|
|
Input: cc.OutputFile().Path(),
|
|
|
|
Output: relocatedLib,
|
|
|
|
})
|
|
|
|
s.addToDataModules(ctx, relPath, relocatedLib)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
property := "data_libs"
|
|
|
|
if depTag == shTestDataDeviceBinsTag {
|
|
|
|
property = "data_device_libs"
|
|
|
|
}
|
|
|
|
ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
|
|
|
|
}
|
|
|
|
})
|
2023-11-15 21:39:40 +01:00
|
|
|
|
|
|
|
installedData := ctx.InstallTestData(s.installDir, s.data)
|
|
|
|
s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath, installedData...)
|
|
|
|
|
2023-12-14 00:19:49 +01:00
|
|
|
android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
|
2019-05-16 23:58:29 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:46:49 +02:00
|
|
|
func (s *ShTest) InstallInData() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-05-16 23:58:29 +02:00
|
|
|
Class: "NATIVE_TESTS",
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile: android.OptionalPathForPath(s.outputFilePath),
|
2021-11-12 19:27:58 +01:00
|
|
|
Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk",
|
2020-06-01 19:45:49 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
2020-07-03 22:18:24 +02:00
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
2019-08-28 02:33:16 +02:00
|
|
|
s.customAndroidMkEntries(entries)
|
2021-11-12 03:59:15 +01:00
|
|
|
entries.SetPath("LOCAL_MODULE_PATH", s.installDir)
|
2020-11-24 21:42:58 +01:00
|
|
|
entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...)
|
2020-06-10 00:09:22 +02:00
|
|
|
if s.testConfig != nil {
|
|
|
|
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
|
2020-06-03 19:28:47 +02:00
|
|
|
}
|
2022-02-11 11:06:07 +01:00
|
|
|
if s.testProperties.Data_bins != nil {
|
|
|
|
entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...)
|
|
|
|
}
|
2022-02-22 08:33:24 +01:00
|
|
|
entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(s.testProperties.Per_testcase_directory))
|
2022-08-12 12:49:20 +02:00
|
|
|
|
|
|
|
s.testProperties.Test_options.SetAndroidMkEntries(entries)
|
2019-08-28 02:33:16 +02:00
|
|
|
},
|
2019-05-16 23:58:29 +02:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2023-12-07 22:10:56 +01:00
|
|
|
func initShBinaryModule(s *ShBinary) {
|
2019-01-26 01:04:11 +01:00
|
|
|
s.AddProperties(&s.properties)
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:20:17 +01:00
|
|
|
// sh_binary is for a shell script or batch file to be installed as an
|
|
|
|
// executable binary to <partition>/bin.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShBinaryFactory() android.Module {
|
2019-01-26 01:04:11 +01:00
|
|
|
module := &ShBinary{}
|
2023-12-07 22:10:56 +01:00
|
|
|
initShBinaryModule(module)
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
|
2019-01-26 01:04:11 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:20:17 +01:00
|
|
|
// sh_binary_host is for a shell script to be installed as an executable binary
|
|
|
|
// to $(HOST_OUT)/bin.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShBinaryHostFactory() android.Module {
|
2019-01-26 01:04:11 +01:00
|
|
|
module := &ShBinary{}
|
2023-12-07 22:10:56 +01:00
|
|
|
initShBinaryModule(module)
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
2019-01-26 01:04:11 +01:00
|
|
|
return module
|
|
|
|
}
|
2019-03-08 20:07:05 +01:00
|
|
|
|
2019-07-01 18:08:50 +02:00
|
|
|
// sh_test defines a shell script based test module.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShTestFactory() android.Module {
|
2019-03-08 20:07:05 +01:00
|
|
|
module := &ShTest{}
|
2023-12-07 22:10:56 +01:00
|
|
|
initShBinaryModule(&module.ShBinary)
|
2019-03-08 20:07:05 +01:00
|
|
|
module.AddProperties(&module.testProperties)
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
|
2019-03-08 20:07:05 +01:00
|
|
|
return module
|
|
|
|
}
|
2019-07-01 18:08:50 +02:00
|
|
|
|
|
|
|
// sh_test_host defines a shell script based test module that runs on a host.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShTestHostFactory() android.Module {
|
2019-07-01 18:08:50 +02:00
|
|
|
module := &ShTest{}
|
2023-12-07 22:10:56 +01:00
|
|
|
initShBinaryModule(&module.ShBinary)
|
2019-07-01 18:08:50 +02:00
|
|
|
module.AddProperties(&module.testProperties)
|
2021-06-28 22:41:43 +02:00
|
|
|
// Default sh_test_host to unit_tests = true
|
|
|
|
if module.testProperties.Test_options.Unit_test == nil {
|
|
|
|
module.testProperties.Test_options.Unit_test = proptools.BoolPtr(true)
|
|
|
|
}
|
2019-07-01 18:08:50 +02:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
2019-07-01 18:08:50 +02:00
|
|
|
return module
|
|
|
|
}
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|