2019-01-26 01:04:11 +01:00
|
|
|
// Copyright 2019 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
package sh
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-07-30 01:46:49 +02:00
|
|
|
"path/filepath"
|
2019-03-08 20:07:05 +01:00
|
|
|
"strings"
|
2020-06-01 19:45:49 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-06-03 19:28:47 +02:00
|
|
|
"android/soong/tradefed"
|
2019-01-26 01:04:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// sh_binary is for shell scripts (and batch files) that are installed as
|
|
|
|
// executable files into .../bin/
|
|
|
|
//
|
|
|
|
// Do not use them for prebuilt C/C++/etc files. Use cc_prebuilt_binary
|
|
|
|
// instead.
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
var pctx = android.NewPackageContext("android/soong/sh")
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
func init() {
|
2020-06-01 19:45:49 +02:00
|
|
|
pctx.Import("android/soong/android")
|
|
|
|
|
|
|
|
android.RegisterModuleType("sh_binary", ShBinaryFactory)
|
|
|
|
android.RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
|
|
|
|
android.RegisterModuleType("sh_test", ShTestFactory)
|
|
|
|
android.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type shBinaryProperties struct {
|
|
|
|
// Source file of this prebuilt.
|
2019-03-05 07:35:41 +01:00
|
|
|
Src *string `android:"path,arch_variant"`
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
// optional subdirectory under which this file is installed into
|
|
|
|
Sub_dir *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// optional name for the installed file. If unspecified, name of the module is used as the file name
|
|
|
|
Filename *string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// when set to true, and filename property is not set, the name for the installed file
|
|
|
|
// is the same as the file name of the source file.
|
|
|
|
Filename_from_src *bool `android:"arch_variant"`
|
|
|
|
|
|
|
|
// Whether this module is directly installable to one of the partitions. Default: true.
|
|
|
|
Installable *bool
|
2019-10-05 05:38:01 +02:00
|
|
|
|
|
|
|
// install symlinks to the binary
|
|
|
|
Symlinks []string `android:"arch_variant"`
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2019-03-08 20:07:05 +01:00
|
|
|
type TestProperties struct {
|
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2020-06-10 00:09:22 +02:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2019-05-16 23:58:29 +02:00
|
|
|
|
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test.
|
|
|
|
Data []string `android:"path,arch_variant"`
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
type ShBinary struct {
|
2020-06-01 19:45:49 +02:00
|
|
|
android.ModuleBase
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
properties shBinaryProperties
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
sourceFilePath android.Path
|
|
|
|
outputFilePath android.OutputPath
|
|
|
|
installedFile android.InstallPath
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
var _ android.HostToolProvider = (*ShBinary)(nil)
|
2019-07-30 01:46:49 +02:00
|
|
|
|
2019-03-08 20:07:05 +01:00
|
|
|
type ShTest struct {
|
|
|
|
ShBinary
|
|
|
|
|
|
|
|
testProperties TestProperties
|
2019-05-16 23:58:29 +02:00
|
|
|
|
2020-06-03 19:28:47 +02:00
|
|
|
data android.Paths
|
|
|
|
testConfig android.Path
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) HostToolPath() android.OptionalPath {
|
|
|
|
return android.OptionalPathForPath(s.installedFile)
|
2019-07-30 01:46:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2019-01-26 01:04:11 +01:00
|
|
|
if s.properties.Src == nil {
|
|
|
|
ctx.PropertyErrorf("src", "missing prebuilt source file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) OutputFile() android.OutputPath {
|
2019-01-26 01:04:11 +01:00
|
|
|
return s.outputFilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShBinary) SubDir() string {
|
2020-06-01 19:45:49 +02:00
|
|
|
return proptools.String(s.properties.Sub_dir)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShBinary) Installable() bool {
|
2020-06-01 19:45:49 +02:00
|
|
|
return s.properties.Installable == nil || proptools.Bool(s.properties.Installable)
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2019-10-05 05:38:01 +02:00
|
|
|
func (s *ShBinary) Symlinks() []string {
|
|
|
|
return s.properties.Symlinks
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) generateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
s.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(s.properties.Src))
|
|
|
|
filename := proptools.String(s.properties.Filename)
|
|
|
|
filename_from_src := proptools.Bool(s.properties.Filename_from_src)
|
2019-01-26 01:04:11 +01:00
|
|
|
if filename == "" {
|
|
|
|
if filename_from_src {
|
|
|
|
filename = s.sourceFilePath.Base()
|
|
|
|
} else {
|
|
|
|
filename = ctx.ModuleName()
|
|
|
|
}
|
|
|
|
} else if filename_from_src {
|
|
|
|
ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
|
|
|
|
return
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
|
2019-01-26 01:04:11 +01:00
|
|
|
|
|
|
|
// This ensures that outputFilePath has the correct name for others to
|
|
|
|
// use, as the source file may have a different name.
|
2020-06-01 19:45:49 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.CpExecutable,
|
2019-01-26 01:04:11 +01:00
|
|
|
Output: s.outputFilePath,
|
|
|
|
Input: s.sourceFilePath,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-07-30 01:46:49 +02:00
|
|
|
s.generateAndroidBuildActions(ctx)
|
2020-06-01 19:45:49 +02:00
|
|
|
installDir := android.PathForModuleInstall(ctx, "bin", proptools.String(s.properties.Sub_dir))
|
2019-07-30 01:46:49 +02:00
|
|
|
s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-01-26 01:04:11 +01:00
|
|
|
Class: "EXECUTABLES",
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile: android.OptionalPathForPath(s.outputFilePath),
|
2019-01-26 01:04:11 +01:00
|
|
|
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
|
2020-06-01 19:45:49 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(entries *android.AndroidMkEntries) {
|
2019-08-28 02:33:16 +02:00
|
|
|
s.customAndroidMkEntries(entries)
|
|
|
|
},
|
2019-01-26 01:04:11 +01:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2019-01-26 01:04:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
|
2019-05-16 23:58:29 +02:00
|
|
|
entries.SetString("LOCAL_MODULE_SUFFIX", "")
|
|
|
|
entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
|
2019-10-05 05:38:01 +02:00
|
|
|
if len(s.properties.Symlinks) > 0 {
|
|
|
|
entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
|
|
|
|
}
|
2019-05-16 23:58:29 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-07-30 01:46:49 +02:00
|
|
|
s.ShBinary.generateAndroidBuildActions(ctx)
|
|
|
|
testDir := "nativetest"
|
|
|
|
if ctx.Target().Arch.ArchType.Multilib == "lib64" {
|
|
|
|
testDir = "nativetest64"
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
|
2019-07-30 01:46:49 +02:00
|
|
|
testDir = filepath.Join(testDir, ctx.Target().NativeBridgeRelativePath)
|
|
|
|
} else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
|
|
|
|
testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
|
|
|
|
}
|
2020-06-01 19:45:49 +02:00
|
|
|
installDir := android.PathForModuleInstall(ctx, testDir, proptools.String(s.properties.Sub_dir))
|
2019-07-30 01:46:49 +02:00
|
|
|
s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
|
2019-05-16 23:58:29 +02:00
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
var configs []tradefed.Config
|
|
|
|
if Bool(s.testProperties.Require_root) {
|
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
|
|
|
} else {
|
|
|
|
options := []tradefed.Option{{Name: "force-root", Value: "false"}}
|
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
|
|
|
|
}
|
|
|
|
s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
|
|
|
|
s.testProperties.Test_config_template, s.testProperties.Test_suites, configs, s.testProperties.Auto_gen_config, s.outputFilePath.Base())
|
2019-05-16 23:58:29 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 01:46:49 +02:00
|
|
|
func (s *ShTest) InstallInData() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
|
|
|
|
return []android.AndroidMkEntries{android.AndroidMkEntries{
|
2019-05-16 23:58:29 +02:00
|
|
|
Class: "NATIVE_TESTS",
|
2020-06-01 19:45:49 +02:00
|
|
|
OutputFile: android.OptionalPathForPath(s.outputFilePath),
|
2019-05-16 23:58:29 +02:00
|
|
|
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
|
2020-06-01 19:45:49 +02:00
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(entries *android.AndroidMkEntries) {
|
2019-08-28 02:33:16 +02:00
|
|
|
s.customAndroidMkEntries(entries)
|
|
|
|
|
|
|
|
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
|
2020-06-10 00:09:22 +02:00
|
|
|
if s.testConfig != nil {
|
|
|
|
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
|
2020-06-03 19:28:47 +02:00
|
|
|
}
|
2019-08-28 02:33:16 +02:00
|
|
|
for _, d := range s.data {
|
|
|
|
rel := d.Rel()
|
|
|
|
path := d.String()
|
|
|
|
if !strings.HasSuffix(path, rel) {
|
|
|
|
panic(fmt.Errorf("path %q does not end with %q", path, rel))
|
|
|
|
}
|
|
|
|
path = strings.TrimSuffix(path, rel)
|
|
|
|
entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
|
2019-05-16 23:58:29 +02:00
|
|
|
}
|
2019-08-28 02:33:16 +02:00
|
|
|
},
|
2019-05-16 23:58:29 +02:00
|
|
|
},
|
2019-12-03 05:24:29 +01:00
|
|
|
}}
|
2019-03-08 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 01:04:11 +01:00
|
|
|
func InitShBinaryModule(s *ShBinary) {
|
|
|
|
s.AddProperties(&s.properties)
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:20:17 +01:00
|
|
|
// sh_binary is for a shell script or batch file to be installed as an
|
|
|
|
// executable binary to <partition>/bin.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShBinaryFactory() android.Module {
|
2019-01-26 01:04:11 +01:00
|
|
|
module := &ShBinary{}
|
|
|
|
InitShBinaryModule(module)
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
|
2019-01-26 01:04:11 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:20:17 +01:00
|
|
|
// sh_binary_host is for a shell script to be installed as an executable binary
|
|
|
|
// to $(HOST_OUT)/bin.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShBinaryHostFactory() android.Module {
|
2019-01-26 01:04:11 +01:00
|
|
|
module := &ShBinary{}
|
|
|
|
InitShBinaryModule(module)
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
2019-01-26 01:04:11 +01:00
|
|
|
return module
|
|
|
|
}
|
2019-03-08 20:07:05 +01:00
|
|
|
|
2019-07-01 18:08:50 +02:00
|
|
|
// sh_test defines a shell script based test module.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShTestFactory() android.Module {
|
2019-03-08 20:07:05 +01:00
|
|
|
module := &ShTest{}
|
|
|
|
InitShBinaryModule(&module.ShBinary)
|
|
|
|
module.AddProperties(&module.testProperties)
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibFirst)
|
2019-03-08 20:07:05 +01:00
|
|
|
return module
|
|
|
|
}
|
2019-07-01 18:08:50 +02:00
|
|
|
|
|
|
|
// sh_test_host defines a shell script based test module that runs on a host.
|
2020-06-01 19:45:49 +02:00
|
|
|
func ShTestHostFactory() android.Module {
|
2019-07-01 18:08:50 +02:00
|
|
|
module := &ShTest{}
|
|
|
|
InitShBinaryModule(&module.ShBinary)
|
|
|
|
module.AddProperties(&module.testProperties)
|
|
|
|
|
2020-06-01 19:45:49 +02:00
|
|
|
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
|
2019-07-01 18:08:50 +02:00
|
|
|
return module
|
|
|
|
}
|
2020-06-03 19:28:47 +02:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|