diff options
Diffstat (limited to 'android')
-rw-r--r-- | android/license.go | 13 | ||||
-rw-r--r-- | android/licenses.go | 26 | ||||
-rw-r--r-- | android/licenses_test.go | 196 | ||||
-rw-r--r-- | android/module.go | 7 | ||||
-rw-r--r-- | android/module_proxy.go | 4 |
5 files changed, 23 insertions, 223 deletions
diff --git a/android/license.go b/android/license.go index ffda58b37..7b4aeeb5d 100644 --- a/android/license.go +++ b/android/license.go @@ -19,7 +19,6 @@ import ( ) type LicenseInfo struct { - EffectiveLicenses []string PackageName *string EffectiveLicenseText NamedPaths EffectiveLicenseKinds []string @@ -79,23 +78,23 @@ func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) { func (m *licenseModule) GenerateAndroidBuildActions(ctx ModuleContext) { // license modules have no licenses, but license_kinds must refer to license_kind modules - mergeStringProps(&m.base().commonProperties.Effective_licenses, ctx.ModuleName()) namePathProps(&m.base().commonProperties.Effective_license_text, m.properties.Package_name, PathsForModuleSrc(ctx, m.properties.License_text)...) + var conditions []string + var kinds []string for _, module := range ctx.GetDirectDepsProxyWithTag(licenseKindTag) { if lk, ok := OtherModuleProvider(ctx, module, LicenseKindInfoProvider); ok { - mergeStringProps(&m.base().commonProperties.Effective_license_conditions, lk.Conditions...) - mergeStringProps(&m.base().commonProperties.Effective_license_kinds, ctx.OtherModuleName(module)) + conditions = append(conditions, lk.Conditions...) + kinds = append(kinds, ctx.OtherModuleName(module)) } else { ctx.ModuleErrorf("license_kinds property %q is not a license_kind module", ctx.OtherModuleName(module)) } } SetProvider(ctx, LicenseInfoProvider, LicenseInfo{ - EffectiveLicenses: m.base().commonProperties.Effective_licenses, PackageName: m.properties.Package_name, EffectiveLicenseText: m.base().commonProperties.Effective_license_text, - EffectiveLicenseKinds: m.base().commonProperties.Effective_license_kinds, - EffectiveLicenseConditions: m.base().commonProperties.Effective_license_conditions, + EffectiveLicenseKinds: SortedUniqueStrings(kinds), + EffectiveLicenseConditions: SortedUniqueStrings(conditions), }) } diff --git a/android/licenses.go b/android/licenses.go index 77f563f8c..32d12c8a2 100644 --- a/android/licenses.go +++ b/android/licenses.go @@ -227,16 +227,18 @@ func licensesPropertyFlattener(ctx ModuleContext) { } 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 @@ func licensesPropertyFlattener(ctx ModuleContext) { } } + 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 @@ func licensesPropertyFlattener(ctx ModuleContext) { 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 @@ func namePathProps(prop *NamedPaths, name *string, values ...Path) { *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) { diff --git a/android/licenses_test.go b/android/licenses_test.go index 8a81e1294..0c371e8e9 100644 --- a/android/licenses_test.go +++ b/android/licenses_test.go @@ -7,15 +7,13 @@ import ( ) var licensesTests = []struct { - name string - fs MockFS - expectedErrors []string - effectiveLicenses map[string][]string - effectiveInheritedLicenses map[string][]string - effectivePackage map[string]string - effectiveNotices map[string][]string - effectiveKinds map[string][]string - effectiveConditions map[string][]string + name string + fs MockFS + expectedErrors []string + effectivePackage map[string]string + effectiveNotices map[string][]string + effectiveKinds map[string][]string + effectiveConditions map[string][]string }{ { name: "invalid module type without licenses property", @@ -69,11 +67,6 @@ var licensesTests = []struct { licenses: ["top_Apache2"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample1": []string{"top_Apache2"}, - "libnested": []string{"top_Apache2"}, - "libother": []string{"top_Apache2"}, - }, effectiveKinds: map[string][]string{ "libexample1": []string{"notice"}, "libnested": []string{"notice"}, @@ -146,18 +139,6 @@ var licensesTests = []struct { deps: ["libexample"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample": []string{"nested_other", "top_other"}, - "libsamepackage": []string{}, - "libnested": []string{}, - "libother": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "libexample": []string{"nested_other", "top_other"}, - "libsamepackage": []string{"nested_other", "top_other"}, - "libnested": []string{"nested_other", "top_other"}, - "libother": []string{"nested_other", "top_other"}, - }, effectiveKinds: map[string][]string{ "libexample": []string{"nested_notice", "top_notice"}, "libsamepackage": []string{}, @@ -217,20 +198,6 @@ var licensesTests = []struct { deps: ["libexample"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample": []string{"other", "top_nested"}, - "libsamepackage": []string{}, - "libnested": []string{}, - "libother": []string{}, - "liboutsider": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "libexample": []string{"other", "top_nested"}, - "libsamepackage": []string{"other", "top_nested"}, - "libnested": []string{"other", "top_nested"}, - "libother": []string{"other", "top_nested"}, - "liboutsider": []string{"other", "top_nested"}, - }, effectiveKinds: map[string][]string{ "libexample": []string{}, "libsamepackage": []string{}, @@ -284,14 +251,6 @@ var licensesTests = []struct { defaults: ["top_defaults"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample": []string{"by_exception_only"}, - "libdefaults": []string{"notice"}, - }, - effectiveInheritedLicenses: map[string][]string{ - "libexample": []string{"by_exception_only"}, - "libdefaults": []string{"notice"}, - }, }, // Package default_applicable_licenses tests @@ -326,14 +285,6 @@ var licensesTests = []struct { deps: ["libexample"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample": []string{"top_notice"}, - "liboutsider": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "libexample": []string{"top_notice"}, - "liboutsider": []string{"top_notice"}, - }, }, { name: "package default_applicable_licenses not inherited to subpackages", @@ -369,18 +320,6 @@ var licensesTests = []struct { deps: ["libexample", "libother", "libnested"], }`), }, - effectiveLicenses: map[string][]string{ - "libexample": []string{"top_notice"}, - "libnested": []string{"outsider"}, - "libother": []string{}, - "liboutsider": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "libexample": []string{"top_notice"}, - "libnested": []string{"outsider"}, - "libother": []string{}, - "liboutsider": []string{"top_notice", "outsider"}, - }, }, { name: "verify that prebuilt dependencies are included", @@ -409,12 +348,6 @@ var licensesTests = []struct { deps: [":module"], }`), }, - effectiveLicenses: map[string][]string{ - "other": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "other": []string{"prebuilt", "top_sources"}, - }, }, { name: "verify that prebuilt dependencies are ignored for licenses reasons (preferred)", @@ -444,13 +377,6 @@ var licensesTests = []struct { deps: [":module"], }`), }, - effectiveLicenses: map[string][]string{ - "other": []string{}, - }, - effectiveInheritedLicenses: map[string][]string{ - "module": []string{"prebuilt", "top_sources"}, - "other": []string{"prebuilt", "top_sources"}, - }, }, } @@ -470,10 +396,6 @@ func TestLicenses(t *testing.T) { ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)). RunTest(t) - if test.effectiveLicenses != nil { - checkEffectiveLicenses(t, result, test.effectiveLicenses) - } - if test.effectivePackage != nil { checkEffectivePackage(t, result, test.effectivePackage) } @@ -489,114 +411,10 @@ func TestLicenses(t *testing.T) { if test.effectiveConditions != nil { checkEffectiveConditions(t, result, test.effectiveConditions) } - - if test.effectiveInheritedLicenses != nil { - checkEffectiveInheritedLicenses(t, result, test.effectiveInheritedLicenses) - } }) } } -func checkEffectiveLicenses(t *testing.T, result *TestResult, effectiveLicenses map[string][]string) { - actualLicenses := make(map[string][]string) - result.Context.Context.VisitAllModules(func(m blueprint.Module) { - if _, ok := m.(*licenseModule); ok { - return - } - if _, ok := m.(*licenseKindModule); ok { - return - } - if _, ok := m.(*packageModule); ok { - return - } - module, ok := m.(Module) - if !ok { - t.Errorf("%q not a module", m.Name()) - return - } - base := module.base() - if base == nil { - return - } - actualLicenses[m.Name()] = base.commonProperties.Effective_licenses - }) - - for moduleName, expectedLicenses := range effectiveLicenses { - licenses, ok := actualLicenses[moduleName] - if !ok { - licenses = []string{} - } - if !compareUnorderedStringArrays(expectedLicenses, licenses) { - t.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses) - } - } -} - -func checkEffectiveInheritedLicenses(t *testing.T, result *TestResult, effectiveInheritedLicenses map[string][]string) { - actualLicenses := make(map[string][]string) - result.Context.Context.VisitAllModules(func(m blueprint.Module) { - if _, ok := m.(*licenseModule); ok { - return - } - if _, ok := m.(*licenseKindModule); ok { - return - } - if _, ok := m.(*packageModule); ok { - return - } - module, ok := m.(Module) - if !ok { - t.Errorf("%q not a module", m.Name()) - return - } - base := module.base() - if base == nil { - return - } - inherited := make(map[string]bool) - for _, l := range base.commonProperties.Effective_licenses { - inherited[l] = true - } - result.Context.Context.VisitDepsDepthFirst(m, func(c blueprint.Module) { - if _, ok := c.(*licenseModule); ok { - return - } - if _, ok := c.(*licenseKindModule); ok { - return - } - if _, ok := c.(*packageModule); ok { - return - } - cmodule, ok := c.(Module) - if !ok { - t.Errorf("%q not a module", c.Name()) - return - } - cbase := cmodule.base() - if cbase == nil { - return - } - for _, l := range cbase.commonProperties.Effective_licenses { - inherited[l] = true - } - }) - actualLicenses[m.Name()] = []string{} - for l := range inherited { - actualLicenses[m.Name()] = append(actualLicenses[m.Name()], l) - } - }) - - for moduleName, expectedInheritedLicenses := range effectiveInheritedLicenses { - licenses, ok := actualLicenses[moduleName] - if !ok { - licenses = []string{} - } - if !compareUnorderedStringArrays(expectedInheritedLicenses, licenses) { - t.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses) - } - } -} - func checkEffectivePackage(t *testing.T, result *TestResult, effectivePackage map[string]string) { actualPackage := make(map[string]string) result.Context.Context.VisitAllModules(func(m blueprint.Module) { diff --git a/android/module.go b/android/module.go index 788c21b59..39a165463 100644 --- a/android/module.go +++ b/android/module.go @@ -94,7 +94,6 @@ type Module interface { ReplacedByPrebuilt() IsReplacedByPrebuilt() bool ExportedToMake() bool - EffectiveLicenseKinds() []string EffectiveLicenseFiles() Paths AddProperties(props ...interface{}) @@ -317,8 +316,6 @@ type commonProperties struct { // Describes the licenses applicable to this module. Must reference license modules. Licenses []string - // Flattened from direct license dependencies. Equal to Licenses unless particular module adds more. - Effective_licenses []string `blueprint:"mutated"` // Override of module name when reporting licenses Effective_package_name *string `blueprint:"mutated"` // Notice files @@ -1467,10 +1464,6 @@ func (m *ModuleBase) ExportedToMake() bool { return m.commonProperties.NamespaceExportedToMake } -func (m *ModuleBase) EffectiveLicenseKinds() []string { - return m.commonProperties.Effective_license_kinds -} - func (m *ModuleBase) EffectiveLicenseFiles() Paths { result := make(Paths, 0, len(m.commonProperties.Effective_license_text)) for _, p := range m.commonProperties.Effective_license_text { diff --git a/android/module_proxy.go b/android/module_proxy.go index afca0d72b..77abc11e6 100644 --- a/android/module_proxy.go +++ b/android/module_proxy.go @@ -164,10 +164,6 @@ func (m ModuleProxy) ExportedToMake() bool { panic("method is not implemented on ModuleProxy") } -func (m ModuleProxy) EffectiveLicenseKinds() []string { - panic("method is not implemented on ModuleProxy") -} - func (m ModuleProxy) EffectiveLicenseFiles() Paths { panic("method is not implemented on ModuleProxy") } |