blob: 66e493bf1f753b8e9443eebdaf5d3e243c37ac49 [file] [log] [blame]
Dan Willemsenb0552672019-01-25 16:04:11 -08001// 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 Jung4b79e982020-06-01 10:45:49 -070015package sh
Dan Willemsenb0552672019-01-25 16:04:11 -080016
17import (
18 "fmt"
Colin Cross7c7c1142019-07-29 16:46:49 -070019 "path/filepath"
Jaewoong Jung6e0eee52020-05-29 16:15:32 -070020 "sort"
Julien Desprez9e7fc142019-03-08 11:07:05 -080021 "strings"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070022
Jaewoong Jung6e0eee52020-05-29 16:15:32 -070023 "github.com/google/blueprint"
Jaewoong Jung4b79e982020-06-01 10:45:49 -070024 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
Jaewoong Jung6e0eee52020-05-29 16:15:32 -070027 "android/soong/cc"
frankfengc5b87492020-06-03 10:28:47 -070028 "android/soong/tradefed"
Dan Willemsenb0552672019-01-25 16:04:11 -080029)
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 Jung4b79e982020-06-01 10:45:49 -070037var pctx = android.NewPackageContext("android/soong/sh")
38
Dan Willemsenb0552672019-01-25 16:04:11 -080039func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070040 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 Willemsenb0552672019-01-25 16:04:11 -080046}
47
48type shBinaryProperties struct {
49 // Source file of this prebuilt.
Colin Cross27b922f2019-03-04 22:35:41 -080050 Src *string `android:"path,arch_variant"`
Dan Willemsenb0552672019-01-25 16:04:11 -080051
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-Tawab6a341312019-10-04 20:38:01 -070064
65 // install symlinks to the binary
66 Symlinks []string `android:"arch_variant"`
Colin Crosscc83efb2020-08-21 14:25:33 -070067
68 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070069 // On device without a dedicated recovery partition, the module is only
70 // available after switching root into
71 // /first_stage_ramdisk. To expose the module before switching root, install
72 // the recovery variant instead.
Colin Crosscc83efb2020-08-21 14:25:33 -070073 Ramdisk_available *bool
74
Yifan Hong60e0cfb2020-10-21 15:17:56 -070075 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070076 // On device without a dedicated recovery partition, the module is only
77 // available after switching root into
78 // /first_stage_ramdisk. To expose the module before switching root, install
79 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -070080 Vendor_ramdisk_available *bool
81
Colin Crosscc83efb2020-08-21 14:25:33 -070082 // Make this module available when building for recovery.
83 Recovery_available *bool
Dan Willemsenb0552672019-01-25 16:04:11 -080084}
85
Julien Desprez9e7fc142019-03-08 11:07:05 -080086type TestProperties struct {
87 // list of compatibility suites (for example "cts", "vts") that the module should be
88 // installed into.
89 Test_suites []string `android:"arch_variant"`
90
91 // the name of the test configuration (for example "AndroidTest.xml") that should be
92 // installed with the module.
Colin Crossa6384822020-06-09 15:09:22 -070093 Test_config *string `android:"path,arch_variant"`
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070094
95 // list of files or filegroup modules that provide data that should be installed alongside
96 // the test.
97 Data []string `android:"path,arch_variant"`
frankfengc5b87492020-06-03 10:28:47 -070098
99 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
100 // with root permission.
101 Require_root *bool
102
103 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
104 // should be installed with the module.
105 Test_config_template *string `android:"path,arch_variant"`
106
107 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
108 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
109 // explicitly.
110 Auto_gen_config *bool
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700111
112 // list of binary modules that should be installed alongside the test
113 Data_bins []string `android:"path,arch_variant"`
114
115 // list of library modules that should be installed alongside the test
116 Data_libs []string `android:"path,arch_variant"`
117
118 // list of device binary modules that should be installed alongside the test.
119 // Only available for host sh_test modules.
120 Data_device_bins []string `android:"path,arch_variant"`
121
122 // list of device library modules that should be installed alongside the test.
123 // Only available for host sh_test modules.
124 Data_device_libs []string `android:"path,arch_variant"`
Julien Desprez9e7fc142019-03-08 11:07:05 -0800125}
126
Dan Willemsenb0552672019-01-25 16:04:11 -0800127type ShBinary struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700128 android.ModuleBase
Dan Willemsenb0552672019-01-25 16:04:11 -0800129
130 properties shBinaryProperties
131
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700132 sourceFilePath android.Path
133 outputFilePath android.OutputPath
134 installedFile android.InstallPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800135}
136
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700137var _ android.HostToolProvider = (*ShBinary)(nil)
Colin Cross7c7c1142019-07-29 16:46:49 -0700138
Julien Desprez9e7fc142019-03-08 11:07:05 -0800139type ShTest struct {
140 ShBinary
141
142 testProperties TestProperties
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700143
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700144 installDir android.InstallPath
145
frankfengc5b87492020-06-03 10:28:47 -0700146 data android.Paths
147 testConfig android.Path
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700148
149 dataModules map[string]android.Path
Julien Desprez9e7fc142019-03-08 11:07:05 -0800150}
151
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700152func (s *ShBinary) HostToolPath() android.OptionalPath {
153 return android.OptionalPathForPath(s.installedFile)
Colin Cross7c7c1142019-07-29 16:46:49 -0700154}
155
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700156func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsenb0552672019-01-25 16:04:11 -0800157}
158
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700159func (s *ShBinary) OutputFile() android.OutputPath {
Dan Willemsenb0552672019-01-25 16:04:11 -0800160 return s.outputFilePath
161}
162
163func (s *ShBinary) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700164 return proptools.String(s.properties.Sub_dir)
Dan Willemsenb0552672019-01-25 16:04:11 -0800165}
166
167func (s *ShBinary) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700168 return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
Dan Willemsenb0552672019-01-25 16:04:11 -0800169}
170
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700171func (s *ShBinary) Symlinks() []string {
172 return s.properties.Symlinks
173}
174
Colin Crosscc83efb2020-08-21 14:25:33 -0700175var _ android.ImageInterface = (*ShBinary)(nil)
176
177func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
178
179func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
180 return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
181}
182
183func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
184 return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
185}
186
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700187func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
188 return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
189}
190
Colin Crosscc83efb2020-08-21 14:25:33 -0700191func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
192 return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
193}
194
195func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
196 return nil
197}
198
199func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
200}
201
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700202func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
Liz Kammer356f7d42021-01-26 09:18:53 -0500203 if s.properties.Src == nil {
204 ctx.PropertyErrorf("src", "missing prebuilt source file")
205 }
206
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700207 s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
208 filename := proptools.String(s.properties.Filename)
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800209 filenameFromSrc := proptools.Bool(s.properties.Filename_from_src)
Dan Willemsenb0552672019-01-25 16:04:11 -0800210 if filename == "" {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800211 if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800212 filename = s.sourceFilePath.Base()
213 } else {
214 filename = ctx.ModuleName()
215 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800216 } else if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800217 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
218 return
219 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700220 s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800221
222 // This ensures that outputFilePath has the correct name for others to
223 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700224 ctx.Build(pctx, android.BuildParams{
225 Rule: android.CpExecutable,
Dan Willemsenb0552672019-01-25 16:04:11 -0800226 Output: s.outputFilePath,
227 Input: s.sourceFilePath,
228 })
229}
230
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700231func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700232 s.generateAndroidBuildActions(ctx)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700233 installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
Colin Cross7c7c1142019-07-29 16:46:49 -0700234 s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
235}
236
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700237func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
238 return []android.AndroidMkEntries{android.AndroidMkEntries{
Dan Willemsenb0552672019-01-25 16:04:11 -0800239 Class: "EXECUTABLES",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700240 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Dan Willemsenb0552672019-01-25 16:04:11 -0800241 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700242 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
243 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700244 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700245 entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700246 },
Dan Willemsenb0552672019-01-25 16:04:11 -0800247 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900248 }}
Dan Willemsenb0552672019-01-25 16:04:11 -0800249}
250
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700251func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700252 entries.SetString("LOCAL_MODULE_SUFFIX", "")
253 entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700254 if len(s.properties.Symlinks) > 0 {
255 entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
256 }
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700257}
258
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700259type dependencyTag struct {
260 blueprint.BaseDependencyTag
261 name string
262}
263
264var (
265 shTestDataBinsTag = dependencyTag{name: "dataBins"}
266 shTestDataLibsTag = dependencyTag{name: "dataLibs"}
267 shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
268 shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
269)
270
271var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
272
273func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
274 s.ShBinary.DepsMutator(ctx)
275
276 ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
277 ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
278 shTestDataLibsTag, s.testProperties.Data_libs...)
Liz Kammer356f7d42021-01-26 09:18:53 -0500279 if (ctx.Target().Os.Class == android.Host || ctx.BazelConversionMode()) && len(ctx.Config().Targets[android.Android]) > 0 {
Jaewoong Jung642916f2020-10-09 17:25:15 -0700280 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700281 ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
282 ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),
283 shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)
284 } else if ctx.Target().Os.Class != android.Host {
285 if len(s.testProperties.Data_device_bins) > 0 {
286 ctx.PropertyErrorf("data_device_bins", "only available for host modules")
287 }
288 if len(s.testProperties.Data_device_libs) > 0 {
289 ctx.PropertyErrorf("data_device_libs", "only available for host modules")
290 }
291 }
292}
293
294func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) {
295 if _, exists := s.dataModules[relPath]; exists {
296 ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s",
297 relPath, s.dataModules[relPath].String(), path.String())
298 return
299 }
300 s.dataModules[relPath] = path
301}
302
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700303func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700304 s.ShBinary.generateAndroidBuildActions(ctx)
305 testDir := "nativetest"
306 if ctx.Target().Arch.ArchType.Multilib == "lib64" {
307 testDir = "nativetest64"
308 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700309 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross7c7c1142019-07-29 16:46:49 -0700310 testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
311 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
312 testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
313 }
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700314 if s.SubDir() != "" {
315 // Don't add the module name to the installation path if sub_dir is specified for backward
316 // compatibility.
317 s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
318 } else {
319 s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
320 }
321 s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700322
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700323 s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
frankfengc5b87492020-06-03 10:28:47 -0700324
325 var configs []tradefed.Config
326 if Bool(s.testProperties.Require_root) {
327 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
328 } else {
329 options := []tradefed.Option{{Name: "force-root", Value: "false"}}
330 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
331 }
frankfengbe6ae772020-09-28 13:22:57 -0700332 if len(s.testProperties.Data_device_bins) > 0 {
333 moduleName := s.Name()
334 remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/"
335 options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
336 for _, bin := range s.testProperties.Data_device_bins {
337 options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin})
338 }
339 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
340 }
frankfengc5b87492020-06-03 10:28:47 -0700341 s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
342 s.testProperties.Test_config_template, s.testProperties.Test_suites, configs, s.testProperties.Auto_gen_config, s.outputFilePath.Base())
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700343
344 s.dataModules = make(map[string]android.Path)
345 ctx.VisitDirectDeps(func(dep android.Module) {
346 depTag := ctx.OtherModuleDependencyTag(dep)
347 switch depTag {
348 case shTestDataBinsTag, shTestDataDeviceBinsTag:
Anton Hansson2f6422c2020-12-31 13:42:10 +0000349 path := android.OutputFileForModule(ctx, dep, "")
350 s.addToDataModules(ctx, path.Base(), path)
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700351 case shTestDataLibsTag, shTestDataDeviceLibsTag:
352 if cc, isCc := dep.(*cc.Module); isCc {
353 // Copy to an intermediate output directory to append "lib[64]" to the path,
354 // so that it's compatible with the default rpath values.
355 var relPath string
356 if cc.Arch().ArchType.Multilib == "lib64" {
357 relPath = filepath.Join("lib64", cc.OutputFile().Path().Base())
358 } else {
359 relPath = filepath.Join("lib", cc.OutputFile().Path().Base())
360 }
361 if _, exist := s.dataModules[relPath]; exist {
362 return
363 }
364 relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath)
365 ctx.Build(pctx, android.BuildParams{
366 Rule: android.Cp,
367 Input: cc.OutputFile().Path(),
368 Output: relocatedLib,
369 })
370 s.addToDataModules(ctx, relPath, relocatedLib)
371 return
372 }
373 property := "data_libs"
374 if depTag == shTestDataDeviceBinsTag {
375 property = "data_device_libs"
376 }
377 ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
378 }
379 })
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700380}
381
Colin Cross7c7c1142019-07-29 16:46:49 -0700382func (s *ShTest) InstallInData() bool {
383 return true
384}
385
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700386func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
387 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700388 Class: "NATIVE_TESTS",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700389 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700390 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700391 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
392 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700393 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700394 entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath())
Liz Kammer57f5b332020-11-24 12:42:58 -0800395 entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...)
Colin Crossa6384822020-06-09 15:09:22 -0700396 if s.testConfig != nil {
397 entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
frankfengc5b87492020-06-03 10:28:47 -0700398 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700399 for _, d := range s.data {
400 rel := d.Rel()
401 path := d.String()
402 if !strings.HasSuffix(path, rel) {
403 panic(fmt.Errorf("path %q does not end with %q", path, rel))
404 }
405 path = strings.TrimSuffix(path, rel)
406 entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700407 }
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700408 relPaths := make([]string, 0)
409 for relPath, _ := range s.dataModules {
410 relPaths = append(relPaths, relPath)
411 }
412 sort.Strings(relPaths)
413 for _, relPath := range relPaths {
414 dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath)
415 entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath)
416 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700417 },
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700418 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900419 }}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800420}
421
Dan Willemsenb0552672019-01-25 16:04:11 -0800422func InitShBinaryModule(s *ShBinary) {
423 s.AddProperties(&s.properties)
424}
425
Patrice Arrudae1034192019-03-11 13:20:17 -0700426// sh_binary is for a shell script or batch file to be installed as an
427// executable binary to <partition>/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700428func ShBinaryFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800429 module := &ShBinary{}
430 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700431 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800432 return module
433}
434
Patrice Arrudae1034192019-03-11 13:20:17 -0700435// sh_binary_host is for a shell script to be installed as an executable binary
436// to $(HOST_OUT)/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700437func ShBinaryHostFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800438 module := &ShBinary{}
439 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700440 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800441 return module
442}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800443
Jaewoong Jung61a83682019-07-01 09:08:50 -0700444// sh_test defines a shell script based test module.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700445func ShTestFactory() android.Module {
Julien Desprez9e7fc142019-03-08 11:07:05 -0800446 module := &ShTest{}
447 InitShBinaryModule(&module.ShBinary)
448 module.AddProperties(&module.testProperties)
449
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700450 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Julien Desprez9e7fc142019-03-08 11:07:05 -0800451 return module
452}
Jaewoong Jung61a83682019-07-01 09:08:50 -0700453
454// sh_test_host defines a shell script based test module that runs on a host.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700455func ShTestHostFactory() android.Module {
Jaewoong Jung61a83682019-07-01 09:08:50 -0700456 module := &ShTest{}
457 InitShBinaryModule(&module.ShBinary)
458 module.AddProperties(&module.testProperties)
459
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700460 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Jaewoong Jung61a83682019-07-01 09:08:50 -0700461 return module
462}
frankfengc5b87492020-06-03 10:28:47 -0700463
464var Bool = proptools.Bool