Skip to content

Instantly share code, notes, and snippets.

@jupj

jupj/README.txt Secret

Last active February 28, 2020 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jupj/639b5cda305d251161fec2304c27c9b9 to your computer and use it in GitHub Desktop.
Save jupj/639b5cda305d251161fec2304c27c9b9 to your computer and use it in GitHub Desktop.
The script first generates simplified diffs of all z*_linux_{GOARCH}.go files.
Then it compares these simplified diffs between the architectures to validate
that all architectures got the same code pulled out from them. These diffs
should be identical.
Finally, it compares the simplified (arch) diff with the merged file. The
resulting diff should not show any specific const, type, or func declarations.
Only package clause, imports, build constraint, comments, and "group headers"
of consts or types should be visible in this diff.
*** zsysnum_linux ***
No merged file for zsysnum_linux
*** zsyscall_linux ***
*** diff zsyscall between arch files ***
diff zsyscall_linux_386.go.diff zsyscall_linux_amd64.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_arm.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_arm64.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_mips.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_mips64.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_mips64le.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_mipsle.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_ppc64.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_ppc64le.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_riscv64.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_s390x.go.diff
diff zsyscall_linux_386.go.diff zsyscall_linux_sparc64.go.diff
*** diff zsyscall merged with architecture ***
1,13d0
< // Code generated by mkmerge.go; DO NOT EDIT.
<
< // +build linux
<
< package unix
<
< import (
< "syscall"
< "unsafe"
< )
<
< // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
<
1825a1559
> // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
*** ztypes_linux ***
*** diff ztypes between arch files ***
diff ztypes_linux_386.go.diff ztypes_linux_amd64.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_arm.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_arm64.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_mips.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_mips64.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_mips64le.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_mipsle.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_ppc64.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_ppc64le.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_riscv64.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_s390x.go.diff
diff ztypes_linux_386.go.diff ztypes_linux_sparc64.go.diff
*** diff ztypes merged with architecture ***
1,7d0
< // Code generated by mkmerge.go; DO NOT EDIT.
<
< // +build linux
<
< package unix
<
< const (
13,15d4
< )
<
< type (
20,21d7
< )
<
141,142d111
<
< const (
147,148d115
< )
<
340,341d280
<
< const (
371,373d307
< )
<
< const (
629,630d549
< )
<
660,661d574
<
< const (
691,692d597
< )
<
795,796d692
<
< const (
798,799d693
< )
<
1204,1205d1065
<
< const (
1211,1212d1069
< )
<
1695,1696d1543
<
< const (
1700,1701d1546
< )
<
*** zerrors_linux ***
*** diff zerrors between arch files ***
diff zerrors_linux_386.go.diff zerrors_linux_amd64.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_arm.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_arm64.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_mips.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_mips64.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_mips64le.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_mipsle.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_ppc64.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_ppc64le.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_riscv64.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_s390x.go.diff
diff zerrors_linux_386.go.diff zerrors_linux_sparc64.go.diff
*** diff zerrors merged with architecture ***
1,9d0
< // Code generated by mkmerge.go; DO NOT EDIT.
<
< // +build linux
<
< package unix
<
< import "syscall"
<
< const (
2510,2513d2387
< )
<
< // Errors
< const (
2573,2576d2422
< )
<
< // Signals
< const (
2594d2435
< )
#!/bin/bash
# Script to validate that mkmerge.go works correct for linux files.
# Checkout the commit for https://golang.org/cl/221318,
# https://golang.org/cl/221319 or https://golang.org/cl/221320 and
# run this script in ~/go/src/golang.org/x/sys/unix
# To clean up after this script (run at your own risk): rm z*_linux_*.go.diff
# base commit to be used for diffing the architecture files:
base=d5e6a3e2c0ae16fc7480523ebcb7fd4dd3215489
goos=linux
for ztype in zsysnum zsyscall ztypes zerrors; do
echo "*** ${ztype}_${goos} ***"
if [ ! -f "${ztype}_${goos}.go" ]; then
echo "No merged file for ${ztype}_${goos}"
echo ""
continue
fi
# List modified files (remove "unix/" prefix)
files=$(git diff --name-only $base -- "${ztype}_${goos}_*.go" | sed 's/^unix\///')
if [ -z "$files" ]; then
echo "No modified files for ${ztype}_${goos}"
echo ""
continue
fi
# Save diff for each modified file - ignore whitespace changes
for file in $files; do
# The patience diff strategy provides a more stable diff
git diff --ignore-all-space --patience $base -- $file |
# Filter the diff: save only the added/removed lines
egrep '^[+-]' | # list only diffed lines
egrep -v '^(---|\+\+\+)' | # remove diff header "---" and "+++"
egrep -v '^[+-]\s*$' | # remove whitespace-only diff lines
cat > "$file.diff"
done
# Compare diffs between arch files
echo "*** diff $ztype between arch files ***"
first=$(echo $files | awk '{print $1}')
rest=$(echo $files | awk '{$1=""; print $0}')
for file in $rest; do
#diff --minimal --brief "$first.diff" "$file.diff"
echo "diff $first.diff" "$file.diff"
diff --minimal "$first.diff" "$file.diff"
done
# Compare the first arch file diff with the merged file (remove "-" at beginning of diff lines)
echo "*** diff $ztype merged with architecture ***"
diff --minimal --report-identical-files --ignore-all-space --ignore-blank-lines "${ztype}_${goos}.go" <(sed 's/^-//' $first.diff)
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment