blob: 54dfc2467095037213bd2f8ffb4d4e2537030d5e [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"
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +000027 "android/soong/bazel"
Jaewoong Jung6e0eee52020-05-29 16:15:32 -070028 "android/soong/cc"
frankfengc5b87492020-06-03 10:28:47 -070029 "android/soong/tradefed"
Dan Willemsenb0552672019-01-25 16:04:11 -080030)
31
32// sh_binary is for shell scripts (and batch files) that are installed as
33// executable files into .../bin/
34//
35// Do not use them for prebuilt C/C++/etc files. Use cc_prebuilt_binary
36// instead.
37
Jaewoong Jung4b79e982020-06-01 10:45:49 -070038var pctx = android.NewPackageContext("android/soong/sh")
39
Dan Willemsenb0552672019-01-25 16:04:11 -080040func init() {
Jaewoong Jung4b79e982020-06-01 10:45:49 -070041 pctx.Import("android/soong/android")
42
43 android.RegisterModuleType("sh_binary", ShBinaryFactory)
44 android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
45 android.RegisterModuleType("sh_test", ShTestFactory)
46 android.RegisterModuleType("sh_test_host", ShTestHostFactory)
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +000047
48 android.RegisterBp2BuildMutator("sh_binary", ShBinaryBp2Build)
Dan Willemsenb0552672019-01-25 16:04:11 -080049}
50
51type shBinaryProperties struct {
52 // Source file of this prebuilt.
Colin Cross27b922f2019-03-04 22:35:41 -080053 Src *string `android:"path,arch_variant"`
Dan Willemsenb0552672019-01-25 16:04:11 -080054
55 // optional subdirectory under which this file is installed into
56 Sub_dir *string `android:"arch_variant"`
57
58 // optional name for the installed file. If unspecified, name of the module is used as the file name
59 Filename *string `android:"arch_variant"`
60
61 // when set to true, and filename property is not set, the name for the installed file
62 // is the same as the file name of the source file.
63 Filename_from_src *bool `android:"arch_variant"`
64
65 // Whether this module is directly installable to one of the partitions. Default: true.
66 Installable *bool
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -070067
68 // install symlinks to the binary
69 Symlinks []string `android:"arch_variant"`
Colin Crosscc83efb2020-08-21 14:25:33 -070070
71 // Make this module available when building for ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070072 // On device without a dedicated recovery partition, the module is only
73 // available after switching root into
74 // /first_stage_ramdisk. To expose the module before switching root, install
75 // the recovery variant instead.
Colin Crosscc83efb2020-08-21 14:25:33 -070076 Ramdisk_available *bool
77
Yifan Hong60e0cfb2020-10-21 15:17:56 -070078 // Make this module available when building for vendor ramdisk.
Yifan Hong39143a92020-10-26 12:43:12 -070079 // On device without a dedicated recovery partition, the module is only
80 // available after switching root into
81 // /first_stage_ramdisk. To expose the module before switching root, install
82 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -070083 Vendor_ramdisk_available *bool
84
Colin Crosscc83efb2020-08-21 14:25:33 -070085 // Make this module available when building for recovery.
86 Recovery_available *bool
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +000087
88 // Properties for Bazel migration purposes.
89 bazel.Properties
Dan Willemsenb0552672019-01-25 16:04:11 -080090}
91
Julien Desprez9e7fc142019-03-08 11:07:05 -080092type TestProperties struct {
93 // list of compatibility suites (for example "cts", "vts") that the module should be
94 // installed into.
95 Test_suites []string `android:"arch_variant"`
96
97 // the name of the test configuration (for example "AndroidTest.xml") that should be
98 // installed with the module.
Colin Crossa6384822020-06-09 15:09:22 -070099 Test_config *string `android:"path,arch_variant"`
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700100
101 // list of files or filegroup modules that provide data that should be installed alongside
102 // the test.
103 Data []string `android:"path,arch_variant"`
frankfengc5b87492020-06-03 10:28:47 -0700104
105 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
106 // with root permission.
107 Require_root *bool
108
109 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
110 // should be installed with the module.
111 Test_config_template *string `android:"path,arch_variant"`
112
113 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
114 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
115 // explicitly.
116 Auto_gen_config *bool
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700117
118 // list of binary modules that should be installed alongside the test
119 Data_bins []string `android:"path,arch_variant"`
120
121 // list of library modules that should be installed alongside the test
122 Data_libs []string `android:"path,arch_variant"`
123
124 // list of device binary modules that should be installed alongside the test.
125 // Only available for host sh_test modules.
126 Data_device_bins []string `android:"path,arch_variant"`
127
128 // list of device library modules that should be installed alongside the test.
129 // Only available for host sh_test modules.
130 Data_device_libs []string `android:"path,arch_variant"`
Julien Desprez9e7fc142019-03-08 11:07:05 -0800131}
132
Dan Willemsenb0552672019-01-25 16:04:11 -0800133type ShBinary struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700134 android.ModuleBase
Dan Willemsenb0552672019-01-25 16:04:11 -0800135
136 properties shBinaryProperties
137
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700138 sourceFilePath android.Path
139 outputFilePath android.OutputPath
140 installedFile android.InstallPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800141}
142
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700143var _ android.HostToolProvider = (*ShBinary)(nil)
Colin Cross7c7c1142019-07-29 16:46:49 -0700144
Julien Desprez9e7fc142019-03-08 11:07:05 -0800145type ShTest struct {
146 ShBinary
147
148 testProperties TestProperties
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700149
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700150 installDir android.InstallPath
151
frankfengc5b87492020-06-03 10:28:47 -0700152 data android.Paths
153 testConfig android.Path
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700154
155 dataModules map[string]android.Path
Julien Desprez9e7fc142019-03-08 11:07:05 -0800156}
157
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700158func (s *ShBinary) HostToolPath() android.OptionalPath {
159 return android.OptionalPathForPath(s.installedFile)
Colin Cross7c7c1142019-07-29 16:46:49 -0700160}
161
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700162func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsenb0552672019-01-25 16:04:11 -0800163}
164
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700165func (s *ShBinary) OutputFile() android.OutputPath {
Dan Willemsenb0552672019-01-25 16:04:11 -0800166 return s.outputFilePath
167}
168
169func (s *ShBinary) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700170 return proptools.String(s.properties.Sub_dir)
Dan Willemsenb0552672019-01-25 16:04:11 -0800171}
172
173func (s *ShBinary) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700174 return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
Dan Willemsenb0552672019-01-25 16:04:11 -0800175}
176
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700177func (s *ShBinary) Symlinks() []string {
178 return s.properties.Symlinks
179}
180
Colin Crosscc83efb2020-08-21 14:25:33 -0700181var _ android.ImageInterface = (*ShBinary)(nil)
182
183func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
184
185func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
186 return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
187}
188
189func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
190 return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
191}
192
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700193func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
194 return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
195}
196
Colin Crosscc83efb2020-08-21 14:25:33 -0700197func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
198 return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
199}
200
201func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
202 return nil
203}
204
205func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
206}
207
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700208func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
Liz Kammer356f7d42021-01-26 09:18:53 -0500209 if s.properties.Src == nil {
210 ctx.PropertyErrorf("src", "missing prebuilt source file")
211 }
212
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700213 s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
214 filename := proptools.String(s.properties.Filename)
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800215 filenameFromSrc := proptools.Bool(s.properties.Filename_from_src)
Dan Willemsenb0552672019-01-25 16:04:11 -0800216 if filename == "" {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800217 if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800218 filename = s.sourceFilePath.Base()
219 } else {
220 filename = ctx.ModuleName()
221 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800222 } else if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800223 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
224 return
225 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700226 s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800227
228 // This ensures that outputFilePath has the correct name for others to
229 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700230 ctx.Build(pctx, android.BuildParams{
231 Rule: android.CpExecutable,
Dan Willemsenb0552672019-01-25 16:04:11 -0800232 Output: s.outputFilePath,
233 Input: s.sourceFilePath,
234 })
235}
236
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700237func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700238 s.generateAndroidBuildActions(ctx)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700239 installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
Colin Cross7c7c1142019-07-29 16:46:49 -0700240 s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
241}
242
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700243func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
244 return []android.AndroidMkEntries{android.AndroidMkEntries{
Dan Willemsenb0552672019-01-25 16:04:11 -0800245 Class: "EXECUTABLES",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700246 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Dan Willemsenb0552672019-01-25 16:04:11 -0800247 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700248 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
249 func(entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700250 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700251 entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700252 },
Dan Willemsenb0552672019-01-25 16:04:11 -0800253 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900254 }}
Dan Willemsenb0552672019-01-25 16:04:11 -0800255}
256
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700257func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700258 entries.SetString("LOCAL_MODULE_SUFFIX", "")
259 entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700260 if len(s.properties.Symlinks) > 0 {
261 entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
262 }
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700263}
264
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700265type dependencyTag struct {
266 blueprint.BaseDependencyTag
267 name string
268}
269
270var (
271 shTestDataBinsTag = dependencyTag{name: "dataBins"}
272 shTestDataLibsTag = dependencyTag{name: "dataLibs"}
273 shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
274 shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
275)
276
277var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
278
279func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
280 s.ShBinary.DepsMutator(ctx)
281
282 ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
283 ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
284 shTestDataLibsTag, s.testProperties.Data_libs...)
Liz Kammer356f7d42021-01-26 09:18:53 -0500285 if (ctx.Target().Os.Class == android.Host || ctx.BazelConversionMode()) && len(ctx.Config().Targets[android.Android]) > 0 {
Jaewoong Jung642916f2020-10-09 17:25:15 -0700286 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700287 ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
288 ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),
289 shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)
290 } else if ctx.Target().Os.Class != android.Host {
291 if len(s.testProperties.Data_device_bins) > 0 {
292 ctx.PropertyErrorf("data_device_bins", "only available for host modules")
293 }
294 if len(s.testProperties.Data_device_libs) > 0 {
295 ctx.PropertyErrorf("data_device_libs", "only available for host modules")
296 }
297 }
298}
299
300func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) {
301 if _, exists := s.dataModules[relPath]; exists {
302 ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s",
303 relPath, s.dataModules[relPath].String(), path.String())
304 return
305 }
306 s.dataModules[relPath] = path
307}
308
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700309func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700310 s.ShBinary.generateAndroidBuildActions(ctx)
311 testDir := "nativetest"
312 if ctx.Target().Arch.ArchType.Multilib == "lib64" {
313 testDir = "nativetest64"
314 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700315 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross7c7c1142019-07-29 16:46:49 -0700316 testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
317 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
318 testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
319 }
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700320 if s.SubDir() != "" {
321 // Don't add the module name to the installation path if sub_dir is specified for backward
322 // compatibility.
323 s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
324 } else {
325 s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
326 }
327 s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700328
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700329 s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
frankfengc5b87492020-06-03 10:28:47 -0700330
331 var configs []tradefed.Config
332 if Bool(s.testProperties.Require_root) {
333 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
334 } else {
335 options := []tradefed.Option{{Name: "force-root", Value: "false"}}
336 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
337 }
frankfengbe6ae772020-09-28 13:22:57 -0700338 if len(s.testProperties.Data_device_bins) > 0 {
339 moduleName := s.Name()
340 remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/"
341 options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
342 for _, bin := range s.testProperties.Data_device_bins {
343 options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin})
344 }
345 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
346 }
frankfengc5b87492020-06-03 10:28:47 -0700347 s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
348 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 -0700349
350 s.dataModules = make(map[string]android.Path)
351 ctx.VisitDirectDeps(func(dep android.Module) {
352 depTag := ctx.OtherModuleDependencyTag(dep)
353 switch depTag {
354 case shTestDataBinsTag, shTestDataDeviceBinsTag:
Anton Hansson2f6422c2020-12-31 13:42:10 +0000355 path := android.OutputFileForModule(ctx, dep, "")
356 s.addToDataModules(ctx, path.Base(), path)
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700357 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())
Liz Kammer57f5b332020-11-24 12:42:58 -0800401 entries.AddCompatibilityTestSuites(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
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +0000470type bazelShBinaryAttributes struct {
471 Srcs bazel.LabelList
472 // Bazel also supports the attributes below, but (so far) these are not required for Bionic
473 // deps
474 // data
475 // args
476 // compatible_with
477 // deprecation
478 // distribs
479 // env
480 // exec_compatible_with
481 // exec_properties
482 // features
483 // licenses
484 // output_licenses
485 // restricted_to
486 // tags
487 // target_compatible_with
488 // testonly
489 // toolchains
490 // visibility
491}
492
493type bazelShBinary struct {
494 android.BazelTargetModuleBase
495 bazelShBinaryAttributes
496}
497
498func BazelShBinaryFactory() android.Module {
499 module := &bazelShBinary{}
500 module.AddProperties(&module.bazelShBinaryAttributes)
501 android.InitBazelTargetModule(module)
502 return module
503}
504
505func ShBinaryBp2Build(ctx android.TopDownMutatorContext) {
506 m, ok := ctx.Module().(*ShBinary)
507 if !ok || !m.properties.Bazel_module.Bp2build_available {
508 return
509 }
510
511 srcs := android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src})
512
513 attrs := &bazelShBinaryAttributes{
514 Srcs: srcs,
515 }
516
517 props := bazel.NewBazelTargetModuleProperties(m.Name(), "sh_binary", "")
518
519 ctx.CreateBazelTargetModule(BazelShBinaryFactory, props, attrs)
520}
521
522func (m *bazelShBinary) Name() string {
523 return m.BaseModuleName()
524}
525
526func (m *bazelShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
527
frankfengc5b87492020-06-03 10:28:47 -0700528var Bool = proptools.Bool