Merge "Add entries for STANDALONE_SYSTEMSERVER_JARS to systemserverclasspath.pb"

This commit is contained in:
Jiakai Zhang
2021-12-01 12:29:37 +00:00
committed by Gerrit Code Review
6 changed files with 169 additions and 13 deletions

View File

@@ -231,3 +231,95 @@ func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
`prebuilt_foo`,
})
}
func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithSystemserverclasspathFragment,
prepareForTestWithMyapex,
dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo"),
).RunTestWithBp(t, `
apex {
name: "myapex",
key: "myapex.key",
systemserverclasspath_fragments: [
"mysystemserverclasspathfragment",
],
updatable: false,
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
java_library {
name: "foo",
srcs: ["b.java"],
installable: true,
apex_available: [
"myapex",
],
}
systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
standalone_contents: [
"foo",
],
apex_available: [
"myapex",
],
}
`)
ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
"etc/classpaths/systemserverclasspath.pb",
"javalib/foo.jar",
})
}
func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithSystemserverclasspathFragment,
prepareForTestWithMyapex,
dexpreopt.FixtureSetApexStandaloneSystemServerJars("myapex:foo"),
).RunTestWithBp(t, `
prebuilt_apex {
name: "myapex",
arch: {
arm64: {
src: "myapex-arm64.apex",
},
arm: {
src: "myapex-arm.apex",
},
},
exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
}
java_import {
name: "foo",
jars: ["foo.jar"],
apex_available: [
"myapex",
],
}
prebuilt_systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
prefer: true,
standalone_contents: [
"foo",
],
apex_available: [
"myapex",
],
}
`)
java.CheckModuleDependencies(t, result.TestContext, "mysystemserverclasspathfragment", "android_common_myapex", []string{
`myapex.deapexer`,
`prebuilt_foo`,
})
}

View File

@@ -49,10 +49,12 @@ type GlobalConfig struct {
ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX
SystemServerJars android.ConfiguredJarList // jars that form the system server
SystemServerApps []string // apps that are loaded into system server
ApexSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server
SpeedApps []string // apps that should be speed optimized
SystemServerJars android.ConfiguredJarList // system_server classpath jars on the platform
SystemServerApps []string // apps that are loaded into system server
ApexSystemServerJars android.ConfiguredJarList // system_server classpath jars delivered via apex
StandaloneSystemServerJars android.ConfiguredJarList // jars on the platform that system_server loads dynamically using separate classloaders
ApexStandaloneSystemServerJars android.ConfiguredJarList // jars delivered via apex that system_server loads dynamically using separate classloaders
SpeedApps []string // apps that should be speed optimized
BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error
@@ -619,6 +621,8 @@ func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig {
SystemServerJars: android.EmptyConfiguredJarList(),
SystemServerApps: nil,
ApexSystemServerJars: android.EmptyConfiguredJarList(),
StandaloneSystemServerJars: android.EmptyConfiguredJarList(),
ApexStandaloneSystemServerJars: android.EmptyConfiguredJarList(),
SpeedApps: nil,
PreoptFlags: nil,
DefaultCompilerFilter: "",

View File

@@ -125,6 +125,13 @@ func FixtureSetApexBootJars(bootJars ...string) android.FixturePreparer {
})
}
// FixtureSetStandaloneSystemServerJars sets the StandaloneSystemServerJars property.
func FixtureSetStandaloneSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars)
})
}
// FixtureSetSystemServerJars sets the SystemServerJars property.
func FixtureSetSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) {
@@ -139,6 +146,14 @@ func FixtureSetApexSystemServerJars(jars ...string) android.FixturePreparer {
})
}
// FixtureSetApexStandaloneSystemServerJars sets the ApexStandaloneSystemServerJars property in the
// global config.
func FixtureSetApexStandaloneSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars)
})
}
// FixtureSetPreoptWithUpdatableBcp sets the PreoptWithUpdatableBcp property in the global config.
func FixtureSetPreoptWithUpdatableBcp(value bool) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) {

View File

@@ -25,7 +25,7 @@ import (
"android/soong/android"
)
// Build rules and utilities to generate individual packages/modules/SdkExtensions/proto/classpaths.proto
// Build rules and utilities to generate individual packages/modules/common/proto/classpaths.proto
// config files based on build configuration to embed into /system and /apex on a device.
//
// See `derive_classpath` service that reads the configs at runtime and defines *CLASSPATH variables
@@ -34,14 +34,15 @@ import (
type classpathType int
const (
// Matches definition in packages/modules/SdkExtensions/proto/classpaths.proto
// Matches definition in packages/modules/common/proto/classpaths.proto
BOOTCLASSPATH classpathType = iota
DEX2OATBOOTCLASSPATH
SYSTEMSERVERCLASSPATH
STANDALONE_SYSTEMSERVER_JARS
)
func (c classpathType) String() string {
return [...]string{"BOOTCLASSPATH", "DEX2OATBOOTCLASSPATH", "SYSTEMSERVERCLASSPATH"}[c]
return [...]string{"BOOTCLASSPATH", "DEX2OATBOOTCLASSPATH", "SYSTEMSERVERCLASSPATH", "STANDALONE_SYSTEMSERVER_JARS"}[c]
}
type classpathFragmentProperties struct {

View File

@@ -58,6 +58,10 @@ func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []andr
func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
configuredJars := p.configuredJars(ctx)
classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
configuredJars = configuredJars.AppendList(standaloneConfiguredJars)
classpathJars = append(classpathJars, standaloneClasspathJars...)
p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
}
@@ -66,6 +70,10 @@ func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleC
return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
}
func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
}
type SystemServerClasspathModule struct {
android.ModuleBase
android.ApexModuleBase
@@ -84,10 +92,15 @@ func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseMo
}
type systemServerClasspathFragmentProperties struct {
// The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
// List of system_server classpath jars, could be either java_library, or java_sdk_library.
//
// The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Contents []string
// List of jars that system_server loads dynamically using separate classloaders.
//
// The order does not matter.
Standalone_contents []string
}
func systemServerClasspathFactory() android.Module {
@@ -101,12 +114,16 @@ func systemServerClasspathFactory() android.Module {
}
func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(s.properties.Contents) == 0 {
ctx.PropertyErrorf("contents", "empty contents are not allowed")
if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
}
configuredJars := s.configuredJars(ctx)
classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
configuredJars = configuredJars.AppendList(standaloneConfiguredJars)
classpathJars = append(classpathJars, standaloneClasspathJars...)
s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
// Collect the module directory for IDE info in java/jdeps.go.
@@ -145,6 +162,17 @@ func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext)
return jars
}
func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
global := dexpreopt.GetGlobalConfig(ctx)
possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
// TODO(jiakaiz): add a check to ensure that the contents are declared in make.
return jars
}
type systemServerClasspathFragmentContentDependencyTag struct {
blueprint.BaseDependencyTag
}
@@ -192,8 +220,11 @@ func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) b
func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
module := ctx.Module()
_, isSourceModule := module.(*SystemServerClasspathModule)
var deps []string
deps = append(deps, s.properties.Contents...)
deps = append(deps, s.properties.Standalone_contents...)
for _, name := range s.properties.Contents {
for _, name := range deps {
// A systemserverclasspath_fragment must depend only on other source modules, while the
// prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
if !isSourceModule {
@@ -206,6 +237,7 @@ func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpM
// Collect information for opening IDE project files in java/jdeps.go.
func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
}
@@ -233,14 +265,22 @@ func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct(
type systemServerClasspathFragmentSdkMemberProperties struct {
android.SdkMemberPropertiesBase
// Contents of the systemserverclasspath fragment
// List of system_server classpath jars, could be either java_library, or java_sdk_library.
//
// The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Contents []string
// List of jars that system_server loads dynamically using separate classloaders.
//
// The order does not matter.
Standalone_contents []string
}
func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
module := variant.(*SystemServerClasspathModule)
s.Contents = module.properties.Contents
s.Standalone_contents = module.properties.Standalone_contents
}
func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
@@ -250,6 +290,10 @@ func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx
if len(s.Contents) > 0 {
propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
}
if len(s.Standalone_contents) > 0 {
propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
}
}
var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)

View File

@@ -99,7 +99,7 @@ func TestPlatformSystemServerClasspathModule_AndroidMkEntries(t *testing.T) {
func TestSystemServerClasspathFragmentWithoutContents(t *testing.T) {
prepareForTestWithSystemServerClasspath.
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
`\Qempty contents are not allowed\E`)).
`\QEither contents or standalone_contents needs to be non-empty\E`)).
RunTestWithBp(t, `
systemserverclasspath_fragment {
name: "systemserverclasspath-fragment",