Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apidiff: ignore internal packages #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 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 All @@ -17,6 +18,7 @@ import (
var (
exportDataOutfile = flag.String("w", "", "file for export data")
incompatibleOnly = flag.Bool("incompatible", false, "display only incompatible changes")
allowInternal = flag.Bool("allow-internal", false, "allow apidiff to compare internal packages")
)

func main() {
Expand Down Expand Up @@ -54,7 +56,12 @@ func main() {
}
oldpkg := mustLoadOrRead(flag.Arg(0))
newpkg := mustLoadOrRead(flag.Arg(1))

if !*allowInternal {
if isInternalPackage(oldpkg.Path()) && isInternalPackage(newpkg.Path()) {
fmt.Fprintf(os.Stderr, "Ignoring internal package %s\n", oldpkg.Path())
os.Exit(0)
}
}
report := apidiff.Changes(oldpkg, newpkg)
var err error
if *incompatibleOnly {
Expand Down Expand Up @@ -140,3 +147,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
}