Allow exporting of sdk members to be done per tag

Previously, every module added to an sdk directly through one of the
SdkMemberType specific properties, e.g. java_libs, was exported and
every module added automatically via a transitive dependencies was not
exported. This change allows that behavior to be customized per tag.

Bug: 186290299
Test: m art-module-sdk
      - verify that this change does not affect its contents.
Change-Id: I563b5bcd823e61c23cdb706cfcbb13337963d550
This commit is contained in:
Paul Duffin 2021-04-23 21:20:20 +01:00
parent 2d1bb89fe3
commit a720811c38
4 changed files with 44 additions and 27 deletions

View File

@ -281,10 +281,31 @@ type SdkMember interface {
Variants() []SdkAware
}
// SdkMemberTypeDependencyTag is the interface that a tag must implement in order to allow the
// dependent module to be automatically added to the sdk. In order for this to work the
// SdkMemberType of the depending module must return true from
// SdkMemberType.HasTransitiveSdkMembers.
type SdkMemberTypeDependencyTag interface {
blueprint.DependencyTag
// SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
// to the sdk.
SdkMemberType() SdkMemberType
// ExportMember determines whether a module added to the sdk through this tag will be exported
// from the sdk or not.
//
// An exported member is added to the sdk using its own name, e.g. if "foo" was exported from sdk
// "bar" then its prebuilt would be simply called "foo". A member can be added to the sdk via
// multiple tags and if any of those tags returns true from this method then the membe will be
// exported. Every module added directly to the sdk via one of the member type specific
// properties, e.g. java_libs, will automatically be exported.
//
// If a member is not exported then it is treated as an internal implementation detail of the
// sdk and so will be added with an sdk specific name. e.g. if "foo" was an internal member of sdk
// "bar" then its prebuilt would be called "bar_foo". Additionally its visibility will be set to
// "//visibility:private" so it will not be accessible from outside its Android.bp file.
ExportMember() bool
}
var _ SdkMemberTypeDependencyTag = (*sdkMemberDependencyTag)(nil)
@ -293,20 +314,28 @@ var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
type sdkMemberDependencyTag struct {
blueprint.BaseDependencyTag
memberType SdkMemberType
export bool
}
func (t *sdkMemberDependencyTag) SdkMemberType() SdkMemberType {
return t.memberType
}
func (t *sdkMemberDependencyTag) ExportMember() bool {
return t.export
}
// Prevent dependencies from the sdk/module_exports onto their members from being
// replaced with a preferred prebuilt.
func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
return false
}
func DependencyTagForSdkMemberType(memberType SdkMemberType) SdkMemberTypeDependencyTag {
return &sdkMemberDependencyTag{memberType: memberType}
// DependencyTagForSdkMemberType creates an SdkMemberTypeDependencyTag that will cause any
// dependencies added by the tag to be added to the sdk as the specified SdkMemberType and exported
// (or not) as specified by the export parameter.
func DependencyTagForSdkMemberType(memberType SdkMemberType, export bool) SdkMemberTypeDependencyTag {
return &sdkMemberDependencyTag{memberType: memberType, export: export}
}
// Interface that must be implemented for every type that can be a member of an

View File

@ -77,8 +77,9 @@ var (
"classpath", "outDir", "workDir")
// Dependency tag that causes the added dependencies to be added as java_header_libs
// to the sdk/module_exports/snapshot.
systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType)
// to the sdk/module_exports/snapshot. Dependencies that are added automatically via this tag are
// not automatically exported.
systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType, false)
)
func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) {

View File

@ -193,7 +193,8 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
memberType: memberType,
dependencyTag: android.DependencyTagForSdkMemberType(memberType),
// Dependencies added directly from member properties are always exported.
dependencyTag: android.DependencyTagForSdkMemberType(memberType, true),
}
listProperties = append(listProperties, memberListProperty)
@ -255,22 +256,6 @@ func (s *sdk) memberListProperties() []*sdkMemberListProperty {
return s.dynamicSdkMemberTypes.memberListProperties
}
func (s *sdk) getExportedMembers() map[string]struct{} {
// Collect all the exported members.
exportedMembers := make(map[string]struct{})
for _, memberListProperty := range s.memberListProperties() {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
// Every member specified explicitly in the properties is exported by the sdk.
for _, name := range names {
exportedMembers[name] = struct{}{}
}
}
return exportedMembers
}
func (s *sdk) snapshot() bool {
return s.properties.Snapshot
}

View File

@ -130,7 +130,8 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) {
// Keep track of which multilib variants are used by the sdk.
s.multilibUsages = s.multilibUsages.addArchType(child.Target().Arch.ArchType)
s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{memberType, child.(android.SdkAware)})
export := memberTag.ExportMember()
s.memberVariantDeps = append(s.memberVariantDeps, sdkMemberVariantDep{memberType, child.(android.SdkAware), export})
// If the member type supports transitive sdk members then recurse down into
// its dependencies, otherwise exit traversal.
@ -226,12 +227,12 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
// Record the names of all the members, both explicitly specified and implicitly
// included.
for _, memberVariantDep := range sdkVariant.memberVariantDeps {
allMembersByName[memberVariantDep.variant.Name()] = struct{}{}
}
name := memberVariantDep.variant.Name()
allMembersByName[name] = struct{}{}
// Merge the exported member sets from all sdk variants.
for key, _ := range sdkVariant.getExportedMembers() {
exportedMembersByName[key] = struct{}{}
if memberVariantDep.export {
exportedMembersByName[name] = struct{}{}
}
}
}
@ -944,6 +945,7 @@ func addSdkMemberPropertiesToSet(ctx *memberContext, memberProperties android.Sd
type sdkMemberVariantDep struct {
memberType android.SdkMemberType
variant android.SdkAware
export bool
}
var _ android.SdkMember = (*sdkMember)(nil)