Skip to content

Commit 24438e5

Browse files
gh73962jba
authored andcommitted
apidiff: ignore internal packages
A feature is added to apidiff that allows users to ignore internal package comparisons. Fixes golang/go#52864. Change-Id: Ic390e198ef81901a9aed4212bc6f49e73ab78336 GitHub-Last-Rev: 9b59beb GitHub-Pull-Request: golang#32 Reviewed-on: https://go-review.googlesource.com/c/exp/+/406534 Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]>
1 parent 39d4317 commit 24438e5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cmd/apidiff/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"go/token"
99
"go/types"
1010
"os"
11+
"strings"
1112

1213
"golang.org/x/exp/apidiff"
1314
"golang.org/x/tools/go/gcexportdata"
@@ -17,6 +18,7 @@ import (
1718
var (
1819
exportDataOutfile = flag.String("w", "", "file for export data")
1920
incompatibleOnly = flag.Bool("incompatible", false, "display only incompatible changes")
21+
allowInternal = flag.Bool("allow-internal", false, "allow apidiff to compare internal packages")
2022
)
2123

2224
func main() {
@@ -54,7 +56,12 @@ func main() {
5456
}
5557
oldpkg := mustLoadOrRead(flag.Arg(0))
5658
newpkg := mustLoadOrRead(flag.Arg(1))
57-
59+
if !*allowInternal {
60+
if isInternalPackage(oldpkg.Path()) && isInternalPackage(newpkg.Path()) {
61+
fmt.Fprintf(os.Stderr, "Ignoring internal package %s\n", oldpkg.Path())
62+
os.Exit(0)
63+
}
64+
}
5865
report := apidiff.Changes(oldpkg, newpkg)
5966
var err error
6067
if *incompatibleOnly {
@@ -140,3 +147,15 @@ func die(format string, args ...interface{}) {
140147
fmt.Fprintf(os.Stderr, format+"\n", args...)
141148
os.Exit(1)
142149
}
150+
151+
func isInternalPackage(pkgPath string) bool {
152+
switch {
153+
case strings.HasSuffix(pkgPath, "/internal"):
154+
return true
155+
case strings.Contains(pkgPath, "/internal/"):
156+
return true
157+
case pkgPath == "internal", strings.HasPrefix(pkgPath, "internal/"):
158+
return true
159+
}
160+
return false
161+
}

0 commit comments

Comments
 (0)