8
8
"go/token"
9
9
"go/types"
10
10
"os"
11
+ "strings"
11
12
12
13
"golang.org/x/exp/apidiff"
13
14
"golang.org/x/tools/go/gcexportdata"
@@ -17,6 +18,7 @@ import (
17
18
var (
18
19
exportDataOutfile = flag .String ("w" , "" , "file for export data" )
19
20
incompatibleOnly = flag .Bool ("incompatible" , false , "display only incompatible changes" )
21
+ allowInternal = flag .Bool ("allow-internal" , false , "allow apidiff to compare internal packages" )
20
22
)
21
23
22
24
func main () {
@@ -54,7 +56,12 @@ func main() {
54
56
}
55
57
oldpkg := mustLoadOrRead (flag .Arg (0 ))
56
58
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
+ }
58
65
report := apidiff .Changes (oldpkg , newpkg )
59
66
var err error
60
67
if * incompatibleOnly {
@@ -140,3 +147,15 @@ func die(format string, args ...interface{}) {
140
147
fmt .Fprintf (os .Stderr , format + "\n " , args ... )
141
148
os .Exit (1 )
142
149
}
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