Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 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 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 15 | package sh |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 18 | "path/filepath" |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 19 | "strings" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 20 | |
Aditya Choudhary | 9b59352 | 2023-10-06 19:54:58 +0000 | [diff] [blame] | 21 | "android/soong/testing" |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 22 | |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
| 25 | |
| 26 | "android/soong/android" |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 27 | "android/soong/cc" |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 28 | "android/soong/tradefed" |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | // sh_binary is for shell scripts (and batch files) that are installed as |
| 32 | // executable files into .../bin/ |
| 33 | // |
| 34 | // Do not use them for prebuilt C/C++/etc files. Use cc_prebuilt_binary |
| 35 | // instead. |
| 36 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 37 | var pctx = android.NewPackageContext("android/soong/sh") |
| 38 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 39 | func init() { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 40 | pctx.Import("android/soong/android") |
| 41 | |
Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 42 | registerShBuildComponents(android.InitRegistrationContext) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 45 | func registerShBuildComponents(ctx android.RegistrationContext) { |
| 46 | ctx.RegisterModuleType("sh_binary", ShBinaryFactory) |
| 47 | ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) |
| 48 | ctx.RegisterModuleType("sh_test", ShTestFactory) |
| 49 | ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) |
| 50 | } |
| 51 | |
| 52 | // Test fixture preparer that will register most sh build components. |
| 53 | // |
| 54 | // Singletons and mutators should only be added here if they are needed for a majority of sh |
| 55 | // module types, otherwise they should be added under a separate preparer to allow them to be |
| 56 | // selected only when needed to reduce test execution time. |
| 57 | // |
| 58 | // Module types do not have much of an overhead unless they are used so this should include as many |
| 59 | // module types as possible. The exceptions are those module types that require mutators and/or |
| 60 | // singletons in order to function in which case they should be kept together in a separate |
| 61 | // preparer. |
| 62 | var PrepareForTestWithShBuildComponents = android.GroupFixturePreparers( |
| 63 | android.FixtureRegisterWithContext(registerShBuildComponents), |
| 64 | ) |
| 65 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 66 | type shBinaryProperties struct { |
| 67 | // Source file of this prebuilt. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 68 | Src *string `android:"path,arch_variant"` |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 69 | |
| 70 | // optional subdirectory under which this file is installed into |
| 71 | Sub_dir *string `android:"arch_variant"` |
| 72 | |
| 73 | // optional name for the installed file. If unspecified, name of the module is used as the file name |
| 74 | Filename *string `android:"arch_variant"` |
| 75 | |
| 76 | // when set to true, and filename property is not set, the name for the installed file |
| 77 | // is the same as the file name of the source file. |
| 78 | Filename_from_src *bool `android:"arch_variant"` |
| 79 | |
| 80 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 81 | Installable *bool |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 82 | |
| 83 | // install symlinks to the binary |
| 84 | Symlinks []string `android:"arch_variant"` |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 85 | |
| 86 | // Make this module available when building for ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 87 | // On device without a dedicated recovery partition, the module is only |
| 88 | // available after switching root into |
| 89 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 90 | // the recovery variant instead. |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 91 | Ramdisk_available *bool |
| 92 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 93 | // Make this module available when building for vendor ramdisk. |
Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 94 | // On device without a dedicated recovery partition, the module is only |
| 95 | // available after switching root into |
| 96 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 97 | // the recovery variant instead. |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 98 | Vendor_ramdisk_available *bool |
| 99 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 100 | // Make this module available when building for recovery. |
| 101 | Recovery_available *bool |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 104 | type TestProperties struct { |
| 105 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 106 | // installed into. |
| 107 | Test_suites []string `android:"arch_variant"` |
| 108 | |
| 109 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 110 | // installed with the module. |
Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 111 | Test_config *string `android:"path,arch_variant"` |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 112 | |
| 113 | // list of files or filegroup modules that provide data that should be installed alongside |
| 114 | // the test. |
| 115 | Data []string `android:"path,arch_variant"` |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 116 | |
| 117 | // Add RootTargetPreparer to auto generated test config. This guarantees the test to run |
| 118 | // with root permission. |
| 119 | Require_root *bool |
| 120 | |
| 121 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 122 | // should be installed with the module. |
| 123 | Test_config_template *string `android:"path,arch_variant"` |
| 124 | |
| 125 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 126 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 127 | // explicitly. |
| 128 | Auto_gen_config *bool |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 129 | |
| 130 | // list of binary modules that should be installed alongside the test |
| 131 | Data_bins []string `android:"path,arch_variant"` |
| 132 | |
| 133 | // list of library modules that should be installed alongside the test |
| 134 | Data_libs []string `android:"path,arch_variant"` |
| 135 | |
| 136 | // list of device binary modules that should be installed alongside the test. |
| 137 | // Only available for host sh_test modules. |
| 138 | Data_device_bins []string `android:"path,arch_variant"` |
| 139 | |
| 140 | // list of device library modules that should be installed alongside the test. |
| 141 | // Only available for host sh_test modules. |
| 142 | Data_device_libs []string `android:"path,arch_variant"` |
Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 143 | |
Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 144 | // list of java modules that provide data that should be installed alongside the test. |
| 145 | Java_data []string |
| 146 | |
Jooyung Han | 3ae4cca | 2022-02-22 16:33:24 +0900 | [diff] [blame] | 147 | // Install the test into a folder named for the module in all test suites. |
| 148 | Per_testcase_directory *bool |
| 149 | |
Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 150 | // Test options. |
Zhenhuang Wang | 0ac5a43 | 2022-08-12 18:49:20 +0800 | [diff] [blame] | 151 | Test_options android.CommonTestOptions |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 154 | type ShBinary struct { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 155 | android.ModuleBase |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 156 | |
| 157 | properties shBinaryProperties |
| 158 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 159 | sourceFilePath android.Path |
| 160 | outputFilePath android.OutputPath |
| 161 | installedFile android.InstallPath |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 164 | var _ android.HostToolProvider = (*ShBinary)(nil) |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 165 | |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 166 | type ShTest struct { |
| 167 | ShBinary |
| 168 | |
| 169 | testProperties TestProperties |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 170 | |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 171 | installDir android.InstallPath |
| 172 | |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 173 | data []android.DataPath |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 174 | testConfig android.Path |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 175 | |
| 176 | dataModules map[string]android.Path |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 179 | func (s *ShBinary) HostToolPath() android.OptionalPath { |
| 180 | return android.OptionalPathForPath(s.installedFile) |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 183 | func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 186 | func (s *ShBinary) OutputFile() android.OutputPath { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 187 | return s.outputFilePath |
| 188 | } |
| 189 | |
| 190 | func (s *ShBinary) SubDir() string { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 191 | return proptools.String(s.properties.Sub_dir) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 194 | func (s *ShBinary) RelativeInstallPath() string { |
| 195 | return s.SubDir() |
| 196 | } |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 197 | func (s *ShBinary) Installable() bool { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 198 | return s.properties.Installable == nil || proptools.Bool(s.properties.Installable) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 201 | func (s *ShBinary) Symlinks() []string { |
| 202 | return s.properties.Symlinks |
| 203 | } |
| 204 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 205 | var _ android.ImageInterface = (*ShBinary)(nil) |
| 206 | |
| 207 | func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
| 208 | |
| 209 | func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 210 | return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() |
| 211 | } |
| 212 | |
| 213 | func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 214 | return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk() |
| 215 | } |
| 216 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 217 | func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 218 | return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk() |
| 219 | } |
| 220 | |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 221 | func (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 222 | return false |
| 223 | } |
| 224 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 225 | func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 226 | return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery() |
| 227 | } |
| 228 | |
| 229 | func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
| 234 | } |
| 235 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 236 | func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 237 | if s.properties.Src == nil { |
| 238 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
| 239 | } |
| 240 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 241 | s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src)) |
| 242 | filename := proptools.String(s.properties.Filename) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 243 | filenameFromSrc := proptools.Bool(s.properties.Filename_from_src) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 244 | if filename == "" { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 245 | if filenameFromSrc { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 246 | filename = s.sourceFilePath.Base() |
| 247 | } else { |
| 248 | filename = ctx.ModuleName() |
| 249 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 250 | } else if filenameFromSrc { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 251 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") |
| 252 | return |
| 253 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 254 | s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 255 | |
| 256 | // This ensures that outputFilePath has the correct name for others to |
| 257 | // use, as the source file may have a different name. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 258 | ctx.Build(pctx, android.BuildParams{ |
| 259 | Rule: android.CpExecutable, |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 260 | Output: s.outputFilePath, |
| 261 | Input: s.sourceFilePath, |
| 262 | }) |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 263 | android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: []string{s.sourceFilePath.String()}}) |
mrziwang | 4f58b5f | 2024-06-10 12:58:40 -0700 | [diff] [blame] | 264 | |
| 265 | ctx.SetOutputFiles(android.Paths{s.outputFilePath}, "") |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 268 | func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 269 | s.generateAndroidBuildActions(ctx) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 270 | installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir)) |
Sundong Ahn | a5c5b9c | 2022-01-12 03:29:17 +0000 | [diff] [blame] | 271 | if !s.Installable() { |
| 272 | s.SkipInstall() |
| 273 | } |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 274 | s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath) |
Colin Cross | 94bf518 | 2021-11-09 17:21:14 -0800 | [diff] [blame] | 275 | for _, symlink := range s.Symlinks() { |
| 276 | ctx.InstallSymlink(installDir, symlink, s.installedFile) |
| 277 | } |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 280 | func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { |
| 281 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 282 | Class: "EXECUTABLES", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 283 | OutputFile: android.OptionalPathForPath(s.outputFilePath), |
Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 284 | Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 285 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 286 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 287 | s.customAndroidMkEntries(entries) |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 288 | entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) |
Sundong Ahn | a5c5b9c | 2022-01-12 03:29:17 +0000 | [diff] [blame] | 289 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !s.Installable()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 290 | }, |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 291 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 292 | }} |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 295 | func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) { |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 296 | entries.SetString("LOCAL_MODULE_SUFFIX", "") |
| 297 | entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel()) |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 298 | if len(s.properties.Symlinks) > 0 { |
| 299 | entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " ")) |
| 300 | } |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 303 | type dependencyTag struct { |
| 304 | blueprint.BaseDependencyTag |
| 305 | name string |
| 306 | } |
| 307 | |
| 308 | var ( |
| 309 | shTestDataBinsTag = dependencyTag{name: "dataBins"} |
| 310 | shTestDataLibsTag = dependencyTag{name: "dataLibs"} |
| 311 | shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} |
| 312 | shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"} |
Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 313 | shTestJavaDataTag = dependencyTag{name: "javaData"} |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 314 | ) |
| 315 | |
| 316 | var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}} |
| 317 | |
| 318 | func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 319 | s.ShBinary.DepsMutator(ctx) |
| 320 | |
| 321 | ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...) |
| 322 | ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...), |
| 323 | shTestDataLibsTag, s.testProperties.Data_libs...) |
Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 324 | if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 { |
Jaewoong Jung | 642916f | 2020-10-09 17:25:15 -0700 | [diff] [blame] | 325 | deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 326 | ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...) |
| 327 | ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...), |
| 328 | shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...) |
Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 329 | |
| 330 | javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}} |
| 331 | ctx.AddVariationDependencies(javaDataVariation, shTestJavaDataTag, s.testProperties.Java_data...) |
| 332 | |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 333 | } else if ctx.Target().Os.Class != android.Host { |
| 334 | if len(s.testProperties.Data_device_bins) > 0 { |
| 335 | ctx.PropertyErrorf("data_device_bins", "only available for host modules") |
| 336 | } |
| 337 | if len(s.testProperties.Data_device_libs) > 0 { |
| 338 | ctx.PropertyErrorf("data_device_libs", "only available for host modules") |
| 339 | } |
Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 340 | if len(s.testProperties.Java_data) > 0 { |
| 341 | ctx.PropertyErrorf("Java_data", "only available for host modules") |
| 342 | } |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| 346 | func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) { |
| 347 | if _, exists := s.dataModules[relPath]; exists { |
| 348 | ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s", |
| 349 | relPath, s.dataModules[relPath].String(), path.String()) |
| 350 | return |
| 351 | } |
| 352 | s.dataModules[relPath] = path |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 353 | s.data = append(s.data, android.DataPath{SrcPath: path}) |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 356 | func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 357 | s.ShBinary.generateAndroidBuildActions(ctx) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 358 | |
| 359 | expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data) |
| 360 | // Emulate the data property for java_data dependencies. |
| 361 | for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) { |
| 362 | expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) |
| 363 | } |
| 364 | for _, d := range expandedData { |
| 365 | s.data = append(s.data, android.DataPath{SrcPath: d}) |
| 366 | } |
| 367 | |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 368 | testDir := "nativetest" |
| 369 | if ctx.Target().Arch.ArchType.Multilib == "lib64" { |
| 370 | testDir = "nativetest64" |
| 371 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 372 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 373 | testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath) |
| 374 | } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { |
| 375 | testDir = filepath.Join(testDir, ctx.Arch().ArchType.String()) |
| 376 | } |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 377 | if s.SubDir() != "" { |
| 378 | // Don't add the module name to the installation path if sub_dir is specified for backward |
| 379 | // compatibility. |
| 380 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir()) |
| 381 | } else { |
| 382 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name()) |
| 383 | } |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 384 | |
| 385 | var configs []tradefed.Config |
| 386 | if Bool(s.testProperties.Require_root) { |
| 387 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) |
| 388 | } else { |
| 389 | options := []tradefed.Option{{Name: "force-root", Value: "false"}} |
| 390 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) |
| 391 | } |
frankfeng | be6ae77 | 2020-09-28 13:22:57 -0700 | [diff] [blame] | 392 | if len(s.testProperties.Data_device_bins) > 0 { |
| 393 | moduleName := s.Name() |
| 394 | remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/" |
| 395 | options := []tradefed.Option{{Name: "cleanup", Value: "true"}} |
| 396 | for _, bin := range s.testProperties.Data_device_bins { |
| 397 | options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin}) |
| 398 | } |
| 399 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) |
| 400 | } |
Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 401 | s.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ |
| 402 | TestConfigProp: s.testProperties.Test_config, |
| 403 | TestConfigTemplateProp: s.testProperties.Test_config_template, |
| 404 | TestSuites: s.testProperties.Test_suites, |
| 405 | Config: configs, |
| 406 | AutoGenConfig: s.testProperties.Auto_gen_config, |
| 407 | OutputFileName: s.outputFilePath.Base(), |
| 408 | DeviceTemplate: "${ShellTestConfigTemplate}", |
| 409 | HostTemplate: "${ShellTestConfigTemplate}", |
| 410 | }) |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 411 | |
| 412 | s.dataModules = make(map[string]android.Path) |
| 413 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 414 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 415 | switch depTag { |
| 416 | case shTestDataBinsTag, shTestDataDeviceBinsTag: |
Anton Hansson | 2f6422c | 2020-12-31 13:42:10 +0000 | [diff] [blame] | 417 | path := android.OutputFileForModule(ctx, dep, "") |
| 418 | s.addToDataModules(ctx, path.Base(), path) |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 419 | case shTestDataLibsTag, shTestDataDeviceLibsTag: |
| 420 | if cc, isCc := dep.(*cc.Module); isCc { |
| 421 | // Copy to an intermediate output directory to append "lib[64]" to the path, |
| 422 | // so that it's compatible with the default rpath values. |
| 423 | var relPath string |
| 424 | if cc.Arch().ArchType.Multilib == "lib64" { |
| 425 | relPath = filepath.Join("lib64", cc.OutputFile().Path().Base()) |
| 426 | } else { |
| 427 | relPath = filepath.Join("lib", cc.OutputFile().Path().Base()) |
| 428 | } |
| 429 | if _, exist := s.dataModules[relPath]; exist { |
| 430 | return |
| 431 | } |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 432 | relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 433 | ctx.Build(pctx, android.BuildParams{ |
| 434 | Rule: android.Cp, |
| 435 | Input: cc.OutputFile().Path(), |
| 436 | Output: relocatedLib, |
| 437 | }) |
| 438 | s.addToDataModules(ctx, relPath, relocatedLib) |
| 439 | return |
| 440 | } |
| 441 | property := "data_libs" |
| 442 | if depTag == shTestDataDeviceBinsTag { |
| 443 | property = "data_device_libs" |
| 444 | } |
| 445 | ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) |
| 446 | } |
| 447 | }) |
Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 448 | |
| 449 | installedData := ctx.InstallTestData(s.installDir, s.data) |
| 450 | s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath, installedData...) |
| 451 | |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 452 | android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{}) |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 455 | func (s *ShTest) InstallInData() bool { |
| 456 | return true |
| 457 | } |
| 458 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 459 | func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { |
| 460 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 461 | Class: "NATIVE_TESTS", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 462 | OutputFile: android.OptionalPathForPath(s.outputFilePath), |
Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 463 | Include: "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 464 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 465 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 466 | s.customAndroidMkEntries(entries) |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 467 | entries.SetPath("LOCAL_MODULE_PATH", s.installDir) |
Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 468 | entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...) |
Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 469 | if s.testConfig != nil { |
| 470 | entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 471 | } |
yangbill | 22bafec | 2022-02-11 18:06:07 +0800 | [diff] [blame] | 472 | if s.testProperties.Data_bins != nil { |
| 473 | entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...) |
| 474 | } |
Jooyung Han | 3ae4cca | 2022-02-22 16:33:24 +0900 | [diff] [blame] | 475 | entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(s.testProperties.Per_testcase_directory)) |
Zhenhuang Wang | 0ac5a43 | 2022-08-12 18:49:20 +0800 | [diff] [blame] | 476 | |
| 477 | s.testProperties.Test_options.SetAndroidMkEntries(entries) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 478 | }, |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 479 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 480 | }} |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 483 | func initShBinaryModule(s *ShBinary) { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 484 | s.AddProperties(&s.properties) |
| 485 | } |
| 486 | |
Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 487 | // sh_binary is for a shell script or batch file to be installed as an |
| 488 | // executable binary to <partition>/bin. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 489 | func ShBinaryFactory() android.Module { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 490 | module := &ShBinary{} |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 491 | initShBinaryModule(module) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 492 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 493 | return module |
| 494 | } |
| 495 | |
Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 496 | // sh_binary_host is for a shell script to be installed as an executable binary |
| 497 | // to $(HOST_OUT)/bin. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 498 | func ShBinaryHostFactory() android.Module { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 499 | module := &ShBinary{} |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 500 | initShBinaryModule(module) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 501 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 502 | return module |
| 503 | } |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 504 | |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 505 | // sh_test defines a shell script based test module. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 506 | func ShTestFactory() android.Module { |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 507 | module := &ShTest{} |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 508 | initShBinaryModule(&module.ShBinary) |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 509 | module.AddProperties(&module.testProperties) |
| 510 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 511 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 512 | return module |
| 513 | } |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 514 | |
| 515 | // sh_test_host defines a shell script based test module that runs on a host. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 516 | func ShTestHostFactory() android.Module { |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 517 | module := &ShTest{} |
Colin Cross | 8ff1058 | 2023-12-07 13:10:56 -0800 | [diff] [blame] | 518 | initShBinaryModule(&module.ShBinary) |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 519 | module.AddProperties(&module.testProperties) |
Julien Desprez | 06f1399 | 2021-06-28 13:41:43 -0700 | [diff] [blame] | 520 | // Default sh_test_host to unit_tests = true |
| 521 | if module.testProperties.Test_options.Unit_test == nil { |
| 522 | module.testProperties.Test_options.Unit_test = proptools.BoolPtr(true) |
| 523 | } |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 524 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 525 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 526 | return module |
| 527 | } |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 528 | |
| 529 | var Bool = proptools.Bool |