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

Commit fa946f7d authored by Jiakai Zhang's avatar Jiakai Zhang Committed by Automerger Merge Worker
Browse files

Dexpreopt ART jars and framework jars together. am: 5f5a17fd am: 04e70bc8

parents 30c6f178 04e70bc8
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -8349,8 +8349,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
		testNoUpdatableJarsInBootImage(t, "", preparer, fragments...)
	})

	t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) {
		err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image`
	t.Run("updatable jar from ART apex in the platform bootclasspath => error", func(t *testing.T) {
		err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the platform bootclasspath`
		// Update the dexpreopt BootJars directly.
		preparer := android.GroupFixturePreparers(
			prepareSetBootJars("com.android.art.debug:some-art-lib"),
@@ -8373,8 +8373,8 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
		testNoUpdatableJarsInBootImage(t, err, preparer)
	})

	t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) {
		err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image`
	t.Run("updatable jar from some other apex in the platform bootclasspath => error", func(t *testing.T) {
		err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the platform bootclasspath`
		preparer := android.GroupFixturePreparers(
			java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"),
			java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"),
@@ -8382,7 +8382,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
		testNoUpdatableJarsInBootImage(t, err, preparer)
	})

	t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) {
	t.Run("non-updatable jar from some other apex in the platform bootclasspath => ok", func(t *testing.T) {
		preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib")
		fragment := java.ApexVariantReference{
			Apex:   proptools.StringPtr("some-non-updatable-apex"),
@@ -8397,7 +8397,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
		testNoUpdatableJarsInBootImage(t, err, preparer)
	})

	t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) {
	t.Run("nonexistent jar in the platform bootclasspath => error", func(t *testing.T) {
		err := `"platform-bootclasspath" depends on undefined module "nonexistent"`
		preparer := java.FixtureConfigureBootJars("platform:nonexistent")
		testNoUpdatableJarsInBootImage(t, err, preparer)
@@ -8410,7 +8410,7 @@ func TestNoUpdatableJarsInBootImage(t *testing.T) {
		testNoUpdatableJarsInBootImage(t, err, preparer)
	})

	t.Run("platform jar in the framework boot image => ok", func(t *testing.T) {
	t.Run("platform jar in the platform bootclasspath => ok", func(t *testing.T) {
		preparer := android.GroupFixturePreparers(
			java.FixtureConfigureBootJars("platform:some-platform-lib"),
			java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"),
+158 −35
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package apex

import (
	"fmt"
	"path/filepath"
	"sort"
	"testing"
@@ -23,8 +24,10 @@ import (
	"android/soong/java"
)

func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string) {
func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOutputs []string, preferPrebuilt bool) {
	bp := `
		// Platform.

		java_sdk_library {
			name: "foo",
			srcs: ["a.java"],
@@ -45,6 +48,84 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu

		platform_bootclasspath {
			name: "platform-bootclasspath",
			fragments: [
				{
					apex: "com.android.art",
					module: "art-bootclasspath-fragment",
				},
			],
		}

		// Source ART APEX.

		java_library {
			name: "core-oj",
			srcs: ["core-oj.java"],
			installable: true,
			apex_available: [
				"com.android.art",
			],
		}

		bootclasspath_fragment {
			name: "art-bootclasspath-fragment",
			image_name: "art",
			contents: ["core-oj"],
			apex_available: [
				"com.android.art",
			],
			hidden_api: {
				split_packages: ["*"],
			},
		}

		apex_key {
			name: "com.android.art.key",
			public_key: "com.android.art.avbpubkey",
			private_key: "com.android.art.pem",
		}

		apex {
			name: "com.android.art",
			key: "com.android.art.key",
			bootclasspath_fragments: ["art-bootclasspath-fragment"],
			updatable: false,
		}

		// Prebuilt ART APEX.

		java_import {
			name: "core-oj",
			prefer: %[1]t,
			jars: ["core-oj.jar"],
			apex_available: [
				"com.android.art",
			],
		}

		prebuilt_bootclasspath_fragment {
			name: "art-bootclasspath-fragment",
			prefer: %[1]t,
			image_name: "art",
			contents: ["core-oj"],
			hidden_api: {
				annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv",
				metadata: "my-bootclasspath-fragment/metadata.csv",
				index: "my-bootclasspath-fragment/index.csv",
				stub_flags: "my-bootclasspath-fragment/stub-flags.csv",
				all_flags: "my-bootclasspath-fragment/all-flags.csv",
			},
			apex_available: [
				"com.android.art",
			],
		}

		prebuilt_apex {
			name: "com.android.art",
			prefer: %[1]t,
			apex_name: "com.android.art",
			src: "com.android.art-arm.apex",
			exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
		}
	`

@@ -52,20 +133,14 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu
		java.PrepareForTestWithDexpreopt,
		java.PrepareForTestWithJavaSdkLibraryFiles,
		java.FixtureWithLastReleaseApis("foo"),
		java.FixtureConfigureBootJars("platform:foo", "system_ext:bar", "platform:baz"),
	).RunTestWithBp(t, bp)
		java.FixtureConfigureBootJars("com.android.art:core-oj", "platform:foo", "system_ext:bar", "platform:baz"),
		PrepareForTestWithApexBuildComponents,
		prepareForTestWithArtApex,
	).RunTestWithBp(t, fmt.Sprintf(bp, preferPrebuilt))

	platformBootclasspath := result.ModuleForTests("platform-bootclasspath", "android_common")
	rule := platformBootclasspath.Output(ruleFile)

	for i := range expectedInputs {
		expectedInputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedInputs[i])
	}

	for i := range expectedOutputs {
		expectedOutputs[i] = filepath.Join("out/soong/dexpreopt_arm64", expectedOutputs[i])
	}

	inputs := rule.Implicits.Strings()
	sort.Strings(inputs)
	sort.Strings(expectedInputs)
@@ -79,33 +154,76 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu
	android.AssertStringPathsRelativeToTopEquals(t, "outputs", result.Config, expectedOutputs, outputs)
}

func TestDexpreoptBootJars(t *testing.T) {
	ruleFile := "boot-foo.art"
func TestDexpreoptBootJarsWithSourceArtApex(t *testing.T) {
	ruleFile := "boot.art"

	expectedInputs := []string{
		"out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar",
		"out/soong/dexpreopt_arm64/dex_artjars/boot.prof",
		"out/soong/dexpreopt_arm64/dex_bootjars/boot.prof",
	}

	expectedOutputs := []string{
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
	}

	testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false)
}

// The only difference is that the ART profile should be deapexed from the prebuilt APEX. Other
// inputs and outputs should be the same as above.
func TestDexpreoptBootJarsWithPrebuiltArtApex(t *testing.T) {
	ruleFile := "boot.art"

	expectedInputs := []string{
		"dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art",
		"dex_bootjars_input/foo.jar",
		"dex_bootjars_input/bar.jar",
		"dex_bootjars_input/baz.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/core-oj.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/foo.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/bar.jar",
		"out/soong/dexpreopt_arm64/dex_bootjars_input/baz.jar",
		"out/soong/.intermediates/com.android.art.deapexer/android_common/deapexer/etc/boot-image.prof",
		"out/soong/dexpreopt_arm64/dex_bootjars/boot.prof",
	}

	expectedOutputs := []string{
		"dex_bootjars/android/system/framework/arm64/boot.invocation",
		"dex_bootjars/android/system/framework/arm64/boot-foo.art",
		"dex_bootjars/android/system/framework/arm64/boot-bar.art",
		"dex_bootjars/android/system/framework/arm64/boot-baz.art",
		"dex_bootjars/android/system/framework/arm64/boot-foo.oat",
		"dex_bootjars/android/system/framework/arm64/boot-bar.oat",
		"dex_bootjars/android/system/framework/arm64/boot-baz.oat",
		"dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
		"dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
		"dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
		"dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
		"dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
		"dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.invocation",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.art",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
		"out/soong/dexpreopt_arm64/dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
	}

	testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
	testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, true)
}

// Changes to the boot.zip structure may break the ART APK scanner.
@@ -116,16 +234,21 @@ func TestDexpreoptBootZip(t *testing.T) {
	expectedInputs := []string{}
	for _, target := range ctx.Config().Targets[android.Android] {
		for _, ext := range []string{".art", ".oat", ".vdex"} {
			for _, jar := range []string{"foo", "bar", "baz"} {
			for _, suffix := range []string{"", "-foo", "-bar", "-baz"} {
				expectedInputs = append(expectedInputs,
					filepath.Join("dex_bootjars", target.Os.String(), "system/framework", target.Arch.ArchType.String(), "boot-"+jar+ext))
					filepath.Join(
						"out/soong/dexpreopt_arm64/dex_bootjars",
						target.Os.String(),
						"system/framework",
						target.Arch.ArchType.String(),
						"boot"+suffix+ext))
			}
		}
	}

	expectedOutputs := []string{
		"dex_bootjars/boot.zip",
		"out/soong/dexpreopt_arm64/dex_bootjars/boot.zip",
	}

	testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs)
	testDexpreoptBoot(t, ruleFile, expectedInputs, expectedOutputs, false)
}
+26 −0
Original line number Diff line number Diff line
@@ -240,6 +240,9 @@ type BootclasspathFragmentModule struct {

	// Collect the module directory for IDE info in java/jdeps.go.
	modulePaths []string

	// Path to the boot image profile.
	profilePath android.Path
}

// commonBootclasspathFragment defines the methods that are implemented by both source and prebuilt
@@ -259,6 +262,12 @@ type commonBootclasspathFragment interface {
	// If it could not create the files then it will return nil. Otherwise, it will return a map from
	// android.ArchType to the predefined paths of the boot image files.
	produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageOutputs

	// getImageName returns the `image_name` property of this fragment.
	getImageName() *string

	// getProfilePath returns the path to the boot image profile.
	getProfilePath() android.Path
}

var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
@@ -528,6 +537,7 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
		// Delegate the production of the boot image files to a module type specific method.
		common := ctx.Module().(commonBootclasspathFragment)
		bootImageFiles = common.produceBootImageFiles(ctx, imageConfig)
		b.profilePath = bootImageFiles.profile

		if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) {
			// Zip the boot image files up, if available. This will generate the zip file in a
@@ -911,6 +921,14 @@ func (b *BootclasspathFragmentModule) AndroidMkEntries() []android.AndroidMkEntr
	return entriesList
}

func (b *BootclasspathFragmentModule) getImageName() *string {
	return b.properties.Image_name
}

func (b *BootclasspathFragmentModule) getProfilePath() android.Path {
	return b.profilePath
}

// Collect information for opening IDE project files in java/jdeps.go.
func (b *BootclasspathFragmentModule) IDEInfo(dpInfo *android.IdeInfo) {
	dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...)
@@ -1207,6 +1225,14 @@ func (module *PrebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
	return buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile)
}

func (b *PrebuiltBootclasspathFragmentModule) getImageName() *string {
	return b.properties.Image_name
}

func (b *PrebuiltBootclasspathFragmentModule) getProfilePath() android.Path {
	return b.profilePath
}

var _ commonBootclasspathFragment = (*PrebuiltBootclasspathFragmentModule)(nil)

// RequiredFilesFromPrebuiltApex returns the list of all files the prebuilt_bootclasspath_fragment
+33 −0
Original line number Diff line number Diff line
@@ -295,6 +295,11 @@ type bootImageConfig struct {

	// The "--single-image" argument.
	singleImage bool

	// Profiles imported from other boot image configs. Each element must represent a
	// `bootclasspath_fragment` of an APEX (i.e., the `name` field of each element must refer to the
	// `image_name` property of a `bootclasspath_fragment`).
	profileImports []*bootImageConfig
}

// Target-dependent description of a boot image.
@@ -711,6 +716,34 @@ func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, p
		cmd.FlagWithInput("--profile-file=", profile)
	}

	fragments := make(map[string]commonBootclasspathFragment)
	ctx.VisitDirectDepsWithTag(bootclasspathFragmentDepTag, func(child android.Module) {
		fragment := child.(commonBootclasspathFragment)
		if fragment.getImageName() != nil && android.IsModulePreferred(child) {
			fragments[*fragment.getImageName()] = fragment
		}
	})

	for _, profileImport := range image.profileImports {
		fragment := fragments[profileImport.name]
		if fragment == nil {
			ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but a "+
				"bootclasspath_fragment with image name '%[2]s' doesn't exist or is not added as a "+
				"dependency of '%[1]s'",
				image.name,
				profileImport.name)
			return bootImageVariantOutputs{}
		}
		if fragment.getProfilePath() == nil {
			ctx.ModuleErrorf("Boot image config '%[1]s' imports profile from '%[2]s', but '%[2]s' "+
				"doesn't provide a profile",
				image.name,
				profileImport.name)
			return bootImageVariantOutputs{}
		}
		cmd.FlagWithInput("--profile-file=", fragment.getProfilePath())
	}

	dirtyImageFile := "frameworks/base/config/dirty-image-objects"
	dirtyImagePath := android.ExistentPathForSource(ctx, dirtyImageFile)
	if dirtyImagePath.Valid() {
+2 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig
		global := dexpreopt.GetGlobalConfig(ctx)

		artModules := global.ArtApexJars
		frameworkModules := global.BootJars.RemoveList(artModules)
		frameworkModules := global.BootJars // This includes `artModules`.
		mainlineBcpModules := global.ApexBootJars
		frameworkSubdir := "system/framework"

@@ -73,7 +73,6 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig
		// Framework config for the boot image extension.
		// It includes framework libraries and depends on the ART config.
		frameworkCfg := bootImageConfig{
			extends:              &artCfg,
			name:                 frameworkBootImageName,
			stem:                 bootImageStem,
			installDir:           frameworkSubdir,
@@ -81,6 +80,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig
			preloadedClassesFile: "frameworks/base/config/preloaded-classes",
			compilerFilter:       "speed-profile",
			singleImage:          false,
			profileImports:       []*bootImageConfig{&artCfg},
		}

		mainlineCfg := bootImageConfig{
Loading