| 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 ( | 
|  | 18 | "fmt" | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 19 | "path/filepath" | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 20 | "sort" | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 21 | "strings" | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [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" | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 27 | "android/soong/bazel" | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 28 | "android/soong/cc" | 
| Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 29 | "android/soong/snapshot" | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 30 | "android/soong/tradefed" | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 31 | ) | 
|  | 32 |  | 
|  | 33 | // sh_binary is for shell scripts (and batch files) that are installed as | 
|  | 34 | // executable files into .../bin/ | 
|  | 35 | // | 
|  | 36 | // Do not use them for prebuilt C/C++/etc files.  Use cc_prebuilt_binary | 
|  | 37 | // instead. | 
|  | 38 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 39 | var pctx = android.NewPackageContext("android/soong/sh") | 
|  | 40 |  | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 41 | func init() { | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 42 | pctx.Import("android/soong/android") | 
|  | 43 |  | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 44 | registerShBuildComponents(android.InitRegistrationContext) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 45 | } | 
|  | 46 |  | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 47 | func registerShBuildComponents(ctx android.RegistrationContext) { | 
|  | 48 | ctx.RegisterModuleType("sh_binary", ShBinaryFactory) | 
|  | 49 | ctx.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) | 
|  | 50 | ctx.RegisterModuleType("sh_test", ShTestFactory) | 
|  | 51 | ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | // Test fixture preparer that will register most sh build components. | 
|  | 55 | // | 
|  | 56 | // Singletons and mutators should only be added here if they are needed for a majority of sh | 
|  | 57 | // module types, otherwise they should be added under a separate preparer to allow them to be | 
|  | 58 | // selected only when needed to reduce test execution time. | 
|  | 59 | // | 
|  | 60 | // Module types do not have much of an overhead unless they are used so this should include as many | 
|  | 61 | // module types as possible. The exceptions are those module types that require mutators and/or | 
|  | 62 | // singletons in order to function in which case they should be kept together in a separate | 
|  | 63 | // preparer. | 
|  | 64 | var PrepareForTestWithShBuildComponents = android.GroupFixturePreparers( | 
|  | 65 | android.FixtureRegisterWithContext(registerShBuildComponents), | 
|  | 66 | ) | 
|  | 67 |  | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 68 | type shBinaryProperties struct { | 
|  | 69 | // Source file of this prebuilt. | 
| Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 70 | Src *string `android:"path,arch_variant"` | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 71 |  | 
|  | 72 | // optional subdirectory under which this file is installed into | 
|  | 73 | Sub_dir *string `android:"arch_variant"` | 
|  | 74 |  | 
|  | 75 | // optional name for the installed file. If unspecified, name of the module is used as the file name | 
|  | 76 | Filename *string `android:"arch_variant"` | 
|  | 77 |  | 
|  | 78 | // when set to true, and filename property is not set, the name for the installed file | 
|  | 79 | // is the same as the file name of the source file. | 
|  | 80 | Filename_from_src *bool `android:"arch_variant"` | 
|  | 81 |  | 
|  | 82 | // Whether this module is directly installable to one of the partitions. Default: true. | 
|  | 83 | Installable *bool | 
| Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | // install symlinks to the binary | 
|  | 86 | Symlinks []string `android:"arch_variant"` | 
| Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 87 |  | 
|  | 88 | // Make this module available when building for ramdisk. | 
| Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 89 | // On device without a dedicated recovery partition, the module is only | 
|  | 90 | // available after switching root into | 
|  | 91 | // /first_stage_ramdisk. To expose the module before switching root, install | 
|  | 92 | // the recovery variant instead. | 
| Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 93 | Ramdisk_available *bool | 
|  | 94 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 95 | // Make this module available when building for vendor ramdisk. | 
| Yifan Hong | 39143a9 | 2020-10-26 12:43:12 -0700 | [diff] [blame] | 96 | // On device without a dedicated recovery partition, the module is only | 
|  | 97 | // available after switching root into | 
|  | 98 | // /first_stage_ramdisk. To expose the module before switching root, install | 
|  | 99 | // the recovery variant instead. | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 100 | Vendor_ramdisk_available *bool | 
|  | 101 |  | 
| Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 102 | // Make this module available when building for recovery. | 
|  | 103 | Recovery_available *bool | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 106 | type TestProperties struct { | 
|  | 107 | // list of compatibility suites (for example "cts", "vts") that the module should be | 
|  | 108 | // installed into. | 
|  | 109 | Test_suites []string `android:"arch_variant"` | 
|  | 110 |  | 
|  | 111 | // the name of the test configuration (for example "AndroidTest.xml") that should be | 
|  | 112 | // installed with the module. | 
| Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 113 | Test_config *string `android:"path,arch_variant"` | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 114 |  | 
|  | 115 | // list of files or filegroup modules that provide data that should be installed alongside | 
|  | 116 | // the test. | 
|  | 117 | Data []string `android:"path,arch_variant"` | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | // Add RootTargetPreparer to auto generated test config. This guarantees the test to run | 
|  | 120 | // with root permission. | 
|  | 121 | Require_root *bool | 
|  | 122 |  | 
|  | 123 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that | 
|  | 124 | // should be installed with the module. | 
|  | 125 | Test_config_template *string `android:"path,arch_variant"` | 
|  | 126 |  | 
|  | 127 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml | 
|  | 128 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true | 
|  | 129 | // explicitly. | 
|  | 130 | Auto_gen_config *bool | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 131 |  | 
|  | 132 | // list of binary modules that should be installed alongside the test | 
|  | 133 | Data_bins []string `android:"path,arch_variant"` | 
|  | 134 |  | 
|  | 135 | // list of library modules that should be installed alongside the test | 
|  | 136 | Data_libs []string `android:"path,arch_variant"` | 
|  | 137 |  | 
|  | 138 | // list of device binary modules that should be installed alongside the test. | 
|  | 139 | // Only available for host sh_test modules. | 
|  | 140 | Data_device_bins []string `android:"path,arch_variant"` | 
|  | 141 |  | 
|  | 142 | // list of device library modules that should be installed alongside the test. | 
|  | 143 | // Only available for host sh_test modules. | 
|  | 144 | Data_device_libs []string `android:"path,arch_variant"` | 
| Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 145 |  | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 146 | // list of java modules that provide data that should be installed alongside the test. | 
|  | 147 | Java_data []string | 
|  | 148 |  | 
| Jooyung Han | 3ae4cca | 2022-02-22 16:33:24 +0900 | [diff] [blame] | 149 | // Install the test into a folder named for the module in all test suites. | 
|  | 150 | Per_testcase_directory *bool | 
|  | 151 |  | 
| Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 152 | // Test options. | 
| Zhenhuang Wang | 0ac5a43 | 2022-08-12 18:49:20 +0800 | [diff] [blame] | 153 | Test_options android.CommonTestOptions | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 156 | type ShBinary struct { | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 157 | android.ModuleBase | 
| Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 158 | android.BazelModuleBase | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 159 |  | 
|  | 160 | properties shBinaryProperties | 
|  | 161 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 162 | sourceFilePath android.Path | 
|  | 163 | outputFilePath android.OutputPath | 
|  | 164 | installedFile  android.InstallPath | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 165 | } | 
|  | 166 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 167 | var _ android.HostToolProvider = (*ShBinary)(nil) | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 168 |  | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 169 | type ShTest struct { | 
|  | 170 | ShBinary | 
|  | 171 |  | 
|  | 172 | testProperties TestProperties | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 173 |  | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 174 | installDir android.InstallPath | 
|  | 175 |  | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 176 | data       android.Paths | 
|  | 177 | testConfig android.Path | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 178 |  | 
|  | 179 | dataModules map[string]android.Path | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 182 | func (s *ShBinary) HostToolPath() android.OptionalPath { | 
|  | 183 | return android.OptionalPathForPath(s.installedFile) | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 184 | } | 
|  | 185 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 186 | func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 189 | func (s *ShBinary) OutputFile() android.OutputPath { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 190 | return s.outputFilePath | 
|  | 191 | } | 
|  | 192 |  | 
| Edward Liaw | 492ca05 | 2023-08-07 19:03:22 +0000 | [diff] [blame] | 193 | func (s *ShBinary) OutputFiles(tag string) (android.Paths, error) { | 
|  | 194 | switch tag { | 
|  | 195 | case "": | 
|  | 196 | return android.Paths{s.outputFilePath}, nil | 
|  | 197 | default: | 
|  | 198 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 199 | } | 
|  | 200 | } | 
|  | 201 |  | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 202 | func (s *ShBinary) SubDir() string { | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 203 | return proptools.String(s.properties.Sub_dir) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 204 | } | 
|  | 205 |  | 
| Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 206 | func (s *ShBinary) RelativeInstallPath() string { | 
|  | 207 | return s.SubDir() | 
|  | 208 | } | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 209 | func (s *ShBinary) Installable() bool { | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 210 | return s.properties.Installable == nil || proptools.Bool(s.properties.Installable) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
| Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 213 | func (s *ShBinary) Symlinks() []string { | 
|  | 214 | return s.properties.Symlinks | 
|  | 215 | } | 
|  | 216 |  | 
| Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 217 | var _ android.ImageInterface = (*ShBinary)(nil) | 
|  | 218 |  | 
|  | 219 | func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {} | 
|  | 220 |  | 
|  | 221 | func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 222 | return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 226 | return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk() | 
|  | 227 | } | 
|  | 228 |  | 
| Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 229 | func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 230 | return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk() | 
|  | 231 | } | 
|  | 232 |  | 
| Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 233 | func (s *ShBinary) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 234 | return false | 
|  | 235 | } | 
|  | 236 |  | 
| Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 237 | func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 238 | return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery() | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string { | 
|  | 242 | return nil | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { | 
|  | 246 | } | 
|  | 247 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 248 | func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 249 | if s.properties.Src == nil { | 
|  | 250 | ctx.PropertyErrorf("src", "missing prebuilt source file") | 
|  | 251 | } | 
|  | 252 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 253 | s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src)) | 
|  | 254 | filename := proptools.String(s.properties.Filename) | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 255 | filenameFromSrc := proptools.Bool(s.properties.Filename_from_src) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 256 | if filename == "" { | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 257 | if filenameFromSrc { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 258 | filename = s.sourceFilePath.Base() | 
|  | 259 | } else { | 
|  | 260 | filename = ctx.ModuleName() | 
|  | 261 | } | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 262 | } else if filenameFromSrc { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 263 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") | 
|  | 264 | return | 
|  | 265 | } | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 266 | s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 267 |  | 
|  | 268 | // This ensures that outputFilePath has the correct name for others to | 
|  | 269 | // use, as the source file may have a different name. | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 270 | ctx.Build(pctx, android.BuildParams{ | 
|  | 271 | Rule:   android.CpExecutable, | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 272 | Output: s.outputFilePath, | 
|  | 273 | Input:  s.sourceFilePath, | 
|  | 274 | }) | 
|  | 275 | } | 
|  | 276 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 277 | func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 278 | s.generateAndroidBuildActions(ctx) | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 279 | installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir)) | 
| Sundong Ahn | a5c5b9c | 2022-01-12 03:29:17 +0000 | [diff] [blame] | 280 | if !s.Installable() { | 
|  | 281 | s.SkipInstall() | 
|  | 282 | } | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 283 | s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath) | 
| Colin Cross | 94bf518 | 2021-11-09 17:21:14 -0800 | [diff] [blame] | 284 | for _, symlink := range s.Symlinks() { | 
|  | 285 | ctx.InstallSymlink(installDir, symlink, s.installedFile) | 
|  | 286 | } | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 287 | } | 
|  | 288 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 289 | func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { | 
|  | 290 | return []android.AndroidMkEntries{android.AndroidMkEntries{ | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 291 | Class:      "EXECUTABLES", | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 292 | OutputFile: android.OptionalPathForPath(s.outputFilePath), | 
| Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 293 | Include:    "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 294 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 295 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 296 | s.customAndroidMkEntries(entries) | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 297 | entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) | 
| Sundong Ahn | a5c5b9c | 2022-01-12 03:29:17 +0000 | [diff] [blame] | 298 | entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !s.Installable()) | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 299 | }, | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 300 | }, | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 301 | }} | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 302 | } | 
|  | 303 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 304 | func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) { | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 305 | entries.SetString("LOCAL_MODULE_SUFFIX", "") | 
|  | 306 | entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel()) | 
| Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 307 | if len(s.properties.Symlinks) > 0 { | 
|  | 308 | entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " ")) | 
|  | 309 | } | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 310 | } | 
|  | 311 |  | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 312 | type dependencyTag struct { | 
|  | 313 | blueprint.BaseDependencyTag | 
|  | 314 | name string | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | var ( | 
|  | 318 | shTestDataBinsTag       = dependencyTag{name: "dataBins"} | 
|  | 319 | shTestDataLibsTag       = dependencyTag{name: "dataLibs"} | 
|  | 320 | shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} | 
|  | 321 | shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"} | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 322 | shTestJavaDataTag       = dependencyTag{name: "javaData"} | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 323 | ) | 
|  | 324 |  | 
|  | 325 | var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}} | 
|  | 326 |  | 
|  | 327 | func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 328 | s.ShBinary.DepsMutator(ctx) | 
|  | 329 |  | 
|  | 330 | ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...) | 
|  | 331 | ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...), | 
|  | 332 | shTestDataLibsTag, s.testProperties.Data_libs...) | 
| Liz Kammer | 3bf97bd | 2022-04-26 09:38:20 -0400 | [diff] [blame] | 333 | 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] | 334 | deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 335 | ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...) | 
|  | 336 | ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...), | 
|  | 337 | shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...) | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 338 |  | 
|  | 339 | javaDataVariation := []blueprint.Variation{{"arch", android.Common.String()}} | 
|  | 340 | ctx.AddVariationDependencies(javaDataVariation, shTestJavaDataTag, s.testProperties.Java_data...) | 
|  | 341 |  | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 342 | } else if ctx.Target().Os.Class != android.Host { | 
|  | 343 | if len(s.testProperties.Data_device_bins) > 0 { | 
|  | 344 | ctx.PropertyErrorf("data_device_bins", "only available for host modules") | 
|  | 345 | } | 
|  | 346 | if len(s.testProperties.Data_device_libs) > 0 { | 
|  | 347 | ctx.PropertyErrorf("data_device_libs", "only available for host modules") | 
|  | 348 | } | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 349 | if len(s.testProperties.Java_data) > 0 { | 
|  | 350 | ctx.PropertyErrorf("Java_data", "only available for host modules") | 
|  | 351 | } | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 352 | } | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) { | 
|  | 356 | if _, exists := s.dataModules[relPath]; exists { | 
|  | 357 | ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s", | 
|  | 358 | relPath, s.dataModules[relPath].String(), path.String()) | 
|  | 359 | return | 
|  | 360 | } | 
|  | 361 | s.dataModules[relPath] = path | 
|  | 362 | } | 
|  | 363 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 364 | func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 365 | s.ShBinary.generateAndroidBuildActions(ctx) | 
|  | 366 | testDir := "nativetest" | 
|  | 367 | if ctx.Target().Arch.ArchType.Multilib == "lib64" { | 
|  | 368 | testDir = "nativetest64" | 
|  | 369 | } | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 370 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 371 | testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath) | 
|  | 372 | } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { | 
|  | 373 | testDir = filepath.Join(testDir, ctx.Arch().ArchType.String()) | 
|  | 374 | } | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 375 | if s.SubDir() != "" { | 
|  | 376 | // Don't add the module name to the installation path if sub_dir is specified for backward | 
|  | 377 | // compatibility. | 
|  | 378 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir()) | 
|  | 379 | } else { | 
|  | 380 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name()) | 
|  | 381 | } | 
|  | 382 | s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath) | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 383 |  | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 384 | expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data) | 
|  | 385 |  | 
|  | 386 | // Emulate the data property for java_data dependencies. | 
|  | 387 | for _, javaData := range ctx.GetDirectDepsWithTag(shTestJavaDataTag) { | 
|  | 388 | expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) | 
|  | 389 | } | 
|  | 390 | s.data = expandedData | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 391 |  | 
|  | 392 | var configs []tradefed.Config | 
|  | 393 | if Bool(s.testProperties.Require_root) { | 
|  | 394 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) | 
|  | 395 | } else { | 
|  | 396 | options := []tradefed.Option{{Name: "force-root", Value: "false"}} | 
|  | 397 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) | 
|  | 398 | } | 
| frankfeng | be6ae77 | 2020-09-28 13:22:57 -0700 | [diff] [blame] | 399 | if len(s.testProperties.Data_device_bins) > 0 { | 
|  | 400 | moduleName := s.Name() | 
|  | 401 | remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/" | 
|  | 402 | options := []tradefed.Option{{Name: "cleanup", Value: "true"}} | 
|  | 403 | for _, bin := range s.testProperties.Data_device_bins { | 
|  | 404 | options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin}) | 
|  | 405 | } | 
|  | 406 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) | 
|  | 407 | } | 
| Cole Faust | 2168054 | 2022-12-07 18:18:37 -0800 | [diff] [blame] | 408 | s.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ | 
|  | 409 | TestConfigProp:         s.testProperties.Test_config, | 
|  | 410 | TestConfigTemplateProp: s.testProperties.Test_config_template, | 
|  | 411 | TestSuites:             s.testProperties.Test_suites, | 
|  | 412 | Config:                 configs, | 
|  | 413 | AutoGenConfig:          s.testProperties.Auto_gen_config, | 
|  | 414 | OutputFileName:         s.outputFilePath.Base(), | 
|  | 415 | DeviceTemplate:         "${ShellTestConfigTemplate}", | 
|  | 416 | HostTemplate:           "${ShellTestConfigTemplate}", | 
|  | 417 | }) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 418 |  | 
|  | 419 | s.dataModules = make(map[string]android.Path) | 
|  | 420 | ctx.VisitDirectDeps(func(dep android.Module) { | 
|  | 421 | depTag := ctx.OtherModuleDependencyTag(dep) | 
|  | 422 | switch depTag { | 
|  | 423 | case shTestDataBinsTag, shTestDataDeviceBinsTag: | 
| Anton Hansson | 2f6422c | 2020-12-31 13:42:10 +0000 | [diff] [blame] | 424 | path := android.OutputFileForModule(ctx, dep, "") | 
|  | 425 | s.addToDataModules(ctx, path.Base(), path) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 426 | case shTestDataLibsTag, shTestDataDeviceLibsTag: | 
|  | 427 | if cc, isCc := dep.(*cc.Module); isCc { | 
|  | 428 | // Copy to an intermediate output directory to append "lib[64]" to the path, | 
|  | 429 | // so that it's compatible with the default rpath values. | 
|  | 430 | var relPath string | 
|  | 431 | if cc.Arch().ArchType.Multilib == "lib64" { | 
|  | 432 | relPath = filepath.Join("lib64", cc.OutputFile().Path().Base()) | 
|  | 433 | } else { | 
|  | 434 | relPath = filepath.Join("lib", cc.OutputFile().Path().Base()) | 
|  | 435 | } | 
|  | 436 | if _, exist := s.dataModules[relPath]; exist { | 
|  | 437 | return | 
|  | 438 | } | 
|  | 439 | relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath) | 
|  | 440 | ctx.Build(pctx, android.BuildParams{ | 
|  | 441 | Rule:   android.Cp, | 
|  | 442 | Input:  cc.OutputFile().Path(), | 
|  | 443 | Output: relocatedLib, | 
|  | 444 | }) | 
|  | 445 | s.addToDataModules(ctx, relPath, relocatedLib) | 
|  | 446 | return | 
|  | 447 | } | 
|  | 448 | property := "data_libs" | 
|  | 449 | if depTag == shTestDataDeviceBinsTag { | 
|  | 450 | property = "data_device_libs" | 
|  | 451 | } | 
|  | 452 | ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) | 
|  | 453 | } | 
|  | 454 | }) | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 455 | } | 
|  | 456 |  | 
| Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 457 | func (s *ShTest) InstallInData() bool { | 
|  | 458 | return true | 
|  | 459 | } | 
|  | 460 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 461 | func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { | 
|  | 462 | return []android.AndroidMkEntries{android.AndroidMkEntries{ | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 463 | Class:      "NATIVE_TESTS", | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 464 | OutputFile: android.OptionalPathForPath(s.outputFilePath), | 
| Ivan Lozano | d06cc74 | 2021-11-12 13:27:58 -0500 | [diff] [blame] | 465 | Include:    "$(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk", | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 466 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 467 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 468 | s.customAndroidMkEntries(entries) | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 469 | entries.SetPath("LOCAL_MODULE_PATH", s.installDir) | 
| Liz Kammer | 57f5b33 | 2020-11-24 12:42:58 -0800 | [diff] [blame] | 470 | entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...) | 
| Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 471 | if s.testConfig != nil { | 
|  | 472 | entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 473 | } | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 474 | for _, d := range s.data { | 
|  | 475 | rel := d.Rel() | 
|  | 476 | path := d.String() | 
|  | 477 | if !strings.HasSuffix(path, rel) { | 
|  | 478 | panic(fmt.Errorf("path %q does not end with %q", path, rel)) | 
|  | 479 | } | 
|  | 480 | path = strings.TrimSuffix(path, rel) | 
|  | 481 | entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel) | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 482 | } | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 483 | relPaths := make([]string, 0) | 
|  | 484 | for relPath, _ := range s.dataModules { | 
|  | 485 | relPaths = append(relPaths, relPath) | 
|  | 486 | } | 
|  | 487 | sort.Strings(relPaths) | 
|  | 488 | for _, relPath := range relPaths { | 
|  | 489 | dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath) | 
|  | 490 | entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath) | 
|  | 491 | } | 
| yangbill | 22bafec | 2022-02-11 18:06:07 +0800 | [diff] [blame] | 492 | if s.testProperties.Data_bins != nil { | 
|  | 493 | entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...) | 
|  | 494 | } | 
| Jooyung Han | 3ae4cca | 2022-02-22 16:33:24 +0900 | [diff] [blame] | 495 | 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] | 496 |  | 
|  | 497 | s.testProperties.Test_options.SetAndroidMkEntries(entries) | 
| Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 498 | }, | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 499 | }, | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 500 | }} | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 501 | } | 
|  | 502 |  | 
| Liz Kammer | 9b2ca5c | 2023-04-28 17:39:24 -0400 | [diff] [blame] | 503 | func initShBinaryModule(s *ShBinary, useBazel bool) { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 504 | s.AddProperties(&s.properties) | 
| Liz Kammer | 9b2ca5c | 2023-04-28 17:39:24 -0400 | [diff] [blame] | 505 | if useBazel { | 
|  | 506 | android.InitBazelModule(s) | 
|  | 507 | } | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 508 | } | 
|  | 509 |  | 
| Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 510 | // sh_binary is for a shell script or batch file to be installed as an | 
|  | 511 | // executable binary to <partition>/bin. | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 512 | func ShBinaryFactory() android.Module { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 513 | module := &ShBinary{} | 
| Liz Kammer | 9b2ca5c | 2023-04-28 17:39:24 -0400 | [diff] [blame] | 514 | initShBinaryModule(module, true) | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 515 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 516 | return module | 
|  | 517 | } | 
|  | 518 |  | 
| Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 519 | // sh_binary_host is for a shell script to be installed as an executable binary | 
|  | 520 | // to $(HOST_OUT)/bin. | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 521 | func ShBinaryHostFactory() android.Module { | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 522 | module := &ShBinary{} | 
| Liz Kammer | 9b2ca5c | 2023-04-28 17:39:24 -0400 | [diff] [blame] | 523 | initShBinaryModule(module, true) | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 524 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) | 
| Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 525 | return module | 
|  | 526 | } | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 527 |  | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 528 | // sh_test defines a shell script based test module. | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 529 | func ShTestFactory() android.Module { | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 530 | module := &ShTest{} | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 531 | initShBinaryModule(&module.ShBinary, true) | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 532 | module.AddProperties(&module.testProperties) | 
|  | 533 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 534 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) | 
| Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 535 | return module | 
|  | 536 | } | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 537 |  | 
|  | 538 | // 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] | 539 | func ShTestHostFactory() android.Module { | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 540 | module := &ShTest{} | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 541 | initShBinaryModule(&module.ShBinary, true) | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 542 | module.AddProperties(&module.testProperties) | 
| Julien Desprez | 06f1399 | 2021-06-28 13:41:43 -0700 | [diff] [blame] | 543 | // Default sh_test_host to unit_tests = true | 
|  | 544 | if module.testProperties.Test_options.Unit_test == nil { | 
|  | 545 | module.testProperties.Test_options.Unit_test = proptools.BoolPtr(true) | 
|  | 546 | } | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 547 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 548 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 549 | return module | 
|  | 550 | } | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 551 |  | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 552 | type bazelShBinaryAttributes struct { | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 553 | Srcs     bazel.LabelListAttribute | 
| Liz Kammer | 48c6ead | 2021-12-21 15:36:11 -0500 | [diff] [blame] | 554 | Filename *string | 
|  | 555 | Sub_dir  *string | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 556 | // Bazel also supports the attributes below, but (so far) these are not required for Bionic | 
|  | 557 | // deps | 
|  | 558 | // data | 
|  | 559 | // args | 
|  | 560 | // compatible_with | 
|  | 561 | // deprecation | 
|  | 562 | // distribs | 
|  | 563 | // env | 
|  | 564 | // exec_compatible_with | 
|  | 565 | // exec_properties | 
|  | 566 | // features | 
|  | 567 | // licenses | 
|  | 568 | // output_licenses | 
|  | 569 | // restricted_to | 
|  | 570 | // tags | 
|  | 571 | // target_compatible_with | 
|  | 572 | // testonly | 
|  | 573 | // toolchains | 
|  | 574 | // visibility | 
|  | 575 | } | 
|  | 576 |  | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 577 | type bazelShTestAttributes struct { | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 578 | Srcs      bazel.LabelListAttribute | 
|  | 579 | Data      bazel.LabelListAttribute | 
|  | 580 | Data_bins bazel.LabelListAttribute | 
|  | 581 | Tags      bazel.StringListAttribute | 
|  | 582 | Runs_on   bazel.StringListAttribute | 
|  | 583 | tradefed.TestConfigAttributes | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 584 | } | 
|  | 585 |  | 
| Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 586 | func (m *ShBinary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { | 
| Jingwen Chen | 0702791 | 2021-03-15 06:02:43 -0400 | [diff] [blame] | 587 | srcs := bazel.MakeLabelListAttribute( | 
|  | 588 | android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src})) | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 589 |  | 
| Liz Kammer | 48c6ead | 2021-12-21 15:36:11 -0500 | [diff] [blame] | 590 | var filename *string | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 591 | if m.properties.Filename != nil { | 
| Liz Kammer | 48c6ead | 2021-12-21 15:36:11 -0500 | [diff] [blame] | 592 | filename = m.properties.Filename | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 593 | } | 
|  | 594 |  | 
| Liz Kammer | 48c6ead | 2021-12-21 15:36:11 -0500 | [diff] [blame] | 595 | var subDir *string | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 596 | if m.properties.Sub_dir != nil { | 
| Liz Kammer | 48c6ead | 2021-12-21 15:36:11 -0500 | [diff] [blame] | 597 | subDir = m.properties.Sub_dir | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 598 | } | 
|  | 599 |  | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 600 | attrs := &bazelShBinaryAttributes{ | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 601 | Srcs:     srcs, | 
|  | 602 | Filename: filename, | 
|  | 603 | Sub_dir:  subDir, | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 604 | } | 
|  | 605 |  | 
| Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 606 | props := bazel.BazelTargetModuleProperties{ | 
| Yu Liu | b302455 | 2021-11-23 14:53:41 -0800 | [diff] [blame] | 607 | Rule_class:        "sh_binary", | 
|  | 608 | Bzl_load_location: "//build/bazel/rules:sh_binary.bzl", | 
| Liz Kammer | fc46bc1 | 2021-02-19 11:06:17 -0500 | [diff] [blame] | 609 | } | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 610 |  | 
| Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 611 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) | 
| Rupert Shuttleworth | a1a56e8 | 2021-02-09 10:59:06 +0000 | [diff] [blame] | 612 | } | 
|  | 613 |  | 
| Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 614 | func (m *ShTest) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 615 | srcs := bazel.MakeLabelListAttribute( | 
|  | 616 | android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src})) | 
|  | 617 |  | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 618 | dataBins := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.testProperties.Data_bins)) | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 619 |  | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 620 | var combinedData bazel.LabelList | 
|  | 621 | combinedData.Append(android.BazelLabelForModuleSrc(ctx, m.testProperties.Data)) | 
|  | 622 | combinedData.Append(android.BazelLabelForModuleDeps(ctx, m.testProperties.Data_bins)) | 
|  | 623 | combinedData.Append(android.BazelLabelForModuleDeps(ctx, m.testProperties.Data_libs)) | 
|  | 624 | data := bazel.MakeLabelListAttribute(combinedData) | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 625 |  | 
|  | 626 | tags := bazel.MakeStringListAttribute( | 
|  | 627 | m.testProperties.Test_options.Tags) | 
|  | 628 |  | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 629 | testConfigAttributes := tradefed.GetTestConfigAttributes( | 
|  | 630 | ctx, | 
|  | 631 | m.testProperties.Test_config, | 
|  | 632 | []string{}, | 
|  | 633 | m.testProperties.Auto_gen_config, | 
|  | 634 | m.testProperties.Test_suites, | 
|  | 635 | m.testProperties.Test_config_template, | 
|  | 636 | nil, | 
|  | 637 | nil, | 
|  | 638 | ) | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 639 |  | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 640 | unitTest := m.testProperties.Test_options.Unit_test | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 641 |  | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 642 | runs_on := bazel.MakeStringListAttribute(android.RunsOn( | 
|  | 643 | m.ModuleBase.HostSupported(), | 
|  | 644 | m.ModuleBase.DeviceSupported(), | 
|  | 645 | (unitTest != nil && *unitTest))) | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 646 |  | 
|  | 647 | attrs := &bazelShTestAttributes{ | 
|  | 648 | Srcs:                 srcs, | 
|  | 649 | Data:                 data, | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 650 | Data_bins:            dataBins, | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 651 | Tags:                 tags, | 
| Jason Wu | 25c69ee | 2023-08-24 15:40:10 -0400 | [diff] [blame] | 652 | Runs_on:              runs_on, | 
|  | 653 | TestConfigAttributes: testConfigAttributes, | 
| Jason Wu | 6d8d44a | 2023-08-08 22:09:12 -0400 | [diff] [blame] | 654 | } | 
|  | 655 |  | 
|  | 656 | props := bazel.BazelTargetModuleProperties{ | 
|  | 657 | Rule_class:        "sh_test", | 
|  | 658 | Bzl_load_location: "//build/bazel/rules:sh_test.bzl", | 
|  | 659 | } | 
|  | 660 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) | 
|  | 661 | } | 
|  | 662 |  | 
| frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 663 | var Bool = proptools.Bool | 
| Rob Seymour | 925aa09 | 2021-08-10 20:42:03 +0000 | [diff] [blame] | 664 |  | 
|  | 665 | var _ snapshot.RelativeInstallPath = (*ShBinary)(nil) |