Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51ce6b0a authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

Merge "apex: emit file_contexts for flattened apex"

parents 66fee25c 7f146c0d
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -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, " && "))
				}
				}
+0 −25
Original line number Original line Diff line number Diff line
@@ -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
+29 −17
Original line number Original line Diff line number Diff line
@@ -257,6 +257,8 @@ 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()

	if a.properties.ApexType == imageApex {
		// remove old file
		// remove old file
		rule.Command().Text("rm").FlagWithOutput("-f ", output)
		rule.Command().Text("rm").FlagWithOutput("-f ", output)
		// copy file_contexts
		// copy file_contexts
@@ -266,6 +268,23 @@ func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) {
		// force-label /apex_manifest.pb and / as system_file so that apexd can read them
		// 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("/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)
		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)
}
}