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

Commit 113c92b0 authored by Bob Badour's avatar Bob Badour
Browse files

Make notice order more deterministic.

Bug: 230357391

Test: m droid dist
Change-Id: Ib3f771f9fd16743fca3f6c80c2ff85c9e42772a9
parent 65a2b40d
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