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