Differentiate between exported and internal sdk members

Internal sdk members are used by an sdk member but not exported by the
sdk. The exported sdk members are those listed explicitly in one of the
sdk member list properties, e.g. java_header_libs.

The prebuilts of an internal sdk member use a unique name so that they
do not clash with the source module. The use of the module internally
is an implementation detail that must not have any effect outside the
snapshot. Having the same name as the source module could cause it to
override the source module, hence why it needs a unique name.

Similarly, they are marked as private so as to prevent their accidental
use from outside the snapshot.

Bug: 142940300
Test: m nothing
Change-Id: Id5364b410be0592f65666afb3e40e9d3f020251c
This commit is contained in:
Paul Duffin
2020-01-20 18:16:30 +00:00
parent 7b81f5e9d7
commit 7291095d82
3 changed files with 144 additions and 19 deletions

View File

@@ -50,6 +50,9 @@ type sdk struct {
// list properties, e.g. java_libs.
dynamicMemberTypeListProperties interface{}
// The set of exported members.
exportedMembers map[string]struct{}
properties sdkProperties
snapshotFile android.OptionalPath
@@ -217,6 +220,33 @@ func SnapshotModuleFactory() android.Module {
return s
}
func (s *sdk) memberListProperties() []*sdkMemberListProperty {
return s.dynamicSdkMemberTypes.memberListProperties
}
func (s *sdk) getExportedMembers() map[string]struct{} {
if s.exportedMembers == nil {
// Collect all the exported members.
s.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 {
s.exportedMembers[name] = struct{}{}
}
}
}
return s.exportedMembers
}
func (s *sdk) isInternalMember(memberName string) bool {
_, ok := s.getExportedMembers()[memberName]
return !ok
}
func (s *sdk) snapshot() bool {
return s.properties.Snapshot
}
@@ -290,7 +320,7 @@ func (t sdkMemberVersionedDepTag) ExcludeFromVisibilityEnforcement() {}
// Step 1: create dependencies from an SDK module to its members.
func memberMutator(mctx android.BottomUpMutatorContext) {
if s, ok := mctx.Module().(*sdk); ok {
for _, memberListProperty := range s.dynamicSdkMemberTypes.memberListProperties {
for _, memberListProperty := range s.memberListProperties() {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
tag := memberListProperty.dependencyTag
memberListProperty.memberType.AddDependencies(mctx, tag, names)