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

Commit 09ef4dc2 authored by Patrice Arruda's avatar Patrice Arruda
Browse files

Update language to comply with inclusive guidance

See https://source.android.com/setup/contribute/respectful-code for
reference

Bug: 161896447
Test: m diff_target_files
Change-Id: I5654ccc5ba9be8cff01689b952d2feaade19ae79
parent 359d4f33
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5,12 +5,12 @@ blueprint_go_binary {
        "diff_target_files.go",
        "glob.go",
        "target_files.go",
        "whitelist.go",
        "allow_list.go",
        "zip_artifact.go",
    ],
    testSrcs: [
        "compare_test.go",
        "glob_test.go",
        "whitelist_test.go",
        "allow_list_test.go",
    ],
}
+28 −28
Original line number Diff line number Diff line
@@ -25,18 +25,13 @@ import (
	"unicode"
)

type jsonWhitelist struct {
	Paths               []string
	IgnoreMatchingLines []string
}

type whitelist struct {
type allowList struct {
	path                string
	ignoreMatchingLines []string
}

func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, error) {
	var ret []whitelist
func parseAllowLists(allowLists []string, allowListFiles []string) ([]allowList, error) {
	var ret []allowList

	add := func(path string, ignoreMatchingLines []string) {
		for _, x := range ret {
@@ -46,24 +41,24 @@ func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist,
			}
		}

		ret = append(ret, whitelist{
		ret = append(ret, allowList{
			path:                path,
			ignoreMatchingLines: ignoreMatchingLines,
		})
	}

	for _, file := range whitelistFiles {
		newWhitelists, err := parseWhitelistFile(file)
	for _, file := range allowListFiles {
		newAllowlists, err := parseAllowListFile(file)
		if err != nil {
			return nil, err
		}

		for _, w := range newWhitelists {
		for _, w := range newAllowlists {
			add(w.path, w.ignoreMatchingLines)
		}
	}

	for _, s := range whitelists {
	for _, s := range allowLists {
		colon := strings.IndexRune(s, ':')
		var ignoreMatchingLines []string
		if colon >= 0 {
@@ -75,7 +70,7 @@ func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist,
	return ret, nil
}

func parseWhitelistFile(file string) ([]whitelist, error) {
func parseAllowListFile(file string) ([]allowList, error) {
	r, err := os.Open(file)
	if err != nil {
		return nil, err
@@ -84,27 +79,32 @@ func parseWhitelistFile(file string) ([]whitelist, error) {

	d := json.NewDecoder(newJSONCommentStripper(r))

	var jsonWhitelists []jsonWhitelist
	var jsonAllowLists []struct {
		Paths               []string
		IgnoreMatchingLines []string
	}

	err = d.Decode(&jsonWhitelists)
	if err := d.Decode(&jsonAllowLists); err != nil {
		return nil, err
	}

	var whitelists []whitelist
	for _, w := range jsonWhitelists {
	var allowLists []allowList
	for _, w := range jsonAllowLists {
		for _, p := range w.Paths {
			whitelists = append(whitelists, whitelist{
			allowLists = append(allowLists, allowList{
				path:                p,
				ignoreMatchingLines: w.IgnoreMatchingLines,
			})
		}
	}

	return whitelists, err
	return allowLists, err
}

func filterModifiedPaths(l [][2]*ZipArtifactFile, whitelists []whitelist) ([][2]*ZipArtifactFile, error) {
func filterModifiedPaths(l [][2]*ZipArtifactFile, allowLists []allowList) ([][2]*ZipArtifactFile, error) {
outer:
	for i := 0; i < len(l); i++ {
		for _, w := range whitelists {
		for _, w := range allowLists {
			if match, err := Match(w.path, l[i][0].Name); err != nil {
				return l, err
			} else if match {
@@ -126,10 +126,10 @@ outer:
	return l, nil
}

func filterNewPaths(l []*ZipArtifactFile, whitelists []whitelist) ([]*ZipArtifactFile, error) {
func filterNewPaths(l []*ZipArtifactFile, allowLists []allowList) ([]*ZipArtifactFile, error) {
outer:
	for i := 0; i < len(l); i++ {
		for _, w := range whitelists {
		for _, w := range allowLists {
			if match, err := Match(w.path, l[i].Name); err != nil {
				return l, err
			} else if match && len(w.ignoreMatchingLines) == 0 {
@@ -192,18 +192,18 @@ func diffIgnoringMatchingLines(a *ZipArtifactFile, b *ZipArtifactFile, ignoreMat
	return bytes.Compare(bufA, bufB) == 0, nil
}

func applyWhitelists(diff zipDiff, whitelists []whitelist) (zipDiff, error) {
func applyAllowLists(diff zipDiff, allowLists []allowList) (zipDiff, error) {
	var err error

	diff.modified, err = filterModifiedPaths(diff.modified, whitelists)
	diff.modified, err = filterModifiedPaths(diff.modified, allowLists)
	if err != nil {
		return diff, err
	}
	diff.onlyInA, err = filterNewPaths(diff.onlyInA, whitelists)
	diff.onlyInA, err = filterNewPaths(diff.onlyInA, allowLists)
	if err != nil {
		return diff, err
	}
	diff.onlyInB, err = filterNewPaths(diff.onlyInB, whitelists)
	diff.onlyInB, err = filterNewPaths(diff.onlyInB, allowLists)
	if err != nil {
		return diff, err
	}
+9 −9
Original line number Diff line number Diff line
@@ -57,10 +57,10 @@ c

var f2 = bytesToZipArtifactFile("dir/f2", nil)

func Test_applyWhitelists(t *testing.T) {
func Test_applyAllowLists(t *testing.T) {
	type args struct {
		diff       zipDiff
		whitelists []whitelist
		allowLists []allowList
	}
	tests := []struct {
		name    string
@@ -74,7 +74,7 @@ func Test_applyWhitelists(t *testing.T) {
				diff: zipDiff{
					onlyInA: []*ZipArtifactFile{f1a, f2},
				},
				whitelists: []whitelist{{path: "dir/f1"}},
				allowLists: []allowList{{path: "dir/f1"}},
			},
			want: zipDiff{
				onlyInA: []*ZipArtifactFile{f2},
@@ -86,7 +86,7 @@ func Test_applyWhitelists(t *testing.T) {
				diff: zipDiff{
					onlyInA: []*ZipArtifactFile{f1a, f2},
				},
				whitelists: []whitelist{{path: "dir/*"}},
				allowLists: []allowList{{path: "dir/*"}},
			},
			want: zipDiff{},
		},
@@ -96,7 +96,7 @@ func Test_applyWhitelists(t *testing.T) {
				diff: zipDiff{
					modified: [][2]*ZipArtifactFile{{f1a, f1b}},
				},
				whitelists: []whitelist{{path: "dir/*"}},
				allowLists: []allowList{{path: "dir/*"}},
			},
			want: zipDiff{},
		},
@@ -106,20 +106,20 @@ func Test_applyWhitelists(t *testing.T) {
				diff: zipDiff{
					modified: [][2]*ZipArtifactFile{{f1a, f1b}},
				},
				whitelists: []whitelist{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
				allowLists: []allowList{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
			},
			want: zipDiff{},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := applyWhitelists(tt.args.diff, tt.args.whitelists)
			got, err := applyAllowLists(tt.args.diff, tt.args.allowLists)
			if (err != nil) != tt.wantErr {
				t.Errorf("applyWhitelists() error = %v, wantErr %v", err, tt.wantErr)
				t.Errorf("Test_applyAllowLists() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("applyWhitelists() = %v, want %v", got, tt.want)
				t.Errorf("Test_applyAllowLists() = %v, want %v", got, tt.want)
			}
		})
	}
+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import (

// compareTargetFiles takes two ZipArtifacts and compares the files they contain by examining
// the path, size, and CRC of each file.
func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, whitelists []whitelist, filters []string) (zipDiff, error) {
func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, allowLists []allowList, filters []string) (zipDiff, error) {
	priZipFiles, err := priZip.Files()
	if err != nil {
		return zipDiff{}, fmt.Errorf("error fetching target file lists from primary zip %v", err)
@@ -45,7 +45,7 @@ func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, whitelists
	// Compare the file lists from both builds
	diff := diffTargetFilesLists(refZipFiles, priZipFiles)

	return applyWhitelists(diff, whitelists)
	return applyAllowLists(diff, allowLists)
}

// zipDiff contains the list of files that differ between two zip files.
+5 −5
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import (
)

var (
	whitelists     = newMultiString("whitelist", "whitelist patterns in the form <pattern>[:<regex of line to ignore>]")
	whitelistFiles = newMultiString("whitelist_file", "files containing whitelist definitions")
	allowLists     = newMultiString("allowlist", "allowlist patterns in the form <pattern>[:<regex of line to ignore>]")
	allowListFiles = newMultiString("allowlist_file", "files containing allowlist definitions")

	filters = newMultiString("filter", "filter patterns to apply to files in target-files.zip before comparing")
)
@@ -47,9 +47,9 @@ func main() {
		os.Exit(1)
	}

	whitelists, err := parseWhitelists(*whitelists, *whitelistFiles)
	allowLists, err := parseAllowLists(*allowLists, *allowListFiles)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error parsing whitelists: %v\n", err)
		fmt.Fprintf(os.Stderr, "Error parsing allowlists: %v\n", err)
		os.Exit(1)
	}

@@ -67,7 +67,7 @@ func main() {
	}
	defer refZip.Close()

	diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, whitelists, *filters)
	diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, allowLists, *filters)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error comparing zip files: %v\n", err)
		os.Exit(1)