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
This commit is contained in:
@@ -5,12 +5,12 @@ blueprint_go_binary {
|
|||||||
"diff_target_files.go",
|
"diff_target_files.go",
|
||||||
"glob.go",
|
"glob.go",
|
||||||
"target_files.go",
|
"target_files.go",
|
||||||
"whitelist.go",
|
"allow_list.go",
|
||||||
"zip_artifact.go",
|
"zip_artifact.go",
|
||||||
],
|
],
|
||||||
testSrcs: [
|
testSrcs: [
|
||||||
"compare_test.go",
|
"compare_test.go",
|
||||||
"glob_test.go",
|
"glob_test.go",
|
||||||
"whitelist_test.go",
|
"allow_list_test.go",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
@@ -25,18 +25,13 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type jsonWhitelist struct {
|
type allowList struct {
|
||||||
Paths []string
|
|
||||||
IgnoreMatchingLines []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type whitelist struct {
|
|
||||||
path string
|
path string
|
||||||
ignoreMatchingLines []string
|
ignoreMatchingLines []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, error) {
|
func parseAllowLists(allowLists []string, allowListFiles []string) ([]allowList, error) {
|
||||||
var ret []whitelist
|
var ret []allowList
|
||||||
|
|
||||||
add := func(path string, ignoreMatchingLines []string) {
|
add := func(path string, ignoreMatchingLines []string) {
|
||||||
for _, x := range ret {
|
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,
|
path: path,
|
||||||
ignoreMatchingLines: ignoreMatchingLines,
|
ignoreMatchingLines: ignoreMatchingLines,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range whitelistFiles {
|
for _, file := range allowListFiles {
|
||||||
newWhitelists, err := parseWhitelistFile(file)
|
newAllowlists, err := parseAllowListFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, w := range newWhitelists {
|
for _, w := range newAllowlists {
|
||||||
add(w.path, w.ignoreMatchingLines)
|
add(w.path, w.ignoreMatchingLines)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range whitelists {
|
for _, s := range allowLists {
|
||||||
colon := strings.IndexRune(s, ':')
|
colon := strings.IndexRune(s, ':')
|
||||||
var ignoreMatchingLines []string
|
var ignoreMatchingLines []string
|
||||||
if colon >= 0 {
|
if colon >= 0 {
|
||||||
@@ -75,7 +70,7 @@ func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist,
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseWhitelistFile(file string) ([]whitelist, error) {
|
func parseAllowListFile(file string) ([]allowList, error) {
|
||||||
r, err := os.Open(file)
|
r, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -84,27 +79,32 @@ func parseWhitelistFile(file string) ([]whitelist, error) {
|
|||||||
|
|
||||||
d := json.NewDecoder(newJSONCommentStripper(r))
|
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
|
var allowLists []allowList
|
||||||
for _, w := range jsonWhitelists {
|
for _, w := range jsonAllowLists {
|
||||||
for _, p := range w.Paths {
|
for _, p := range w.Paths {
|
||||||
whitelists = append(whitelists, whitelist{
|
allowLists = append(allowLists, allowList{
|
||||||
path: p,
|
path: p,
|
||||||
ignoreMatchingLines: w.IgnoreMatchingLines,
|
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:
|
outer:
|
||||||
for i := 0; i < len(l); i++ {
|
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 {
|
if match, err := Match(w.path, l[i][0].Name); err != nil {
|
||||||
return l, err
|
return l, err
|
||||||
} else if match {
|
} else if match {
|
||||||
@@ -126,10 +126,10 @@ outer:
|
|||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterNewPaths(l []*ZipArtifactFile, whitelists []whitelist) ([]*ZipArtifactFile, error) {
|
func filterNewPaths(l []*ZipArtifactFile, allowLists []allowList) ([]*ZipArtifactFile, error) {
|
||||||
outer:
|
outer:
|
||||||
for i := 0; i < len(l); i++ {
|
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 {
|
if match, err := Match(w.path, l[i].Name); err != nil {
|
||||||
return l, err
|
return l, err
|
||||||
} else if match && len(w.ignoreMatchingLines) == 0 {
|
} 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
|
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
|
var err error
|
||||||
|
|
||||||
diff.modified, err = filterModifiedPaths(diff.modified, whitelists)
|
diff.modified, err = filterModifiedPaths(diff.modified, allowLists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diff, err
|
return diff, err
|
||||||
}
|
}
|
||||||
diff.onlyInA, err = filterNewPaths(diff.onlyInA, whitelists)
|
diff.onlyInA, err = filterNewPaths(diff.onlyInA, allowLists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diff, err
|
return diff, err
|
||||||
}
|
}
|
||||||
diff.onlyInB, err = filterNewPaths(diff.onlyInB, whitelists)
|
diff.onlyInB, err = filterNewPaths(diff.onlyInB, allowLists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diff, err
|
return diff, err
|
||||||
}
|
}
|
@@ -57,10 +57,10 @@ c
|
|||||||
|
|
||||||
var f2 = bytesToZipArtifactFile("dir/f2", nil)
|
var f2 = bytesToZipArtifactFile("dir/f2", nil)
|
||||||
|
|
||||||
func Test_applyWhitelists(t *testing.T) {
|
func Test_applyAllowLists(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
diff zipDiff
|
diff zipDiff
|
||||||
whitelists []whitelist
|
allowLists []allowList
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -74,7 +74,7 @@ func Test_applyWhitelists(t *testing.T) {
|
|||||||
diff: zipDiff{
|
diff: zipDiff{
|
||||||
onlyInA: []*ZipArtifactFile{f1a, f2},
|
onlyInA: []*ZipArtifactFile{f1a, f2},
|
||||||
},
|
},
|
||||||
whitelists: []whitelist{{path: "dir/f1"}},
|
allowLists: []allowList{{path: "dir/f1"}},
|
||||||
},
|
},
|
||||||
want: zipDiff{
|
want: zipDiff{
|
||||||
onlyInA: []*ZipArtifactFile{f2},
|
onlyInA: []*ZipArtifactFile{f2},
|
||||||
@@ -86,7 +86,7 @@ func Test_applyWhitelists(t *testing.T) {
|
|||||||
diff: zipDiff{
|
diff: zipDiff{
|
||||||
onlyInA: []*ZipArtifactFile{f1a, f2},
|
onlyInA: []*ZipArtifactFile{f1a, f2},
|
||||||
},
|
},
|
||||||
whitelists: []whitelist{{path: "dir/*"}},
|
allowLists: []allowList{{path: "dir/*"}},
|
||||||
},
|
},
|
||||||
want: zipDiff{},
|
want: zipDiff{},
|
||||||
},
|
},
|
||||||
@@ -96,7 +96,7 @@ func Test_applyWhitelists(t *testing.T) {
|
|||||||
diff: zipDiff{
|
diff: zipDiff{
|
||||||
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
|
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
|
||||||
},
|
},
|
||||||
whitelists: []whitelist{{path: "dir/*"}},
|
allowLists: []allowList{{path: "dir/*"}},
|
||||||
},
|
},
|
||||||
want: zipDiff{},
|
want: zipDiff{},
|
||||||
},
|
},
|
||||||
@@ -106,20 +106,20 @@ func Test_applyWhitelists(t *testing.T) {
|
|||||||
diff: zipDiff{
|
diff: zipDiff{
|
||||||
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
|
modified: [][2]*ZipArtifactFile{{f1a, f1b}},
|
||||||
},
|
},
|
||||||
whitelists: []whitelist{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
|
allowLists: []allowList{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}},
|
||||||
},
|
},
|
||||||
want: zipDiff{},
|
want: zipDiff{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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 {
|
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
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
@@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
// compareTargetFiles takes two ZipArtifacts and compares the files they contain by examining
|
// compareTargetFiles takes two ZipArtifacts and compares the files they contain by examining
|
||||||
// the path, size, and CRC of each file.
|
// 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()
|
priZipFiles, err := priZip.Files()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return zipDiff{}, fmt.Errorf("error fetching target file lists from primary zip %v", err)
|
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
|
// Compare the file lists from both builds
|
||||||
diff := diffTargetFilesLists(refZipFiles, priZipFiles)
|
diff := diffTargetFilesLists(refZipFiles, priZipFiles)
|
||||||
|
|
||||||
return applyWhitelists(diff, whitelists)
|
return applyAllowLists(diff, allowLists)
|
||||||
}
|
}
|
||||||
|
|
||||||
// zipDiff contains the list of files that differ between two zip files.
|
// zipDiff contains the list of files that differ between two zip files.
|
||||||
|
@@ -22,8 +22,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
whitelists = newMultiString("whitelist", "whitelist patterns in the form <pattern>[:<regex of line to ignore>]")
|
allowLists = newMultiString("allowlist", "allowlist patterns in the form <pattern>[:<regex of line to ignore>]")
|
||||||
whitelistFiles = newMultiString("whitelist_file", "files containing whitelist definitions")
|
allowListFiles = newMultiString("allowlist_file", "files containing allowlist definitions")
|
||||||
|
|
||||||
filters = newMultiString("filter", "filter patterns to apply to files in target-files.zip before comparing")
|
filters = newMultiString("filter", "filter patterns to apply to files in target-files.zip before comparing")
|
||||||
)
|
)
|
||||||
@@ -47,9 +47,9 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
whitelists, err := parseWhitelists(*whitelists, *whitelistFiles)
|
allowLists, err := parseAllowLists(*allowLists, *allowListFiles)
|
||||||
if err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer refZip.Close()
|
defer refZip.Close()
|
||||||
|
|
||||||
diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, whitelists, *filters)
|
diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, allowLists, *filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error comparing zip files: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error comparing zip files: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Reference in New Issue
Block a user