blob: 6f40ae4896e54c12ce360fbad1e61bd2ddd0bd2f [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.
69 Ramdisk_available *bool
70
Yifan Hong60e0cfb2020-10-21 15:17:56 -070071 // Make this module available when building for vendor ramdisk.
72 Vendor_ramdisk_available *bool
73
Colin Crosscc83efb2020-08-21 14:25:33 -070074 // Make this module available when building for recovery.
75 Recovery_available *bool
Dan Willemsenb0552672019-01-25 16:04:11 -080076}
77
Julien Desprez9e7fc142019-03-08 11:07:05 -080078type 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 Crossa6384822020-06-09 15:09:22 -070085 Test_config *string `android:"path,arch_variant"`
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070086
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"`
frankfengc5b87492020-06-03 10:28:47 -070090
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 Jung6e0eee52020-05-29 16:15:32 -0700103
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 Desprez9e7fc142019-03-08 11:07:05 -0800117}
118
Dan Willemsenb0552672019-01-25 16:04:11 -0800119type ShBinary struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700120 android.ModuleBase
Dan Willemsenb0552672019-01-25 16:04:11 -0800121
122 properties shBinaryProperties
123
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700124 sourceFilePath android.Path
125 outputFilePath android.OutputPath
126 installedFile android.InstallPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800127}
128
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700129var _ android.HostToolProvider = (*ShBinary)(nil)
Colin Cross7c7c1142019-07-29 16:46:49 -0700130
Julien Desprez9e7fc142019-03-08 11:07:05 -0800131type ShTest struct {
132 ShBinary
133
134 testProperties TestProperties
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700135
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700136 installDir android.InstallPath
137
frankfengc5b87492020-06-03 10:28:47 -0700138 data android.Paths
139 testConfig android.Path
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700140
141 dataModules map[string]android.Path
Julien Desprez9e7fc142019-03-08 11:07:05 -0800142}
143
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700144func (s *ShBinary) HostToolPath() android.OptionalPath {
145 return android.OptionalPathForPath(s.installedFile)
Colin Cross7c7c1142019-07-29 16:46:49 -0700146}
147
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700148func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsenb0552672019-01-25 16:04:11 -0800149 if s.properties.Src == nil {
150 ctx.PropertyErrorf("src", "missing prebuilt source file")
151 }
Dan Willemsenb0552672019-01-25 16:04:11 -0800152}
153
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700154func (s *ShBinary) OutputFile() android.OutputPath {
Dan Willemsenb0552672019-01-25 16:04:11 -0800155 return s.outputFilePath
156}
157
158func (s *ShBinary) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700159 return proptools.String(s.properties.Sub_dir)
Dan Willemsenb0552672019-01-25 16:04:11 -0800160}
161
162func (s *ShBinary) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700163 return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
Dan Willemsenb0552672019-01-25 16:04:11 -0800164}
165
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700166func (s *ShBinary) Symlinks() []string {
167 return s.properties.Symlinks
168}
169
Colin Crosscc83efb2020-08-21 14:25:33 -0700170var _ android.ImageInterface = (*ShBinary)(nil)
171
172func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
173
174func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
175 return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
176}
177
178func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
179 return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
180}
181
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700182func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
183 return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
184}
185
Colin Crosscc83efb2020-08-21 14:25:33 -0700186func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
187 return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
188}
189
190func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
191 return nil
192}
193
194func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
195}
196
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700197func (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 Willemsenb0552672019-01-25 16:04:11 -0800201 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 Jung4b79e982020-06-01 10:45:49 -0700211 s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800212
213 // This ensures that outputFilePath has the correct name for others to
214 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700215 ctx.Build(pctx, android.BuildParams{
216 Rule: android.CpExecutable,
Dan Willemsenb0552672019-01-25 16:04:11 -0800217 Output: s.outputFilePath,
218 Input: s.sourceFilePath,
219 })
220}
221
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700222func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700223 s.generateAndroidBuildActions(ctx)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700224 installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
Colin Cross7c7c1142019-07-29 16:46:49 -0700225 s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
226}
227
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700228func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
229 return []android.AndroidMkEntries{android.AndroidMkEntries{
Dan Willemsenb0552672019-01-25 16:04:11 -0800230 Class: "EXECUTABLES",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700231 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Dan Willemsenb0552672019-01-25 16:04:11 -0800232 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700233 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
234 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700235 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700236 entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700237 },
Dan Willemsenb0552672019-01-25 16:04:11 -0800238 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900239 }}
Dan Willemsenb0552672019-01-25 16:04:11 -0800240}
241
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700242func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700243 entries.SetString("LOCAL_MODULE_SUFFIX", "")
244 entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700245 if len(s.properties.Symlinks) > 0 {
246 entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
247 }
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700248}
249
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700250type dependencyTag struct {
251 blueprint.BaseDependencyTag
252 name string
253}
254
255var (
256 shTestDataBinsTag = dependencyTag{name: "dataBins"}
257 shTestDataLibsTag = dependencyTag{name: "dataLibs"}
258 shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
259 shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
260)
261
262var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
263
264func (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 Jung642916f2020-10-09 17:25:15 -0700271 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700272 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
285func (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 Jung4b79e982020-06-01 10:45:49 -0700294func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700295 s.ShBinary.generateAndroidBuildActions(ctx)
296 testDir := "nativetest"
297 if ctx.Target().Arch.ArchType.Multilib == "lib64" {
298 testDir = "nativetest64"
299 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700300 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross7c7c1142019-07-29 16:46:49 -0700301 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 Jung4aedc862020-06-10 17:23:46 -0700305 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 Jung8eaeb092019-05-16 14:58:29 -0700313
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700314 s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
frankfengc5b87492020-06-03 10:28:47 -0700315
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 }
frankfengbe6ae772020-09-28 13:22:57 -0700323 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 }
frankfengc5b87492020-06-03 10:28:47 -0700332 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 Jung6e0eee52020-05-29 16:15:32 -0700334
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 Jung8eaeb092019-05-16 14:58:29 -0700378}
379
Colin Cross7c7c1142019-07-29 16:46:49 -0700380func (s *ShTest) InstallInData() bool {
381 return true
382}
383
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700384func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
385 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700386 Class: "NATIVE_TESTS",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700387 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700388 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700389 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
390 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700391 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700392 entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700393 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
Colin Crossa6384822020-06-09 15:09:22 -0700394 if s.testConfig != nil {
395 entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
frankfengc5b87492020-06-03 10:28:47 -0700396 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700397 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 Jung8eaeb092019-05-16 14:58:29 -0700405 }
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700406 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 Junge0dc8df2019-08-27 17:33:16 -0700415 },
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700416 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900417 }}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800418}
419
Dan Willemsenb0552672019-01-25 16:04:11 -0800420func InitShBinaryModule(s *ShBinary) {
421 s.AddProperties(&s.properties)
422}
423
Patrice Arrudae1034192019-03-11 13:20:17 -0700424// sh_binary is for a shell script or batch file to be installed as an
425// executable binary to <partition>/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700426func ShBinaryFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800427 module := &ShBinary{}
428 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700429 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800430 return module
431}
432
Patrice Arrudae1034192019-03-11 13:20:17 -0700433// sh_binary_host is for a shell script to be installed as an executable binary
434// to $(HOST_OUT)/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700435func ShBinaryHostFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800436 module := &ShBinary{}
437 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700438 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800439 return module
440}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800441
Jaewoong Jung61a83682019-07-01 09:08:50 -0700442// sh_test defines a shell script based test module.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700443func ShTestFactory() android.Module {
Julien Desprez9e7fc142019-03-08 11:07:05 -0800444 module := &ShTest{}
445 InitShBinaryModule(&module.ShBinary)
446 module.AddProperties(&module.testProperties)
447
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700448 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Julien Desprez9e7fc142019-03-08 11:07:05 -0800449 return module
450}
Jaewoong Jung61a83682019-07-01 09:08:50 -0700451
452// sh_test_host defines a shell script based test module that runs on a host.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700453func ShTestHostFactory() android.Module {
Jaewoong Jung61a83682019-07-01 09:08:50 -0700454 module := &ShTest{}
455 InitShBinaryModule(&module.ShBinary)
456 module.AddProperties(&module.testProperties)
457
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700458 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Jaewoong Jung61a83682019-07-01 09:08:50 -0700459 return module
460}
frankfengc5b87492020-06-03 10:28:47 -0700461
462var Bool = proptools.Bool