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

Commit d93e1b1e authored by Jiyong Park's avatar Jiyong Park
Browse files

bundle config for apexes are auto-generated

bundle config file for apexes are auto-generated. It is included in the
<apex>-base.zip file, which is expected to be extracted and then fed
into the bundletool.

This change is in preparation for the upcoming change to include
information about embedded apks in the bundle confir file.

Exempt-From-Owner-Approval: cherry-pick from master

Bug: 148002117
Test: m

Merged-In: If25d75e0f62036dc777faf8593ed8eb9a74950b0
(cherry picked from commit bd159610)
Change-Id: If25d75e0f62036dc777faf8593ed8eb9a74950b0
parent 30ec3c97
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -3609,6 +3609,35 @@ func TestSymlinksFromApexToSystem(t *testing.T) {
	ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file
}

func TestAppBundle(t *testing.T) {
	ctx, _ := testApex(t, `
		apex {
			name: "myapex",
			key: "myapex.key",
			apps: ["AppFoo"],
		}

		apex_key {
			name: "myapex.key",
			public_key: "testkey.avbpubkey",
			private_key: "testkey.pem",
		}

		android_app {
			name: "AppFoo",
			srcs: ["foo/bar/MyClass.java"],
			sdk_version: "none",
			system_modules: "none",
			apex_available: [ "myapex" ],
		}
	`)

	bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("Bundle Config")
	content := bundleConfigRule.Args["content"]

	ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`)
}

func TestMain(m *testing.M) {
	run := func() int {
		setUp()
+42 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package apex

import (
	"encoding/json"
	"fmt"
	"path/filepath"
	"runtime"
@@ -136,15 +137,17 @@ var (
		})

	apexBundleRule = pctx.StaticRule("apexBundleRule", blueprint.RuleParams{
		Command: `${zip2zip} -i $in -o $out ` +
		Command: `${zip2zip} -i $in -o $out.base ` +
			`apex_payload.img:apex/${abi}.img ` +
			`apex_manifest.json:root/apex_manifest.json ` +
			`apex_manifest.pb:root/apex_manifest.pb ` +
			`AndroidManifest.xml:manifest/AndroidManifest.xml ` +
			`assets/NOTICE.html.gz:assets/NOTICE.html.gz`,
		CommandDeps: []string{"${zip2zip}"},
			`assets/NOTICE.html.gz:assets/NOTICE.html.gz &&` +
			`${soong_zip} -o $out.config -C $$(dirname ${config}) -f ${config} && ` +
			`${merge_zips} $out $out.base $out.config`,
		CommandDeps: []string{"${zip2zip}", "${soong_zip}", "${merge_zips}"},
		Description: "app bundle",
	}, "abi")
	}, "abi", "config")

	emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
		Command:        `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
@@ -246,6 +249,36 @@ func (a *apexBundle) buildInstalledFilesFile(ctx android.ModuleContext, builtApe
	return output.OutputPath
}

func (a *apexBundle) buildBundleConfig(ctx android.ModuleContext) android.OutputPath {
	output := android.PathForModuleOut(ctx, "bundle_config.json")

	config := struct {
		Compression struct {
			Uncompressed_glob []string `json:"uncompressed_glob"`
		} `json:"compression"`
	}{}

	config.Compression.Uncompressed_glob = []string{
		"apex_payload.img",
		"apex_manifest.*",
	}
	j, err := json.Marshal(config)
	if err != nil {
		panic(fmt.Errorf("error while marshalling to %q: %#v", output, err))
	}

	ctx.Build(pctx, android.BuildParams{
		Rule:        android.WriteFile,
		Output:      output,
		Description: "Bundle Config " + output.String(),
		Args: map[string]string{
			"content": string(j),
		},
	})

	return output.OutputPath
}

func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
	var abis []string
	for _, target := range ctx.MultiTargets() {
@@ -465,13 +498,17 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
			Description: "apex proto convert",
		})

		bundleConfig := a.buildBundleConfig(ctx)

		ctx.Build(pctx, android.BuildParams{
			Rule:        apexBundleRule,
			Input:       apexProtoFile,
			Implicit:    bundleConfig,
			Output:      a.bundleModuleFile,
			Description: "apex bundle module",
			Args: map[string]string{
				"abi":    strings.Join(abis, "."),
				"config": bundleConfig.String(),
			},
		})
	} else {