Clean up some of the code around effective license.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I01f0407e4eb6050b556bfebc1cc4d1abd29ad4a6
diff --git a/android/licenses.go b/android/licenses.go
index 77f563f..32d12c8 100644
--- a/android/licenses.go
+++ b/android/licenses.go
@@ -227,16 +227,18 @@
}
var licenses []string
+ var texts NamedPaths
+ var conditions []string
+ var kinds []string
for _, module := range ctx.GetDirectDepsProxyWithTag(licensesTag) {
if l, ok := OtherModuleProvider(ctx, module, LicenseInfoProvider); ok {
licenses = append(licenses, ctx.OtherModuleName(module))
if m.base().commonProperties.Effective_package_name == nil && l.PackageName != nil {
m.base().commonProperties.Effective_package_name = l.PackageName
}
- mergeStringProps(&m.base().commonProperties.Effective_licenses, l.EffectiveLicenses...)
- mergeNamedPathProps(&m.base().commonProperties.Effective_license_text, l.EffectiveLicenseText...)
- mergeStringProps(&m.base().commonProperties.Effective_license_kinds, l.EffectiveLicenseKinds...)
- mergeStringProps(&m.base().commonProperties.Effective_license_conditions, l.EffectiveLicenseConditions...)
+ texts = append(texts, l.EffectiveLicenseText...)
+ kinds = append(kinds, l.EffectiveLicenseKinds...)
+ conditions = append(conditions, l.EffectiveLicenseConditions...)
} else {
propertyName := "licenses"
primaryProperty := m.base().primaryLicensesProperty
@@ -247,6 +249,10 @@
}
}
+ m.base().commonProperties.Effective_license_text = SortedUniqueNamedPaths(texts)
+ m.base().commonProperties.Effective_license_kinds = SortedUniqueStrings(kinds)
+ m.base().commonProperties.Effective_license_conditions = SortedUniqueStrings(conditions)
+
// Make the license information available for other modules.
licenseInfo := LicensesInfo{
Licenses: licenses,
@@ -254,12 +260,6 @@
SetProvider(ctx, LicensesInfoProvider, licenseInfo)
}
-// Update a property string array with a distinct union of its values and a list of new values.
-func mergeStringProps(prop *[]string, values ...string) {
- *prop = append(*prop, values...)
- *prop = SortedUniqueStrings(*prop)
-}
-
// Update a property NamedPath array with a distinct union of its values and a list of new values.
func namePathProps(prop *NamedPaths, name *string, values ...Path) {
if name == nil {
@@ -274,12 +274,6 @@
*prop = SortedUniqueNamedPaths(*prop)
}
-// Update a property NamedPath array with a distinct union of its values and a list of new values.
-func mergeNamedPathProps(prop *NamedPaths, values ...NamedPath) {
- *prop = append(*prop, values...)
- *prop = SortedUniqueNamedPaths(*prop)
-}
-
// Get the licenses property falling back to the package default.
func getLicenses(ctx BaseModuleContext, module Module) []string {
if exemptFromRequiredApplicableLicensesProperty(module) {