mirror of https://github.com/kubernetes/kops.git
commit
51bde64325
12
WORKSPACE
12
WORKSPACE
|
|
@ -7,19 +7,19 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
|||
http_archive(
|
||||
name = "io_bazel_rules_go",
|
||||
urls = [
|
||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.19.7/rules_go-v0.19.7.tar.gz",
|
||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.19.7/rules_go-v0.19.7.tar.gz",
|
||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.2/rules_go-v0.20.2.tar.gz",
|
||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.2/rules_go-v0.20.2.tar.gz",
|
||||
],
|
||||
sha256 = "b480589f57e8b09f4b0892437b9afe889e0d6660e92f5d53d3f0546c01e67ca5",
|
||||
sha256 = "b9aa86ec08a292b97ec4591cf578e020b35f98e12173bbd4a921f84f583aebd9",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "bazel_gazelle",
|
||||
sha256 = "7fc87f4170011201b1690326e8c16c5d802836e3a0d617d8f75c3af2b23180c4",
|
||||
urls = [
|
||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz",
|
||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
|
||||
],
|
||||
sha256 = "86c6d481b3f7aedc1d60c1c211c6f76da282ae197c3b3160f54bd3a8f847896f",
|
||||
)
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -77,7 +77,7 @@ require (
|
|||
github.com/Masterminds/sprig v2.17.1+incompatible
|
||||
github.com/aokoli/goutils v1.0.1 // indirect
|
||||
github.com/aws/aws-sdk-go v1.23.0
|
||||
github.com/bazelbuild/bazel-gazelle v0.18.2-0.20190823151146-67c9ddf12d8a
|
||||
github.com/bazelbuild/bazel-gazelle v0.19.1
|
||||
github.com/blang/semver v3.5.0+incompatible
|
||||
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
|
||||
github.com/client9/misspell v0.0.0-20170928000206-9ce5d979ffda
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -45,6 +45,8 @@ github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
|
|||
github.com/bazelbuild/bazel-gazelle v0.0.0-20181012220611-c728ce9f663e/go.mod h1:uHBSeeATKpVazAACZBDPL/Nk/UhQDDsJWDlqYJo8/Us=
|
||||
github.com/bazelbuild/bazel-gazelle v0.18.2-0.20190823151146-67c9ddf12d8a h1:deQfCtgFxAkn4SvpkM/76bGuZf16y5WL/4dvcAWLHho=
|
||||
github.com/bazelbuild/bazel-gazelle v0.18.2-0.20190823151146-67c9ddf12d8a/go.mod h1:D0ehMSbS+vesFsLGiD6JXu3mVEzOlfUl8wNnq+x/9p0=
|
||||
github.com/bazelbuild/bazel-gazelle v0.19.1 h1:TSCGVqpHStCj1MTszuDfZt6Z2Ca8ekq2oWiqcHKVEAE=
|
||||
github.com/bazelbuild/bazel-gazelle v0.19.1/go.mod h1:rPwzNHUqEzngx1iVBfO/2X2npKaT3tqPqqHW6rVsn/A=
|
||||
github.com/bazelbuild/buildtools v0.0.0-20180226164855-80c7f0d45d7e/go.mod h1:5JP0TXzWDHXv8qvxRC4InIazwdyDseBDbzESUMKk1yU=
|
||||
github.com/bazelbuild/buildtools v0.0.0-20190731111112-f720930ceb60 h1:OfyUN/Msd8yqJww6deQ9vayJWw+Jrbe6Qp9giv51QQI=
|
||||
github.com/bazelbuild/buildtools v0.0.0-20190731111112-f720930ceb60/go.mod h1:5JP0TXzWDHXv8qvxRC4InIazwdyDseBDbzESUMKk1yU=
|
||||
|
|
@ -521,6 +523,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
|
|
|||
|
|
@ -127,39 +127,36 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro
|
|||
// Load the repo configuration file (WORKSPACE by default) to find out
|
||||
// names and prefixes of other go_repositories. This affects external
|
||||
// dependency resolution for Go.
|
||||
// TODO(jayconrod): this should be moved to language/go.
|
||||
var repoFileMap map[*rule.File][]string
|
||||
// TODO(jayconrod): Go-specific code should be moved to language/go.
|
||||
if ucr.repoConfigPath == "" {
|
||||
ucr.repoConfigPath = filepath.Join(c.RepoRoot, "WORKSPACE")
|
||||
}
|
||||
repoConfigFile, err := rule.LoadWorkspaceFile(ucr.repoConfigPath, "")
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
uc.repos, repoFileMap, err = repo.ListRepositories(repoConfigFile)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
} else if err == nil {
|
||||
c.Repos, _, err = repo.ListRepositories(repoConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
repoPrefixes := make(map[string]bool)
|
||||
for _, r := range uc.repos {
|
||||
repoPrefixes[r.GoPrefix] = true
|
||||
}
|
||||
for _, imp := range ucr.knownImports {
|
||||
if repoPrefixes[imp] {
|
||||
continue
|
||||
}
|
||||
repo := repo.Repo{
|
||||
uc.repos = append(uc.repos, repo.Repo{
|
||||
Name: label.ImportPathToBazelRepoName(imp),
|
||||
GoPrefix: imp,
|
||||
})
|
||||
}
|
||||
for _, r := range c.Repos {
|
||||
if r.Kind() == "go_repository" {
|
||||
uc.repos = append(uc.repos, repo.Repo{
|
||||
Name: r.Name(),
|
||||
GoPrefix: r.AttrString("importpath"),
|
||||
})
|
||||
}
|
||||
uc.repos = append(uc.repos, repo)
|
||||
}
|
||||
|
||||
// If the repo configuration file is not WORKSPACE, also load WORKSPACE
|
||||
// so we can apply any necessary fixes.
|
||||
// and any declared macro files so we can apply fixes.
|
||||
workspacePath := filepath.Join(c.RepoRoot, "WORKSPACE")
|
||||
var workspace *rule.File
|
||||
if ucr.repoConfigPath == workspacePath {
|
||||
|
|
@ -169,21 +166,18 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro
|
|||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
if workspace != nil {
|
||||
_, repoFileMap, err = repo.ListRepositories(workspace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if workspace != nil {
|
||||
c.RepoName = findWorkspaceName(workspace)
|
||||
uc.workspaceFiles = make([]*rule.File, 0, len(repoFileMap))
|
||||
seen := make(map[string]bool)
|
||||
for f := range repoFileMap {
|
||||
if !seen[f.Path] {
|
||||
_, repoFileMap, err := repo.ListRepositories(workspace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
seen := make(map[*rule.File]bool)
|
||||
for _, f := range repoFileMap {
|
||||
if !seen[f] {
|
||||
uc.workspaceFiles = append(uc.workspaceFiles, f)
|
||||
seen[f.Path] = true
|
||||
seen[f] = true
|
||||
}
|
||||
}
|
||||
sort.Slice(uc.workspaceFiles, func(i, j int) bool {
|
||||
|
|
@ -238,7 +232,7 @@ var genericLoads = []rule.LoadInfo{
|
|||
},
|
||||
}
|
||||
|
||||
func runFixUpdate(cmd command, args []string) error {
|
||||
func runFixUpdate(cmd command, args []string) (err error) {
|
||||
cexts := make([]config.Configurer, 0, len(languages)+3)
|
||||
cexts = append(cexts,
|
||||
&config.CommonConfigurer{},
|
||||
|
|
@ -258,11 +252,15 @@ func runFixUpdate(cmd command, args []string) error {
|
|||
}
|
||||
ruleIndex := resolve.NewRuleIndex(mrslv.Resolver)
|
||||
|
||||
c, err := newFixUpdateConfiguration(cmd, args, cexts, loads)
|
||||
c, err := newFixUpdateConfiguration(cmd, args, cexts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fixRepoFiles(c, loads); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd == fixCmd {
|
||||
// Only check the version when "fix" is run. Generated build files
|
||||
// frequently work with older version of rules_go, and we don't want to
|
||||
|
|
@ -365,7 +363,11 @@ func runFixUpdate(cmd command, args []string) error {
|
|||
|
||||
// Resolve dependencies.
|
||||
rc, cleanupRc := repo.NewRemoteCache(uc.repos)
|
||||
defer cleanupRc()
|
||||
defer func() {
|
||||
if cerr := cleanupRc(); err == nil && cerr != nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
for _, v := range visits {
|
||||
for i, r := range v.rules {
|
||||
from := label.New(c.RepoName, v.pkgRel, r.Name())
|
||||
|
|
@ -396,7 +398,7 @@ func runFixUpdate(cmd command, args []string) error {
|
|||
return exit
|
||||
}
|
||||
|
||||
func newFixUpdateConfiguration(cmd command, args []string, cexts []config.Configurer, loads []rule.LoadInfo) (*config.Config, error) {
|
||||
func newFixUpdateConfiguration(cmd command, args []string, cexts []config.Configurer) (*config.Config, error) {
|
||||
c := config.New()
|
||||
|
||||
fs := flag.NewFlagSet("gazelle", flag.ContinueOnError)
|
||||
|
|
@ -423,11 +425,6 @@ func newFixUpdateConfiguration(cmd command, args []string, cexts []config.Config
|
|||
}
|
||||
}
|
||||
|
||||
uc := getUpdateConfig(c)
|
||||
if err := fixRepoFiles(c, uc.workspaceFiles, loads); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
|
|
@ -460,7 +457,7 @@ FLAGS:
|
|||
fs.PrintDefaults()
|
||||
}
|
||||
|
||||
func fixRepoFiles(c *config.Config, files []*rule.File, loads []rule.LoadInfo) error {
|
||||
func fixRepoFiles(c *config.Config, loads []rule.LoadInfo) error {
|
||||
uc := getUpdateConfig(c)
|
||||
if !c.ShouldFix {
|
||||
return nil
|
||||
|
|
@ -475,10 +472,10 @@ func fixRepoFiles(c *config.Config, files []*rule.File, loads []rule.LoadInfo) e
|
|||
return nil
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
for _, f := range uc.workspaceFiles {
|
||||
merger.FixLoads(f, loads)
|
||||
if f.Path == filepath.Join(c.RepoRoot, "WORKSPACE") {
|
||||
merger.FixWorkspace(f)
|
||||
removeLegacyGoRepository(f)
|
||||
if err := merger.CheckGazelleLoaded(f); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -490,6 +487,20 @@ func fixRepoFiles(c *config.Config, files []*rule.File, loads []rule.LoadInfo) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// removeLegacyGoRepository removes loads of go_repository from
|
||||
// @io_bazel_rules_go. FixLoads should be called after this; it will load from
|
||||
// @bazel_gazelle.
|
||||
func removeLegacyGoRepository(f *rule.File) {
|
||||
for _, l := range f.Loads {
|
||||
if l.Name() == "@io_bazel_rules_go//go:def.bzl" {
|
||||
l.Remove("go_repository")
|
||||
if l.IsEmpty() {
|
||||
l.Delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func findWorkspaceName(f *rule.File) string {
|
||||
for _, r := range f.Rules {
|
||||
if r.Kind() == "workspace" {
|
||||
|
|
|
|||
|
|
@ -21,37 +21,26 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/config"
|
||||
gzflag "github.com/bazelbuild/bazel-gazelle/flag"
|
||||
"github.com/bazelbuild/bazel-gazelle/language"
|
||||
"github.com/bazelbuild/bazel-gazelle/merger"
|
||||
"github.com/bazelbuild/bazel-gazelle/repo"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
)
|
||||
|
||||
type updateReposFn func(c *updateReposConfig, workspace *rule.File, oldFile *rule.File, kinds map[string]rule.KindInfo) ([]*rule.File, error)
|
||||
|
||||
type updateReposConfig struct {
|
||||
fn updateReposFn
|
||||
lockFilename string
|
||||
importPaths []string
|
||||
macroFileName string
|
||||
macroDefName string
|
||||
buildExternalAttr string
|
||||
buildFileNamesAttr string
|
||||
buildFileGenerationAttr string
|
||||
buildTagsAttr string
|
||||
buildFileProtoModeAttr string
|
||||
buildExtraArgsAttr string
|
||||
pruneRules bool
|
||||
repoFilePath string
|
||||
importPaths []string
|
||||
macroFileName string
|
||||
macroDefName string
|
||||
pruneRules bool
|
||||
workspace *rule.File
|
||||
repoFileMap map[string]*rule.File
|
||||
}
|
||||
|
||||
var validBuildExternalAttr = []string{"external", "vendored"}
|
||||
var validBuildFileGenerationAttr = []string{"auto", "on", "off"}
|
||||
var validBuildFileProtoModeAttr = []string{"default", "legacy", "disable", "disable_global", "package"}
|
||||
|
||||
const updateReposName = "_update-repos"
|
||||
|
||||
func getUpdateReposConfig(c *config.Config) *updateReposConfig {
|
||||
|
|
@ -82,52 +71,58 @@ func (f macroFlag) String() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (_ *updateReposConfigurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {
|
||||
func (*updateReposConfigurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {
|
||||
uc := &updateReposConfig{}
|
||||
c.Exts[updateReposName] = uc
|
||||
fs.StringVar(&uc.lockFilename, "from_file", "", "Gazelle will translate repositories listed in this file into repository rules in WORKSPACE or a .bzl macro function. Gopkg.lock and go.mod files are supported")
|
||||
fs.StringVar(&uc.buildFileNamesAttr, "build_file_names", "", "Sets the build_file_name attribute for the generated go_repository rule(s).")
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &uc.buildExternalAttr, Allowed: validBuildExternalAttr}, "build_external", "Sets the build_external attribute for the generated go_repository rule(s).")
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &uc.buildFileGenerationAttr, Allowed: validBuildFileGenerationAttr}, "build_file_generation", "Sets the build_file_generation attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&uc.buildTagsAttr, "build_tags", "", "Sets the build_tags attribute for the generated go_repository rule(s).")
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &uc.buildFileProtoModeAttr, Allowed: validBuildFileProtoModeAttr}, "build_file_proto_mode", "Sets the build_file_proto_mode attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&uc.buildExtraArgsAttr, "build_extra_args", "", "Sets the build_extra_args attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&uc.repoFilePath, "from_file", "", "Gazelle will translate repositories listed in this file into repository rules in WORKSPACE or a .bzl macro function. Gopkg.lock and go.mod files are supported")
|
||||
fs.Var(macroFlag{macroFileName: &uc.macroFileName, macroDefName: &uc.macroDefName}, "to_macro", "Tells Gazelle to write repository rules into a .bzl macro function rather than the WORKSPACE file. . The expected format is: macroFile%defName")
|
||||
fs.BoolVar(&uc.pruneRules, "prune", false, "When enabled, Gazelle will remove rules that no longer have equivalent repos in the Gopkg.lock/go.mod file. Can only used with -from_file.")
|
||||
}
|
||||
|
||||
func (_ *updateReposConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error {
|
||||
func (*updateReposConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error {
|
||||
uc := getUpdateReposConfig(c)
|
||||
switch {
|
||||
case uc.lockFilename != "":
|
||||
case uc.repoFilePath != "":
|
||||
if len(fs.Args()) != 0 {
|
||||
return fmt.Errorf("Got %d positional arguments with -from_file; wanted 0.\nTry -help for more information.", len(fs.Args()))
|
||||
return fmt.Errorf("got %d positional arguments with -from_file; wanted 0.\nTry -help for more information.", len(fs.Args()))
|
||||
}
|
||||
uc.fn = importFromLockFile
|
||||
|
||||
default:
|
||||
if len(fs.Args()) == 0 {
|
||||
return fmt.Errorf("No repositories specified\nTry -help for more information.")
|
||||
return fmt.Errorf("no repositories specified\nTry -help for more information.")
|
||||
}
|
||||
if uc.pruneRules {
|
||||
return fmt.Errorf("The -prune option can only be used with -from_file.")
|
||||
return fmt.Errorf("the -prune option can only be used with -from_file")
|
||||
}
|
||||
uc.fn = updateImportPaths
|
||||
uc.importPaths = fs.Args()
|
||||
}
|
||||
|
||||
var err error
|
||||
workspacePath := filepath.Join(c.RepoRoot, "WORKSPACE")
|
||||
uc.workspace, err = rule.LoadWorkspaceFile(workspacePath, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading WORKSPACE file: %v", err)
|
||||
}
|
||||
c.Repos, uc.repoFileMap, err = repo.ListRepositories(uc.workspace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading WORKSPACE file: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *updateReposConfigurer) KnownDirectives() []string { return nil }
|
||||
func (*updateReposConfigurer) KnownDirectives() []string { return nil }
|
||||
|
||||
func (_ *updateReposConfigurer) Configure(c *config.Config, rel string, f *rule.File) {}
|
||||
func (*updateReposConfigurer) Configure(c *config.Config, rel string, f *rule.File) {}
|
||||
|
||||
func updateRepos(args []string) error {
|
||||
cexts := make([]config.Configurer, 0, 2)
|
||||
func updateRepos(args []string) (err error) {
|
||||
// Build configuration with all languages.
|
||||
cexts := make([]config.Configurer, 0, len(languages)+2)
|
||||
cexts = append(cexts, &config.CommonConfigurer{}, &updateReposConfigurer{})
|
||||
kinds := make(map[string]rule.KindInfo)
|
||||
loads := []rule.LoadInfo{}
|
||||
for _, lang := range languages {
|
||||
cexts = append(cexts, lang)
|
||||
loads = append(loads, lang.Loads()...)
|
||||
for kind, info := range lang.Kinds() {
|
||||
kinds[kind] = info
|
||||
|
|
@ -139,43 +134,140 @@ func updateRepos(args []string) error {
|
|||
}
|
||||
uc := getUpdateReposConfig(c)
|
||||
|
||||
path := filepath.Join(c.RepoRoot, "WORKSPACE")
|
||||
workspace, err := rule.LoadWorkspaceFile(path, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading %q: %v", path, err)
|
||||
// TODO(jayconrod): move Go-specific RemoteCache logic to language/go.
|
||||
var knownRepos []repo.Repo
|
||||
for _, r := range c.Repos {
|
||||
if r.Kind() == "go_repository" {
|
||||
knownRepos = append(knownRepos, repo.Repo{
|
||||
Name: r.Name(),
|
||||
GoPrefix: r.AttrString("importpath"),
|
||||
Remote: r.AttrString("remote"),
|
||||
VCS: r.AttrString("vcs"),
|
||||
})
|
||||
}
|
||||
}
|
||||
var destFile *rule.File
|
||||
if uc.macroFileName == "" {
|
||||
destFile = workspace
|
||||
rc, cleanup := repo.NewRemoteCache(knownRepos)
|
||||
defer func() {
|
||||
if cerr := cleanup(); err == nil && cerr != nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
|
||||
// Fix the workspace file with each language.
|
||||
for _, lang := range languages {
|
||||
lang.Fix(c, uc.workspace)
|
||||
}
|
||||
|
||||
// Generate rules from command language arguments or by importing a file.
|
||||
var gen, empty []*rule.Rule
|
||||
if uc.repoFilePath == "" {
|
||||
gen, err = updateRepoImports(c, rc)
|
||||
} else {
|
||||
macroPath := filepath.Join(c.RepoRoot, filepath.Clean(uc.macroFileName))
|
||||
if _, err = os.Stat(macroPath); os.IsNotExist(err) {
|
||||
destFile, err = rule.EmptyMacroFile(macroPath, "", uc.macroDefName)
|
||||
} else {
|
||||
destFile, err = rule.LoadMacroFile(macroPath, "", uc.macroDefName)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading %q: %v", macroPath, err)
|
||||
}
|
||||
gen, empty, err = importRepos(c, rc)
|
||||
}
|
||||
|
||||
merger.FixWorkspace(workspace)
|
||||
|
||||
files, err := uc.fn(uc, workspace, destFile, kinds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
|
||||
// Organize generated and empty rules by file. A rule should go into the file
|
||||
// it came from (by name). New rules should go into WORKSPACE or the file
|
||||
// specified with -to_macro.
|
||||
var newGen []*rule.Rule
|
||||
genForFiles := make(map[*rule.File][]*rule.Rule)
|
||||
emptyForFiles := make(map[*rule.File][]*rule.Rule)
|
||||
for _, r := range gen {
|
||||
f := uc.repoFileMap[r.Name()]
|
||||
if f != nil {
|
||||
genForFiles[f] = append(genForFiles[f], r)
|
||||
} else {
|
||||
newGen = append(newGen, r)
|
||||
}
|
||||
}
|
||||
for _, r := range empty {
|
||||
f := uc.repoFileMap[r.Name()]
|
||||
if f == nil {
|
||||
panic(fmt.Sprintf("empty rule %q for deletion that was not found", r.Name()))
|
||||
}
|
||||
emptyForFiles[f] = append(emptyForFiles[f], r)
|
||||
}
|
||||
|
||||
var newGenFile *rule.File
|
||||
var macroPath string
|
||||
if uc.macroFileName != "" {
|
||||
macroPath = filepath.Join(c.RepoRoot, filepath.Clean(uc.macroFileName))
|
||||
}
|
||||
for f := range genForFiles {
|
||||
if macroPath == "" && filepath.Base(f.Path) == "WORKSPACE" ||
|
||||
macroPath != "" && f.Path == macroPath && f.DefName == uc.macroDefName {
|
||||
newGenFile = f
|
||||
break
|
||||
}
|
||||
}
|
||||
if newGenFile == nil {
|
||||
if uc.macroFileName == "" {
|
||||
newGenFile = uc.workspace
|
||||
} else {
|
||||
var err error
|
||||
newGenFile, err = rule.LoadMacroFile(macroPath, "", uc.macroDefName)
|
||||
if os.IsNotExist(err) {
|
||||
newGenFile, err = rule.EmptyMacroFile(macroPath, "", uc.macroDefName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating %q: %v", macroPath, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("error loading %q: %v", macroPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
genForFiles[newGenFile] = append(genForFiles[newGenFile], newGen...)
|
||||
|
||||
// Merge rules and fix loads in each file.
|
||||
seenFile := make(map[*rule.File]bool)
|
||||
sortedFiles := make([]*rule.File, 0, len(genForFiles))
|
||||
for f := range genForFiles {
|
||||
if !seenFile[f] {
|
||||
seenFile[f] = true
|
||||
sortedFiles = append(sortedFiles, f)
|
||||
}
|
||||
}
|
||||
for f := range emptyForFiles {
|
||||
if !seenFile[f] {
|
||||
seenFile[f] = true
|
||||
sortedFiles = append(sortedFiles, f)
|
||||
}
|
||||
}
|
||||
sort.Slice(sortedFiles, func(i, j int) bool {
|
||||
if cmp := strings.Compare(sortedFiles[i].Path, sortedFiles[j].Path); cmp != 0 {
|
||||
return cmp < 0
|
||||
}
|
||||
return sortedFiles[i].DefName < sortedFiles[j].DefName
|
||||
})
|
||||
|
||||
updatedFiles := make(map[string]*rule.File)
|
||||
for _, f := range sortedFiles {
|
||||
merger.MergeFile(f, emptyForFiles[f], genForFiles[f], merger.PreResolve, kinds)
|
||||
merger.FixLoads(f, loads)
|
||||
if f.Path == workspace.Path {
|
||||
if err := merger.CheckGazelleLoaded(workspace); err != nil {
|
||||
if f == uc.workspace {
|
||||
if err := merger.CheckGazelleLoaded(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := f.Save(f.Path); err != nil {
|
||||
return err
|
||||
f.Sync()
|
||||
if uf, ok := updatedFiles[f.Path]; ok {
|
||||
uf.SyncMacroFile(f)
|
||||
} else {
|
||||
updatedFiles[f.Path] = f
|
||||
}
|
||||
}
|
||||
for _, f := range sortedFiles {
|
||||
if uf := updatedFiles[f.Path]; uf != nil {
|
||||
if err := uf.Save(uf.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
delete(updatedFiles, f.Path)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -224,80 +316,53 @@ FLAGS:
|
|||
fs.PrintDefaults()
|
||||
}
|
||||
|
||||
func updateImportPaths(c *updateReposConfig, workspace *rule.File, destFile *rule.File, kinds map[string]rule.KindInfo) ([]*rule.File, error) {
|
||||
repos, reposByFile, err := repo.ListRepositories(workspace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc, cleanupRc := repo.NewRemoteCache(repos)
|
||||
defer cleanupRc()
|
||||
|
||||
genRules := make([]*rule.Rule, len(c.importPaths))
|
||||
errs := make([]error, len(c.importPaths))
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(c.importPaths))
|
||||
for i, imp := range c.importPaths {
|
||||
go func(i int, imp string) {
|
||||
defer wg.Done()
|
||||
r, err := repo.UpdateRepo(rc, imp)
|
||||
if err != nil {
|
||||
errs[i] = err
|
||||
return
|
||||
}
|
||||
r.Remote = "" // don't set these explicitly
|
||||
r.VCS = ""
|
||||
rule := repo.GenerateRule(r)
|
||||
applyBuildAttributes(c, rule)
|
||||
genRules[i] = rule
|
||||
}(i, imp)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func updateRepoImports(c *config.Config, rc *repo.RemoteCache) (gen []*rule.Rule, err error) {
|
||||
// TODO(jayconrod): let the user pick the language with a command line flag.
|
||||
// For now, only use the first language that implements the interface.
|
||||
uc := getUpdateReposConfig(c)
|
||||
var updater language.RepoUpdater
|
||||
for _, lang := range languages {
|
||||
if u, ok := lang.(language.RepoUpdater); ok {
|
||||
updater = u
|
||||
break
|
||||
}
|
||||
}
|
||||
files := repo.MergeRules(genRules, reposByFile, destFile, kinds, false)
|
||||
return files, nil
|
||||
if updater == nil {
|
||||
return nil, fmt.Errorf("no languages can update repositories")
|
||||
}
|
||||
res := updater.UpdateRepos(language.UpdateReposArgs{
|
||||
Config: c,
|
||||
Imports: uc.importPaths,
|
||||
Cache: rc,
|
||||
})
|
||||
return res.Gen, res.Error
|
||||
}
|
||||
|
||||
func importFromLockFile(c *updateReposConfig, workspace *rule.File, destFile *rule.File, kinds map[string]rule.KindInfo) ([]*rule.File, error) {
|
||||
repos, reposByFile, err := repo.ListRepositories(workspace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func importRepos(c *config.Config, rc *repo.RemoteCache) (gen, empty []*rule.Rule, err error) {
|
||||
uc := getUpdateReposConfig(c)
|
||||
importSupported := false
|
||||
var importer language.RepoImporter
|
||||
for _, lang := range languages {
|
||||
if i, ok := lang.(language.RepoImporter); ok {
|
||||
importSupported = true
|
||||
if i.CanImport(uc.repoFilePath) {
|
||||
importer = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
rc, cleanupRc := repo.NewRemoteCache(repos)
|
||||
defer cleanupRc()
|
||||
genRules, err := repo.ImportRepoRules(c.lockFilename, rc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range genRules {
|
||||
applyBuildAttributes(c, genRules[i])
|
||||
}
|
||||
files := repo.MergeRules(genRules, reposByFile, destFile, kinds, c.pruneRules)
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func applyBuildAttributes(c *updateReposConfig, r *rule.Rule) {
|
||||
if c.buildExternalAttr != "" {
|
||||
r.SetAttr("build_external", c.buildExternalAttr)
|
||||
}
|
||||
if c.buildFileNamesAttr != "" {
|
||||
r.SetAttr("build_file_name", c.buildFileNamesAttr)
|
||||
}
|
||||
if c.buildFileGenerationAttr != "" {
|
||||
r.SetAttr("build_file_generation", c.buildFileGenerationAttr)
|
||||
}
|
||||
if c.buildTagsAttr != "" {
|
||||
r.SetAttr("build_tags", c.buildTagsAttr)
|
||||
}
|
||||
if c.buildFileProtoModeAttr != "" {
|
||||
r.SetAttr("build_file_proto_mode", c.buildFileProtoModeAttr)
|
||||
}
|
||||
if c.buildExtraArgsAttr != "" {
|
||||
extraArgs := strings.Split(c.buildExtraArgsAttr, ",")
|
||||
r.SetAttr("build_extra_args", extraArgs)
|
||||
if importer == nil {
|
||||
if importSupported {
|
||||
return nil, nil, fmt.Errorf("unknown file format: %s", uc.repoFilePath)
|
||||
} else {
|
||||
return nil, nil, fmt.Errorf("no supported languages can import configuration files")
|
||||
}
|
||||
}
|
||||
res := importer.ImportRepos(language.ImportReposArgs{
|
||||
Config: c,
|
||||
Path: uc.repoFilePath,
|
||||
Prune: uc.pruneRules,
|
||||
Cache: rc,
|
||||
})
|
||||
return res.Gen, res.Empty, res.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,11 @@ type Config struct {
|
|||
// # gazelle:map_kind.
|
||||
KindMap map[string]MappedKind
|
||||
|
||||
// Repos is a list of repository rules declared in the main WORKSPACE file
|
||||
// or in macros called by the main WORKSPACE file. This may affect rule
|
||||
// generation and dependency resolution.
|
||||
Repos []*rule.Rule
|
||||
|
||||
// Exts is a set of configurable extensions. Generally, each language
|
||||
// has its own set of extensions, but other modules may provide their own
|
||||
// extensions as well. Values in here may be populated by command line
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["lang.go"],
|
||||
srcs = [
|
||||
"lang.go",
|
||||
"update.go",
|
||||
],
|
||||
importmap = "k8s.io/kops/vendor/github.com/bazelbuild/bazel-gazelle/language",
|
||||
importpath = "github.com/bazelbuild/bazel-gazelle/language",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/config:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/repo:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/resolve:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/rule:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -5,16 +5,20 @@ go_library(
|
|||
srcs = [
|
||||
"config.go",
|
||||
"constants.go",
|
||||
"dep.go",
|
||||
"fileinfo.go",
|
||||
"fix.go",
|
||||
"generate.go",
|
||||
"godep.go",
|
||||
"kinds.go",
|
||||
"known_go_imports.go",
|
||||
"known_proto_imports.go",
|
||||
"lang.go",
|
||||
"modules.go",
|
||||
"package.go",
|
||||
"resolve.go",
|
||||
"std_package_list.go",
|
||||
"update.go",
|
||||
],
|
||||
importmap = "k8s.io/kops/vendor/github.com/bazelbuild/bazel-gazelle/language/go",
|
||||
importpath = "github.com/bazelbuild/bazel-gazelle/language/go",
|
||||
|
|
@ -30,5 +34,7 @@ go_library(
|
|||
"//vendor/github.com/bazelbuild/bazel-gazelle/resolve:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/rule:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/buildtools/build:go_default_library",
|
||||
"//vendor/github.com/pelletier/go-toml:go_default_library",
|
||||
"//vendor/golang.org/x/sync/errgroup:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -78,11 +78,26 @@ type goConfig struct {
|
|||
// In this mode, we won't go out to the network to resolve external deps.
|
||||
goRepositoryMode bool
|
||||
|
||||
// By default, internal packages are only visible to its siblings.
|
||||
// goVisibility adds a list of packages the internal packages should be
|
||||
// visible to
|
||||
goVisibility []string
|
||||
|
||||
// moduleMode is true if the current directory is intended to be built
|
||||
// as part of a module. Minimal module compatibility won't be supported
|
||||
// if this is true in the root directory. External dependencies may be
|
||||
// resolved differently (also depending on goRepositoryMode).
|
||||
moduleMode bool
|
||||
|
||||
// submodules is a list of modules which have the current module's path
|
||||
// as a prefix of their own path. This affects visibility attributes
|
||||
// in internal packages.
|
||||
submodules []moduleRepo
|
||||
|
||||
// buildExternalAttr, buildFileNamesAttr, buildFileGenerationAttr,
|
||||
// buildTagsAttr, buildFileProtoModeAttr, and buildExtraArgsAttr are
|
||||
// attributes for go_repository rules, set on the command line.
|
||||
buildExternalAttr, buildFileNamesAttr, buildFileGenerationAttr, buildTagsAttr, buildFileProtoModeAttr, buildExtraArgsAttr string
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -109,6 +124,9 @@ func (gc *goConfig) clone() *goConfig {
|
|||
for k, v := range gc.genericTags {
|
||||
gcCopy.genericTags[k] = v
|
||||
}
|
||||
gcCopy.goProtoCompilers = gc.goProtoCompilers[:len(gc.goProtoCompilers):len(gc.goProtoCompilers)]
|
||||
gcCopy.goGrpcCompilers = gc.goGrpcCompilers[:len(gc.goGrpcCompilers):len(gc.goGrpcCompilers)]
|
||||
gcCopy.submodules = gc.submodules[:len(gc.submodules):len(gc.submodules)]
|
||||
return &gcCopy
|
||||
}
|
||||
|
||||
|
|
@ -200,17 +218,26 @@ func (f tagsFlag) String() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (_ *goLang) KnownDirectives() []string {
|
||||
type moduleRepo struct {
|
||||
repoName, modulePath string
|
||||
}
|
||||
|
||||
var validBuildExternalAttr = []string{"external", "vendored"}
|
||||
var validBuildFileGenerationAttr = []string{"auto", "on", "off"}
|
||||
var validBuildFileProtoModeAttr = []string{"default", "legacy", "disable", "disable_global", "package"}
|
||||
|
||||
func (*goLang) KnownDirectives() []string {
|
||||
return []string{
|
||||
"build_tags",
|
||||
"go_grpc_compilers",
|
||||
"go_proto_compilers",
|
||||
"go_visibility",
|
||||
"importmap_prefix",
|
||||
"prefix",
|
||||
}
|
||||
}
|
||||
|
||||
func (_ *goLang) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {
|
||||
func (*goLang) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {
|
||||
gc := newGoConfig()
|
||||
switch cmd {
|
||||
case "fix", "update":
|
||||
|
|
@ -244,11 +271,34 @@ func (_ *goLang) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {
|
|||
"go_repository_module_mode",
|
||||
false,
|
||||
"set when gazelle is invoked by go_repository in module mode")
|
||||
|
||||
case "update-repos":
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &gc.buildExternalAttr, Allowed: validBuildExternalAttr},
|
||||
"build_external",
|
||||
"Sets the build_external attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&gc.buildExtraArgsAttr,
|
||||
"build_extra_args",
|
||||
"",
|
||||
"Sets the build_extra_args attribute for the generated go_repository rule(s).")
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &gc.buildFileGenerationAttr, Allowed: validBuildFileGenerationAttr},
|
||||
"build_file_generation",
|
||||
"Sets the build_file_generation attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&gc.buildFileNamesAttr,
|
||||
"build_file_names",
|
||||
"",
|
||||
"Sets the build_file_name attribute for the generated go_repository rule(s).")
|
||||
fs.Var(&gzflag.AllowedStringFlag{Value: &gc.buildFileProtoModeAttr, Allowed: validBuildFileProtoModeAttr},
|
||||
"build_file_proto_mode",
|
||||
"Sets the build_file_proto_mode attribute for the generated go_repository rule(s).")
|
||||
fs.StringVar(&gc.buildTagsAttr,
|
||||
"build_tags",
|
||||
"",
|
||||
"Sets the build_tags attribute for the generated go_repository rule(s).")
|
||||
}
|
||||
c.Exts[goName] = gc
|
||||
}
|
||||
|
||||
func (_ *goLang) CheckFlags(fs *flag.FlagSet, c *config.Config) error {
|
||||
func (*goLang) CheckFlags(fs *flag.FlagSet, c *config.Config) error {
|
||||
// The base of the -go_prefix flag may be used to generate proto_library
|
||||
// rule names when there are no .proto sources (empty rules to be deleted)
|
||||
// or when the package name can't be determined.
|
||||
|
|
@ -257,10 +307,27 @@ func (_ *goLang) CheckFlags(fs *flag.FlagSet, c *config.Config) error {
|
|||
if pc := proto.GetProtoConfig(c); pc != nil {
|
||||
pc.GoPrefix = gc.prefix
|
||||
}
|
||||
|
||||
// List modules that may refer to internal packages in this module.
|
||||
for _, r := range c.Repos {
|
||||
if r.Kind() != "go_repository" {
|
||||
continue
|
||||
}
|
||||
modulePath := r.AttrString("importpath")
|
||||
if !strings.HasPrefix(modulePath, gc.prefix+"/") {
|
||||
continue
|
||||
}
|
||||
m := moduleRepo{
|
||||
repoName: r.Name(),
|
||||
modulePath: modulePath,
|
||||
}
|
||||
gc.submodules = append(gc.submodules, m)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *goLang) Configure(c *config.Config, rel string, f *rule.File) {
|
||||
func (*goLang) Configure(c *config.Config, rel string, f *rule.File) {
|
||||
var gc *goConfig
|
||||
if raw, ok := c.Exts[goName]; !ok {
|
||||
gc = newGoConfig()
|
||||
|
|
@ -302,6 +369,7 @@ func (_ *goLang) Configure(c *config.Config, rel string, f *rule.File) {
|
|||
}
|
||||
gc.preprocessTags()
|
||||
gc.setBuildTags(d.Value)
|
||||
|
||||
case "go_grpc_compilers":
|
||||
// Special syntax (empty value) to reset directive.
|
||||
if d.Value == "" {
|
||||
|
|
@ -311,6 +379,7 @@ func (_ *goLang) Configure(c *config.Config, rel string, f *rule.File) {
|
|||
gc.goGrpcCompilersSet = true
|
||||
gc.goGrpcCompilers = splitValue(d.Value)
|
||||
}
|
||||
|
||||
case "go_proto_compilers":
|
||||
// Special syntax (empty value) to reset directive.
|
||||
if d.Value == "" {
|
||||
|
|
@ -320,9 +389,14 @@ func (_ *goLang) Configure(c *config.Config, rel string, f *rule.File) {
|
|||
gc.goProtoCompilersSet = true
|
||||
gc.goProtoCompilers = splitValue(d.Value)
|
||||
}
|
||||
|
||||
case "go_visibility":
|
||||
gc.goVisibility = append(gc.goVisibility, strings.TrimSpace(d.Value))
|
||||
|
||||
case "importmap_prefix":
|
||||
gc.importMapPrefix = d.Value
|
||||
gc.importMapPrefixRel = rel
|
||||
|
||||
case "prefix":
|
||||
setPrefix(d.Value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,15 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package repo
|
||||
package golang
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"sort"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/label"
|
||||
"github.com/bazelbuild/bazel-gazelle/language"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
toml "github.com/pelletier/go-toml"
|
||||
)
|
||||
|
||||
|
|
@ -32,34 +35,34 @@ type depProject struct {
|
|||
Source string `toml:"source"`
|
||||
}
|
||||
|
||||
func importRepoRulesDep(filename string, _ *RemoteCache) ([]Repo, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
func importReposFromDep(args language.ImportReposArgs) language.ImportReposResult {
|
||||
data, err := ioutil.ReadFile(args.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
var file depLockFile
|
||||
if err := toml.Unmarshal(data, &file); err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
|
||||
var repos []Repo
|
||||
for _, p := range file.Projects {
|
||||
var vcs string
|
||||
gen := make([]*rule.Rule, len(file.Projects))
|
||||
for i, p := range file.Projects {
|
||||
gen[i] = rule.NewRule("go_repository", label.ImportPathToBazelRepoName(p.Name))
|
||||
gen[i].SetAttr("importpath", p.Name)
|
||||
gen[i].SetAttr("commit", p.Revision)
|
||||
if p.Source != "" {
|
||||
// TODO(#411): Handle source directives correctly. It may be an import
|
||||
// path, or a URL. In the case of an import path, we should resolve it
|
||||
// to the correct remote and vcs. In the case of a URL, we should
|
||||
// correctly determine what VCS to use (the URL will usually start
|
||||
// with "https://", which is used by multiple VCSs).
|
||||
vcs = "git"
|
||||
gen[i].SetAttr("remote", p.Source)
|
||||
gen[i].SetAttr("vcs", "git")
|
||||
}
|
||||
repos = append(repos, Repo{
|
||||
Name: label.ImportPathToBazelRepoName(p.Name),
|
||||
GoPrefix: p.Name,
|
||||
Commit: p.Revision,
|
||||
Remote: p.Source,
|
||||
VCS: vcs,
|
||||
})
|
||||
}
|
||||
return repos, nil
|
||||
sort.SliceStable(gen, func(i, j int) bool {
|
||||
return gen[i].Name() < gen[j].Name()
|
||||
})
|
||||
|
||||
return language.ImportReposResult{Gen: gen}
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ func (g tagGroup) check(c *config.Config, os, arch string) bool {
|
|||
if os == "" {
|
||||
return false
|
||||
}
|
||||
match = os == t
|
||||
match = matchesOS(os, t)
|
||||
} else if _, ok := rule.KnownArchSet[t]; ok {
|
||||
if arch == "" {
|
||||
return false
|
||||
|
|
@ -594,6 +594,20 @@ func isOSArchSpecific(info fileInfo, cgoTags tagLine) (osSpecific, archSpecific
|
|||
return osSpecific, archSpecific
|
||||
}
|
||||
|
||||
// matchesOS checks if a value is equal to either an OS value or to any of its
|
||||
// aliases.
|
||||
func matchesOS(os, value string) bool {
|
||||
if os == value {
|
||||
return true
|
||||
}
|
||||
for _, alias := range rule.OSAliases[os] {
|
||||
if alias == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// checkConstraints determines whether build constraints are satisfied on
|
||||
// a given platform.
|
||||
//
|
||||
|
|
@ -608,7 +622,7 @@ func isOSArchSpecific(info fileInfo, cgoTags tagLine) (osSpecific, archSpecific
|
|||
// is a list tags from +build comments found near the top of the file. cgoTags
|
||||
// is an extra set of tags in a #cgo directive.
|
||||
func checkConstraints(c *config.Config, os, arch, osSuffix, archSuffix string, fileTags []tagLine, cgoTags tagLine) bool {
|
||||
if osSuffix != "" && osSuffix != os || archSuffix != "" && archSuffix != arch {
|
||||
if osSuffix != "" && !matchesOS(os, osSuffix) || archSuffix != "" && archSuffix != arch {
|
||||
return false
|
||||
}
|
||||
for _, l := range fileTags {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
package golang
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"log"
|
||||
"path"
|
||||
|
|
@ -229,8 +230,18 @@ func (gl *goLang) GenerateRules(args language.GenerateArgs) language.GenerateRes
|
|||
for _, f := range regularFiles {
|
||||
regularFileSet[f] = true
|
||||
}
|
||||
// Some of the generated files may have been consumed by other rules
|
||||
consumedFileSet := make(map[string]bool)
|
||||
for _, r := range args.OtherGen {
|
||||
for _, f := range r.AttrStrings("srcs") {
|
||||
consumedFileSet[f] = true
|
||||
}
|
||||
if f := r.AttrString("src"); f != "" {
|
||||
consumedFileSet[f] = true
|
||||
}
|
||||
}
|
||||
for _, f := range genFiles {
|
||||
if regularFileSet[f] {
|
||||
if regularFileSet[f] || consumedFileSet[f] {
|
||||
continue
|
||||
}
|
||||
info := fileNameInfo(filepath.Join(args.Dir, f))
|
||||
|
|
@ -396,7 +407,7 @@ func (g *generator) generateProto(mode proto.Mode, target protoTarget, importPat
|
|||
protoName = proto.RuleName(importPath)
|
||||
}
|
||||
goProtoName := strings.TrimSuffix(protoName, "_proto") + "_go_proto"
|
||||
visibility := []string{rule.CheckInternalVisibility(g.rel, "//visibility:public")}
|
||||
visibility := g.commonVisibility(importPath)
|
||||
|
||||
if mode == proto.LegacyMode {
|
||||
filegroup := rule.NewRule("filegroup", filegroupName)
|
||||
|
|
@ -437,12 +448,12 @@ func (g *generator) generateLib(pkg *goPackage, embed string) *rule.Rule {
|
|||
if !pkg.library.sources.hasGo() && embed == "" {
|
||||
return goLibrary // empty
|
||||
}
|
||||
var visibility string
|
||||
var visibility []string
|
||||
if pkg.isCommand() {
|
||||
// Libraries made for a go_binary should not be exposed to the public.
|
||||
visibility = "//visibility:private"
|
||||
visibility = []string{"//visibility:private"}
|
||||
} else {
|
||||
visibility = rule.CheckInternalVisibility(pkg.rel, "//visibility:public")
|
||||
visibility = g.commonVisibility(pkg.importPath)
|
||||
}
|
||||
g.setCommonAttrs(goLibrary, pkg.rel, visibility, pkg.library, embed)
|
||||
g.setImportAttrs(goLibrary, pkg.importPath)
|
||||
|
|
@ -455,7 +466,7 @@ func (g *generator) generateBin(pkg *goPackage, library string) *rule.Rule {
|
|||
if !pkg.isCommand() || pkg.binary.sources.isEmpty() && library == "" {
|
||||
return goBinary // empty
|
||||
}
|
||||
visibility := rule.CheckInternalVisibility(pkg.rel, "//visibility:public")
|
||||
visibility := g.commonVisibility(pkg.importPath)
|
||||
g.setCommonAttrs(goBinary, pkg.rel, visibility, pkg.binary, library)
|
||||
return goBinary
|
||||
}
|
||||
|
|
@ -465,14 +476,14 @@ func (g *generator) generateTest(pkg *goPackage, library string) *rule.Rule {
|
|||
if !pkg.test.sources.hasGo() {
|
||||
return goTest // empty
|
||||
}
|
||||
g.setCommonAttrs(goTest, pkg.rel, "", pkg.test, library)
|
||||
g.setCommonAttrs(goTest, pkg.rel, nil, pkg.test, library)
|
||||
if pkg.hasTestdata {
|
||||
goTest.SetAttr("data", rule.GlobValue{Patterns: []string{"testdata/**"}})
|
||||
}
|
||||
return goTest
|
||||
}
|
||||
|
||||
func (g *generator) setCommonAttrs(r *rule.Rule, pkgRel, visibility string, target goTarget, embed string) {
|
||||
func (g *generator) setCommonAttrs(r *rule.Rule, pkgRel string, visibility []string, target goTarget, embed string) {
|
||||
if !target.sources.isEmpty() {
|
||||
r.SetAttr("srcs", target.sources.buildFlat())
|
||||
}
|
||||
|
|
@ -485,8 +496,8 @@ func (g *generator) setCommonAttrs(r *rule.Rule, pkgRel, visibility string, targ
|
|||
if !target.copts.isEmpty() {
|
||||
r.SetAttr("copts", g.options(target.copts.build(), pkgRel))
|
||||
}
|
||||
if g.shouldSetVisibility && visibility != "" {
|
||||
r.SetAttr("visibility", []string{visibility})
|
||||
if g.shouldSetVisibility && len(visibility) > 0 {
|
||||
r.SetAttr("visibility", visibility)
|
||||
}
|
||||
if embed != "" {
|
||||
r.SetAttr("embed", []string{":" + embed})
|
||||
|
|
@ -517,6 +528,38 @@ func (g *generator) setImportAttrs(r *rule.Rule, importPath string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *generator) commonVisibility(importPath string) []string {
|
||||
// If the Bazel package name (rel) contains "internal", add visibility for
|
||||
// subpackages of the parent.
|
||||
// If the import path contains "internal" but rel does not, this is
|
||||
// probably an internal submodule. Add visibility for all subpackages.
|
||||
relIndex := pathtools.Index(g.rel, "internal")
|
||||
importIndex := pathtools.Index(importPath, "internal")
|
||||
visibility := getGoConfig(g.c).goVisibility
|
||||
if relIndex >= 0 {
|
||||
parent := strings.TrimSuffix(g.rel[:relIndex], "/")
|
||||
visibility = append(visibility, fmt.Sprintf("//%s:__subpackages__", parent))
|
||||
} else if importIndex >= 0 {
|
||||
visibility = append(visibility, "//:__subpackages__")
|
||||
} else {
|
||||
return []string{"//visibility:public"}
|
||||
}
|
||||
|
||||
// Add visibility for any submodules that have the internal parent as
|
||||
// a prefix of their module path.
|
||||
if importIndex >= 0 {
|
||||
gc := getGoConfig(g.c)
|
||||
internalRoot := strings.TrimSuffix(importPath[:importIndex], "/")
|
||||
for _, m := range gc.submodules {
|
||||
if strings.HasPrefix(m.modulePath, internalRoot) {
|
||||
visibility = append(visibility, fmt.Sprintf("@%s//:__subpackages__", m.repoName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return visibility
|
||||
}
|
||||
|
||||
var (
|
||||
// shortOptPrefixes are strings that come at the beginning of an option
|
||||
// argument that includes a path, e.g., -Ifoo/bar.
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package repo
|
||||
package golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/label"
|
||||
"github.com/bazelbuild/bazel-gazelle/language"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type goDepLockFile struct {
|
||||
|
|
@ -37,60 +39,50 @@ type goDepProject struct {
|
|||
Rev string
|
||||
}
|
||||
|
||||
func importRepoRulesGoDep(filename string, cache *RemoteCache) ([]Repo, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
func importReposFromGodep(args language.ImportReposArgs) language.ImportReposResult {
|
||||
data, err := ioutil.ReadFile(args.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
|
||||
file := goDepLockFile{}
|
||||
|
||||
if err := json.Unmarshal(data, &file); err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var eg errgroup.Group
|
||||
roots := make([]string, len(file.Deps))
|
||||
errs := make([]error, len(file.Deps))
|
||||
|
||||
wg.Add(len(file.Deps))
|
||||
for i, p := range file.Deps {
|
||||
go func(i int, p goDepProject) {
|
||||
defer wg.Done()
|
||||
rootRepo, _, err := cache.Root(p.ImportPath)
|
||||
for i := range file.Deps {
|
||||
i := i
|
||||
eg.Go(func() error {
|
||||
p := file.Deps[i]
|
||||
repoRoot, _, err := args.Cache.Root(p.ImportPath)
|
||||
if err != nil {
|
||||
errs[i] = err
|
||||
} else {
|
||||
roots[i] = rootRepo
|
||||
return err
|
||||
}
|
||||
}(i, p)
|
||||
roots[i] = repoRoot
|
||||
return nil
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
var repos []Repo
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := eg.Wait(); err != nil {
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
|
||||
gen := make([]*rule.Rule, 0, len(file.Deps))
|
||||
repoToRev := make(map[string]string)
|
||||
|
||||
for i, p := range file.Deps {
|
||||
repoRoot := roots[i]
|
||||
if rev, ok := repoToRev[repoRoot]; !ok {
|
||||
repos = append(repos, Repo{
|
||||
Name: label.ImportPathToBazelRepoName(repoRoot),
|
||||
GoPrefix: repoRoot,
|
||||
Commit: p.Rev,
|
||||
})
|
||||
r := rule.NewRule("go_repository", label.ImportPathToBazelRepoName(repoRoot))
|
||||
r.SetAttr("importpath", repoRoot)
|
||||
r.SetAttr("commit", p.Rev)
|
||||
repoToRev[repoRoot] = p.Rev
|
||||
gen = append(gen, r)
|
||||
} else {
|
||||
if p.Rev != rev {
|
||||
return nil, fmt.Errorf("Repo %s imported at multiple revisions: %s, %s", repoRoot, p.Rev, rev)
|
||||
return language.ImportReposResult{Error: fmt.Errorf("repo %s imported at multiple revisions: %s, %s", repoRoot, p.Rev, rev)}
|
||||
}
|
||||
}
|
||||
}
|
||||
return repos, nil
|
||||
return language.ImportReposResult{Gen: gen}
|
||||
}
|
||||
|
|
@ -33,11 +33,11 @@ var knownGoProtoImports = map[string]label.Label{
|
|||
"google.golang.org/genproto/googleapis/api/serviceconfig": label.New("go_googleapis", "google/api", "serviceconfig_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/configchange": label.New("go_googleapis", "google/api", "configchange_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/distribution": label.New("go_googleapis", "google/api", "distribution_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api": label.New("go_googleapis", "google/api", "api_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/expr/v1alpha1": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/expr/v1beta1": label.New("go_googleapis", "google/api/expr/v1beta1", "expr_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/httpbody": label.New("go_googleapis", "google/api", "httpbody_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/label": label.New("go_googleapis", "google/api", "label_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api": label.New("go_googleapis", "google/api", "api_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/metric": label.New("go_googleapis", "google/api", "metric_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/monitoredres": label.New("go_googleapis", "google/api", "monitoredres_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/api/servicecontrol/v1": label.New("go_googleapis", "google/api/servicecontrol/v1", "servicecontrol_go_proto"),
|
||||
|
|
@ -55,7 +55,9 @@ var knownGoProtoImports = map[string]label.Label{
|
|||
"google.golang.org/genproto/googleapis/bytestream": label.New("go_googleapis", "google/bytestream", "bytestream_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/asset/v1": label.New("go_googleapis", "google/cloud/asset/v1", "asset_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/asset/v1beta1": label.New("go_googleapis", "google/cloud/asset/v1beta1", "asset_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/asset/v1p2beta1": label.New("go_googleapis", "google/cloud/asset/v1p2beta1", "asset_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/audit": label.New("go_googleapis", "google/cloud/audit", "audit_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/automl/v1": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/automl/v1beta1": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/bigquery/datatransfer/v1": label.New("go_googleapis", "google/cloud/bigquery/datatransfer/v1", "datatransfer_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/bigquery/logging/v1": label.New("go_googleapis", "google/cloud/bigquery/logging/v1", "logging_go_proto"),
|
||||
|
|
@ -69,6 +71,7 @@ var knownGoProtoImports = map[string]label.Label{
|
|||
"google.golang.org/genproto/googleapis/cloud/dataproc/v1beta2": label.New("go_googleapis", "google/cloud/dataproc/v1beta2", "dataproc_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/dialogflow/v2": label.New("go_googleapis", "google/cloud/dialogflow/v2", "dialogflow_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/document/v1beta1": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/functions/v1beta2": label.New("go_googleapis", "google/cloud/functions/v1beta2", "functions_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/iot/v1": label.New("go_googleapis", "google/cloud/iot/v1", "iot_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/irm/v1alpha2": label.New("go_googleapis", "google/cloud/irm/v1alpha2", "irm_go_proto"),
|
||||
|
|
@ -103,6 +106,7 @@ var knownGoProtoImports = map[string]label.Label{
|
|||
"google.golang.org/genproto/googleapis/cloud/tasks/v2beta3": label.New("go_googleapis", "google/cloud/tasks/v2beta3", "tasks_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/texttospeech/v1": label.New("go_googleapis", "google/cloud/texttospeech/v1", "texttospeech_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/texttospeech/v1beta1": label.New("go_googleapis", "google/cloud/texttospeech/v1beta1", "texttospeech_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/translate/v3": label.New("go_googleapis", "google/cloud/translate/v3", "translate_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/translate/v3beta1": label.New("go_googleapis", "google/cloud/translate/v3beta1", "translate_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/videointelligence/v1": label.New("go_googleapis", "google/cloud/videointelligence/v1", "videointelligence_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/cloud/videointelligence/v1beta1": label.New("go_googleapis", "google/cloud/videointelligence/v1beta1", "videointelligence_go_proto"),
|
||||
|
|
@ -160,6 +164,7 @@ var knownGoProtoImports = map[string]label.Label{
|
|||
"google.golang.org/genproto/googleapis/firestore/v1beta1": label.New("go_googleapis", "google/firestore/v1beta1", "firestore_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/genomics/v1": label.New("go_googleapis", "google/genomics/v1", "genomics_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/genomics/v1alpha2": label.New("go_googleapis", "google/genomics/v1alpha2", "genomics_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/geo/type/viewport": label.New("go_googleapis", "google/geo/type", "viewport_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/home/graph/v1": label.New("go_googleapis", "google/home/graph/v1", "graph_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/iam/admin/v1": label.New("go_googleapis", "google/iam/admin/v1", "admin_go_proto"),
|
||||
"google.golang.org/genproto/googleapis/iam/credentials/v1": label.New("go_googleapis", "google/iam/credentials/v1", "credentials_go_proto"),
|
||||
|
|
|
|||
|
|
@ -684,10 +684,12 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/enums/google_ads_field_data_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_date_selection_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_price_bucket.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_rate_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/income_range_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/interaction_event_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/interaction_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/invoice_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/job_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/keyword_match_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/keyword_plan_competition_level.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
|
|
@ -742,6 +744,8 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/enums/promotion_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/proximity_radius_units.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/quality_score_bucket.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/reach_plan_ad_length.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/reach_plan_age_range.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/real_estate_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/recommendation_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
"google/ads/googleads/v2/enums/search_engine_results_page_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_go_proto"),
|
||||
|
|
@ -844,6 +848,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/errors/id_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/image_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/internal_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/invoice_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_ad_group_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_campaign_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
|
|
@ -873,6 +878,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/errors/query_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/quota_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/range_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/reach_plan_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/recommendation_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/region_code_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
"google/ads/googleads/v2/errors/request_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_go_proto"),
|
||||
|
|
@ -953,6 +959,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/resources/group_placement_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/hotel_group_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/hotel_performance_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/invoice.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan_ad_group.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan_campaign.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_go_proto"),
|
||||
|
|
@ -1056,6 +1063,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/services/group_placement_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/hotel_group_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/hotel_performance_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/invoice_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_ad_group_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_campaign_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_idea_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
|
|
@ -1079,6 +1087,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/services/payments_account_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/product_bidding_category_constant_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/product_group_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/reach_plan_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/recommendation_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/remarketing_action_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
"google/ads/googleads/v2/services/search_term_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_go_proto"),
|
||||
|
|
@ -1103,8 +1112,6 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/api/distribution.proto": label.New("go_googleapis", "google/api", "distribution_go_proto"),
|
||||
"google/api/documentation.proto": label.New("go_googleapis", "google/api", "serviceconfig_go_proto"),
|
||||
"google/api/endpoint.proto": label.New("go_googleapis", "google/api", "serviceconfig_go_proto"),
|
||||
"google/api/experimental/authorization_config.proto": label.New("go_googleapis", "google/api", "api_go_proto"),
|
||||
"google/api/experimental/experimental.proto": label.New("go_googleapis", "google/api", "api_go_proto"),
|
||||
"google/api/expr/v1alpha1/cel_service.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_go_proto"),
|
||||
"google/api/expr/v1alpha1/checked.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_go_proto"),
|
||||
"google/api/expr/v1alpha1/conformance_service.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_go_proto"),
|
||||
|
|
@ -1177,7 +1184,19 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/asset/v1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1", "asset_go_proto"),
|
||||
"google/cloud/asset/v1beta1/asset_service.proto": label.New("go_googleapis", "google/cloud/asset/v1beta1", "asset_go_proto"),
|
||||
"google/cloud/asset/v1beta1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1beta1", "asset_go_proto"),
|
||||
"google/cloud/asset/v1p2beta1/asset_service.proto": label.New("go_googleapis", "google/cloud/asset/v1p2beta1", "asset_go_proto"),
|
||||
"google/cloud/asset/v1p2beta1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1p2beta1", "asset_go_proto"),
|
||||
"google/cloud/audit/audit_log.proto": label.New("go_googleapis", "google/cloud/audit", "audit_go_proto"),
|
||||
"google/cloud/automl/v1/annotation_payload.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/data_items.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/dataset.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/io.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/model.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/model_evaluation.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/operations.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/prediction_service.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/service.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1/translation.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1beta1/annotation_payload.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1beta1/annotation_spec.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_go_proto"),
|
||||
"google/cloud/automl/v1beta1/classification.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_go_proto"),
|
||||
|
|
@ -1215,6 +1234,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/bigquery/storage/v1beta1/read_options.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_go_proto"),
|
||||
"google/cloud/bigquery/storage/v1beta1/storage.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_go_proto"),
|
||||
"google/cloud/bigquery/storage/v1beta1/table_reference.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_go_proto"),
|
||||
"google/cloud/bigquery/v2/encryption_config.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_go_proto"),
|
||||
"google/cloud/bigquery/v2/model.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_go_proto"),
|
||||
"google/cloud/bigquery/v2/model_reference.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_go_proto"),
|
||||
"google/cloud/bigquery/v2/standard_sql.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_go_proto"),
|
||||
|
|
@ -1222,6 +1242,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/binaryauthorization/v1beta1/resources.proto": label.New("go_googleapis", "google/cloud/binaryauthorization/v1beta1", "binaryauthorization_go_proto"),
|
||||
"google/cloud/binaryauthorization/v1beta1/service.proto": label.New("go_googleapis", "google/cloud/binaryauthorization/v1beta1", "binaryauthorization_go_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/datacatalog.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_go_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/gcs_fileset_spec.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_go_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/schema.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_go_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/search.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_go_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/table_spec.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_go_proto"),
|
||||
|
|
@ -1237,6 +1258,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/datalabeling/v1beta1/human_annotation_config.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_go_proto"),
|
||||
"google/cloud/datalabeling/v1beta1/instruction.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_go_proto"),
|
||||
"google/cloud/datalabeling/v1beta1/operations.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_go_proto"),
|
||||
"google/cloud/dataproc/v1/autoscaling_policies.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_go_proto"),
|
||||
"google/cloud/dataproc/v1/clusters.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_go_proto"),
|
||||
"google/cloud/dataproc/v1/jobs.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_go_proto"),
|
||||
"google/cloud/dataproc/v1/operations.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_go_proto"),
|
||||
|
|
@ -1261,11 +1283,16 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/dialogflow/v2beta1/context.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/document.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/entity_type.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/gcs.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/intent.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/knowledge_base.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/session.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/session_entity_type.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/validation_result.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/webhook.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_go_proto"),
|
||||
"google/cloud/document/v1beta1/document.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_go_proto"),
|
||||
"google/cloud/document/v1beta1/document_understanding.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_go_proto"),
|
||||
"google/cloud/document/v1beta1/geometry.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_go_proto"),
|
||||
"google/cloud/functions/v1beta2/functions.proto": label.New("go_googleapis", "google/cloud/functions/v1beta2", "functions_go_proto"),
|
||||
"google/cloud/functions/v1beta2/operations.proto": label.New("go_googleapis", "google/cloud/functions/v1beta2", "functions_go_proto"),
|
||||
"google/cloud/iot/v1/device_manager.proto": label.New("go_googleapis", "google/cloud/iot/v1", "iot_go_proto"),
|
||||
|
|
@ -1350,6 +1377,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/cloud/tasks/v2beta3/task.proto": label.New("go_googleapis", "google/cloud/tasks/v2beta3", "tasks_go_proto"),
|
||||
"google/cloud/texttospeech/v1/cloud_tts.proto": label.New("go_googleapis", "google/cloud/texttospeech/v1", "texttospeech_go_proto"),
|
||||
"google/cloud/texttospeech/v1beta1/cloud_tts.proto": label.New("go_googleapis", "google/cloud/texttospeech/v1beta1", "texttospeech_go_proto"),
|
||||
"google/cloud/translate/v3/translation_service.proto": label.New("go_googleapis", "google/cloud/translate/v3", "translate_go_proto"),
|
||||
"google/cloud/translate/v3beta1/translation_service.proto": label.New("go_googleapis", "google/cloud/translate/v3beta1", "translate_go_proto"),
|
||||
"google/cloud/videointelligence/v1/video_intelligence.proto": label.New("go_googleapis", "google/cloud/videointelligence/v1", "videointelligence_go_proto"),
|
||||
"google/cloud/videointelligence/v1beta1/video_intelligence.proto": label.New("go_googleapis", "google/cloud/videointelligence/v1beta1", "videointelligence_go_proto"),
|
||||
|
|
@ -1458,7 +1486,9 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/devtools/resultstore/v2/configured_target.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/coverage.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/coverage_summary.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/download_metadata.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/file.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/file_processing_error.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/file_set.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/invocation.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/resultstore_download.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
|
|
@ -1466,6 +1496,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/devtools/resultstore/v2/resultstore_upload.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/target.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/test_suite.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/resultstore/v2/upload_metadata.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_go_proto"),
|
||||
"google/devtools/source/v1/source_context.proto": label.New("go_googleapis", "google/devtools/source/v1", "source_go_proto"),
|
||||
"google/devtools/sourcerepo/v1/sourcerepo.proto": label.New("go_googleapis", "google/devtools/sourcerepo/v1", "sourcerepo_go_proto"),
|
||||
"google/example/library/v1/library.proto": label.New("go_googleapis", "google/example/library/v1", "library_go_proto"),
|
||||
|
|
@ -1505,6 +1536,7 @@ var knownProtoImports = map[string]label.Label{
|
|||
"google/genomics/v1/references.proto": label.New("go_googleapis", "google/genomics/v1", "genomics_go_proto"),
|
||||
"google/genomics/v1/variants.proto": label.New("go_googleapis", "google/genomics/v1", "genomics_go_proto"),
|
||||
"google/genomics/v1alpha2/pipelines.proto": label.New("go_googleapis", "google/genomics/v1alpha2", "genomics_go_proto"),
|
||||
"google/geo/type/viewport.proto": label.New("go_googleapis", "google/geo/type", "viewport_go_proto"),
|
||||
"google/home/graph/v1/device.proto": label.New("go_googleapis", "google/home/graph/v1", "graph_go_proto"),
|
||||
"google/home/graph/v1/homegraph.proto": label.New("go_googleapis", "google/home/graph/v1", "graph_go_proto"),
|
||||
"google/iam/admin/v1/iam.proto": label.New("go_googleapis", "google/iam/admin/v1", "admin_go_proto"),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package repo
|
||||
package golang
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -30,14 +30,16 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/label"
|
||||
"github.com/bazelbuild/bazel-gazelle/language"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
)
|
||||
|
||||
func importRepoRulesModules(filename string, _ *RemoteCache) (repos []Repo, err error) {
|
||||
func importReposFromModules(args language.ImportReposArgs) language.ImportReposResult {
|
||||
// Copy go.mod to temporary directory. We may run commands that modify it,
|
||||
// and we want to leave the original alone.
|
||||
tempDir, err := copyGoModToTemp(filename)
|
||||
tempDir, err := copyGoModToTemp(args.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
|
|
@ -54,13 +56,13 @@ func importRepoRulesModules(filename string, _ *RemoteCache) (repos []Repo, err
|
|||
pathToModule := map[string]*module{}
|
||||
data, err := goListModules(tempDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(data))
|
||||
for dec.More() {
|
||||
mod := new(module)
|
||||
if err := dec.Decode(mod); err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
if mod.Main {
|
||||
continue
|
||||
|
|
@ -71,13 +73,13 @@ func importRepoRulesModules(filename string, _ *RemoteCache) (repos []Repo, err
|
|||
mod.Replace.Path)
|
||||
continue
|
||||
}
|
||||
pathToModule[mod.Replace.Path + "@" + mod.Replace.Version] = mod
|
||||
pathToModule[mod.Replace.Path+"@"+mod.Replace.Version] = mod
|
||||
} else {
|
||||
pathToModule[mod.Path + "@" + mod.Version] = mod
|
||||
pathToModule[mod.Path+"@"+mod.Version] = mod
|
||||
}
|
||||
}
|
||||
// Load sums from go.sum. Ideally, they're all there.
|
||||
goSumPath := filepath.Join(filepath.Dir(filename), "go.sum")
|
||||
goSumPath := filepath.Join(filepath.Dir(args.Path), "go.sum")
|
||||
data, _ = ioutil.ReadFile(goSumPath)
|
||||
lines := bytes.Split(data, []byte("\n"))
|
||||
for _, line := range lines {
|
||||
|
|
@ -90,7 +92,7 @@ func importRepoRulesModules(filename string, _ *RemoteCache) (repos []Repo, err
|
|||
if strings.HasSuffix(version, "/go.mod") {
|
||||
continue
|
||||
}
|
||||
if mod, ok := pathToModule[path + "@" + version]; ok {
|
||||
if mod, ok := pathToModule[path+"@"+version]; ok {
|
||||
mod.Sum = sum
|
||||
}
|
||||
}
|
||||
|
|
@ -104,40 +106,42 @@ func importRepoRulesModules(filename string, _ *RemoteCache) (repos []Repo, err
|
|||
if len(missingSumArgs) > 0 {
|
||||
data, err := goModDownload(tempDir, missingSumArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
dec = json.NewDecoder(bytes.NewReader(data))
|
||||
for dec.More() {
|
||||
var dl module
|
||||
if err := dec.Decode(&dl); err != nil {
|
||||
return nil, err
|
||||
return language.ImportReposResult{Error: err}
|
||||
}
|
||||
if mod, ok := pathToModule[dl.Path + "@" + dl.Version]; ok {
|
||||
if mod, ok := pathToModule[dl.Path+"@"+dl.Version]; ok {
|
||||
mod.Sum = dl.Sum
|
||||
}
|
||||
}
|
||||
}
|
||||
// Translate to repo metadata.
|
||||
repos = make([]Repo, 0, len(pathToModule))
|
||||
|
||||
// Translate to repository rules.
|
||||
gen := make([]*rule.Rule, 0, len(pathToModule))
|
||||
for pathVer, mod := range pathToModule {
|
||||
if mod.Sum == "" {
|
||||
log.Printf("could not determine sum for module %s", pathVer)
|
||||
continue
|
||||
}
|
||||
repo := Repo{
|
||||
Name: label.ImportPathToBazelRepoName(mod.Path),
|
||||
GoPrefix: mod.Path,
|
||||
Version: mod.Version,
|
||||
Sum: mod.Sum,
|
||||
r := rule.NewRule("go_repository", label.ImportPathToBazelRepoName(mod.Path))
|
||||
r.SetAttr("importpath", mod.Path)
|
||||
r.SetAttr("sum", mod.Sum)
|
||||
if mod.Replace == nil {
|
||||
r.SetAttr("version", mod.Version)
|
||||
} else {
|
||||
r.SetAttr("replace", mod.Replace.Path)
|
||||
r.SetAttr("version", mod.Replace.Version)
|
||||
}
|
||||
if mod.Replace != nil {
|
||||
repo.Replace = mod.Replace.Path
|
||||
repo.Version = mod.Replace.Version
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
gen = append(gen, r)
|
||||
}
|
||||
sort.Slice(repos, func(i, j int) bool { return repos[i].Name < repos[j].Name })
|
||||
return repos, nil
|
||||
sort.Slice(gen, func(i, j int) bool {
|
||||
return gen[i].Name() < gen[j].Name()
|
||||
})
|
||||
return language.ImportReposResult{Gen: gen}
|
||||
}
|
||||
|
||||
// goListModules invokes "go list" in a directory containing a go.mod file.
|
||||
|
|
@ -67,12 +67,12 @@ func (gl *goLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.Remo
|
|||
}
|
||||
imports := importsRaw.(rule.PlatformStrings)
|
||||
r.DelAttr("deps")
|
||||
resolve := resolveGo
|
||||
resolve := ResolveGo
|
||||
if r.Kind() == "go_proto_library" {
|
||||
resolve = resolveProto
|
||||
}
|
||||
deps, errs := imports.Map(func(imp string) (string, error) {
|
||||
l, err := resolve(c, ix, rc, r, imp, from)
|
||||
l, err := resolve(c, ix, rc, imp, from)
|
||||
if err == skipImportError {
|
||||
return "", nil
|
||||
} else if err != nil {
|
||||
|
|
@ -106,7 +106,13 @@ var (
|
|||
notFoundError = errors.New("rule not found")
|
||||
)
|
||||
|
||||
func resolveGo(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, imp string, from label.Label) (label.Label, error) {
|
||||
// ResolveGo resolves a Go import path to a Bazel label, possibly using the
|
||||
// given rule index and remote cache. Some special cases may be applied to
|
||||
// known proto import paths, depending on the current proto mode.
|
||||
//
|
||||
// This may be used directly by other language extensions related to Go
|
||||
// (gomock). Gazelle calls Language.Resolve instead.
|
||||
func ResolveGo(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, imp string, from label.Label) (label.Label, error) {
|
||||
gc := getGoConfig(c)
|
||||
pcMode := getProtoMode(c)
|
||||
if build.IsLocalImport(imp) {
|
||||
|
|
@ -117,7 +123,7 @@ func resolveGo(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r
|
|||
imp = path.Join(gc.prefix, cleanRel)
|
||||
}
|
||||
|
||||
if isStandard(imp) {
|
||||
if IsStandard(imp) {
|
||||
return label.NoLabel, skipImportError
|
||||
}
|
||||
|
||||
|
|
@ -185,8 +191,8 @@ func resolveGo(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r
|
|||
}
|
||||
}
|
||||
|
||||
// isStandard returns whether a package is in the standard library.
|
||||
func isStandard(imp string) bool {
|
||||
// IsStandard returns whether a package is in the standard library.
|
||||
func IsStandard(imp string) bool {
|
||||
return stdPackages[imp]
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +292,7 @@ func resolveVendored(rc *repo.RemoteCache, imp string) (label.Label, error) {
|
|||
return label.New("", path.Join("vendor", imp), defaultLibName), nil
|
||||
}
|
||||
|
||||
func resolveProto(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, imp string, from label.Label) (label.Label, error) {
|
||||
func resolveProto(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, imp string, from label.Label) (label.Label, error) {
|
||||
pcMode := getProtoMode(c)
|
||||
|
||||
if wellKnownProtos[imp] {
|
||||
|
|
|
|||
|
|
@ -21,14 +21,27 @@ package golang
|
|||
|
||||
var stdPackages = map[string]bool{
|
||||
"archive/tar": true,
|
||||
"archive/tar/testdata": true,
|
||||
"archive/zip": true,
|
||||
"archive/zip/testdata": true,
|
||||
"bufio": true,
|
||||
"builtin": true,
|
||||
"bytes": true,
|
||||
"cmd": true,
|
||||
"cmd/addr2line": true,
|
||||
"cmd/api": true,
|
||||
"cmd/api/testdata/src/issue21181/dep": true,
|
||||
"cmd/api/testdata/src/issue21181/indirect": true,
|
||||
"cmd/api/testdata/src/issue21181/p": true,
|
||||
"cmd/api/testdata/src/issue29837/p": true,
|
||||
"cmd/api/testdata/src/pkg/p1": true,
|
||||
"cmd/api/testdata/src/pkg/p2": true,
|
||||
"cmd/api/testdata/src/pkg/p3": true,
|
||||
"cmd/asm": true,
|
||||
"cmd/asm/internal/arch": true,
|
||||
"cmd/asm/internal/asm": true,
|
||||
"cmd/asm/internal/asm/testdata": true,
|
||||
"cmd/asm/internal/asm/testdata/avx512enc": true,
|
||||
"cmd/asm/internal/flags": true,
|
||||
"cmd/asm/internal/lex": true,
|
||||
"cmd/buildid": true,
|
||||
|
|
@ -38,26 +51,41 @@ var stdPackages = map[string]bool{
|
|||
"cmd/compile/internal/arm": true,
|
||||
"cmd/compile/internal/arm64": true,
|
||||
"cmd/compile/internal/gc": true,
|
||||
"cmd/compile/internal/gc/builtin": true,
|
||||
"cmd/compile/internal/gc/testdata": true,
|
||||
"cmd/compile/internal/gc/testdata/gen": true,
|
||||
"cmd/compile/internal/gc/testdata/reproducible": true,
|
||||
"cmd/compile/internal/mips": true,
|
||||
"cmd/compile/internal/mips64": true,
|
||||
"cmd/compile/internal/ppc64": true,
|
||||
"cmd/compile/internal/s390x": true,
|
||||
"cmd/compile/internal/ssa": true,
|
||||
"cmd/compile/internal/ssa/gen": true,
|
||||
"cmd/compile/internal/ssa/testdata": true,
|
||||
"cmd/compile/internal/syntax": true,
|
||||
"cmd/compile/internal/syntax/testdata": true,
|
||||
"cmd/compile/internal/test": true,
|
||||
"cmd/compile/internal/types": true,
|
||||
"cmd/compile/internal/wasm": true,
|
||||
"cmd/compile/internal/x86": true,
|
||||
"cmd/cover": true,
|
||||
"cmd/cover/testdata": true,
|
||||
"cmd/cover/testdata/html": true,
|
||||
"cmd/dist": true,
|
||||
"cmd/doc": true,
|
||||
"cmd/doc/testdata": true,
|
||||
"cmd/doc/testdata/nested": true,
|
||||
"cmd/doc/testdata/nested/nested": true,
|
||||
"cmd/fix": true,
|
||||
"cmd/go": true,
|
||||
"cmd/go/internal/auth": true,
|
||||
"cmd/go/internal/base": true,
|
||||
"cmd/go/internal/bug": true,
|
||||
"cmd/go/internal/cache": true,
|
||||
"cmd/go/internal/cfg": true,
|
||||
"cmd/go/internal/clean": true,
|
||||
"cmd/go/internal/cmdflag": true,
|
||||
"cmd/go/internal/dirhash": true,
|
||||
"cmd/go/internal/doc": true,
|
||||
"cmd/go/internal/envcmd": true,
|
||||
"cmd/go/internal/fix": true,
|
||||
|
|
@ -65,64 +93,336 @@ var stdPackages = map[string]bool{
|
|||
"cmd/go/internal/generate": true,
|
||||
"cmd/go/internal/get": true,
|
||||
"cmd/go/internal/help": true,
|
||||
"cmd/go/internal/imports": true,
|
||||
"cmd/go/internal/imports/testdata/android": true,
|
||||
"cmd/go/internal/imports/testdata/illumos": true,
|
||||
"cmd/go/internal/imports/testdata/star": true,
|
||||
"cmd/go/internal/list": true,
|
||||
"cmd/go/internal/load": true,
|
||||
"cmd/go/internal/lockedfile": true,
|
||||
"cmd/go/internal/lockedfile/internal/filelock": true,
|
||||
"cmd/go/internal/modcmd": true,
|
||||
"cmd/go/internal/modconv": true,
|
||||
"cmd/go/internal/modconv/testdata": true,
|
||||
"cmd/go/internal/modfetch": true,
|
||||
"cmd/go/internal/modfetch/codehost": true,
|
||||
"cmd/go/internal/modfile": true,
|
||||
"cmd/go/internal/modfile/testdata": true,
|
||||
"cmd/go/internal/modget": true,
|
||||
"cmd/go/internal/modinfo": true,
|
||||
"cmd/go/internal/modload": true,
|
||||
"cmd/go/internal/module": true,
|
||||
"cmd/go/internal/mvs": true,
|
||||
"cmd/go/internal/note": true,
|
||||
"cmd/go/internal/par": true,
|
||||
"cmd/go/internal/renameio": true,
|
||||
"cmd/go/internal/robustio": true,
|
||||
"cmd/go/internal/run": true,
|
||||
"cmd/go/internal/search": true,
|
||||
"cmd/go/internal/semver": true,
|
||||
"cmd/go/internal/str": true,
|
||||
"cmd/go/internal/sumweb": true,
|
||||
"cmd/go/internal/test": true,
|
||||
"cmd/go/internal/tlog": true,
|
||||
"cmd/go/internal/tool": true,
|
||||
"cmd/go/internal/txtar": true,
|
||||
"cmd/go/internal/version": true,
|
||||
"cmd/go/internal/vet": true,
|
||||
"cmd/go/internal/web": true,
|
||||
"cmd/go/internal/work": true,
|
||||
"cmd/go/testdata": true,
|
||||
"cmd/go/testdata/badmod": true,
|
||||
"cmd/go/testdata/failssh": true,
|
||||
"cmd/go/testdata/generate": true,
|
||||
"cmd/go/testdata/importcom": true,
|
||||
"cmd/go/testdata/importcom/src/bad": true,
|
||||
"cmd/go/testdata/importcom/src/conflict": true,
|
||||
"cmd/go/testdata/importcom/src/works/x": true,
|
||||
"cmd/go/testdata/importcom/src/wrongplace": true,
|
||||
"cmd/go/testdata/importcycle/src/selfimport": true,
|
||||
"cmd/go/testdata/local": true,
|
||||
"cmd/go/testdata/local/easysub": true,
|
||||
"cmd/go/testdata/local/sub": true,
|
||||
"cmd/go/testdata/local/sub/sub": true,
|
||||
"cmd/go/testdata/mod": true,
|
||||
"cmd/go/testdata/modlegacy/src/new": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/p1": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/p2": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/sub": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/sub/inner": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/sub/inner/x": true,
|
||||
"cmd/go/testdata/modlegacy/src/new/sub/x/v1/y": true,
|
||||
"cmd/go/testdata/modlegacy/src/old/p1": true,
|
||||
"cmd/go/testdata/modlegacy/src/old/p2": true,
|
||||
"cmd/go/testdata/norunexample": true,
|
||||
"cmd/go/testdata/rundir": true,
|
||||
"cmd/go/testdata/rundir/sub": true,
|
||||
"cmd/go/testdata/script": true,
|
||||
"cmd/go/testdata/shadow/root1/src/foo": true,
|
||||
"cmd/go/testdata/shadow/root1/src/math": true,
|
||||
"cmd/go/testdata/shadow/root2/src/foo": true,
|
||||
"cmd/go/testdata/src": true,
|
||||
"cmd/go/testdata/src/badc": true,
|
||||
"cmd/go/testdata/src/badpkg": true,
|
||||
"cmd/go/testdata/src/bench": true,
|
||||
"cmd/go/testdata/src/benchfatal": true,
|
||||
"cmd/go/testdata/src/canonical/a": true,
|
||||
"cmd/go/testdata/src/canonical/a/vendor/c": true,
|
||||
"cmd/go/testdata/src/canonical/b": true,
|
||||
"cmd/go/testdata/src/canonical/d": true,
|
||||
"cmd/go/testdata/src/cgoasm": true,
|
||||
"cmd/go/testdata/src/cgocover": true,
|
||||
"cmd/go/testdata/src/cgocover2": true,
|
||||
"cmd/go/testdata/src/cgocover3": true,
|
||||
"cmd/go/testdata/src/cgocover4": true,
|
||||
"cmd/go/testdata/src/cgotest": true,
|
||||
"cmd/go/testdata/src/coverasm": true,
|
||||
"cmd/go/testdata/src/coverbad": true,
|
||||
"cmd/go/testdata/src/coverdep": true,
|
||||
"cmd/go/testdata/src/coverdep/p1": true,
|
||||
"cmd/go/testdata/src/coverdep2/p1": true,
|
||||
"cmd/go/testdata/src/coverdep2/p2": true,
|
||||
"cmd/go/testdata/src/coverdot1": true,
|
||||
"cmd/go/testdata/src/coverdot2": true,
|
||||
"cmd/go/testdata/src/dupload": true,
|
||||
"cmd/go/testdata/src/dupload/p": true,
|
||||
"cmd/go/testdata/src/dupload/p2": true,
|
||||
"cmd/go/testdata/src/dupload/vendor/p": true,
|
||||
"cmd/go/testdata/src/empty/pkg": true,
|
||||
"cmd/go/testdata/src/empty/pkgtest": true,
|
||||
"cmd/go/testdata/src/empty/pkgtestxtest": true,
|
||||
"cmd/go/testdata/src/empty/pkgxtest": true,
|
||||
"cmd/go/testdata/src/empty/test": true,
|
||||
"cmd/go/testdata/src/empty/testxtest": true,
|
||||
"cmd/go/testdata/src/empty/xtest": true,
|
||||
"cmd/go/testdata/src/exclude": true,
|
||||
"cmd/go/testdata/src/exclude/empty": true,
|
||||
"cmd/go/testdata/src/exclude/ignore": true,
|
||||
"cmd/go/testdata/src/gencycle": true,
|
||||
"cmd/go/testdata/src/go-cmd-test": true,
|
||||
"cmd/go/testdata/src/hello": true,
|
||||
"cmd/go/testdata/src/importmain/ismain": true,
|
||||
"cmd/go/testdata/src/importmain/test": true,
|
||||
"cmd/go/testdata/src/main_test": true,
|
||||
"cmd/go/testdata/src/multimain": true,
|
||||
"cmd/go/testdata/src/my.pkg": true,
|
||||
"cmd/go/testdata/src/my.pkg/main": true,
|
||||
"cmd/go/testdata/src/not_main": true,
|
||||
"cmd/go/testdata/src/notest": true,
|
||||
"cmd/go/testdata/src/run": true,
|
||||
"cmd/go/testdata/src/run/internal": true,
|
||||
"cmd/go/testdata/src/run/subdir/internal/private": true,
|
||||
"cmd/go/testdata/src/skipper": true,
|
||||
"cmd/go/testdata/src/sleepy1": true,
|
||||
"cmd/go/testdata/src/sleepy2": true,
|
||||
"cmd/go/testdata/src/sleepybad": true,
|
||||
"cmd/go/testdata/src/syntaxerror": true,
|
||||
"cmd/go/testdata/src/testcache": true,
|
||||
"cmd/go/testdata/src/testcycle/p1": true,
|
||||
"cmd/go/testdata/src/testcycle/p2": true,
|
||||
"cmd/go/testdata/src/testcycle/p3": true,
|
||||
"cmd/go/testdata/src/testcycle/q1": true,
|
||||
"cmd/go/testdata/src/testdep/p1": true,
|
||||
"cmd/go/testdata/src/testdep/p2": true,
|
||||
"cmd/go/testdata/src/testdep/p3": true,
|
||||
"cmd/go/testdata/src/testlist": true,
|
||||
"cmd/go/testdata/src/testnorun": true,
|
||||
"cmd/go/testdata/src/testrace": true,
|
||||
"cmd/go/testdata/src/testregexp": true,
|
||||
"cmd/go/testdata/src/vend": true,
|
||||
"cmd/go/testdata/src/vend/dir1": true,
|
||||
"cmd/go/testdata/src/vend/hello": true,
|
||||
"cmd/go/testdata/src/vend/subdir": true,
|
||||
"cmd/go/testdata/src/vend/vendor/p": true,
|
||||
"cmd/go/testdata/src/vend/vendor/q": true,
|
||||
"cmd/go/testdata/src/vend/vendor/strings": true,
|
||||
"cmd/go/testdata/src/vend/vendor/vend/dir1/dir2": true,
|
||||
"cmd/go/testdata/src/vend/x": true,
|
||||
"cmd/go/testdata/src/vend/x/invalid": true,
|
||||
"cmd/go/testdata/src/vend/x/vendor/p": true,
|
||||
"cmd/go/testdata/src/vend/x/vendor/p/p": true,
|
||||
"cmd/go/testdata/src/vend/x/vendor/r": true,
|
||||
"cmd/go/testdata/src/vetcycle": true,
|
||||
"cmd/go/testdata/src/vetfail/p1": true,
|
||||
"cmd/go/testdata/src/vetfail/p2": true,
|
||||
"cmd/go/testdata/src/vetpkg": true,
|
||||
"cmd/go/testdata/src/xtestonly": true,
|
||||
"cmd/go/testdata/testcover/pkg1": true,
|
||||
"cmd/go/testdata/testcover/pkg2": true,
|
||||
"cmd/go/testdata/testcover/pkg3": true,
|
||||
"cmd/go/testdata/testcover/pkg4": true,
|
||||
"cmd/go/testdata/testimport": true,
|
||||
"cmd/go/testdata/testimport/p1": true,
|
||||
"cmd/go/testdata/testimport/p2": true,
|
||||
"cmd/go/testdata/testinternal": true,
|
||||
"cmd/go/testdata/testinternal2": true,
|
||||
"cmd/go/testdata/testinternal2/x/y/z/internal/w": true,
|
||||
"cmd/go/testdata/testinternal3": true,
|
||||
"cmd/go/testdata/testinternal4/src/p": true,
|
||||
"cmd/go/testdata/testinternal4/src/q/internal/x": true,
|
||||
"cmd/go/testdata/testinternal4/src/q/j": true,
|
||||
"cmd/go/testdata/testonly": true,
|
||||
"cmd/go/testdata/testonly2": true,
|
||||
"cmd/go/testdata/testterminal18153": true,
|
||||
"cmd/go/testdata/testvendor/src/p": true,
|
||||
"cmd/go/testdata/testvendor/src/q/vendor/x": true,
|
||||
"cmd/go/testdata/testvendor/src/q/y": true,
|
||||
"cmd/go/testdata/testvendor/src/q/z": true,
|
||||
"cmd/go/testdata/testvendor2/src/p": true,
|
||||
"cmd/go/testdata/testvendor2/vendor/x": true,
|
||||
"cmd/gofmt": true,
|
||||
"cmd/gofmt/testdata": true,
|
||||
"cmd/internal/bio": true,
|
||||
"cmd/internal/browser": true,
|
||||
"cmd/internal/buildid": true,
|
||||
"cmd/internal/buildid/testdata": true,
|
||||
"cmd/internal/dwarf": true,
|
||||
"cmd/internal/edit": true,
|
||||
"cmd/internal/gcprog": true,
|
||||
"cmd/internal/goobj": true,
|
||||
"cmd/internal/goobj/testdata": true,
|
||||
"cmd/internal/goobj/testdata/mycgo": true,
|
||||
"cmd/internal/obj": true,
|
||||
"cmd/internal/obj/arm": true,
|
||||
"cmd/internal/obj/arm64": true,
|
||||
"cmd/internal/obj/mips": true,
|
||||
"cmd/internal/obj/ppc64": true,
|
||||
"cmd/internal/obj/s390x": true,
|
||||
"cmd/internal/obj/wasm": true,
|
||||
"cmd/internal/obj/x86": true,
|
||||
"cmd/internal/objabi": true,
|
||||
"cmd/internal/objfile": true,
|
||||
"cmd/internal/src": true,
|
||||
"cmd/internal/sys": true,
|
||||
"cmd/internal/test2json": true,
|
||||
"cmd/internal/test2json/testdata": true,
|
||||
"cmd/link": true,
|
||||
"cmd/link/internal/amd64": true,
|
||||
"cmd/link/internal/arm": true,
|
||||
"cmd/link/internal/arm64": true,
|
||||
"cmd/link/internal/ld": true,
|
||||
"cmd/link/internal/ld/testdata/httptest/main": true,
|
||||
"cmd/link/internal/ld/testdata/issue10978": true,
|
||||
"cmd/link/internal/ld/testdata/issue25459/a": true,
|
||||
"cmd/link/internal/ld/testdata/issue25459/main": true,
|
||||
"cmd/link/internal/ld/testdata/issue26237/b.dir": true,
|
||||
"cmd/link/internal/ld/testdata/issue26237/main": true,
|
||||
"cmd/link/internal/ld/testdata/issue32233/lib": true,
|
||||
"cmd/link/internal/ld/testdata/issue32233/main": true,
|
||||
"cmd/link/internal/loadelf": true,
|
||||
"cmd/link/internal/loadmacho": true,
|
||||
"cmd/link/internal/loadpe": true,
|
||||
"cmd/link/internal/loadxcoff": true,
|
||||
"cmd/link/internal/mips": true,
|
||||
"cmd/link/internal/mips64": true,
|
||||
"cmd/link/internal/objfile": true,
|
||||
"cmd/link/internal/ppc64": true,
|
||||
"cmd/link/internal/s390x": true,
|
||||
"cmd/link/internal/sym": true,
|
||||
"cmd/link/internal/wasm": true,
|
||||
"cmd/link/internal/x86": true,
|
||||
"cmd/link/testdata": true,
|
||||
"cmd/nm": true,
|
||||
"cmd/objdump": true,
|
||||
"cmd/objdump/testdata": true,
|
||||
"cmd/pack": true,
|
||||
"cmd/pprof": true,
|
||||
"cmd/test2json": true,
|
||||
"cmd/trace": true,
|
||||
"cmd/vendor": true,
|
||||
"cmd/vendor/github.com/google/pprof": true,
|
||||
"cmd/vendor/github.com/google/pprof/driver": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/binutils": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/driver": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/elfexec": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/graph": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/measurement": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/plugin": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/report": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/symbolizer": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/symbolz": true,
|
||||
"cmd/vendor/github.com/google/pprof/internal/transport": true,
|
||||
"cmd/vendor/github.com/google/pprof/profile": true,
|
||||
"cmd/vendor/github.com/google/pprof/third_party/d3": true,
|
||||
"cmd/vendor/github.com/google/pprof/third_party/d3flamegraph": true,
|
||||
"cmd/vendor/github.com/google/pprof/third_party/svgpan": true,
|
||||
"cmd/vendor/github.com/ianlancetaylor/demangle": true,
|
||||
"cmd/vendor/golang.org/x/arch": true,
|
||||
"cmd/vendor/golang.org/x/arch/arm/armasm": true,
|
||||
"cmd/vendor/golang.org/x/arch/arm64/arm64asm": true,
|
||||
"cmd/vendor/golang.org/x/arch/ppc64/ppc64asm": true,
|
||||
"cmd/vendor/golang.org/x/arch/x86/x86asm": true,
|
||||
"cmd/vendor/golang.org/x/crypto": true,
|
||||
"cmd/vendor/golang.org/x/crypto/ssh/terminal": true,
|
||||
"cmd/vendor/golang.org/x/sys": true,
|
||||
"cmd/vendor/golang.org/x/sys/unix": true,
|
||||
"cmd/vendor/golang.org/x/sys/windows": true,
|
||||
"cmd/vendor/golang.org/x/tools": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/internal/facts": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/assign": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/bools": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/composite": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/errorsas": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/printf": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/shift": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/tests": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/unmarshal": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/analysis/unitchecker": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/ast/astutil": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/ast/inspector": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/cfg": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/types/objectpath": true,
|
||||
"cmd/vendor/golang.org/x/tools/go/types/typeutil": true,
|
||||
"cmd/vet": true,
|
||||
"cmd/vet/internal/cfg": true,
|
||||
"cmd/vet/internal/whitelist": true,
|
||||
"cmd/vet/testdata/asm": true,
|
||||
"cmd/vet/testdata/assign": true,
|
||||
"cmd/vet/testdata/atomic": true,
|
||||
"cmd/vet/testdata/bool": true,
|
||||
"cmd/vet/testdata/buildtag": true,
|
||||
"cmd/vet/testdata/cgo": true,
|
||||
"cmd/vet/testdata/composite": true,
|
||||
"cmd/vet/testdata/copylock": true,
|
||||
"cmd/vet/testdata/deadcode": true,
|
||||
"cmd/vet/testdata/httpresponse": true,
|
||||
"cmd/vet/testdata/lostcancel": true,
|
||||
"cmd/vet/testdata/method": true,
|
||||
"cmd/vet/testdata/nilfunc": true,
|
||||
"cmd/vet/testdata/print": true,
|
||||
"cmd/vet/testdata/rangeloop": true,
|
||||
"cmd/vet/testdata/shift": true,
|
||||
"cmd/vet/testdata/structtag": true,
|
||||
"cmd/vet/testdata/tagtest": true,
|
||||
"cmd/vet/testdata/testingpkg": true,
|
||||
"cmd/vet/testdata/unmarshal": true,
|
||||
"cmd/vet/testdata/unsafeptr": true,
|
||||
"cmd/vet/testdata/unused": true,
|
||||
"compress/bzip2": true,
|
||||
"compress/bzip2/testdata": true,
|
||||
"compress/flate": true,
|
||||
"compress/flate/testdata": true,
|
||||
"compress/gzip": true,
|
||||
"compress/gzip/testdata": true,
|
||||
"compress/lzw": true,
|
||||
"compress/testdata": true,
|
||||
"compress/zlib": true,
|
||||
"container/heap": true,
|
||||
"container/list": true,
|
||||
|
|
@ -134,28 +434,42 @@ var stdPackages = map[string]bool{
|
|||
"crypto/des": true,
|
||||
"crypto/dsa": true,
|
||||
"crypto/ecdsa": true,
|
||||
"crypto/ecdsa/testdata": true,
|
||||
"crypto/ed25519": true,
|
||||
"crypto/ed25519/internal/edwards25519": true,
|
||||
"crypto/ed25519/testdata": true,
|
||||
"crypto/elliptic": true,
|
||||
"crypto/hmac": true,
|
||||
"crypto/internal/cipherhw": true,
|
||||
"crypto/internal/randutil": true,
|
||||
"crypto/internal/subtle": true,
|
||||
"crypto/md5": true,
|
||||
"crypto/rand": true,
|
||||
"crypto/rc4": true,
|
||||
"crypto/rsa": true,
|
||||
"crypto/rsa/testdata": true,
|
||||
"crypto/sha1": true,
|
||||
"crypto/sha256": true,
|
||||
"crypto/sha512": true,
|
||||
"crypto/subtle": true,
|
||||
"crypto/tls": true,
|
||||
"crypto/tls/testdata": true,
|
||||
"crypto/x509": true,
|
||||
"crypto/x509/pkix": true,
|
||||
"crypto/x509/testdata": true,
|
||||
"database/sql": true,
|
||||
"database/sql/driver": true,
|
||||
"debug/dwarf": true,
|
||||
"debug/dwarf/testdata": true,
|
||||
"debug/elf": true,
|
||||
"debug/elf/testdata": true,
|
||||
"debug/gosym": true,
|
||||
"debug/gosym/testdata": true,
|
||||
"debug/macho": true,
|
||||
"debug/macho/testdata": true,
|
||||
"debug/pe": true,
|
||||
"debug/pe/testdata": true,
|
||||
"debug/plan9obj": true,
|
||||
"debug/plan9obj/testdata": true,
|
||||
"encoding": true,
|
||||
"encoding/ascii85": true,
|
||||
"encoding/asn1": true,
|
||||
|
|
@ -166,6 +480,7 @@ var stdPackages = map[string]bool{
|
|||
"encoding/gob": true,
|
||||
"encoding/hex": true,
|
||||
"encoding/json": true,
|
||||
"encoding/json/testdata": true,
|
||||
"encoding/pem": true,
|
||||
"encoding/xml": true,
|
||||
"errors": true,
|
||||
|
|
@ -174,18 +489,35 @@ var stdPackages = map[string]bool{
|
|||
"fmt": true,
|
||||
"go/ast": true,
|
||||
"go/build": true,
|
||||
"go/build/testdata/doc": true,
|
||||
"go/build/testdata/empty": true,
|
||||
"go/build/testdata/multi": true,
|
||||
"go/build/testdata/other": true,
|
||||
"go/build/testdata/other/file": true,
|
||||
"go/build/testdata/withvendor/src/a/b": true,
|
||||
"go/build/testdata/withvendor/src/a/vendor/c/d": true,
|
||||
"go/constant": true,
|
||||
"go/doc": true,
|
||||
"go/doc/testdata": true,
|
||||
"go/format": true,
|
||||
"go/importer": true,
|
||||
"go/internal/gccgoimporter": true,
|
||||
"go/internal/gccgoimporter/testdata": true,
|
||||
"go/internal/gcimporter": true,
|
||||
"go/internal/gcimporter/testdata": true,
|
||||
"go/internal/gcimporter/testdata/versions": true,
|
||||
"go/internal/srcimporter": true,
|
||||
"go/internal/srcimporter/testdata/issue20855": true,
|
||||
"go/internal/srcimporter/testdata/issue23092": true,
|
||||
"go/internal/srcimporter/testdata/issue24392": true,
|
||||
"go/parser": true,
|
||||
"go/parser/testdata": true,
|
||||
"go/printer": true,
|
||||
"go/printer/testdata": true,
|
||||
"go/scanner": true,
|
||||
"go/token": true,
|
||||
"go/types": true,
|
||||
"go/types/testdata": true,
|
||||
"hash": true,
|
||||
"hash/adler32": true,
|
||||
"hash/crc32": true,
|
||||
|
|
@ -201,20 +533,37 @@ var stdPackages = map[string]bool{
|
|||
"image/internal/imageutil": true,
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
"image/png/testdata": true,
|
||||
"image/png/testdata/pngsuite": true,
|
||||
"image/testdata": true,
|
||||
"index/suffixarray": true,
|
||||
"internal/bytealg": true,
|
||||
"internal/cfg": true,
|
||||
"internal/cpu": true,
|
||||
"internal/fmtsort": true,
|
||||
"internal/goroot": true,
|
||||
"internal/goversion": true,
|
||||
"internal/lazyregexp": true,
|
||||
"internal/lazytemplate": true,
|
||||
"internal/nettrace": true,
|
||||
"internal/oserror": true,
|
||||
"internal/poll": true,
|
||||
"internal/race": true,
|
||||
"internal/reflectlite": true,
|
||||
"internal/singleflight": true,
|
||||
"internal/syscall/unix": true,
|
||||
"internal/syscall/windows": true,
|
||||
"internal/syscall/windows/registry": true,
|
||||
"internal/syscall/windows/sysdll": true,
|
||||
"internal/testenv": true,
|
||||
"internal/testlog": true,
|
||||
"internal/trace": true,
|
||||
"internal/trace/testdata": true,
|
||||
"internal/xcoff": true,
|
||||
"internal/xcoff/testdata": true,
|
||||
"io": true,
|
||||
"io/ioutil": true,
|
||||
"io/ioutil/testdata": true,
|
||||
"log": true,
|
||||
"log/syslog": true,
|
||||
"math": true,
|
||||
|
|
@ -224,10 +573,13 @@ var stdPackages = map[string]bool{
|
|||
"math/rand": true,
|
||||
"mime": true,
|
||||
"mime/multipart": true,
|
||||
"mime/multipart/testdata": true,
|
||||
"mime/quotedprintable": true,
|
||||
"mime/testdata": true,
|
||||
"net": true,
|
||||
"net/http": true,
|
||||
"net/http/cgi": true,
|
||||
"net/http/cgi/testdata": true,
|
||||
"net/http/cookiejar": true,
|
||||
"net/http/fcgi": true,
|
||||
"net/http/httptest": true,
|
||||
|
|
@ -235,11 +587,13 @@ var stdPackages = map[string]bool{
|
|||
"net/http/httputil": true,
|
||||
"net/http/internal": true,
|
||||
"net/http/pprof": true,
|
||||
"net/http/testdata": true,
|
||||
"net/internal/socktest": true,
|
||||
"net/mail": true,
|
||||
"net/rpc": true,
|
||||
"net/rpc/jsonrpc": true,
|
||||
"net/smtp": true,
|
||||
"net/testdata": true,
|
||||
"net/textproto": true,
|
||||
"net/url": true,
|
||||
"os": true,
|
||||
|
|
@ -253,21 +607,34 @@ var stdPackages = map[string]bool{
|
|||
"reflect": true,
|
||||
"regexp": true,
|
||||
"regexp/syntax": true,
|
||||
"regexp/testdata": true,
|
||||
"runtime": true,
|
||||
"runtime/cgo": true,
|
||||
"runtime/debug": true,
|
||||
"runtime/internal/atomic": true,
|
||||
"runtime/internal/math": true,
|
||||
"runtime/internal/sys": true,
|
||||
"runtime/msan": true,
|
||||
"runtime/pprof": true,
|
||||
"runtime/pprof/internal/profile": true,
|
||||
"runtime/pprof/testdata": true,
|
||||
"runtime/pprof/testdata/mappingtest": true,
|
||||
"runtime/race": true,
|
||||
"runtime/race/testdata": true,
|
||||
"runtime/testdata/testprog": true,
|
||||
"runtime/testdata/testprogcgo": true,
|
||||
"runtime/testdata/testprogcgo/windows": true,
|
||||
"runtime/testdata/testprognet": true,
|
||||
"runtime/trace": true,
|
||||
"sort": true,
|
||||
"strconv": true,
|
||||
"strconv/testdata": true,
|
||||
"strings": true,
|
||||
"sync": true,
|
||||
"sync/atomic": true,
|
||||
"syscall": true,
|
||||
"syscall/js": true,
|
||||
"testdata": true,
|
||||
"testing": true,
|
||||
"testing/internal/testdeps": true,
|
||||
"testing/iotest": true,
|
||||
|
|
@ -276,9 +643,36 @@ var stdPackages = map[string]bool{
|
|||
"text/tabwriter": true,
|
||||
"text/template": true,
|
||||
"text/template/parse": true,
|
||||
"text/template/testdata": true,
|
||||
"time": true,
|
||||
"unicode": true,
|
||||
"unicode/utf16": true,
|
||||
"unicode/utf8": true,
|
||||
"unsafe": true,
|
||||
"vendor": true,
|
||||
"vendor/golang.org/x/crypto": true,
|
||||
"vendor/golang.org/x/crypto/chacha20poly1305": true,
|
||||
"vendor/golang.org/x/crypto/cryptobyte": true,
|
||||
"vendor/golang.org/x/crypto/cryptobyte/asn1": true,
|
||||
"vendor/golang.org/x/crypto/curve25519": true,
|
||||
"vendor/golang.org/x/crypto/hkdf": true,
|
||||
"vendor/golang.org/x/crypto/internal/chacha20": true,
|
||||
"vendor/golang.org/x/crypto/internal/subtle": true,
|
||||
"vendor/golang.org/x/crypto/poly1305": true,
|
||||
"vendor/golang.org/x/net": true,
|
||||
"vendor/golang.org/x/net/dns/dnsmessage": true,
|
||||
"vendor/golang.org/x/net/http/httpguts": true,
|
||||
"vendor/golang.org/x/net/http/httpproxy": true,
|
||||
"vendor/golang.org/x/net/http2/hpack": true,
|
||||
"vendor/golang.org/x/net/idna": true,
|
||||
"vendor/golang.org/x/net/lif": true,
|
||||
"vendor/golang.org/x/net/nettest": true,
|
||||
"vendor/golang.org/x/net/route": true,
|
||||
"vendor/golang.org/x/sys": true,
|
||||
"vendor/golang.org/x/sys/cpu": true,
|
||||
"vendor/golang.org/x/text": true,
|
||||
"vendor/golang.org/x/text/secure/bidirule": true,
|
||||
"vendor/golang.org/x/text/transform": true,
|
||||
"vendor/golang.org/x/text/unicode/bidi": true,
|
||||
"vendor/golang.org/x/text/unicode/norm": true,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
/* Copyright 2019 The Bazel Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package golang
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/language"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// UpdateRepos generates go_repository rules corresponding to modules in
|
||||
// args.Imports. Each module argument may specify a version with an '@' suffix
|
||||
// (in the same format as 'go get'). If no version is specified, @latest
|
||||
// is requested.
|
||||
func (*goLang) UpdateRepos(args language.UpdateReposArgs) language.UpdateReposResult {
|
||||
gen := make([]*rule.Rule, len(args.Imports))
|
||||
var eg errgroup.Group
|
||||
for i := range args.Imports {
|
||||
i := i
|
||||
eg.Go(func() error {
|
||||
arg := args.Imports[i]
|
||||
modPath, query := arg, "latest"
|
||||
if i := strings.IndexByte(arg, '@'); i >= 0 {
|
||||
modPath, query = arg[:i], arg[i+1:]
|
||||
}
|
||||
name, version, sum, err := args.Cache.ModVersion(modPath, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gen[i] = rule.NewRule("go_repository", name)
|
||||
gen[i].SetAttr("importpath", modPath)
|
||||
gen[i].SetAttr("version", version)
|
||||
gen[i].SetAttr("sum", sum)
|
||||
setBuildAttrs(getGoConfig(args.Config), gen[i])
|
||||
return nil
|
||||
})
|
||||
}
|
||||
if err := eg.Wait(); err != nil {
|
||||
return language.UpdateReposResult{Error: err}
|
||||
}
|
||||
return language.UpdateReposResult{Gen: gen}
|
||||
}
|
||||
|
||||
var repoImportFuncs = map[string]func(args language.ImportReposArgs) language.ImportReposResult{
|
||||
"Gopkg.lock": importReposFromDep,
|
||||
"go.mod": importReposFromModules,
|
||||
"Godeps.json": importReposFromGodep,
|
||||
}
|
||||
|
||||
func (*goLang) CanImport(path string) bool {
|
||||
return repoImportFuncs[filepath.Base(path)] != nil
|
||||
}
|
||||
|
||||
func (*goLang) ImportRepos(args language.ImportReposArgs) language.ImportReposResult {
|
||||
res := repoImportFuncs[filepath.Base(args.Path)](args)
|
||||
for _, r := range res.Gen {
|
||||
setBuildAttrs(getGoConfig(args.Config), r)
|
||||
}
|
||||
if args.Prune {
|
||||
genNamesSet := make(map[string]bool)
|
||||
for _, r := range res.Gen {
|
||||
genNamesSet[r.Name()] = true
|
||||
}
|
||||
for _, r := range args.Config.Repos {
|
||||
if name := r.Name(); r.Kind() == "go_repository" && !genNamesSet[name] {
|
||||
res.Empty = append(res.Empty, rule.NewRule("go_repository", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func setBuildAttrs(gc *goConfig, r *rule.Rule) {
|
||||
if gc.buildExternalAttr != "" {
|
||||
r.SetAttr("build_external", gc.buildExternalAttr)
|
||||
}
|
||||
if gc.buildFileNamesAttr != "" {
|
||||
r.SetAttr("build_file_name", gc.buildFileNamesAttr)
|
||||
}
|
||||
if gc.buildFileGenerationAttr != "" {
|
||||
r.SetAttr("build_file_generation", gc.buildFileGenerationAttr)
|
||||
}
|
||||
if gc.buildTagsAttr != "" {
|
||||
r.SetAttr("build_tags", gc.buildTagsAttr)
|
||||
}
|
||||
if gc.buildFileProtoModeAttr != "" {
|
||||
r.SetAttr("build_file_proto_mode", gc.buildFileProtoModeAttr)
|
||||
}
|
||||
if gc.buildExtraArgsAttr != "" {
|
||||
extraArgs := strings.Split(gc.buildExtraArgsAttr, ",")
|
||||
r.SetAttr("build_extra_args", extraArgs)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Generated by language/proto/gen/gen_known_imports.go
|
||||
// From language/proto/proto.csv
|
||||
// From proto.csv
|
||||
|
||||
package proto
|
||||
|
||||
|
|
@ -684,10 +684,12 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/enums/google_ads_field_data_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_date_selection_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_price_bucket.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/hotel_rate_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/income_range_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/interaction_event_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/interaction_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/invoice_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/job_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/keyword_match_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/keyword_plan_competition_level.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
|
|
@ -742,6 +744,8 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/enums/promotion_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/proximity_radius_units.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/quality_score_bucket.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/reach_plan_ad_length.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/reach_plan_age_range.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/real_estate_placeholder_field.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/recommendation_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
"google/ads/googleads/v2/enums/search_engine_results_page_type.proto": label.New("go_googleapis", "google/ads/googleads/v2/enums", "enums_proto"),
|
||||
|
|
@ -844,6 +848,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/errors/id_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/image_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/internal_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/invoice_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_ad_group_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_campaign_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/keyword_plan_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
|
|
@ -873,6 +878,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/errors/query_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/quota_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/range_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/reach_plan_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/recommendation_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/region_code_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
"google/ads/googleads/v2/errors/request_error.proto": label.New("go_googleapis", "google/ads/googleads/v2/errors", "errors_proto"),
|
||||
|
|
@ -953,6 +959,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/resources/group_placement_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/hotel_group_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/hotel_performance_view.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/invoice.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan_ad_group.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
"google/ads/googleads/v2/resources/keyword_plan_campaign.proto": label.New("go_googleapis", "google/ads/googleads/v2/resources", "resources_proto"),
|
||||
|
|
@ -1056,6 +1063,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/services/group_placement_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/hotel_group_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/hotel_performance_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/invoice_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_ad_group_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_campaign_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/keyword_plan_idea_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
|
|
@ -1079,6 +1087,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/ads/googleads/v2/services/payments_account_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/product_bidding_category_constant_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/product_group_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/reach_plan_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/recommendation_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/remarketing_action_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
"google/ads/googleads/v2/services/search_term_view_service.proto": label.New("go_googleapis", "google/ads/googleads/v2/services", "services_proto"),
|
||||
|
|
@ -1103,8 +1112,6 @@ var knownImports = map[string]label.Label{
|
|||
"google/api/distribution.proto": label.New("go_googleapis", "google/api", "distribution_proto"),
|
||||
"google/api/documentation.proto": label.New("go_googleapis", "google/api", "serviceconfig_proto"),
|
||||
"google/api/endpoint.proto": label.New("go_googleapis", "google/api", "serviceconfig_proto"),
|
||||
"google/api/experimental/authorization_config.proto": label.New("go_googleapis", "google/api", "api_proto"),
|
||||
"google/api/experimental/experimental.proto": label.New("go_googleapis", "google/api", "api_proto"),
|
||||
"google/api/expr/v1alpha1/cel_service.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_proto"),
|
||||
"google/api/expr/v1alpha1/checked.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_proto"),
|
||||
"google/api/expr/v1alpha1/conformance_service.proto": label.New("go_googleapis", "google/api/expr/v1alpha1", "expr_proto"),
|
||||
|
|
@ -1177,7 +1184,19 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/asset/v1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1", "asset_proto"),
|
||||
"google/cloud/asset/v1beta1/asset_service.proto": label.New("go_googleapis", "google/cloud/asset/v1beta1", "asset_proto"),
|
||||
"google/cloud/asset/v1beta1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1beta1", "asset_proto"),
|
||||
"google/cloud/asset/v1p2beta1/asset_service.proto": label.New("go_googleapis", "google/cloud/asset/v1p2beta1", "asset_proto"),
|
||||
"google/cloud/asset/v1p2beta1/assets.proto": label.New("go_googleapis", "google/cloud/asset/v1p2beta1", "asset_proto"),
|
||||
"google/cloud/audit/audit_log.proto": label.New("go_googleapis", "google/cloud/audit", "audit_proto"),
|
||||
"google/cloud/automl/v1/annotation_payload.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/data_items.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/dataset.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/io.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/model.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/model_evaluation.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/operations.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/prediction_service.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/service.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1/translation.proto": label.New("go_googleapis", "google/cloud/automl/v1", "automl_proto"),
|
||||
"google/cloud/automl/v1beta1/annotation_payload.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_proto"),
|
||||
"google/cloud/automl/v1beta1/annotation_spec.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_proto"),
|
||||
"google/cloud/automl/v1beta1/classification.proto": label.New("go_googleapis", "google/cloud/automl/v1beta1", "automl_proto"),
|
||||
|
|
@ -1215,6 +1234,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/bigquery/storage/v1beta1/read_options.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_proto"),
|
||||
"google/cloud/bigquery/storage/v1beta1/storage.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_proto"),
|
||||
"google/cloud/bigquery/storage/v1beta1/table_reference.proto": label.New("go_googleapis", "google/cloud/bigquery/storage/v1beta1", "storage_proto"),
|
||||
"google/cloud/bigquery/v2/encryption_config.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_proto"),
|
||||
"google/cloud/bigquery/v2/model.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_proto"),
|
||||
"google/cloud/bigquery/v2/model_reference.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_proto"),
|
||||
"google/cloud/bigquery/v2/standard_sql.proto": label.New("go_googleapis", "google/cloud/bigquery/v2", "bigquery_proto"),
|
||||
|
|
@ -1222,6 +1242,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/binaryauthorization/v1beta1/resources.proto": label.New("go_googleapis", "google/cloud/binaryauthorization/v1beta1", "binaryauthorization_proto"),
|
||||
"google/cloud/binaryauthorization/v1beta1/service.proto": label.New("go_googleapis", "google/cloud/binaryauthorization/v1beta1", "binaryauthorization_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/datacatalog.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/gcs_fileset_spec.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/schema.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/search.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_proto"),
|
||||
"google/cloud/datacatalog/v1beta1/table_spec.proto": label.New("go_googleapis", "google/cloud/datacatalog/v1beta1", "datacatalog_proto"),
|
||||
|
|
@ -1237,6 +1258,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/datalabeling/v1beta1/human_annotation_config.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_proto"),
|
||||
"google/cloud/datalabeling/v1beta1/instruction.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_proto"),
|
||||
"google/cloud/datalabeling/v1beta1/operations.proto": label.New("go_googleapis", "google/cloud/datalabeling/v1beta1", "datalabeling_proto"),
|
||||
"google/cloud/dataproc/v1/autoscaling_policies.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_proto"),
|
||||
"google/cloud/dataproc/v1/clusters.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_proto"),
|
||||
"google/cloud/dataproc/v1/jobs.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_proto"),
|
||||
"google/cloud/dataproc/v1/operations.proto": label.New("go_googleapis", "google/cloud/dataproc/v1", "dataproc_proto"),
|
||||
|
|
@ -1261,11 +1283,16 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/dialogflow/v2beta1/context.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/document.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/entity_type.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/gcs.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/intent.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/knowledge_base.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/session.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/session_entity_type.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/validation_result.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/dialogflow/v2beta1/webhook.proto": label.New("go_googleapis", "google/cloud/dialogflow/v2beta1", "dialogflow_proto"),
|
||||
"google/cloud/document/v1beta1/document.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_proto"),
|
||||
"google/cloud/document/v1beta1/document_understanding.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_proto"),
|
||||
"google/cloud/document/v1beta1/geometry.proto": label.New("go_googleapis", "google/cloud/document/v1beta1", "document_proto"),
|
||||
"google/cloud/functions/v1beta2/functions.proto": label.New("go_googleapis", "google/cloud/functions/v1beta2", "functions_proto"),
|
||||
"google/cloud/functions/v1beta2/operations.proto": label.New("go_googleapis", "google/cloud/functions/v1beta2", "functions_proto"),
|
||||
"google/cloud/iot/v1/device_manager.proto": label.New("go_googleapis", "google/cloud/iot/v1", "iot_proto"),
|
||||
|
|
@ -1350,6 +1377,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/cloud/tasks/v2beta3/task.proto": label.New("go_googleapis", "google/cloud/tasks/v2beta3", "tasks_proto"),
|
||||
"google/cloud/texttospeech/v1/cloud_tts.proto": label.New("go_googleapis", "google/cloud/texttospeech/v1", "texttospeech_proto"),
|
||||
"google/cloud/texttospeech/v1beta1/cloud_tts.proto": label.New("go_googleapis", "google/cloud/texttospeech/v1beta1", "texttospeech_proto"),
|
||||
"google/cloud/translate/v3/translation_service.proto": label.New("go_googleapis", "google/cloud/translate/v3", "translate_proto"),
|
||||
"google/cloud/translate/v3beta1/translation_service.proto": label.New("go_googleapis", "google/cloud/translate/v3beta1", "translate_proto"),
|
||||
"google/cloud/videointelligence/v1/video_intelligence.proto": label.New("go_googleapis", "google/cloud/videointelligence/v1", "videointelligence_proto"),
|
||||
"google/cloud/videointelligence/v1beta1/video_intelligence.proto": label.New("go_googleapis", "google/cloud/videointelligence/v1beta1", "videointelligence_proto"),
|
||||
|
|
@ -1458,7 +1486,9 @@ var knownImports = map[string]label.Label{
|
|||
"google/devtools/resultstore/v2/configured_target.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/coverage.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/coverage_summary.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/download_metadata.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/file.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/file_processing_error.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/file_set.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/invocation.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/resultstore_download.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
|
|
@ -1466,6 +1496,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/devtools/resultstore/v2/resultstore_upload.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/target.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/test_suite.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/resultstore/v2/upload_metadata.proto": label.New("go_googleapis", "google/devtools/resultstore/v2", "resultstore_proto"),
|
||||
"google/devtools/source/v1/source_context.proto": label.New("go_googleapis", "google/devtools/source/v1", "source_proto"),
|
||||
"google/devtools/sourcerepo/v1/sourcerepo.proto": label.New("go_googleapis", "google/devtools/sourcerepo/v1", "sourcerepo_proto"),
|
||||
"google/example/library/v1/library.proto": label.New("go_googleapis", "google/example/library/v1", "library_proto"),
|
||||
|
|
@ -1505,6 +1536,7 @@ var knownImports = map[string]label.Label{
|
|||
"google/genomics/v1/references.proto": label.New("go_googleapis", "google/genomics/v1", "genomics_proto"),
|
||||
"google/genomics/v1/variants.proto": label.New("go_googleapis", "google/genomics/v1", "genomics_proto"),
|
||||
"google/genomics/v1alpha2/pipelines.proto": label.New("go_googleapis", "google/genomics/v1alpha2", "genomics_proto"),
|
||||
"google/geo/type/viewport.proto": label.New("go_googleapis", "google/geo/type", "viewport_proto"),
|
||||
"google/home/graph/v1/device.proto": label.New("go_googleapis", "google/home/graph/v1", "graph_proto"),
|
||||
"google/home/graph/v1/homegraph.proto": label.New("go_googleapis", "google/home/graph/v1", "graph_proto"),
|
||||
"google/iam/admin/v1/iam.proto": label.New("go_googleapis", "google/iam/admin/v1", "admin_proto"),
|
||||
|
|
|
|||
|
|
@ -682,10 +682,12 @@ google/ads/googleads/v2/enums/google_ads_field_category.proto,@go_googleapis//go
|
|||
google/ads/googleads/v2/enums/google_ads_field_data_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/hotel_date_selection_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/hotel_placeholder_field.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/hotel_price_bucket.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/hotel_rate_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/income_range_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/interaction_event_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/interaction_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/invoice_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/job_placeholder_field.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/keyword_match_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/keyword_plan_competition_level.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
|
|
@ -740,6 +742,8 @@ google/ads/googleads/v2/enums/promotion_extension_occasion.proto,@go_googleapis/
|
|||
google/ads/googleads/v2/enums/promotion_placeholder_field.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/proximity_radius_units.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/quality_score_bucket.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/reach_plan_ad_length.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/reach_plan_age_range.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/real_estate_placeholder_field.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/recommendation_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
google/ads/googleads/v2/enums/search_engine_results_page_type.proto,@go_googleapis//google/ads/googleads/v2/enums:enums_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/enums,@go_googleapis//google/ads/googleads/v2/enums:enums_go_proto
|
||||
|
|
@ -842,6 +846,7 @@ google/ads/googleads/v2/errors/header_error.proto,@go_googleapis//google/ads/goo
|
|||
google/ads/googleads/v2/errors/id_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/image_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/internal_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/invoice_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/keyword_plan_ad_group_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/keyword_plan_campaign_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/keyword_plan_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
|
|
@ -871,6 +876,7 @@ google/ads/googleads/v2/errors/policy_violation_error.proto,@go_googleapis//goog
|
|||
google/ads/googleads/v2/errors/query_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/quota_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/range_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/reach_plan_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/recommendation_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/region_code_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
google/ads/googleads/v2/errors/request_error.proto,@go_googleapis//google/ads/googleads/v2/errors:errors_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/errors,@go_googleapis//google/ads/googleads/v2/errors:errors_go_proto
|
||||
|
|
@ -951,6 +957,7 @@ google/ads/googleads/v2/resources/google_ads_field.proto,@go_googleapis//google/
|
|||
google/ads/googleads/v2/resources/group_placement_view.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/hotel_group_view.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/hotel_performance_view.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/invoice.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/keyword_plan.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/keyword_plan_ad_group.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
google/ads/googleads/v2/resources/keyword_plan_campaign.proto,@go_googleapis//google/ads/googleads/v2/resources:resources_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/resources,@go_googleapis//google/ads/googleads/v2/resources:resources_go_proto
|
||||
|
|
@ -1054,6 +1061,7 @@ google/ads/googleads/v2/services/google_ads_service.proto,@go_googleapis//google
|
|||
google/ads/googleads/v2/services/group_placement_view_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/hotel_group_view_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/hotel_performance_view_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/invoice_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/keyword_plan_ad_group_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/keyword_plan_campaign_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/keyword_plan_idea_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
|
|
@ -1077,6 +1085,7 @@ google/ads/googleads/v2/services/parental_status_view_service.proto,@go_googleap
|
|||
google/ads/googleads/v2/services/payments_account_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/product_bidding_category_constant_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/product_group_view_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/reach_plan_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/recommendation_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/remarketing_action_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
google/ads/googleads/v2/services/search_term_view_service.proto,@go_googleapis//google/ads/googleads/v2/services:services_proto,google.golang.org/genproto/googleapis/ads/googleads/v2/services,@go_googleapis//google/ads/googleads/v2/services:services_go_proto
|
||||
|
|
@ -1101,8 +1110,6 @@ google/api/control.proto,@go_googleapis//google/api:serviceconfig_proto,google.g
|
|||
google/api/distribution.proto,@go_googleapis//google/api:distribution_proto,google.golang.org/genproto/googleapis/api/distribution,@go_googleapis//google/api:distribution_go_proto
|
||||
google/api/documentation.proto,@go_googleapis//google/api:serviceconfig_proto,google.golang.org/genproto/googleapis/api/serviceconfig,@go_googleapis//google/api:serviceconfig_go_proto
|
||||
google/api/endpoint.proto,@go_googleapis//google/api:serviceconfig_proto,google.golang.org/genproto/googleapis/api/serviceconfig,@go_googleapis//google/api:serviceconfig_go_proto
|
||||
google/api/experimental/authorization_config.proto,@go_googleapis//google/api:api_proto,google.golang.org/genproto/googleapis/api,@go_googleapis//google/api:api_go_proto
|
||||
google/api/experimental/experimental.proto,@go_googleapis//google/api:api_proto,google.golang.org/genproto/googleapis/api,@go_googleapis//google/api:api_go_proto
|
||||
google/api/expr/v1alpha1/cel_service.proto,@go_googleapis//google/api/expr/v1alpha1:expr_proto,google.golang.org/genproto/googleapis/api/expr/v1alpha1,@go_googleapis//google/api/expr/v1alpha1:expr_go_proto
|
||||
google/api/expr/v1alpha1/checked.proto,@go_googleapis//google/api/expr/v1alpha1:expr_proto,google.golang.org/genproto/googleapis/api/expr/v1alpha1,@go_googleapis//google/api/expr/v1alpha1:expr_go_proto
|
||||
google/api/expr/v1alpha1/conformance_service.proto,@go_googleapis//google/api/expr/v1alpha1:expr_proto,google.golang.org/genproto/googleapis/api/expr/v1alpha1,@go_googleapis//google/api/expr/v1alpha1:expr_go_proto
|
||||
|
|
@ -1175,7 +1182,19 @@ google/cloud/asset/v1/asset_service.proto,@go_googleapis//google/cloud/asset/v1:
|
|||
google/cloud/asset/v1/assets.proto,@go_googleapis//google/cloud/asset/v1:asset_proto,google.golang.org/genproto/googleapis/cloud/asset/v1,@go_googleapis//google/cloud/asset/v1:asset_go_proto
|
||||
google/cloud/asset/v1beta1/asset_service.proto,@go_googleapis//google/cloud/asset/v1beta1:asset_proto,google.golang.org/genproto/googleapis/cloud/asset/v1beta1,@go_googleapis//google/cloud/asset/v1beta1:asset_go_proto
|
||||
google/cloud/asset/v1beta1/assets.proto,@go_googleapis//google/cloud/asset/v1beta1:asset_proto,google.golang.org/genproto/googleapis/cloud/asset/v1beta1,@go_googleapis//google/cloud/asset/v1beta1:asset_go_proto
|
||||
google/cloud/asset/v1p2beta1/asset_service.proto,@go_googleapis//google/cloud/asset/v1p2beta1:asset_proto,google.golang.org/genproto/googleapis/cloud/asset/v1p2beta1,@go_googleapis//google/cloud/asset/v1p2beta1:asset_go_proto
|
||||
google/cloud/asset/v1p2beta1/assets.proto,@go_googleapis//google/cloud/asset/v1p2beta1:asset_proto,google.golang.org/genproto/googleapis/cloud/asset/v1p2beta1,@go_googleapis//google/cloud/asset/v1p2beta1:asset_go_proto
|
||||
google/cloud/audit/audit_log.proto,@go_googleapis//google/cloud/audit:audit_proto,google.golang.org/genproto/googleapis/cloud/audit,@go_googleapis//google/cloud/audit:audit_go_proto
|
||||
google/cloud/automl/v1/annotation_payload.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/data_items.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/dataset.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/io.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/model.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/model_evaluation.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/operations.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/prediction_service.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/service.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1/translation.proto,@go_googleapis//google/cloud/automl/v1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1,@go_googleapis//google/cloud/automl/v1:automl_go_proto
|
||||
google/cloud/automl/v1beta1/annotation_payload.proto,@go_googleapis//google/cloud/automl/v1beta1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1beta1,@go_googleapis//google/cloud/automl/v1beta1:automl_go_proto
|
||||
google/cloud/automl/v1beta1/annotation_spec.proto,@go_googleapis//google/cloud/automl/v1beta1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1beta1,@go_googleapis//google/cloud/automl/v1beta1:automl_go_proto
|
||||
google/cloud/automl/v1beta1/classification.proto,@go_googleapis//google/cloud/automl/v1beta1:automl_proto,google.golang.org/genproto/googleapis/cloud/automl/v1beta1,@go_googleapis//google/cloud/automl/v1beta1:automl_go_proto
|
||||
|
|
@ -1213,6 +1232,7 @@ google/cloud/bigquery/storage/v1beta1/avro.proto,@go_googleapis//google/cloud/bi
|
|||
google/cloud/bigquery/storage/v1beta1/read_options.proto,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_proto,google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1beta1,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_go_proto
|
||||
google/cloud/bigquery/storage/v1beta1/storage.proto,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_proto,google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1beta1,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_go_proto
|
||||
google/cloud/bigquery/storage/v1beta1/table_reference.proto,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_proto,google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1beta1,@go_googleapis//google/cloud/bigquery/storage/v1beta1:storage_go_proto
|
||||
google/cloud/bigquery/v2/encryption_config.proto,@go_googleapis//google/cloud/bigquery/v2:bigquery_proto,google.golang.org/genproto/googleapis/cloud/bigquery/v2,@go_googleapis//google/cloud/bigquery/v2:bigquery_go_proto
|
||||
google/cloud/bigquery/v2/model.proto,@go_googleapis//google/cloud/bigquery/v2:bigquery_proto,google.golang.org/genproto/googleapis/cloud/bigquery/v2,@go_googleapis//google/cloud/bigquery/v2:bigquery_go_proto
|
||||
google/cloud/bigquery/v2/model_reference.proto,@go_googleapis//google/cloud/bigquery/v2:bigquery_proto,google.golang.org/genproto/googleapis/cloud/bigquery/v2,@go_googleapis//google/cloud/bigquery/v2:bigquery_go_proto
|
||||
google/cloud/bigquery/v2/standard_sql.proto,@go_googleapis//google/cloud/bigquery/v2:bigquery_proto,google.golang.org/genproto/googleapis/cloud/bigquery/v2,@go_googleapis//google/cloud/bigquery/v2:bigquery_go_proto
|
||||
|
|
@ -1220,6 +1240,7 @@ google/cloud/billing/v1/cloud_billing.proto,@go_googleapis//google/cloud/billing
|
|||
google/cloud/binaryauthorization/v1beta1/resources.proto,@go_googleapis//google/cloud/binaryauthorization/v1beta1:binaryauthorization_proto,google.golang.org/genproto/googleapis/cloud/binaryauthorization/v1beta1,@go_googleapis//google/cloud/binaryauthorization/v1beta1:binaryauthorization_go_proto
|
||||
google/cloud/binaryauthorization/v1beta1/service.proto,@go_googleapis//google/cloud/binaryauthorization/v1beta1:binaryauthorization_proto,google.golang.org/genproto/googleapis/cloud/binaryauthorization/v1beta1,@go_googleapis//google/cloud/binaryauthorization/v1beta1:binaryauthorization_go_proto
|
||||
google/cloud/datacatalog/v1beta1/datacatalog.proto,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_proto,google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_go_proto
|
||||
google/cloud/datacatalog/v1beta1/gcs_fileset_spec.proto,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_proto,google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_go_proto
|
||||
google/cloud/datacatalog/v1beta1/schema.proto,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_proto,google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_go_proto
|
||||
google/cloud/datacatalog/v1beta1/search.proto,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_proto,google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_go_proto
|
||||
google/cloud/datacatalog/v1beta1/table_spec.proto,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_proto,google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1,@go_googleapis//google/cloud/datacatalog/v1beta1:datacatalog_go_proto
|
||||
|
|
@ -1235,6 +1256,7 @@ google/cloud/datalabeling/v1beta1/evaluation_job.proto,@go_googleapis//google/cl
|
|||
google/cloud/datalabeling/v1beta1/human_annotation_config.proto,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_proto,google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_go_proto
|
||||
google/cloud/datalabeling/v1beta1/instruction.proto,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_proto,google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_go_proto
|
||||
google/cloud/datalabeling/v1beta1/operations.proto,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_proto,google.golang.org/genproto/googleapis/cloud/datalabeling/v1beta1,@go_googleapis//google/cloud/datalabeling/v1beta1:datalabeling_go_proto
|
||||
google/cloud/dataproc/v1/autoscaling_policies.proto,@go_googleapis//google/cloud/dataproc/v1:dataproc_proto,google.golang.org/genproto/googleapis/cloud/dataproc/v1,@go_googleapis//google/cloud/dataproc/v1:dataproc_go_proto
|
||||
google/cloud/dataproc/v1/clusters.proto,@go_googleapis//google/cloud/dataproc/v1:dataproc_proto,google.golang.org/genproto/googleapis/cloud/dataproc/v1,@go_googleapis//google/cloud/dataproc/v1:dataproc_go_proto
|
||||
google/cloud/dataproc/v1/jobs.proto,@go_googleapis//google/cloud/dataproc/v1:dataproc_proto,google.golang.org/genproto/googleapis/cloud/dataproc/v1,@go_googleapis//google/cloud/dataproc/v1:dataproc_go_proto
|
||||
google/cloud/dataproc/v1/operations.proto,@go_googleapis//google/cloud/dataproc/v1:dataproc_proto,google.golang.org/genproto/googleapis/cloud/dataproc/v1,@go_googleapis//google/cloud/dataproc/v1:dataproc_go_proto
|
||||
|
|
@ -1259,11 +1281,16 @@ google/cloud/dialogflow/v2beta1/audio_config.proto,@go_googleapis//google/cloud/
|
|||
google/cloud/dialogflow/v2beta1/context.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/document.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/entity_type.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/gcs.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/intent.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/knowledge_base.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/session.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/session_entity_type.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/validation_result.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/dialogflow/v2beta1/webhook.proto,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_proto,google.golang.org/genproto/googleapis/cloud/dialogflow/v2beta1,@go_googleapis//google/cloud/dialogflow/v2beta1:dialogflow_go_proto
|
||||
google/cloud/document/v1beta1/document.proto,@go_googleapis//google/cloud/document/v1beta1:document_proto,google.golang.org/genproto/googleapis/cloud/document/v1beta1,@go_googleapis//google/cloud/document/v1beta1:document_go_proto
|
||||
google/cloud/document/v1beta1/document_understanding.proto,@go_googleapis//google/cloud/document/v1beta1:document_proto,google.golang.org/genproto/googleapis/cloud/document/v1beta1,@go_googleapis//google/cloud/document/v1beta1:document_go_proto
|
||||
google/cloud/document/v1beta1/geometry.proto,@go_googleapis//google/cloud/document/v1beta1:document_proto,google.golang.org/genproto/googleapis/cloud/document/v1beta1,@go_googleapis//google/cloud/document/v1beta1:document_go_proto
|
||||
google/cloud/functions/v1beta2/functions.proto,@go_googleapis//google/cloud/functions/v1beta2:functions_proto,google.golang.org/genproto/googleapis/cloud/functions/v1beta2,@go_googleapis//google/cloud/functions/v1beta2:functions_go_proto
|
||||
google/cloud/functions/v1beta2/operations.proto,@go_googleapis//google/cloud/functions/v1beta2:functions_proto,google.golang.org/genproto/googleapis/cloud/functions/v1beta2,@go_googleapis//google/cloud/functions/v1beta2:functions_go_proto
|
||||
google/cloud/iot/v1/device_manager.proto,@go_googleapis//google/cloud/iot/v1:iot_proto,google.golang.org/genproto/googleapis/cloud/iot/v1,@go_googleapis//google/cloud/iot/v1:iot_go_proto
|
||||
|
|
@ -1348,6 +1375,7 @@ google/cloud/tasks/v2beta3/target.proto,@go_googleapis//google/cloud/tasks/v2bet
|
|||
google/cloud/tasks/v2beta3/task.proto,@go_googleapis//google/cloud/tasks/v2beta3:tasks_proto,google.golang.org/genproto/googleapis/cloud/tasks/v2beta3,@go_googleapis//google/cloud/tasks/v2beta3:tasks_go_proto
|
||||
google/cloud/texttospeech/v1/cloud_tts.proto,@go_googleapis//google/cloud/texttospeech/v1:texttospeech_proto,google.golang.org/genproto/googleapis/cloud/texttospeech/v1,@go_googleapis//google/cloud/texttospeech/v1:texttospeech_go_proto
|
||||
google/cloud/texttospeech/v1beta1/cloud_tts.proto,@go_googleapis//google/cloud/texttospeech/v1beta1:texttospeech_proto,google.golang.org/genproto/googleapis/cloud/texttospeech/v1beta1,@go_googleapis//google/cloud/texttospeech/v1beta1:texttospeech_go_proto
|
||||
google/cloud/translate/v3/translation_service.proto,@go_googleapis//google/cloud/translate/v3:translate_proto,google.golang.org/genproto/googleapis/cloud/translate/v3,@go_googleapis//google/cloud/translate/v3:translate_go_proto
|
||||
google/cloud/translate/v3beta1/translation_service.proto,@go_googleapis//google/cloud/translate/v3beta1:translate_proto,google.golang.org/genproto/googleapis/cloud/translate/v3beta1,@go_googleapis//google/cloud/translate/v3beta1:translate_go_proto
|
||||
google/cloud/videointelligence/v1/video_intelligence.proto,@go_googleapis//google/cloud/videointelligence/v1:videointelligence_proto,google.golang.org/genproto/googleapis/cloud/videointelligence/v1,@go_googleapis//google/cloud/videointelligence/v1:videointelligence_go_proto
|
||||
google/cloud/videointelligence/v1beta1/video_intelligence.proto,@go_googleapis//google/cloud/videointelligence/v1beta1:videointelligence_proto,google.golang.org/genproto/googleapis/cloud/videointelligence/v1beta1,@go_googleapis//google/cloud/videointelligence/v1beta1:videointelligence_go_proto
|
||||
|
|
@ -1456,7 +1484,9 @@ google/devtools/resultstore/v2/configuration.proto,@go_googleapis//google/devtoo
|
|||
google/devtools/resultstore/v2/configured_target.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/coverage.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/coverage_summary.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/download_metadata.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/file.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/file_processing_error.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/file_set.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/invocation.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/resultstore_download.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
|
|
@ -1464,6 +1494,7 @@ google/devtools/resultstore/v2/resultstore_file_download.proto,@go_googleapis//g
|
|||
google/devtools/resultstore/v2/resultstore_upload.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/target.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/test_suite.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/resultstore/v2/upload_metadata.proto,@go_googleapis//google/devtools/resultstore/v2:resultstore_proto,google.golang.org/genproto/googleapis/devtools/resultstore/v2,@go_googleapis//google/devtools/resultstore/v2:resultstore_go_proto
|
||||
google/devtools/source/v1/source_context.proto,@go_googleapis//google/devtools/source/v1:source_proto,google.golang.org/genproto/googleapis/devtools/source/v1,@go_googleapis//google/devtools/source/v1:source_go_proto
|
||||
google/devtools/sourcerepo/v1/sourcerepo.proto,@go_googleapis//google/devtools/sourcerepo/v1:sourcerepo_proto,google.golang.org/genproto/googleapis/devtools/sourcerepo/v1,@go_googleapis//google/devtools/sourcerepo/v1:sourcerepo_go_proto
|
||||
google/example/library/v1/library.proto,@go_googleapis//google/example/library/v1:library_proto,google.golang.org/genproto/googleapis/example/library/v1,@go_googleapis//google/example/library/v1:library_go_proto
|
||||
|
|
@ -1503,6 +1534,7 @@ google/genomics/v1/reads.proto,@go_googleapis//google/genomics/v1:genomics_proto
|
|||
google/genomics/v1/references.proto,@go_googleapis//google/genomics/v1:genomics_proto,google.golang.org/genproto/googleapis/genomics/v1,@go_googleapis//google/genomics/v1:genomics_go_proto
|
||||
google/genomics/v1/variants.proto,@go_googleapis//google/genomics/v1:genomics_proto,google.golang.org/genproto/googleapis/genomics/v1,@go_googleapis//google/genomics/v1:genomics_go_proto
|
||||
google/genomics/v1alpha2/pipelines.proto,@go_googleapis//google/genomics/v1alpha2:genomics_proto,google.golang.org/genproto/googleapis/genomics/v1alpha2,@go_googleapis//google/genomics/v1alpha2:genomics_go_proto
|
||||
google/geo/type/viewport.proto,@go_googleapis//google/geo/type:viewport_proto,google.golang.org/genproto/googleapis/geo/type/viewport,@go_googleapis//google/geo/type:viewport_go_proto
|
||||
google/home/graph/v1/device.proto,@go_googleapis//google/home/graph/v1:graph_proto,google.golang.org/genproto/googleapis/home/graph/v1,@go_googleapis//google/home/graph/v1:graph_go_proto
|
||||
google/home/graph/v1/homegraph.proto,@go_googleapis//google/home/graph/v1:graph_proto,google.golang.org/genproto/googleapis/home/graph/v1,@go_googleapis//google/home/graph/v1:graph_go_proto
|
||||
google/iam/admin/v1/iam.proto,@go_googleapis//google/iam/admin/v1:admin_proto,google.golang.org/genproto/googleapis/iam/admin/v1,@go_googleapis//google/iam/admin/v1:admin_go_proto
|
||||
|
|
|
|||
|
|
|
@ -0,0 +1,120 @@
|
|||
/* Copyright 2019 The Bazel Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package language
|
||||
|
||||
import (
|
||||
"github.com/bazelbuild/bazel-gazelle/config"
|
||||
"github.com/bazelbuild/bazel-gazelle/repo"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
)
|
||||
|
||||
// RepoUpdater may be implemented by languages that support updating
|
||||
// repository rules that provide named libraries.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type RepoUpdater interface {
|
||||
UpdateRepos(args UpdateReposArgs) UpdateReposResult
|
||||
}
|
||||
|
||||
// UpdateReposArgs contains arguments for RepoUpdater.UpdateRepos.
|
||||
// Arguments are passed in a struct value so that new fields may be added
|
||||
// in the future without breaking existing implementations.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type UpdateReposArgs struct {
|
||||
// Config is the configuration for the main workspace.
|
||||
Config *config.Config
|
||||
|
||||
// Imports is a list of libraries to update. UpdateRepos should return
|
||||
// repository rules that provide these libraries. It may also return
|
||||
// repository rules providing transitive dependencies.
|
||||
Imports []string
|
||||
|
||||
// Cache stores information fetched from the network and ensures that
|
||||
// the same request isn't made multiple times.
|
||||
Cache *repo.RemoteCache
|
||||
}
|
||||
|
||||
// UpdateReposResult contains return values for RepoUpdater.UpdateRepos.
|
||||
// Results are returned through a struct so that new (optional) fields may be
|
||||
// added without breaking existing implementations.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type UpdateReposResult struct {
|
||||
// Gen is a list of repository rules that provide libraries named by
|
||||
// UpdateImportArgs.Imports. These will be merged with existing rules or
|
||||
// added to WORKSPACE. This list may be shorter or longer than the list
|
||||
// of imports, since a single repository may provide multiple imports,
|
||||
// and additional repositories may be needed for transitive dependencies.
|
||||
Gen []*rule.Rule
|
||||
|
||||
// Error is any fatal error that occurred. Non-fatal errors should be logged.
|
||||
Error error
|
||||
}
|
||||
|
||||
// RepoImporter may be implemented by languages that support importing
|
||||
// repository rules from another build system.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type RepoImporter interface {
|
||||
// CanImport returns whether a given configuration file may be imported
|
||||
// with this extension. Only one extension may import any given file.
|
||||
// ImportRepos will not be called unless this returns true.
|
||||
CanImport(path string) bool
|
||||
|
||||
// ImportRepos generates a list of repository rules by reading a
|
||||
// configuration file from another build system.
|
||||
ImportRepos(args ImportReposArgs) ImportReposResult
|
||||
}
|
||||
|
||||
// ImportReposArgs contains arguments for RepoImporter.ImportRepos.
|
||||
// Arguments are passed in a struct value so that new fields may be added
|
||||
// in the future without breaking existing implementations.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type ImportReposArgs struct {
|
||||
// Config is the configuration for the main workspace.
|
||||
Config *config.Config
|
||||
|
||||
// Path is the name of the configuration file to import.
|
||||
Path string
|
||||
|
||||
// Prune indicates whether repository rules that are no longer needed
|
||||
// should be deleted. This means the Empty list in the result should be
|
||||
// filled in.
|
||||
Prune bool
|
||||
|
||||
// Cache stores information fetched from the network and ensures that
|
||||
// the same request isn't made multiple times.
|
||||
Cache *repo.RemoteCache
|
||||
}
|
||||
|
||||
// ImportReposResult contains return values for RepoImporter.ImportRepos.
|
||||
// Results are returned through a struct so that new (optional) fields may
|
||||
// be added without breaking existing implementations.
|
||||
//
|
||||
// EXPERIMENTAL: this may change or be removed.
|
||||
type ImportReposResult struct {
|
||||
// Gen is a list of imported repository rules.
|
||||
Gen []*rule.Rule
|
||||
|
||||
// Empty is a list of repository rules that may be deleted. This should only
|
||||
// be set if ImportReposArgs.Prune is true.
|
||||
Empty []*rule.Rule
|
||||
|
||||
// Error is any fatal error that occurred. Non-fatal errors should be logged.
|
||||
Error error
|
||||
}
|
||||
|
|
@ -139,12 +139,6 @@ func newLoadIndex(f *rule.File, after []string) int {
|
|||
return index
|
||||
}
|
||||
|
||||
// FixWorkspace updates rules in the WORKSPACE file f that were used with an
|
||||
// older version of rules_go or gazelle.
|
||||
func FixWorkspace(f *rule.File) {
|
||||
removeLegacyGoRepository(f)
|
||||
}
|
||||
|
||||
// CheckGazelleLoaded searches the given WORKSPACE file for a repository named
|
||||
// "bazel_gazelle". If no such repository is found *and* the repo is not
|
||||
// declared with a directive *and* at least one load statement mentions
|
||||
|
|
@ -183,17 +177,3 @@ by adding a comment like this to WORKSPACE:
|
|||
# gazelle:repo bazel_gazelle
|
||||
`, f.Path)
|
||||
}
|
||||
|
||||
// removeLegacyGoRepository removes loads of go_repository from
|
||||
// @io_bazel_rules_go. FixLoads should be called after this; it will load from
|
||||
// @bazel_gazelle.
|
||||
func removeLegacyGoRepository(f *rule.File) {
|
||||
for _, l := range f.Loads {
|
||||
if l.Name() == "@io_bazel_rules_go//go:def.bzl" {
|
||||
l.Remove("go_repository")
|
||||
if l.IsEmpty() {
|
||||
l.Delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,3 +65,47 @@ func RelBaseName(rel, prefix, root string) string {
|
|||
}
|
||||
return base
|
||||
}
|
||||
|
||||
// Index returns the starting index of the string sub within the non-absolute
|
||||
// slash-separated path p. sub must start and end at component boundaries
|
||||
// within p.
|
||||
func Index(p, sub string) int {
|
||||
if sub == "" {
|
||||
return 0
|
||||
}
|
||||
p = path.Clean(p)
|
||||
sub = path.Clean(sub)
|
||||
if path.IsAbs(sub) {
|
||||
if HasPrefix(p, sub) {
|
||||
return 0
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
if p == "" || p == "/" {
|
||||
return -1
|
||||
}
|
||||
|
||||
i := 0 // i is the index of the first byte of a path element
|
||||
if len(p) > 0 && p[0] == '/' {
|
||||
i++
|
||||
}
|
||||
for {
|
||||
suffix := p[i:]
|
||||
if len(suffix) < len(sub) {
|
||||
return -1
|
||||
}
|
||||
if suffix[:len(sub)] == sub && (len(suffix) == len(sub) || suffix[len(sub)] == '/') {
|
||||
return i
|
||||
}
|
||||
j := strings.IndexByte(suffix, '/')
|
||||
if j < 0 {
|
||||
return -1
|
||||
}
|
||||
i += j + 1
|
||||
if i >= len(p) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"dep.go",
|
||||
"godep.go",
|
||||
"modules.go",
|
||||
"remote.go",
|
||||
"repo.go",
|
||||
],
|
||||
|
|
@ -14,10 +11,8 @@ go_library(
|
|||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/label:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/merger:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/pathtools:go_default_library",
|
||||
"//vendor/github.com/bazelbuild/bazel-gazelle/rule:go_default_library",
|
||||
"//vendor/github.com/pelletier/go-toml:go_default_library",
|
||||
"//vendor/golang.org/x/tools/go/vcs:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -33,26 +34,6 @@ import (
|
|||
"golang.org/x/tools/go/vcs"
|
||||
)
|
||||
|
||||
// UpdateRepo returns an object describing a repository at the most recent
|
||||
// commit or version tag.
|
||||
//
|
||||
// This function uses RemoteCache to retrieve information about the repository.
|
||||
// Depending on how the RemoteCache was initialized and used earlier, some
|
||||
// information may already be locally available. Frequently though, information
|
||||
// will be fetched over the network, so this function may be slow.
|
||||
func UpdateRepo(rc *RemoteCache, modPath string) (Repo, error) {
|
||||
name, version, sum, err := rc.ModVersion(modPath, "latest")
|
||||
if err != nil {
|
||||
return Repo{}, err
|
||||
}
|
||||
return Repo{
|
||||
Name: name,
|
||||
GoPrefix: modPath,
|
||||
Version: version,
|
||||
Sum: sum,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RemoteCache stores information about external repositories. The cache may
|
||||
// be initialized with information about known repositories, i.e., those listed
|
||||
// in the WORKSPACE file and mentioned on the command line. Other information
|
||||
|
|
@ -129,6 +110,16 @@ type modVersionValue struct {
|
|||
path, name, version, sum string
|
||||
}
|
||||
|
||||
// Repo describes details of a Go repository known in advance. It is used to
|
||||
// initialize RemoteCache so that some repositories don't need to be looked up.
|
||||
//
|
||||
// DEPRECATED: Go-specific details should be removed from RemoteCache, and
|
||||
// lookup logic should be moved to language/go. This means RemoteCache will
|
||||
// need to be initialized in a different way.
|
||||
type Repo struct {
|
||||
Name, GoPrefix, Remote, VCS string
|
||||
}
|
||||
|
||||
// NewRemoteCache creates a new RemoteCache with a set of known repositories.
|
||||
// The Root and Remote methods will return information about repositories listed
|
||||
// here without accessing the network. However, the Head method will still
|
||||
|
|
@ -570,3 +561,23 @@ func pathWithoutSemver(path string) string {
|
|||
}
|
||||
return path[:m[2]] + path[m[3]:]
|
||||
}
|
||||
|
||||
// findGoTool attempts to locate the go executable. If GOROOT is set, we'll
|
||||
// prefer the one in there; otherwise, we'll rely on PATH. If the wrapper
|
||||
// script generated by the gazelle rule is invoked by Bazel, it will set
|
||||
// GOROOT to the configured SDK. We don't want to rely on the host SDK in
|
||||
// that situation.
|
||||
//
|
||||
// TODO(jayconrod): copied from language/go (though it was originally in this
|
||||
// package). Go-specific details should be removed from RemoteCache, and
|
||||
// this copy should be deleted.
|
||||
func findGoTool() string {
|
||||
path := "go" // rely on PATH by default
|
||||
if goroot, ok := os.LookupEnv("GOROOT"); ok {
|
||||
path = filepath.Join(goroot, "bin", "go")
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
path += ".exe"
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,215 +28,17 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/bazelbuild/bazel-gazelle/merger"
|
||||
"github.com/bazelbuild/bazel-gazelle/rule"
|
||||
)
|
||||
|
||||
// Repo describes an external repository rule declared in a Bazel
|
||||
// WORKSPACE file or macro file.
|
||||
type Repo struct {
|
||||
// Name is the value of the "name" attribute of the repository rule.
|
||||
Name string
|
||||
|
||||
// GoPrefix is the portion of the Go import path for the root of this
|
||||
// repository. Usually the same as Remote.
|
||||
GoPrefix string
|
||||
|
||||
// Commit is the revision at which a repository is checked out (for example,
|
||||
// a Git commit id).
|
||||
Commit string
|
||||
|
||||
// Tag is the name of the version at which a repository is checked out.
|
||||
Tag string
|
||||
|
||||
// Remote is the URL the repository can be cloned or checked out from.
|
||||
Remote string
|
||||
|
||||
// VCS is the version control system used to check out the repository.
|
||||
// May also be "http" for HTTP archives.
|
||||
VCS string
|
||||
|
||||
// Version is the semantic version of the module to download. Exactly one
|
||||
// of Version, Commit, and Tag must be set.
|
||||
Version string
|
||||
|
||||
// Sum is the hash of the module to be verified after download.
|
||||
Sum string
|
||||
|
||||
// Replace is the Go import path of the module configured by the replace
|
||||
// directive in go.mod.
|
||||
Replace string
|
||||
}
|
||||
|
||||
type byName []Repo
|
||||
|
||||
func (s byName) Len() int { return len(s) }
|
||||
func (s byName) Less(i, j int) bool { return s[i].Name < s[j].Name }
|
||||
func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
type byRuleName []*rule.Rule
|
||||
|
||||
func (s byRuleName) Len() int { return len(s) }
|
||||
func (s byRuleName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }
|
||||
func (s byRuleName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
type lockFileFormat int
|
||||
|
||||
const (
|
||||
unknownFormat lockFileFormat = iota
|
||||
depFormat
|
||||
moduleFormat
|
||||
godepFormat
|
||||
)
|
||||
|
||||
var lockFileParsers = map[lockFileFormat]func(string, *RemoteCache) ([]Repo, error){
|
||||
depFormat: importRepoRulesDep,
|
||||
moduleFormat: importRepoRulesModules,
|
||||
godepFormat: importRepoRulesGoDep,
|
||||
}
|
||||
|
||||
// ImportRepoRules reads the lock file of a vendoring tool and returns
|
||||
// a list of equivalent repository rules that can be merged into a WORKSPACE
|
||||
// file. The format of the file is inferred from its basename.
|
||||
func ImportRepoRules(filename string, repoCache *RemoteCache) ([]*rule.Rule, error) {
|
||||
format := getLockFileFormat(filename)
|
||||
if format == unknownFormat {
|
||||
return nil, fmt.Errorf(`%s: unrecognized lock file format. Expected "Gopkg.lock", "go.mod", or "Godeps.json"`, filename)
|
||||
}
|
||||
parser := lockFileParsers[format]
|
||||
repos, err := parser(filename, repoCache)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing %q: %v", filename, err)
|
||||
}
|
||||
sort.Stable(byName(repos))
|
||||
|
||||
rules := make([]*rule.Rule, 0, len(repos))
|
||||
for _, repo := range repos {
|
||||
rules = append(rules, GenerateRule(repo))
|
||||
}
|
||||
return rules, nil
|
||||
}
|
||||
|
||||
// MergeRules merges a list of generated repo rules with the already defined repo rules,
|
||||
// and then updates each rule's underlying file. If the generated rule matches an existing
|
||||
// one, then it inherits the file where the existing rule was defined. If the rule is new then
|
||||
// its file is set as the destFile parameter. If pruneRules is set, then this function will prune
|
||||
// any existing rules that no longer have an equivalent repo defined in the Gopkg.lock/go.mod file.
|
||||
// A list of the updated files is returned.
|
||||
func MergeRules(genRules []*rule.Rule, existingRules map[*rule.File][]string, destFile *rule.File, kinds map[string]rule.KindInfo, pruneRules bool) []*rule.File {
|
||||
sort.Stable(byRuleName(genRules))
|
||||
|
||||
ruleMap := make(map[string]bool)
|
||||
if pruneRules {
|
||||
for _, r := range genRules {
|
||||
ruleMap[r.Name()] = true
|
||||
}
|
||||
}
|
||||
|
||||
repoMap := make(map[string]*rule.File)
|
||||
emptyRules := make([]*rule.Rule, 0)
|
||||
for file, repoNames := range existingRules {
|
||||
// Avoid writing to the same file by matching destFile with its definition in existingRules
|
||||
if file.Path == destFile.Path && file.MacroName() != "" && file.MacroName() == destFile.MacroName() {
|
||||
file = destFile
|
||||
}
|
||||
for _, name := range repoNames {
|
||||
if pruneRules && !ruleMap[name] {
|
||||
emptyRules = append(emptyRules, rule.NewRule("go_repository", name))
|
||||
}
|
||||
repoMap[name] = file
|
||||
}
|
||||
}
|
||||
|
||||
rulesByFile := make(map[*rule.File][]*rule.Rule)
|
||||
for _, rule := range genRules {
|
||||
dest := destFile
|
||||
if file, ok := repoMap[rule.Name()]; ok {
|
||||
dest = file
|
||||
}
|
||||
rulesByFile[dest] = append(rulesByFile[dest], rule)
|
||||
}
|
||||
emptyRulesByFile := make(map[*rule.File][]*rule.Rule)
|
||||
for _, rule := range emptyRules {
|
||||
if file, ok := repoMap[rule.Name()]; ok {
|
||||
emptyRulesByFile[file] = append(emptyRulesByFile[file], rule)
|
||||
}
|
||||
}
|
||||
|
||||
updatedFiles := make(map[string]*rule.File)
|
||||
for f, rules := range rulesByFile {
|
||||
merger.MergeFile(f, emptyRulesByFile[f], rules, merger.PreResolve, kinds)
|
||||
delete(emptyRulesByFile, f)
|
||||
f.Sync()
|
||||
if uf, ok := updatedFiles[f.Path]; ok {
|
||||
uf.SyncMacroFile(f)
|
||||
} else {
|
||||
updatedFiles[f.Path] = f
|
||||
}
|
||||
}
|
||||
// Merge the remaining files that have empty rules, but no genRules
|
||||
for f, rules := range emptyRulesByFile {
|
||||
merger.MergeFile(f, rules, nil, merger.PreResolve, kinds)
|
||||
f.Sync()
|
||||
if uf, ok := updatedFiles[f.Path]; ok {
|
||||
uf.SyncMacroFile(f)
|
||||
} else {
|
||||
updatedFiles[f.Path] = f
|
||||
}
|
||||
}
|
||||
|
||||
files := make([]*rule.File, 0, len(updatedFiles))
|
||||
for _, f := range updatedFiles {
|
||||
files = append(files, f)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func getLockFileFormat(filename string) lockFileFormat {
|
||||
switch filepath.Base(filename) {
|
||||
case "Gopkg.lock":
|
||||
return depFormat
|
||||
case "go.mod":
|
||||
return moduleFormat
|
||||
case "Godeps.json":
|
||||
return godepFormat
|
||||
default:
|
||||
return unknownFormat
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateRule returns a repository rule for the given repository that can
|
||||
// be written in a WORKSPACE file.
|
||||
func GenerateRule(repo Repo) *rule.Rule {
|
||||
r := rule.NewRule("go_repository", repo.Name)
|
||||
if repo.Commit != "" {
|
||||
r.SetAttr("commit", repo.Commit)
|
||||
}
|
||||
if repo.Tag != "" {
|
||||
r.SetAttr("tag", repo.Tag)
|
||||
}
|
||||
r.SetAttr("importpath", repo.GoPrefix)
|
||||
if repo.Remote != "" {
|
||||
r.SetAttr("remote", repo.Remote)
|
||||
}
|
||||
if repo.VCS != "" {
|
||||
r.SetAttr("vcs", repo.VCS)
|
||||
}
|
||||
if repo.Version != "" {
|
||||
r.SetAttr("version", repo.Version)
|
||||
}
|
||||
if repo.Sum != "" {
|
||||
r.SetAttr("sum", repo.Sum)
|
||||
}
|
||||
if repo.Replace != "" {
|
||||
r.SetAttr("replace", repo.Replace)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// FindExternalRepo attempts to locate the directory where Bazel has fetched
|
||||
// the external repository with the given name. An error is returned if the
|
||||
// repository directory cannot be located.
|
||||
|
|
@ -266,9 +68,29 @@ func FindExternalRepo(repoRoot, name string) (string, error) {
|
|||
|
||||
// ListRepositories extracts metadata about repositories declared in a
|
||||
// file.
|
||||
func ListRepositories(workspace *rule.File) (repos []Repo, repoNamesByFile map[*rule.File][]string, err error) {
|
||||
repoNamesByFile = make(map[*rule.File][]string)
|
||||
repos, repoNamesByFile[workspace] = getRepos(workspace.Rules)
|
||||
func ListRepositories(workspace *rule.File) (repos []*rule.Rule, repoFileMap map[string]*rule.File, err error) {
|
||||
repoIndexMap := make(map[string]int)
|
||||
repoFileMap = make(map[string]*rule.File)
|
||||
for _, repo := range workspace.Rules {
|
||||
if name := repo.Name(); name != "" {
|
||||
repos = append(repos, repo)
|
||||
repoFileMap[name] = workspace
|
||||
repoIndexMap[name] = len(repos) - 1
|
||||
}
|
||||
}
|
||||
extraRepos, err := parseRepositoryDirectives(workspace.Directives)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, repo := range extraRepos {
|
||||
if i, ok := repoIndexMap[repo.Name()]; ok {
|
||||
repos[i] = repo
|
||||
} else {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
repoFileMap[repo.Name()] = workspace
|
||||
}
|
||||
|
||||
for _, d := range workspace.Directives {
|
||||
switch d.Key {
|
||||
case "repository_macro":
|
||||
|
|
@ -281,13 +103,54 @@ func ListRepositories(workspace *rule.File) (repos []Repo, repoNamesByFile map[*
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
currRepos, names := getRepos(macroFile.Rules)
|
||||
repoNamesByFile[macroFile] = names
|
||||
repos = append(repos, currRepos...)
|
||||
for _, repo := range macroFile.Rules {
|
||||
if name := repo.Name(); name != "" {
|
||||
repos = append(repos, repo)
|
||||
repoFileMap[name] = macroFile
|
||||
repoIndexMap[name] = len(repos) - 1
|
||||
}
|
||||
}
|
||||
extraRepos, err = parseRepositoryDirectives(macroFile.Directives)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, repo := range extraRepos {
|
||||
if i, ok := repoIndexMap[repo.Name()]; ok {
|
||||
repos[i] = repo
|
||||
} else {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
repoFileMap[repo.Name()] = macroFile
|
||||
}
|
||||
}
|
||||
}
|
||||
return repos, repoFileMap, nil
|
||||
}
|
||||
|
||||
return repos, repoNamesByFile, nil
|
||||
func parseRepositoryDirectives(directives []rule.Directive) (repos []*rule.Rule, err error) {
|
||||
for _, d := range directives {
|
||||
switch d.Key {
|
||||
case "repository":
|
||||
vals := strings.Fields(d.Value)
|
||||
if len(vals) < 2 {
|
||||
return nil, fmt.Errorf("failure parsing repository: %s, expected repository kind and attributes", d.Value)
|
||||
}
|
||||
kind := vals[0]
|
||||
r := rule.NewRule(kind, "")
|
||||
for _, val := range vals[1:] {
|
||||
kv := strings.SplitN(val, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
return nil, fmt.Errorf("failure parsing repository: %s, expected format for attributes is attr1_name=attr1_value", d.Value)
|
||||
}
|
||||
r.SetAttr(kv[0], kv[1])
|
||||
}
|
||||
if r.Name() == "" {
|
||||
return nil, fmt.Errorf("failure parsing repository: %s, expected a name attribute for the given repository", d.Value)
|
||||
}
|
||||
repos = append(repos, r)
|
||||
}
|
||||
}
|
||||
return repos, nil
|
||||
}
|
||||
|
||||
func parseRepositoryMacroDirective(directive string) (string, string, error) {
|
||||
|
|
@ -301,50 +164,3 @@ func parseRepositoryMacroDirective(directive string) (string, string, error) {
|
|||
}
|
||||
return f, vals[1], nil
|
||||
}
|
||||
|
||||
func getRepos(rules []*rule.Rule) (repos []Repo, names []string) {
|
||||
for _, r := range rules {
|
||||
name := r.Name()
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
var repo Repo
|
||||
switch r.Kind() {
|
||||
case "go_repository":
|
||||
// TODO(jayconrod): extract other fields needed by go_repository.
|
||||
// Currently, we don't use the result of this function to produce new
|
||||
// go_repository rules, so it doesn't matter.
|
||||
goPrefix := r.AttrString("importpath")
|
||||
version := r.AttrString("version")
|
||||
sum := r.AttrString("sum")
|
||||
replace := r.AttrString("replace")
|
||||
revision := r.AttrString("commit")
|
||||
tag := r.AttrString("tag")
|
||||
remote := r.AttrString("remote")
|
||||
vcs := r.AttrString("vcs")
|
||||
if goPrefix == "" {
|
||||
continue
|
||||
}
|
||||
repo = Repo{
|
||||
Name: name,
|
||||
GoPrefix: goPrefix,
|
||||
Version: version,
|
||||
Sum: sum,
|
||||
Replace: replace,
|
||||
Commit: revision,
|
||||
Tag: tag,
|
||||
Remote: remote,
|
||||
VCS: vcs,
|
||||
}
|
||||
|
||||
// TODO(jayconrod): infer from {new_,}git_repository, {new_,}http_archive,
|
||||
// local_repository.
|
||||
|
||||
default:
|
||||
continue
|
||||
}
|
||||
repos = append(repos, repo)
|
||||
names = append(names, repo.Name)
|
||||
}
|
||||
return repos, names
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,17 @@ type Directive struct {
|
|||
// is returned. Errors are reported for unrecognized directives and directives
|
||||
// out of place (after the first statement).
|
||||
func ParseDirectives(f *bzl.File) []Directive {
|
||||
return parseDirectives(f.Stmt)
|
||||
}
|
||||
|
||||
// ParseDirectivesFromMacro scans a macro body for Gazelle directives. The
|
||||
// full list of directives is returned. Errors are reported for unrecognized
|
||||
// directives and directives out of place (after the first statement).
|
||||
func ParseDirectivesFromMacro(f *bzl.DefStmt) []Directive {
|
||||
return parseDirectives(f.Body)
|
||||
}
|
||||
|
||||
func parseDirectives(stmt []bzl.Expr) []Directive {
|
||||
var directives []Directive
|
||||
parseComment := func(com bzl.Comment) {
|
||||
match := directiveRe.FindStringSubmatch(com.Token)
|
||||
|
|
@ -49,7 +60,7 @@ func ParseDirectives(f *bzl.File) []Directive {
|
|||
directives = append(directives, Directive{key, value})
|
||||
}
|
||||
|
||||
for _, s := range f.Stmt {
|
||||
for _, s := range stmt {
|
||||
coms := s.Comment()
|
||||
for _, com := range coms.Before {
|
||||
parseComment(com)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import (
|
|||
|
||||
// Platform represents a GOOS/GOARCH pair. When Platform is used to describe
|
||||
// sources, dependencies, or flags, either OS or Arch may be empty.
|
||||
//
|
||||
// DEPRECATED: do not use outside language/go. This type is Go-specific
|
||||
// and should be moved to the Go extension.
|
||||
type Platform struct {
|
||||
OS, Arch string
|
||||
}
|
||||
|
|
@ -43,6 +46,8 @@ func (p Platform) String() string {
|
|||
// KnownPlatforms is the set of target platforms that Go supports. Gazelle
|
||||
// will generate multi-platform build files using these tags. rules_go and
|
||||
// Bazel may not actually support all of these.
|
||||
//
|
||||
// DEPRECATED: do not use outside language/go.
|
||||
var KnownPlatforms = []Platform{
|
||||
{"android", "386"},
|
||||
{"android", "amd64"},
|
||||
|
|
@ -56,6 +61,10 @@ var KnownPlatforms = []Platform{
|
|||
{"freebsd", "386"},
|
||||
{"freebsd", "amd64"},
|
||||
{"freebsd", "arm"},
|
||||
{"ios", "386"},
|
||||
{"ios", "amd64"},
|
||||
{"ios", "arm"},
|
||||
{"ios", "arm64"},
|
||||
{"linux", "386"},
|
||||
{"linux", "amd64"},
|
||||
{"linux", "arm"},
|
||||
|
|
@ -84,6 +93,11 @@ var KnownPlatforms = []Platform{
|
|||
{"windows", "amd64"},
|
||||
}
|
||||
|
||||
var OSAliases = map[string][]string{
|
||||
"android": []string{"linux"},
|
||||
"ios": []string{"darwin"},
|
||||
}
|
||||
|
||||
var (
|
||||
// KnownOSs is the sorted list of operating systems that Go supports.
|
||||
KnownOSs []string
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package rule
|
|||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
bzl "github.com/bazelbuild/buildtools/build"
|
||||
)
|
||||
|
||||
// PlatformStrings contains a set of strings associated with a buildable
|
||||
|
|
@ -30,6 +32,9 @@ import (
|
|||
// in more than one list within a set (e.g., in "linux" and "windows" within
|
||||
// the OS set). Strings within each list should be sorted, though this may
|
||||
// not be relied upon.
|
||||
//
|
||||
// DEPRECATED: do not use outside language/go. This type is Go-specific and
|
||||
// should be moved to the Go extension.
|
||||
type PlatformStrings struct {
|
||||
// Generic is a list of strings not specific to any platform.
|
||||
Generic []string
|
||||
|
|
@ -190,3 +195,51 @@ func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (Platfor
|
|||
}
|
||||
return result, errors
|
||||
}
|
||||
|
||||
func (ps PlatformStrings) BzlExpr() bzl.Expr {
|
||||
var pieces []bzl.Expr
|
||||
if len(ps.Generic) > 0 {
|
||||
pieces = append(pieces, ExprFromValue(ps.Generic))
|
||||
}
|
||||
if len(ps.OS) > 0 {
|
||||
pieces = append(pieces, platformStringsOSArchDictExpr(ps.OS))
|
||||
}
|
||||
if len(ps.Arch) > 0 {
|
||||
pieces = append(pieces, platformStringsOSArchDictExpr(ps.Arch))
|
||||
}
|
||||
if len(ps.Platform) > 0 {
|
||||
pieces = append(pieces, platformStringsPlatformDictExpr(ps.Platform))
|
||||
}
|
||||
if len(pieces) == 0 {
|
||||
return &bzl.ListExpr{}
|
||||
} else if len(pieces) == 1 {
|
||||
return pieces[0]
|
||||
} else {
|
||||
e := pieces[0]
|
||||
if list, ok := e.(*bzl.ListExpr); ok {
|
||||
list.ForceMultiLine = true
|
||||
}
|
||||
for _, piece := range pieces[1:] {
|
||||
e = &bzl.BinaryExpr{X: e, Y: piece, Op: "+"}
|
||||
}
|
||||
return e
|
||||
}
|
||||
}
|
||||
|
||||
func platformStringsOSArchDictExpr(m map[string][]string) bzl.Expr {
|
||||
s := make(SelectStringListValue)
|
||||
for key, value := range m {
|
||||
s["@io_bazel_rules_go//go/platform:"+key] = value
|
||||
}
|
||||
s["//conditions:default"] = nil
|
||||
return s.BzlExpr()
|
||||
}
|
||||
|
||||
func platformStringsPlatformDictExpr(m map[Platform][]string) bzl.Expr {
|
||||
s := make(SelectStringListValue)
|
||||
for key, value := range m {
|
||||
s["@io_bazel_rules_go//go/platform:"+key.String()] = value
|
||||
}
|
||||
s["//conditions:default"] = nil
|
||||
return s.BzlExpr()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ type File struct {
|
|||
// Path is the file system path to the build file (same as File.Path).
|
||||
Path string
|
||||
|
||||
// DefName is the name of the function definition this File refers to
|
||||
// if loaded with LoadMacroFile or a similar function. Normally empty.
|
||||
DefName string
|
||||
|
||||
// Directives is a list of configuration directives found in top-level
|
||||
// comments in the file. This should not be modified after the file is read.
|
||||
Directives []Directive
|
||||
|
|
@ -177,9 +181,10 @@ type function struct {
|
|||
// the next time Sync is called.
|
||||
func ScanASTBody(pkg, defName string, bzlFile *bzl.File) *File {
|
||||
f := &File{
|
||||
File: bzlFile,
|
||||
Pkg: pkg,
|
||||
Path: bzlFile.Path,
|
||||
File: bzlFile,
|
||||
Pkg: pkg,
|
||||
Path: bzlFile.Path,
|
||||
DefName: defName,
|
||||
}
|
||||
var defStmt *bzl.DefStmt
|
||||
f.Rules, f.Loads, defStmt = scanExprs(defName, bzlFile.Stmt)
|
||||
|
|
@ -200,7 +205,11 @@ func ScanASTBody(pkg, defName string, bzlFile *bzl.File) *File {
|
|||
inserted: false,
|
||||
}
|
||||
}
|
||||
f.Directives = ParseDirectives(bzlFile)
|
||||
if f.function != nil {
|
||||
f.Directives = ParseDirectivesFromMacro(f.function.stmt)
|
||||
} else {
|
||||
f.Directives = ParseDirectives(bzlFile)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,50 @@ type GlobValue struct {
|
|||
Excludes []string
|
||||
}
|
||||
|
||||
// BzlExprValue is implemented by types that have custom translations
|
||||
// to Starlark values.
|
||||
type BzlExprValue interface {
|
||||
BzlExpr() bzl.Expr
|
||||
}
|
||||
|
||||
// SelectStringListValue is a value that can be translated to a Bazel
|
||||
// select expression that picks a string list based on a string condition.
|
||||
type SelectStringListValue map[string][]string
|
||||
|
||||
func (s SelectStringListValue) BzlExpr() bzl.Expr {
|
||||
defaultKey := "//conditions:default"
|
||||
keys := make([]string, 0, len(s))
|
||||
haveDefaultKey := false
|
||||
for key := range s {
|
||||
if key == defaultKey {
|
||||
haveDefaultKey = true
|
||||
} else {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
if haveDefaultKey {
|
||||
keys = append(keys, defaultKey)
|
||||
}
|
||||
|
||||
args := make([]bzl.Expr, 0, len(s))
|
||||
for _, key := range keys {
|
||||
value := ExprFromValue(s[key])
|
||||
if key != defaultKey {
|
||||
value.(*bzl.ListExpr).ForceMultiLine = true
|
||||
}
|
||||
args = append(args, &bzl.KeyValueExpr{
|
||||
Key: &bzl.StringExpr{Value: key},
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
sel := &bzl.CallExpr{
|
||||
X: &bzl.Ident{Name: "select"},
|
||||
List: []bzl.Expr{&bzl.DictExpr{List: args, ForceMultiLine: true}},
|
||||
}
|
||||
return sel
|
||||
}
|
||||
|
||||
// ExprFromValue converts a value into an expression that can be written into
|
||||
// a Bazel build file. The following types of values can be converted:
|
||||
//
|
||||
|
|
@ -52,6 +96,9 @@ func ExprFromValue(val interface{}) bzl.Expr {
|
|||
if e, ok := val.(bzl.Expr); ok {
|
||||
return e
|
||||
}
|
||||
if be, ok := val.(BzlExprValue); ok {
|
||||
return be.BzlExpr()
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(val)
|
||||
switch rv.Kind() {
|
||||
|
|
@ -85,23 +132,14 @@ func ExprFromValue(val interface{}) bzl.Expr {
|
|||
sort.Sort(byString(rkeys))
|
||||
args := make([]bzl.Expr, len(rkeys))
|
||||
for i, rk := range rkeys {
|
||||
label := fmt.Sprintf("@io_bazel_rules_go//go/platform:%s", mapKeyString(rk))
|
||||
k := &bzl.StringExpr{Value: label}
|
||||
k := &bzl.StringExpr{Value: mapKeyString(rk)}
|
||||
v := ExprFromValue(rv.MapIndex(rk).Interface())
|
||||
if l, ok := v.(*bzl.ListExpr); ok {
|
||||
l.ForceMultiLine = true
|
||||
}
|
||||
args[i] = &bzl.KeyValueExpr{Key: k, Value: v}
|
||||
}
|
||||
args = append(args, &bzl.KeyValueExpr{
|
||||
Key: &bzl.StringExpr{Value: "//conditions:default"},
|
||||
Value: &bzl.ListExpr{},
|
||||
})
|
||||
sel := &bzl.CallExpr{
|
||||
X: &bzl.Ident{Name: "select"},
|
||||
List: []bzl.Expr{&bzl.DictExpr{List: args, ForceMultiLine: true}},
|
||||
}
|
||||
return sel
|
||||
return &bzl.DictExpr{List: args, ForceMultiLine: true}
|
||||
|
||||
case reflect.Struct:
|
||||
switch val := val.(type) {
|
||||
|
|
@ -119,35 +157,6 @@ func ExprFromValue(val interface{}) bzl.Expr {
|
|||
X: &bzl.LiteralExpr{Token: "glob"},
|
||||
List: globArgs,
|
||||
}
|
||||
|
||||
case PlatformStrings:
|
||||
var pieces []bzl.Expr
|
||||
if len(val.Generic) > 0 {
|
||||
pieces = append(pieces, ExprFromValue(val.Generic))
|
||||
}
|
||||
if len(val.OS) > 0 {
|
||||
pieces = append(pieces, ExprFromValue(val.OS))
|
||||
}
|
||||
if len(val.Arch) > 0 {
|
||||
pieces = append(pieces, ExprFromValue(val.Arch))
|
||||
}
|
||||
if len(val.Platform) > 0 {
|
||||
pieces = append(pieces, ExprFromValue(val.Platform))
|
||||
}
|
||||
if len(pieces) == 0 {
|
||||
return &bzl.ListExpr{}
|
||||
} else if len(pieces) == 1 {
|
||||
return pieces[0]
|
||||
} else {
|
||||
e := pieces[0]
|
||||
if list, ok := e.(*bzl.ListExpr); ok {
|
||||
list.ForceMultiLine = true
|
||||
}
|
||||
for _, piece := range pieces[1:] {
|
||||
e = &bzl.BinaryExpr{X: e, Y: piece, Op: "+"}
|
||||
}
|
||||
return e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,8 +168,6 @@ func mapKeyString(k reflect.Value) string {
|
|||
switch s := k.Interface().(type) {
|
||||
case string:
|
||||
return s
|
||||
case Platform:
|
||||
return s.String()
|
||||
default:
|
||||
log.Panicf("unexpected map key: %v", k)
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/chai2010/gettext-go/gettext"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gettext.SetLocale("zh_CN")
|
||||
gettext.BindTextdomain("hello", "../examples/local", nil)
|
||||
gettext.Textdomain("hello")
|
||||
|
||||
fmt.Println(gettext.Gettext("Hello, world!"))
|
||||
// Output: 你好, 世界!
|
||||
}
|
||||
|
|
@ -28,6 +28,9 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ go_library(
|
|||
importpath = "github.com/fsnotify/fsnotify",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = select({
|
||||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:darwin": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
|
|
@ -25,6 +28,9 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
// Copyright 2014 Google Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// This binary compares memory usage between btree and gollrb.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/google/btree"
|
||||
"github.com/petar/GoLLRB/llrb"
|
||||
)
|
||||
|
||||
var (
|
||||
size = flag.Int("size", 1000000, "size of the tree to build")
|
||||
degree = flag.Int("degree", 8, "degree of btree")
|
||||
gollrb = flag.Bool("llrb", false, "use llrb instead of btree")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
vals := rand.Perm(*size)
|
||||
var t, v interface{}
|
||||
v = vals
|
||||
var stats runtime.MemStats
|
||||
for i := 0; i < 10; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
fmt.Println("-------- BEFORE ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
start := time.Now()
|
||||
if *gollrb {
|
||||
tr := llrb.New()
|
||||
for _, v := range vals {
|
||||
tr.ReplaceOrInsert(llrb.Int(v))
|
||||
}
|
||||
t = tr // keep it around
|
||||
} else {
|
||||
tr := btree.New(*degree)
|
||||
for _, v := range vals {
|
||||
tr.ReplaceOrInsert(btree.Int(v))
|
||||
}
|
||||
t = tr // keep it around
|
||||
}
|
||||
fmt.Printf("%v inserts in %v\n", *size, time.Since(start))
|
||||
fmt.Println("-------- AFTER ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
for i := 0; i < 10; i++ {
|
||||
runtime.GC()
|
||||
}
|
||||
fmt.Println("-------- AFTER GC ----------")
|
||||
runtime.ReadMemStats(&stats)
|
||||
fmt.Printf("%+v\n", stats)
|
||||
if t == v {
|
||||
fmt.Println("to make sure vals and tree aren't GC'd")
|
||||
}
|
||||
}
|
||||
|
|
@ -8,5 +8,5 @@ go_library(
|
|||
],
|
||||
importmap = "k8s.io/kops/vendor/github.com/gophercloud/gophercloud/internal",
|
||||
importpath = "github.com/gophercloud/gophercloud/internal",
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//vendor/github.com/gophercloud/gophercloud:__subpackages__"],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/github.com/mattn/go-isatty:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/github.com/mattn/go-isatty:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/github.com/mattn/go-isatty:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"//vendor/golang.org/x/net/ipv4:go_default_library",
|
||||
"//vendor/golang.org/x/net/ipv6:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:darwin": [
|
||||
"//vendor/golang.org/x/net/ipv4:go_default_library",
|
||||
|
|
@ -72,6 +73,11 @@ go_library(
|
|||
"//vendor/golang.org/x/net/ipv6:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/net/ipv4:go_default_library",
|
||||
"//vendor/golang.org/x/net/ipv6:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/net/ipv4:go_default_library",
|
||||
"//vendor/golang.org/x/net/ipv6:go_default_library",
|
||||
|
|
|
|||
|
|
@ -1,198 +0,0 @@
|
|||
//+build ignore
|
||||
|
||||
// compression_generate.go is meant to run with go generate. It will use
|
||||
// go/{importer,types} to track down all the RR struct types. Then for each type
|
||||
// it will look to see if there are (compressible) names, if so it will add that
|
||||
// type to compressionLenHelperType and comressionLenSearchType which "fake" the
|
||||
// compression so that Len() is fast.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"go/importer"
|
||||
"go/types"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var packageHdr = `
|
||||
// Code generated by "go run compress_generate.go"; DO NOT EDIT.
|
||||
|
||||
package dns
|
||||
|
||||
`
|
||||
|
||||
// getTypeStruct will take a type and the package scope, and return the
|
||||
// (innermost) struct if the type is considered a RR type (currently defined as
|
||||
// those structs beginning with a RR_Header, could be redefined as implementing
|
||||
// the RR interface). The bool return value indicates if embedded structs were
|
||||
// resolved.
|
||||
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
|
||||
st, ok := t.Underlying().(*types.Struct)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
|
||||
return st, false
|
||||
}
|
||||
if st.Field(0).Anonymous() {
|
||||
st, _ := getTypeStruct(st.Field(0).Type(), scope)
|
||||
return st, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Import and type-check the package
|
||||
pkg, err := importer.Default().Import("github.com/miekg/dns")
|
||||
fatalIfErr(err)
|
||||
scope := pkg.Scope()
|
||||
|
||||
var domainTypes []string // Types that have a domain name in them (either compressible or not).
|
||||
var cdomainTypes []string // Types that have a compressible domain name in them (subset of domainType)
|
||||
Names:
|
||||
for _, name := range scope.Names() {
|
||||
o := scope.Lookup(name)
|
||||
if o == nil || !o.Exported() {
|
||||
continue
|
||||
}
|
||||
st, _ := getTypeStruct(o.Type(), scope)
|
||||
if st == nil {
|
||||
continue
|
||||
}
|
||||
if name == "PrivateRR" {
|
||||
continue
|
||||
}
|
||||
|
||||
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
|
||||
log.Fatalf("Constant Type%s does not exist.", o.Name())
|
||||
}
|
||||
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
if st.Tag(i) == `dns:"domain-name"` {
|
||||
domainTypes = append(domainTypes, o.Name())
|
||||
continue Names
|
||||
}
|
||||
if st.Tag(i) == `dns:"cdomain-name"` {
|
||||
cdomainTypes = append(cdomainTypes, o.Name())
|
||||
domainTypes = append(domainTypes, o.Name())
|
||||
continue Names
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case st.Tag(i) == `dns:"domain-name"`:
|
||||
domainTypes = append(domainTypes, o.Name())
|
||||
continue Names
|
||||
case st.Tag(i) == `dns:"cdomain-name"`:
|
||||
cdomainTypes = append(cdomainTypes, o.Name())
|
||||
domainTypes = append(domainTypes, o.Name())
|
||||
continue Names
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(packageHdr)
|
||||
|
||||
// compressionLenHelperType - all types that have domain-name/cdomain-name can be used for compressing names
|
||||
|
||||
fmt.Fprint(b, "func compressionLenHelperType(c map[string]int, r RR, initLen int) int {\n")
|
||||
fmt.Fprint(b, "currentLen := initLen\n")
|
||||
fmt.Fprint(b, "switch x := r.(type) {\n")
|
||||
for _, name := range domainTypes {
|
||||
o := scope.Lookup(name)
|
||||
st, _ := getTypeStruct(o.Type(), scope)
|
||||
|
||||
fmt.Fprintf(b, "case *%s:\n", name)
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
out := func(s string) {
|
||||
fmt.Fprintf(b, "currentLen -= len(x.%s) + 1\n", st.Field(i).Name())
|
||||
fmt.Fprintf(b, "currentLen += compressionLenHelper(c, x.%s, currentLen)\n", st.Field(i).Name())
|
||||
}
|
||||
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
switch st.Tag(i) {
|
||||
case `dns:"domain-name"`:
|
||||
fallthrough
|
||||
case `dns:"cdomain-name"`:
|
||||
// For HIP we need to slice over the elements in this slice.
|
||||
fmt.Fprintf(b, `for i := range x.%s {
|
||||
currentLen -= len(x.%s[i]) + 1
|
||||
}
|
||||
`, st.Field(i).Name(), st.Field(i).Name())
|
||||
fmt.Fprintf(b, `for i := range x.%s {
|
||||
currentLen += compressionLenHelper(c, x.%s[i], currentLen)
|
||||
}
|
||||
`, st.Field(i).Name(), st.Field(i).Name())
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case st.Tag(i) == `dns:"cdomain-name"`:
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"domain-name"`:
|
||||
out(st.Field(i).Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(b, "}\nreturn currentLen - initLen\n}\n\n")
|
||||
|
||||
// compressionLenSearchType - search cdomain-tags types for compressible names.
|
||||
|
||||
fmt.Fprint(b, "func compressionLenSearchType(c map[string]int, r RR) (int, bool, int) {\n")
|
||||
fmt.Fprint(b, "switch x := r.(type) {\n")
|
||||
for _, name := range cdomainTypes {
|
||||
o := scope.Lookup(name)
|
||||
st, _ := getTypeStruct(o.Type(), scope)
|
||||
|
||||
fmt.Fprintf(b, "case *%s:\n", name)
|
||||
j := 1
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
out := func(s string, j int) {
|
||||
fmt.Fprintf(b, "k%d, ok%d, sz%d := compressionLenSearch(c, x.%s)\n", j, j, j, st.Field(i).Name())
|
||||
}
|
||||
|
||||
// There are no slice types with names that can be compressed.
|
||||
|
||||
switch {
|
||||
case st.Tag(i) == `dns:"cdomain-name"`:
|
||||
out(st.Field(i).Name(), j)
|
||||
j++
|
||||
}
|
||||
}
|
||||
k := "k1"
|
||||
ok := "ok1"
|
||||
sz := "sz1"
|
||||
for i := 2; i < j; i++ {
|
||||
k += fmt.Sprintf(" + k%d", i)
|
||||
ok += fmt.Sprintf(" && ok%d", i)
|
||||
sz += fmt.Sprintf(" + sz%d", i)
|
||||
}
|
||||
fmt.Fprintf(b, "return %s, %s, %s\n", k, ok, sz)
|
||||
}
|
||||
fmt.Fprintln(b, "}\nreturn 0, false, 0\n}\n\n")
|
||||
|
||||
// gofmt
|
||||
res, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
b.WriteTo(os.Stderr)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := os.Create("zcompress.go")
|
||||
fatalIfErr(err)
|
||||
defer f.Close()
|
||||
f.Write(res)
|
||||
}
|
||||
|
||||
func fatalIfErr(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
//+build ignore
|
||||
|
||||
// types_generate.go is meant to run with go generate. It will use
|
||||
// go/{importer,types} to track down all the RR struct types. Then for each type
|
||||
// it will generate conversion tables (TypeToRR and TypeToString) and banal
|
||||
// methods (len, Header, copy) based on the struct tags. The generated source is
|
||||
// written to ztypes.go, and is meant to be checked into git.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"go/importer"
|
||||
"go/types"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var packageHdr = `
|
||||
// Code generated by "go run duplicate_generate.go"; DO NOT EDIT.
|
||||
|
||||
package dns
|
||||
|
||||
`
|
||||
|
||||
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
|
||||
st, ok := t.Underlying().(*types.Struct)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
|
||||
return st, false
|
||||
}
|
||||
if st.Field(0).Anonymous() {
|
||||
st, _ := getTypeStruct(st.Field(0).Type(), scope)
|
||||
return st, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Import and type-check the package
|
||||
pkg, err := importer.Default().Import("github.com/miekg/dns")
|
||||
fatalIfErr(err)
|
||||
scope := pkg.Scope()
|
||||
|
||||
// Collect actual types (*X)
|
||||
var namedTypes []string
|
||||
for _, name := range scope.Names() {
|
||||
o := scope.Lookup(name)
|
||||
if o == nil || !o.Exported() {
|
||||
continue
|
||||
}
|
||||
|
||||
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if name == "PrivateRR" || name == "RFC3597" {
|
||||
continue
|
||||
}
|
||||
if name == "OPT" || name == "ANY" || name == "IXFR" || name == "AXFR" {
|
||||
continue
|
||||
}
|
||||
|
||||
namedTypes = append(namedTypes, o.Name())
|
||||
}
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(packageHdr)
|
||||
|
||||
// Generate the giant switch that calls the correct function for each type.
|
||||
fmt.Fprint(b, "// isDuplicateRdata calls the rdata specific functions\n")
|
||||
fmt.Fprint(b, "func isDuplicateRdata(r1, r2 RR) bool {\n")
|
||||
fmt.Fprint(b, "switch r1.Header().Rrtype {\n")
|
||||
|
||||
for _, name := range namedTypes {
|
||||
|
||||
o := scope.Lookup(name)
|
||||
_, isEmbedded := getTypeStruct(o.Type(), scope)
|
||||
if isEmbedded {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "case Type%s:\nreturn isDuplicate%s(r1.(*%s), r2.(*%s))\n", name, name, name, name)
|
||||
}
|
||||
fmt.Fprintf(b, "}\nreturn false\n}\n")
|
||||
|
||||
// Generate the duplicate check for each type.
|
||||
fmt.Fprint(b, "// isDuplicate() functions\n\n")
|
||||
for _, name := range namedTypes {
|
||||
|
||||
o := scope.Lookup(name)
|
||||
st, isEmbedded := getTypeStruct(o.Type(), scope)
|
||||
if isEmbedded {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "func isDuplicate%s(r1, r2 *%s) bool {\n", name, name)
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
field := st.Field(i).Name()
|
||||
o2 := func(s string) { fmt.Fprintf(b, s+"\n", field, field) }
|
||||
o3 := func(s string) { fmt.Fprintf(b, s+"\n", field, field, field) }
|
||||
|
||||
// For some reason, a and aaaa don't pop up as *types.Slice here (mostly like because the are
|
||||
// *indirectly* defined as a slice in the net package).
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok || st.Tag(i) == `dns:"a"` || st.Tag(i) == `dns:"aaaa"` {
|
||||
o2("if len(r1.%s) != len(r2.%s) {\nreturn false\n}")
|
||||
|
||||
if st.Tag(i) == `dns:"cdomain-name"` || st.Tag(i) == `dns:"domain-name"` {
|
||||
o3(`for i := 0; i < len(r1.%s); i++ {
|
||||
if !isDulicateName(r1.%s[i], r2.%s[i]) {
|
||||
return false
|
||||
}
|
||||
}`)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
o3(`for i := 0; i < len(r1.%s); i++ {
|
||||
if r1.%s[i] != r2.%s[i] {
|
||||
return false
|
||||
}
|
||||
}`)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
switch st.Tag(i) {
|
||||
case `dns:"-"`:
|
||||
// ignored
|
||||
case `dns:"cdomain-name"`, `dns:"domain-name"`:
|
||||
o2("if !isDulicateName(r1.%s, r2.%s) {\nreturn false\n}")
|
||||
default:
|
||||
o2("if r1.%s != r2.%s {\nreturn false\n}")
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(b, "return true\n}\n\n")
|
||||
}
|
||||
|
||||
// gofmt
|
||||
res, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
b.WriteTo(os.Stderr)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// write result
|
||||
f, err := os.Create("zduplicate.go")
|
||||
fatalIfErr(err)
|
||||
defer f.Close()
|
||||
f.Write(res)
|
||||
}
|
||||
|
||||
func fatalIfErr(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,348 +0,0 @@
|
|||
//+build ignore
|
||||
|
||||
// msg_generate.go is meant to run with go generate. It will use
|
||||
// go/{importer,types} to track down all the RR struct types. Then for each type
|
||||
// it will generate pack/unpack methods based on the struct tags. The generated source is
|
||||
// written to zmsg.go, and is meant to be checked into git.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"go/importer"
|
||||
"go/types"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var packageHdr = `
|
||||
// Code generated by "go run msg_generate.go"; DO NOT EDIT.
|
||||
|
||||
package dns
|
||||
|
||||
`
|
||||
|
||||
// getTypeStruct will take a type and the package scope, and return the
|
||||
// (innermost) struct if the type is considered a RR type (currently defined as
|
||||
// those structs beginning with a RR_Header, could be redefined as implementing
|
||||
// the RR interface). The bool return value indicates if embedded structs were
|
||||
// resolved.
|
||||
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
|
||||
st, ok := t.Underlying().(*types.Struct)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
|
||||
return st, false
|
||||
}
|
||||
if st.Field(0).Anonymous() {
|
||||
st, _ := getTypeStruct(st.Field(0).Type(), scope)
|
||||
return st, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Import and type-check the package
|
||||
pkg, err := importer.Default().Import("github.com/miekg/dns")
|
||||
fatalIfErr(err)
|
||||
scope := pkg.Scope()
|
||||
|
||||
// Collect actual types (*X)
|
||||
var namedTypes []string
|
||||
for _, name := range scope.Names() {
|
||||
o := scope.Lookup(name)
|
||||
if o == nil || !o.Exported() {
|
||||
continue
|
||||
}
|
||||
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
|
||||
continue
|
||||
}
|
||||
if name == "PrivateRR" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if corresponding TypeX exists
|
||||
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
|
||||
log.Fatalf("Constant Type%s does not exist.", o.Name())
|
||||
}
|
||||
|
||||
namedTypes = append(namedTypes, o.Name())
|
||||
}
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(packageHdr)
|
||||
|
||||
fmt.Fprint(b, "// pack*() functions\n\n")
|
||||
for _, name := range namedTypes {
|
||||
o := scope.Lookup(name)
|
||||
st, _ := getTypeStruct(o.Type(), scope)
|
||||
|
||||
fmt.Fprintf(b, "func (rr *%s) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) {\n", name)
|
||||
fmt.Fprint(b, `off, err := rr.Hdr.pack(msg, off, compression, compress)
|
||||
if err != nil {
|
||||
return off, err
|
||||
}
|
||||
headerEnd := off
|
||||
`)
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
o := func(s string) {
|
||||
fmt.Fprintf(b, s, st.Field(i).Name())
|
||||
fmt.Fprint(b, `if err != nil {
|
||||
return off, err
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
switch st.Tag(i) {
|
||||
case `dns:"-"`: // ignored
|
||||
case `dns:"txt"`:
|
||||
o("off, err = packStringTxt(rr.%s, msg, off)\n")
|
||||
case `dns:"opt"`:
|
||||
o("off, err = packDataOpt(rr.%s, msg, off)\n")
|
||||
case `dns:"nsec"`:
|
||||
o("off, err = packDataNsec(rr.%s, msg, off)\n")
|
||||
case `dns:"domain-name"`:
|
||||
o("off, err = packDataDomainNames(rr.%s, msg, off, compression, compress)\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case st.Tag(i) == `dns:"-"`: // ignored
|
||||
case st.Tag(i) == `dns:"cdomain-name"`:
|
||||
o("off, err = PackDomainName(rr.%s, msg, off, compression, compress)\n")
|
||||
case st.Tag(i) == `dns:"domain-name"`:
|
||||
o("off, err = PackDomainName(rr.%s, msg, off, compression, false)\n")
|
||||
case st.Tag(i) == `dns:"a"`:
|
||||
o("off, err = packDataA(rr.%s, msg, off)\n")
|
||||
case st.Tag(i) == `dns:"aaaa"`:
|
||||
o("off, err = packDataAAAA(rr.%s, msg, off)\n")
|
||||
case st.Tag(i) == `dns:"uint48"`:
|
||||
o("off, err = packUint48(rr.%s, msg, off)\n")
|
||||
case st.Tag(i) == `dns:"txt"`:
|
||||
o("off, err = packString(rr.%s, msg, off)\n")
|
||||
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-base32`): // size-base32 can be packed just like base32
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"base32"`:
|
||||
o("off, err = packStringBase32(rr.%s, msg, off)\n")
|
||||
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`): // size-base64 can be packed just like base64
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"base64"`:
|
||||
o("off, err = packStringBase64(rr.%s, msg, off)\n")
|
||||
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-hex:SaltLength`):
|
||||
// directly write instead of using o() so we get the error check in the correct place
|
||||
field := st.Field(i).Name()
|
||||
fmt.Fprintf(b, `// Only pack salt if value is not "-", i.e. empty
|
||||
if rr.%s != "-" {
|
||||
off, err = packStringHex(rr.%s, msg, off)
|
||||
if err != nil {
|
||||
return off, err
|
||||
}
|
||||
}
|
||||
`, field, field)
|
||||
continue
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-hex`): // size-hex can be packed just like hex
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"hex"`:
|
||||
o("off, err = packStringHex(rr.%s, msg, off)\n")
|
||||
|
||||
case st.Tag(i) == `dns:"octet"`:
|
||||
o("off, err = packStringOctet(rr.%s, msg, off)\n")
|
||||
case st.Tag(i) == "":
|
||||
switch st.Field(i).Type().(*types.Basic).Kind() {
|
||||
case types.Uint8:
|
||||
o("off, err = packUint8(rr.%s, msg, off)\n")
|
||||
case types.Uint16:
|
||||
o("off, err = packUint16(rr.%s, msg, off)\n")
|
||||
case types.Uint32:
|
||||
o("off, err = packUint32(rr.%s, msg, off)\n")
|
||||
case types.Uint64:
|
||||
o("off, err = packUint64(rr.%s, msg, off)\n")
|
||||
case types.String:
|
||||
o("off, err = packString(rr.%s, msg, off)\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name())
|
||||
}
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
}
|
||||
// We have packed everything, only now we know the rdlength of this RR
|
||||
fmt.Fprintln(b, "rr.Header().Rdlength = uint16(off-headerEnd)")
|
||||
fmt.Fprintln(b, "return off, nil }\n")
|
||||
}
|
||||
|
||||
fmt.Fprint(b, "// unpack*() functions\n\n")
|
||||
for _, name := range namedTypes {
|
||||
o := scope.Lookup(name)
|
||||
st, _ := getTypeStruct(o.Type(), scope)
|
||||
|
||||
fmt.Fprintf(b, "func unpack%s(h RR_Header, msg []byte, off int) (RR, int, error) {\n", name)
|
||||
fmt.Fprintf(b, "rr := new(%s)\n", name)
|
||||
fmt.Fprint(b, "rr.Hdr = h\n")
|
||||
fmt.Fprint(b, `if noRdata(h) {
|
||||
return rr, off, nil
|
||||
}
|
||||
var err error
|
||||
rdStart := off
|
||||
_ = rdStart
|
||||
|
||||
`)
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
o := func(s string) {
|
||||
fmt.Fprintf(b, s, st.Field(i).Name())
|
||||
fmt.Fprint(b, `if err != nil {
|
||||
return rr, off, err
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
// size-* are special, because they reference a struct member we should use for the length.
|
||||
if strings.HasPrefix(st.Tag(i), `dns:"size-`) {
|
||||
structMember := structMember(st.Tag(i))
|
||||
structTag := structTag(st.Tag(i))
|
||||
switch structTag {
|
||||
case "hex":
|
||||
fmt.Fprintf(b, "rr.%s, off, err = unpackStringHex(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
||||
case "base32":
|
||||
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase32(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
||||
case "base64":
|
||||
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase64(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
fmt.Fprint(b, `if err != nil {
|
||||
return rr, off, err
|
||||
}
|
||||
`)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
switch st.Tag(i) {
|
||||
case `dns:"-"`: // ignored
|
||||
case `dns:"txt"`:
|
||||
o("rr.%s, off, err = unpackStringTxt(msg, off)\n")
|
||||
case `dns:"opt"`:
|
||||
o("rr.%s, off, err = unpackDataOpt(msg, off)\n")
|
||||
case `dns:"nsec"`:
|
||||
o("rr.%s, off, err = unpackDataNsec(msg, off)\n")
|
||||
case `dns:"domain-name"`:
|
||||
o("rr.%s, off, err = unpackDataDomainNames(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch st.Tag(i) {
|
||||
case `dns:"-"`: // ignored
|
||||
case `dns:"cdomain-name"`:
|
||||
fallthrough
|
||||
case `dns:"domain-name"`:
|
||||
o("rr.%s, off, err = UnpackDomainName(msg, off)\n")
|
||||
case `dns:"a"`:
|
||||
o("rr.%s, off, err = unpackDataA(msg, off)\n")
|
||||
case `dns:"aaaa"`:
|
||||
o("rr.%s, off, err = unpackDataAAAA(msg, off)\n")
|
||||
case `dns:"uint48"`:
|
||||
o("rr.%s, off, err = unpackUint48(msg, off)\n")
|
||||
case `dns:"txt"`:
|
||||
o("rr.%s, off, err = unpackString(msg, off)\n")
|
||||
case `dns:"base32"`:
|
||||
o("rr.%s, off, err = unpackStringBase32(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
||||
case `dns:"base64"`:
|
||||
o("rr.%s, off, err = unpackStringBase64(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
||||
case `dns:"hex"`:
|
||||
o("rr.%s, off, err = unpackStringHex(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
||||
case `dns:"octet"`:
|
||||
o("rr.%s, off, err = unpackStringOctet(msg, off)\n")
|
||||
case "":
|
||||
switch st.Field(i).Type().(*types.Basic).Kind() {
|
||||
case types.Uint8:
|
||||
o("rr.%s, off, err = unpackUint8(msg, off)\n")
|
||||
case types.Uint16:
|
||||
o("rr.%s, off, err = unpackUint16(msg, off)\n")
|
||||
case types.Uint32:
|
||||
o("rr.%s, off, err = unpackUint32(msg, off)\n")
|
||||
case types.Uint64:
|
||||
o("rr.%s, off, err = unpackUint64(msg, off)\n")
|
||||
case types.String:
|
||||
o("rr.%s, off, err = unpackString(msg, off)\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name())
|
||||
}
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
// If we've hit len(msg) we return without error.
|
||||
if i < st.NumFields()-1 {
|
||||
fmt.Fprintf(b, `if off == len(msg) {
|
||||
return rr, off, nil
|
||||
}
|
||||
`)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(b, "return rr, off, err }\n\n")
|
||||
}
|
||||
// Generate typeToUnpack map
|
||||
fmt.Fprintln(b, "var typeToUnpack = map[uint16]func(RR_Header, []byte, int) (RR, int, error){")
|
||||
for _, name := range namedTypes {
|
||||
if name == "RFC3597" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "Type%s: unpack%s,\n", name, name)
|
||||
}
|
||||
fmt.Fprintln(b, "}\n")
|
||||
|
||||
// gofmt
|
||||
res, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
b.WriteTo(os.Stderr)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// write result
|
||||
f, err := os.Create("zmsg.go")
|
||||
fatalIfErr(err)
|
||||
defer f.Close()
|
||||
f.Write(res)
|
||||
}
|
||||
|
||||
// structMember will take a tag like dns:"size-base32:SaltLength" and return the last part of this string.
|
||||
func structMember(s string) string {
|
||||
fields := strings.Split(s, ":")
|
||||
if len(fields) == 0 {
|
||||
return ""
|
||||
}
|
||||
f := fields[len(fields)-1]
|
||||
// f should have a closing "
|
||||
if len(f) > 1 {
|
||||
return f[:len(f)-1]
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// structTag will take a tag like dns:"size-base32:SaltLength" and return base32.
|
||||
func structTag(s string) string {
|
||||
fields := strings.Split(s, ":")
|
||||
if len(fields) < 2 {
|
||||
return ""
|
||||
}
|
||||
return fields[1][len("\"size-"):]
|
||||
}
|
||||
|
||||
func fatalIfErr(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,272 +0,0 @@
|
|||
//+build ignore
|
||||
|
||||
// types_generate.go is meant to run with go generate. It will use
|
||||
// go/{importer,types} to track down all the RR struct types. Then for each type
|
||||
// it will generate conversion tables (TypeToRR and TypeToString) and banal
|
||||
// methods (len, Header, copy) based on the struct tags. The generated source is
|
||||
// written to ztypes.go, and is meant to be checked into git.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"go/importer"
|
||||
"go/types"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var skipLen = map[string]struct{}{
|
||||
"NSEC": {},
|
||||
"NSEC3": {},
|
||||
"OPT": {},
|
||||
"CSYNC": {},
|
||||
}
|
||||
|
||||
var packageHdr = `
|
||||
// Code generated by "go run types_generate.go"; DO NOT EDIT.
|
||||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net"
|
||||
)
|
||||
|
||||
`
|
||||
|
||||
var TypeToRR = template.Must(template.New("TypeToRR").Parse(`
|
||||
// TypeToRR is a map of constructors for each RR type.
|
||||
var TypeToRR = map[uint16]func() RR{
|
||||
{{range .}}{{if ne . "RFC3597"}} Type{{.}}: func() RR { return new({{.}}) },
|
||||
{{end}}{{end}} }
|
||||
|
||||
`))
|
||||
|
||||
var typeToString = template.Must(template.New("typeToString").Parse(`
|
||||
// TypeToString is a map of strings for each RR type.
|
||||
var TypeToString = map[uint16]string{
|
||||
{{range .}}{{if ne . "NSAPPTR"}} Type{{.}}: "{{.}}",
|
||||
{{end}}{{end}} TypeNSAPPTR: "NSAP-PTR",
|
||||
}
|
||||
|
||||
`))
|
||||
|
||||
var headerFunc = template.Must(template.New("headerFunc").Parse(`
|
||||
{{range .}} func (rr *{{.}}) Header() *RR_Header { return &rr.Hdr }
|
||||
{{end}}
|
||||
|
||||
`))
|
||||
|
||||
// getTypeStruct will take a type and the package scope, and return the
|
||||
// (innermost) struct if the type is considered a RR type (currently defined as
|
||||
// those structs beginning with a RR_Header, could be redefined as implementing
|
||||
// the RR interface). The bool return value indicates if embedded structs were
|
||||
// resolved.
|
||||
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
|
||||
st, ok := t.Underlying().(*types.Struct)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
|
||||
return st, false
|
||||
}
|
||||
if st.Field(0).Anonymous() {
|
||||
st, _ := getTypeStruct(st.Field(0).Type(), scope)
|
||||
return st, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Import and type-check the package
|
||||
pkg, err := importer.Default().Import("github.com/miekg/dns")
|
||||
fatalIfErr(err)
|
||||
scope := pkg.Scope()
|
||||
|
||||
// Collect constants like TypeX
|
||||
var numberedTypes []string
|
||||
for _, name := range scope.Names() {
|
||||
o := scope.Lookup(name)
|
||||
if o == nil || !o.Exported() {
|
||||
continue
|
||||
}
|
||||
b, ok := o.Type().(*types.Basic)
|
||||
if !ok || b.Kind() != types.Uint16 {
|
||||
continue
|
||||
}
|
||||
if !strings.HasPrefix(o.Name(), "Type") {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimPrefix(o.Name(), "Type")
|
||||
if name == "PrivateRR" {
|
||||
continue
|
||||
}
|
||||
numberedTypes = append(numberedTypes, name)
|
||||
}
|
||||
|
||||
// Collect actual types (*X)
|
||||
var namedTypes []string
|
||||
for _, name := range scope.Names() {
|
||||
o := scope.Lookup(name)
|
||||
if o == nil || !o.Exported() {
|
||||
continue
|
||||
}
|
||||
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
|
||||
continue
|
||||
}
|
||||
if name == "PrivateRR" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if corresponding TypeX exists
|
||||
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
|
||||
log.Fatalf("Constant Type%s does not exist.", o.Name())
|
||||
}
|
||||
|
||||
namedTypes = append(namedTypes, o.Name())
|
||||
}
|
||||
|
||||
b := &bytes.Buffer{}
|
||||
b.WriteString(packageHdr)
|
||||
|
||||
// Generate TypeToRR
|
||||
fatalIfErr(TypeToRR.Execute(b, namedTypes))
|
||||
|
||||
// Generate typeToString
|
||||
fatalIfErr(typeToString.Execute(b, numberedTypes))
|
||||
|
||||
// Generate headerFunc
|
||||
fatalIfErr(headerFunc.Execute(b, namedTypes))
|
||||
|
||||
// Generate len()
|
||||
fmt.Fprint(b, "// len() functions\n")
|
||||
for _, name := range namedTypes {
|
||||
if _, ok := skipLen[name]; ok {
|
||||
continue
|
||||
}
|
||||
o := scope.Lookup(name)
|
||||
st, isEmbedded := getTypeStruct(o.Type(), scope)
|
||||
if isEmbedded {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "func (rr *%s) len() int {\n", name)
|
||||
fmt.Fprintf(b, "l := rr.Hdr.len()\n")
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
o := func(s string) { fmt.Fprintf(b, s, st.Field(i).Name()) }
|
||||
|
||||
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
switch st.Tag(i) {
|
||||
case `dns:"-"`:
|
||||
// ignored
|
||||
case `dns:"cdomain-name"`, `dns:"domain-name"`, `dns:"txt"`:
|
||||
o("for _, x := range rr.%s { l += len(x) + 1 }\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch {
|
||||
case st.Tag(i) == `dns:"-"`:
|
||||
// ignored
|
||||
case st.Tag(i) == `dns:"cdomain-name"`, st.Tag(i) == `dns:"domain-name"`:
|
||||
o("l += len(rr.%s) + 1\n")
|
||||
case st.Tag(i) == `dns:"octet"`:
|
||||
o("l += len(rr.%s)\n")
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`):
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"base64"`:
|
||||
o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n")
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-hex:`): // this has an extra field where the length is stored
|
||||
o("l += len(rr.%s)/2\n")
|
||||
case strings.HasPrefix(st.Tag(i), `dns:"size-hex`):
|
||||
fallthrough
|
||||
case st.Tag(i) == `dns:"hex"`:
|
||||
o("l += len(rr.%s)/2 + 1\n")
|
||||
case st.Tag(i) == `dns:"a"`:
|
||||
o("l += net.IPv4len // %s\n")
|
||||
case st.Tag(i) == `dns:"aaaa"`:
|
||||
o("l += net.IPv6len // %s\n")
|
||||
case st.Tag(i) == `dns:"txt"`:
|
||||
o("for _, t := range rr.%s { l += len(t) + 1 }\n")
|
||||
case st.Tag(i) == `dns:"uint48"`:
|
||||
o("l += 6 // %s\n")
|
||||
case st.Tag(i) == "":
|
||||
switch st.Field(i).Type().(*types.Basic).Kind() {
|
||||
case types.Uint8:
|
||||
o("l++ // %s\n")
|
||||
case types.Uint16:
|
||||
o("l += 2 // %s\n")
|
||||
case types.Uint32:
|
||||
o("l += 4 // %s\n")
|
||||
case types.Uint64:
|
||||
o("l += 8 // %s\n")
|
||||
case types.String:
|
||||
o("l += len(rr.%s) + 1\n")
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name())
|
||||
}
|
||||
default:
|
||||
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(b, "return l }\n")
|
||||
}
|
||||
|
||||
// Generate copy()
|
||||
fmt.Fprint(b, "// copy() functions\n")
|
||||
for _, name := range namedTypes {
|
||||
o := scope.Lookup(name)
|
||||
st, isEmbedded := getTypeStruct(o.Type(), scope)
|
||||
if isEmbedded {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "func (rr *%s) copy() RR {\n", name)
|
||||
fields := []string{"rr.Hdr"}
|
||||
for i := 1; i < st.NumFields(); i++ {
|
||||
f := st.Field(i).Name()
|
||||
if sl, ok := st.Field(i).Type().(*types.Slice); ok {
|
||||
t := sl.Underlying().String()
|
||||
t = strings.TrimPrefix(t, "[]")
|
||||
if strings.Contains(t, ".") {
|
||||
splits := strings.Split(t, ".")
|
||||
t = splits[len(splits)-1]
|
||||
}
|
||||
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s)); copy(%s, rr.%s)\n",
|
||||
f, t, f, f, f)
|
||||
fields = append(fields, f)
|
||||
continue
|
||||
}
|
||||
if st.Field(i).Type().String() == "net.IP" {
|
||||
fields = append(fields, "copyIP(rr."+f+")")
|
||||
continue
|
||||
}
|
||||
fields = append(fields, "rr."+f)
|
||||
}
|
||||
fmt.Fprintf(b, "return &%s{%s}\n", name, strings.Join(fields, ","))
|
||||
fmt.Fprintf(b, "}\n")
|
||||
}
|
||||
|
||||
// gofmt
|
||||
res, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
b.WriteTo(os.Stderr)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// write result
|
||||
f, err := os.Create("ztypes.go")
|
||||
fatalIfErr(err)
|
||||
defer f.Close()
|
||||
f.Write(res)
|
||||
}
|
||||
|
||||
func fatalIfErr(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,6 @@ go_library(
|
|||
srcs = ["metric.go"],
|
||||
importmap = "k8s.io/kops/vendor/github.com/prometheus/client_golang/prometheus/internal",
|
||||
importpath = "github.com/prometheus/client_golang/prometheus/internal",
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//vendor/github.com/prometheus/client_golang/prometheus:__subpackages__"],
|
||||
deps = ["//vendor/github.com/prometheus/client_model/go:go_default_library"],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ go_library(
|
|||
importpath = "golang.org/x/crypto/ssh/terminal",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = select({
|
||||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:darwin": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
|
|
@ -24,6 +27,9 @@ go_library(
|
|||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,383 +0,0 @@
|
|||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
// This program generates internet protocol constants and tables by
|
||||
// reading IANA protocol registries.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var registries = []struct {
|
||||
url string
|
||||
parse func(io.Writer, io.Reader) error
|
||||
}{
|
||||
{
|
||||
"https://www.iana.org/assignments/dscp-registry/dscp-registry.xml",
|
||||
parseDSCPRegistry,
|
||||
},
|
||||
{
|
||||
"https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml",
|
||||
parseProtocolNumbers,
|
||||
},
|
||||
{
|
||||
"https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml",
|
||||
parseAddrFamilyNumbers,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
var bb bytes.Buffer
|
||||
fmt.Fprintf(&bb, "// go generate gen.go\n")
|
||||
fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(&bb, "// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).\n")
|
||||
fmt.Fprintf(&bb, `package iana // import "golang.org/x/net/internal/iana"`+"\n\n")
|
||||
for _, r := range registries {
|
||||
resp, err := http.Get(r.url)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Fprintf(os.Stderr, "got HTTP status code %v for %v\n", resp.StatusCode, r.url)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := r.parse(&bb, resp.Body); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintf(&bb, "\n")
|
||||
}
|
||||
b, err := format.Source(bb.Bytes())
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := ioutil.WriteFile("const.go", b, 0644); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func parseDSCPRegistry(w io.Writer, r io.Reader) error {
|
||||
dec := xml.NewDecoder(r)
|
||||
var dr dscpRegistry
|
||||
if err := dec.Decode(&dr); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", dr.Title, dr.Updated)
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, dr := range dr.escapeDSCP() {
|
||||
fmt.Fprintf(w, "DiffServ%s = %#02x", dr.Name, dr.Value)
|
||||
fmt.Fprintf(w, "// %s\n", dr.OrigName)
|
||||
}
|
||||
for _, er := range dr.escapeECN() {
|
||||
fmt.Fprintf(w, "%s = %#02x", er.Descr, er.Value)
|
||||
fmt.Fprintf(w, "// %s\n", er.OrigDescr)
|
||||
}
|
||||
fmt.Fprintf(w, ")\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type dscpRegistry struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Title string `xml:"title"`
|
||||
Updated string `xml:"updated"`
|
||||
Note string `xml:"note"`
|
||||
Registries []struct {
|
||||
Title string `xml:"title"`
|
||||
Registries []struct {
|
||||
Title string `xml:"title"`
|
||||
Records []struct {
|
||||
Name string `xml:"name"`
|
||||
Space string `xml:"space"`
|
||||
} `xml:"record"`
|
||||
} `xml:"registry"`
|
||||
Records []struct {
|
||||
Value string `xml:"value"`
|
||||
Descr string `xml:"description"`
|
||||
} `xml:"record"`
|
||||
} `xml:"registry"`
|
||||
}
|
||||
|
||||
type canonDSCPRecord struct {
|
||||
OrigName string
|
||||
Name string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (drr *dscpRegistry) escapeDSCP() []canonDSCPRecord {
|
||||
var drs []canonDSCPRecord
|
||||
for _, preg := range drr.Registries {
|
||||
if !strings.Contains(preg.Title, "Differentiated Services Field Codepoints") {
|
||||
continue
|
||||
}
|
||||
for _, reg := range preg.Registries {
|
||||
if !strings.Contains(reg.Title, "Pool 1 Codepoints") {
|
||||
continue
|
||||
}
|
||||
drs = make([]canonDSCPRecord, len(reg.Records))
|
||||
sr := strings.NewReplacer(
|
||||
"+", "",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, dr := range reg.Records {
|
||||
s := strings.TrimSpace(dr.Name)
|
||||
drs[i].OrigName = s
|
||||
drs[i].Name = sr.Replace(s)
|
||||
n, err := strconv.ParseUint(dr.Space, 2, 8)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
drs[i].Value = int(n) << 2
|
||||
}
|
||||
}
|
||||
}
|
||||
return drs
|
||||
}
|
||||
|
||||
type canonECNRecord struct {
|
||||
OrigDescr string
|
||||
Descr string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (drr *dscpRegistry) escapeECN() []canonECNRecord {
|
||||
var ers []canonECNRecord
|
||||
for _, reg := range drr.Registries {
|
||||
if !strings.Contains(reg.Title, "ECN Field") {
|
||||
continue
|
||||
}
|
||||
ers = make([]canonECNRecord, len(reg.Records))
|
||||
sr := strings.NewReplacer(
|
||||
"Capable", "",
|
||||
"Not-ECT", "",
|
||||
"ECT(1)", "",
|
||||
"ECT(0)", "",
|
||||
"CE", "",
|
||||
"(", "",
|
||||
")", "",
|
||||
"+", "",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, er := range reg.Records {
|
||||
s := strings.TrimSpace(er.Descr)
|
||||
ers[i].OrigDescr = s
|
||||
ss := strings.Split(s, " ")
|
||||
if len(ss) > 1 {
|
||||
ers[i].Descr = strings.Join(ss[1:], " ")
|
||||
} else {
|
||||
ers[i].Descr = ss[0]
|
||||
}
|
||||
ers[i].Descr = sr.Replace(er.Descr)
|
||||
n, err := strconv.ParseUint(er.Value, 2, 8)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ers[i].Value = int(n)
|
||||
}
|
||||
}
|
||||
return ers
|
||||
}
|
||||
|
||||
func parseProtocolNumbers(w io.Writer, r io.Reader) error {
|
||||
dec := xml.NewDecoder(r)
|
||||
var pn protocolNumbers
|
||||
if err := dec.Decode(&pn); err != nil {
|
||||
return err
|
||||
}
|
||||
prs := pn.escape()
|
||||
prs = append([]canonProtocolRecord{{
|
||||
Name: "IP",
|
||||
Descr: "IPv4 encapsulation, pseudo protocol number",
|
||||
Value: 0,
|
||||
}}, prs...)
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", pn.Title, pn.Updated)
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, pr := range prs {
|
||||
if pr.Name == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "Protocol%s = %d", pr.Name, pr.Value)
|
||||
s := pr.Descr
|
||||
if s == "" {
|
||||
s = pr.OrigName
|
||||
}
|
||||
fmt.Fprintf(w, "// %s\n", s)
|
||||
}
|
||||
fmt.Fprintf(w, ")\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type protocolNumbers struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Title string `xml:"title"`
|
||||
Updated string `xml:"updated"`
|
||||
RegTitle string `xml:"registry>title"`
|
||||
Note string `xml:"registry>note"`
|
||||
Records []struct {
|
||||
Value string `xml:"value"`
|
||||
Name string `xml:"name"`
|
||||
Descr string `xml:"description"`
|
||||
} `xml:"registry>record"`
|
||||
}
|
||||
|
||||
type canonProtocolRecord struct {
|
||||
OrigName string
|
||||
Name string
|
||||
Descr string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (pn *protocolNumbers) escape() []canonProtocolRecord {
|
||||
prs := make([]canonProtocolRecord, len(pn.Records))
|
||||
sr := strings.NewReplacer(
|
||||
"-in-", "in",
|
||||
"-within-", "within",
|
||||
"-over-", "over",
|
||||
"+", "P",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, pr := range pn.Records {
|
||||
if strings.Contains(pr.Name, "Deprecated") ||
|
||||
strings.Contains(pr.Name, "deprecated") {
|
||||
continue
|
||||
}
|
||||
prs[i].OrigName = pr.Name
|
||||
s := strings.TrimSpace(pr.Name)
|
||||
switch pr.Name {
|
||||
case "ISIS over IPv4":
|
||||
prs[i].Name = "ISIS"
|
||||
case "manet":
|
||||
prs[i].Name = "MANET"
|
||||
default:
|
||||
prs[i].Name = sr.Replace(s)
|
||||
}
|
||||
ss := strings.Split(pr.Descr, "\n")
|
||||
for i := range ss {
|
||||
ss[i] = strings.TrimSpace(ss[i])
|
||||
}
|
||||
if len(ss) > 1 {
|
||||
prs[i].Descr = strings.Join(ss, " ")
|
||||
} else {
|
||||
prs[i].Descr = ss[0]
|
||||
}
|
||||
prs[i].Value, _ = strconv.Atoi(pr.Value)
|
||||
}
|
||||
return prs
|
||||
}
|
||||
|
||||
func parseAddrFamilyNumbers(w io.Writer, r io.Reader) error {
|
||||
dec := xml.NewDecoder(r)
|
||||
var afn addrFamilylNumbers
|
||||
if err := dec.Decode(&afn); err != nil {
|
||||
return err
|
||||
}
|
||||
afrs := afn.escape()
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", afn.Title, afn.Updated)
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, afr := range afrs {
|
||||
if afr.Name == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "AddrFamily%s = %d", afr.Name, afr.Value)
|
||||
fmt.Fprintf(w, "// %s\n", afr.Descr)
|
||||
}
|
||||
fmt.Fprintf(w, ")\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type addrFamilylNumbers struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Title string `xml:"title"`
|
||||
Updated string `xml:"updated"`
|
||||
RegTitle string `xml:"registry>title"`
|
||||
Note string `xml:"registry>note"`
|
||||
Records []struct {
|
||||
Value string `xml:"value"`
|
||||
Descr string `xml:"description"`
|
||||
} `xml:"registry>record"`
|
||||
}
|
||||
|
||||
type canonAddrFamilyRecord struct {
|
||||
Name string
|
||||
Descr string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (afn *addrFamilylNumbers) escape() []canonAddrFamilyRecord {
|
||||
afrs := make([]canonAddrFamilyRecord, len(afn.Records))
|
||||
sr := strings.NewReplacer(
|
||||
"IP version 4", "IPv4",
|
||||
"IP version 6", "IPv6",
|
||||
"Identifier", "ID",
|
||||
"-", "",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, afr := range afn.Records {
|
||||
if strings.Contains(afr.Descr, "Unassigned") ||
|
||||
strings.Contains(afr.Descr, "Reserved") {
|
||||
continue
|
||||
}
|
||||
afrs[i].Descr = afr.Descr
|
||||
s := strings.TrimSpace(afr.Descr)
|
||||
switch s {
|
||||
case "IP (IP version 4)":
|
||||
afrs[i].Name = "IPv4"
|
||||
case "IP6 (IP version 6)":
|
||||
afrs[i].Name = "IPv6"
|
||||
case "AFI for L2VPN information":
|
||||
afrs[i].Name = "L2VPN"
|
||||
case "E.164 with NSAP format subaddress":
|
||||
afrs[i].Name = "E164withSubaddress"
|
||||
case "MT IP: Multi-Topology IP version 4":
|
||||
afrs[i].Name = "MTIPv4"
|
||||
case "MAC/24":
|
||||
afrs[i].Name = "MACFinal24bits"
|
||||
case "MAC/40":
|
||||
afrs[i].Name = "MACFinal40bits"
|
||||
case "IPv6/64":
|
||||
afrs[i].Name = "IPv6Initial64bits"
|
||||
default:
|
||||
n := strings.Index(s, "(")
|
||||
if n > 0 {
|
||||
s = s[:n]
|
||||
}
|
||||
n = strings.Index(s, ":")
|
||||
if n > 0 {
|
||||
s = s[:n]
|
||||
}
|
||||
afrs[i].Name = sr.Replace(s)
|
||||
}
|
||||
afrs[i].Value, _ = strconv.Atoi(afr.Value)
|
||||
}
|
||||
return afrs
|
||||
}
|
||||
|
|
@ -89,7 +89,6 @@ go_library(
|
|||
"zsys_openbsd_arm.go",
|
||||
"zsys_solaris_amd64.go",
|
||||
],
|
||||
cgo = True,
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/net/internal/socket",
|
||||
importpath = "golang.org/x/net/internal/socket",
|
||||
visibility = ["//vendor/golang.org/x/net:__subpackages__"],
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <linux/in.h>
|
||||
#include <linux/in6.h>
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/socket.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type mmsghdr C.struct_mmsghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofMmsghdr = C.sizeof_struct_mmsghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type mmsghdr C.struct_mmsghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofMmsghdr = C.sizeof_struct_mmsghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
|
|
@ -68,7 +68,6 @@ go_library(
|
|||
"zsys_openbsd.go",
|
||||
"zsys_solaris.go",
|
||||
],
|
||||
cgo = True,
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/net/ipv4",
|
||||
importpath = "golang.org/x/net/ipv4",
|
||||
visibility = ["//visibility:public"],
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_STRIPHDR = C.IP_STRIPHDR
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
sysIP_BOUND_IF = C.IP_BOUND_IF
|
||||
sysIP_PKTINFO = C.IP_PKTINFO
|
||||
sysIP_RECVPKTINFO = C.IP_RECVPKTINFO
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF
|
||||
sysIP_MULTICAST_IFINDEX = C.IP_MULTICAST_IFINDEX
|
||||
sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP
|
||||
sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP
|
||||
sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE
|
||||
sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofInetPktinfo = C.sizeof_struct_in_pktinfo
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
sizeofIPMreqn = C.sizeof_struct_ip_mreqn
|
||||
sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type inetPktinfo C.struct_in_pktinfo
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
||||
type ipMreqn C.struct_ip_mreqn
|
||||
|
||||
type ipMreqSource C.struct_ip_mreq_source
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
)
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_SENDSRCADDR = C.IP_SENDSRCADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_ONESBCAST = C.IP_ONESBCAST
|
||||
sysIP_BINDANY = C.IP_BINDANY
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
sysIP_MINTTL = C.IP_MINTTL
|
||||
sysIP_DONTFRAG = C.IP_DONTFRAG
|
||||
sysIP_RECVTOS = C.IP_RECVTOS
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
sysIP_MULTICAST_VIF = C.IP_MULTICAST_VIF
|
||||
sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP
|
||||
sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP
|
||||
sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE
|
||||
sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
sizeofIPMreqn = C.sizeof_struct_ip_mreqn
|
||||
sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
||||
type ipMreqn C.struct_ip_mreqn
|
||||
|
||||
type ipMreqSource C.struct_ip_mreq_source
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <time.h>
|
||||
|
||||
#include <linux/errqueue.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/filter.h>
|
||||
#include <sys/socket.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_ROUTER_ALERT = C.IP_ROUTER_ALERT
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_PKTINFO = C.IP_PKTINFO
|
||||
sysIP_PKTOPTIONS = C.IP_PKTOPTIONS
|
||||
sysIP_MTU_DISCOVER = C.IP_MTU_DISCOVER
|
||||
sysIP_RECVERR = C.IP_RECVERR
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
sysIP_RECVTOS = C.IP_RECVTOS
|
||||
sysIP_MTU = C.IP_MTU
|
||||
sysIP_FREEBIND = C.IP_FREEBIND
|
||||
sysIP_TRANSPARENT = C.IP_TRANSPARENT
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_ORIGDSTADDR = C.IP_ORIGDSTADDR
|
||||
sysIP_RECVORIGDSTADDR = C.IP_RECVORIGDSTADDR
|
||||
sysIP_MINTTL = C.IP_MINTTL
|
||||
sysIP_NODEFRAG = C.IP_NODEFRAG
|
||||
sysIP_UNICAST_IF = C.IP_UNICAST_IF
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE
|
||||
sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE
|
||||
sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP
|
||||
sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP
|
||||
sysIP_MSFILTER = C.IP_MSFILTER
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
sysMCAST_MSFILTER = C.MCAST_MSFILTER
|
||||
sysIP_MULTICAST_ALL = C.IP_MULTICAST_ALL
|
||||
|
||||
//sysIP_PMTUDISC_DONT = C.IP_PMTUDISC_DONT
|
||||
//sysIP_PMTUDISC_WANT = C.IP_PMTUDISC_WANT
|
||||
//sysIP_PMTUDISC_DO = C.IP_PMTUDISC_DO
|
||||
//sysIP_PMTUDISC_PROBE = C.IP_PMTUDISC_PROBE
|
||||
//sysIP_PMTUDISC_INTERFACE = C.IP_PMTUDISC_INTERFACE
|
||||
//sysIP_PMTUDISC_OMIT = C.IP_PMTUDISC_OMIT
|
||||
|
||||
sysICMP_FILTER = C.ICMP_FILTER
|
||||
|
||||
sysSO_EE_ORIGIN_NONE = C.SO_EE_ORIGIN_NONE
|
||||
sysSO_EE_ORIGIN_LOCAL = C.SO_EE_ORIGIN_LOCAL
|
||||
sysSO_EE_ORIGIN_ICMP = C.SO_EE_ORIGIN_ICMP
|
||||
sysSO_EE_ORIGIN_ICMP6 = C.SO_EE_ORIGIN_ICMP6
|
||||
sysSO_EE_ORIGIN_TXSTATUS = C.SO_EE_ORIGIN_TXSTATUS
|
||||
sysSO_EE_ORIGIN_TIMESTAMPING = C.SO_EE_ORIGIN_TIMESTAMPING
|
||||
|
||||
sysSOL_SOCKET = C.SOL_SOCKET
|
||||
sysSO_ATTACH_FILTER = C.SO_ATTACH_FILTER
|
||||
|
||||
sizeofKernelSockaddrStorage = C.sizeof_struct___kernel_sockaddr_storage
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofInetPktinfo = C.sizeof_struct_in_pktinfo
|
||||
sizeofSockExtendedErr = C.sizeof_struct_sock_extended_err
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
sizeofIPMreqn = C.sizeof_struct_ip_mreqn
|
||||
sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPFilter = C.sizeof_struct_icmp_filter
|
||||
|
||||
sizeofSockFprog = C.sizeof_struct_sock_fprog
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage C.struct___kernel_sockaddr_storage
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type inetPktinfo C.struct_in_pktinfo
|
||||
|
||||
type sockExtendedErr C.struct_sock_extended_err
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
||||
type ipMreqn C.struct_ip_mreqn
|
||||
|
||||
type ipMreqSource C.struct_ip_mreq_source
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
||||
type icmpFilter C.struct_icmp_filter
|
||||
|
||||
type sockFProg C.struct_sock_fprog
|
||||
|
||||
type sockFilter C.struct_sock_filter
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
)
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
)
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
|
||||
package ipv4
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIP_OPTIONS = C.IP_OPTIONS
|
||||
sysIP_HDRINCL = C.IP_HDRINCL
|
||||
sysIP_TOS = C.IP_TOS
|
||||
sysIP_TTL = C.IP_TTL
|
||||
sysIP_RECVOPTS = C.IP_RECVOPTS
|
||||
sysIP_RECVRETOPTS = C.IP_RECVRETOPTS
|
||||
sysIP_RECVDSTADDR = C.IP_RECVDSTADDR
|
||||
sysIP_RETOPTS = C.IP_RETOPTS
|
||||
sysIP_RECVIF = C.IP_RECVIF
|
||||
sysIP_RECVSLLA = C.IP_RECVSLLA
|
||||
sysIP_RECVTTL = C.IP_RECVTTL
|
||||
|
||||
sysIP_MULTICAST_IF = C.IP_MULTICAST_IF
|
||||
sysIP_MULTICAST_TTL = C.IP_MULTICAST_TTL
|
||||
sysIP_MULTICAST_LOOP = C.IP_MULTICAST_LOOP
|
||||
sysIP_ADD_MEMBERSHIP = C.IP_ADD_MEMBERSHIP
|
||||
sysIP_DROP_MEMBERSHIP = C.IP_DROP_MEMBERSHIP
|
||||
sysIP_BLOCK_SOURCE = C.IP_BLOCK_SOURCE
|
||||
sysIP_UNBLOCK_SOURCE = C.IP_UNBLOCK_SOURCE
|
||||
sysIP_ADD_SOURCE_MEMBERSHIP = C.IP_ADD_SOURCE_MEMBERSHIP
|
||||
sysIP_DROP_SOURCE_MEMBERSHIP = C.IP_DROP_SOURCE_MEMBERSHIP
|
||||
sysIP_NEXTHOP = C.IP_NEXTHOP
|
||||
|
||||
sysIP_PKTINFO = C.IP_PKTINFO
|
||||
sysIP_RECVPKTINFO = C.IP_RECVPKTINFO
|
||||
sysIP_DONTFRAG = C.IP_DONTFRAG
|
||||
|
||||
sysIP_BOUND_IF = C.IP_BOUND_IF
|
||||
sysIP_UNSPEC_SRC = C.IP_UNSPEC_SRC
|
||||
sysIP_BROADCAST_TTL = C.IP_BROADCAST_TTL
|
||||
sysIP_DHCPINIT_IF = C.IP_DHCPINIT_IF
|
||||
|
||||
sysIP_REUSEADDR = C.IP_REUSEADDR
|
||||
sysIP_DONTROUTE = C.IP_DONTROUTE
|
||||
sysIP_BROADCAST = C.IP_BROADCAST
|
||||
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofInetPktinfo = C.sizeof_struct_in_pktinfo
|
||||
|
||||
sizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
sizeofIPMreqSource = C.sizeof_struct_ip_mreq_source
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type inetPktinfo C.struct_in_pktinfo
|
||||
|
||||
type ipMreq C.struct_ip_mreq
|
||||
|
||||
type ipMreqSource C.struct_ip_mreq_source
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
// This program generates system adaptation constants and types,
|
||||
// internet protocol constants and tables by reading template files
|
||||
// and IANA protocol registries.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := genzsys(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := geniana(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func genzsys() error {
|
||||
defs := "defs_" + runtime.GOOS + ".go"
|
||||
f, err := os.Open(defs)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
f.Close()
|
||||
cmd := exec.Command("go", "tool", "cgo", "-godefs", defs)
|
||||
b, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err = format.Source(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
zsys := "zsys_" + runtime.GOOS + ".go"
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
zsys = "zsys_" + runtime.GOOS + "_" + runtime.GOARCH + ".go"
|
||||
}
|
||||
if err := ioutil.WriteFile(zsys, b, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var registries = []struct {
|
||||
url string
|
||||
parse func(io.Writer, io.Reader) error
|
||||
}{
|
||||
{
|
||||
"https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xml",
|
||||
parseICMPv4Parameters,
|
||||
},
|
||||
}
|
||||
|
||||
func geniana() error {
|
||||
var bb bytes.Buffer
|
||||
fmt.Fprintf(&bb, "// go generate gen.go\n")
|
||||
fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(&bb, "package ipv4\n\n")
|
||||
for _, r := range registries {
|
||||
resp, err := http.Get(r.url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("got HTTP status code %v for %v\n", resp.StatusCode, r.url)
|
||||
}
|
||||
if err := r.parse(&bb, resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(&bb, "\n")
|
||||
}
|
||||
b, err := format.Source(bb.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile("iana.go", b, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseICMPv4Parameters(w io.Writer, r io.Reader) error {
|
||||
dec := xml.NewDecoder(r)
|
||||
var icp icmpv4Parameters
|
||||
if err := dec.Decode(&icp); err != nil {
|
||||
return err
|
||||
}
|
||||
prs := icp.escape()
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated)
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, pr := range prs {
|
||||
if pr.Descr == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "ICMPType%s ICMPType = %d", pr.Descr, pr.Value)
|
||||
fmt.Fprintf(w, "// %s\n", pr.OrigDescr)
|
||||
}
|
||||
fmt.Fprintf(w, ")\n\n")
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated)
|
||||
fmt.Fprintf(w, "var icmpTypes = map[ICMPType]string{\n")
|
||||
for _, pr := range prs {
|
||||
if pr.Descr == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "%d: %q,\n", pr.Value, strings.ToLower(pr.OrigDescr))
|
||||
}
|
||||
fmt.Fprintf(w, "}\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type icmpv4Parameters struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Title string `xml:"title"`
|
||||
Updated string `xml:"updated"`
|
||||
Registries []struct {
|
||||
Title string `xml:"title"`
|
||||
Records []struct {
|
||||
Value string `xml:"value"`
|
||||
Descr string `xml:"description"`
|
||||
} `xml:"record"`
|
||||
} `xml:"registry"`
|
||||
}
|
||||
|
||||
type canonICMPv4ParamRecord struct {
|
||||
OrigDescr string
|
||||
Descr string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (icp *icmpv4Parameters) escape() []canonICMPv4ParamRecord {
|
||||
id := -1
|
||||
for i, r := range icp.Registries {
|
||||
if strings.Contains(r.Title, "Type") || strings.Contains(r.Title, "type") {
|
||||
id = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if id < 0 {
|
||||
return nil
|
||||
}
|
||||
prs := make([]canonICMPv4ParamRecord, len(icp.Registries[id].Records))
|
||||
sr := strings.NewReplacer(
|
||||
"Messages", "",
|
||||
"Message", "",
|
||||
"ICMP", "",
|
||||
"+", "P",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, pr := range icp.Registries[id].Records {
|
||||
if strings.Contains(pr.Descr, "Reserved") ||
|
||||
strings.Contains(pr.Descr, "Unassigned") ||
|
||||
strings.Contains(pr.Descr, "Deprecated") ||
|
||||
strings.Contains(pr.Descr, "Experiment") ||
|
||||
strings.Contains(pr.Descr, "experiment") {
|
||||
continue
|
||||
}
|
||||
ss := strings.Split(pr.Descr, "\n")
|
||||
if len(ss) > 1 {
|
||||
prs[i].Descr = strings.Join(ss, " ")
|
||||
} else {
|
||||
prs[i].Descr = ss[0]
|
||||
}
|
||||
s := strings.TrimSpace(prs[i].Descr)
|
||||
prs[i].OrigDescr = s
|
||||
prs[i].Descr = sr.Replace(s)
|
||||
prs[i].Value, _ = strconv.Atoi(pr.Value)
|
||||
}
|
||||
return prs
|
||||
}
|
||||
|
|
@ -65,7 +65,6 @@ go_library(
|
|||
"zsys_openbsd.go",
|
||||
"zsys_solaris.go",
|
||||
],
|
||||
cgo = True,
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/net/ipv6",
|
||||
importpath = "golang.org/x/net/ipv6",
|
||||
visibility = ["//visibility:public"],
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#define __APPLE_USE_RFC_3542
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
|
||||
sysIPV6_PORTRANGE = C.IPV6_PORTRANGE
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
sysIPV6_2292PKTINFO = C.IPV6_2292PKTINFO
|
||||
sysIPV6_2292HOPLIMIT = C.IPV6_2292HOPLIMIT
|
||||
sysIPV6_2292NEXTHOP = C.IPV6_2292NEXTHOP
|
||||
sysIPV6_2292HOPOPTS = C.IPV6_2292HOPOPTS
|
||||
sysIPV6_2292DSTOPTS = C.IPV6_2292DSTOPTS
|
||||
sysIPV6_2292RTHDR = C.IPV6_2292RTHDR
|
||||
|
||||
sysIPV6_2292PKTOPTIONS = C.IPV6_2292PKTOPTIONS
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_IPSEC_POLICY = C.IPV6_IPSEC_POLICY
|
||||
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
|
||||
sysIPV6_AUTOFLOWLABEL = C.IPV6_AUTOFLOWLABEL
|
||||
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
|
||||
sysIPV6_PREFER_TEMPADDR = C.IPV6_PREFER_TEMPADDR
|
||||
|
||||
sysIPV6_MSFILTER = C.IPV6_MSFILTER
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
|
||||
sysIPV6_BOUND_IF = C.IPV6_BOUND_IF
|
||||
|
||||
sysIPV6_PORTRANGE_DEFAULT = C.IPV6_PORTRANGE_DEFAULT
|
||||
sysIPV6_PORTRANGE_HIGH = C.IPV6_PORTRANGE_HIGH
|
||||
sysIPV6_PORTRANGE_LOW = C.IPV6_PORTRANGE_LOW
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
sysIPV6_PORTRANGE = C.IPV6_PORTRANGE
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_IPSEC_POLICY = C.IPV6_IPSEC_POLICY
|
||||
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
|
||||
sysIPV6_AUTOFLOWLABEL = C.IPV6_AUTOFLOWLABEL
|
||||
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
|
||||
sysIPV6_PREFER_TEMPADDR = C.IPV6_PREFER_TEMPADDR
|
||||
|
||||
sysIPV6_PORTRANGE_DEFAULT = C.IPV6_PORTRANGE_DEFAULT
|
||||
sysIPV6_PORTRANGE_HIGH = C.IPV6_PORTRANGE_HIGH
|
||||
sysIPV6_PORTRANGE_LOW = C.IPV6_PORTRANGE_LOW
|
||||
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
sysIPV6_PORTRANGE = C.IPV6_PORTRANGE
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_IPSEC_POLICY = C.IPV6_IPSEC_POLICY
|
||||
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
|
||||
sysIPV6_AUTOFLOWLABEL = C.IPV6_AUTOFLOWLABEL
|
||||
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
|
||||
sysIPV6_PREFER_TEMPADDR = C.IPV6_PREFER_TEMPADDR
|
||||
|
||||
sysIPV6_BINDANY = C.IPV6_BINDANY
|
||||
|
||||
sysIPV6_MSFILTER = C.IPV6_MSFILTER
|
||||
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
|
||||
sysIPV6_PORTRANGE_DEFAULT = C.IPV6_PORTRANGE_DEFAULT
|
||||
sysIPV6_PORTRANGE_HIGH = C.IPV6_PORTRANGE_HIGH
|
||||
sysIPV6_PORTRANGE_LOW = C.IPV6_PORTRANGE_LOW
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <linux/in.h>
|
||||
#include <linux/in6.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/icmpv6.h>
|
||||
#include <linux/filter.h>
|
||||
#include <sys/socket.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_ADDRFORM = C.IPV6_ADDRFORM
|
||||
sysIPV6_2292PKTINFO = C.IPV6_2292PKTINFO
|
||||
sysIPV6_2292HOPOPTS = C.IPV6_2292HOPOPTS
|
||||
sysIPV6_2292DSTOPTS = C.IPV6_2292DSTOPTS
|
||||
sysIPV6_2292RTHDR = C.IPV6_2292RTHDR
|
||||
sysIPV6_2292PKTOPTIONS = C.IPV6_2292PKTOPTIONS
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_2292HOPLIMIT = C.IPV6_2292HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_FLOWINFO = C.IPV6_FLOWINFO
|
||||
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_ADD_MEMBERSHIP = C.IPV6_ADD_MEMBERSHIP
|
||||
sysIPV6_DROP_MEMBERSHIP = C.IPV6_DROP_MEMBERSHIP
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
sysMCAST_MSFILTER = C.MCAST_MSFILTER
|
||||
sysIPV6_ROUTER_ALERT = C.IPV6_ROUTER_ALERT
|
||||
sysIPV6_MTU_DISCOVER = C.IPV6_MTU_DISCOVER
|
||||
sysIPV6_MTU = C.IPV6_MTU
|
||||
sysIPV6_RECVERR = C.IPV6_RECVERR
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
sysIPV6_JOIN_ANYCAST = C.IPV6_JOIN_ANYCAST
|
||||
sysIPV6_LEAVE_ANYCAST = C.IPV6_LEAVE_ANYCAST
|
||||
|
||||
//sysIPV6_PMTUDISC_DONT = C.IPV6_PMTUDISC_DONT
|
||||
//sysIPV6_PMTUDISC_WANT = C.IPV6_PMTUDISC_WANT
|
||||
//sysIPV6_PMTUDISC_DO = C.IPV6_PMTUDISC_DO
|
||||
//sysIPV6_PMTUDISC_PROBE = C.IPV6_PMTUDISC_PROBE
|
||||
//sysIPV6_PMTUDISC_INTERFACE = C.IPV6_PMTUDISC_INTERFACE
|
||||
//sysIPV6_PMTUDISC_OMIT = C.IPV6_PMTUDISC_OMIT
|
||||
|
||||
sysIPV6_FLOWLABEL_MGR = C.IPV6_FLOWLABEL_MGR
|
||||
sysIPV6_FLOWINFO_SEND = C.IPV6_FLOWINFO_SEND
|
||||
|
||||
sysIPV6_IPSEC_POLICY = C.IPV6_IPSEC_POLICY
|
||||
sysIPV6_XFRM_POLICY = C.IPV6_XFRM_POLICY
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
|
||||
sysIPV6_ADDR_PREFERENCES = C.IPV6_ADDR_PREFERENCES
|
||||
|
||||
sysIPV6_PREFER_SRC_TMP = C.IPV6_PREFER_SRC_TMP
|
||||
sysIPV6_PREFER_SRC_PUBLIC = C.IPV6_PREFER_SRC_PUBLIC
|
||||
sysIPV6_PREFER_SRC_PUBTMP_DEFAULT = C.IPV6_PREFER_SRC_PUBTMP_DEFAULT
|
||||
sysIPV6_PREFER_SRC_COA = C.IPV6_PREFER_SRC_COA
|
||||
sysIPV6_PREFER_SRC_HOME = C.IPV6_PREFER_SRC_HOME
|
||||
sysIPV6_PREFER_SRC_CGA = C.IPV6_PREFER_SRC_CGA
|
||||
sysIPV6_PREFER_SRC_NONCGA = C.IPV6_PREFER_SRC_NONCGA
|
||||
|
||||
sysIPV6_MINHOPCOUNT = C.IPV6_MINHOPCOUNT
|
||||
|
||||
sysIPV6_ORIGDSTADDR = C.IPV6_ORIGDSTADDR
|
||||
sysIPV6_RECVORIGDSTADDR = C.IPV6_RECVORIGDSTADDR
|
||||
sysIPV6_TRANSPARENT = C.IPV6_TRANSPARENT
|
||||
sysIPV6_UNICAST_IF = C.IPV6_UNICAST_IF
|
||||
|
||||
sysICMPV6_FILTER = C.ICMPV6_FILTER
|
||||
|
||||
sysICMPV6_FILTER_BLOCK = C.ICMPV6_FILTER_BLOCK
|
||||
sysICMPV6_FILTER_PASS = C.ICMPV6_FILTER_PASS
|
||||
sysICMPV6_FILTER_BLOCKOTHERS = C.ICMPV6_FILTER_BLOCKOTHERS
|
||||
sysICMPV6_FILTER_PASSONLY = C.ICMPV6_FILTER_PASSONLY
|
||||
|
||||
sysSOL_SOCKET = C.SOL_SOCKET
|
||||
sysSO_ATTACH_FILTER = C.SO_ATTACH_FILTER
|
||||
|
||||
sizeofKernelSockaddrStorage = C.sizeof_struct___kernel_sockaddr_storage
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
sizeofIPv6FlowlabelReq = C.sizeof_struct_in6_flowlabel_req
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
|
||||
sizeofSockFprog = C.sizeof_struct_sock_fprog
|
||||
)
|
||||
|
||||
type kernelSockaddrStorage C.struct___kernel_sockaddr_storage
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6FlowlabelReq C.struct_in6_flowlabel_req
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
||||
type sockFProg C.struct_sock_fprog
|
||||
|
||||
type sockFilter C.struct_sock_filter
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
sysIPV6_PORTRANGE = C.IPV6_PORTRANGE
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_IPSEC_POLICY = C.IPV6_IPSEC_POLICY
|
||||
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
|
||||
sysIPV6_PORTRANGE_DEFAULT = C.IPV6_PORTRANGE_DEFAULT
|
||||
sysIPV6_PORTRANGE_HIGH = C.IPV6_PORTRANGE_HIGH
|
||||
sysIPV6_PORTRANGE_LOW = C.IPV6_PORTRANGE_LOW
|
||||
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
sysIPV6_PORTRANGE = C.IPV6_PORTRANGE
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
|
||||
sysIPV6_AUTH_LEVEL = C.IPV6_AUTH_LEVEL
|
||||
sysIPV6_ESP_TRANS_LEVEL = C.IPV6_ESP_TRANS_LEVEL
|
||||
sysIPV6_ESP_NETWORK_LEVEL = C.IPV6_ESP_NETWORK_LEVEL
|
||||
sysIPSEC6_OUTSA = C.IPSEC6_OUTSA
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
|
||||
sysIPV6_AUTOFLOWLABEL = C.IPV6_AUTOFLOWLABEL
|
||||
sysIPV6_IPCOMP_LEVEL = C.IPV6_IPCOMP_LEVEL
|
||||
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
sysIPV6_PIPEX = C.IPV6_PIPEX
|
||||
|
||||
sysIPV6_RTABLE = C.IPV6_RTABLE
|
||||
|
||||
sysIPV6_PORTRANGE_DEFAULT = C.IPV6_PORTRANGE_DEFAULT
|
||||
sysIPV6_PORTRANGE_HIGH = C.IPV6_PORTRANGE_HIGH
|
||||
sysIPV6_PORTRANGE_LOW = C.IPV6_PORTRANGE_LOW
|
||||
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package ipv6
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysIPV6_UNICAST_HOPS = C.IPV6_UNICAST_HOPS
|
||||
sysIPV6_MULTICAST_IF = C.IPV6_MULTICAST_IF
|
||||
sysIPV6_MULTICAST_HOPS = C.IPV6_MULTICAST_HOPS
|
||||
sysIPV6_MULTICAST_LOOP = C.IPV6_MULTICAST_LOOP
|
||||
sysIPV6_JOIN_GROUP = C.IPV6_JOIN_GROUP
|
||||
sysIPV6_LEAVE_GROUP = C.IPV6_LEAVE_GROUP
|
||||
|
||||
sysIPV6_PKTINFO = C.IPV6_PKTINFO
|
||||
|
||||
sysIPV6_HOPLIMIT = C.IPV6_HOPLIMIT
|
||||
sysIPV6_NEXTHOP = C.IPV6_NEXTHOP
|
||||
sysIPV6_HOPOPTS = C.IPV6_HOPOPTS
|
||||
sysIPV6_DSTOPTS = C.IPV6_DSTOPTS
|
||||
|
||||
sysIPV6_RTHDR = C.IPV6_RTHDR
|
||||
sysIPV6_RTHDRDSTOPTS = C.IPV6_RTHDRDSTOPTS
|
||||
|
||||
sysIPV6_RECVPKTINFO = C.IPV6_RECVPKTINFO
|
||||
sysIPV6_RECVHOPLIMIT = C.IPV6_RECVHOPLIMIT
|
||||
sysIPV6_RECVHOPOPTS = C.IPV6_RECVHOPOPTS
|
||||
|
||||
sysIPV6_RECVRTHDR = C.IPV6_RECVRTHDR
|
||||
|
||||
sysIPV6_RECVRTHDRDSTOPTS = C.IPV6_RECVRTHDRDSTOPTS
|
||||
|
||||
sysIPV6_CHECKSUM = C.IPV6_CHECKSUM
|
||||
sysIPV6_RECVTCLASS = C.IPV6_RECVTCLASS
|
||||
sysIPV6_USE_MIN_MTU = C.IPV6_USE_MIN_MTU
|
||||
sysIPV6_DONTFRAG = C.IPV6_DONTFRAG
|
||||
sysIPV6_SEC_OPT = C.IPV6_SEC_OPT
|
||||
sysIPV6_SRC_PREFERENCES = C.IPV6_SRC_PREFERENCES
|
||||
sysIPV6_RECVPATHMTU = C.IPV6_RECVPATHMTU
|
||||
sysIPV6_PATHMTU = C.IPV6_PATHMTU
|
||||
sysIPV6_TCLASS = C.IPV6_TCLASS
|
||||
sysIPV6_V6ONLY = C.IPV6_V6ONLY
|
||||
|
||||
sysIPV6_RECVDSTOPTS = C.IPV6_RECVDSTOPTS
|
||||
|
||||
sysMCAST_JOIN_GROUP = C.MCAST_JOIN_GROUP
|
||||
sysMCAST_LEAVE_GROUP = C.MCAST_LEAVE_GROUP
|
||||
sysMCAST_BLOCK_SOURCE = C.MCAST_BLOCK_SOURCE
|
||||
sysMCAST_UNBLOCK_SOURCE = C.MCAST_UNBLOCK_SOURCE
|
||||
sysMCAST_JOIN_SOURCE_GROUP = C.MCAST_JOIN_SOURCE_GROUP
|
||||
sysMCAST_LEAVE_SOURCE_GROUP = C.MCAST_LEAVE_SOURCE_GROUP
|
||||
|
||||
sysIPV6_PREFER_SRC_HOME = C.IPV6_PREFER_SRC_HOME
|
||||
sysIPV6_PREFER_SRC_COA = C.IPV6_PREFER_SRC_COA
|
||||
sysIPV6_PREFER_SRC_PUBLIC = C.IPV6_PREFER_SRC_PUBLIC
|
||||
sysIPV6_PREFER_SRC_TMP = C.IPV6_PREFER_SRC_TMP
|
||||
sysIPV6_PREFER_SRC_NONCGA = C.IPV6_PREFER_SRC_NONCGA
|
||||
sysIPV6_PREFER_SRC_CGA = C.IPV6_PREFER_SRC_CGA
|
||||
|
||||
sysIPV6_PREFER_SRC_MIPMASK = C.IPV6_PREFER_SRC_MIPMASK
|
||||
sysIPV6_PREFER_SRC_MIPDEFAULT = C.IPV6_PREFER_SRC_MIPDEFAULT
|
||||
sysIPV6_PREFER_SRC_TMPMASK = C.IPV6_PREFER_SRC_TMPMASK
|
||||
sysIPV6_PREFER_SRC_TMPDEFAULT = C.IPV6_PREFER_SRC_TMPDEFAULT
|
||||
sysIPV6_PREFER_SRC_CGAMASK = C.IPV6_PREFER_SRC_CGAMASK
|
||||
sysIPV6_PREFER_SRC_CGADEFAULT = C.IPV6_PREFER_SRC_CGADEFAULT
|
||||
|
||||
sysIPV6_PREFER_SRC_MASK = C.IPV6_PREFER_SRC_MASK
|
||||
|
||||
sysIPV6_PREFER_SRC_DEFAULT = C.IPV6_PREFER_SRC_DEFAULT
|
||||
|
||||
sysIPV6_BOUND_IF = C.IPV6_BOUND_IF
|
||||
sysIPV6_UNSPEC_SRC = C.IPV6_UNSPEC_SRC
|
||||
|
||||
sysICMP6_FILTER = C.ICMP6_FILTER
|
||||
|
||||
sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
sizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
sizeofIPv6Mtuinfo = C.sizeof_struct_ip6_mtuinfo
|
||||
|
||||
sizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
sizeofGroupReq = C.sizeof_struct_group_req
|
||||
sizeofGroupSourceReq = C.sizeof_struct_group_source_req
|
||||
|
||||
sizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
type sockaddrStorage C.struct_sockaddr_storage
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type ipv6Mtuinfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ipv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type groupReq C.struct_group_req
|
||||
|
||||
type groupSourceReq C.struct_group_source_req
|
||||
|
||||
type icmpv6Filter C.struct_icmp6_filter
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
// This program generates system adaptation constants and types,
|
||||
// internet protocol constants and tables by reading template files
|
||||
// and IANA protocol registries.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := genzsys(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := geniana(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func genzsys() error {
|
||||
defs := "defs_" + runtime.GOOS + ".go"
|
||||
f, err := os.Open(defs)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
f.Close()
|
||||
cmd := exec.Command("go", "tool", "cgo", "-godefs", defs)
|
||||
b, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err = format.Source(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
zsys := "zsys_" + runtime.GOOS + ".go"
|
||||
switch runtime.GOOS {
|
||||
case "freebsd", "linux":
|
||||
zsys = "zsys_" + runtime.GOOS + "_" + runtime.GOARCH + ".go"
|
||||
}
|
||||
if err := ioutil.WriteFile(zsys, b, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var registries = []struct {
|
||||
url string
|
||||
parse func(io.Writer, io.Reader) error
|
||||
}{
|
||||
{
|
||||
"https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml",
|
||||
parseICMPv6Parameters,
|
||||
},
|
||||
}
|
||||
|
||||
func geniana() error {
|
||||
var bb bytes.Buffer
|
||||
fmt.Fprintf(&bb, "// go generate gen.go\n")
|
||||
fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(&bb, "package ipv6\n\n")
|
||||
for _, r := range registries {
|
||||
resp, err := http.Get(r.url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("got HTTP status code %v for %v\n", resp.StatusCode, r.url)
|
||||
}
|
||||
if err := r.parse(&bb, resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(&bb, "\n")
|
||||
}
|
||||
b, err := format.Source(bb.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile("iana.go", b, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseICMPv6Parameters(w io.Writer, r io.Reader) error {
|
||||
dec := xml.NewDecoder(r)
|
||||
var icp icmpv6Parameters
|
||||
if err := dec.Decode(&icp); err != nil {
|
||||
return err
|
||||
}
|
||||
prs := icp.escape()
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated)
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, pr := range prs {
|
||||
if pr.Name == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "ICMPType%s ICMPType = %d", pr.Name, pr.Value)
|
||||
fmt.Fprintf(w, "// %s\n", pr.OrigName)
|
||||
}
|
||||
fmt.Fprintf(w, ")\n\n")
|
||||
fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated)
|
||||
fmt.Fprintf(w, "var icmpTypes = map[ICMPType]string{\n")
|
||||
for _, pr := range prs {
|
||||
if pr.Name == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "%d: %q,\n", pr.Value, strings.ToLower(pr.OrigName))
|
||||
}
|
||||
fmt.Fprintf(w, "}\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type icmpv6Parameters struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Title string `xml:"title"`
|
||||
Updated string `xml:"updated"`
|
||||
Registries []struct {
|
||||
Title string `xml:"title"`
|
||||
Records []struct {
|
||||
Value string `xml:"value"`
|
||||
Name string `xml:"name"`
|
||||
} `xml:"record"`
|
||||
} `xml:"registry"`
|
||||
}
|
||||
|
||||
type canonICMPv6ParamRecord struct {
|
||||
OrigName string
|
||||
Name string
|
||||
Value int
|
||||
}
|
||||
|
||||
func (icp *icmpv6Parameters) escape() []canonICMPv6ParamRecord {
|
||||
id := -1
|
||||
for i, r := range icp.Registries {
|
||||
if strings.Contains(r.Title, "Type") || strings.Contains(r.Title, "type") {
|
||||
id = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if id < 0 {
|
||||
return nil
|
||||
}
|
||||
prs := make([]canonICMPv6ParamRecord, len(icp.Registries[id].Records))
|
||||
sr := strings.NewReplacer(
|
||||
"Messages", "",
|
||||
"Message", "",
|
||||
"ICMP", "",
|
||||
"+", "P",
|
||||
"-", "",
|
||||
"/", "",
|
||||
".", "",
|
||||
" ", "",
|
||||
)
|
||||
for i, pr := range icp.Registries[id].Records {
|
||||
if strings.Contains(pr.Name, "Reserved") ||
|
||||
strings.Contains(pr.Name, "Unassigned") ||
|
||||
strings.Contains(pr.Name, "Deprecated") ||
|
||||
strings.Contains(pr.Name, "Experiment") ||
|
||||
strings.Contains(pr.Name, "experiment") {
|
||||
continue
|
||||
}
|
||||
ss := strings.Split(pr.Name, "\n")
|
||||
if len(ss) > 1 {
|
||||
prs[i].Name = strings.Join(ss, " ")
|
||||
} else {
|
||||
prs[i].Name = ss[0]
|
||||
}
|
||||
s := strings.TrimSpace(prs[i].Name)
|
||||
prs[i].OrigName = s
|
||||
prs[i].Name = sr.Replace(s)
|
||||
prs[i].Value, _ = strconv.Atoi(pr.Value)
|
||||
}
|
||||
return prs
|
||||
}
|
||||
|
|
@ -10,6 +10,6 @@ go_library(
|
|||
],
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/oauth2/internal",
|
||||
importpath = "golang.org/x/oauth2/internal",
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//vendor/golang.org/x/oauth2:__subpackages__"],
|
||||
deps = ["//vendor/golang.org/x/net/context/ctxhttp:go_default_library"],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# This source code refers to The Go Authors for copyright purposes.
|
||||
# The master list of authors is in the main Go distribution,
|
||||
# visible at http://tip.golang.org/AUTHORS.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# This source code was written by the Go contributors.
|
||||
# The master list of contributors is in the main Go distribution,
|
||||
# visible at http://tip.golang.org/CONTRIBUTORS.
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
Google as part of the Go project.
|
||||
|
||||
Google hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable (except as stated in this section)
|
||||
patent license to make, have made, use, offer to sell, sell, import,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation of Go, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by Google and acquired in
|
||||
the future, licensable by Google that are necessarily infringed by this
|
||||
implementation of Go. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation of Go or any code incorporated within this
|
||||
implementation of Go constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation of Go
|
||||
shall terminate as of the date such litigation is filed.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["errgroup.go"],
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/sync/errgroup",
|
||||
importpath = "golang.org/x/sync/errgroup",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package errgroup provides synchronization, error propagation, and Context
|
||||
// cancelation for groups of goroutines working on subtasks of a common task.
|
||||
package errgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Group is a collection of goroutines working on subtasks that are part of
|
||||
// the same overall task.
|
||||
//
|
||||
// A zero Group is valid and does not cancel on error.
|
||||
type Group struct {
|
||||
cancel func()
|
||||
|
||||
wg sync.WaitGroup
|
||||
|
||||
errOnce sync.Once
|
||||
err error
|
||||
}
|
||||
|
||||
// WithContext returns a new Group and an associated Context derived from ctx.
|
||||
//
|
||||
// The derived Context is canceled the first time a function passed to Go
|
||||
// returns a non-nil error or the first time Wait returns, whichever occurs
|
||||
// first.
|
||||
func WithContext(ctx context.Context) (*Group, context.Context) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
return &Group{cancel: cancel}, ctx
|
||||
}
|
||||
|
||||
// Wait blocks until all function calls from the Go method have returned, then
|
||||
// returns the first non-nil error (if any) from them.
|
||||
func (g *Group) Wait() error {
|
||||
g.wg.Wait()
|
||||
if g.cancel != nil {
|
||||
g.cancel()
|
||||
}
|
||||
return g.err
|
||||
}
|
||||
|
||||
// Go calls the given function in a new goroutine.
|
||||
//
|
||||
// The first call to return a non-nil error cancels the group; its error will be
|
||||
// returned by Wait.
|
||||
func (g *Group) Go(f func() error) {
|
||||
g.wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer g.wg.Done()
|
||||
|
||||
if err := f(); err != nil {
|
||||
g.errOnce.Do(func() {
|
||||
g.err = err
|
||||
if g.cancel != nil {
|
||||
g.cancel()
|
||||
}
|
||||
})
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// mkasm_darwin.go generates assembly trampolines to call libSystem routines from Go.
|
||||
//This program must be run after mksyscall.go.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in1, err := ioutil.ReadFile("syscall_darwin.go")
|
||||
if err != nil {
|
||||
log.Fatalf("can't open syscall_darwin.go: %s", err)
|
||||
}
|
||||
arch := os.Args[1]
|
||||
in2, err := ioutil.ReadFile(fmt.Sprintf("syscall_darwin_%s.go", arch))
|
||||
if err != nil {
|
||||
log.Fatalf("can't open syscall_darwin_%s.go: %s", arch, err)
|
||||
}
|
||||
in3, err := ioutil.ReadFile(fmt.Sprintf("zsyscall_darwin_%s.go", arch))
|
||||
if err != nil {
|
||||
log.Fatalf("can't open zsyscall_darwin_%s.go: %s", arch, err)
|
||||
}
|
||||
in := string(in1) + string(in2) + string(in3)
|
||||
|
||||
trampolines := map[string]bool{}
|
||||
|
||||
var out bytes.Buffer
|
||||
|
||||
fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
|
||||
fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
|
||||
fmt.Fprintf(&out, "\n")
|
||||
fmt.Fprintf(&out, "// +build go1.12\n")
|
||||
fmt.Fprintf(&out, "\n")
|
||||
fmt.Fprintf(&out, "#include \"textflag.h\"\n")
|
||||
for _, line := range strings.Split(in, "\n") {
|
||||
if !strings.HasPrefix(line, "func ") || !strings.HasSuffix(line, "_trampoline()") {
|
||||
continue
|
||||
}
|
||||
fn := line[5 : len(line)-13]
|
||||
if !trampolines[fn] {
|
||||
trampolines[fn] = true
|
||||
fmt.Fprintf(&out, "TEXT ·%s_trampoline(SB),NOSPLIT,$0-0\n", fn)
|
||||
fmt.Fprintf(&out, "\tJMP\t%s(SB)\n", fn)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(fmt.Sprintf("zsyscall_darwin_%s.s", arch), out.Bytes(), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("can't write zsyscall_darwin_%s.s: %s", arch, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// mkpost processes the output of cgo -godefs to
|
||||
// modify the generated types. It is used to clean up
|
||||
// the sys API in an architecture specific manner.
|
||||
//
|
||||
// mkpost is run after cgo -godefs; see README.md.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
||||
goos := os.Getenv("GOOS")
|
||||
goarch := os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
// Check that we are using the Docker-based build system if we should be.
|
||||
if goos == "linux" {
|
||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
||||
os.Stderr.WriteString("In the Docker-based build system, mkpost should not be called directly.\n")
|
||||
os.Stderr.WriteString("See README.md\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Intentionally export __val fields in Fsid and Sigset_t
|
||||
valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__val(\s+\S+\s+)}`)
|
||||
b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$3}"))
|
||||
|
||||
// Intentionally export __fds_bits field in FdSet
|
||||
fdSetRegex := regexp.MustCompile(`type (FdSet) struct {(\s+)X__fds_bits(\s+\S+\s+)}`)
|
||||
b = fdSetRegex.ReplaceAll(b, []byte("type $1 struct {${2}Bits$3}"))
|
||||
|
||||
// If we have empty Ptrace structs, we should delete them. Only s390x emits
|
||||
// nonempty Ptrace structs.
|
||||
ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
|
||||
b = ptraceRexexp.ReplaceAll(b, nil)
|
||||
|
||||
// Replace the control_regs union with a blank identifier for now.
|
||||
controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`)
|
||||
b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64"))
|
||||
|
||||
// Remove fields that are added by glibc
|
||||
// Note that this is unstable as the identifers are private.
|
||||
removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`)
|
||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Convert [65]int8 to [65]byte in Utsname members to simplify
|
||||
// conversion to string; see golang.org/issue/20753
|
||||
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
|
||||
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
|
||||
|
||||
// Convert [1024]int8 to [1024]byte in Ptmget members
|
||||
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
||||
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
||||
|
||||
// Remove spare fields (e.g. in Statx_t)
|
||||
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
|
||||
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove cgo padding fields
|
||||
removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
|
||||
b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove padding, hidden, or unused fields
|
||||
removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`)
|
||||
b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
|
||||
|
||||
// Remove the first line of warning from cgo
|
||||
b = b[bytes.IndexByte(b, '\n')+1:]
|
||||
// Modify the command in the header to include:
|
||||
// mkpost, our own warning, and a build tag.
|
||||
replacement := fmt.Sprintf(`$1 | go run mkpost.go
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s,%s`, goarch, goos)
|
||||
cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
|
||||
b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
|
||||
|
||||
// gofmt
|
||||
b, err = format.Source(b)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
os.Stdout.Write(b)
|
||||
}
|
||||
|
|
@ -1,407 +0,0 @@
|
|||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_darwin.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named errno.
|
||||
|
||||
A line beginning with //sysnb is like //sys, except that the
|
||||
goroutine will not be suspended during the execution of the system
|
||||
call. This must only be used for system calls which can never
|
||||
block, as otherwise the system call could cause all goroutines to
|
||||
hang.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
plan9 = flag.Bool("plan9", false, "plan9")
|
||||
openbsd = flag.Bool("openbsd", false, "openbsd")
|
||||
netbsd = flag.Bool("netbsd", false, "netbsd")
|
||||
dragonfly = flag.Bool("dragonfly", false, "dragonfly")
|
||||
arm = flag.Bool("arm", false, "arm") // 64-bit value should use (even, odd)-pair
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
filename = flag.String("output", "", "output file name (standard output if omitted)")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Get the OS and architecture (using GOARCH_TARGET if it exists)
|
||||
goos := os.Getenv("GOOS")
|
||||
if goos == "" {
|
||||
fmt.Fprintln(os.Stderr, "GOOS not defined in environment")
|
||||
os.Exit(1)
|
||||
}
|
||||
goarch := os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
|
||||
// Check that we are using the Docker-based build system if we should
|
||||
if goos == "linux" {
|
||||
if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
|
||||
fmt.Fprintf(os.Stderr, "In the Docker-based build system, mksyscall should not be called directly.\n")
|
||||
fmt.Fprintf(os.Stderr, "See README.md\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
libc := false
|
||||
if goos == "darwin" && strings.Contains(buildTags(), ",go1.12") {
|
||||
libc = true
|
||||
}
|
||||
trampolines := map[string]bool{}
|
||||
|
||||
text := ""
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, errno error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, sysname := f[2], f[3], f[4], f[5]
|
||||
|
||||
// ClockGettime doesn't have a syscall number on Darwin, only generate libc wrappers.
|
||||
if goos == "darwin" && !libc && funct == "ClockGettime" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// Go function header.
|
||||
outDecl := ""
|
||||
if len(out) > 0 {
|
||||
outDecl = fmt.Sprintf(" (%s)", strings.Join(out, ", "))
|
||||
}
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outDecl)
|
||||
|
||||
// Check if err return available
|
||||
errvar := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
||||
text += fmt.Sprintf("\t_p%d, %s = BytePtrFromString(%s)\n", n, errvar, p.Name)
|
||||
text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\tvar _p%d *byte\n", n)
|
||||
text += fmt.Sprintf("\t_p%d, _ = BytePtrFromString(%s)\n", n, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass dummy pointer in that case.
|
||||
// Used to pass nil, but some OSes or simulators reject write(fd, nil, 0).
|
||||
text += fmt.Sprintf("\tvar _p%d unsafe.Pointer\n", n)
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = unsafe.Pointer(&%s[0])\n\t}", p.Name, n, p.Name)
|
||||
text += fmt.Sprintf(" else {\n\t\t_p%d = unsafe.Pointer(&_zero)\n\t}\n", n)
|
||||
args = append(args, fmt.Sprintf("uintptr(_p%d)", n), fmt.Sprintf("uintptr(len(%s))", p.Name))
|
||||
n++
|
||||
} else if p.Type == "int64" && (*openbsd || *netbsd) {
|
||||
args = append(args, "0")
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else if endianness == "little-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int64" && *dragonfly {
|
||||
if regexp.MustCompile(`^(?i)extp(read|write)`).FindStringSubmatch(funct) == nil {
|
||||
args = append(args, "0")
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else if endianness == "little-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
} else if (p.Type == "int64" || p.Type == "uint64") && endianness != "" {
|
||||
if len(args)%2 == 1 && *arm {
|
||||
// arm abi specifies 64-bit argument uses
|
||||
// (even, odd) pair
|
||||
args = append(args, "0")
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which form to use; pad args with zeros.
|
||||
asm := "Syscall"
|
||||
if nonblock != nil {
|
||||
if errvar == "" && goos == "linux" {
|
||||
asm = "RawSyscallNoError"
|
||||
} else {
|
||||
asm = "RawSyscall"
|
||||
}
|
||||
} else {
|
||||
if errvar == "" && goos == "linux" {
|
||||
asm = "SyscallNoError"
|
||||
}
|
||||
}
|
||||
if len(args) <= 3 {
|
||||
for len(args) < 3 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else if len(args) <= 6 {
|
||||
asm += "6"
|
||||
for len(args) < 6 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else if len(args) <= 9 {
|
||||
asm += "9"
|
||||
for len(args) < 9 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s too many arguments to system call\n", path, funct)
|
||||
}
|
||||
|
||||
// System call number.
|
||||
if sysname == "" {
|
||||
sysname = "SYS_" + funct
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToUpper(sysname)
|
||||
}
|
||||
|
||||
var libcFn string
|
||||
if libc {
|
||||
asm = "syscall_" + strings.ToLower(asm[:1]) + asm[1:] // internal syscall call
|
||||
sysname = strings.TrimPrefix(sysname, "SYS_") // remove SYS_
|
||||
sysname = strings.ToLower(sysname) // lowercase
|
||||
if sysname == "getdirentries64" {
|
||||
// Special case - libSystem name and
|
||||
// raw syscall name don't match.
|
||||
sysname = "__getdirentries64"
|
||||
}
|
||||
libcFn = sysname
|
||||
sysname = "funcPC(libc_" + sysname + "_trampoline)"
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := fmt.Sprintf("%s(%s, %s)", asm, sysname, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
ret := []string{"_", "_", "_"}
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" && !*plan9 {
|
||||
reg = "e1"
|
||||
ret[2] = reg
|
||||
doErrno = true
|
||||
} else if p.Name == "err" && *plan9 {
|
||||
ret[0] = "r0"
|
||||
ret[2] = "e1"
|
||||
break
|
||||
} else {
|
||||
reg = fmt.Sprintf("r%d", i)
|
||||
ret[i] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%s != 0", reg)
|
||||
}
|
||||
if p.Type == "int64" && endianness != "" {
|
||||
// 64-bit number in r1:r0 or r0:r1.
|
||||
if i+2 > len(out) {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s not enough registers for int64 return\n", path, funct)
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1)
|
||||
} else {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i)
|
||||
}
|
||||
ret[i] = fmt.Sprintf("r%d", i)
|
||||
ret[i+1] = fmt.Sprintf("r%d", i+1)
|
||||
}
|
||||
if reg != "e1" || *plan9 {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" {
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
} else {
|
||||
if errvar == "" && goos == "linux" {
|
||||
// raw syscall without error on Linux, see golang.org/issue/22924
|
||||
text += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], call)
|
||||
} else {
|
||||
text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call)
|
||||
}
|
||||
}
|
||||
text += body
|
||||
|
||||
if *plan9 && ret[2] == "e1" {
|
||||
text += "\tif int32(r0) == -1 {\n"
|
||||
text += "\t\terr = e1\n"
|
||||
text += "\t}\n"
|
||||
} else if doErrno {
|
||||
text += "\tif e1 != 0 {\n"
|
||||
text += "\t\terr = errnoErr(e1)\n"
|
||||
text += "\t}\n"
|
||||
}
|
||||
text += "\treturn\n"
|
||||
text += "}\n\n"
|
||||
|
||||
if libc && !trampolines[libcFn] {
|
||||
// some system calls share a trampoline, like read and readlen.
|
||||
trampolines[libcFn] = true
|
||||
// Declare assembly trampoline.
|
||||
text += fmt.Sprintf("func libc_%s_trampoline()\n", libcFn)
|
||||
// Assembly trampoline calls the libc_* function, which this magic
|
||||
// redirects to use the function from libSystem.
|
||||
text += fmt.Sprintf("//go:linkname libc_%s libc_%s\n", libcFn, libcFn)
|
||||
text += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"/usr/lib/libSystem.B.dylib\"\n", libcFn, libcFn)
|
||||
text += "\n"
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package unix
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var _ syscall.Errno
|
||||
|
||||
%s
|
||||
`
|
||||
|
|
@ -1,404 +0,0 @@
|
|||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_aix.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
aix = flag.Bool("aix", false, "aix")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_aix_ppc.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
text := ""
|
||||
cExtern := "/*\n#include <stdint.h>\n#include <stddef.h>\n"
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// Check if value return, err return available
|
||||
errvar := ""
|
||||
retvar := ""
|
||||
rettype := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
} else {
|
||||
retvar = p.Name
|
||||
rettype = p.Type
|
||||
}
|
||||
}
|
||||
|
||||
// System call name.
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
cRettype := ""
|
||||
if rettype == "unsafe.Pointer" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "uintptr" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "int" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int32" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int64" {
|
||||
cRettype = "long long"
|
||||
} else if rettype == "uint32" {
|
||||
cRettype = "unsigned int"
|
||||
} else if rettype == "uint64" {
|
||||
cRettype = "unsigned long long"
|
||||
} else {
|
||||
cRettype = "int"
|
||||
}
|
||||
if sysname == "exit" {
|
||||
cRettype = "void"
|
||||
}
|
||||
|
||||
// Change p.Types to c
|
||||
var cIn []string
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "string" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t", "size_t")
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "uintptr" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "int" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int32" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int64" {
|
||||
cIn = append(cIn, "long long")
|
||||
} else if p.Type == "uint32" {
|
||||
cIn = append(cIn, "unsigned int")
|
||||
} else if p.Type == "uint64" {
|
||||
cIn = append(cIn, "unsigned long long")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
}
|
||||
|
||||
if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" {
|
||||
// Imports of system calls from libc
|
||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
||||
cIn := strings.Join(cIn, ", ")
|
||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
||||
}
|
||||
|
||||
// So file name.
|
||||
if *aix {
|
||||
if modname == "" {
|
||||
modname = "libc.a/shr_64.o"
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
strconvfunc := "C.CString"
|
||||
|
||||
// Go function header.
|
||||
if outps != "" {
|
||||
outps = fmt.Sprintf(" (%s)", outps)
|
||||
}
|
||||
if text != "" {
|
||||
text += "\n"
|
||||
}
|
||||
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
argN := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "C.uintptr_t(uintptr(unsafe.Pointer("+p.Name+")))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\t_p%d := uintptr(unsafe.Pointer(%s(%s)))\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
text += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(unsafe.Pointer(_p%d)))", n))
|
||||
n++
|
||||
text += fmt.Sprintf("\tvar _p%d int\n", n)
|
||||
text += fmt.Sprintf("\t_p%d = len(%s)\n", n, p.Name)
|
||||
args = append(args, fmt.Sprintf("C.size_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
n++
|
||||
} else if p.Type == "bool" {
|
||||
text += fmt.Sprintf("\tvar _p%d uint32\n", n)
|
||||
text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n)
|
||||
args = append(args, fmt.Sprintf("_p%d", n))
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(uintptr(%s))", p.Name))
|
||||
} else if p.Type == "int" {
|
||||
if (argN == 2) && ((funct == "readlen") || (funct == "writelen")) {
|
||||
args = append(args, fmt.Sprintf("C.size_t(%s)", p.Name))
|
||||
} else if argN == 0 && funct == "fcntl" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if (argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt")) {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int32" {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
} else if p.Type == "int64" {
|
||||
args = append(args, fmt.Sprintf("C.longlong(%s)", p.Name))
|
||||
} else if p.Type == "uint32" {
|
||||
args = append(args, fmt.Sprintf("C.uint(%s)", p.Name))
|
||||
} else if p.Type == "uint64" {
|
||||
args = append(args, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
||||
} else if p.Type == "uintptr" {
|
||||
args = append(args, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
argN++
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := ""
|
||||
if sysname == "exit" {
|
||||
if errvar != "" {
|
||||
call += "er :="
|
||||
} else {
|
||||
call += ""
|
||||
}
|
||||
} else if errvar != "" {
|
||||
call += "r0,er :="
|
||||
} else if retvar != "" {
|
||||
call += "r0,_ :="
|
||||
} else {
|
||||
call += ""
|
||||
}
|
||||
call += fmt.Sprintf("C.%s(%s)", sysname, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
} else {
|
||||
reg = "r0"
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
|
||||
// verify return
|
||||
if sysname != "exit" && errvar != "" {
|
||||
if regexp.MustCompile(`^uintptr`).FindStringSubmatch(cRettype) != nil {
|
||||
body += "\tif (uintptr(r0) ==^uintptr(0) && er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
} else {
|
||||
body += "\tif (r0 ==-1 && er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
}
|
||||
} else if errvar != "" {
|
||||
body += "\tif (er != nil) {\n"
|
||||
body += fmt.Sprintf("\t\t%s = er\n", errvar)
|
||||
body += "\t}\n"
|
||||
}
|
||||
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
text += body
|
||||
|
||||
text += "\treturn\n"
|
||||
text += "}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, cExtern, imp, text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
|
||||
%s
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
||||
|
|
@ -1,602 +0,0 @@
|
|||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_aix.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
|
||||
|
||||
This program will generate three files and handle both gc and gccgo implementation:
|
||||
- zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation)
|
||||
- zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6
|
||||
- zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type.
|
||||
|
||||
The generated code looks like this
|
||||
|
||||
zsyscall_aix_ppc64.go
|
||||
func asyscall(...) (n int, err error) {
|
||||
// Pointer Creation
|
||||
r1, e1 := callasyscall(...)
|
||||
// Type Conversion
|
||||
// Error Handler
|
||||
return
|
||||
}
|
||||
|
||||
zsyscall_aix_ppc64_gc.go
|
||||
//go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o"
|
||||
//go:linkname libc_asyscall libc_asyscall
|
||||
var asyscall syscallFunc
|
||||
|
||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
||||
r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... )
|
||||
return
|
||||
}
|
||||
|
||||
zsyscall_aix_ppc64_ggcgo.go
|
||||
|
||||
// int asyscall(...)
|
||||
|
||||
import "C"
|
||||
|
||||
func callasyscall(...) (r1 uintptr, e1 Errno) {
|
||||
r1 = uintptr(C.asyscall(...))
|
||||
e1 = syscall.GetErrno()
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
aix = flag.Bool("aix", false, "aix")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc64.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
// GCCGO
|
||||
textgccgo := ""
|
||||
cExtern := "/*\n#include <stdint.h>\n"
|
||||
// GC
|
||||
textgc := ""
|
||||
dynimports := ""
|
||||
linknames := ""
|
||||
var vars []string
|
||||
// COMMON
|
||||
textcommon := ""
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
|
||||
onlyCommon := false
|
||||
if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
|
||||
// This function call another syscall which is already implemented.
|
||||
// Therefore, the gc and gccgo part must not be generated.
|
||||
onlyCommon = true
|
||||
}
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
|
||||
textcommon += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
if !onlyCommon {
|
||||
textgccgo += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
textgc += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
}
|
||||
|
||||
// Check if value return, err return available
|
||||
errvar := ""
|
||||
rettype := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
} else {
|
||||
rettype = p.Type
|
||||
}
|
||||
}
|
||||
|
||||
sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
// GCCGO Prototype return type
|
||||
cRettype := ""
|
||||
if rettype == "unsafe.Pointer" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "uintptr" {
|
||||
cRettype = "uintptr_t"
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
|
||||
cRettype = "uintptr_t"
|
||||
} else if rettype == "int" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int32" {
|
||||
cRettype = "int"
|
||||
} else if rettype == "int64" {
|
||||
cRettype = "long long"
|
||||
} else if rettype == "uint32" {
|
||||
cRettype = "unsigned int"
|
||||
} else if rettype == "uint64" {
|
||||
cRettype = "unsigned long long"
|
||||
} else {
|
||||
cRettype = "int"
|
||||
}
|
||||
if sysname == "exit" {
|
||||
cRettype = "void"
|
||||
}
|
||||
|
||||
// GCCGO Prototype arguments type
|
||||
var cIn []string
|
||||
for i, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "string" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t", "size_t")
|
||||
} else if p.Type == "unsafe.Pointer" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "uintptr" {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else if p.Type == "int" {
|
||||
if (i == 0 || i == 2) && funct == "fcntl" {
|
||||
// These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock
|
||||
cIn = append(cIn, "uintptr_t")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
|
||||
} else if p.Type == "int32" {
|
||||
cIn = append(cIn, "int")
|
||||
} else if p.Type == "int64" {
|
||||
cIn = append(cIn, "long long")
|
||||
} else if p.Type == "uint32" {
|
||||
cIn = append(cIn, "unsigned int")
|
||||
} else if p.Type == "uint64" {
|
||||
cIn = append(cIn, "unsigned long long")
|
||||
} else {
|
||||
cIn = append(cIn, "int")
|
||||
}
|
||||
}
|
||||
|
||||
if !onlyCommon {
|
||||
// GCCGO Prototype Generation
|
||||
// Imports of system calls from libc
|
||||
cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
|
||||
cIn := strings.Join(cIn, ", ")
|
||||
cExtern += fmt.Sprintf("(%s);\n", cIn)
|
||||
}
|
||||
// GC Library name
|
||||
if modname == "" {
|
||||
modname = "libc.a/shr_64.o"
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
sysvarname := fmt.Sprintf("libc_%s", sysname)
|
||||
|
||||
if !onlyCommon {
|
||||
// GC Runtime import of function to allow cross-platform builds.
|
||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic %s %s \"%s\"\n", sysvarname, sysname, modname)
|
||||
// GC Link symbol to proc address variable.
|
||||
linknames += fmt.Sprintf("//go:linkname %s %s\n", sysvarname, sysvarname)
|
||||
// GC Library proc address variable.
|
||||
vars = append(vars, sysvarname)
|
||||
}
|
||||
|
||||
strconvfunc := "BytePtrFromString"
|
||||
strconvtype := "*byte"
|
||||
|
||||
// Go function header.
|
||||
if outps != "" {
|
||||
outps = fmt.Sprintf(" (%s)", outps)
|
||||
}
|
||||
if textcommon != "" {
|
||||
textcommon += "\n"
|
||||
}
|
||||
|
||||
textcommon += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
|
||||
|
||||
// Prepare arguments tocall.
|
||||
var argscommon []string // Arguments in the common part
|
||||
var argscall []string // Arguments for call prototype
|
||||
var argsgc []string // Arguments for gc call (with syscall6)
|
||||
var argsgccgo []string // Arguments for gccgo call (with C.name_of_syscall)
|
||||
n := 0
|
||||
argN := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr ", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
|
||||
n++
|
||||
} else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
textcommon += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
|
||||
textcommon += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("len(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n), fmt.Sprintf("_lenp%d int", n))
|
||||
argsgc = append(argsgc, fmt.Sprintf("_p%d", n), fmt.Sprintf("uintptr(_lenp%d)", n))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n), fmt.Sprintf("C.size_t(_lenp%d)", n))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses int64 with 32 bits mode. Case not yet implemented\n")
|
||||
} else if p.Type == "bool" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses bool. Case not yet implemented\n")
|
||||
} else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil || p.Type == "unsafe.Pointer" {
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else if p.Type == "int" {
|
||||
if (argN == 0 || argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt") || (funct == "FcntlFlock")) {
|
||||
// These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock
|
||||
argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
|
||||
} else {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
} else if p.Type == "int32" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int32", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
} else if p.Type == "int64" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s int64", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.longlong(%s)", p.Name))
|
||||
} else if p.Type == "uint32" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uint32", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uint(%s)", p.Name))
|
||||
} else if p.Type == "uint64" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uint64", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.ulonglong(%s)", p.Name))
|
||||
} else if p.Type == "uintptr" {
|
||||
argscommon = append(argscommon, p.Name)
|
||||
argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
|
||||
argsgc = append(argsgc, p.Name)
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
|
||||
} else {
|
||||
argscommon = append(argscommon, fmt.Sprintf("int(%s)", p.Name))
|
||||
argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
|
||||
argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
|
||||
}
|
||||
argN++
|
||||
}
|
||||
nargs := len(argsgc)
|
||||
|
||||
// COMMON function generation
|
||||
argscommonlist := strings.Join(argscommon, ", ")
|
||||
callcommon := fmt.Sprintf("call%s(%s)", sysname, argscommonlist)
|
||||
ret := []string{"_", "_"}
|
||||
body := ""
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
ret[1] = reg
|
||||
doErrno = true
|
||||
} else {
|
||||
reg = "r0"
|
||||
ret[0] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%s != 0", reg)
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" {
|
||||
textcommon += fmt.Sprintf("\t%s\n", callcommon)
|
||||
} else {
|
||||
textcommon += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], callcommon)
|
||||
}
|
||||
textcommon += body
|
||||
|
||||
if doErrno {
|
||||
textcommon += "\tif e1 != 0 {\n"
|
||||
textcommon += "\t\terr = errnoErr(e1)\n"
|
||||
textcommon += "\t}\n"
|
||||
}
|
||||
textcommon += "\treturn\n"
|
||||
textcommon += "}\n"
|
||||
|
||||
if onlyCommon {
|
||||
continue
|
||||
}
|
||||
|
||||
// CALL Prototype
|
||||
callProto := fmt.Sprintf("func call%s(%s) (r1 uintptr, e1 Errno) {\n", sysname, strings.Join(argscall, ", "))
|
||||
|
||||
// GC function generation
|
||||
asm := "syscall6"
|
||||
if nonblock != nil {
|
||||
asm = "rawSyscall6"
|
||||
}
|
||||
|
||||
if len(argsgc) <= 6 {
|
||||
for len(argsgc) < 6 {
|
||||
argsgc = append(argsgc, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: too many arguments to system call", funct)
|
||||
os.Exit(1)
|
||||
}
|
||||
argsgclist := strings.Join(argsgc, ", ")
|
||||
callgc := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, argsgclist)
|
||||
|
||||
textgc += callProto
|
||||
textgc += fmt.Sprintf("\tr1, _, e1 = %s\n", callgc)
|
||||
textgc += "\treturn\n}\n"
|
||||
|
||||
// GCCGO function generation
|
||||
argsgccgolist := strings.Join(argsgccgo, ", ")
|
||||
callgccgo := fmt.Sprintf("C.%s(%s)", sysname, argsgccgolist)
|
||||
textgccgo += callProto
|
||||
textgccgo += fmt.Sprintf("\tr1 = uintptr(%s)\n", callgccgo)
|
||||
textgccgo += "\te1 = syscall.GetErrno()\n"
|
||||
textgccgo += "\treturn\n}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64.go
|
||||
err := ioutil.WriteFile("zsyscall_aix_ppc64.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64_gc.go
|
||||
vardecls := "\t" + strings.Join(vars, ",\n\t")
|
||||
vardecls += " syscallFunc"
|
||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Print zsyscall_aix_ppc64_gccgo.go
|
||||
err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go",
|
||||
[]byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)),
|
||||
0644)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
const srcTemplate1 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
||||
const srcTemplate2 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
// +build !gccgo
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
type syscallFunc uintptr
|
||||
|
||||
var (
|
||||
%s
|
||||
)
|
||||
|
||||
// Implemented in runtime/syscall_aix.go.
|
||||
func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
||||
func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
|
||||
|
||||
%s
|
||||
`
|
||||
const srcTemplate3 = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
// +build gccgo
|
||||
|
||||
package %s
|
||||
|
||||
%s
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
`
|
||||
|
|
@ -1,335 +0,0 @@
|
|||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
This program reads a file containing function prototypes
|
||||
(like syscall_solaris.go) and generates system call bodies.
|
||||
The prototypes are marked by lines beginning with "//sys"
|
||||
and read like func declarations if //sys is replaced by func, but:
|
||||
* The parameter lists must give a name for each argument.
|
||||
This includes return parameters.
|
||||
* The parameter lists must give a type for each argument:
|
||||
the (x, y, z int) shorthand is not allowed.
|
||||
* If the return parameter is an error number, it must be named err.
|
||||
* If go func name needs to be different than its libc name,
|
||||
* or the function is not in libc, name could be specified
|
||||
* at the end, after "=" sign, like
|
||||
//sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
b32 = flag.Bool("b32", false, "32bit big-endian")
|
||||
l32 = flag.Bool("l32", false, "32bit little-endian")
|
||||
tags = flag.String("tags", "", "build tags")
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksyscall_solaris.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return *tags
|
||||
}
|
||||
|
||||
// Param is function parameter
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
// usage prints the program usage
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: go run mksyscall_solaris.go [-b32 | -l32] [-tags x,y] [file ...]\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// parseParamList parses parameter list and returns a slice of parameters
|
||||
func parseParamList(list string) []string {
|
||||
list = strings.TrimSpace(list)
|
||||
if list == "" {
|
||||
return []string{}
|
||||
}
|
||||
return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
|
||||
}
|
||||
|
||||
// parseParam splits a parameter into name and type
|
||||
func parseParam(p string) Param {
|
||||
ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
|
||||
if ps == nil {
|
||||
fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
|
||||
os.Exit(1)
|
||||
}
|
||||
return Param{ps[1], ps[2]}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
|
||||
endianness := ""
|
||||
if *b32 {
|
||||
endianness = "big-endian"
|
||||
} else if *l32 {
|
||||
endianness = "little-endian"
|
||||
}
|
||||
|
||||
pack := ""
|
||||
text := ""
|
||||
dynimports := ""
|
||||
linknames := ""
|
||||
var vars []string
|
||||
for _, path := range flag.Args() {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
s := bufio.NewScanner(file)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
t = strings.TrimSpace(t)
|
||||
t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
|
||||
if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
|
||||
pack = p[1]
|
||||
}
|
||||
nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
|
||||
if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Line must be of the form
|
||||
// func Open(path string, mode int, perm int) (fd int, err error)
|
||||
// Split into name, in params, out params.
|
||||
f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
|
||||
if f == nil {
|
||||
fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
|
||||
os.Exit(1)
|
||||
}
|
||||
funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
|
||||
|
||||
// Split argument lists on comma.
|
||||
in := parseParamList(inps)
|
||||
out := parseParamList(outps)
|
||||
|
||||
inps = strings.Join(in, ", ")
|
||||
outps = strings.Join(out, ", ")
|
||||
|
||||
// Try in vain to keep people from editing this file.
|
||||
// The theory is that they jump into the middle of the file
|
||||
// without reading the header.
|
||||
text += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
|
||||
|
||||
// So file name.
|
||||
if modname == "" {
|
||||
modname = "libc"
|
||||
}
|
||||
|
||||
// System call name.
|
||||
if sysname == "" {
|
||||
sysname = funct
|
||||
}
|
||||
|
||||
// System call pointer variable name.
|
||||
sysvarname := fmt.Sprintf("proc%s", sysname)
|
||||
|
||||
strconvfunc := "BytePtrFromString"
|
||||
strconvtype := "*byte"
|
||||
|
||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||
|
||||
// Runtime import of function to allow cross-platform builds.
|
||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
|
||||
// Link symbol to proc address variable.
|
||||
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
|
||||
// Library proc address variable.
|
||||
vars = append(vars, sysvarname)
|
||||
|
||||
// Go function header.
|
||||
outlist := strings.Join(out, ", ")
|
||||
if outlist != "" {
|
||||
outlist = fmt.Sprintf(" (%s)", outlist)
|
||||
}
|
||||
if text != "" {
|
||||
text += "\n"
|
||||
}
|
||||
text += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outlist)
|
||||
|
||||
// Check if err return available
|
||||
errvar := ""
|
||||
for _, param := range out {
|
||||
p := parseParam(param)
|
||||
if p.Type == "error" {
|
||||
errvar = p.Name
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare arguments to Syscall.
|
||||
var args []string
|
||||
n := 0
|
||||
for _, param := range in {
|
||||
p := parseParam(param)
|
||||
if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
|
||||
args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))")
|
||||
} else if p.Type == "string" && errvar != "" {
|
||||
text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
text += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
|
||||
text += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if p.Type == "string" {
|
||||
fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
|
||||
text += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
|
||||
text += fmt.Sprintf("\t_p%d, _ = %s(%s)\n", n, strconvfunc, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
|
||||
n++
|
||||
} else if s := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); s != nil {
|
||||
// Convert slice into pointer, length.
|
||||
// Have to be careful not to take address of &a[0] if len == 0:
|
||||
// pass nil in that case.
|
||||
text += fmt.Sprintf("\tvar _p%d *%s\n", n, s[1])
|
||||
text += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
|
||||
args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("uintptr(len(%s))", p.Name))
|
||||
n++
|
||||
} else if p.Type == "int64" && endianness != "" {
|
||||
if endianness == "big-endian" {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s>>32)", p.Name), fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name), fmt.Sprintf("uintptr(%s>>32)", p.Name))
|
||||
}
|
||||
} else if p.Type == "bool" {
|
||||
text += fmt.Sprintf("\tvar _p%d uint32\n", n)
|
||||
text += fmt.Sprintf("\tif %s {\n\t\t_p%d = 1\n\t} else {\n\t\t_p%d = 0\n\t}\n", p.Name, n, n)
|
||||
args = append(args, fmt.Sprintf("uintptr(_p%d)", n))
|
||||
n++
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("uintptr(%s)", p.Name))
|
||||
}
|
||||
}
|
||||
nargs := len(args)
|
||||
|
||||
// Determine which form to use; pad args with zeros.
|
||||
asm := "sysvicall6"
|
||||
if nonblock != nil {
|
||||
asm = "rawSysvicall6"
|
||||
}
|
||||
if len(args) <= 6 {
|
||||
for len(args) < 6 {
|
||||
args = append(args, "0")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: too many arguments to system call\n", path)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Actual call.
|
||||
arglist := strings.Join(args, ", ")
|
||||
call := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, arglist)
|
||||
|
||||
// Assign return values.
|
||||
body := ""
|
||||
ret := []string{"_", "_", "_"}
|
||||
doErrno := false
|
||||
for i := 0; i < len(out); i++ {
|
||||
p := parseParam(out[i])
|
||||
reg := ""
|
||||
if p.Name == "err" {
|
||||
reg = "e1"
|
||||
ret[2] = reg
|
||||
doErrno = true
|
||||
} else {
|
||||
reg = fmt.Sprintf("r%d", i)
|
||||
ret[i] = reg
|
||||
}
|
||||
if p.Type == "bool" {
|
||||
reg = fmt.Sprintf("%d != 0", reg)
|
||||
}
|
||||
if p.Type == "int64" && endianness != "" {
|
||||
// 64-bit number in r1:r0 or r0:r1.
|
||||
if i+2 > len(out) {
|
||||
fmt.Fprintf(os.Stderr, "%s: not enough registers for int64 return\n", path)
|
||||
os.Exit(1)
|
||||
}
|
||||
if endianness == "big-endian" {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i, i+1)
|
||||
} else {
|
||||
reg = fmt.Sprintf("int64(r%d)<<32 | int64(r%d)", i+1, i)
|
||||
}
|
||||
ret[i] = fmt.Sprintf("r%d", i)
|
||||
ret[i+1] = fmt.Sprintf("r%d", i+1)
|
||||
}
|
||||
if reg != "e1" {
|
||||
body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
|
||||
}
|
||||
}
|
||||
if ret[0] == "_" && ret[1] == "_" && ret[2] == "_" {
|
||||
text += fmt.Sprintf("\t%s\n", call)
|
||||
} else {
|
||||
text += fmt.Sprintf("\t%s, %s, %s := %s\n", ret[0], ret[1], ret[2], call)
|
||||
}
|
||||
text += body
|
||||
|
||||
if doErrno {
|
||||
text += "\tif e1 != 0 {\n"
|
||||
text += "\t\terr = e1\n"
|
||||
text += "\t}\n"
|
||||
}
|
||||
text += "\treturn\n"
|
||||
text += "}\n"
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
imp := ""
|
||||
if pack != "unix" {
|
||||
imp = "import \"golang.org/x/sys/unix\"\n"
|
||||
|
||||
}
|
||||
vardecls := "\t" + strings.Join(vars, ",\n\t")
|
||||
vardecls += " syscallFunc"
|
||||
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, text)
|
||||
}
|
||||
|
||||
const srcTemplate = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package %s
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
var (
|
||||
%s
|
||||
)
|
||||
|
||||
%s
|
||||
`
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// Generate system call table for DragonFly, NetBSD,
|
||||
// FreeBSD, OpenBSD or Darwin from master list
|
||||
// (for example, /usr/src/sys/kern/syscalls.master or
|
||||
// sys/syscall.h).
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
goos, goarch string
|
||||
)
|
||||
|
||||
// cmdLine returns this programs's commandline arguments
|
||||
func cmdLine() string {
|
||||
return "go run mksysnum.go " + strings.Join(os.Args[1:], " ")
|
||||
}
|
||||
|
||||
// buildTags returns build tags
|
||||
func buildTags() string {
|
||||
return fmt.Sprintf("%s,%s", goarch, goos)
|
||||
}
|
||||
|
||||
func checkErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// source string and substring slice for regexp
|
||||
type re struct {
|
||||
str string // source string
|
||||
sub []string // matched sub-string
|
||||
}
|
||||
|
||||
// Match performs regular expression match
|
||||
func (r *re) Match(exp string) bool {
|
||||
r.sub = regexp.MustCompile(exp).FindStringSubmatch(r.str)
|
||||
if r.sub != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// fetchFile fetches a text file from URL
|
||||
func fetchFile(URL string) io.Reader {
|
||||
resp, err := http.Get(URL)
|
||||
checkErr(err)
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
checkErr(err)
|
||||
return strings.NewReader(string(body))
|
||||
}
|
||||
|
||||
// readFile reads a text file from path
|
||||
func readFile(path string) io.Reader {
|
||||
file, err := os.Open(os.Args[1])
|
||||
checkErr(err)
|
||||
return file
|
||||
}
|
||||
|
||||
func format(name, num, proto string) string {
|
||||
name = strings.ToUpper(name)
|
||||
// There are multiple entries for enosys and nosys, so comment them out.
|
||||
nm := re{str: name}
|
||||
if nm.Match(`^SYS_E?NOSYS$`) {
|
||||
name = fmt.Sprintf("// %s", name)
|
||||
}
|
||||
if name == `SYS_SYS_EXIT` {
|
||||
name = `SYS_EXIT`
|
||||
}
|
||||
return fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Get the OS (using GOOS_TARGET if it exist)
|
||||
goos = os.Getenv("GOOS_TARGET")
|
||||
if goos == "" {
|
||||
goos = os.Getenv("GOOS")
|
||||
}
|
||||
// Get the architecture (using GOARCH_TARGET if it exists)
|
||||
goarch = os.Getenv("GOARCH_TARGET")
|
||||
if goarch == "" {
|
||||
goarch = os.Getenv("GOARCH")
|
||||
}
|
||||
// Check if GOOS and GOARCH environment variables are defined
|
||||
if goarch == "" || goos == "" {
|
||||
fmt.Fprintf(os.Stderr, "GOARCH or GOOS not defined in environment\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
file := strings.TrimSpace(os.Args[1])
|
||||
var syscalls io.Reader
|
||||
if strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "http://") {
|
||||
// Download syscalls.master file
|
||||
syscalls = fetchFile(file)
|
||||
} else {
|
||||
syscalls = readFile(file)
|
||||
}
|
||||
|
||||
var text, line string
|
||||
s := bufio.NewScanner(syscalls)
|
||||
for s.Scan() {
|
||||
t := re{str: line}
|
||||
if t.Match(`^(.*)\\$`) {
|
||||
// Handle continuation
|
||||
line = t.sub[1]
|
||||
line += strings.TrimLeft(s.Text(), " \t")
|
||||
} else {
|
||||
// New line
|
||||
line = s.Text()
|
||||
}
|
||||
t = re{str: line}
|
||||
if t.Match(`\\$`) {
|
||||
continue
|
||||
}
|
||||
t = re{str: line}
|
||||
|
||||
switch goos {
|
||||
case "dragonfly":
|
||||
if t.Match(`^([0-9]+)\s+STD\s+({ \S+\s+(\w+).*)$`) {
|
||||
num, proto := t.sub[1], t.sub[2]
|
||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "freebsd":
|
||||
if t.Match(`^([0-9]+)\s+\S+\s+(?:NO)?STD\s+({ \S+\s+(\w+).*)$`) {
|
||||
num, proto := t.sub[1], t.sub[2]
|
||||
name := fmt.Sprintf("SYS_%s", t.sub[3])
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "openbsd":
|
||||
if t.Match(`^([0-9]+)\s+STD\s+(NOLOCK\s+)?({ \S+\s+\*?(\w+).*)$`) {
|
||||
num, proto, name := t.sub[1], t.sub[3], t.sub[4]
|
||||
text += format(name, num, proto)
|
||||
}
|
||||
case "netbsd":
|
||||
if t.Match(`^([0-9]+)\s+((STD)|(NOERR))\s+(RUMP\s+)?({\s+\S+\s*\*?\s*\|(\S+)\|(\S*)\|(\w+).*\s+})(\s+(\S+))?$`) {
|
||||
num, proto, compat := t.sub[1], t.sub[6], t.sub[8]
|
||||
name := t.sub[7] + "_" + t.sub[9]
|
||||
if t.sub[11] != "" {
|
||||
name = t.sub[7] + "_" + t.sub[11]
|
||||
}
|
||||
name = strings.ToUpper(name)
|
||||
if compat == "" || compat == "13" || compat == "30" || compat == "50" {
|
||||
text += fmt.Sprintf(" %s = %s; // %s\n", name, num, proto)
|
||||
}
|
||||
}
|
||||
case "darwin":
|
||||
if t.Match(`^#define\s+SYS_(\w+)\s+([0-9]+)`) {
|
||||
name, num := t.sub[1], t.sub[2]
|
||||
name = strings.ToUpper(name)
|
||||
text += fmt.Sprintf(" SYS_%s = %s;\n", name, num)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unrecognized GOOS=%s\n", goos)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
}
|
||||
err := s.Err()
|
||||
checkErr(err)
|
||||
|
||||
fmt.Printf(template, cmdLine(), buildTags(), text)
|
||||
}
|
||||
|
||||
const template = `// %s
|
||||
// Code generated by the command above; see README.md. DO NOT EDIT.
|
||||
|
||||
// +build %s
|
||||
|
||||
package unix
|
||||
|
||||
const(
|
||||
%s)`
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
// +build aix
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See also mkerrors.sh and mkall.sh
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/limits.h>
|
||||
#include <sys/un.h>
|
||||
#include <utime.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/termio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
PathMax = C.PATH_MAX
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
type off64 C.off64_t
|
||||
type off C.off_t
|
||||
type Mode_t C.mode_t
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type StTimespec C.struct_st_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
type Timeval32 C.struct_timeval32
|
||||
|
||||
type Timex C.struct_timex
|
||||
|
||||
type Time_t C.time_t
|
||||
|
||||
type Tms C.struct_tms
|
||||
|
||||
type Utimbuf C.struct_utimbuf
|
||||
|
||||
type Timezone C.struct_timezone
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit64
|
||||
|
||||
type Pid_t C.pid_t
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
type dev_t C.dev_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type StatxTimestamp C.struct_statx_timestamp
|
||||
|
||||
type Statx_t C.struct_statx
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
)
|
||||
|
||||
type IfMsgHdr C.struct_if_msghdr
|
||||
|
||||
// Misc
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
||||
type Ustat_t C.struct_ustat
|
||||
|
||||
type Sigset_t C.sigset_t
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_REMOVEDIR = C.AT_REMOVEDIR
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Termio C.struct_termio
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
//poll
|
||||
|
||||
type PollFd struct {
|
||||
Fd int32
|
||||
Events uint16
|
||||
Revents uint16
|
||||
}
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
//flock_t
|
||||
|
||||
type Flock_t C.struct_flock64
|
||||
|
||||
// Statfs
|
||||
|
||||
type Fsid_t C.struct_fsid_t
|
||||
type Fsid64_t C.struct_fsid64_t
|
||||
|
||||
type Statfs_t C.struct_statfs
|
||||
|
||||
const RNDGETENTCNT = 0x80045200
|
||||
|
|
@ -1,283 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define __DARWIN_UNIX03 0
|
||||
#define KERNEL
|
||||
#define _DARWIN_USE_64_BIT_INODE
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/message.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_var.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
type Timeval32 C.struct_timeval32
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat64
|
||||
|
||||
type Statfs_t C.struct_statfs64
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Fstore_t C.struct_fstore
|
||||
|
||||
type Radvisory_t C.struct_radvisory
|
||||
|
||||
type Fbootstraptransfer_t C.struct_fbootstraptransfer
|
||||
|
||||
type Log2phys_t C.struct_log2phys
|
||||
|
||||
type Fsid C.struct_fsid
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet4Pktinfo C.struct_in_pktinfo
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Ptrace requests
|
||||
|
||||
const (
|
||||
PTRACE_TRACEME = C.PT_TRACE_ME
|
||||
PTRACE_CONT = C.PT_CONTINUE
|
||||
PTRACE_KILL = C.PT_KILL
|
||||
)
|
||||
|
||||
// Events (kqueue, kevent)
|
||||
|
||||
type Kevent_t C.struct_kevent
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr
|
||||
SizeofIfmaMsghdr2 = C.sizeof_struct_ifma_msghdr2
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfData C.struct_if_data
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type IfmaMsghdr C.struct_ifma_msghdr
|
||||
|
||||
type IfmaMsghdr2 C.struct_ifma_msghdr2
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
// fchmodat-like syscalls.
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_REMOVEDIR = C.AT_REMOVEDIR
|
||||
AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
// uname
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
||||
// Clockinfo
|
||||
|
||||
const SizeofClockinfo = C.sizeof_struct_clockinfo
|
||||
|
||||
type Clockinfo C.struct_clockinfo
|
||||
|
|
@ -1,263 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type Statfs_t C.struct_statfs
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
type Fsid C.struct_fsid
|
||||
|
||||
// File system limits
|
||||
|
||||
const (
|
||||
PathMax = C.PATH_MAX
|
||||
)
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Ptrace requests
|
||||
|
||||
const (
|
||||
PTRACE_TRACEME = C.PT_TRACE_ME
|
||||
PTRACE_CONT = C.PT_CONTINUE
|
||||
PTRACE_KILL = C.PT_KILL
|
||||
)
|
||||
|
||||
// Events (kqueue, kevent)
|
||||
|
||||
type Kevent_t C.struct_kevent
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr
|
||||
SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfData C.struct_if_data
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type IfmaMsghdr C.struct_ifma_msghdr
|
||||
|
||||
type IfAnnounceMsghdr C.struct_if_announcemsghdr
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
// fchmodat-like syscalls.
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
// Uname
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
|
@ -1,356 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define _WANT_FREEBSD11_STAT 1
|
||||
#define _WANT_FREEBSD11_STATFS 1
|
||||
#define _WANT_FREEBSD11_DIRENT 1
|
||||
#define _WANT_FREEBSD11_KEVENT 1
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/capsicum.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
// This structure is a duplicate of if_data on FreeBSD 8-STABLE.
|
||||
// See /usr/include/net/if.h.
|
||||
struct if_data8 {
|
||||
u_char ifi_type;
|
||||
u_char ifi_physical;
|
||||
u_char ifi_addrlen;
|
||||
u_char ifi_hdrlen;
|
||||
u_char ifi_link_state;
|
||||
u_char ifi_spare_char1;
|
||||
u_char ifi_spare_char2;
|
||||
u_char ifi_datalen;
|
||||
u_long ifi_mtu;
|
||||
u_long ifi_metric;
|
||||
u_long ifi_baudrate;
|
||||
u_long ifi_ipackets;
|
||||
u_long ifi_ierrors;
|
||||
u_long ifi_opackets;
|
||||
u_long ifi_oerrors;
|
||||
u_long ifi_collisions;
|
||||
u_long ifi_ibytes;
|
||||
u_long ifi_obytes;
|
||||
u_long ifi_imcasts;
|
||||
u_long ifi_omcasts;
|
||||
u_long ifi_iqdrops;
|
||||
u_long ifi_noproto;
|
||||
u_long ifi_hwassist;
|
||||
// FIXME: these are now unions, so maybe need to change definitions?
|
||||
#undef ifi_epoch
|
||||
time_t ifi_epoch;
|
||||
#undef ifi_lastchange
|
||||
struct timeval ifi_lastchange;
|
||||
};
|
||||
|
||||
// This structure is a duplicate of if_msghdr on FreeBSD 8-STABLE.
|
||||
// See /usr/include/net/if.h.
|
||||
struct if_msghdr8 {
|
||||
u_short ifm_msglen;
|
||||
u_char ifm_version;
|
||||
u_char ifm_type;
|
||||
int ifm_addrs;
|
||||
int ifm_flags;
|
||||
u_short ifm_index;
|
||||
struct if_data8 ifm_data;
|
||||
};
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
const (
|
||||
_statfsVersion = C.STATFS_VERSION
|
||||
_dirblksiz = C.DIRBLKSIZ
|
||||
)
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type stat_freebsd11_t C.struct_freebsd11_stat
|
||||
|
||||
type Statfs_t C.struct_statfs
|
||||
|
||||
type statfs_freebsd11_t C.struct_freebsd11_statfs
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
type dirent_freebsd11 C.struct_freebsd11_dirent
|
||||
|
||||
type Fsid C.struct_fsid
|
||||
|
||||
// File system limits
|
||||
|
||||
const (
|
||||
PathMax = C.PATH_MAX
|
||||
)
|
||||
|
||||
// Advice to Fadvise
|
||||
|
||||
const (
|
||||
FADV_NORMAL = C.POSIX_FADV_NORMAL
|
||||
FADV_RANDOM = C.POSIX_FADV_RANDOM
|
||||
FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL
|
||||
FADV_WILLNEED = C.POSIX_FADV_WILLNEED
|
||||
FADV_DONTNEED = C.POSIX_FADV_DONTNEED
|
||||
FADV_NOREUSE = C.POSIX_FADV_NOREUSE
|
||||
)
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPMreqn C.struct_ip_mreqn
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPMreqn = C.sizeof_struct_ip_mreqn
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Ptrace requests
|
||||
|
||||
const (
|
||||
PTRACE_TRACEME = C.PT_TRACE_ME
|
||||
PTRACE_CONT = C.PT_CONTINUE
|
||||
PTRACE_KILL = C.PT_KILL
|
||||
)
|
||||
|
||||
// Events (kqueue, kevent)
|
||||
|
||||
type Kevent_t C.struct_kevent_freebsd11
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
sizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr8
|
||||
sizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfData = C.sizeof_struct_if_data8
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr
|
||||
SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type ifMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr8
|
||||
|
||||
type ifData C.struct_if_data
|
||||
|
||||
type IfData C.struct_if_data8
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type IfmaMsghdr C.struct_ifma_msghdr
|
||||
|
||||
type IfAnnounceMsghdr C.struct_if_announcemsghdr
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfZbuf = C.sizeof_struct_bpf_zbuf
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
SizeofBpfZbufHeader = C.sizeof_struct_bpf_zbuf_header
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfZbuf C.struct_bpf_zbuf
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
type BpfZbufHeader C.struct_bpf_zbuf_header
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
// fchmodat-like syscalls.
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_REMOVEDIR = C.AT_REMOVEDIR
|
||||
AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLINIGNEOF = C.POLLINIGNEOF
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
// Capabilities
|
||||
|
||||
type CapRights C.struct_cap_rights
|
||||
|
||||
// Uname
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
|
@ -1,289 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type Statfs_t C.struct_statfs
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
type Fsid C.fsid_t
|
||||
|
||||
// File system limits
|
||||
|
||||
const (
|
||||
PathMax = C.PATH_MAX
|
||||
)
|
||||
|
||||
// Advice to Fadvise
|
||||
|
||||
const (
|
||||
FADV_NORMAL = C.POSIX_FADV_NORMAL
|
||||
FADV_RANDOM = C.POSIX_FADV_RANDOM
|
||||
FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL
|
||||
FADV_WILLNEED = C.POSIX_FADV_WILLNEED
|
||||
FADV_DONTNEED = C.POSIX_FADV_DONTNEED
|
||||
FADV_NOREUSE = C.POSIX_FADV_NOREUSE
|
||||
)
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Ptrace requests
|
||||
|
||||
const (
|
||||
PTRACE_TRACEME = C.PT_TRACE_ME
|
||||
PTRACE_CONT = C.PT_CONTINUE
|
||||
PTRACE_KILL = C.PT_KILL
|
||||
)
|
||||
|
||||
// Events (kqueue, kevent)
|
||||
|
||||
type Kevent_t C.struct_kevent
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfData C.struct_if_data
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type IfAnnounceMsghdr C.struct_if_announcemsghdr
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
type Mclpool C.struct_mclpool
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
type BpfTimeval C.struct_bpf_timeval
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
type Ptmget C.struct_ptmget
|
||||
|
||||
// fchmodat-like syscalls.
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
// Sysctl
|
||||
|
||||
type Sysctlnode C.struct_sysctlnode
|
||||
|
||||
// Uname
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
||||
// Clockinfo
|
||||
|
||||
const SizeofClockinfo = C.sizeof_struct_clockinfo
|
||||
|
||||
type Clockinfo C.struct_clockinfo
|
||||
|
|
@ -1,282 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/wait.h>
|
||||
#include <uvm/uvmexp.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type Statfs_t C.struct_statfs
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
type Fsid C.fsid_t
|
||||
|
||||
// File system limits
|
||||
|
||||
const (
|
||||
PathMax = C.PATH_MAX
|
||||
)
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Ptrace requests
|
||||
|
||||
const (
|
||||
PTRACE_TRACEME = C.PT_TRACE_ME
|
||||
PTRACE_CONT = C.PT_CONTINUE
|
||||
PTRACE_KILL = C.PT_KILL
|
||||
)
|
||||
|
||||
// Events (kqueue, kevent)
|
||||
|
||||
type Kevent_t C.struct_kevent
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfData C.struct_if_data
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type IfAnnounceMsghdr C.struct_if_announcemsghdr
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
type Mclpool C.struct_mclpool
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
type BpfTimeval C.struct_bpf_timeval
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
// fchmodat-like syscalls.
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
)
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
||||
// Signal Sets
|
||||
|
||||
type Sigset_t C.sigset_t
|
||||
|
||||
// Uname
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
||||
// Uvmexp
|
||||
|
||||
const SizeofUvmexp = C.sizeof_struct_uvmexp
|
||||
|
||||
type Uvmexp C.struct_uvmexp
|
||||
|
||||
// Clockinfo
|
||||
|
||||
const SizeofClockinfo = C.sizeof_struct_clockinfo
|
||||
|
||||
type Clockinfo C.struct_clockinfo
|
||||
|
|
@ -1,266 +0,0 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
Input to cgo -godefs. See README.md
|
||||
*/
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package unix
|
||||
|
||||
/*
|
||||
#define KERNEL
|
||||
// These defines ensure that builds done on newer versions of Solaris are
|
||||
// backwards-compatible with older versions of Solaris and
|
||||
// OpenSolaris-based derivatives.
|
||||
#define __USE_SUNOS_SOCKETS__ // msghdr
|
||||
#define __USE_LEGACY_PROTOTYPES__ // iovec
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <limits.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <termio.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/route.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/icmp6.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <ustat.h>
|
||||
#include <utime.h>
|
||||
|
||||
enum {
|
||||
sizeofPtr = sizeof(void*),
|
||||
};
|
||||
|
||||
union sockaddr_all {
|
||||
struct sockaddr s1; // this one gets used for fields
|
||||
struct sockaddr_in s2; // these pad it out
|
||||
struct sockaddr_in6 s3;
|
||||
struct sockaddr_un s4;
|
||||
struct sockaddr_dl s5;
|
||||
};
|
||||
|
||||
struct sockaddr_any {
|
||||
struct sockaddr addr;
|
||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
||||
};
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
// Machine characteristics
|
||||
|
||||
const (
|
||||
SizeofPtr = C.sizeofPtr
|
||||
SizeofShort = C.sizeof_short
|
||||
SizeofInt = C.sizeof_int
|
||||
SizeofLong = C.sizeof_long
|
||||
SizeofLongLong = C.sizeof_longlong
|
||||
PathMax = C.PATH_MAX
|
||||
MaxHostNameLen = C.MAXHOSTNAMELEN
|
||||
)
|
||||
|
||||
// Basic types
|
||||
|
||||
type (
|
||||
_C_short C.short
|
||||
_C_int C.int
|
||||
_C_long C.long
|
||||
_C_long_long C.longlong
|
||||
)
|
||||
|
||||
// Time
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
type Timeval C.struct_timeval
|
||||
|
||||
type Timeval32 C.struct_timeval32
|
||||
|
||||
type Tms C.struct_tms
|
||||
|
||||
type Utimbuf C.struct_utimbuf
|
||||
|
||||
// Processes
|
||||
|
||||
type Rusage C.struct_rusage
|
||||
|
||||
type Rlimit C.struct_rlimit
|
||||
|
||||
type _Gid_t C.gid_t
|
||||
|
||||
// Files
|
||||
|
||||
type Stat_t C.struct_stat
|
||||
|
||||
type Flock_t C.struct_flock
|
||||
|
||||
type Dirent C.struct_dirent
|
||||
|
||||
// Filesystems
|
||||
|
||||
type _Fsblkcnt_t C.fsblkcnt_t
|
||||
|
||||
type Statvfs_t C.struct_statvfs
|
||||
|
||||
// Sockets
|
||||
|
||||
type RawSockaddrInet4 C.struct_sockaddr_in
|
||||
|
||||
type RawSockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
type RawSockaddrUnix C.struct_sockaddr_un
|
||||
|
||||
type RawSockaddrDatalink C.struct_sockaddr_dl
|
||||
|
||||
type RawSockaddr C.struct_sockaddr
|
||||
|
||||
type RawSockaddrAny C.struct_sockaddr_any
|
||||
|
||||
type _Socklen C.socklen_t
|
||||
|
||||
type Linger C.struct_linger
|
||||
|
||||
type Iovec C.struct_iovec
|
||||
|
||||
type IPMreq C.struct_ip_mreq
|
||||
|
||||
type IPv6Mreq C.struct_ipv6_mreq
|
||||
|
||||
type Msghdr C.struct_msghdr
|
||||
|
||||
type Cmsghdr C.struct_cmsghdr
|
||||
|
||||
type Inet6Pktinfo C.struct_in6_pktinfo
|
||||
|
||||
type IPv6MTUInfo C.struct_ip6_mtuinfo
|
||||
|
||||
type ICMPv6Filter C.struct_icmp6_filter
|
||||
|
||||
const (
|
||||
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
|
||||
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
|
||||
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
|
||||
SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
|
||||
SizeofLinger = C.sizeof_struct_linger
|
||||
SizeofIPMreq = C.sizeof_struct_ip_mreq
|
||||
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
|
||||
SizeofMsghdr = C.sizeof_struct_msghdr
|
||||
SizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
|
||||
SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
|
||||
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
|
||||
)
|
||||
|
||||
// Select
|
||||
|
||||
type FdSet C.fd_set
|
||||
|
||||
// Misc
|
||||
|
||||
type Utsname C.struct_utsname
|
||||
|
||||
type Ustat_t C.struct_ustat
|
||||
|
||||
const (
|
||||
AT_FDCWD = C.AT_FDCWD
|
||||
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
|
||||
AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
|
||||
AT_REMOVEDIR = C.AT_REMOVEDIR
|
||||
AT_EACCESS = C.AT_EACCESS
|
||||
)
|
||||
|
||||
// Routing and interface messages
|
||||
|
||||
const (
|
||||
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
|
||||
SizeofIfData = C.sizeof_struct_if_data
|
||||
SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
|
||||
SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
|
||||
SizeofRtMetrics = C.sizeof_struct_rt_metrics
|
||||
)
|
||||
|
||||
type IfMsghdr C.struct_if_msghdr
|
||||
|
||||
type IfData C.struct_if_data
|
||||
|
||||
type IfaMsghdr C.struct_ifa_msghdr
|
||||
|
||||
type RtMsghdr C.struct_rt_msghdr
|
||||
|
||||
type RtMetrics C.struct_rt_metrics
|
||||
|
||||
// Berkeley packet filter
|
||||
|
||||
const (
|
||||
SizeofBpfVersion = C.sizeof_struct_bpf_version
|
||||
SizeofBpfStat = C.sizeof_struct_bpf_stat
|
||||
SizeofBpfProgram = C.sizeof_struct_bpf_program
|
||||
SizeofBpfInsn = C.sizeof_struct_bpf_insn
|
||||
SizeofBpfHdr = C.sizeof_struct_bpf_hdr
|
||||
)
|
||||
|
||||
type BpfVersion C.struct_bpf_version
|
||||
|
||||
type BpfStat C.struct_bpf_stat
|
||||
|
||||
type BpfProgram C.struct_bpf_program
|
||||
|
||||
type BpfInsn C.struct_bpf_insn
|
||||
|
||||
type BpfTimeval C.struct_bpf_timeval
|
||||
|
||||
type BpfHdr C.struct_bpf_hdr
|
||||
|
||||
// Terminal handling
|
||||
|
||||
type Termios C.struct_termios
|
||||
|
||||
type Termio C.struct_termio
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
||||
// poll
|
||||
|
||||
type PollFd C.struct_pollfd
|
||||
|
||||
const (
|
||||
POLLERR = C.POLLERR
|
||||
POLLHUP = C.POLLHUP
|
||||
POLLIN = C.POLLIN
|
||||
POLLNVAL = C.POLLNVAL
|
||||
POLLOUT = C.POLLOUT
|
||||
POLLPRI = C.POLLPRI
|
||||
POLLRDBAND = C.POLLRDBAND
|
||||
POLLRDNORM = C.POLLRDNORM
|
||||
POLLWRBAND = C.POLLWRBAND
|
||||
POLLWRNORM = C.POLLWRNORM
|
||||
)
|
||||
|
|
@ -5,7 +5,7 @@ go_library(
|
|||
srcs = ["internal.go"],
|
||||
importmap = "k8s.io/kops/vendor/golang.org/x/text/encoding/internal",
|
||||
importpath = "golang.org/x/text/encoding/internal",
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//vendor/golang.org/x/text/encoding:__subpackages__"],
|
||||
deps = [
|
||||
"//vendor/golang.org/x/text/encoding:go_default_library",
|
||||
"//vendor/golang.org/x/text/encoding/internal/identifier:go_default_library",
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/internal/gen"
|
||||
)
|
||||
|
||||
type registry struct {
|
||||
XMLName xml.Name `xml:"registry"`
|
||||
Updated string `xml:"updated"`
|
||||
Registry []struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Record []struct {
|
||||
Name string `xml:"name"`
|
||||
Xref []struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Data string `xml:"data,attr"`
|
||||
} `xml:"xref"`
|
||||
Desc struct {
|
||||
Data string `xml:",innerxml"`
|
||||
// Any []struct {
|
||||
// Data string `xml:",chardata"`
|
||||
// } `xml:",any"`
|
||||
// Data string `xml:",chardata"`
|
||||
} `xml:"description,"`
|
||||
MIB string `xml:"value"`
|
||||
Alias []string `xml:"alias"`
|
||||
MIME string `xml:"preferred_alias"`
|
||||
} `xml:"record"`
|
||||
} `xml:"registry"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := gen.OpenIANAFile("assignments/character-sets/character-sets.xml")
|
||||
reg := ®istry{}
|
||||
if err := xml.NewDecoder(r).Decode(®); err != nil && err != io.EOF {
|
||||
log.Fatalf("Error decoding charset registry: %v", err)
|
||||
}
|
||||
if len(reg.Registry) == 0 || reg.Registry[0].ID != "character-sets-1" {
|
||||
log.Fatalf("Unexpected ID %s", reg.Registry[0].ID)
|
||||
}
|
||||
|
||||
w := &bytes.Buffer{}
|
||||
fmt.Fprintf(w, "const (\n")
|
||||
for _, rec := range reg.Registry[0].Record {
|
||||
constName := ""
|
||||
for _, a := range rec.Alias {
|
||||
if strings.HasPrefix(a, "cs") && strings.IndexByte(a, '-') == -1 {
|
||||
// Some of the constant definitions have comments in them. Strip those.
|
||||
constName = strings.Title(strings.SplitN(a[2:], "\n", 2)[0])
|
||||
}
|
||||
}
|
||||
if constName == "" {
|
||||
switch rec.MIB {
|
||||
case "2085":
|
||||
constName = "HZGB2312" // Not listed as alias for some reason.
|
||||
default:
|
||||
log.Fatalf("No cs alias defined for %s.", rec.MIB)
|
||||
}
|
||||
}
|
||||
if rec.MIME != "" {
|
||||
rec.MIME = fmt.Sprintf(" (MIME: %s)", rec.MIME)
|
||||
}
|
||||
fmt.Fprintf(w, "// %s is the MIB identifier with IANA name %s%s.\n//\n", constName, rec.Name, rec.MIME)
|
||||
if len(rec.Desc.Data) > 0 {
|
||||
fmt.Fprint(w, "// ")
|
||||
d := xml.NewDecoder(strings.NewReader(rec.Desc.Data))
|
||||
inElem := true
|
||||
attr := ""
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
switch x := t.(type) {
|
||||
case xml.CharData:
|
||||
attr = "" // Don't need attribute info.
|
||||
a := bytes.Split([]byte(x), []byte("\n"))
|
||||
for i, b := range a {
|
||||
if b = bytes.TrimSpace(b); len(b) != 0 {
|
||||
if !inElem && i > 0 {
|
||||
fmt.Fprint(w, "\n// ")
|
||||
}
|
||||
inElem = false
|
||||
fmt.Fprintf(w, "%s ", string(b))
|
||||
}
|
||||
}
|
||||
case xml.StartElement:
|
||||
if x.Name.Local == "xref" {
|
||||
inElem = true
|
||||
use := false
|
||||
for _, a := range x.Attr {
|
||||
if a.Name.Local == "type" {
|
||||
use = use || a.Value != "person"
|
||||
}
|
||||
if a.Name.Local == "data" && use {
|
||||
attr = a.Value + " "
|
||||
}
|
||||
}
|
||||
}
|
||||
case xml.EndElement:
|
||||
inElem = false
|
||||
fmt.Fprint(w, attr)
|
||||
}
|
||||
}
|
||||
fmt.Fprint(w, "\n")
|
||||
}
|
||||
for _, x := range rec.Xref {
|
||||
switch x.Type {
|
||||
case "rfc":
|
||||
fmt.Fprintf(w, "// Reference: %s\n", strings.ToUpper(x.Data))
|
||||
case "uri":
|
||||
fmt.Fprintf(w, "// Reference: %s\n", x.Data)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(w, "%s MIB = %s\n", constName, rec.MIB)
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
fmt.Fprintln(w, ")")
|
||||
|
||||
gen.WriteGoFile("mib.go", "identifier", w.Bytes())
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"golang.org/x/text/internal/gen"
|
||||
"golang.org/x/text/internal/triegen"
|
||||
"golang.org/x/text/internal/ucd"
|
||||
)
|
||||
|
||||
var outputFile = flag.String("out", "tables.go", "output file")
|
||||
|
||||
func main() {
|
||||
gen.Init()
|
||||
gen.Repackage("gen_trieval.go", "trieval.go", "bidi")
|
||||
gen.Repackage("gen_ranges.go", "ranges_test.go", "bidi")
|
||||
|
||||
genTables()
|
||||
}
|
||||
|
||||
// bidiClass names and codes taken from class "bc" in
|
||||
// https://www.unicode.org/Public/8.0.0/ucd/PropertyValueAliases.txt
|
||||
var bidiClass = map[string]Class{
|
||||
"AL": AL, // ArabicLetter
|
||||
"AN": AN, // ArabicNumber
|
||||
"B": B, // ParagraphSeparator
|
||||
"BN": BN, // BoundaryNeutral
|
||||
"CS": CS, // CommonSeparator
|
||||
"EN": EN, // EuropeanNumber
|
||||
"ES": ES, // EuropeanSeparator
|
||||
"ET": ET, // EuropeanTerminator
|
||||
"L": L, // LeftToRight
|
||||
"NSM": NSM, // NonspacingMark
|
||||
"ON": ON, // OtherNeutral
|
||||
"R": R, // RightToLeft
|
||||
"S": S, // SegmentSeparator
|
||||
"WS": WS, // WhiteSpace
|
||||
|
||||
"FSI": Control,
|
||||
"PDF": Control,
|
||||
"PDI": Control,
|
||||
"LRE": Control,
|
||||
"LRI": Control,
|
||||
"LRO": Control,
|
||||
"RLE": Control,
|
||||
"RLI": Control,
|
||||
"RLO": Control,
|
||||
}
|
||||
|
||||
func genTables() {
|
||||
if numClass > 0x0F {
|
||||
log.Fatalf("Too many Class constants (%#x > 0x0F).", numClass)
|
||||
}
|
||||
w := gen.NewCodeWriter()
|
||||
defer w.WriteVersionedGoFile(*outputFile, "bidi")
|
||||
|
||||
gen.WriteUnicodeVersion(w)
|
||||
|
||||
t := triegen.NewTrie("bidi")
|
||||
|
||||
// Build data about bracket mapping. These bits need to be or-ed with
|
||||
// any other bits.
|
||||
orMask := map[rune]uint64{}
|
||||
|
||||
xorMap := map[rune]int{}
|
||||
xorMasks := []rune{0} // First value is no-op.
|
||||
|
||||
ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) {
|
||||
r1 := p.Rune(0)
|
||||
r2 := p.Rune(1)
|
||||
xor := r1 ^ r2
|
||||
if _, ok := xorMap[xor]; !ok {
|
||||
xorMap[xor] = len(xorMasks)
|
||||
xorMasks = append(xorMasks, xor)
|
||||
}
|
||||
entry := uint64(xorMap[xor]) << xorMaskShift
|
||||
switch p.String(2) {
|
||||
case "o":
|
||||
entry |= openMask
|
||||
case "c", "n":
|
||||
default:
|
||||
log.Fatalf("Unknown bracket class %q.", p.String(2))
|
||||
}
|
||||
orMask[r1] = entry
|
||||
})
|
||||
|
||||
w.WriteComment(`
|
||||
xorMasks contains masks to be xor-ed with brackets to get the reverse
|
||||
version.`)
|
||||
w.WriteVar("xorMasks", xorMasks)
|
||||
|
||||
done := map[rune]bool{}
|
||||
|
||||
insert := func(r rune, c Class) {
|
||||
if !done[r] {
|
||||
t.Insert(r, orMask[r]|uint64(c))
|
||||
done[r] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the derived BiDi properties.
|
||||
ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) {
|
||||
r := p.Rune(0)
|
||||
class, ok := bidiClass[p.String(1)]
|
||||
if !ok {
|
||||
log.Fatalf("%U: Unknown BiDi class %q", r, p.String(1))
|
||||
}
|
||||
insert(r, class)
|
||||
})
|
||||
visitDefaults(insert)
|
||||
|
||||
// TODO: use sparse blocks. This would reduce table size considerably
|
||||
// from the looks of it.
|
||||
|
||||
sz, err := t.Gen(w)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w.Size += sz
|
||||
}
|
||||
|
||||
// dummy values to make methods in gen_common compile. The real versions
|
||||
// will be generated by this file to tables.go.
|
||||
var (
|
||||
xorMasks []rune
|
||||
)
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/text/internal/gen"
|
||||
"golang.org/x/text/internal/ucd"
|
||||
"golang.org/x/text/unicode/rangetable"
|
||||
)
|
||||
|
||||
// These tables are hand-extracted from:
|
||||
// https://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedBidiClass.txt
|
||||
func visitDefaults(fn func(r rune, c Class)) {
|
||||
// first write default values for ranges listed above.
|
||||
visitRunes(fn, AL, []rune{
|
||||
0x0600, 0x07BF, // Arabic
|
||||
0x08A0, 0x08FF, // Arabic Extended-A
|
||||
0xFB50, 0xFDCF, // Arabic Presentation Forms
|
||||
0xFDF0, 0xFDFF,
|
||||
0xFE70, 0xFEFF,
|
||||
0x0001EE00, 0x0001EEFF, // Arabic Mathematical Alpha Symbols
|
||||
})
|
||||
visitRunes(fn, R, []rune{
|
||||
0x0590, 0x05FF, // Hebrew
|
||||
0x07C0, 0x089F, // Nko et al.
|
||||
0xFB1D, 0xFB4F,
|
||||
0x00010800, 0x00010FFF, // Cypriot Syllabary et. al.
|
||||
0x0001E800, 0x0001EDFF,
|
||||
0x0001EF00, 0x0001EFFF,
|
||||
})
|
||||
visitRunes(fn, ET, []rune{ // European Terminator
|
||||
0x20A0, 0x20Cf, // Currency symbols
|
||||
})
|
||||
rangetable.Visit(unicode.Noncharacter_Code_Point, func(r rune) {
|
||||
fn(r, BN) // Boundary Neutral
|
||||
})
|
||||
ucd.Parse(gen.OpenUCDFile("DerivedCoreProperties.txt"), func(p *ucd.Parser) {
|
||||
if p.String(1) == "Default_Ignorable_Code_Point" {
|
||||
fn(p.Rune(0), BN) // Boundary Neutral
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func visitRunes(fn func(r rune, c Class), c Class, runes []rune) {
|
||||
for i := 0; i < len(runes); i += 2 {
|
||||
lo, hi := runes[i], runes[i+1]
|
||||
for j := lo; j <= hi; j++ {
|
||||
fn(j, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// Class is the Unicode BiDi class. Each rune has a single class.
|
||||
type Class uint
|
||||
|
||||
const (
|
||||
L Class = iota // LeftToRight
|
||||
R // RightToLeft
|
||||
EN // EuropeanNumber
|
||||
ES // EuropeanSeparator
|
||||
ET // EuropeanTerminator
|
||||
AN // ArabicNumber
|
||||
CS // CommonSeparator
|
||||
B // ParagraphSeparator
|
||||
S // SegmentSeparator
|
||||
WS // WhiteSpace
|
||||
ON // OtherNeutral
|
||||
BN // BoundaryNeutral
|
||||
NSM // NonspacingMark
|
||||
AL // ArabicLetter
|
||||
Control // Control LRO - PDI
|
||||
|
||||
numClass
|
||||
|
||||
LRO // LeftToRightOverride
|
||||
RLO // RightToLeftOverride
|
||||
LRE // LeftToRightEmbedding
|
||||
RLE // RightToLeftEmbedding
|
||||
PDF // PopDirectionalFormat
|
||||
LRI // LeftToRightIsolate
|
||||
RLI // RightToLeftIsolate
|
||||
FSI // FirstStrongIsolate
|
||||
PDI // PopDirectionalIsolate
|
||||
|
||||
unknownClass = ^Class(0)
|
||||
)
|
||||
|
||||
var controlToClass = map[rune]Class{
|
||||
0x202D: LRO, // LeftToRightOverride,
|
||||
0x202E: RLO, // RightToLeftOverride,
|
||||
0x202A: LRE, // LeftToRightEmbedding,
|
||||
0x202B: RLE, // RightToLeftEmbedding,
|
||||
0x202C: PDF, // PopDirectionalFormat,
|
||||
0x2066: LRI, // LeftToRightIsolate,
|
||||
0x2067: RLI, // RightToLeftIsolate,
|
||||
0x2068: FSI, // FirstStrongIsolate,
|
||||
0x2069: PDI, // PopDirectionalIsolate,
|
||||
}
|
||||
|
||||
// A trie entry has the following bits:
|
||||
// 7..5 XOR mask for brackets
|
||||
// 4 1: Bracket open, 0: Bracket close
|
||||
// 3..0 Class type
|
||||
|
||||
const (
|
||||
openMask = 0x10
|
||||
xorMaskShift = 5
|
||||
)
|
||||
|
|
@ -1,986 +0,0 @@
|
|||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// Normalization table generator.
|
||||
// Data read from the web.
|
||||
// See forminfo.go for a description of the trie values associated with each rune.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/internal/gen"
|
||||
"golang.org/x/text/internal/triegen"
|
||||
"golang.org/x/text/internal/ucd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gen.Init()
|
||||
loadUnicodeData()
|
||||
compactCCC()
|
||||
loadCompositionExclusions()
|
||||
completeCharFields(FCanonical)
|
||||
completeCharFields(FCompatibility)
|
||||
computeNonStarterCounts()
|
||||
verifyComputed()
|
||||
printChars()
|
||||
testDerived()
|
||||
printTestdata()
|
||||
makeTables()
|
||||
}
|
||||
|
||||
var (
|
||||
tablelist = flag.String("tables",
|
||||
"all",
|
||||
"comma-separated list of which tables to generate; "+
|
||||
"can be 'decomp', 'recomp', 'info' and 'all'")
|
||||
test = flag.Bool("test",
|
||||
false,
|
||||
"test existing tables against DerivedNormalizationProps and generate test data for regression testing")
|
||||
verbose = flag.Bool("verbose",
|
||||
false,
|
||||
"write data to stdout as it is parsed")
|
||||
)
|
||||
|
||||
const MaxChar = 0x10FFFF // anything above this shouldn't exist
|
||||
|
||||
// Quick Check properties of runes allow us to quickly
|
||||
// determine whether a rune may occur in a normal form.
|
||||
// For a given normal form, a rune may be guaranteed to occur
|
||||
// verbatim (QC=Yes), may or may not combine with another
|
||||
// rune (QC=Maybe), or may not occur (QC=No).
|
||||
type QCResult int
|
||||
|
||||
const (
|
||||
QCUnknown QCResult = iota
|
||||
QCYes
|
||||
QCNo
|
||||
QCMaybe
|
||||
)
|
||||
|
||||
func (r QCResult) String() string {
|
||||
switch r {
|
||||
case QCYes:
|
||||
return "Yes"
|
||||
case QCNo:
|
||||
return "No"
|
||||
case QCMaybe:
|
||||
return "Maybe"
|
||||
}
|
||||
return "***UNKNOWN***"
|
||||
}
|
||||
|
||||
const (
|
||||
FCanonical = iota // NFC or NFD
|
||||
FCompatibility // NFKC or NFKD
|
||||
FNumberOfFormTypes
|
||||
)
|
||||
|
||||
const (
|
||||
MComposed = iota // NFC or NFKC
|
||||
MDecomposed // NFD or NFKD
|
||||
MNumberOfModes
|
||||
)
|
||||
|
||||
// This contains only the properties we're interested in.
|
||||
type Char struct {
|
||||
name string
|
||||
codePoint rune // if zero, this index is not a valid code point.
|
||||
ccc uint8 // canonical combining class
|
||||
origCCC uint8
|
||||
excludeInComp bool // from CompositionExclusions.txt
|
||||
compatDecomp bool // it has a compatibility expansion
|
||||
|
||||
nTrailingNonStarters uint8
|
||||
nLeadingNonStarters uint8 // must be equal to trailing if non-zero
|
||||
|
||||
forms [FNumberOfFormTypes]FormInfo // For FCanonical and FCompatibility
|
||||
|
||||
state State
|
||||
}
|
||||
|
||||
var chars = make([]Char, MaxChar+1)
|
||||
var cccMap = make(map[uint8]uint8)
|
||||
|
||||
func (c Char) String() string {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
fmt.Fprintf(buf, "%U [%s]:\n", c.codePoint, c.name)
|
||||
fmt.Fprintf(buf, " ccc: %v\n", c.ccc)
|
||||
fmt.Fprintf(buf, " excludeInComp: %v\n", c.excludeInComp)
|
||||
fmt.Fprintf(buf, " compatDecomp: %v\n", c.compatDecomp)
|
||||
fmt.Fprintf(buf, " state: %v\n", c.state)
|
||||
fmt.Fprintf(buf, " NFC:\n")
|
||||
fmt.Fprint(buf, c.forms[FCanonical])
|
||||
fmt.Fprintf(buf, " NFKC:\n")
|
||||
fmt.Fprint(buf, c.forms[FCompatibility])
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// In UnicodeData.txt, some ranges are marked like this:
|
||||
// 3400;<CJK Ideograph Extension A, First>;Lo;0;L;;;;;N;;;;;
|
||||
// 4DB5;<CJK Ideograph Extension A, Last>;Lo;0;L;;;;;N;;;;;
|
||||
// parseCharacter keeps a state variable indicating the weirdness.
|
||||
type State int
|
||||
|
||||
const (
|
||||
SNormal State = iota // known to be zero for the type
|
||||
SFirst
|
||||
SLast
|
||||
SMissing
|
||||
)
|
||||
|
||||
var lastChar = rune('\u0000')
|
||||
|
||||
func (c Char) isValid() bool {
|
||||
return c.codePoint != 0 && c.state != SMissing
|
||||
}
|
||||
|
||||
type FormInfo struct {
|
||||
quickCheck [MNumberOfModes]QCResult // index: MComposed or MDecomposed
|
||||
verified [MNumberOfModes]bool // index: MComposed or MDecomposed
|
||||
|
||||
combinesForward bool // May combine with rune on the right
|
||||
combinesBackward bool // May combine with rune on the left
|
||||
isOneWay bool // Never appears in result
|
||||
inDecomp bool // Some decompositions result in this char.
|
||||
decomp Decomposition
|
||||
expandedDecomp Decomposition
|
||||
}
|
||||
|
||||
func (f FormInfo) String() string {
|
||||
buf := bytes.NewBuffer(make([]byte, 0))
|
||||
|
||||
fmt.Fprintf(buf, " quickCheck[C]: %v\n", f.quickCheck[MComposed])
|
||||
fmt.Fprintf(buf, " quickCheck[D]: %v\n", f.quickCheck[MDecomposed])
|
||||
fmt.Fprintf(buf, " cmbForward: %v\n", f.combinesForward)
|
||||
fmt.Fprintf(buf, " cmbBackward: %v\n", f.combinesBackward)
|
||||
fmt.Fprintf(buf, " isOneWay: %v\n", f.isOneWay)
|
||||
fmt.Fprintf(buf, " inDecomp: %v\n", f.inDecomp)
|
||||
fmt.Fprintf(buf, " decomposition: %X\n", f.decomp)
|
||||
fmt.Fprintf(buf, " expandedDecomp: %X\n", f.expandedDecomp)
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type Decomposition []rune
|
||||
|
||||
func parseDecomposition(s string, skipfirst bool) (a []rune, err error) {
|
||||
decomp := strings.Split(s, " ")
|
||||
if len(decomp) > 0 && skipfirst {
|
||||
decomp = decomp[1:]
|
||||
}
|
||||
for _, d := range decomp {
|
||||
point, err := strconv.ParseUint(d, 16, 64)
|
||||
if err != nil {
|
||||
return a, err
|
||||
}
|
||||
a = append(a, rune(point))
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func loadUnicodeData() {
|
||||
f := gen.OpenUCDFile("UnicodeData.txt")
|
||||
defer f.Close()
|
||||
p := ucd.New(f)
|
||||
for p.Next() {
|
||||
r := p.Rune(ucd.CodePoint)
|
||||
char := &chars[r]
|
||||
|
||||
char.ccc = uint8(p.Uint(ucd.CanonicalCombiningClass))
|
||||
decmap := p.String(ucd.DecompMapping)
|
||||
|
||||
exp, err := parseDecomposition(decmap, false)
|
||||
isCompat := false
|
||||
if err != nil {
|
||||
if len(decmap) > 0 {
|
||||
exp, err = parseDecomposition(decmap, true)
|
||||
if err != nil {
|
||||
log.Fatalf(`%U: bad decomp |%v|: "%s"`, r, decmap, err)
|
||||
}
|
||||
isCompat = true
|
||||
}
|
||||
}
|
||||
|
||||
char.name = p.String(ucd.Name)
|
||||
char.codePoint = r
|
||||
char.forms[FCompatibility].decomp = exp
|
||||
if !isCompat {
|
||||
char.forms[FCanonical].decomp = exp
|
||||
} else {
|
||||
char.compatDecomp = true
|
||||
}
|
||||
if len(decmap) > 0 {
|
||||
char.forms[FCompatibility].decomp = exp
|
||||
}
|
||||
}
|
||||
if err := p.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// compactCCC converts the sparse set of CCC values to a continguous one,
|
||||
// reducing the number of bits needed from 8 to 6.
|
||||
func compactCCC() {
|
||||
m := make(map[uint8]uint8)
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
m[c.ccc] = 0
|
||||
}
|
||||
cccs := []int{}
|
||||
for v, _ := range m {
|
||||
cccs = append(cccs, int(v))
|
||||
}
|
||||
sort.Ints(cccs)
|
||||
for i, c := range cccs {
|
||||
cccMap[uint8(i)] = uint8(c)
|
||||
m[uint8(c)] = uint8(i)
|
||||
}
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
c.origCCC = c.ccc
|
||||
c.ccc = m[c.ccc]
|
||||
}
|
||||
if len(m) >= 1<<6 {
|
||||
log.Fatalf("too many difference CCC values: %d >= 64", len(m))
|
||||
}
|
||||
}
|
||||
|
||||
// CompositionExclusions.txt has form:
|
||||
// 0958 # ...
|
||||
// See https://unicode.org/reports/tr44/ for full explanation
|
||||
func loadCompositionExclusions() {
|
||||
f := gen.OpenUCDFile("CompositionExclusions.txt")
|
||||
defer f.Close()
|
||||
p := ucd.New(f)
|
||||
for p.Next() {
|
||||
c := &chars[p.Rune(0)]
|
||||
if c.excludeInComp {
|
||||
log.Fatalf("%U: Duplicate entry in exclusions.", c.codePoint)
|
||||
}
|
||||
c.excludeInComp = true
|
||||
}
|
||||
if e := p.Err(); e != nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
}
|
||||
|
||||
// hasCompatDecomp returns true if any of the recursive
|
||||
// decompositions contains a compatibility expansion.
|
||||
// In this case, the character may not occur in NFK*.
|
||||
func hasCompatDecomp(r rune) bool {
|
||||
c := &chars[r]
|
||||
if c.compatDecomp {
|
||||
return true
|
||||
}
|
||||
for _, d := range c.forms[FCompatibility].decomp {
|
||||
if hasCompatDecomp(d) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Hangul related constants.
|
||||
const (
|
||||
HangulBase = 0xAC00
|
||||
HangulEnd = 0xD7A4 // hangulBase + Jamo combinations (19 * 21 * 28)
|
||||
|
||||
JamoLBase = 0x1100
|
||||
JamoLEnd = 0x1113
|
||||
JamoVBase = 0x1161
|
||||
JamoVEnd = 0x1176
|
||||
JamoTBase = 0x11A8
|
||||
JamoTEnd = 0x11C3
|
||||
|
||||
JamoLVTCount = 19 * 21 * 28
|
||||
JamoTCount = 28
|
||||
)
|
||||
|
||||
func isHangul(r rune) bool {
|
||||
return HangulBase <= r && r < HangulEnd
|
||||
}
|
||||
|
||||
func isHangulWithoutJamoT(r rune) bool {
|
||||
if !isHangul(r) {
|
||||
return false
|
||||
}
|
||||
r -= HangulBase
|
||||
return r < JamoLVTCount && r%JamoTCount == 0
|
||||
}
|
||||
|
||||
func ccc(r rune) uint8 {
|
||||
return chars[r].ccc
|
||||
}
|
||||
|
||||
// Insert a rune in a buffer, ordered by Canonical Combining Class.
|
||||
func insertOrdered(b Decomposition, r rune) Decomposition {
|
||||
n := len(b)
|
||||
b = append(b, 0)
|
||||
cc := ccc(r)
|
||||
if cc > 0 {
|
||||
// Use bubble sort.
|
||||
for ; n > 0; n-- {
|
||||
if ccc(b[n-1]) <= cc {
|
||||
break
|
||||
}
|
||||
b[n] = b[n-1]
|
||||
}
|
||||
}
|
||||
b[n] = r
|
||||
return b
|
||||
}
|
||||
|
||||
// Recursively decompose.
|
||||
func decomposeRecursive(form int, r rune, d Decomposition) Decomposition {
|
||||
dcomp := chars[r].forms[form].decomp
|
||||
if len(dcomp) == 0 {
|
||||
return insertOrdered(d, r)
|
||||
}
|
||||
for _, c := range dcomp {
|
||||
d = decomposeRecursive(form, c, d)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func completeCharFields(form int) {
|
||||
// Phase 0: pre-expand decomposition.
|
||||
for i := range chars {
|
||||
f := &chars[i].forms[form]
|
||||
if len(f.decomp) == 0 {
|
||||
continue
|
||||
}
|
||||
exp := make(Decomposition, 0)
|
||||
for _, c := range f.decomp {
|
||||
exp = decomposeRecursive(form, c, exp)
|
||||
}
|
||||
f.expandedDecomp = exp
|
||||
}
|
||||
|
||||
// Phase 1: composition exclusion, mark decomposition.
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
f := &c.forms[form]
|
||||
|
||||
// Marks script-specific exclusions and version restricted.
|
||||
f.isOneWay = c.excludeInComp
|
||||
|
||||
// Singletons
|
||||
f.isOneWay = f.isOneWay || len(f.decomp) == 1
|
||||
|
||||
// Non-starter decompositions
|
||||
if len(f.decomp) > 1 {
|
||||
chk := c.ccc != 0 || chars[f.decomp[0]].ccc != 0
|
||||
f.isOneWay = f.isOneWay || chk
|
||||
}
|
||||
|
||||
// Runes that decompose into more than two runes.
|
||||
f.isOneWay = f.isOneWay || len(f.decomp) > 2
|
||||
|
||||
if form == FCompatibility {
|
||||
f.isOneWay = f.isOneWay || hasCompatDecomp(c.codePoint)
|
||||
}
|
||||
|
||||
for _, r := range f.decomp {
|
||||
chars[r].forms[form].inDecomp = true
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 2: forward and backward combining.
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
f := &c.forms[form]
|
||||
|
||||
if !f.isOneWay && len(f.decomp) == 2 {
|
||||
f0 := &chars[f.decomp[0]].forms[form]
|
||||
f1 := &chars[f.decomp[1]].forms[form]
|
||||
if !f0.isOneWay {
|
||||
f0.combinesForward = true
|
||||
}
|
||||
if !f1.isOneWay {
|
||||
f1.combinesBackward = true
|
||||
}
|
||||
}
|
||||
if isHangulWithoutJamoT(rune(i)) {
|
||||
f.combinesForward = true
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 3: quick check values.
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
f := &c.forms[form]
|
||||
|
||||
switch {
|
||||
case len(f.decomp) > 0:
|
||||
f.quickCheck[MDecomposed] = QCNo
|
||||
case isHangul(rune(i)):
|
||||
f.quickCheck[MDecomposed] = QCNo
|
||||
default:
|
||||
f.quickCheck[MDecomposed] = QCYes
|
||||
}
|
||||
switch {
|
||||
case f.isOneWay:
|
||||
f.quickCheck[MComposed] = QCNo
|
||||
case (i & 0xffff00) == JamoLBase:
|
||||
f.quickCheck[MComposed] = QCYes
|
||||
if JamoLBase <= i && i < JamoLEnd {
|
||||
f.combinesForward = true
|
||||
}
|
||||
if JamoVBase <= i && i < JamoVEnd {
|
||||
f.quickCheck[MComposed] = QCMaybe
|
||||
f.combinesBackward = true
|
||||
f.combinesForward = true
|
||||
}
|
||||
if JamoTBase <= i && i < JamoTEnd {
|
||||
f.quickCheck[MComposed] = QCMaybe
|
||||
f.combinesBackward = true
|
||||
}
|
||||
case !f.combinesBackward:
|
||||
f.quickCheck[MComposed] = QCYes
|
||||
default:
|
||||
f.quickCheck[MComposed] = QCMaybe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func computeNonStarterCounts() {
|
||||
// Phase 4: leading and trailing non-starter count
|
||||
for i := range chars {
|
||||
c := &chars[i]
|
||||
|
||||
runes := []rune{rune(i)}
|
||||
// We always use FCompatibility so that the CGJ insertion points do not
|
||||
// change for repeated normalizations with different forms.
|
||||
if exp := c.forms[FCompatibility].expandedDecomp; len(exp) > 0 {
|
||||
runes = exp
|
||||
}
|
||||
// We consider runes that combine backwards to be non-starters for the
|
||||
// purpose of Stream-Safe Text Processing.
|
||||
for _, r := range runes {
|
||||
if cr := &chars[r]; cr.ccc == 0 && !cr.forms[FCompatibility].combinesBackward {
|
||||
break
|
||||
}
|
||||
c.nLeadingNonStarters++
|
||||
}
|
||||
for i := len(runes) - 1; i >= 0; i-- {
|
||||
if cr := &chars[runes[i]]; cr.ccc == 0 && !cr.forms[FCompatibility].combinesBackward {
|
||||
break
|
||||
}
|
||||
c.nTrailingNonStarters++
|
||||
}
|
||||
if c.nTrailingNonStarters > 3 {
|
||||
log.Fatalf("%U: Decomposition with more than 3 (%d) trailing modifiers (%U)", i, c.nTrailingNonStarters, runes)
|
||||
}
|
||||
|
||||
if isHangul(rune(i)) {
|
||||
c.nTrailingNonStarters = 2
|
||||
if isHangulWithoutJamoT(rune(i)) {
|
||||
c.nTrailingNonStarters = 1
|
||||
}
|
||||
}
|
||||
|
||||
if l, t := c.nLeadingNonStarters, c.nTrailingNonStarters; l > 0 && l != t {
|
||||
log.Fatalf("%U: number of leading and trailing non-starters should be equal (%d vs %d)", i, l, t)
|
||||
}
|
||||
if t := c.nTrailingNonStarters; t > 3 {
|
||||
log.Fatalf("%U: number of trailing non-starters is %d > 3", t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printBytes(w io.Writer, b []byte, name string) {
|
||||
fmt.Fprintf(w, "// %s: %d bytes\n", name, len(b))
|
||||
fmt.Fprintf(w, "var %s = [...]byte {", name)
|
||||
for i, c := range b {
|
||||
switch {
|
||||
case i%64 == 0:
|
||||
fmt.Fprintf(w, "\n// Bytes %x - %x\n", i, i+63)
|
||||
case i%8 == 0:
|
||||
fmt.Fprintf(w, "\n")
|
||||
}
|
||||
fmt.Fprintf(w, "0x%.2X, ", c)
|
||||
}
|
||||
fmt.Fprint(w, "\n}\n\n")
|
||||
}
|
||||
|
||||
// See forminfo.go for format.
|
||||
func makeEntry(f *FormInfo, c *Char) uint16 {
|
||||
e := uint16(0)
|
||||
if r := c.codePoint; HangulBase <= r && r < HangulEnd {
|
||||
e |= 0x40
|
||||
}
|
||||
if f.combinesForward {
|
||||
e |= 0x20
|
||||
}
|
||||
if f.quickCheck[MDecomposed] == QCNo {
|
||||
e |= 0x4
|
||||
}
|
||||
switch f.quickCheck[MComposed] {
|
||||
case QCYes:
|
||||
case QCNo:
|
||||
e |= 0x10
|
||||
case QCMaybe:
|
||||
e |= 0x18
|
||||
default:
|
||||
log.Fatalf("Illegal quickcheck value %v.", f.quickCheck[MComposed])
|
||||
}
|
||||
e |= uint16(c.nTrailingNonStarters)
|
||||
return e
|
||||
}
|
||||
|
||||
// decompSet keeps track of unique decompositions, grouped by whether
|
||||
// the decomposition is followed by a trailing and/or leading CCC.
|
||||
type decompSet [7]map[string]bool
|
||||
|
||||
const (
|
||||
normalDecomp = iota
|
||||
firstMulti
|
||||
firstCCC
|
||||
endMulti
|
||||
firstLeadingCCC
|
||||
firstCCCZeroExcept
|
||||
firstStarterWithNLead
|
||||
lastDecomp
|
||||
)
|
||||
|
||||
var cname = []string{"firstMulti", "firstCCC", "endMulti", "firstLeadingCCC", "firstCCCZeroExcept", "firstStarterWithNLead", "lastDecomp"}
|
||||
|
||||
func makeDecompSet() decompSet {
|
||||
m := decompSet{}
|
||||
for i := range m {
|
||||
m[i] = make(map[string]bool)
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *decompSet) insert(key int, s string) {
|
||||
m[key][s] = true
|
||||
}
|
||||
|
||||
func printCharInfoTables(w io.Writer) int {
|
||||
mkstr := func(r rune, f *FormInfo) (int, string) {
|
||||
d := f.expandedDecomp
|
||||
s := string([]rune(d))
|
||||
if max := 1 << 6; len(s) >= max {
|
||||
const msg = "%U: too many bytes in decomposition: %d >= %d"
|
||||
log.Fatalf(msg, r, len(s), max)
|
||||
}
|
||||
head := uint8(len(s))
|
||||
if f.quickCheck[MComposed] != QCYes {
|
||||
head |= 0x40
|
||||
}
|
||||
if f.combinesForward {
|
||||
head |= 0x80
|
||||
}
|
||||
s = string([]byte{head}) + s
|
||||
|
||||
lccc := ccc(d[0])
|
||||
tccc := ccc(d[len(d)-1])
|
||||
cc := ccc(r)
|
||||
if cc != 0 && lccc == 0 && tccc == 0 {
|
||||
log.Fatalf("%U: trailing and leading ccc are 0 for non-zero ccc %d", r, cc)
|
||||
}
|
||||
if tccc < lccc && lccc != 0 {
|
||||
const msg = "%U: lccc (%d) must be <= tcc (%d)"
|
||||
log.Fatalf(msg, r, lccc, tccc)
|
||||
}
|
||||
index := normalDecomp
|
||||
nTrail := chars[r].nTrailingNonStarters
|
||||
nLead := chars[r].nLeadingNonStarters
|
||||
if tccc > 0 || lccc > 0 || nTrail > 0 {
|
||||
tccc <<= 2
|
||||
tccc |= nTrail
|
||||
s += string([]byte{tccc})
|
||||
index = endMulti
|
||||
for _, r := range d[1:] {
|
||||
if ccc(r) == 0 {
|
||||
index = firstCCC
|
||||
}
|
||||
}
|
||||
if lccc > 0 || nLead > 0 {
|
||||
s += string([]byte{lccc})
|
||||
if index == firstCCC {
|
||||
log.Fatalf("%U: multi-segment decomposition not supported for decompositions with leading CCC != 0", r)
|
||||
}
|
||||
index = firstLeadingCCC
|
||||
}
|
||||
if cc != lccc {
|
||||
if cc != 0 {
|
||||
log.Fatalf("%U: for lccc != ccc, expected ccc to be 0; was %d", r, cc)
|
||||
}
|
||||
index = firstCCCZeroExcept
|
||||
}
|
||||
} else if len(d) > 1 {
|
||||
index = firstMulti
|
||||
}
|
||||
return index, s
|
||||
}
|
||||
|
||||
decompSet := makeDecompSet()
|
||||
const nLeadStr = "\x00\x01" // 0-byte length and tccc with nTrail.
|
||||
decompSet.insert(firstStarterWithNLead, nLeadStr)
|
||||
|
||||
// Store the uniqued decompositions in a byte buffer,
|
||||
// preceded by their byte length.
|
||||
for _, c := range chars {
|
||||
for _, f := range c.forms {
|
||||
if len(f.expandedDecomp) == 0 {
|
||||
continue
|
||||
}
|
||||
if f.combinesBackward {
|
||||
log.Fatalf("%U: combinesBackward and decompose", c.codePoint)
|
||||
}
|
||||
index, s := mkstr(c.codePoint, &f)
|
||||
decompSet.insert(index, s)
|
||||
}
|
||||
}
|
||||
|
||||
decompositions := bytes.NewBuffer(make([]byte, 0, 10000))
|
||||
size := 0
|
||||
positionMap := make(map[string]uint16)
|
||||
decompositions.WriteString("\000")
|
||||
fmt.Fprintln(w, "const (")
|
||||
for i, m := range decompSet {
|
||||
sa := []string{}
|
||||
for s := range m {
|
||||
sa = append(sa, s)
|
||||
}
|
||||
sort.Strings(sa)
|
||||
for _, s := range sa {
|
||||
p := decompositions.Len()
|
||||
decompositions.WriteString(s)
|
||||
positionMap[s] = uint16(p)
|
||||
}
|
||||
if cname[i] != "" {
|
||||
fmt.Fprintf(w, "%s = 0x%X\n", cname[i], decompositions.Len())
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "maxDecomp = 0x8000")
|
||||
fmt.Fprintln(w, ")")
|
||||
b := decompositions.Bytes()
|
||||
printBytes(w, b, "decomps")
|
||||
size += len(b)
|
||||
|
||||
varnames := []string{"nfc", "nfkc"}
|
||||
for i := 0; i < FNumberOfFormTypes; i++ {
|
||||
trie := triegen.NewTrie(varnames[i])
|
||||
|
||||
for r, c := range chars {
|
||||
f := c.forms[i]
|
||||
d := f.expandedDecomp
|
||||
if len(d) != 0 {
|
||||
_, key := mkstr(c.codePoint, &f)
|
||||
trie.Insert(rune(r), uint64(positionMap[key]))
|
||||
if c.ccc != ccc(d[0]) {
|
||||
// We assume the lead ccc of a decomposition !=0 in this case.
|
||||
if ccc(d[0]) == 0 {
|
||||
log.Fatalf("Expected leading CCC to be non-zero; ccc is %d", c.ccc)
|
||||
}
|
||||
}
|
||||
} else if c.nLeadingNonStarters > 0 && len(f.expandedDecomp) == 0 && c.ccc == 0 && !f.combinesBackward {
|
||||
// Handle cases where it can't be detected that the nLead should be equal
|
||||
// to nTrail.
|
||||
trie.Insert(c.codePoint, uint64(positionMap[nLeadStr]))
|
||||
} else if v := makeEntry(&f, &c)<<8 | uint16(c.ccc); v != 0 {
|
||||
trie.Insert(c.codePoint, uint64(0x8000|v))
|
||||
}
|
||||
}
|
||||
sz, err := trie.Gen(w, triegen.Compact(&normCompacter{name: varnames[i]}))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
size += sz
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
func contains(sa []string, s string) bool {
|
||||
for _, a := range sa {
|
||||
if a == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func makeTables() {
|
||||
w := &bytes.Buffer{}
|
||||
|
||||
size := 0
|
||||
if *tablelist == "" {
|
||||
return
|
||||
}
|
||||
list := strings.Split(*tablelist, ",")
|
||||
if *tablelist == "all" {
|
||||
list = []string{"recomp", "info"}
|
||||
}
|
||||
|
||||
// Compute maximum decomposition size.
|
||||
max := 0
|
||||
for _, c := range chars {
|
||||
if n := len(string(c.forms[FCompatibility].expandedDecomp)); n > max {
|
||||
max = n
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, `import "sync"`)
|
||||
fmt.Fprintln(w)
|
||||
|
||||
fmt.Fprintln(w, "const (")
|
||||
fmt.Fprintln(w, "\t// Version is the Unicode edition from which the tables are derived.")
|
||||
fmt.Fprintf(w, "\tVersion = %q\n", gen.UnicodeVersion())
|
||||
fmt.Fprintln(w)
|
||||
fmt.Fprintln(w, "\t// MaxTransformChunkSize indicates the maximum number of bytes that Transform")
|
||||
fmt.Fprintln(w, "\t// may need to write atomically for any Form. Making a destination buffer at")
|
||||
fmt.Fprintln(w, "\t// least this size ensures that Transform can always make progress and that")
|
||||
fmt.Fprintln(w, "\t// the user does not need to grow the buffer on an ErrShortDst.")
|
||||
fmt.Fprintf(w, "\tMaxTransformChunkSize = %d+maxNonStarters*4\n", len(string(0x034F))+max)
|
||||
fmt.Fprintln(w, ")\n")
|
||||
|
||||
// Print the CCC remap table.
|
||||
size += len(cccMap)
|
||||
fmt.Fprintf(w, "var ccc = [%d]uint8{", len(cccMap))
|
||||
for i := 0; i < len(cccMap); i++ {
|
||||
if i%8 == 0 {
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
fmt.Fprintf(w, "%3d, ", cccMap[uint8(i)])
|
||||
}
|
||||
fmt.Fprintln(w, "\n}\n")
|
||||
|
||||
if contains(list, "info") {
|
||||
size += printCharInfoTables(w)
|
||||
}
|
||||
|
||||
if contains(list, "recomp") {
|
||||
// Note that we use 32 bit keys, instead of 64 bit.
|
||||
// This clips the bits of three entries, but we know
|
||||
// this won't cause a collision. The compiler will catch
|
||||
// any changes made to UnicodeData.txt that introduces
|
||||
// a collision.
|
||||
// Note that the recomposition map for NFC and NFKC
|
||||
// are identical.
|
||||
|
||||
// Recomposition map
|
||||
nrentries := 0
|
||||
for _, c := range chars {
|
||||
f := c.forms[FCanonical]
|
||||
if !f.isOneWay && len(f.decomp) > 0 {
|
||||
nrentries++
|
||||
}
|
||||
}
|
||||
sz := nrentries * 8
|
||||
size += sz
|
||||
fmt.Fprintf(w, "// recompMap: %d bytes (entries only)\n", sz)
|
||||
fmt.Fprintln(w, "var recompMap map[uint32]rune")
|
||||
fmt.Fprintln(w, "var recompMapOnce sync.Once\n")
|
||||
fmt.Fprintln(w, `const recompMapPacked = "" +`)
|
||||
var buf [8]byte
|
||||
for i, c := range chars {
|
||||
f := c.forms[FCanonical]
|
||||
d := f.decomp
|
||||
if !f.isOneWay && len(d) > 0 {
|
||||
key := uint32(uint16(d[0]))<<16 + uint32(uint16(d[1]))
|
||||
binary.BigEndian.PutUint32(buf[:4], key)
|
||||
binary.BigEndian.PutUint32(buf[4:], uint32(i))
|
||||
fmt.Fprintf(w, "\t\t%q + // 0x%.8X: 0x%.8X\n", string(buf[:]), key, uint32(i))
|
||||
}
|
||||
}
|
||||
// hack so we don't have to special case the trailing plus sign
|
||||
fmt.Fprintf(w, ` ""`)
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "// Total size of tables: %dKB (%d bytes)\n", (size+512)/1024, size)
|
||||
gen.WriteVersionedGoFile("tables.go", "norm", w.Bytes())
|
||||
}
|
||||
|
||||
func printChars() {
|
||||
if *verbose {
|
||||
for _, c := range chars {
|
||||
if !c.isValid() || c.state == SMissing {
|
||||
continue
|
||||
}
|
||||
fmt.Println(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// verifyComputed does various consistency tests.
|
||||
func verifyComputed() {
|
||||
for i, c := range chars {
|
||||
for _, f := range c.forms {
|
||||
isNo := (f.quickCheck[MDecomposed] == QCNo)
|
||||
if (len(f.decomp) > 0) != isNo && !isHangul(rune(i)) {
|
||||
log.Fatalf("%U: NF*D QC must be No if rune decomposes", i)
|
||||
}
|
||||
|
||||
isMaybe := f.quickCheck[MComposed] == QCMaybe
|
||||
if f.combinesBackward != isMaybe {
|
||||
log.Fatalf("%U: NF*C QC must be Maybe if combinesBackward", i)
|
||||
}
|
||||
if len(f.decomp) > 0 && f.combinesForward && isMaybe {
|
||||
log.Fatalf("%U: NF*C QC must be Yes or No if combinesForward and decomposes", i)
|
||||
}
|
||||
|
||||
if len(f.expandedDecomp) != 0 {
|
||||
continue
|
||||
}
|
||||
if a, b := c.nLeadingNonStarters > 0, (c.ccc > 0 || f.combinesBackward); a != b {
|
||||
// We accept these runes to be treated differently (it only affects
|
||||
// segment breaking in iteration, most likely on improper use), but
|
||||
// reconsider if more characters are added.
|
||||
// U+FF9E HALFWIDTH KATAKANA VOICED SOUND MARK;Lm;0;L;<narrow> 3099;;;;N;;;;;
|
||||
// U+FF9F HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK;Lm;0;L;<narrow> 309A;;;;N;;;;;
|
||||
// U+3133 HANGUL LETTER KIYEOK-SIOS;Lo;0;L;<compat> 11AA;;;;N;HANGUL LETTER GIYEOG SIOS;;;;
|
||||
// U+318E HANGUL LETTER ARAEAE;Lo;0;L;<compat> 11A1;;;;N;HANGUL LETTER ALAE AE;;;;
|
||||
// U+FFA3 HALFWIDTH HANGUL LETTER KIYEOK-SIOS;Lo;0;L;<narrow> 3133;;;;N;HALFWIDTH HANGUL LETTER GIYEOG SIOS;;;;
|
||||
// U+FFDC HALFWIDTH HANGUL LETTER I;Lo;0;L;<narrow> 3163;;;;N;;;;;
|
||||
if i != 0xFF9E && i != 0xFF9F && !(0x3133 <= i && i <= 0x318E) && !(0xFFA3 <= i && i <= 0xFFDC) {
|
||||
log.Fatalf("%U: nLead was %v; want %v", i, a, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
nfc := c.forms[FCanonical]
|
||||
nfkc := c.forms[FCompatibility]
|
||||
if nfc.combinesBackward != nfkc.combinesBackward {
|
||||
log.Fatalf("%U: Cannot combine combinesBackward\n", c.codePoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use values in DerivedNormalizationProps.txt to compare against the
|
||||
// values we computed.
|
||||
// DerivedNormalizationProps.txt has form:
|
||||
// 00C0..00C5 ; NFD_QC; N # ...
|
||||
// 0374 ; NFD_QC; N # ...
|
||||
// See https://unicode.org/reports/tr44/ for full explanation
|
||||
func testDerived() {
|
||||
f := gen.OpenUCDFile("DerivedNormalizationProps.txt")
|
||||
defer f.Close()
|
||||
p := ucd.New(f)
|
||||
for p.Next() {
|
||||
r := p.Rune(0)
|
||||
c := &chars[r]
|
||||
|
||||
var ftype, mode int
|
||||
qt := p.String(1)
|
||||
switch qt {
|
||||
case "NFC_QC":
|
||||
ftype, mode = FCanonical, MComposed
|
||||
case "NFD_QC":
|
||||
ftype, mode = FCanonical, MDecomposed
|
||||
case "NFKC_QC":
|
||||
ftype, mode = FCompatibility, MComposed
|
||||
case "NFKD_QC":
|
||||
ftype, mode = FCompatibility, MDecomposed
|
||||
default:
|
||||
continue
|
||||
}
|
||||
var qr QCResult
|
||||
switch p.String(2) {
|
||||
case "Y":
|
||||
qr = QCYes
|
||||
case "N":
|
||||
qr = QCNo
|
||||
case "M":
|
||||
qr = QCMaybe
|
||||
default:
|
||||
log.Fatalf(`Unexpected quick check value "%s"`, p.String(2))
|
||||
}
|
||||
if got := c.forms[ftype].quickCheck[mode]; got != qr {
|
||||
log.Printf("%U: FAILED %s (was %v need %v)\n", r, qt, got, qr)
|
||||
}
|
||||
c.forms[ftype].verified[mode] = true
|
||||
}
|
||||
if err := p.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// Any unspecified value must be QCYes. Verify this.
|
||||
for i, c := range chars {
|
||||
for j, fd := range c.forms {
|
||||
for k, qr := range fd.quickCheck {
|
||||
if !fd.verified[k] && qr != QCYes {
|
||||
m := "%U: FAIL F:%d M:%d (was %v need Yes) %s\n"
|
||||
log.Printf(m, i, j, k, qr, c.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testHeader = `const (
|
||||
Yes = iota
|
||||
No
|
||||
Maybe
|
||||
)
|
||||
|
||||
type formData struct {
|
||||
qc uint8
|
||||
combinesForward bool
|
||||
decomposition string
|
||||
}
|
||||
|
||||
type runeData struct {
|
||||
r rune
|
||||
ccc uint8
|
||||
nLead uint8
|
||||
nTrail uint8
|
||||
f [2]formData // 0: canonical; 1: compatibility
|
||||
}
|
||||
|
||||
func f(qc uint8, cf bool, dec string) [2]formData {
|
||||
return [2]formData{{qc, cf, dec}, {qc, cf, dec}}
|
||||
}
|
||||
|
||||
func g(qc, qck uint8, cf, cfk bool, d, dk string) [2]formData {
|
||||
return [2]formData{{qc, cf, d}, {qck, cfk, dk}}
|
||||
}
|
||||
|
||||
var testData = []runeData{
|
||||
`
|
||||
|
||||
func printTestdata() {
|
||||
type lastInfo struct {
|
||||
ccc uint8
|
||||
nLead uint8
|
||||
nTrail uint8
|
||||
f string
|
||||
}
|
||||
|
||||
last := lastInfo{}
|
||||
w := &bytes.Buffer{}
|
||||
fmt.Fprintf(w, testHeader)
|
||||
for r, c := range chars {
|
||||
f := c.forms[FCanonical]
|
||||
qc, cf, d := f.quickCheck[MComposed], f.combinesForward, string(f.expandedDecomp)
|
||||
f = c.forms[FCompatibility]
|
||||
qck, cfk, dk := f.quickCheck[MComposed], f.combinesForward, string(f.expandedDecomp)
|
||||
s := ""
|
||||
if d == dk && qc == qck && cf == cfk {
|
||||
s = fmt.Sprintf("f(%s, %v, %q)", qc, cf, d)
|
||||
} else {
|
||||
s = fmt.Sprintf("g(%s, %s, %v, %v, %q, %q)", qc, qck, cf, cfk, d, dk)
|
||||
}
|
||||
current := lastInfo{c.ccc, c.nLeadingNonStarters, c.nTrailingNonStarters, s}
|
||||
if last != current {
|
||||
fmt.Fprintf(w, "\t{0x%x, %d, %d, %d, %s},\n", r, c.origCCC, c.nLeadingNonStarters, c.nTrailingNonStarters, s)
|
||||
last = current
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "}")
|
||||
gen.WriteVersionedGoFile("data_test.go", "norm", w.Bytes())
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue