Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6196ea23 authored by Bob Badour's avatar Bob Badour Committed by Gerrit Code Review
Browse files

Merge "Make notice order more deterministic."

parents 255c1f0e 113c92b0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -360,7 +360,8 @@ func (ni *NoticeIndex) getLibName(noticeFor *TargetNode, h hash) string {
						continue
					}
				}
				for r, prefix := range SafePrebuiltPrefixes {
				for _, r := range OrderedSafePrebuiltPrefixes {
					prefix := SafePrebuiltPrefixes[r]
					match := r.FindString(licenseText)
					if len(match) == 0 {
						continue
+43 −17
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ package compliance

import (
	"regexp"
	"sort"
	"strings"
)

var (
@@ -41,6 +43,7 @@ var (
		"development/":          false,
		"frameworks/":           false,
		"packages/":             true,
		"prebuilts/module_sdk/": true,
		"prebuilts/":            false,
		"sdk/":                  false,
		"system/":               false,
@@ -53,6 +56,10 @@ var (
	// containing the path of a safe prefix to the safe prefix.
	SafePrebuiltPrefixes = make(map[*regexp.Regexp]string)

	// OrderedSafePrebuiltPrefixes lists the SafePrebuiltPrefixes ordered by
	// increasing length.
	OrderedSafePrebuiltPrefixes = make([]*regexp.Regexp, 0, 0)

	// ImpliesUnencumbered lists the condition names representing an author attempt to disclaim copyright.
	ImpliesUnencumbered = LicenseConditionSet(UnencumberedCondition)

@@ -89,14 +96,33 @@ var (
	ccBySa       = regexp.MustCompile(`^SPDX-license-identifier-CC-BY.*-SA.*`)
)

// byIncreasingLength implements `sort.Interface` to order regular expressions by increasing length.
type byIncreasingLength []*regexp.Regexp

func (l byIncreasingLength) Len() int      { return len(l) }
func (l byIncreasingLength) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l byIncreasingLength) Less(i, j int) bool {
	ri := l[i].String()
	rj := l[j].String()
	if len(ri) == len(rj) {
		return ri < rj
	}
	return len(ri) < len(rj)
}

func init() {
	for prefix := range SafePathPrefixes {
		if prefix == "prebuilts/" {
		if strings.HasPrefix(prefix, "prebuilts/") {
			continue
		}
		r := regexp.MustCompile("^prebuilts/[^ ]*/" + prefix)
		r := regexp.MustCompile("^prebuilts/(?:runtime/mainline/)?" + prefix)
		SafePrebuiltPrefixes[r] = prefix
	}
	OrderedSafePrebuiltPrefixes = make([]*regexp.Regexp, 0, len(SafePrebuiltPrefixes))
	for r := range SafePrebuiltPrefixes {
		OrderedSafePrebuiltPrefixes = append(OrderedSafePrebuiltPrefixes, r)
	}
	sort.Sort(byIncreasingLength(OrderedSafePrebuiltPrefixes))
}

// LicenseConditionSetFromNames returns a set containing the recognized `names` and