Skip to content

Commit

Permalink
apidiff: ignore internal pack
Browse files Browse the repository at this point in the history
  • Loading branch information
gh73962 committed May 16, 2022
1 parent 39d4317 commit 3b7c810
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cmd/apidiff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go/token"
"go/types"
"os"
"strings"

"golang.org/x/exp/apidiff"
"golang.org/x/tools/go/gcexportdata"
Expand Down Expand Up @@ -44,6 +45,10 @@ func main() {
os.Exit(2)
}
pkg := mustLoadPackage(flag.Arg(0))
// if the package is an internal package, ignore it
if isInternalPackage(pkg.PkgPath) {
die("ignore internal package:%s", pkg.PkgPath)
}
if err := writeExportData(pkg, *exportDataOutfile); err != nil {
die("writing export data: %v", err)
}
Expand All @@ -54,7 +59,10 @@ func main() {
}
oldpkg := mustLoadOrRead(flag.Arg(0))
newpkg := mustLoadOrRead(flag.Arg(1))

// if the package is an internal package, ignore it
if isInternalPackage(oldpkg.Path()) || isInternalPackage(newpkg.Path()) {
return
}
report := apidiff.Changes(oldpkg, newpkg)
var err error
if *incompatibleOnly {
Expand Down Expand Up @@ -140,3 +148,15 @@ func die(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}

func isInternalPackage(pkgPath string) bool {
switch {
case strings.HasSuffix(pkgPath, "/internal"):
return true
case strings.Contains(pkgPath, "/internal/"):
return true
case pkgPath == "internal", strings.HasPrefix(pkgPath, "internal/"):
return true
}
return false
}

0 comments on commit 3b7c810

Please sign in to comment.