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