Merge "Add entries for STANDALONE_SYSTEMSERVER_JARS to systemserverclasspath.pb" am: 2258b889bf am: 1d7dad1f09 am: 0cb50b1036 am: 33ea009498

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1876173

Change-Id: I9c1f63b38f151fface4001dd98800488b91e6926
This commit is contained in:
Jiakai Zhang
2021-12-01 13:13:19 +00:00
committed by Automerger Merge Worker
6 changed files with 169 additions and 13 deletions

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",