android_filesystem modules can be included in APEX

android_filesystem modules can be included in APEX via the new
`filesystems` property. The filesystem images are placed at
./etc/fs/<modulename>.img.

Bug: 172413888
Test: m nothing

Change-Id: I215ca7a32ff1988a0de4e1f71397684e189839ea
This commit is contained in:
Jiyong Park 2021-01-07 15:31:24 +09:00
parent 22313cb192
commit 12a719c0fc
3 changed files with 36 additions and 2 deletions

View file

@ -7,6 +7,7 @@ bootstrap_go_package {
"soong-android",
"soong-bpf",
"soong-cc",
"soong-filesystem",
"soong-java",
"soong-python",
"soong-rust",

View file

@ -30,6 +30,7 @@ import (
"android/soong/bpf"
"android/soong/cc"
prebuilt_etc "android/soong/etc"
"android/soong/filesystem"
"android/soong/java"
"android/soong/python"
"android/soong/rust"
@ -96,6 +97,9 @@ type apexBundleProperties struct {
// List of BPF programs inside this APEX bundle.
Bpfs []string
// List of filesystem images that are embedded inside this APEX bundle.
Filesystems []string
// Name of the apex_key module that provides the private key to sign this APEX bundle.
Key *string
@ -530,6 +534,7 @@ var (
bpfTag = dependencyTag{name: "bpf", payload: true}
certificateTag = dependencyTag{name: "certificate"}
executableTag = dependencyTag{name: "executable", payload: true}
fsTag = dependencyTag{name: "filesystem", payload: true}
javaLibTag = dependencyTag{name: "javaLib", payload: true}
jniLibTag = dependencyTag{name: "jniLib", payload: true}
keyTag = dependencyTag{name: "key"}
@ -709,6 +714,7 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
commonVariation := ctx.Config().AndroidCommonTarget.Variations()
ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...)
ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)
// With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@ -1481,6 +1487,11 @@ func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path
return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
}
func apexFileForFilesystem(ctx android.BaseModuleContext, buildFile android.Path, fs filesystem.Filesystem) apexFile {
dirInApex := filepath.Join("etc", "fs")
return newApexFile(ctx, buildFile, buildFile.Base(), dirInApex, etc, fs)
}
// WalyPayloadDeps visits dependencies that contributes to the payload of this APEX. For each of the
// visited module, the `do` callback is executed. Returning true in the callback continues the visit
// to the child modules. Returning false makes the visit to continue in the sibling or the parent
@ -1655,6 +1666,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else {
ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
}
case fsTag:
if fs, ok := child.(filesystem.Filesystem); ok {
filesInfo = append(filesInfo, apexFileForFilesystem(ctx, fs.OutputPath(), fs))
} else {
ctx.PropertyErrorf("filesystems", "%q is not a filesystem module", depName)
}
case prebuiltTag:
if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))

View file

@ -46,7 +46,10 @@ func filesystemFactory() android.Module {
return module
}
var dependencyTag = struct{ blueprint.BaseDependencyTag }{}
var dependencyTag = struct {
blueprint.BaseDependencyTag
android.InstallAlwaysNeededDependencyTag
}{}
func (f *filesystem) DepsMutator(ctx android.BottomUpMutatorContext) {
f.AddDeps(ctx, dependencyTag)
@ -80,7 +83,7 @@ func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Text(">").Output(propFile).
Implicit(mkuserimg)
f.output = android.PathForModuleOut(ctx, "filesystem.img").OutputPath
f.output = android.PathForModuleOut(ctx, f.installFileName()).OutputPath
builder.Command().BuiltTool("build_image").
Text(rootDir.String()). // input directory
Input(propFile).
@ -109,3 +112,16 @@ func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries {
},
}}
}
// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
// package to have access to the output file.
type Filesystem interface {
android.Module
OutputPath() android.Path
}
var _ Filesystem = (*filesystem)(nil)
func (f *filesystem) OutputPath() android.Path {
return f.output
}