1*333d2b36SAndroid Build Coastguard Worker// Copyright 2019 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage sh 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "fmt" 19*333d2b36SAndroid Build Coastguard Worker "path/filepath" 20*333d2b36SAndroid Build Coastguard Worker "strings" 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 23*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 24*333d2b36SAndroid Build Coastguard Worker 25*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 26*333d2b36SAndroid Build Coastguard Worker "android/soong/cc" 27*333d2b36SAndroid Build Coastguard Worker "android/soong/tradefed" 28*333d2b36SAndroid Build Coastguard Worker) 29*333d2b36SAndroid Build Coastguard Worker 30*333d2b36SAndroid Build Coastguard Worker// sh_binary is for shell scripts (and batch files) that are installed as 31*333d2b36SAndroid Build Coastguard Worker// executable files into .../bin/ 32*333d2b36SAndroid Build Coastguard Worker// 33*333d2b36SAndroid Build Coastguard Worker// Do not use them for prebuilt C/C++/etc files. Use cc_prebuilt_binary 34*333d2b36SAndroid Build Coastguard Worker// instead. 35*333d2b36SAndroid Build Coastguard Worker 36*333d2b36SAndroid Build Coastguard Workervar pctx = android.NewPackageContext("android/soong/sh") 37*333d2b36SAndroid Build Coastguard Worker 38*333d2b36SAndroid Build Coastguard Workerfunc init() { 39*333d2b36SAndroid Build Coastguard Worker pctx.Import("android/soong/android") 40*333d2b36SAndroid Build Coastguard Worker 41*333d2b36SAndroid Build Coastguard Worker registerShBuildComponents(android.InitRegistrationContext) 42*333d2b36SAndroid Build Coastguard Worker} 43*333d2b36SAndroid Build Coastguard Worker 44*333d2b36SAndroid Build Coastguard Workerfunc registerShBuildComponents(ctx android.RegistrationContext) { 45*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("sh_binary", ShBinaryFactory) 46*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) 47*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("sh_test", ShTestFactory) 48*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) 49*333d2b36SAndroid Build Coastguard Worker ctx.RegisterModuleType("sh_defaults", ShDefaultsFactory) 50*333d2b36SAndroid Build Coastguard Worker} 51*333d2b36SAndroid Build Coastguard Worker 52*333d2b36SAndroid Build Coastguard Worker// Test fixture preparer that will register most sh build components. 53*333d2b36SAndroid Build Coastguard Worker// 54*333d2b36SAndroid Build Coastguard Worker// Singletons and mutators should only be added here if they are needed for a majority of sh 55*333d2b36SAndroid Build Coastguard Worker// module types, otherwise they should be added under a separate preparer to allow them to be 56*333d2b36SAndroid Build Coastguard Worker// selected only when needed to reduce test execution time. 57*333d2b36SAndroid Build Coastguard Worker// 58*333d2b36SAndroid Build Coastguard Worker// Module types do not have much of an overhead unless they are used so this should include as many 59*333d2b36SAndroid Build Coastguard Worker// module types as possible. The exceptions are those module types that require mutators and/or 60*333d2b36SAndroid Build Coastguard Worker// singletons in order to function in which case they should be kept together in a separate 61*333d2b36SAndroid Build Coastguard Worker// preparer. 62*333d2b36SAndroid Build Coastguard Workervar PrepareForTestWithShBuildComponents = android.GroupFixturePreparers( 63*333d2b36SAndroid Build Coastguard Worker android.FixtureRegisterWithContext(registerShBuildComponents), 64*333d2b36SAndroid Build Coastguard Worker) 65*333d2b36SAndroid Build Coastguard Worker 66*333d2b36SAndroid Build Coastguard Workertype shBinaryProperties struct { 67*333d2b36SAndroid Build Coastguard Worker // Source file of this prebuilt. 68*333d2b36SAndroid Build Coastguard Worker Src *string `android:"path,arch_variant"` 69*333d2b36SAndroid Build Coastguard Worker 70*333d2b36SAndroid Build Coastguard Worker // optional subdirectory under which this file is installed into 71*333d2b36SAndroid Build Coastguard Worker Sub_dir *string `android:"arch_variant"` 72*333d2b36SAndroid Build Coastguard Worker 73*333d2b36SAndroid Build Coastguard Worker // optional name for the installed file. If unspecified, name of the module is used as the file name 74*333d2b36SAndroid Build Coastguard Worker Filename *string `android:"arch_variant"` 75*333d2b36SAndroid Build Coastguard Worker 76*333d2b36SAndroid Build Coastguard Worker // when set to true, and filename property is not set, the name for the installed file 77*333d2b36SAndroid Build Coastguard Worker // is the same as the file name of the source file. 78*333d2b36SAndroid Build Coastguard Worker Filename_from_src *bool `android:"arch_variant"` 79*333d2b36SAndroid Build Coastguard Worker 80*333d2b36SAndroid Build Coastguard Worker // Whether this module is directly installable to one of the partitions. Default: true. 81*333d2b36SAndroid Build Coastguard Worker Installable *bool 82*333d2b36SAndroid Build Coastguard Worker 83*333d2b36SAndroid Build Coastguard Worker // install symlinks to the binary 84*333d2b36SAndroid Build Coastguard Worker Symlinks []string `android:"arch_variant"` 85*333d2b36SAndroid Build Coastguard Worker 86*333d2b36SAndroid Build Coastguard Worker // Make this module available when building for ramdisk. 87*333d2b36SAndroid Build Coastguard Worker // On device without a dedicated recovery partition, the module is only 88*333d2b36SAndroid Build Coastguard Worker // available after switching root into 89*333d2b36SAndroid Build Coastguard Worker // /first_stage_ramdisk. To expose the module before switching root, install 90*333d2b36SAndroid Build Coastguard Worker // the recovery variant instead. 91*333d2b36SAndroid Build Coastguard Worker Ramdisk_available *bool 92*333d2b36SAndroid Build Coastguard Worker 93*333d2b36SAndroid Build Coastguard Worker // Make this module available when building for vendor ramdisk. 94*333d2b36SAndroid Build Coastguard Worker // On device without a dedicated recovery partition, the module is only 95*333d2b36SAndroid Build Coastguard Worker // available after switching root into 96*333d2b36SAndroid Build Coastguard Worker // /first_stage_ramdisk. To expose the module before switching root, install 97*333d2b36SAndroid Build Coastguard Worker // the recovery variant instead. 98*333d2b36SAndroid Build Coastguard Worker Vendor_ramdisk_available *bool 99*333d2b36SAndroid Build Coastguard Worker 100*333d2b36SAndroid Build Coastguard Worker // Make this module available when building for recovery. 101*333d2b36SAndroid Build Coastguard Worker Recovery_available *bool 102*333d2b36SAndroid Build Coastguard Worker 103*333d2b36SAndroid Build Coastguard Worker // The name of the image this module is built for 104*333d2b36SAndroid Build Coastguard Worker ImageVariation string `blueprint:"mutated"` 105*333d2b36SAndroid Build Coastguard Worker 106*333d2b36SAndroid Build Coastguard Worker // Suffix for the name of Android.mk entries generated by this module 107*333d2b36SAndroid Build Coastguard Worker SubName string `blueprint:"mutated"` 108*333d2b36SAndroid Build Coastguard Worker} 109*333d2b36SAndroid Build Coastguard Worker 110*333d2b36SAndroid Build Coastguard Workertype TestProperties struct { 111*333d2b36SAndroid Build Coastguard Worker // list of compatibility suites (for example "cts", "vts") that the module should be 112*333d2b36SAndroid Build Coastguard Worker // installed into. 113*333d2b36SAndroid Build Coastguard Worker Test_suites []string `android:"arch_variant"` 114*333d2b36SAndroid Build Coastguard Worker 115*333d2b36SAndroid Build Coastguard Worker // the name of the test configuration (for example "AndroidTest.xml") that should be 116*333d2b36SAndroid Build Coastguard Worker // installed with the module. 117*333d2b36SAndroid Build Coastguard Worker Test_config *string `android:"path,arch_variant"` 118*333d2b36SAndroid Build Coastguard Worker 119*333d2b36SAndroid Build Coastguard Worker // list of files or filegroup modules that provide data that should be installed alongside 120*333d2b36SAndroid Build Coastguard Worker // the test. 121*333d2b36SAndroid Build Coastguard Worker Data []string `android:"path,arch_variant"` 122*333d2b36SAndroid Build Coastguard Worker 123*333d2b36SAndroid Build Coastguard Worker // same as data, but adds dependencies using the device's os variation and the common 124*333d2b36SAndroid Build Coastguard Worker // architecture's variation. Can be used to add a module built for device to the data of a 125*333d2b36SAndroid Build Coastguard Worker // host test. 126*333d2b36SAndroid Build Coastguard Worker Device_common_data []string `android:"path_device_common"` 127*333d2b36SAndroid Build Coastguard Worker 128*333d2b36SAndroid Build Coastguard Worker // same as data, but adds dependencies using the device's os variation and the device's first 129*333d2b36SAndroid Build Coastguard Worker // architecture's variation. Can be used to add a module built for device to the data of a 130*333d2b36SAndroid Build Coastguard Worker // host test. 131*333d2b36SAndroid Build Coastguard Worker Device_first_data []string `android:"path_device_first"` 132*333d2b36SAndroid Build Coastguard Worker 133*333d2b36SAndroid Build Coastguard Worker // Add RootTargetPreparer to auto generated test config. This guarantees the test to run 134*333d2b36SAndroid Build Coastguard Worker // with root permission. 135*333d2b36SAndroid Build Coastguard Worker Require_root *bool 136*333d2b36SAndroid Build Coastguard Worker 137*333d2b36SAndroid Build Coastguard Worker // the name of the test configuration template (for example "AndroidTestTemplate.xml") that 138*333d2b36SAndroid Build Coastguard Worker // should be installed with the module. 139*333d2b36SAndroid Build Coastguard Worker Test_config_template *string `android:"path,arch_variant"` 140*333d2b36SAndroid Build Coastguard Worker 141*333d2b36SAndroid Build Coastguard Worker // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml 142*333d2b36SAndroid Build Coastguard Worker // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true 143*333d2b36SAndroid Build Coastguard Worker // explicitly. 144*333d2b36SAndroid Build Coastguard Worker Auto_gen_config *bool 145*333d2b36SAndroid Build Coastguard Worker 146*333d2b36SAndroid Build Coastguard Worker // list of binary modules that should be installed alongside the test 147*333d2b36SAndroid Build Coastguard Worker Data_bins []string `android:"path,arch_variant"` 148*333d2b36SAndroid Build Coastguard Worker 149*333d2b36SAndroid Build Coastguard Worker // list of library modules that should be installed alongside the test 150*333d2b36SAndroid Build Coastguard Worker Data_libs []string `android:"path,arch_variant"` 151*333d2b36SAndroid Build Coastguard Worker 152*333d2b36SAndroid Build Coastguard Worker // list of device binary modules that should be installed alongside the test. 153*333d2b36SAndroid Build Coastguard Worker // Only available for host sh_test modules. 154*333d2b36SAndroid Build Coastguard Worker Data_device_bins []string `android:"path,arch_variant"` 155*333d2b36SAndroid Build Coastguard Worker 156*333d2b36SAndroid Build Coastguard Worker // list of device library modules that should be installed alongside the test. 157*333d2b36SAndroid Build Coastguard Worker // Only available for host sh_test modules. 158*333d2b36SAndroid Build Coastguard Worker Data_device_libs []string `android:"path,arch_variant"` 159*333d2b36SAndroid Build Coastguard Worker 160*333d2b36SAndroid Build Coastguard Worker // list of java modules that provide data that should be installed alongside the test. 161*333d2b36SAndroid Build Coastguard Worker Java_data []string 162*333d2b36SAndroid Build Coastguard Worker 163*333d2b36SAndroid Build Coastguard Worker // Install the test into a folder named for the module in all test suites. 164*333d2b36SAndroid Build Coastguard Worker Per_testcase_directory *bool 165*333d2b36SAndroid Build Coastguard Worker 166*333d2b36SAndroid Build Coastguard Worker // Test options. 167*333d2b36SAndroid Build Coastguard Worker Test_options android.CommonTestOptions 168*333d2b36SAndroid Build Coastguard Worker 169*333d2b36SAndroid Build Coastguard Worker // a list of extra test configuration files that should be installed with the module. 170*333d2b36SAndroid Build Coastguard Worker Extra_test_configs []string `android:"path,arch_variant"` 171*333d2b36SAndroid Build Coastguard Worker} 172*333d2b36SAndroid Build Coastguard Worker 173*333d2b36SAndroid Build Coastguard Workertype ShBinary struct { 174*333d2b36SAndroid Build Coastguard Worker android.ModuleBase 175*333d2b36SAndroid Build Coastguard Worker android.DefaultableModuleBase 176*333d2b36SAndroid Build Coastguard Worker 177*333d2b36SAndroid Build Coastguard Worker properties shBinaryProperties 178*333d2b36SAndroid Build Coastguard Worker 179*333d2b36SAndroid Build Coastguard Worker sourceFilePath android.Path 180*333d2b36SAndroid Build Coastguard Worker outputFilePath android.OutputPath 181*333d2b36SAndroid Build Coastguard Worker installedFile android.InstallPath 182*333d2b36SAndroid Build Coastguard Worker} 183*333d2b36SAndroid Build Coastguard Worker 184*333d2b36SAndroid Build Coastguard Workervar _ android.HostToolProvider = (*ShBinary)(nil) 185*333d2b36SAndroid Build Coastguard Worker 186*333d2b36SAndroid Build Coastguard Workertype ShTest struct { 187*333d2b36SAndroid Build Coastguard Worker ShBinary 188*333d2b36SAndroid Build Coastguard Worker 189*333d2b36SAndroid Build Coastguard Worker testProperties TestProperties 190*333d2b36SAndroid Build Coastguard Worker 191*333d2b36SAndroid Build Coastguard Worker installDir android.InstallPath 192*333d2b36SAndroid Build Coastguard Worker 193*333d2b36SAndroid Build Coastguard Worker data []android.DataPath 194*333d2b36SAndroid Build Coastguard Worker testConfig android.Path 195*333d2b36SAndroid Build Coastguard Worker extraTestConfigs android.Paths 196*333d2b36SAndroid Build Coastguard Worker 197*333d2b36SAndroid Build Coastguard Worker dataModules map[string]android.Path 198*333d2b36SAndroid Build Coastguard Worker} 199*333d2b36SAndroid Build Coastguard Worker 200*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) HostToolPath() android.OptionalPath { 201*333d2b36SAndroid Build Coastguard Worker return android.OptionalPathForPath(s.installedFile) 202*333d2b36SAndroid Build Coastguard Worker} 203*333d2b36SAndroid Build Coastguard Worker 204*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) { 205*333d2b36SAndroid Build Coastguard Worker} 206*333d2b36SAndroid Build Coastguard Worker 207*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) OutputFile() android.Path { 208*333d2b36SAndroid Build Coastguard Worker return s.outputFilePath 209*333d2b36SAndroid Build Coastguard Worker} 210*333d2b36SAndroid Build Coastguard Worker 211*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) SubDir() string { 212*333d2b36SAndroid Build Coastguard Worker return proptools.String(s.properties.Sub_dir) 213*333d2b36SAndroid Build Coastguard Worker} 214*333d2b36SAndroid Build Coastguard Worker 215*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) RelativeInstallPath() string { 216*333d2b36SAndroid Build Coastguard Worker return s.SubDir() 217*333d2b36SAndroid Build Coastguard Worker} 218*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) Installable() bool { 219*333d2b36SAndroid Build Coastguard Worker return s.properties.Installable == nil || proptools.Bool(s.properties.Installable) 220*333d2b36SAndroid Build Coastguard Worker} 221*333d2b36SAndroid Build Coastguard Worker 222*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) Symlinks() []string { 223*333d2b36SAndroid Build Coastguard Worker return s.properties.Symlinks 224*333d2b36SAndroid Build Coastguard Worker} 225*333d2b36SAndroid Build Coastguard Worker 226*333d2b36SAndroid Build Coastguard Workervar _ android.ImageInterface = (*ShBinary)(nil) 227*333d2b36SAndroid Build Coastguard Worker 228*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) ImageMutatorBegin(ctx android.ImageInterfaceContext) {} 229*333d2b36SAndroid Build Coastguard Worker 230*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) VendorVariantNeeded(ctx android.ImageInterfaceContext) bool { 231*333d2b36SAndroid Build Coastguard Worker return s.InstallInVendor() 232*333d2b36SAndroid Build Coastguard Worker} 233*333d2b36SAndroid Build Coastguard Worker 234*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) ProductVariantNeeded(ctx android.ImageInterfaceContext) bool { 235*333d2b36SAndroid Build Coastguard Worker return s.InstallInProduct() 236*333d2b36SAndroid Build Coastguard Worker} 237*333d2b36SAndroid Build Coastguard Worker 238*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) CoreVariantNeeded(ctx android.ImageInterfaceContext) bool { 239*333d2b36SAndroid Build Coastguard Worker return !s.InstallInRecovery() && !s.InstallInRamdisk() && !s.InstallInVendorRamdisk() && !s.ModuleBase.InstallInVendor() 240*333d2b36SAndroid Build Coastguard Worker} 241*333d2b36SAndroid Build Coastguard Worker 242*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) RamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { 243*333d2b36SAndroid Build Coastguard Worker return proptools.Bool(s.properties.Ramdisk_available) || s.InstallInRamdisk() 244*333d2b36SAndroid Build Coastguard Worker} 245*333d2b36SAndroid Build Coastguard Worker 246*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { 247*333d2b36SAndroid Build Coastguard Worker return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.InstallInVendorRamdisk() 248*333d2b36SAndroid Build Coastguard Worker} 249*333d2b36SAndroid Build Coastguard Worker 250*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool { 251*333d2b36SAndroid Build Coastguard Worker return false 252*333d2b36SAndroid Build Coastguard Worker} 253*333d2b36SAndroid Build Coastguard Worker 254*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) RecoveryVariantNeeded(ctx android.ImageInterfaceContext) bool { 255*333d2b36SAndroid Build Coastguard Worker return proptools.Bool(s.properties.Recovery_available) || s.InstallInRecovery() 256*333d2b36SAndroid Build Coastguard Worker} 257*333d2b36SAndroid Build Coastguard Worker 258*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) ExtraImageVariations(ctx android.ImageInterfaceContext) []string { 259*333d2b36SAndroid Build Coastguard Worker return nil 260*333d2b36SAndroid Build Coastguard Worker} 261*333d2b36SAndroid Build Coastguard Worker 262*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) SetImageVariation(ctx android.ImageInterfaceContext, variation string) { 263*333d2b36SAndroid Build Coastguard Worker s.properties.ImageVariation = variation 264*333d2b36SAndroid Build Coastguard Worker} 265*333d2b36SAndroid Build Coastguard Worker 266*333d2b36SAndroid Build Coastguard Worker// Overrides ModuleBase.InstallInRamdisk() so that the install rule respects 267*333d2b36SAndroid Build Coastguard Worker// Ramdisk_available property for ramdisk variant 268*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) InstallInRamdisk() bool { 269*333d2b36SAndroid Build Coastguard Worker return s.ModuleBase.InstallInRamdisk() || 270*333d2b36SAndroid Build Coastguard Worker (proptools.Bool(s.properties.Ramdisk_available) && s.properties.ImageVariation == android.RamdiskVariation) 271*333d2b36SAndroid Build Coastguard Worker} 272*333d2b36SAndroid Build Coastguard Worker 273*333d2b36SAndroid Build Coastguard Worker// Overrides ModuleBase.InstallInVendorRamdisk() so that the install rule respects 274*333d2b36SAndroid Build Coastguard Worker// Vendor_ramdisk_available property for vendor ramdisk variant 275*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) InstallInVendorRamdisk() bool { 276*333d2b36SAndroid Build Coastguard Worker return s.ModuleBase.InstallInVendorRamdisk() || 277*333d2b36SAndroid Build Coastguard Worker (proptools.Bool(s.properties.Vendor_ramdisk_available) && s.properties.ImageVariation == android.VendorRamdiskVariation) 278*333d2b36SAndroid Build Coastguard Worker} 279*333d2b36SAndroid Build Coastguard Worker 280*333d2b36SAndroid Build Coastguard Worker// Overrides ModuleBase.InstallInRecovery() so that the install rule respects 281*333d2b36SAndroid Build Coastguard Worker// Recovery_available property for recovery variant 282*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) InstallInRecovery() bool { 283*333d2b36SAndroid Build Coastguard Worker return s.ModuleBase.InstallInRecovery() || 284*333d2b36SAndroid Build Coastguard Worker (proptools.Bool(s.properties.Recovery_available) && s.properties.ImageVariation == android.RecoveryVariation) 285*333d2b36SAndroid Build Coastguard Worker} 286*333d2b36SAndroid Build Coastguard Worker 287*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { 288*333d2b36SAndroid Build Coastguard Worker if s.properties.Src == nil { 289*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("src", "missing prebuilt source file") 290*333d2b36SAndroid Build Coastguard Worker } 291*333d2b36SAndroid Build Coastguard Worker 292*333d2b36SAndroid Build Coastguard Worker s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src)) 293*333d2b36SAndroid Build Coastguard Worker filename := proptools.String(s.properties.Filename) 294*333d2b36SAndroid Build Coastguard Worker filenameFromSrc := proptools.Bool(s.properties.Filename_from_src) 295*333d2b36SAndroid Build Coastguard Worker if filename == "" { 296*333d2b36SAndroid Build Coastguard Worker if filenameFromSrc { 297*333d2b36SAndroid Build Coastguard Worker filename = s.sourceFilePath.Base() 298*333d2b36SAndroid Build Coastguard Worker } else { 299*333d2b36SAndroid Build Coastguard Worker filename = ctx.ModuleName() 300*333d2b36SAndroid Build Coastguard Worker } 301*333d2b36SAndroid Build Coastguard Worker } else if filenameFromSrc { 302*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") 303*333d2b36SAndroid Build Coastguard Worker return 304*333d2b36SAndroid Build Coastguard Worker } 305*333d2b36SAndroid Build Coastguard Worker s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath 306*333d2b36SAndroid Build Coastguard Worker 307*333d2b36SAndroid Build Coastguard Worker // This ensures that outputFilePath has the correct name for others to 308*333d2b36SAndroid Build Coastguard Worker // use, as the source file may have a different name. 309*333d2b36SAndroid Build Coastguard Worker ctx.Build(pctx, android.BuildParams{ 310*333d2b36SAndroid Build Coastguard Worker Rule: android.CpExecutable, 311*333d2b36SAndroid Build Coastguard Worker Output: s.outputFilePath, 312*333d2b36SAndroid Build Coastguard Worker Input: s.sourceFilePath, 313*333d2b36SAndroid Build Coastguard Worker }) 314*333d2b36SAndroid Build Coastguard Worker 315*333d2b36SAndroid Build Coastguard Worker s.properties.SubName = s.GetSubname(ctx) 316*333d2b36SAndroid Build Coastguard Worker 317*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: []string{s.sourceFilePath.String()}}) 318*333d2b36SAndroid Build Coastguard Worker 319*333d2b36SAndroid Build Coastguard Worker ctx.SetOutputFiles(android.Paths{s.outputFilePath}, "") 320*333d2b36SAndroid Build Coastguard Worker} 321*333d2b36SAndroid Build Coastguard Worker 322*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) GetSubname(ctx android.ModuleContext) string { 323*333d2b36SAndroid Build Coastguard Worker ret := "" 324*333d2b36SAndroid Build Coastguard Worker if s.properties.ImageVariation != "" { 325*333d2b36SAndroid Build Coastguard Worker if s.properties.ImageVariation != android.VendorVariation { 326*333d2b36SAndroid Build Coastguard Worker ret = "." + s.properties.ImageVariation 327*333d2b36SAndroid Build Coastguard Worker } 328*333d2b36SAndroid Build Coastguard Worker } 329*333d2b36SAndroid Build Coastguard Worker return ret 330*333d2b36SAndroid Build Coastguard Worker} 331*333d2b36SAndroid Build Coastguard Worker 332*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { 333*333d2b36SAndroid Build Coastguard Worker s.generateAndroidBuildActions(ctx) 334*333d2b36SAndroid Build Coastguard Worker installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir)) 335*333d2b36SAndroid Build Coastguard Worker if !s.Installable() { 336*333d2b36SAndroid Build Coastguard Worker s.SkipInstall() 337*333d2b36SAndroid Build Coastguard Worker } 338*333d2b36SAndroid Build Coastguard Worker s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath) 339*333d2b36SAndroid Build Coastguard Worker for _, symlink := range s.Symlinks() { 340*333d2b36SAndroid Build Coastguard Worker ctx.InstallSymlink(installDir, symlink, s.installedFile) 341*333d2b36SAndroid Build Coastguard Worker } 342*333d2b36SAndroid Build Coastguard Worker} 343*333d2b36SAndroid Build Coastguard Worker 344*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { 345*333d2b36SAndroid Build Coastguard Worker return []android.AndroidMkEntries{{ 346*333d2b36SAndroid Build Coastguard Worker Class: "EXECUTABLES", 347*333d2b36SAndroid Build Coastguard Worker OutputFile: android.OptionalPathForPath(s.outputFilePath), 348*333d2b36SAndroid Build Coastguard Worker Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", 349*333d2b36SAndroid Build Coastguard Worker ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 350*333d2b36SAndroid Build Coastguard Worker func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 351*333d2b36SAndroid Build Coastguard Worker s.customAndroidMkEntries(entries) 352*333d2b36SAndroid Build Coastguard Worker entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) 353*333d2b36SAndroid Build Coastguard Worker entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !s.Installable()) 354*333d2b36SAndroid Build Coastguard Worker }, 355*333d2b36SAndroid Build Coastguard Worker }, 356*333d2b36SAndroid Build Coastguard Worker SubName: s.properties.SubName, 357*333d2b36SAndroid Build Coastguard Worker }} 358*333d2b36SAndroid Build Coastguard Worker} 359*333d2b36SAndroid Build Coastguard Worker 360*333d2b36SAndroid Build Coastguard Workerfunc (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) { 361*333d2b36SAndroid Build Coastguard Worker entries.SetString("LOCAL_MODULE_SUFFIX", "") 362*333d2b36SAndroid Build Coastguard Worker entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel()) 363*333d2b36SAndroid Build Coastguard Worker if len(s.properties.Symlinks) > 0 { 364*333d2b36SAndroid Build Coastguard Worker entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " ")) 365*333d2b36SAndroid Build Coastguard Worker } 366*333d2b36SAndroid Build Coastguard Worker} 367*333d2b36SAndroid Build Coastguard Worker 368*333d2b36SAndroid Build Coastguard Workertype dependencyTag struct { 369*333d2b36SAndroid Build Coastguard Worker blueprint.BaseDependencyTag 370*333d2b36SAndroid Build Coastguard Worker name string 371*333d2b36SAndroid Build Coastguard Worker} 372*333d2b36SAndroid Build Coastguard Worker 373*333d2b36SAndroid Build Coastguard Workervar ( 374*333d2b36SAndroid Build Coastguard Worker shTestDataBinsTag = dependencyTag{name: "dataBins"} 375*333d2b36SAndroid Build Coastguard Worker shTestDataLibsTag = dependencyTag{name: "dataLibs"} 376*333d2b36SAndroid Build Coastguard Worker shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} 377*333d2b36SAndroid Build Coastguard Worker shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"} 378*333d2b36SAndroid Build Coastguard Worker shTestJavaDataTag = dependencyTag{name: "javaData"} 379*333d2b36SAndroid Build Coastguard Worker) 380*333d2b36SAndroid Build Coastguard Worker 381*333d2b36SAndroid Build Coastguard Workervar sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}} 382*333d2b36SAndroid Build Coastguard Worker 383*333d2b36SAndroid Build Coastguard Workerfunc (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) { 384*333d2b36SAndroid Build Coastguard Worker s.ShBinary.DepsMutator(ctx) 385*333d2b36SAndroid Build Coastguard Worker 386*333d2b36SAndroid Build Coastguard Worker ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...) 387*333d2b36SAndroid Build Coastguard Worker ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...), 388*333d2b36SAndroid Build Coastguard Worker shTestDataLibsTag, s.testProperties.Data_libs...) 389*333d2b36SAndroid Build Coastguard Worker if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 { 390*333d2b36SAndroid Build Coastguard Worker deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() 391*333d2b36SAndroid Build Coastguard Worker ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...) 392*333d2b36SAndroid Build Coastguard Worker ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...), 393*333d2b36SAndroid Build Coastguard Worker shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...) 394*333d2b36SAndroid Build Coastguard Worker 395*333d2b36SAndroid Build Coastguard Worker javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}} 396*333d2b36SAndroid Build Coastguard Worker ctx.AddVariationDependencies(javaDataVariation, shTestJavaDataTag, s.testProperties.Java_data...) 397*333d2b36SAndroid Build Coastguard Worker 398*333d2b36SAndroid Build Coastguard Worker } else if ctx.Target().Os.Class != android.Host { 399*333d2b36SAndroid Build Coastguard Worker if len(s.testProperties.Data_device_bins) > 0 { 400*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("data_device_bins", "only available for host modules") 401*333d2b36SAndroid Build Coastguard Worker } 402*333d2b36SAndroid Build Coastguard Worker if len(s.testProperties.Data_device_libs) > 0 { 403*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("data_device_libs", "only available for host modules") 404*333d2b36SAndroid Build Coastguard Worker } 405*333d2b36SAndroid Build Coastguard Worker if len(s.testProperties.Java_data) > 0 { 406*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf("Java_data", "only available for host modules") 407*333d2b36SAndroid Build Coastguard Worker } 408*333d2b36SAndroid Build Coastguard Worker } 409*333d2b36SAndroid Build Coastguard Worker} 410*333d2b36SAndroid Build Coastguard Worker 411*333d2b36SAndroid Build Coastguard Workerfunc (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) { 412*333d2b36SAndroid Build Coastguard Worker if _, exists := s.dataModules[relPath]; exists { 413*333d2b36SAndroid Build Coastguard Worker ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s", 414*333d2b36SAndroid Build Coastguard Worker relPath, s.dataModules[relPath].String(), path.String()) 415*333d2b36SAndroid Build Coastguard Worker return 416*333d2b36SAndroid Build Coastguard Worker } 417*333d2b36SAndroid Build Coastguard Worker s.dataModules[relPath] = path 418*333d2b36SAndroid Build Coastguard Worker s.data = append(s.data, android.DataPath{SrcPath: path}) 419*333d2b36SAndroid Build Coastguard Worker} 420*333d2b36SAndroid Build Coastguard Worker 421*333d2b36SAndroid Build Coastguard Workerfunc (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { 422*333d2b36SAndroid Build Coastguard Worker s.ShBinary.generateAndroidBuildActions(ctx) 423*333d2b36SAndroid Build Coastguard Worker 424*333d2b36SAndroid Build Coastguard Worker expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data) 425*333d2b36SAndroid Build Coastguard Worker expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_common_data)...) 426*333d2b36SAndroid Build Coastguard Worker expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_first_data)...) 427*333d2b36SAndroid Build Coastguard Worker // Emulate the data property for java_data dependencies. 428*333d2b36SAndroid Build Coastguard Worker for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) { 429*333d2b36SAndroid Build Coastguard Worker expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) 430*333d2b36SAndroid Build Coastguard Worker } 431*333d2b36SAndroid Build Coastguard Worker for _, d := range expandedData { 432*333d2b36SAndroid Build Coastguard Worker s.data = append(s.data, android.DataPath{SrcPath: d}) 433*333d2b36SAndroid Build Coastguard Worker } 434*333d2b36SAndroid Build Coastguard Worker 435*333d2b36SAndroid Build Coastguard Worker testDir := "nativetest" 436*333d2b36SAndroid Build Coastguard Worker if ctx.Target().Arch.ArchType.Multilib == "lib64" { 437*333d2b36SAndroid Build Coastguard Worker testDir = "nativetest64" 438*333d2b36SAndroid Build Coastguard Worker } 439*333d2b36SAndroid Build Coastguard Worker if ctx.Target().NativeBridge == android.NativeBridgeEnabled { 440*333d2b36SAndroid Build Coastguard Worker testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath) 441*333d2b36SAndroid Build Coastguard Worker } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { 442*333d2b36SAndroid Build Coastguard Worker testDir = filepath.Join(testDir, ctx.Arch().ArchType.String()) 443*333d2b36SAndroid Build Coastguard Worker } 444*333d2b36SAndroid Build Coastguard Worker if s.SubDir() != "" { 445*333d2b36SAndroid Build Coastguard Worker // Don't add the module name to the installation path if sub_dir is specified for backward 446*333d2b36SAndroid Build Coastguard Worker // compatibility. 447*333d2b36SAndroid Build Coastguard Worker s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir()) 448*333d2b36SAndroid Build Coastguard Worker } else { 449*333d2b36SAndroid Build Coastguard Worker s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name()) 450*333d2b36SAndroid Build Coastguard Worker } 451*333d2b36SAndroid Build Coastguard Worker 452*333d2b36SAndroid Build Coastguard Worker var configs []tradefed.Config 453*333d2b36SAndroid Build Coastguard Worker if Bool(s.testProperties.Require_root) { 454*333d2b36SAndroid Build Coastguard Worker configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) 455*333d2b36SAndroid Build Coastguard Worker } else { 456*333d2b36SAndroid Build Coastguard Worker options := []tradefed.Option{{Name: "force-root", Value: "false"}} 457*333d2b36SAndroid Build Coastguard Worker configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) 458*333d2b36SAndroid Build Coastguard Worker } 459*333d2b36SAndroid Build Coastguard Worker if len(s.testProperties.Data_device_bins) > 0 { 460*333d2b36SAndroid Build Coastguard Worker moduleName := s.Name() 461*333d2b36SAndroid Build Coastguard Worker remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/" 462*333d2b36SAndroid Build Coastguard Worker options := []tradefed.Option{{Name: "cleanup", Value: "true"}} 463*333d2b36SAndroid Build Coastguard Worker for _, bin := range s.testProperties.Data_device_bins { 464*333d2b36SAndroid Build Coastguard Worker options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin}) 465*333d2b36SAndroid Build Coastguard Worker } 466*333d2b36SAndroid Build Coastguard Worker configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) 467*333d2b36SAndroid Build Coastguard Worker } 468*333d2b36SAndroid Build Coastguard Worker s.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ 469*333d2b36SAndroid Build Coastguard Worker TestConfigProp: s.testProperties.Test_config, 470*333d2b36SAndroid Build Coastguard Worker TestConfigTemplateProp: s.testProperties.Test_config_template, 471*333d2b36SAndroid Build Coastguard Worker TestSuites: s.testProperties.Test_suites, 472*333d2b36SAndroid Build Coastguard Worker Config: configs, 473*333d2b36SAndroid Build Coastguard Worker AutoGenConfig: s.testProperties.Auto_gen_config, 474*333d2b36SAndroid Build Coastguard Worker OutputFileName: s.outputFilePath.Base(), 475*333d2b36SAndroid Build Coastguard Worker DeviceTemplate: "${ShellTestConfigTemplate}", 476*333d2b36SAndroid Build Coastguard Worker HostTemplate: "${ShellTestConfigTemplate}", 477*333d2b36SAndroid Build Coastguard Worker }) 478*333d2b36SAndroid Build Coastguard Worker 479*333d2b36SAndroid Build Coastguard Worker s.extraTestConfigs = android.PathsForModuleSrc(ctx, s.testProperties.Extra_test_configs) 480*333d2b36SAndroid Build Coastguard Worker s.dataModules = make(map[string]android.Path) 481*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(func(dep android.Module) { 482*333d2b36SAndroid Build Coastguard Worker depTag := ctx.OtherModuleDependencyTag(dep) 483*333d2b36SAndroid Build Coastguard Worker switch depTag { 484*333d2b36SAndroid Build Coastguard Worker case shTestDataBinsTag, shTestDataDeviceBinsTag: 485*333d2b36SAndroid Build Coastguard Worker path := android.OutputFileForModule(ctx, dep, "") 486*333d2b36SAndroid Build Coastguard Worker s.addToDataModules(ctx, path.Base(), path) 487*333d2b36SAndroid Build Coastguard Worker case shTestDataLibsTag, shTestDataDeviceLibsTag: 488*333d2b36SAndroid Build Coastguard Worker if cc, isCc := dep.(*cc.Module); isCc { 489*333d2b36SAndroid Build Coastguard Worker // Copy to an intermediate output directory to append "lib[64]" to the path, 490*333d2b36SAndroid Build Coastguard Worker // so that it's compatible with the default rpath values. 491*333d2b36SAndroid Build Coastguard Worker var relPath string 492*333d2b36SAndroid Build Coastguard Worker if cc.Arch().ArchType.Multilib == "lib64" { 493*333d2b36SAndroid Build Coastguard Worker relPath = filepath.Join("lib64", cc.OutputFile().Path().Base()) 494*333d2b36SAndroid Build Coastguard Worker } else { 495*333d2b36SAndroid Build Coastguard Worker relPath = filepath.Join("lib", cc.OutputFile().Path().Base()) 496*333d2b36SAndroid Build Coastguard Worker } 497*333d2b36SAndroid Build Coastguard Worker if _, exist := s.dataModules[relPath]; exist { 498*333d2b36SAndroid Build Coastguard Worker return 499*333d2b36SAndroid Build Coastguard Worker } 500*333d2b36SAndroid Build Coastguard Worker relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) 501*333d2b36SAndroid Build Coastguard Worker ctx.Build(pctx, android.BuildParams{ 502*333d2b36SAndroid Build Coastguard Worker Rule: android.Cp, 503*333d2b36SAndroid Build Coastguard Worker Input: cc.OutputFile().Path(), 504*333d2b36SAndroid Build Coastguard Worker Output: relocatedLib, 505*333d2b36SAndroid Build Coastguard Worker }) 506*333d2b36SAndroid Build Coastguard Worker s.addToDataModules(ctx, relPath, relocatedLib) 507*333d2b36SAndroid Build Coastguard Worker return 508*333d2b36SAndroid Build Coastguard Worker } 509*333d2b36SAndroid Build Coastguard Worker property := "data_libs" 510*333d2b36SAndroid Build Coastguard Worker if depTag == shTestDataDeviceBinsTag { 511*333d2b36SAndroid Build Coastguard Worker property = "data_device_libs" 512*333d2b36SAndroid Build Coastguard Worker } 513*333d2b36SAndroid Build Coastguard Worker ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) 514*333d2b36SAndroid Build Coastguard Worker } 515*333d2b36SAndroid Build Coastguard Worker }) 516*333d2b36SAndroid Build Coastguard Worker 517*333d2b36SAndroid Build Coastguard Worker installedData := ctx.InstallTestData(s.installDir, s.data) 518*333d2b36SAndroid Build Coastguard Worker s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath, installedData...) 519*333d2b36SAndroid Build Coastguard Worker 520*333d2b36SAndroid Build Coastguard Worker mkEntries := s.AndroidMkEntries()[0] 521*333d2b36SAndroid Build Coastguard Worker android.SetProvider(ctx, tradefed.BaseTestProviderKey, tradefed.BaseTestProviderData{ 522*333d2b36SAndroid Build Coastguard Worker TestcaseRelDataFiles: addArch(ctx.Arch().ArchType.String(), installedData.Paths()), 523*333d2b36SAndroid Build Coastguard Worker OutputFile: s.outputFilePath, 524*333d2b36SAndroid Build Coastguard Worker TestConfig: s.testConfig, 525*333d2b36SAndroid Build Coastguard Worker TestSuites: s.testProperties.Test_suites, 526*333d2b36SAndroid Build Coastguard Worker IsHost: false, 527*333d2b36SAndroid Build Coastguard Worker IsUnitTest: Bool(s.testProperties.Test_options.Unit_test), 528*333d2b36SAndroid Build Coastguard Worker MkInclude: mkEntries.Include, 529*333d2b36SAndroid Build Coastguard Worker MkAppClass: mkEntries.Class, 530*333d2b36SAndroid Build Coastguard Worker InstallDir: s.installDir, 531*333d2b36SAndroid Build Coastguard Worker }) 532*333d2b36SAndroid Build Coastguard Worker} 533*333d2b36SAndroid Build Coastguard Worker 534*333d2b36SAndroid Build Coastguard Workerfunc addArch(archType string, paths android.Paths) []string { 535*333d2b36SAndroid Build Coastguard Worker archRelPaths := []string{} 536*333d2b36SAndroid Build Coastguard Worker for _, p := range paths { 537*333d2b36SAndroid Build Coastguard Worker archRelPaths = append(archRelPaths, fmt.Sprintf("%s/%s", archType, p.Rel())) 538*333d2b36SAndroid Build Coastguard Worker } 539*333d2b36SAndroid Build Coastguard Worker return archRelPaths 540*333d2b36SAndroid Build Coastguard Worker} 541*333d2b36SAndroid Build Coastguard Worker 542*333d2b36SAndroid Build Coastguard Workerfunc (s *ShTest) InstallInData() bool { 543*333d2b36SAndroid Build Coastguard Worker return true 544*333d2b36SAndroid Build Coastguard Worker} 545*333d2b36SAndroid Build Coastguard Worker 546*333d2b36SAndroid Build Coastguard Workerfunc (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { 547*333d2b36SAndroid Build Coastguard Worker return []android.AndroidMkEntries{android.AndroidMkEntries{ 548*333d2b36SAndroid Build Coastguard Worker Class: "NATIVE_TESTS", 549*333d2b36SAndroid Build Coastguard Worker OutputFile: android.OptionalPathForPath(s.outputFilePath), 550*333d2b36SAndroid Build Coastguard Worker Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", 551*333d2b36SAndroid Build Coastguard Worker ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 552*333d2b36SAndroid Build Coastguard Worker func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 553*333d2b36SAndroid Build Coastguard Worker s.customAndroidMkEntries(entries) 554*333d2b36SAndroid Build Coastguard Worker entries.SetPath("LOCAL_MODULE_PATH", s.installDir) 555*333d2b36SAndroid Build Coastguard Worker entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...) 556*333d2b36SAndroid Build Coastguard Worker if s.testConfig != nil { 557*333d2b36SAndroid Build Coastguard Worker entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) 558*333d2b36SAndroid Build Coastguard Worker } 559*333d2b36SAndroid Build Coastguard Worker if s.testProperties.Data_bins != nil { 560*333d2b36SAndroid Build Coastguard Worker entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...) 561*333d2b36SAndroid Build Coastguard Worker } 562*333d2b36SAndroid Build Coastguard Worker entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(s.testProperties.Per_testcase_directory)) 563*333d2b36SAndroid Build Coastguard Worker if len(s.extraTestConfigs) > 0 { 564*333d2b36SAndroid Build Coastguard Worker entries.AddStrings("LOCAL_EXTRA_FULL_TEST_CONFIGS", s.extraTestConfigs.Strings()...) 565*333d2b36SAndroid Build Coastguard Worker } 566*333d2b36SAndroid Build Coastguard Worker 567*333d2b36SAndroid Build Coastguard Worker s.testProperties.Test_options.SetAndroidMkEntries(entries) 568*333d2b36SAndroid Build Coastguard Worker }, 569*333d2b36SAndroid Build Coastguard Worker }, 570*333d2b36SAndroid Build Coastguard Worker }} 571*333d2b36SAndroid Build Coastguard Worker} 572*333d2b36SAndroid Build Coastguard Worker 573*333d2b36SAndroid Build Coastguard Workerfunc initShBinaryModule(s *ShBinary) { 574*333d2b36SAndroid Build Coastguard Worker s.AddProperties(&s.properties) 575*333d2b36SAndroid Build Coastguard Worker} 576*333d2b36SAndroid Build Coastguard Worker 577*333d2b36SAndroid Build Coastguard Worker// sh_binary is for a shell script or batch file to be installed as an 578*333d2b36SAndroid Build Coastguard Worker// executable binary to <partition>/bin. 579*333d2b36SAndroid Build Coastguard Workerfunc ShBinaryFactory() android.Module { 580*333d2b36SAndroid Build Coastguard Worker module := &ShBinary{} 581*333d2b36SAndroid Build Coastguard Worker initShBinaryModule(module) 582*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) 583*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 584*333d2b36SAndroid Build Coastguard Worker return module 585*333d2b36SAndroid Build Coastguard Worker} 586*333d2b36SAndroid Build Coastguard Worker 587*333d2b36SAndroid Build Coastguard Worker// sh_binary_host is for a shell script to be installed as an executable binary 588*333d2b36SAndroid Build Coastguard Worker// to $(HOST_OUT)/bin. 589*333d2b36SAndroid Build Coastguard Workerfunc ShBinaryHostFactory() android.Module { 590*333d2b36SAndroid Build Coastguard Worker module := &ShBinary{} 591*333d2b36SAndroid Build Coastguard Worker initShBinaryModule(module) 592*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) 593*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 594*333d2b36SAndroid Build Coastguard Worker return module 595*333d2b36SAndroid Build Coastguard Worker} 596*333d2b36SAndroid Build Coastguard Worker 597*333d2b36SAndroid Build Coastguard Worker// sh_test defines a shell script based test module. 598*333d2b36SAndroid Build Coastguard Workerfunc ShTestFactory() android.Module { 599*333d2b36SAndroid Build Coastguard Worker module := &ShTest{} 600*333d2b36SAndroid Build Coastguard Worker initShBinaryModule(&module.ShBinary) 601*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.testProperties) 602*333d2b36SAndroid Build Coastguard Worker 603*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) 604*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 605*333d2b36SAndroid Build Coastguard Worker return module 606*333d2b36SAndroid Build Coastguard Worker} 607*333d2b36SAndroid Build Coastguard Worker 608*333d2b36SAndroid Build Coastguard Worker// sh_test_host defines a shell script based test module that runs on a host. 609*333d2b36SAndroid Build Coastguard Workerfunc ShTestHostFactory() android.Module { 610*333d2b36SAndroid Build Coastguard Worker module := &ShTest{} 611*333d2b36SAndroid Build Coastguard Worker initShBinaryModule(&module.ShBinary) 612*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&module.testProperties) 613*333d2b36SAndroid Build Coastguard Worker // Default sh_test_host to unit_tests = true 614*333d2b36SAndroid Build Coastguard Worker if module.testProperties.Test_options.Unit_test == nil { 615*333d2b36SAndroid Build Coastguard Worker module.testProperties.Test_options.Unit_test = proptools.BoolPtr(true) 616*333d2b36SAndroid Build Coastguard Worker } 617*333d2b36SAndroid Build Coastguard Worker 618*333d2b36SAndroid Build Coastguard Worker android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) 619*333d2b36SAndroid Build Coastguard Worker android.InitDefaultableModule(module) 620*333d2b36SAndroid Build Coastguard Worker return module 621*333d2b36SAndroid Build Coastguard Worker} 622*333d2b36SAndroid Build Coastguard Worker 623*333d2b36SAndroid Build Coastguard Workertype ShDefaults struct { 624*333d2b36SAndroid Build Coastguard Worker android.ModuleBase 625*333d2b36SAndroid Build Coastguard Worker android.DefaultsModuleBase 626*333d2b36SAndroid Build Coastguard Worker} 627*333d2b36SAndroid Build Coastguard Worker 628*333d2b36SAndroid Build Coastguard Workerfunc ShDefaultsFactory() android.Module { 629*333d2b36SAndroid Build Coastguard Worker module := &ShDefaults{} 630*333d2b36SAndroid Build Coastguard Worker 631*333d2b36SAndroid Build Coastguard Worker module.AddProperties(&shBinaryProperties{}, &TestProperties{}) 632*333d2b36SAndroid Build Coastguard Worker android.InitDefaultsModule(module) 633*333d2b36SAndroid Build Coastguard Worker 634*333d2b36SAndroid Build Coastguard Worker return module 635*333d2b36SAndroid Build Coastguard Worker} 636*333d2b36SAndroid Build Coastguard Worker 637*333d2b36SAndroid Build Coastguard Workervar Bool = proptools.Bool 638