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" |
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 | |
| 42 | android.RegisterModuleType("sh_binary", ShBinaryFactory) |
| 43 | android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory) |
| 44 | android.RegisterModuleType("sh_test", ShTestFactory) |
| 45 | android.RegisterModuleType("sh_test_host", ShTestHostFactory) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | type shBinaryProperties struct { |
| 49 | // Source file of this prebuilt. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 50 | Src *string `android:"path,arch_variant"` |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 51 | |
| 52 | // optional subdirectory under which this file is installed into |
| 53 | Sub_dir *string `android:"arch_variant"` |
| 54 | |
| 55 | // optional name for the installed file. If unspecified, name of the module is used as the file name |
| 56 | Filename *string `android:"arch_variant"` |
| 57 | |
| 58 | // when set to true, and filename property is not set, the name for the installed file |
| 59 | // is the same as the file name of the source file. |
| 60 | Filename_from_src *bool `android:"arch_variant"` |
| 61 | |
| 62 | // Whether this module is directly installable to one of the partitions. Default: true. |
| 63 | Installable *bool |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 64 | |
| 65 | // install symlinks to the binary |
| 66 | Symlinks []string `android:"arch_variant"` |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 67 | |
| 68 | // Make this module available when building for ramdisk. |
| 69 | Ramdisk_available *bool |
| 70 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame^] | 71 | // Make this module available when building for vendor ramdisk. |
| 72 | Vendor_ramdisk_available *bool |
| 73 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 74 | // Make this module available when building for recovery. |
| 75 | Recovery_available *bool |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 78 | type TestProperties struct { |
| 79 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 80 | // installed into. |
| 81 | Test_suites []string `android:"arch_variant"` |
| 82 | |
| 83 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 84 | // installed with the module. |
Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 85 | Test_config *string `android:"path,arch_variant"` |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 86 | |
| 87 | // list of files or filegroup modules that provide data that should be installed alongside |
| 88 | // the test. |
| 89 | Data []string `android:"path,arch_variant"` |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 90 | |
| 91 | // Add RootTargetPreparer to auto generated test config. This guarantees the test to run |
| 92 | // with root permission. |
| 93 | Require_root *bool |
| 94 | |
| 95 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 96 | // should be installed with the module. |
| 97 | Test_config_template *string `android:"path,arch_variant"` |
| 98 | |
| 99 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 100 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 101 | // explicitly. |
| 102 | Auto_gen_config *bool |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 103 | |
| 104 | // list of binary modules that should be installed alongside the test |
| 105 | Data_bins []string `android:"path,arch_variant"` |
| 106 | |
| 107 | // list of library modules that should be installed alongside the test |
| 108 | Data_libs []string `android:"path,arch_variant"` |
| 109 | |
| 110 | // list of device binary modules that should be installed alongside the test. |
| 111 | // Only available for host sh_test modules. |
| 112 | Data_device_bins []string `android:"path,arch_variant"` |
| 113 | |
| 114 | // list of device library modules that should be installed alongside the test. |
| 115 | // Only available for host sh_test modules. |
| 116 | Data_device_libs []string `android:"path,arch_variant"` |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 119 | type ShBinary struct { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 120 | android.ModuleBase |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 121 | |
| 122 | properties shBinaryProperties |
| 123 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 124 | sourceFilePath android.Path |
| 125 | outputFilePath android.OutputPath |
| 126 | installedFile android.InstallPath |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 129 | var _ android.HostToolProvider = (*ShBinary)(nil) |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 130 | |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 131 | type ShTest struct { |
| 132 | ShBinary |
| 133 | |
| 134 | testProperties TestProperties |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 135 | |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 136 | installDir android.InstallPath |
| 137 | |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 138 | data android.Paths |
| 139 | testConfig android.Path |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 140 | |
| 141 | dataModules map[string]android.Path |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 144 | func (s *ShBinary) HostToolPath() android.OptionalPath { |
| 145 | return android.OptionalPathForPath(s.installedFile) |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 148 | func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 149 | if s.properties.Src == nil { |
| 150 | ctx.PropertyErrorf("src", "missing prebuilt source file") |
| 151 | } |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 154 | func (s *ShBinary) OutputFile() android.OutputPath { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 155 | return s.outputFilePath |
| 156 | } |
| 157 | |
| 158 | func (s *ShBinary) SubDir() string { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 159 | return proptools.String(s.properties.Sub_dir) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | func (s *ShBinary) Installable() bool { |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 163 | return s.properties.Installable == nil || proptools.Bool(s.properties.Installable) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 166 | func (s *ShBinary) Symlinks() []string { |
| 167 | return s.properties.Symlinks |
| 168 | } |
| 169 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 170 | var _ android.ImageInterface = (*ShBinary)(nil) |
| 171 | |
| 172 | func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {} |
| 173 | |
| 174 | func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool { |
| 175 | return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() |
| 176 | } |
| 177 | |
| 178 | func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 179 | return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk() |
| 180 | } |
| 181 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame^] | 182 | func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { |
| 183 | return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk() |
| 184 | } |
| 185 | |
Colin Cross | cc83efb | 2020-08-21 14:25:33 -0700 | [diff] [blame] | 186 | func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { |
| 187 | return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery() |
| 188 | } |
| 189 | |
| 190 | func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string { |
| 191 | return nil |
| 192 | } |
| 193 | |
| 194 | func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { |
| 195 | } |
| 196 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 197 | func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) { |
| 198 | s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src)) |
| 199 | filename := proptools.String(s.properties.Filename) |
| 200 | filename_from_src := proptools.Bool(s.properties.Filename_from_src) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 201 | if filename == "" { |
| 202 | if filename_from_src { |
| 203 | filename = s.sourceFilePath.Base() |
| 204 | } else { |
| 205 | filename = ctx.ModuleName() |
| 206 | } |
| 207 | } else if filename_from_src { |
| 208 | ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") |
| 209 | return |
| 210 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 211 | s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 212 | |
| 213 | // This ensures that outputFilePath has the correct name for others to |
| 214 | // use, as the source file may have a different name. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 215 | ctx.Build(pctx, android.BuildParams{ |
| 216 | Rule: android.CpExecutable, |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 217 | Output: s.outputFilePath, |
| 218 | Input: s.sourceFilePath, |
| 219 | }) |
| 220 | } |
| 221 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 222 | func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 223 | s.generateAndroidBuildActions(ctx) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 224 | installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir)) |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 225 | s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath) |
| 226 | } |
| 227 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 228 | func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { |
| 229 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 230 | Class: "EXECUTABLES", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 231 | OutputFile: android.OptionalPathForPath(s.outputFilePath), |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 232 | Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 233 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 234 | func(entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 235 | s.customAndroidMkEntries(entries) |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 236 | entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 237 | }, |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 238 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 239 | }} |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 242 | func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) { |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 243 | entries.SetString("LOCAL_MODULE_SUFFIX", "") |
| 244 | entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel()) |
Rashed Abdel-Tawab | 6a34131 | 2019-10-04 20:38:01 -0700 | [diff] [blame] | 245 | if len(s.properties.Symlinks) > 0 { |
| 246 | entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " ")) |
| 247 | } |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 250 | type dependencyTag struct { |
| 251 | blueprint.BaseDependencyTag |
| 252 | name string |
| 253 | } |
| 254 | |
| 255 | var ( |
| 256 | shTestDataBinsTag = dependencyTag{name: "dataBins"} |
| 257 | shTestDataLibsTag = dependencyTag{name: "dataLibs"} |
| 258 | shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} |
| 259 | shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"} |
| 260 | ) |
| 261 | |
| 262 | var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}} |
| 263 | |
| 264 | func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 265 | s.ShBinary.DepsMutator(ctx) |
| 266 | |
| 267 | ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...) |
| 268 | ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...), |
| 269 | shTestDataLibsTag, s.testProperties.Data_libs...) |
| 270 | 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] | 271 | deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 272 | ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...) |
| 273 | ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...), |
| 274 | shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...) |
| 275 | } else if ctx.Target().Os.Class != android.Host { |
| 276 | if len(s.testProperties.Data_device_bins) > 0 { |
| 277 | ctx.PropertyErrorf("data_device_bins", "only available for host modules") |
| 278 | } |
| 279 | if len(s.testProperties.Data_device_libs) > 0 { |
| 280 | ctx.PropertyErrorf("data_device_libs", "only available for host modules") |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) { |
| 286 | if _, exists := s.dataModules[relPath]; exists { |
| 287 | ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s", |
| 288 | relPath, s.dataModules[relPath].String(), path.String()) |
| 289 | return |
| 290 | } |
| 291 | s.dataModules[relPath] = path |
| 292 | } |
| 293 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 294 | func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 295 | s.ShBinary.generateAndroidBuildActions(ctx) |
| 296 | testDir := "nativetest" |
| 297 | if ctx.Target().Arch.ArchType.Multilib == "lib64" { |
| 298 | testDir = "nativetest64" |
| 299 | } |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 300 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 301 | testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath) |
| 302 | } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { |
| 303 | testDir = filepath.Join(testDir, ctx.Arch().ArchType.String()) |
| 304 | } |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 305 | if s.SubDir() != "" { |
| 306 | // Don't add the module name to the installation path if sub_dir is specified for backward |
| 307 | // compatibility. |
| 308 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir()) |
| 309 | } else { |
| 310 | s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name()) |
| 311 | } |
| 312 | s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath) |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 313 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 314 | s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data) |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 315 | |
| 316 | var configs []tradefed.Config |
| 317 | if Bool(s.testProperties.Require_root) { |
| 318 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) |
| 319 | } else { |
| 320 | options := []tradefed.Option{{Name: "force-root", Value: "false"}} |
| 321 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) |
| 322 | } |
frankfeng | be6ae77 | 2020-09-28 13:22:57 -0700 | [diff] [blame] | 323 | if len(s.testProperties.Data_device_bins) > 0 { |
| 324 | moduleName := s.Name() |
| 325 | remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/" |
| 326 | options := []tradefed.Option{{Name: "cleanup", Value: "true"}} |
| 327 | for _, bin := range s.testProperties.Data_device_bins { |
| 328 | options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin}) |
| 329 | } |
| 330 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) |
| 331 | } |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 332 | s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config, |
| 333 | s.testProperties.Test_config_template, s.testProperties.Test_suites, configs, s.testProperties.Auto_gen_config, s.outputFilePath.Base()) |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 334 | |
| 335 | s.dataModules = make(map[string]android.Path) |
| 336 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 337 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 338 | switch depTag { |
| 339 | case shTestDataBinsTag, shTestDataDeviceBinsTag: |
| 340 | if cc, isCc := dep.(*cc.Module); isCc { |
| 341 | s.addToDataModules(ctx, cc.OutputFile().Path().Base(), cc.OutputFile().Path()) |
| 342 | return |
| 343 | } |
| 344 | property := "data_bins" |
| 345 | if depTag == shTestDataDeviceBinsTag { |
| 346 | property = "data_device_bins" |
| 347 | } |
| 348 | ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) |
| 349 | case shTestDataLibsTag, shTestDataDeviceLibsTag: |
| 350 | if cc, isCc := dep.(*cc.Module); isCc { |
| 351 | // Copy to an intermediate output directory to append "lib[64]" to the path, |
| 352 | // so that it's compatible with the default rpath values. |
| 353 | var relPath string |
| 354 | if cc.Arch().ArchType.Multilib == "lib64" { |
| 355 | relPath = filepath.Join("lib64", cc.OutputFile().Path().Base()) |
| 356 | } else { |
| 357 | relPath = filepath.Join("lib", cc.OutputFile().Path().Base()) |
| 358 | } |
| 359 | if _, exist := s.dataModules[relPath]; exist { |
| 360 | return |
| 361 | } |
| 362 | relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath) |
| 363 | ctx.Build(pctx, android.BuildParams{ |
| 364 | Rule: android.Cp, |
| 365 | Input: cc.OutputFile().Path(), |
| 366 | Output: relocatedLib, |
| 367 | }) |
| 368 | s.addToDataModules(ctx, relPath, relocatedLib) |
| 369 | return |
| 370 | } |
| 371 | property := "data_libs" |
| 372 | if depTag == shTestDataDeviceBinsTag { |
| 373 | property = "data_device_libs" |
| 374 | } |
| 375 | ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) |
| 376 | } |
| 377 | }) |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Colin Cross | 7c7c114 | 2019-07-29 16:46:49 -0700 | [diff] [blame] | 380 | func (s *ShTest) InstallInData() bool { |
| 381 | return true |
| 382 | } |
| 383 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 384 | func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { |
| 385 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 386 | Class: "NATIVE_TESTS", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 387 | OutputFile: android.OptionalPathForPath(s.outputFilePath), |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 388 | Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk", |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 389 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 390 | func(entries *android.AndroidMkEntries) { |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 391 | s.customAndroidMkEntries(entries) |
Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 392 | entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath()) |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 393 | entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...) |
Colin Cross | a638482 | 2020-06-09 15:09:22 -0700 | [diff] [blame] | 394 | if s.testConfig != nil { |
| 395 | entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 396 | } |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 397 | for _, d := range s.data { |
| 398 | rel := d.Rel() |
| 399 | path := d.String() |
| 400 | if !strings.HasSuffix(path, rel) { |
| 401 | panic(fmt.Errorf("path %q does not end with %q", path, rel)) |
| 402 | } |
| 403 | path = strings.TrimSuffix(path, rel) |
| 404 | entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel) |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 405 | } |
Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 406 | relPaths := make([]string, 0) |
| 407 | for relPath, _ := range s.dataModules { |
| 408 | relPaths = append(relPaths, relPath) |
| 409 | } |
| 410 | sort.Strings(relPaths) |
| 411 | for _, relPath := range relPaths { |
| 412 | dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath) |
| 413 | entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath) |
| 414 | } |
Jaewoong Jung | e0dc8df | 2019-08-27 17:33:16 -0700 | [diff] [blame] | 415 | }, |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 416 | }, |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 417 | }} |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 420 | func InitShBinaryModule(s *ShBinary) { |
| 421 | s.AddProperties(&s.properties) |
| 422 | } |
| 423 | |
Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 424 | // sh_binary is for a shell script or batch file to be installed as an |
| 425 | // executable binary to <partition>/bin. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 426 | func ShBinaryFactory() android.Module { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 427 | module := &ShBinary{} |
| 428 | InitShBinaryModule(module) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 429 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 430 | return module |
| 431 | } |
| 432 | |
Patrice Arruda | e103419 | 2019-03-11 13:20:17 -0700 | [diff] [blame] | 433 | // sh_binary_host is for a shell script to be installed as an executable binary |
| 434 | // to $(HOST_OUT)/bin. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 435 | func ShBinaryHostFactory() android.Module { |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 436 | module := &ShBinary{} |
| 437 | InitShBinaryModule(module) |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 438 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) |
Dan Willemsen | b055267 | 2019-01-25 16:04:11 -0800 | [diff] [blame] | 439 | return module |
| 440 | } |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 441 | |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 442 | // sh_test defines a shell script based test module. |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 443 | func ShTestFactory() android.Module { |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 444 | module := &ShTest{} |
| 445 | InitShBinaryModule(&module.ShBinary) |
| 446 | module.AddProperties(&module.testProperties) |
| 447 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 448 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst) |
Julien Desprez | 9e7fc14 | 2019-03-08 11:07:05 -0800 | [diff] [blame] | 449 | return module |
| 450 | } |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 451 | |
| 452 | // 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] | 453 | func ShTestHostFactory() android.Module { |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 454 | module := &ShTest{} |
| 455 | InitShBinaryModule(&module.ShBinary) |
| 456 | module.AddProperties(&module.testProperties) |
| 457 | |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 458 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) |
Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 459 | return module |
| 460 | } |
frankfeng | c5b8749 | 2020-06-03 10:28:47 -0700 | [diff] [blame] | 461 | |
| 462 | var Bool = proptools.Bool |