Merge "apex: emit file_contexts for flattened apex" am: 51ce6b0acc
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1435292 Change-Id: I23fe348b58f5e60fd854c79c594b09a8fa66c6da
This commit is contained in:
@@ -264,6 +264,10 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
|
|||||||
postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
|
postInstallCommands = append(postInstallCommands, a.compatSymlinks...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File_contexts of flattened APEXes should be merged into file_contexts.bin
|
||||||
|
fmt.Fprintln(w, "LOCAL_FILE_CONTEXTS :=", a.fileContexts)
|
||||||
|
|
||||||
if len(postInstallCommands) > 0 {
|
if len(postInstallCommands) > 0 {
|
||||||
fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
|
fmt.Fprintln(w, "LOCAL_POST_INSTALL_CMD :=", strings.Join(postInstallCommands, " && "))
|
||||||
}
|
}
|
||||||
|
25
apex/apex.go
25
apex/apex.go
@@ -19,7 +19,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/bootstrap"
|
"github.com/google/blueprint/bootstrap"
|
||||||
@@ -743,12 +742,6 @@ func init() {
|
|||||||
android.PreDepsMutators(RegisterPreDepsMutators)
|
android.PreDepsMutators(RegisterPreDepsMutators)
|
||||||
android.PostDepsMutators(RegisterPostDepsMutators)
|
android.PostDepsMutators(RegisterPostDepsMutators)
|
||||||
|
|
||||||
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
|
|
||||||
apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
|
|
||||||
sort.Strings(*apexFileContextsInfos)
|
|
||||||
ctx.Strict("APEX_FILE_CONTEXTS_INFOS", strings.Join(*apexFileContextsInfos, " "))
|
|
||||||
})
|
|
||||||
|
|
||||||
android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
|
android.AddNeverAllowRules(createApexPermittedPackagesRules(qModulesPackages())...)
|
||||||
android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
|
android.AddNeverAllowRules(createApexPermittedPackagesRules(rModulesPackages())...)
|
||||||
}
|
}
|
||||||
@@ -916,24 +909,6 @@ func apexMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
apexFileContextsInfosKey = android.NewOnceKey("apexFileContextsInfosKey")
|
|
||||||
apexFileContextsInfosMutex sync.Mutex
|
|
||||||
)
|
|
||||||
|
|
||||||
func apexFileContextsInfos(config android.Config) *[]string {
|
|
||||||
return config.Once(apexFileContextsInfosKey, func() interface{} {
|
|
||||||
return &[]string{}
|
|
||||||
}).(*[]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) {
|
|
||||||
apexFileContextsInfosMutex.Lock()
|
|
||||||
defer apexFileContextsInfosMutex.Unlock()
|
|
||||||
apexFileContextsInfos := apexFileContextsInfos(ctx.Config())
|
|
||||||
*apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
|
func apexFlattenedMutator(mctx android.BottomUpMutatorContext) {
|
||||||
if !mctx.Module().Enabled() {
|
if !mctx.Module().Enabled() {
|
||||||
return
|
return
|
||||||
|
@@ -257,15 +257,34 @@ func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) {
|
|||||||
|
|
||||||
output := android.PathForModuleOut(ctx, "file_contexts")
|
output := android.PathForModuleOut(ctx, "file_contexts")
|
||||||
rule := android.NewRuleBuilder()
|
rule := android.NewRuleBuilder()
|
||||||
// remove old file
|
|
||||||
rule.Command().Text("rm").FlagWithOutput("-f ", output)
|
if a.properties.ApexType == imageApex {
|
||||||
// copy file_contexts
|
// remove old file
|
||||||
rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
|
rule.Command().Text("rm").FlagWithOutput("-f ", output)
|
||||||
// new line
|
// copy file_contexts
|
||||||
rule.Command().Text("echo").Text(">>").Output(output)
|
rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output)
|
||||||
// force-label /apex_manifest.pb and / as system_file so that apexd can read them
|
// new line
|
||||||
rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
|
rule.Command().Text("echo").Text(">>").Output(output)
|
||||||
rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output)
|
// force-label /apex_manifest.pb and / as system_file so that apexd can read them
|
||||||
|
rule.Command().Text("echo").Flag("/apex_manifest\\\\.pb u:object_r:system_file:s0").Text(">>").Output(output)
|
||||||
|
rule.Command().Text("echo").Flag("/ u:object_r:system_file:s0").Text(">>").Output(output)
|
||||||
|
} else {
|
||||||
|
// For flattened apexes, install path should be prepended.
|
||||||
|
// File_contexts file should be emiited to make via LOCAL_FILE_CONTEXTS
|
||||||
|
// so that it can be merged into file_contexts.bin
|
||||||
|
apexPath := android.InstallPathToOnDevicePath(ctx, a.installDir.Join(ctx, a.Name()))
|
||||||
|
apexPath = strings.ReplaceAll(apexPath, ".", `\\.`)
|
||||||
|
// remove old file
|
||||||
|
rule.Command().Text("rm").FlagWithOutput("-f ", output)
|
||||||
|
// copy file_contexts
|
||||||
|
rule.Command().Text("awk").Text(`'/object_r/{printf("` + apexPath + `%s\n", $0)}'`).Input(fileContexts).Text(">").Output(output)
|
||||||
|
// new line
|
||||||
|
rule.Command().Text("echo").Text(">>").Output(output)
|
||||||
|
// force-label /apex_manifest.pb and / as system_file so that apexd can read them
|
||||||
|
rule.Command().Text("echo").Flag(apexPath + `/apex_manifest\\.pb u:object_r:system_file:s0`).Text(">>").Output(output)
|
||||||
|
rule.Command().Text("echo").Flag(apexPath + "/ u:object_r:system_file:s0").Text(">>").Output(output)
|
||||||
|
}
|
||||||
|
|
||||||
rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts")
|
rule.Build(pctx, ctx, "file_contexts."+a.Name(), "Generate file_contexts")
|
||||||
|
|
||||||
a.fileContexts = output.OutputPath
|
a.fileContexts = output.OutputPath
|
||||||
@@ -689,14 +708,7 @@ func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) {
|
|||||||
// instead of `android.PathForOutput`) to return the correct path to the flattened
|
// instead of `android.PathForOutput`) to return the correct path to the flattened
|
||||||
// APEX (as its contents is installed by Make, not Soong).
|
// APEX (as its contents is installed by Make, not Soong).
|
||||||
factx := flattenedApexContext{ctx}
|
factx := flattenedApexContext{ctx}
|
||||||
apexBundleName := a.Name()
|
a.outputFile = android.PathForModuleInstall(&factx, "apex", a.Name())
|
||||||
a.outputFile = android.PathForModuleInstall(&factx, "apex", apexBundleName)
|
|
||||||
|
|
||||||
if a.installable() {
|
|
||||||
installPath := android.PathForModuleInstall(ctx, "apex", apexBundleName)
|
|
||||||
devicePath := android.InstallPathToOnDevicePath(ctx, installPath)
|
|
||||||
addFlattenedFileContextsInfos(ctx, apexBundleName+":"+devicePath+":"+a.fileContexts.String())
|
|
||||||
}
|
|
||||||
a.buildFilesInfo(ctx)
|
a.buildFilesInfo(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user