Add license modules to the sdk

Adds initial support for adding license modules to the sdk, along with
any referenced license text files. There is a number of minor
improvements to be made but the core of the support is there and it
works for ART sdks.

Basically, this change will automatically add license modules
referenced from any sdk member module as an internal sdk member. An
internal module has an sdk snapshot specific name that will not
conflict with the source module and which cannot be referenced from
outside the sdk snapshot.

Bug: 181569894
Test: m art-module-sdk art-module-host-exports art-module-test-exports
      - diff output before and after this change
        made sure that every prebuilt had a licenses field
        and that the license modules were added
Change-Id: I0c5ccabf58f4ef487e42ef8e61a5b2a74c0e81af
diff --git a/android/licenses.go b/android/licenses.go
index c9e1da4..464ba49 100644
--- a/android/licenses.go
+++ b/android/licenses.go
@@ -32,8 +32,23 @@
 	blueprint.BaseDependencyTag
 }
 
+func (l licensesDependencyTag) SdkMemberType(Module) SdkMemberType {
+	// Add the supplied module to the sdk as a license module.
+	return LicenseModuleSdkMemberType
+}
+
+func (l licensesDependencyTag) ExportMember() bool {
+	// The license module will only every be referenced from within the sdk. This will ensure that it
+	// gets a unique name and so avoid clashing with the original license module.
+	return false
+}
+
 var (
 	licensesTag = licensesDependencyTag{}
+
+	// License modules, i.e. modules depended upon via a licensesTag, must be automatically added to
+	// any sdk/module_exports to which their referencing module is a member.
+	_ SdkMemberTypeDependencyTag = licensesTag
 )
 
 // Describes the property provided by a module to reference applicable licenses.
@@ -140,7 +155,6 @@
 	}
 
 	licenses := getLicenses(ctx, m)
-
 	ctx.AddVariationDependencies(nil, licensesTag, licenses...)
 }
 
@@ -191,8 +205,10 @@
 		return
 	}
 
+	var licenses []string
 	for _, module := range ctx.GetDirectDepsWithTag(licensesTag) {
 		if l, ok := module.(*licenseModule); ok {
+			licenses = append(licenses, ctx.OtherModuleName(module))
 			if m.base().commonProperties.Effective_package_name == nil && l.properties.Package_name != nil {
 				m.base().commonProperties.Effective_package_name = l.properties.Package_name
 			}
@@ -209,6 +225,12 @@
 			ctx.ModuleErrorf("%s property %q is not a license module", propertyName, ctx.OtherModuleName(module))
 		}
 	}
+
+	// Make the license information available for other modules.
+	licenseInfo := LicenseInfo{
+		Licenses: licenses,
+	}
+	ctx.SetProvider(LicenseInfoProvider, licenseInfo)
 }
 
 // Update a property string array with a distinct union of its values and a list of new values.
@@ -277,3 +299,12 @@
 	}
 	return true
 }
+
+// LicenseInfo contains information about licenses for a specific module.
+type LicenseInfo struct {
+	// The list of license modules this depends upon, either explicitly or through default package
+	// configuration.
+	Licenses []string
+}
+
+var LicenseInfoProvider = blueprint.NewProvider(LicenseInfo{})