Soong package structure refactoring
Give prebuilt_etc and sh_binary their own packages and split the
gigantic main Android.bp up to small, per-package ones.
Test: m nothing, TreeHugger
Bug: 156980228
Change-Id: I7b00cd344b9f16861f1ff39edf0029f016b853d0
diff --git a/android/Android.bp b/android/Android.bp
new file mode 100644
index 0000000..47dbc5d
--- /dev/null
+++ b/android/Android.bp
@@ -0,0 +1,80 @@
+bootstrap_go_package {
+ name: "soong-android",
+ pkgPath: "android/soong/android",
+ deps: [
+ "blueprint",
+ "blueprint-bootstrap",
+ "soong",
+ "soong-android-soongconfig",
+ "soong-env",
+ "soong-shared",
+ "soong-ui-metrics_proto",
+ ],
+ srcs: [
+ "androidmk.go",
+ "apex.go",
+ "api_levels.go",
+ "arch.go",
+ "config.go",
+ "csuite_config.go",
+ "defaults.go",
+ "defs.go",
+ "expand.go",
+ "filegroup.go",
+ "hooks.go",
+ "image.go",
+ "makevars.go",
+ "metrics.go",
+ "module.go",
+ "mutator.go",
+ "namespace.go",
+ "neverallow.go",
+ "notices.go",
+ "onceper.go",
+ "override_module.go",
+ "package.go",
+ "package_ctx.go",
+ "path_properties.go",
+ "paths.go",
+ "prebuilt.go",
+ "proto.go",
+ "register.go",
+ "rule_builder.go",
+ "sandbox.go",
+ "sdk.go",
+ "singleton.go",
+ "soong_config_modules.go",
+ "testing.go",
+ "util.go",
+ "variable.go",
+ "visibility.go",
+ "vts_config.go",
+ "writedocs.go",
+
+ // Lock down environment access last
+ "env.go",
+ ],
+ testSrcs: [
+ "android_test.go",
+ "androidmk_test.go",
+ "arch_test.go",
+ "config_test.go",
+ "csuite_config_test.go",
+ "expand_test.go",
+ "module_test.go",
+ "mutator_test.go",
+ "namespace_test.go",
+ "neverallow_test.go",
+ "onceper_test.go",
+ "package_test.go",
+ "path_properties_test.go",
+ "paths_test.go",
+ "prebuilt_test.go",
+ "rule_builder_test.go",
+ "soong_config_modules_test.go",
+ "util_test.go",
+ "variable_test.go",
+ "visibility_test.go",
+ "vts_config_test.go",
+ ],
+}
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
deleted file mode 100644
index f0c0767..0000000
--- a/android/prebuilt_etc.go
+++ /dev/null
@@ -1,285 +0,0 @@
-// Copyright 2016 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.
-
-package android
-
-import "strconv"
-
-// TODO(jungw): Now that it handles more than the ones in etc/, consider renaming this file.
-
-func init() {
- RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
- RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
- RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
- RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
- RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
- RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
-}
-
-type prebuiltEtcProperties struct {
- // Source file of this prebuilt.
- Src *string `android:"path,arch_variant"`
-
- // 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"`
-
- // Make this module available when building for ramdisk.
- Ramdisk_available *bool
-
- // Make this module available when building for recovery.
- Recovery_available *bool
-
- // Whether this module is directly installable to one of the partitions. Default: true.
- Installable *bool
-
- // Install symlinks to the installed file.
- Symlinks []string `android:"arch_variant"`
-}
-
-type PrebuiltEtcModule interface {
- Module
- SubDir() string
- OutputFile() OutputPath
-}
-
-type PrebuiltEtc struct {
- ModuleBase
-
- properties prebuiltEtcProperties
-
- sourceFilePath Path
- outputFilePath OutputPath
- // The base install location, e.g. "etc" for prebuilt_etc, "usr/share" for prebuilt_usr_share.
- installDirBase string
- // The base install location when soc_specific property is set to true, e.g. "firmware" for prebuilt_firmware.
- socInstallDirBase string
- installDirPath InstallPath
- additionalDependencies *Paths
-}
-
-func (p *PrebuiltEtc) inRamdisk() bool {
- return p.ModuleBase.InRamdisk() || p.ModuleBase.InstallInRamdisk()
-}
-
-func (p *PrebuiltEtc) onlyInRamdisk() bool {
- return p.ModuleBase.InstallInRamdisk()
-}
-
-func (p *PrebuiltEtc) InstallInRamdisk() bool {
- return p.inRamdisk()
-}
-
-func (p *PrebuiltEtc) inRecovery() bool {
- return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery()
-}
-
-func (p *PrebuiltEtc) onlyInRecovery() bool {
- return p.ModuleBase.InstallInRecovery()
-}
-
-func (p *PrebuiltEtc) InstallInRecovery() bool {
- return p.inRecovery()
-}
-
-var _ ImageInterface = (*PrebuiltEtc)(nil)
-
-func (p *PrebuiltEtc) ImageMutatorBegin(ctx BaseModuleContext) {}
-
-func (p *PrebuiltEtc) CoreVariantNeeded(ctx BaseModuleContext) bool {
- return !p.ModuleBase.InstallInRecovery() && !p.ModuleBase.InstallInRamdisk()
-}
-
-func (p *PrebuiltEtc) RamdiskVariantNeeded(ctx BaseModuleContext) bool {
- return Bool(p.properties.Ramdisk_available) || p.ModuleBase.InstallInRamdisk()
-}
-
-func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx BaseModuleContext) bool {
- return Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery()
-}
-
-func (p *PrebuiltEtc) ExtraImageVariations(ctx BaseModuleContext) []string {
- return nil
-}
-
-func (p *PrebuiltEtc) SetImageVariation(ctx BaseModuleContext, variation string, module Module) {
-}
-
-func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) {
- if p.properties.Src == nil {
- ctx.PropertyErrorf("src", "missing prebuilt source file")
- }
-}
-
-func (p *PrebuiltEtc) SourceFilePath(ctx ModuleContext) Path {
- return PathForModuleSrc(ctx, String(p.properties.Src))
-}
-
-func (p *PrebuiltEtc) InstallDirPath() InstallPath {
- return p.installDirPath
-}
-
-// This allows other derivative modules (e.g. prebuilt_etc_xml) to perform
-// additional steps (like validating the src) before the file is installed.
-func (p *PrebuiltEtc) SetAdditionalDependencies(paths Paths) {
- p.additionalDependencies = &paths
-}
-
-func (p *PrebuiltEtc) OutputFile() OutputPath {
- return p.outputFilePath
-}
-
-func (p *PrebuiltEtc) SubDir() string {
- return String(p.properties.Sub_dir)
-}
-
-func (p *PrebuiltEtc) Installable() bool {
- return p.properties.Installable == nil || Bool(p.properties.Installable)
-}
-
-func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx ModuleContext) {
- p.sourceFilePath = PathForModuleSrc(ctx, String(p.properties.Src))
- filename := String(p.properties.Filename)
- filename_from_src := Bool(p.properties.Filename_from_src)
- if filename == "" {
- if filename_from_src {
- filename = p.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
- }
- p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
-
- // If soc install dir was specified and SOC specific is set, set the installDirPath to the specified
- // socInstallDirBase.
- installBaseDir := p.installDirBase
- if ctx.SocSpecific() && p.socInstallDirBase != "" {
- installBaseDir = p.socInstallDirBase
- }
- p.installDirPath = PathForModuleInstall(ctx, installBaseDir, String(p.properties.Sub_dir))
-
- // This ensures that outputFilePath has the correct name for others to
- // use, as the source file may have a different name.
- ctx.Build(pctx, BuildParams{
- Rule: Cp,
- Output: p.outputFilePath,
- Input: p.sourceFilePath,
- })
-}
-
-func (p *PrebuiltEtc) AndroidMkEntries() []AndroidMkEntries {
- nameSuffix := ""
- if p.inRamdisk() && !p.onlyInRamdisk() {
- nameSuffix = ".ramdisk"
- }
- if p.inRecovery() && !p.onlyInRecovery() {
- nameSuffix = ".recovery"
- }
- return []AndroidMkEntries{AndroidMkEntries{
- Class: "ETC",
- SubName: nameSuffix,
- OutputFile: OptionalPathForPath(p.outputFilePath),
- ExtraEntries: []AndroidMkExtraEntriesFunc{
- func(entries *AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_TAGS", "optional")
- entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
- entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
- if len(p.properties.Symlinks) > 0 {
- entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...)
- }
- entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
- if p.additionalDependencies != nil {
- for _, path := range *p.additionalDependencies {
- entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
- }
- }
- },
- },
- }}
-}
-
-func InitPrebuiltEtcModule(p *PrebuiltEtc, dirBase string) {
- p.installDirBase = dirBase
- p.AddProperties(&p.properties)
-}
-
-// prebuilt_etc is for a prebuilt artifact that is installed in
-// <partition>/etc/<sub_dir> directory.
-func PrebuiltEtcFactory() Module {
- module := &PrebuiltEtc{}
- InitPrebuiltEtcModule(module, "etc")
- // This module is device-only
- InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
- return module
-}
-
-// prebuilt_etc_host is for a host prebuilt artifact that is installed in
-// $(HOST_OUT)/etc/<sub_dir> directory.
-func PrebuiltEtcHostFactory() Module {
- module := &PrebuiltEtc{}
- InitPrebuiltEtcModule(module, "etc")
- // This module is host-only
- InitAndroidArchModule(module, HostSupported, MultilibCommon)
- return module
-}
-
-// prebuilt_usr_share is for a prebuilt artifact that is installed in
-// <partition>/usr/share/<sub_dir> directory.
-func PrebuiltUserShareFactory() Module {
- module := &PrebuiltEtc{}
- InitPrebuiltEtcModule(module, "usr/share")
- // This module is device-only
- InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
- return module
-}
-
-// prebuild_usr_share_host is for a host prebuilt artifact that is installed in
-// $(HOST_OUT)/usr/share/<sub_dir> directory.
-func PrebuiltUserShareHostFactory() Module {
- module := &PrebuiltEtc{}
- InitPrebuiltEtcModule(module, "usr/share")
- // This module is host-only
- InitAndroidArchModule(module, HostSupported, MultilibCommon)
- return module
-}
-
-// prebuilt_font installs a font in <partition>/fonts directory.
-func PrebuiltFontFactory() Module {
- module := &PrebuiltEtc{}
- InitPrebuiltEtcModule(module, "fonts")
- // This module is device-only
- InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
- return module
-}
-
-// prebuilt_firmware installs a firmware file to <partition>/etc/firmware directory for system image.
-// If soc_specific property is set to true, the firmware file is installed to the vendor <partition>/firmware
-// directory for vendor image.
-func PrebuiltFirmwareFactory() Module {
- module := &PrebuiltEtc{}
- module.socInstallDirBase = "firmware"
- InitPrebuiltEtcModule(module, "etc/firmware")
- // This module is device-only
- InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
- return module
-}
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
deleted file mode 100644
index 6e751e7..0000000
--- a/android/prebuilt_etc_test.go
+++ /dev/null
@@ -1,254 +0,0 @@
-// Copyright 2018 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.
-
-package android
-
-import (
- "path/filepath"
- "reflect"
- "testing"
-)
-
-func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
- fs := map[string][]byte{
- "foo.conf": nil,
- "bar.conf": nil,
- "baz.conf": nil,
- }
-
- config := TestArchConfig(buildDir, nil, bp, fs)
-
- ctx := NewTestArchContext()
- ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory)
- ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
- ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
- ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
- ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
- ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory)
- ctx.Register(config)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- FailIfErrored(t, errs)
-
- return ctx, config
-}
-
-func TestPrebuiltEtcVariants(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_etc {
- name: "foo.conf",
- src: "foo.conf",
- }
- prebuilt_etc {
- name: "bar.conf",
- src: "bar.conf",
- recovery_available: true,
- }
- prebuilt_etc {
- name: "baz.conf",
- src: "baz.conf",
- recovery: true,
- }
- `)
-
- foo_variants := ctx.ModuleVariantsForTests("foo.conf")
- if len(foo_variants) != 1 {
- t.Errorf("expected 1, got %#v", foo_variants)
- }
-
- bar_variants := ctx.ModuleVariantsForTests("bar.conf")
- if len(bar_variants) != 2 {
- t.Errorf("expected 2, got %#v", bar_variants)
- }
-
- baz_variants := ctx.ModuleVariantsForTests("baz.conf")
- if len(baz_variants) != 1 {
- t.Errorf("expected 1, got %#v", bar_variants)
- }
-}
-
-func TestPrebuiltEtcOutputPath(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_etc {
- name: "foo.conf",
- src: "foo.conf",
- filename: "foo.installed.conf",
- }
- `)
-
- p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- if p.outputFilePath.Base() != "foo.installed.conf" {
- t.Errorf("expected foo.installed.conf, got %q", p.outputFilePath.Base())
- }
-}
-
-func TestPrebuiltEtcGlob(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_etc {
- name: "my_foo",
- src: "foo.*",
- }
- prebuilt_etc {
- name: "my_bar",
- src: "bar.*",
- filename_from_src: true,
- }
- `)
-
- p := ctx.ModuleForTests("my_foo", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- if p.outputFilePath.Base() != "my_foo" {
- t.Errorf("expected my_foo, got %q", p.outputFilePath.Base())
- }
-
- p = ctx.ModuleForTests("my_bar", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- if p.outputFilePath.Base() != "bar.conf" {
- t.Errorf("expected bar.conf, got %q", p.outputFilePath.Base())
- }
-}
-
-func TestPrebuiltEtcAndroidMk(t *testing.T) {
- ctx, config := testPrebuiltEtc(t, `
- prebuilt_etc {
- name: "foo",
- src: "foo.conf",
- owner: "abc",
- filename_from_src: true,
- required: ["modA", "moduleB"],
- host_required: ["hostModA", "hostModB"],
- target_required: ["targetModA"],
- }
- `)
-
- expected := map[string][]string{
- "LOCAL_MODULE": {"foo"},
- "LOCAL_MODULE_CLASS": {"ETC"},
- "LOCAL_MODULE_OWNER": {"abc"},
- "LOCAL_INSTALLED_MODULE_STEM": {"foo.conf"},
- "LOCAL_REQUIRED_MODULES": {"modA", "moduleB"},
- "LOCAL_HOST_REQUIRED_MODULES": {"hostModA", "hostModB"},
- "LOCAL_TARGET_REQUIRED_MODULES": {"targetModA"},
- }
-
- mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- entries := AndroidMkEntriesForTest(t, config, "", mod)[0]
- for k, expectedValue := range expected {
- if value, ok := entries.EntryMap[k]; ok {
- if !reflect.DeepEqual(value, expectedValue) {
- t.Errorf("Incorrect %s '%s', expected '%s'", k, value, expectedValue)
- }
- } else {
- t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
- }
- }
-}
-
-func TestPrebuiltEtcHost(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_etc_host {
- name: "foo.conf",
- src: "foo.conf",
- }
- `)
-
- buildOS := BuildOs.String()
- p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
- if !p.Host() {
- t.Errorf("host bit is not set for a prebuilt_etc_host module.")
- }
-}
-
-func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_usr_share {
- name: "foo.conf",
- src: "foo.conf",
- sub_dir: "bar",
- }
- `)
-
- p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- expected := buildDir + "/target/product/test_device/system/usr/share/bar"
- if p.installDirPath.String() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
- }
-}
-
-func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
- ctx, config := testPrebuiltEtc(t, `
- prebuilt_usr_share_host {
- name: "foo.conf",
- src: "foo.conf",
- sub_dir: "bar",
- }
- `)
-
- buildOS := BuildOs.String()
- p := ctx.ModuleForTests("foo.conf", buildOS+"_common").Module().(*PrebuiltEtc)
- expected := filepath.Join(buildDir, "host", config.PrebuiltOS(), "usr", "share", "bar")
- if p.installDirPath.String() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
- }
-}
-
-func TestPrebuiltFontInstallDirPath(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, `
- prebuilt_font {
- name: "foo.conf",
- src: "foo.conf",
- }
- `)
-
- p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- expected := buildDir + "/target/product/test_device/system/fonts"
- if p.installDirPath.String() != expected {
- t.Errorf("expected %q, got %q", expected, p.installDirPath.String())
- }
-}
-
-func TestPrebuiltFirmwareDirPath(t *testing.T) {
- targetPath := buildDir + "/target/product/test_device"
- tests := []struct {
- description string
- config string
- expectedPath string
- }{{
- description: "prebuilt: system firmware",
- config: `
- prebuilt_firmware {
- name: "foo.conf",
- src: "foo.conf",
- }`,
- expectedPath: filepath.Join(targetPath, "system/etc/firmware"),
- }, {
- description: "prebuilt: vendor firmware",
- config: `
- prebuilt_firmware {
- name: "foo.conf",
- src: "foo.conf",
- soc_specific: true,
- sub_dir: "sub_dir",
- }`,
- expectedPath: filepath.Join(targetPath, "vendor/firmware/sub_dir"),
- }}
- for _, tt := range tests {
- t.Run(tt.description, func(t *testing.T) {
- ctx, _ := testPrebuiltEtc(t, tt.config)
- p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a").Module().(*PrebuiltEtc)
- if p.installDirPath.String() != tt.expectedPath {
- t.Errorf("expected %q, got %q", tt.expectedPath, p.installDirPath)
- }
- })
- }
-}
diff --git a/android/sh_binary.go b/android/sh_binary.go
deleted file mode 100644
index 7d9dc67..0000000
--- a/android/sh_binary.go
+++ /dev/null
@@ -1,259 +0,0 @@
-// 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.
-
-package android
-
-import (
- "fmt"
- "path/filepath"
- "strings"
-)
-
-// 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.
-
-func init() {
- RegisterModuleType("sh_binary", ShBinaryFactory)
- RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
- RegisterModuleType("sh_test", ShTestFactory)
- RegisterModuleType("sh_test_host", ShTestHostFactory)
-}
-
-type shBinaryProperties struct {
- // Source file of this prebuilt.
- Src *string `android:"path,arch_variant"`
-
- // 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
-
- // install symlinks to the binary
- Symlinks []string `android:"arch_variant"`
-}
-
-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.
- Test_config *string `android:"arch_variant"`
-
- // list of files or filegroup modules that provide data that should be installed alongside
- // the test.
- Data []string `android:"path,arch_variant"`
-}
-
-type ShBinary struct {
- ModuleBase
-
- properties shBinaryProperties
-
- sourceFilePath Path
- outputFilePath OutputPath
- installedFile InstallPath
-}
-
-var _ HostToolProvider = (*ShBinary)(nil)
-
-type ShTest struct {
- ShBinary
-
- testProperties TestProperties
-
- data Paths
-}
-
-func (s *ShBinary) HostToolPath() OptionalPath {
- return OptionalPathForPath(s.installedFile)
-}
-
-func (s *ShBinary) DepsMutator(ctx BottomUpMutatorContext) {
- if s.properties.Src == nil {
- ctx.PropertyErrorf("src", "missing prebuilt source file")
- }
-}
-
-func (s *ShBinary) OutputFile() OutputPath {
- return s.outputFilePath
-}
-
-func (s *ShBinary) SubDir() string {
- return String(s.properties.Sub_dir)
-}
-
-func (s *ShBinary) Installable() bool {
- return s.properties.Installable == nil || Bool(s.properties.Installable)
-}
-
-func (s *ShBinary) Symlinks() []string {
- return s.properties.Symlinks
-}
-
-func (s *ShBinary) generateAndroidBuildActions(ctx ModuleContext) {
- s.sourceFilePath = PathForModuleSrc(ctx, String(s.properties.Src))
- filename := String(s.properties.Filename)
- filename_from_src := Bool(s.properties.Filename_from_src)
- 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
- }
- s.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
-
- // This ensures that outputFilePath has the correct name for others to
- // use, as the source file may have a different name.
- ctx.Build(pctx, BuildParams{
- Rule: CpExecutable,
- Output: s.outputFilePath,
- Input: s.sourceFilePath,
- })
-}
-
-func (s *ShBinary) GenerateAndroidBuildActions(ctx ModuleContext) {
- s.generateAndroidBuildActions(ctx)
- installDir := PathForModuleInstall(ctx, "bin", String(s.properties.Sub_dir))
- s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
-}
-
-func (s *ShBinary) AndroidMkEntries() []AndroidMkEntries {
- return []AndroidMkEntries{AndroidMkEntries{
- Class: "EXECUTABLES",
- OutputFile: OptionalPathForPath(s.outputFilePath),
- Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
- ExtraEntries: []AndroidMkExtraEntriesFunc{
- func(entries *AndroidMkEntries) {
- s.customAndroidMkEntries(entries)
- },
- },
- }}
-}
-
-func (s *ShBinary) customAndroidMkEntries(entries *AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_RELATIVE_PATH", String(s.properties.Sub_dir))
- entries.SetString("LOCAL_MODULE_SUFFIX", "")
- entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
- if len(s.properties.Symlinks) > 0 {
- entries.SetString("LOCAL_MODULE_SYMLINKS", strings.Join(s.properties.Symlinks, " "))
- }
-}
-
-func (s *ShTest) GenerateAndroidBuildActions(ctx ModuleContext) {
- s.ShBinary.generateAndroidBuildActions(ctx)
- testDir := "nativetest"
- if ctx.Target().Arch.ArchType.Multilib == "lib64" {
- testDir = "nativetest64"
- }
- if ctx.Target().NativeBridge == NativeBridgeEnabled {
- 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())
- }
- installDir := PathForModuleInstall(ctx, testDir, String(s.properties.Sub_dir))
- s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
-
- s.data = PathsForModuleSrc(ctx, s.testProperties.Data)
-}
-
-func (s *ShTest) InstallInData() bool {
- return true
-}
-
-func (s *ShTest) AndroidMkEntries() []AndroidMkEntries {
- return []AndroidMkEntries{AndroidMkEntries{
- Class: "NATIVE_TESTS",
- OutputFile: OptionalPathForPath(s.outputFilePath),
- Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
- ExtraEntries: []AndroidMkExtraEntriesFunc{
- func(entries *AndroidMkEntries) {
- s.customAndroidMkEntries(entries)
-
- entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
- entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config))
- 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)
- }
- },
- },
- }}
-}
-
-func InitShBinaryModule(s *ShBinary) {
- s.AddProperties(&s.properties)
-}
-
-// sh_binary is for a shell script or batch file to be installed as an
-// executable binary to <partition>/bin.
-func ShBinaryFactory() Module {
- module := &ShBinary{}
- module.Prefer32(func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool {
- return class == Device && ctx.Config().DevicePrefer32BitExecutables()
- })
- InitShBinaryModule(module)
- InitAndroidArchModule(module, HostAndDeviceSupported, MultilibFirst)
- return module
-}
-
-// sh_binary_host is for a shell script to be installed as an executable binary
-// to $(HOST_OUT)/bin.
-func ShBinaryHostFactory() Module {
- module := &ShBinary{}
- InitShBinaryModule(module)
- InitAndroidArchModule(module, HostSupported, MultilibFirst)
- return module
-}
-
-// sh_test defines a shell script based test module.
-func ShTestFactory() Module {
- module := &ShTest{}
- InitShBinaryModule(&module.ShBinary)
- module.AddProperties(&module.testProperties)
-
- InitAndroidArchModule(module, HostAndDeviceSupported, MultilibFirst)
- return module
-}
-
-// sh_test_host defines a shell script based test module that runs on a host.
-func ShTestHostFactory() Module {
- module := &ShTest{}
- InitShBinaryModule(&module.ShBinary)
- module.AddProperties(&module.testProperties)
-
- InitAndroidArchModule(module, HostSupported, MultilibFirst)
- return module
-}
diff --git a/android/sh_binary_test.go b/android/sh_binary_test.go
deleted file mode 100644
index 137e773..0000000
--- a/android/sh_binary_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package android
-
-import (
- "reflect"
- "testing"
-)
-
-func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
- fs := map[string][]byte{
- "test.sh": nil,
- "testdata/data1": nil,
- "testdata/sub/data2": nil,
- }
-
- config := TestArchConfig(buildDir, nil, bp, fs)
-
- ctx := NewTestArchContext()
- ctx.RegisterModuleType("sh_test", ShTestFactory)
- ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
- ctx.Register(config)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- FailIfErrored(t, errs)
-
- return ctx, config
-}
-
-func TestShTestTestData(t *testing.T) {
- ctx, config := testShBinary(t, `
- sh_test {
- name: "foo",
- src: "test.sh",
- filename: "test.sh",
- data: [
- "testdata/data1",
- "testdata/sub/data2",
- ],
- }
- `)
-
- mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
-
- entries := AndroidMkEntriesForTest(t, config, "", mod)[0]
- expected := []string{":testdata/data1", ":testdata/sub/data2"}
- actual := entries.EntryMap["LOCAL_TEST_DATA"]
- if !reflect.DeepEqual(expected, actual) {
- t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
- }
-}
-
-func TestShTestHost(t *testing.T) {
- ctx, _ := testShBinary(t, `
- sh_test_host {
- name: "foo",
- src: "test.sh",
- filename: "test.sh",
- data: [
- "testdata/data1",
- "testdata/sub/data2",
- ],
- }
- `)
-
- buildOS := BuildOs.String()
- mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
- if !mod.Host() {
- t.Errorf("host bit is not set for a sh_test_host module.")
- }
-}
diff --git a/android/soongconfig/Android.bp b/android/soongconfig/Android.bp
new file mode 100644
index 0000000..df912e6
--- /dev/null
+++ b/android/soongconfig/Android.bp
@@ -0,0 +1,13 @@
+bootstrap_go_package {
+ name: "soong-android-soongconfig",
+ pkgPath: "android/soong/android/soongconfig",
+ deps: [
+ "blueprint",
+ "blueprint-parser",
+ "blueprint-proptools",
+ ],
+ srcs: [
+ "config.go",
+ "modules.go",
+ ],
+}