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