blob: 7e5c3440a8eb4097511bd9e148e3392cfe167487 [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 if s.properties.Src == nil {
158 ctx.PropertyErrorf("src", "missing prebuilt source file")
159 }
Dan Willemsenb0552672019-01-25 16:04:11 -0800160}
161
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700162func (s *ShBinary) OutputFile() android.OutputPath {
Dan Willemsenb0552672019-01-25 16:04:11 -0800163 return s.outputFilePath
164}
165
166func (s *ShBinary) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700167 return proptools.String(s.properties.Sub_dir)
Dan Willemsenb0552672019-01-25 16:04:11 -0800168}
169
170func (s *ShBinary) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700171 return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
Dan Willemsenb0552672019-01-25 16:04:11 -0800172}
173
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700174func (s *ShBinary) Symlinks() []string {
175 return s.properties.Symlinks
176}
177
Colin Crosscc83efb2020-08-21 14:25:33 -0700178var _ android.ImageInterface = (*ShBinary)(nil)
179
180func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
181
182func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
183 return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
184}
185
186func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
187 return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
188}
189
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700190func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
191 return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
192}
193
Colin Crosscc83efb2020-08-21 14:25:33 -0700194func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
195 return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
196}
197
198func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
199 return nil
200}
201
202func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
203}
204
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700205func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
206 s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
207 filename := proptools.String(s.properties.Filename)
208 filename_from_src := proptools.Bool(s.properties.Filename_from_src)
Dan Willemsenb0552672019-01-25 16:04:11 -0800209 if filename == "" {
210 if filename_from_src {
211 filename = s.sourceFilePath.Base()
212 } else {
213 filename = ctx.ModuleName()
214 }
215 } else if filename_from_src {
216 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
217 return
218 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700219 s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800220
221 // This ensures that outputFilePath has the correct name for others to
222 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700223 ctx.Build(pctx, android.BuildParams{
224 Rule: android.CpExecutable,
Dan Willemsenb0552672019-01-25 16:04:11 -0800225 Output: s.outputFilePath,
226 Input: s.sourceFilePath,
227 })
228}
229
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700230func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700231 s.generateAndroidBuildActions(ctx)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700232 installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
Colin Cross7c7c1142019-07-29 16:46:49 -0700233 s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
234}
235
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700236func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
237 return []android.AndroidMkEntries{android.AndroidMkEntries{
Dan Willemsenb0552672019-01-25 16:04:11 -0800238 Class: "EXECUTABLES",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700239 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Dan Willemsenb0552672019-01-25 16:04:11 -0800240 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700241 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
242 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700243 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700244 entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700245 },
Dan Willemsenb0552672019-01-25 16:04:11 -0800246 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900247 }}
Dan Willemsenb0552672019-01-25 16:04:11 -0800248}
249
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700250func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700251 entries.SetString("LOCAL_MODULE_SUFFIX", "")
252 entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700253 if len(s.properties.Symlinks) > 0 {
254 entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
255 }
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700256}
257
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700258type dependencyTag struct {
259 blueprint.BaseDependencyTag
260 name string
261}
262
263var (
264 shTestDataBinsTag = dependencyTag{name: "dataBins"}
265 shTestDataLibsTag = dependencyTag{name: "dataLibs"}
266 shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
267 shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
268)
269
270var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
271
272func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
273 s.ShBinary.DepsMutator(ctx)
274
275 ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
276 ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
277 shTestDataLibsTag, s.testProperties.Data_libs...)
278 if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 {
Jaewoong Jung642916f2020-10-09 17:25:15 -0700279 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700280 ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
281 ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),
282 shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)
283 } else if ctx.Target().Os.Class != android.Host {
284 if len(s.testProperties.Data_device_bins) > 0 {
285 ctx.PropertyErrorf("data_device_bins", "only available for host modules")
286 }
287 if len(s.testProperties.Data_device_libs) > 0 {
288 ctx.PropertyErrorf("data_device_libs", "only available for host modules")
289 }
290 }
291}
292
293func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) {
294 if _, exists := s.dataModules[relPath]; exists {
295 ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s",
296 relPath, s.dataModules[relPath].String(), path.String())
297 return
298 }
299 s.dataModules[relPath] = path
300}
301
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700302func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700303 s.ShBinary.generateAndroidBuildActions(ctx)
304 testDir := "nativetest"
305 if ctx.Target().Arch.ArchType.Multilib == "lib64" {
306 testDir = "nativetest64"
307 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700308 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross7c7c1142019-07-29 16:46:49 -0700309 testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
310 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
311 testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
312 }
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700313 if s.SubDir() != "" {
314 // Don't add the module name to the installation path if sub_dir is specified for backward
315 // compatibility.
316 s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
317 } else {
318 s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
319 }
320 s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700321
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700322 s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
frankfengc5b87492020-06-03 10:28:47 -0700323
324 var configs []tradefed.Config
325 if Bool(s.testProperties.Require_root) {
326 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
327 } else {
328 options := []tradefed.Option{{Name: "force-root", Value: "false"}}
329 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
330 }
frankfengbe6ae772020-09-28 13:22:57 -0700331 if len(s.testProperties.Data_device_bins) > 0 {
332 moduleName := s.Name()
333 remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/"
334 options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
335 for _, bin := range s.testProperties.Data_device_bins {
336 options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin})
337 }
338 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
339 }
frankfengc5b87492020-06-03 10:28:47 -0700340 s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
341 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 -0700342
343 s.dataModules = make(map[string]android.Path)
344 ctx.VisitDirectDeps(func(dep android.Module) {
345 depTag := ctx.OtherModuleDependencyTag(dep)
346 switch depTag {
347 case shTestDataBinsTag, shTestDataDeviceBinsTag:
348 if cc, isCc := dep.(*cc.Module); isCc {
349 s.addToDataModules(ctx, cc.OutputFile().Path().Base(), cc.OutputFile().Path())
350 return
351 }
352 property := "data_bins"
353 if depTag == shTestDataDeviceBinsTag {
354 property = "data_device_bins"
355 }
356 ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
357 case shTestDataLibsTag, shTestDataDeviceLibsTag:
358 if cc, isCc := dep.(*cc.Module); isCc {
359 // Copy to an intermediate output directory to append "lib[64]" to the path,
360 // so that it's compatible with the default rpath values.
361 var relPath string
362 if cc.Arch().ArchType.Multilib == "lib64" {
363 relPath = filepath.Join("lib64", cc.OutputFile().Path().Base())
364 } else {
365 relPath = filepath.Join("lib", cc.OutputFile().Path().Base())
366 }
367 if _, exist := s.dataModules[relPath]; exist {
368 return
369 }
370 relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath)
371 ctx.Build(pctx, android.BuildParams{
372 Rule: android.Cp,
373 Input: cc.OutputFile().Path(),
374 Output: relocatedLib,
375 })
376 s.addToDataModules(ctx, relPath, relocatedLib)
377 return
378 }
379 property := "data_libs"
380 if depTag == shTestDataDeviceBinsTag {
381 property = "data_device_libs"
382 }
383 ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
384 }
385 })
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700386}
387
Colin Cross7c7c1142019-07-29 16:46:49 -0700388func (s *ShTest) InstallInData() bool {
389 return true
390}
391
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700392func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
393 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700394 Class: "NATIVE_TESTS",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700395 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700396 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700397 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
398 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700399 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700400 entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath())
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700401 entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
Colin Crossa6384822020-06-09 15:09:22 -0700402 if s.testConfig != nil {
403 entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
frankfengc5b87492020-06-03 10:28:47 -0700404 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700405 for _, d := range s.data {
406 rel := d.Rel()
407 path := d.String()
408 if !strings.HasSuffix(path, rel) {
409 panic(fmt.Errorf("path %q does not end with %q", path, rel))
410 }
411 path = strings.TrimSuffix(path, rel)
412 entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700413 }
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700414 relPaths := make([]string, 0)
415 for relPath, _ := range s.dataModules {
416 relPaths = append(relPaths, relPath)
417 }
418 sort.Strings(relPaths)
419 for _, relPath := range relPaths {
420 dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath)
421 entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath)
422 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700423 },
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700424 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900425 }}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800426}
427
Dan Willemsenb0552672019-01-25 16:04:11 -0800428func InitShBinaryModule(s *ShBinary) {
429 s.AddProperties(&s.properties)
430}
431
Patrice Arrudae1034192019-03-11 13:20:17 -0700432// sh_binary is for a shell script or batch file to be installed as an
433// executable binary to <partition>/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700434func ShBinaryFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800435 module := &ShBinary{}
436 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700437 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800438 return module
439}
440
Patrice Arrudae1034192019-03-11 13:20:17 -0700441// sh_binary_host is for a shell script to be installed as an executable binary
442// to $(HOST_OUT)/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700443func ShBinaryHostFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800444 module := &ShBinary{}
445 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700446 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800447 return module
448}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800449
Jaewoong Jung61a83682019-07-01 09:08:50 -0700450// sh_test defines a shell script based test module.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700451func ShTestFactory() android.Module {
Julien Desprez9e7fc142019-03-08 11:07:05 -0800452 module := &ShTest{}
453 InitShBinaryModule(&module.ShBinary)
454 module.AddProperties(&module.testProperties)
455
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700456 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Julien Desprez9e7fc142019-03-08 11:07:05 -0800457 return module
458}
Jaewoong Jung61a83682019-07-01 09:08:50 -0700459
460// sh_test_host defines a shell script based test module that runs on a host.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700461func ShTestHostFactory() android.Module {
Jaewoong Jung61a83682019-07-01 09:08:50 -0700462 module := &ShTest{}
463 InitShBinaryModule(&module.ShBinary)
464 module.AddProperties(&module.testProperties)
465
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700466 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Jaewoong Jung61a83682019-07-01 09:08:50 -0700467 return module
468}
frankfengc5b87492020-06-03 10:28:47 -0700469
470var Bool = proptools.Bool