blob: 031cd47170faa1e505b6b3f1d7191c4f70bd7af6 [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
Dan Willemsenb0552672019-01-25 16:04:11 -080087}
88
Julien Desprez9e7fc142019-03-08 11:07:05 -080089type TestProperties struct {
90 // list of compatibility suites (for example "cts", "vts") that the module should be
91 // installed into.
92 Test_suites []string `android:"arch_variant"`
93
94 // the name of the test configuration (for example "AndroidTest.xml") that should be
95 // installed with the module.
Colin Crossa6384822020-06-09 15:09:22 -070096 Test_config *string `android:"path,arch_variant"`
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070097
98 // list of files or filegroup modules that provide data that should be installed alongside
99 // the test.
100 Data []string `android:"path,arch_variant"`
frankfengc5b87492020-06-03 10:28:47 -0700101
102 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
103 // with root permission.
104 Require_root *bool
105
106 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
107 // should be installed with the module.
108 Test_config_template *string `android:"path,arch_variant"`
109
110 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
111 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
112 // explicitly.
113 Auto_gen_config *bool
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700114
115 // list of binary modules that should be installed alongside the test
116 Data_bins []string `android:"path,arch_variant"`
117
118 // list of library modules that should be installed alongside the test
119 Data_libs []string `android:"path,arch_variant"`
120
121 // list of device binary modules that should be installed alongside the test.
122 // Only available for host sh_test modules.
123 Data_device_bins []string `android:"path,arch_variant"`
124
125 // list of device library modules that should be installed alongside the test.
126 // Only available for host sh_test modules.
127 Data_device_libs []string `android:"path,arch_variant"`
Julien Desprez9e7fc142019-03-08 11:07:05 -0800128}
129
Dan Willemsenb0552672019-01-25 16:04:11 -0800130type ShBinary struct {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700131 android.ModuleBase
Liz Kammerea6666f2021-02-17 10:17:28 -0500132 android.BazelModuleBase
Dan Willemsenb0552672019-01-25 16:04:11 -0800133
134 properties shBinaryProperties
135
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700136 sourceFilePath android.Path
137 outputFilePath android.OutputPath
138 installedFile android.InstallPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800139}
140
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700141var _ android.HostToolProvider = (*ShBinary)(nil)
Colin Cross7c7c1142019-07-29 16:46:49 -0700142
Julien Desprez9e7fc142019-03-08 11:07:05 -0800143type ShTest struct {
144 ShBinary
145
146 testProperties TestProperties
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700147
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700148 installDir android.InstallPath
149
frankfengc5b87492020-06-03 10:28:47 -0700150 data android.Paths
151 testConfig android.Path
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700152
153 dataModules map[string]android.Path
Julien Desprez9e7fc142019-03-08 11:07:05 -0800154}
155
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700156func (s *ShBinary) HostToolPath() android.OptionalPath {
157 return android.OptionalPathForPath(s.installedFile)
Colin Cross7c7c1142019-07-29 16:46:49 -0700158}
159
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700160func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsenb0552672019-01-25 16:04:11 -0800161}
162
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700163func (s *ShBinary) OutputFile() android.OutputPath {
Dan Willemsenb0552672019-01-25 16:04:11 -0800164 return s.outputFilePath
165}
166
167func (s *ShBinary) SubDir() string {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700168 return proptools.String(s.properties.Sub_dir)
Dan Willemsenb0552672019-01-25 16:04:11 -0800169}
170
171func (s *ShBinary) Installable() bool {
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700172 return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
Dan Willemsenb0552672019-01-25 16:04:11 -0800173}
174
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700175func (s *ShBinary) Symlinks() []string {
176 return s.properties.Symlinks
177}
178
Colin Crosscc83efb2020-08-21 14:25:33 -0700179var _ android.ImageInterface = (*ShBinary)(nil)
180
181func (s *ShBinary) ImageMutatorBegin(ctx android.BaseModuleContext) {}
182
183func (s *ShBinary) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
184 return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk()
185}
186
187func (s *ShBinary) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
188 return proptools.Bool(s.properties.Ramdisk_available) || s.ModuleBase.InstallInRamdisk()
189}
190
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700191func (s *ShBinary) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
192 return proptools.Bool(s.properties.Vendor_ramdisk_available) || s.ModuleBase.InstallInVendorRamdisk()
193}
194
Colin Crosscc83efb2020-08-21 14:25:33 -0700195func (s *ShBinary) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
196 return proptools.Bool(s.properties.Recovery_available) || s.ModuleBase.InstallInRecovery()
197}
198
199func (s *ShBinary) ExtraImageVariations(ctx android.BaseModuleContext) []string {
200 return nil
201}
202
203func (s *ShBinary) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
204}
205
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700206func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
Liz Kammer356f7d42021-01-26 09:18:53 -0500207 if s.properties.Src == nil {
208 ctx.PropertyErrorf("src", "missing prebuilt source file")
209 }
210
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700211 s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
212 filename := proptools.String(s.properties.Filename)
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800213 filenameFromSrc := proptools.Bool(s.properties.Filename_from_src)
Dan Willemsenb0552672019-01-25 16:04:11 -0800214 if filename == "" {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800215 if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800216 filename = s.sourceFilePath.Base()
217 } else {
218 filename = ctx.ModuleName()
219 }
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800220 } else if filenameFromSrc {
Dan Willemsenb0552672019-01-25 16:04:11 -0800221 ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
222 return
223 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700224 s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
Dan Willemsenb0552672019-01-25 16:04:11 -0800225
226 // This ensures that outputFilePath has the correct name for others to
227 // use, as the source file may have a different name.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700228 ctx.Build(pctx, android.BuildParams{
229 Rule: android.CpExecutable,
Dan Willemsenb0552672019-01-25 16:04:11 -0800230 Output: s.outputFilePath,
231 Input: s.sourceFilePath,
232 })
233}
234
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700235func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700236 s.generateAndroidBuildActions(ctx)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700237 installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
Colin Cross7c7c1142019-07-29 16:46:49 -0700238 s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
239}
240
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700241func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
242 return []android.AndroidMkEntries{android.AndroidMkEntries{
Dan Willemsenb0552672019-01-25 16:04:11 -0800243 Class: "EXECUTABLES",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700244 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Dan Willemsenb0552672019-01-25 16:04:11 -0800245 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700246 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700247 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700248 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700249 entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700250 },
Dan Willemsenb0552672019-01-25 16:04:11 -0800251 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900252 }}
Dan Willemsenb0552672019-01-25 16:04:11 -0800253}
254
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700255func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700256 entries.SetString("LOCAL_MODULE_SUFFIX", "")
257 entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
Rashed Abdel-Tawab6a341312019-10-04 20:38:01 -0700258 if len(s.properties.Symlinks) > 0 {
259 entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
260 }
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700261}
262
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700263type dependencyTag struct {
264 blueprint.BaseDependencyTag
265 name string
266}
267
268var (
269 shTestDataBinsTag = dependencyTag{name: "dataBins"}
270 shTestDataLibsTag = dependencyTag{name: "dataLibs"}
271 shTestDataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
272 shTestDataDeviceLibsTag = dependencyTag{name: "dataDeviceLibs"}
273)
274
275var sharedLibVariations = []blueprint.Variation{{Mutator: "link", Variation: "shared"}}
276
277func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) {
278 s.ShBinary.DepsMutator(ctx)
279
280 ctx.AddFarVariationDependencies(ctx.Target().Variations(), shTestDataBinsTag, s.testProperties.Data_bins...)
281 ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...),
282 shTestDataLibsTag, s.testProperties.Data_libs...)
Liz Kammer356f7d42021-01-26 09:18:53 -0500283 if (ctx.Target().Os.Class == android.Host || ctx.BazelConversionMode()) && len(ctx.Config().Targets[android.Android]) > 0 {
Jaewoong Jung642916f2020-10-09 17:25:15 -0700284 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700285 ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...)
286 ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...),
287 shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)
288 } else if ctx.Target().Os.Class != android.Host {
289 if len(s.testProperties.Data_device_bins) > 0 {
290 ctx.PropertyErrorf("data_device_bins", "only available for host modules")
291 }
292 if len(s.testProperties.Data_device_libs) > 0 {
293 ctx.PropertyErrorf("data_device_libs", "only available for host modules")
294 }
295 }
296}
297
298func (s *ShTest) addToDataModules(ctx android.ModuleContext, relPath string, path android.Path) {
299 if _, exists := s.dataModules[relPath]; exists {
300 ctx.ModuleErrorf("data modules have a conflicting installation path, %v - %s, %s",
301 relPath, s.dataModules[relPath].String(), path.String())
302 return
303 }
304 s.dataModules[relPath] = path
305}
306
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700307func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross7c7c1142019-07-29 16:46:49 -0700308 s.ShBinary.generateAndroidBuildActions(ctx)
309 testDir := "nativetest"
310 if ctx.Target().Arch.ArchType.Multilib == "lib64" {
311 testDir = "nativetest64"
312 }
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700313 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross7c7c1142019-07-29 16:46:49 -0700314 testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
315 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
316 testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
317 }
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700318 if s.SubDir() != "" {
319 // Don't add the module name to the installation path if sub_dir is specified for backward
320 // compatibility.
321 s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
322 } else {
323 s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
324 }
325 s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700326
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700327 s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
frankfengc5b87492020-06-03 10:28:47 -0700328
329 var configs []tradefed.Config
330 if Bool(s.testProperties.Require_root) {
331 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
332 } else {
333 options := []tradefed.Option{{Name: "force-root", Value: "false"}}
334 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
335 }
frankfengbe6ae772020-09-28 13:22:57 -0700336 if len(s.testProperties.Data_device_bins) > 0 {
337 moduleName := s.Name()
338 remoteDir := "/data/local/tests/unrestricted/" + moduleName + "/"
339 options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
340 for _, bin := range s.testProperties.Data_device_bins {
341 options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: remoteDir + bin})
342 }
343 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
344 }
frankfengc5b87492020-06-03 10:28:47 -0700345 s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
346 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 -0700347
348 s.dataModules = make(map[string]android.Path)
349 ctx.VisitDirectDeps(func(dep android.Module) {
350 depTag := ctx.OtherModuleDependencyTag(dep)
351 switch depTag {
352 case shTestDataBinsTag, shTestDataDeviceBinsTag:
Anton Hansson2f6422c2020-12-31 13:42:10 +0000353 path := android.OutputFileForModule(ctx, dep, "")
354 s.addToDataModules(ctx, path.Base(), path)
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700355 case shTestDataLibsTag, shTestDataDeviceLibsTag:
356 if cc, isCc := dep.(*cc.Module); isCc {
357 // Copy to an intermediate output directory to append "lib[64]" to the path,
358 // so that it's compatible with the default rpath values.
359 var relPath string
360 if cc.Arch().ArchType.Multilib == "lib64" {
361 relPath = filepath.Join("lib64", cc.OutputFile().Path().Base())
362 } else {
363 relPath = filepath.Join("lib", cc.OutputFile().Path().Base())
364 }
365 if _, exist := s.dataModules[relPath]; exist {
366 return
367 }
368 relocatedLib := android.PathForModuleOut(ctx, "relocated", relPath)
369 ctx.Build(pctx, android.BuildParams{
370 Rule: android.Cp,
371 Input: cc.OutputFile().Path(),
372 Output: relocatedLib,
373 })
374 s.addToDataModules(ctx, relPath, relocatedLib)
375 return
376 }
377 property := "data_libs"
378 if depTag == shTestDataDeviceBinsTag {
379 property = "data_device_libs"
380 }
381 ctx.PropertyErrorf(property, "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
382 }
383 })
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700384}
385
Colin Cross7c7c1142019-07-29 16:46:49 -0700386func (s *ShTest) InstallInData() bool {
387 return true
388}
389
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700390func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
391 return []android.AndroidMkEntries{android.AndroidMkEntries{
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700392 Class: "NATIVE_TESTS",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700393 OutputFile: android.OptionalPathForPath(s.outputFilePath),
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700394 Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700395 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
Colin Crossaa255532020-07-03 13:18:24 -0700396 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700397 s.customAndroidMkEntries(entries)
Jaewoong Jung4aedc862020-06-10 17:23:46 -0700398 entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath())
Liz Kammer57f5b332020-11-24 12:42:58 -0800399 entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...)
Colin Crossa6384822020-06-09 15:09:22 -0700400 if s.testConfig != nil {
401 entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
frankfengc5b87492020-06-03 10:28:47 -0700402 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700403 for _, d := range s.data {
404 rel := d.Rel()
405 path := d.String()
406 if !strings.HasSuffix(path, rel) {
407 panic(fmt.Errorf("path %q does not end with %q", path, rel))
408 }
409 path = strings.TrimSuffix(path, rel)
410 entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700411 }
Jaewoong Jung6e0eee52020-05-29 16:15:32 -0700412 relPaths := make([]string, 0)
413 for relPath, _ := range s.dataModules {
414 relPaths = append(relPaths, relPath)
415 }
416 sort.Strings(relPaths)
417 for _, relPath := range relPaths {
418 dir := strings.TrimSuffix(s.dataModules[relPath].String(), relPath)
419 entries.AddStrings("LOCAL_TEST_DATA", dir+":"+relPath)
420 }
Jaewoong Junge0dc8df2019-08-27 17:33:16 -0700421 },
Jaewoong Jung8eaeb092019-05-16 14:58:29 -0700422 },
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900423 }}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800424}
425
Dan Willemsenb0552672019-01-25 16:04:11 -0800426func InitShBinaryModule(s *ShBinary) {
427 s.AddProperties(&s.properties)
Liz Kammerea6666f2021-02-17 10:17:28 -0500428 android.InitBazelModule(s)
Dan Willemsenb0552672019-01-25 16:04:11 -0800429}
430
Patrice Arrudae1034192019-03-11 13:20:17 -0700431// sh_binary is for a shell script or batch file to be installed as an
432// executable binary to <partition>/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700433func ShBinaryFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800434 module := &ShBinary{}
435 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700436 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800437 return module
438}
439
Patrice Arrudae1034192019-03-11 13:20:17 -0700440// sh_binary_host is for a shell script to be installed as an executable binary
441// to $(HOST_OUT)/bin.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700442func ShBinaryHostFactory() android.Module {
Dan Willemsenb0552672019-01-25 16:04:11 -0800443 module := &ShBinary{}
444 InitShBinaryModule(module)
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700445 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Dan Willemsenb0552672019-01-25 16:04:11 -0800446 return module
447}
Julien Desprez9e7fc142019-03-08 11:07:05 -0800448
Jaewoong Jung61a83682019-07-01 09:08:50 -0700449// sh_test defines a shell script based test module.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700450func ShTestFactory() android.Module {
Julien Desprez9e7fc142019-03-08 11:07:05 -0800451 module := &ShTest{}
452 InitShBinaryModule(&module.ShBinary)
453 module.AddProperties(&module.testProperties)
454
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700455 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
Julien Desprez9e7fc142019-03-08 11:07:05 -0800456 return module
457}
Jaewoong Jung61a83682019-07-01 09:08:50 -0700458
459// sh_test_host defines a shell script based test module that runs on a host.
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700460func ShTestHostFactory() android.Module {
Jaewoong Jung61a83682019-07-01 09:08:50 -0700461 module := &ShTest{}
462 InitShBinaryModule(&module.ShBinary)
463 module.AddProperties(&module.testProperties)
464
Jaewoong Jung4b79e982020-06-01 10:45:49 -0700465 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
Jaewoong Jung61a83682019-07-01 09:08:50 -0700466 return module
467}
frankfengc5b87492020-06-03 10:28:47 -0700468
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +0000469type bazelShBinaryAttributes struct {
470 Srcs bazel.LabelList
471 // Bazel also supports the attributes below, but (so far) these are not required for Bionic
472 // deps
473 // data
474 // args
475 // compatible_with
476 // deprecation
477 // distribs
478 // env
479 // exec_compatible_with
480 // exec_properties
481 // features
482 // licenses
483 // output_licenses
484 // restricted_to
485 // tags
486 // target_compatible_with
487 // testonly
488 // toolchains
489 // visibility
490}
491
492type bazelShBinary struct {
493 android.BazelTargetModuleBase
494 bazelShBinaryAttributes
495}
496
497func BazelShBinaryFactory() android.Module {
498 module := &bazelShBinary{}
499 module.AddProperties(&module.bazelShBinaryAttributes)
500 android.InitBazelTargetModule(module)
501 return module
502}
503
504func ShBinaryBp2Build(ctx android.TopDownMutatorContext) {
505 m, ok := ctx.Module().(*ShBinary)
Liz Kammerea6666f2021-02-17 10:17:28 -0500506 if !ok || !m.ConvertWithBp2build() {
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +0000507 return
508 }
509
510 srcs := android.BazelLabelForModuleSrc(ctx, []string{*m.properties.Src})
511
512 attrs := &bazelShBinaryAttributes{
513 Srcs: srcs,
514 }
515
Liz Kammerfc46bc12021-02-19 11:06:17 -0500516 props := bazel.BazelTargetModuleProperties{
517 Rule_class: "sh_binary",
518 }
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +0000519
Liz Kammerfc46bc12021-02-19 11:06:17 -0500520 ctx.CreateBazelTargetModule(BazelShBinaryFactory, m.Name(), props, attrs)
Rupert Shuttlewortha1a56e82021-02-09 10:59:06 +0000521}
522
523func (m *bazelShBinary) Name() string {
524 return m.BaseModuleName()
525}
526
527func (m *bazelShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
528
frankfengc5b87492020-06-03 10:28:47 -0700529var Bool = proptools.Bool