-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement "import public" using type aliases. (#583)
Type aliases were added in Go 1.9, so this change bumps the minium required Go version for protos which use public imports.
- Loading branch information
Showing
19 changed files
with
518 additions
and
1,197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"flag" | ||
"fmt" | ||
"go/build" | ||
"go/parser" | ||
"go/token" | ||
"io/ioutil" | ||
|
@@ -38,8 +39,13 @@ func TestGolden(t *testing.T) { | |
|
||
// Find all the proto files we need to compile. We assume that each directory | ||
// contains the files for a single package. | ||
supportTypeAliases := hasReleaseTag("1.9") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
neild
Author
Contributor
|
||
packages := map[string][]string{} | ||
err = filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error { | ||
if filepath.Base(path) == "import_public" && !supportTypeAliases { | ||
// Public imports require type alias support. | ||
return filepath.SkipDir | ||
} | ||
if !strings.HasSuffix(path, ".proto") { | ||
return nil | ||
} | ||
|
@@ -405,3 +411,12 @@ func protoc(t *testing.T, args []string) { | |
t.Fatalf("protoc: %v", err) | ||
} | ||
} | ||
|
||
func hasReleaseTag(want string) bool { | ||
for _, tag := range build.Default.ReleaseTags { | ||
if tag == want { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.
This won't work
If I print out build.Default.ReleaseTags on Mac I get
Support type aliases are also supported from go1.9 and up, this check should be forwards compatible and not only check for go 1.9