Merge "Force ART modules to be built from source here, regardless of default."
diff --git a/android/packaging.go b/android/packaging.go
index da745ff..9b901ce 100644
--- a/android/packaging.go
+++ b/android/packaging.go
@@ -49,6 +49,11 @@
return ""
}
+// Path relative to the root of the package
+func (p *PackagingSpec) RelPathInPackage() string {
+ return p.relPathInPackage
+}
+
type PackageModule interface {
Module
packagingBase() *PackagingBase
@@ -61,7 +66,7 @@
// returns zip entries in it. This is expected to be called in GenerateAndroidBuildActions,
// followed by a build rule that unzips it and creates the final output (img, zip, tar.gz,
// etc.) from the extracted files
- CopyDepsToZip(ctx ModuleContext, zipOut OutputPath) []string
+ CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) []string
}
// PackagingBase provides basic functionality for packaging dependencies. A module is expected to
@@ -87,9 +92,17 @@
Lib64 depsProperty `android:"arch_variant"`
}
+type packagingArchProperties struct {
+ Arm64 depsProperty
+ Arm depsProperty
+ X86_64 depsProperty
+ X86 depsProperty
+}
+
type PackagingProperties struct {
Deps []string `android:"arch_variant"`
Multilib packagingMultilibProperties `android:"arch_variant"`
+ Arch packagingArchProperties
}
func InitPackageModule(p PackageModule) {
@@ -116,6 +129,7 @@
} else if arch == Common {
ret = append(ret, p.properties.Multilib.Common.Deps...)
}
+
for i, t := range ctx.MultiTargets() {
if t.Arch.ArchType == arch {
ret = append(ret, p.properties.Deps...)
@@ -124,6 +138,20 @@
}
}
}
+
+ if ctx.Arch().ArchType == Common {
+ switch arch {
+ case Arm64:
+ ret = append(ret, p.properties.Arch.Arm64.Deps...)
+ case Arm:
+ ret = append(ret, p.properties.Arch.Arm.Deps...)
+ case X86_64:
+ ret = append(ret, p.properties.Arch.X86_64.Deps...)
+ case X86:
+ ret = append(ret, p.properties.Arch.X86.Deps...)
+ }
+ }
+
return FirstUniqueStrings(ret)
}
@@ -152,7 +180,7 @@
}
// See PackageModule.CopyDepsToZip
-func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut OutputPath) (entries []string) {
+func (p *PackagingBase) CopyDepsToZip(ctx ModuleContext, zipOut WritablePath) (entries []string) {
m := make(map[string]PackagingSpec)
ctx.WalkDeps(func(child Module, parent Module) bool {
if !IsInstallDepNeeded(ctx.OtherModuleDependencyTag(child)) {
@@ -168,7 +196,7 @@
builder := NewRuleBuilder(pctx, ctx)
- dir := PathForModuleOut(ctx, ".zip").OutputPath
+ dir := PathForModuleOut(ctx, ".zip")
builder.Command().Text("rm").Flag("-rf").Text(dir.String())
builder.Command().Text("mkdir").Flag("-p").Text(dir.String())
diff --git a/android/packaging_test.go b/android/packaging_test.go
index 7269bfb..2c99b97 100644
--- a/android/packaging_test.go
+++ b/android/packaging_test.go
@@ -61,30 +61,45 @@
entries []string
}
-func packageTestModuleFactory() Module {
+func packageMultiTargetTestModuleFactory() Module {
module := &packageTestModule{}
InitPackageModule(module)
InitAndroidMultiTargetsArchModule(module, DeviceSupported, MultilibCommon)
return module
}
+func packageTestModuleFactory() Module {
+ module := &packageTestModule{}
+ InitPackageModule(module)
+ InitAndroidArchModule(module, DeviceSupported, MultilibBoth)
+ return module
+}
+
func (m *packageTestModule) DepsMutator(ctx BottomUpMutatorContext) {
m.AddDeps(ctx, installDepTag{})
}
func (m *packageTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
- zipFile := PathForModuleOut(ctx, "myzip.zip").OutputPath
+ zipFile := PathForModuleOut(ctx, "myzip.zip")
m.entries = m.CopyDepsToZip(ctx, zipFile)
}
-func runPackagingTest(t *testing.T, bp string, expected []string) {
+func runPackagingTest(t *testing.T, multitarget bool, bp string, expected []string) {
t.Helper()
config := TestArchConfig(buildDir, nil, bp, nil)
ctx := NewTestArchContext(config)
ctx.RegisterModuleType("component", componentTestModuleFactory)
- ctx.RegisterModuleType("package_module", packageTestModuleFactory)
+
+ var archVariant string
+ if multitarget {
+ archVariant = "android_common"
+ ctx.RegisterModuleType("package_module", packageMultiTargetTestModuleFactory)
+ } else {
+ archVariant = "android_arm64_armv8-a"
+ ctx.RegisterModuleType("package_module", packageTestModuleFactory)
+ }
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
@@ -92,7 +107,7 @@
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
- p := ctx.ModuleForTests("package", "android_common").Module().(*packageTestModule)
+ p := ctx.ModuleForTests("package", archVariant).Module().(*packageTestModule)
actual := p.entries
actual = SortedUniqueStrings(actual)
expected = SortedUniqueStrings(expected)
@@ -101,8 +116,9 @@
}
}
-func TestPackagingBase(t *testing.T) {
- runPackagingTest(t,
+func TestPackagingBaseMultiTarget(t *testing.T) {
+ multiTarget := true
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -114,7 +130,7 @@
}
`, []string{"lib64/foo"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -131,7 +147,7 @@
}
`, []string{"lib64/foo", "lib64/bar"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -149,7 +165,7 @@
}
`, []string{"lib32/foo", "lib32/bar", "lib64/foo", "lib64/bar"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -172,7 +188,7 @@
}
`, []string{"lib32/foo", "lib32/bar", "lib64/foo"})
- runPackagingTest(t,
+ runPackagingTest(t, multiTarget,
`
component {
name: "foo",
@@ -193,4 +209,136 @@
compile_multilib: "both",
}
`, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ component {
+ name: "baz",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ arch: {
+ arm64: {
+ deps: ["bar"],
+ },
+ x86_64: {
+ deps: ["baz"],
+ },
+ },
+ compile_multilib: "both",
+ }
+ `, []string{"lib32/foo", "lib64/foo", "lib64/bar"})
+}
+
+func TestPackagingBaseSingleTarget(t *testing.T) {
+ multiTarget := false
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ }
+ `, []string{"lib64/foo"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ deps: ["bar"],
+ }
+
+ component {
+ name: "bar",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ compile_multilib: "32",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ multilib: {
+ lib32: {
+ deps: ["bar"],
+ },
+ },
+ }
+ `, []string{"lib64/foo"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ multilib: {
+ lib64: {
+ deps: ["bar"],
+ },
+ },
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
+
+ runPackagingTest(t, multiTarget,
+ `
+ component {
+ name: "foo",
+ }
+
+ component {
+ name: "bar",
+ }
+
+ component {
+ name: "baz",
+ }
+
+ package_module {
+ name: "package",
+ deps: ["foo"],
+ arch: {
+ arm64: {
+ deps: ["bar"],
+ },
+ x86_64: {
+ deps: ["baz"],
+ },
+ },
+ }
+ `, []string{"lib64/foo", "lib64/bar"})
}
diff --git a/android/paths.go b/android/paths.go
index b5a1401..8106958 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -1011,8 +1011,13 @@
return p.config.buildDir
}
+func (p OutputPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
+ return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
+}
+
var _ Path = OutputPath{}
var _ WritablePath = OutputPath{}
+var _ objPathProvider = OutputPath{}
// toolDepPath is a Path representing a dependency of the build tool.
type toolDepPath struct {
diff --git a/bp2build/bp2build.go b/bp2build/bp2build.go
index a414f04..b89d0a0 100644
--- a/bp2build/bp2build.go
+++ b/bp2build/bp2build.go
@@ -28,7 +28,7 @@
ruleShims := CreateRuleShims(android.ModuleTypeFactories())
- buildToTargets := GenerateSoongModuleTargets(ctx.Context(), ctx.mode)
+ buildToTargets := GenerateBazelTargets(ctx.Context(), ctx.mode)
filesToWrite := CreateBazelFiles(ruleShims, buildToTargets, ctx.mode)
for _, f := range filesToWrite {
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 1af1d60..1fa3e06 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -159,7 +159,7 @@
return attributes
}
-func GenerateSoongModuleTargets(ctx bpToBuildContext, codegenMode CodegenMode) map[string]BazelTargets {
+func GenerateBazelTargets(ctx bpToBuildContext, codegenMode CodegenMode) map[string]BazelTargets {
buildFileToTargets := make(map[string]BazelTargets)
ctx.VisitAllModules(func(m blueprint.Module) {
dir := ctx.ModuleDir(m)
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index a01a7cd..df7dd17 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -201,7 +201,7 @@
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, QueryView)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, QueryView)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@@ -252,7 +252,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("Expected %d bazel target, got %d", expectedCount, actualCount)
}
@@ -408,7 +408,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount := len(bazelTargets); actualCount != testCase.expectedBazelTargetCount {
t.Fatalf("Expected %d bazel target, got %d", testCase.expectedBazelTargetCount, actualCount)
}
@@ -617,7 +617,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
t.Fatalf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount)
}
@@ -815,7 +815,7 @@
_, errs = ctx.ResolveDependencies(config)
android.FailIfErrored(t, errs)
- bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, Bp2Build)[dir]
+ bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[dir]
if actualCount := len(bazelTargets); actualCount != 1 {
t.Fatalf("%s: Expected 1 bazel target, got %d", testCase.description, actualCount)
}
diff --git a/cmd/soong_build/queryview.go b/cmd/soong_build/queryview.go
index 5d61d0c..dc0b323 100644
--- a/cmd/soong_build/queryview.go
+++ b/cmd/soong_build/queryview.go
@@ -24,7 +24,7 @@
func createBazelQueryView(ctx *android.Context, bazelQueryViewDir string) error {
ruleShims := bp2build.CreateRuleShims(android.ModuleTypeFactories())
- buildToTargets := bp2build.GenerateSoongModuleTargets(*ctx, bp2build.QueryView)
+ buildToTargets := bp2build.GenerateBazelTargets(*ctx, bp2build.QueryView)
filesToWrite := bp2build.CreateBazelFiles(ruleShims, buildToTargets, bp2build.QueryView)
for _, f := range filesToWrite {
diff --git a/filesystem/Android.bp b/filesystem/Android.bp
index 926df6e..9994241 100644
--- a/filesystem/Android.bp
+++ b/filesystem/Android.bp
@@ -7,6 +7,7 @@
"soong-android",
],
srcs: [
+ "bootimg.go",
"filesystem.go",
],
testSrcs: [
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
new file mode 100644
index 0000000..4bc1823
--- /dev/null
+++ b/filesystem/bootimg.go
@@ -0,0 +1,222 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// 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 filesystem
+
+import (
+ "fmt"
+ "strconv"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterModuleType("bootimg", bootimgFactory)
+}
+
+type bootimg struct {
+ android.ModuleBase
+
+ properties bootimgProperties
+
+ output android.OutputPath
+ installDir android.InstallPath
+}
+
+type bootimgProperties struct {
+ // Path to the linux kernel prebuilt file
+ Kernel_prebuilt *string `android:"arch_variant,path"`
+
+ // Filesystem module that is used as ramdisk
+ Ramdisk_module *string
+
+ // Path to the device tree blob (DTB) prebuilt file to add to this boot image
+ Dtb_prebuilt *string `android:"arch_variant,path"`
+
+ // Header version number. Must be set to one of the version numbers that are currently
+ // supported. Refer to
+ // https://source.android.com/devices/bootloader/boot-image-header
+ Header_version *string
+
+ // Determines if this image is for the vendor_boot partition. Default is false. Refer to
+ // https://source.android.com/devices/bootloader/partitions/vendor-boot-partitions
+ Vendor_boot *bool
+
+ // Optional kernel commandline
+ Cmdline *string
+
+ // When set to true, sign the image with avbtool. Default is false.
+ Use_avb *bool
+
+ // Name of the partition stored in vbmeta desc. Defaults to the name of this module.
+ Partition_name *string
+
+ // Path to the private key that avbtool will use to sign this filesystem image.
+ // TODO(jiyong): allow apex_key to be specified here
+ Avb_private_key *string `android:"path"`
+
+ // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
+ Avb_algorithm *string
+}
+
+// bootimg is the image for the boot partition. It consists of header, kernel, ramdisk, and dtb.
+func bootimgFactory() android.Module {
+ module := &bootimg{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ return module
+}
+
+type bootimgDep struct {
+ blueprint.BaseDependencyTag
+ kind string
+}
+
+var bootimgRamdiskDep = bootimgDep{kind: "ramdisk"}
+
+func (b *bootimg) DepsMutator(ctx android.BottomUpMutatorContext) {
+ ramdisk := proptools.String(b.properties.Ramdisk_module)
+ if ramdisk != "" {
+ ctx.AddDependency(ctx.Module(), bootimgRamdiskDep, ramdisk)
+ }
+}
+
+func (b *bootimg) installFileName() string {
+ return b.BaseModuleName() + ".img"
+}
+
+func (b *bootimg) partitionName() string {
+ return proptools.StringDefault(b.properties.Partition_name, b.BaseModuleName())
+}
+
+func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ var unsignedOutput android.OutputPath
+ if proptools.Bool(b.properties.Vendor_boot) {
+ unsignedOutput = b.buildVendorBootImage(ctx)
+ } else {
+ // TODO(jiyong): fix this
+ ctx.PropertyErrorf("vendor_boot", "only vendor_boot:true is supported")
+ }
+
+ if proptools.Bool(b.properties.Use_avb) {
+ b.output = b.signImage(ctx, unsignedOutput)
+ } else {
+ b.output = unsignedOutput
+ }
+
+ b.installDir = android.PathForModuleInstall(ctx, "etc")
+ ctx.InstallFile(b.installDir, b.installFileName(), b.output)
+}
+
+func (b *bootimg) buildVendorBootImage(ctx android.ModuleContext) android.OutputPath {
+ output := android.PathForModuleOut(ctx, "unsigned.img").OutputPath
+ builder := android.NewRuleBuilder(pctx, ctx)
+ cmd := builder.Command().BuiltTool("mkbootimg")
+
+ kernel := android.OptionalPathForModuleSrc(ctx, b.properties.Kernel_prebuilt)
+ if kernel.Valid() {
+ ctx.PropertyErrorf("kernel_prebuilt", "vendor_boot partition can't have kernel")
+ return output
+ }
+
+ dtbName := proptools.String(b.properties.Dtb_prebuilt)
+ if dtbName == "" {
+ ctx.PropertyErrorf("dtb_prebuilt", "must be set")
+ return output
+ }
+ dtb := android.PathForModuleSrc(ctx, dtbName)
+ cmd.FlagWithInput("--dtb ", dtb)
+
+ cmdline := proptools.String(b.properties.Cmdline)
+ if cmdline != "" {
+ cmd.FlagWithArg("--vendor_cmdline ", "\""+cmdline+"\"")
+ }
+
+ headerVersion := proptools.String(b.properties.Header_version)
+ if headerVersion == "" {
+ ctx.PropertyErrorf("header_version", "must be set")
+ return output
+ }
+ verNum, err := strconv.Atoi(headerVersion)
+ if err != nil {
+ ctx.PropertyErrorf("header_version", "%q is not a number", headerVersion)
+ return output
+ }
+ if verNum < 3 {
+ ctx.PropertyErrorf("header_version", "must be 3 or higher for vendor_boot")
+ return output
+ }
+ cmd.FlagWithArg("--header_version ", headerVersion)
+
+ ramdiskName := proptools.String(b.properties.Ramdisk_module)
+ if ramdiskName == "" {
+ ctx.PropertyErrorf("ramdisk_module", "must be set")
+ return output
+ }
+ ramdisk := ctx.GetDirectDepWithTag(ramdiskName, bootimgRamdiskDep)
+ if filesystem, ok := ramdisk.(*filesystem); ok {
+ cmd.FlagWithInput("--vendor_ramdisk ", filesystem.OutputPath())
+ } else {
+ ctx.PropertyErrorf("ramdisk", "%q is not android_filesystem module", ramdisk.Name())
+ return output
+ }
+
+ cmd.FlagWithOutput("--vendor_boot ", output)
+
+ builder.Build("build_vendor_bootimg", fmt.Sprintf("Creating %s", b.BaseModuleName()))
+ return output
+}
+
+func (b *bootimg) signImage(ctx android.ModuleContext, unsignedImage android.OutputPath) android.OutputPath {
+ signedImage := android.PathForModuleOut(ctx, "signed.img").OutputPath
+ key := android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key))
+
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().Text("cp").Input(unsignedImage).Output(signedImage)
+ builder.Command().
+ BuiltTool("avbtool").
+ Flag("add_hash_footer").
+ FlagWithArg("--partition_name ", b.partitionName()).
+ FlagWithInput("--key ", key).
+ FlagWithOutput("--image ", signedImage)
+
+ builder.Build("sign_bootimg", fmt.Sprintf("Signing %s", b.BaseModuleName()))
+
+ return signedImage
+}
+
+var _ android.AndroidMkEntriesProvider = (*bootimg)(nil)
+
+// Implements android.AndroidMkEntriesProvider
+func (b *bootimg) AndroidMkEntries() []android.AndroidMkEntries {
+ return []android.AndroidMkEntries{android.AndroidMkEntries{
+ Class: "ETC",
+ OutputFile: android.OptionalPathForPath(b.output),
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_PATH", b.installDir.ToMakePath().String())
+ entries.SetString("LOCAL_INSTALLED_MODULE_STEM", b.installFileName())
+ },
+ },
+ }}
+}
+
+var _ Filesystem = (*bootimg)(nil)
+
+func (b *bootimg) OutputPath() android.Path {
+ return b.output
+}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 654617c..5092ad0 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -47,6 +47,10 @@
// Hash and signing algorithm for avbtool. Default is SHA256_RSA4096.
Avb_algorithm *string
+
+ // Type of the filesystem. Currently, ext4 and compressed_cpio are supported. Default is
+ // ext4.
+ Type *string
}
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
@@ -71,6 +75,27 @@
f.AddDeps(ctx, dependencyTag)
}
+type fsType int
+
+const (
+ ext4Type fsType = iota
+ compressedCpioType
+ unknown
+)
+
+func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
+ typeStr := proptools.StringDefault(f.properties.Type, "ext4")
+ switch typeStr {
+ case "ext4":
+ return ext4Type
+ case "compressed_cpio":
+ return compressedCpioType
+ default:
+ ctx.PropertyErrorf("type", "%q not supported", typeStr)
+ return unknown
+ }
+}
+
func (f *filesystem) installFileName() string {
return f.BaseModuleName() + ".img"
}
@@ -78,6 +103,20 @@
var pctx = android.NewPackageContext("android/soong/filesystem")
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ switch f.fsType(ctx) {
+ case ext4Type:
+ f.output = f.buildImageUsingBuildImage(ctx)
+ case compressedCpioType:
+ f.output = f.buildCompressedCpioImage(ctx)
+ default:
+ return
+ }
+
+ f.installDir = android.PathForModuleInstall(ctx, "etc")
+ ctx.InstallFile(f.installDir, f.installFileName(), f.output)
+}
+
+func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) android.OutputPath {
zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
f.CopyDepsToZip(ctx, zipFile)
@@ -89,19 +128,18 @@
Input(zipFile)
propFile, toolDeps := f.buildPropFile(ctx)
- f.output = android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
builder.Command().BuiltTool("build_image").
Text(rootDir.String()). // input directory
Input(propFile).
Implicits(toolDeps).
- Output(f.output).
+ Output(output).
Text(rootDir.String()) // directory where to find fs_config_files|dirs
// rootDir is not deleted. Might be useful for quick inspection.
builder.Build("build_filesystem_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
- f.installDir = android.PathForModuleInstall(ctx, "etc")
- ctx.InstallFile(f.installDir, f.installFileName(), f.output)
+ return output
}
func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.OutputPath, toolDeps android.Paths) {
@@ -120,8 +158,17 @@
deps = append(deps, path)
}
- // TODO(jiyong): support more filesystem types other than ext4
- addStr("fs_type", "ext4")
+ // Type string that build_image.py accepts.
+ fsTypeStr := func(t fsType) string {
+ switch t {
+ // TODO(jiyong): add more types like f2fs, erofs, etc.
+ case ext4Type:
+ return "ext4"
+ }
+ panic(fmt.Errorf("unsupported fs type %v", t))
+ }
+
+ addStr("fs_type", fsTypeStr(f.fsType(ctx)))
addStr("mount_point", "system")
addStr("use_dynamic_partition_size", "true")
addPath("ext_mkuserimg", ctx.Config().HostToolPath(ctx, "mkuserimg_mke2fs"))
@@ -154,6 +201,39 @@
return propFile, deps
}
+func (f *filesystem) buildCompressedCpioImage(ctx android.ModuleContext) android.OutputPath {
+ if proptools.Bool(f.properties.Use_avb) {
+ ctx.PropertyErrorf("use_avb", "signing compresed cpio image using avbtool is not supported."+
+ "Consider adding this to bootimg module and signing the entire boot image.")
+ }
+
+ zipFile := android.PathForModuleOut(ctx, "temp.zip").OutputPath
+ f.CopyDepsToZip(ctx, zipFile)
+
+ rootDir := android.PathForModuleOut(ctx, "root").OutputPath
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().
+ BuiltTool("zipsync").
+ FlagWithArg("-d ", rootDir.String()). // zipsync wipes this. No need to clear.
+ Input(zipFile)
+
+ output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ builder.Command().
+ BuiltTool("mkbootfs").
+ Text(rootDir.String()). // input directory
+ Text("|").
+ BuiltTool("lz4").
+ Flag("--favor-decSpeed"). // for faster boot
+ Flag("-12"). // maximum compression level
+ Flag("-l"). // legacy format for kernel
+ Text(">").Output(output)
+
+ // rootDir is not deleted. Might be useful for quick inspection.
+ builder.Build("build_compressed_cpio_image", fmt.Sprintf("Creating filesystem %s", f.BaseModuleName()))
+
+ return output
+}
+
var _ android.AndroidMkEntriesProvider = (*filesystem)(nil)
// Implements android.AndroidMkEntriesProvider
diff --git a/java/dex.go b/java/dex.go
index 055d479..24600c2 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -263,10 +263,10 @@
}
func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion sdkSpec,
- classesJar android.Path, jarName string) android.ModuleOutPath {
+ classesJar android.Path, jarName string) android.OutputPath {
// Compile classes.jar into classes.dex and then javalib.jar
- javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
+ javalibJar := android.PathForModuleOut(ctx, "dex", jarName).OutputPath
outDir := android.PathForModuleOut(ctx, "dex")
zipFlags := "--ignore_missing_files"
@@ -329,7 +329,7 @@
})
}
if proptools.Bool(d.dexProperties.Uncompress_dex) {
- alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName)
+ alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
javalibJar = alignedJavalibJar
}
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index ac00592..da62100 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -118,7 +118,7 @@
return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx))
}
-func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) {
+func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) {
// TODO(b/148690468): The check on d.installPath is to bail out in cases where
// the dexpreopter struct hasn't been fully initialized before we're called,
// e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 2cd025e..eafbf5d 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -89,8 +89,8 @@
var _ hiddenAPIIntf = (*hiddenAPI)(nil)
-func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bool, dexJar android.ModuleOutPath,
- implementationJar android.Path, uncompressDex bool) android.ModuleOutPath {
+func (h *hiddenAPI) hiddenAPI(ctx android.ModuleContext, name string, primary bool, dexJar android.OutputPath,
+ implementationJar android.Path, uncompressDex bool) android.OutputPath {
if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
// Modules whose names are of the format <x>-hiddenapi provide hiddenapi information
@@ -116,7 +116,7 @@
// hiddenapi information for a module on the boot jars list then encode
// the gathered information in the generated dex file.
if name == bootJarName {
- hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", name+".jar")
+ hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", name+".jar").OutputPath
// More than one library with the same classes can be encoded but only one can
// be added to the global set of flags, otherwise it will result in duplicate
diff --git a/java/java.go b/java/java.go
index 59ec94d..d49b64f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1689,35 +1689,44 @@
// Combine the classes built from sources, any manifests, and any static libraries into
// classes.jar. If there is only one input jar this step will be skipped.
- var outputFile android.ModuleOutPath
+ var outputFile android.OutputPath
if len(jars) == 1 && !manifest.Valid() {
+ // Optimization: skip the combine step as there is nothing to do
+ // TODO(ccross): this leaves any module-info.class files, but those should only come from
+ // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
+ // any if len(jars) == 1.
+
+ // Transform the single path to the jar into an OutputPath as that is required by the following
+ // code.
if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
- // Optimization: skip the combine step if there is nothing to do
- // TODO(ccross): this leaves any module-info.class files, but those should only come from
- // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
- // any if len(jars) == 1.
- outputFile = moduleOutPath
+ // The path contains an embedded OutputPath so reuse that.
+ outputFile = moduleOutPath.OutputPath
+ } else if outputPath, ok := jars[0].(android.OutputPath); ok {
+ // The path is an OutputPath so reuse it directly.
+ outputFile = outputPath
} else {
+ // The file is not in the out directory so create an OutputPath into which it can be copied
+ // and which the following code can use to refer to it.
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: jars[0],
Output: combinedJar,
})
- outputFile = combinedJar
+ outputFile = combinedJar.OutputPath
}
} else {
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
false, nil, nil)
- outputFile = combinedJar
+ outputFile = combinedJar.OutputPath
}
// jarjar implementation jar if necessary
if j.expandJarjarRules != nil {
// Transform classes.jar into classes-jarjar.jar
- jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
+ jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
outputFile = jarjarFile
@@ -1762,7 +1771,7 @@
implementationAndResourcesJar := outputFile
if j.resourceJar != nil {
jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
- combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
+ combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
false, nil, nil)
implementationAndResourcesJar = combinedJar
@@ -1788,7 +1797,7 @@
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
}
// Dex compilation
- var dexOutputFile android.ModuleOutPath
+ var dexOutputFile android.OutputPath
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
if ctx.Failed() {
return
@@ -1807,11 +1816,11 @@
// merge dex jar with resources if necessary
if j.resourceJar != nil {
jars := android.Paths{dexOutputFile, j.resourceJar}
- combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
+ combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
false, nil, nil)
if *j.dexProperties.Uncompress_dex {
- combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
+ combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
dexOutputFile = combinedAlignedJar
} else {
@@ -1875,7 +1884,7 @@
jarName += strconv.Itoa(idx)
}
- classes := android.PathForModuleOut(ctx, "javac", jarName)
+ classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
if ctx.Config().EmitXrefRules() {
@@ -1955,12 +1964,12 @@
}
func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
- classesJar android.Path, jarName string) android.ModuleOutPath {
+ classesJar android.Path, jarName string) android.OutputPath {
specs := j.jacocoModuleToZipCommand(ctx)
jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
- instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
+ instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
@@ -2937,7 +2946,7 @@
}
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
- var dexOutputFile android.ModuleOutPath
+ var dexOutputFile android.OutputPath
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
if ctx.Failed() {
return
diff --git a/kernel/Android.bp b/kernel/Android.bp
new file mode 100644
index 0000000..f8a48d9
--- /dev/null
+++ b/kernel/Android.bp
@@ -0,0 +1,18 @@
+bootstrap_go_package {
+ name: "soong-kernel",
+ pkgPath: "android/soong/kernel",
+ deps: [
+ "blueprint",
+ "soong",
+ "soong-android",
+ "soong-cc",
+ "soong-cc-config",
+ ],
+ srcs: [
+ "prebuilt_kernel_modules.go",
+ ],
+ testSrcs: [
+ "prebuilt_kernel_modules_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
diff --git a/kernel/prebuilt_kernel_modules.go b/kernel/prebuilt_kernel_modules.go
new file mode 100644
index 0000000..94e04cb
--- /dev/null
+++ b/kernel/prebuilt_kernel_modules.go
@@ -0,0 +1,166 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// 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 kernel
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "android/soong/android"
+ _ "android/soong/cc/config"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+)
+
+func init() {
+ android.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
+ pctx.Import("android/soong/cc/config")
+}
+
+type prebuiltKernelModules struct {
+ android.ModuleBase
+
+ properties prebuiltKernelModulesProperties
+
+ installDir android.InstallPath
+}
+
+type prebuiltKernelModulesProperties struct {
+ // List or filegroup of prebuilt kernel module files. Should have .ko suffix.
+ Srcs []string `android:"path,arch_variant"`
+
+ // Kernel version that these modules are for. Kernel modules are installed to
+ // /lib/modules/<kernel_version> directory in the corresponding partition. Default is "".
+ Kernel_version *string
+}
+
+// prebuilt_kernel_modules installs a set of prebuilt kernel module files to the correct directory.
+// In addition, this module builds modules.load, modules.dep, modules.softdep and modules.alias
+// using depmod and installs them as well.
+func prebuiltKernelModulesFactory() android.Module {
+ module := &prebuiltKernelModules{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+ return module
+}
+
+func (pkm *prebuiltKernelModules) KernelVersion() string {
+ return proptools.StringDefault(pkm.properties.Kernel_version, "")
+}
+
+func (pkm *prebuiltKernelModules) DepsMutator(ctx android.BottomUpMutatorContext) {
+ // do nothing
+}
+
+func (pkm *prebuiltKernelModules) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ modules := android.PathsForModuleSrc(ctx, pkm.properties.Srcs)
+
+ depmodOut := runDepmod(ctx, modules)
+ strippedModules := stripDebugSymbols(ctx, modules)
+
+ installDir := android.PathForModuleInstall(ctx, "lib", "module")
+ if pkm.KernelVersion() != "" {
+ installDir = installDir.Join(ctx, pkm.KernelVersion())
+ }
+
+ for _, m := range strippedModules {
+ ctx.InstallFile(installDir, filepath.Base(m.String()), m)
+ }
+ ctx.InstallFile(installDir, "modules.load", depmodOut.modulesLoad)
+ ctx.InstallFile(installDir, "modules.dep", depmodOut.modulesDep)
+ ctx.InstallFile(installDir, "modules.softdep", depmodOut.modulesSoftdep)
+ ctx.InstallFile(installDir, "modules.alias", depmodOut.modulesAlias)
+}
+
+var (
+ pctx = android.NewPackageContext("android/soong/kernel")
+
+ stripRule = pctx.AndroidStaticRule("strip",
+ blueprint.RuleParams{
+ Command: "$stripCmd -o $out --strip-debug $in",
+ CommandDeps: []string{"$stripCmd"},
+ }, "stripCmd")
+)
+
+func stripDebugSymbols(ctx android.ModuleContext, modules android.Paths) android.OutputPaths {
+ dir := android.PathForModuleOut(ctx, "stripped").OutputPath
+ var outputs android.OutputPaths
+
+ for _, m := range modules {
+ stripped := dir.Join(ctx, filepath.Base(m.String()))
+ ctx.Build(pctx, android.BuildParams{
+ Rule: stripRule,
+ Input: m,
+ Output: stripped,
+ Args: map[string]string{
+ "stripCmd": "${config.ClangBin}/llvm-strip",
+ },
+ })
+ outputs = append(outputs, stripped)
+ }
+
+ return outputs
+}
+
+type depmodOutputs struct {
+ modulesLoad android.OutputPath
+ modulesDep android.OutputPath
+ modulesSoftdep android.OutputPath
+ modulesAlias android.OutputPath
+}
+
+func runDepmod(ctx android.ModuleContext, modules android.Paths) depmodOutputs {
+ baseDir := android.PathForModuleOut(ctx, "depmod").OutputPath
+ fakeVer := "0.0" // depmod demands this anyway
+ modulesDir := baseDir.Join(ctx, "lib", "modules", fakeVer)
+
+ builder := android.NewRuleBuilder(pctx, ctx)
+
+ // Copy the module files to a temporary dir
+ builder.Command().Text("rm").Flag("-rf").Text(modulesDir.String())
+ builder.Command().Text("mkdir").Flag("-p").Text(modulesDir.String())
+ for _, m := range modules {
+ builder.Command().Text("cp").Input(m).Text(modulesDir.String())
+ }
+
+ // Enumerate modules to load
+ modulesLoad := modulesDir.Join(ctx, "modules.load")
+ var basenames []string
+ for _, m := range modules {
+ basenames = append(basenames, filepath.Base(m.String()))
+ }
+ builder.Command().
+ Text("echo").Flag("\"" + strings.Join(basenames, " ") + "\"").
+ Text("|").Text("tr").Flag("\" \"").Flag("\"\\n\"").
+ Text(">").Output(modulesLoad)
+
+ // Run depmod to build modules.dep/softdep/alias files
+ modulesDep := modulesDir.Join(ctx, "modules.dep")
+ modulesSoftdep := modulesDir.Join(ctx, "modules.softdep")
+ modulesAlias := modulesDir.Join(ctx, "modules.alias")
+ builder.Command().
+ BuiltTool("depmod").
+ FlagWithArg("-b ", baseDir.String()).
+ Text(fakeVer).
+ ImplicitOutput(modulesDep).
+ ImplicitOutput(modulesSoftdep).
+ ImplicitOutput(modulesAlias)
+
+ builder.Build("depmod", fmt.Sprintf("depmod %s", ctx.ModuleName()))
+
+ return depmodOutputs{modulesLoad, modulesDep, modulesSoftdep, modulesAlias}
+}
diff --git a/kernel/prebuilt_kernel_modules_test.go b/kernel/prebuilt_kernel_modules_test.go
new file mode 100644
index 0000000..b49e167
--- /dev/null
+++ b/kernel/prebuilt_kernel_modules_test.go
@@ -0,0 +1,129 @@
+// Copyright 2021 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 kernel
+
+import (
+ "io/ioutil"
+ "os"
+ "reflect"
+ "strings"
+ "testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+)
+
+func testKernelModules(t *testing.T, bp string, fs map[string][]byte) (*android.TestContext, android.Config) {
+ bp = bp + `
+ cc_binary_host {
+ name: "depmod",
+ srcs: ["depmod.cpp"],
+ stl: "none",
+ static_executable: true,
+ system_shared_libs: [],
+ }
+ `
+ bp = bp + cc.GatherRequiredDepsForTest(android.Android)
+
+ fs["depmod.cpp"] = nil
+ cc.GatherRequiredFilesForTest(fs)
+
+ config := android.TestArchConfig(buildDir, nil, bp, fs)
+
+ ctx := android.NewTestArchContext(config)
+ ctx.RegisterModuleType("prebuilt_kernel_modules", prebuiltKernelModulesFactory)
+ ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
+ cc.RegisterRequiredBuildComponentsForTest(ctx)
+
+ ctx.Register()
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ android.FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ android.FailIfErrored(t, errs)
+
+ return ctx, config
+}
+
+func ensureListContains(t *testing.T, result []string, expected string) {
+ t.Helper()
+ if !android.InList(expected, result) {
+ t.Errorf("%q is not found in %v", expected, result)
+ }
+}
+
+func ensureContains(t *testing.T, result string, expected string) {
+ t.Helper()
+ if !strings.Contains(result, expected) {
+ t.Errorf("%q is not found in %q", expected, result)
+ }
+}
+
+func TestKernelModulesFilelist(t *testing.T) {
+ ctx, _ := testKernelModules(t, `
+ prebuilt_kernel_modules {
+ name: "foo",
+ srcs: ["*.ko"],
+ kernel_version: "5.10",
+ }
+ `,
+ map[string][]byte{
+ "mod1.ko": nil,
+ "mod2.ko": nil,
+ })
+
+ expected := []string{
+ "lib/module/5.10/mod1.ko",
+ "lib/module/5.10/mod2.ko",
+ "lib/module/5.10/modules.load",
+ "lib/module/5.10/modules.dep",
+ "lib/module/5.10/modules.softdep",
+ "lib/module/5.10/modules.alias",
+ }
+
+ var actual []string
+ for _, ps := range ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().PackagingSpecs() {
+ actual = append(actual, ps.RelPathInPackage())
+ }
+ actual = android.SortedUniqueStrings(actual)
+ expected = android.SortedUniqueStrings(expected)
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("\ngot: %v\nexpected: %v\n", actual, expected)
+ }
+}
+
+var buildDir string
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_kernel_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}