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:
parent
2d1bb89fe3
commit
a720811c38
|
@ -281,10 +281,31 @@ type SdkMember interface {
|
||||||
Variants() []SdkAware
|
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 {
|
type SdkMemberTypeDependencyTag interface {
|
||||||
blueprint.DependencyTag
|
blueprint.DependencyTag
|
||||||
|
|
||||||
|
// SdkMemberType returns the SdkMemberType that will be used to automatically add the child module
|
||||||
|
// to the sdk.
|
||||||
SdkMemberType() SdkMemberType
|
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)
|
var _ SdkMemberTypeDependencyTag = (*sdkMemberDependencyTag)(nil)
|
||||||
|
@ -293,20 +314,28 @@ var _ ReplaceSourceWithPrebuilt = (*sdkMemberDependencyTag)(nil)
|
||||||
type sdkMemberDependencyTag struct {
|
type sdkMemberDependencyTag struct {
|
||||||
blueprint.BaseDependencyTag
|
blueprint.BaseDependencyTag
|
||||||
memberType SdkMemberType
|
memberType SdkMemberType
|
||||||
|
export bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *sdkMemberDependencyTag) SdkMemberType() SdkMemberType {
|
func (t *sdkMemberDependencyTag) SdkMemberType() SdkMemberType {
|
||||||
return t.memberType
|
return t.memberType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *sdkMemberDependencyTag) ExportMember() bool {
|
||||||
|
return t.export
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent dependencies from the sdk/module_exports onto their members from being
|
// Prevent dependencies from the sdk/module_exports onto their members from being
|
||||||
// replaced with a preferred prebuilt.
|
// replaced with a preferred prebuilt.
|
||||||
func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
|
func (t *sdkMemberDependencyTag) ReplaceSourceWithPrebuilt() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func DependencyTagForSdkMemberType(memberType SdkMemberType) SdkMemberTypeDependencyTag {
|
// DependencyTagForSdkMemberType creates an SdkMemberTypeDependencyTag that will cause any
|
||||||
return &sdkMemberDependencyTag{memberType: memberType}
|
// 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
|
// Interface that must be implemented for every type that can be a member of an
|
||||||
|
|
|
@ -77,8 +77,9 @@ var (
|
||||||
"classpath", "outDir", "workDir")
|
"classpath", "outDir", "workDir")
|
||||||
|
|
||||||
// Dependency tag that causes the added dependencies to be added as java_header_libs
|
// Dependency tag that causes the added dependencies to be added as java_header_libs
|
||||||
// to the sdk/module_exports/snapshot.
|
// to the sdk/module_exports/snapshot. Dependencies that are added automatically via this tag are
|
||||||
systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType)
|
// not automatically exported.
|
||||||
|
systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType, false)
|
||||||
)
|
)
|
||||||
|
|
||||||
func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) {
|
func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) {
|
||||||
|
|
19
sdk/sdk.go
19
sdk/sdk.go
|
@ -193,7 +193,8 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
|
||||||
|
|
||||||
memberType: memberType,
|
memberType: memberType,
|
||||||
|
|
||||||
dependencyTag: android.DependencyTagForSdkMemberType(memberType),
|
// Dependencies added directly from member properties are always exported.
|
||||||
|
dependencyTag: android.DependencyTagForSdkMemberType(memberType, true),
|
||||||
}
|
}
|
||||||
|
|
||||||
listProperties = append(listProperties, memberListProperty)
|
listProperties = append(listProperties, memberListProperty)
|
||||||
|
@ -255,22 +256,6 @@ func (s *sdk) memberListProperties() []*sdkMemberListProperty {
|
||||||
return s.dynamicSdkMemberTypes.memberListProperties
|
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 {
|
func (s *sdk) snapshot() bool {
|
||||||
return s.properties.Snapshot
|
return s.properties.Snapshot
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,8 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) {
|
||||||
// Keep track of which multilib variants are used by the sdk.
|
// Keep track of which multilib variants are used by the sdk.
|
||||||
s.multilibUsages = s.multilibUsages.addArchType(child.Target().Arch.ArchType)
|
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
|
// If the member type supports transitive sdk members then recurse down into
|
||||||
// its dependencies, otherwise exit traversal.
|
// 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
|
// Record the names of all the members, both explicitly specified and implicitly
|
||||||
// included.
|
// included.
|
||||||
for _, memberVariantDep := range sdkVariant.memberVariantDeps {
|
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.
|
if memberVariantDep.export {
|
||||||
for key, _ := range sdkVariant.getExportedMembers() {
|
exportedMembersByName[name] = struct{}{}
|
||||||
exportedMembersByName[key] = struct{}{}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,6 +945,7 @@ func addSdkMemberPropertiesToSet(ctx *memberContext, memberProperties android.Sd
|
||||||
type sdkMemberVariantDep struct {
|
type sdkMemberVariantDep struct {
|
||||||
memberType android.SdkMemberType
|
memberType android.SdkMemberType
|
||||||
variant android.SdkAware
|
variant android.SdkAware
|
||||||
|
export bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ android.SdkMember = (*sdkMember)(nil)
|
var _ android.SdkMember = (*sdkMember)(nil)
|
||||||
|
|
Loading…
Reference in New Issue