Debian Codegraph @

protoc.go

raw symbols SCIP
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package mainscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/
18
19 import (
20 "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/"
21 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
22 "osscip-go gomod github.com/golang/go/src go1.13 os/"
23 "os/execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/"
24 "path/filepathscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/"
25 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
26 "text/templatescip-go gomod github.com/golang/go/src go1.13 `text/template`/"
27 )
28
29 var (
30 tmplscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/tmpl. = templatescip-go gomod github.com/golang/go/src go1.13 `text/template`/.Mustscip-go gomod github.com/golang/go/src go1.13 `text/template`/Must().(templatescip-go gomod github.com/golang/go/src go1.13 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.13 `text/template`/New().("protoc").Parsescip-go gomod github.com/golang/go/src go1.13 `text/template`/Template#Parse().(`protoc -I
31 {{- range $index, $include := .Includes -}}
32 {{if $index}}` + string(filepathscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/.ListSeparatorscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/ListSeparator.) + `{{end -}}
33 {{.}}
34 {{- end -}}
35 {{- if .Descriptors}} --include_imports --descriptor_set_out={{.Descriptors}}{{- end -}}
36
37 {{ if lt .Version 2 }}
38 {{- range $index, $name := .Names }} --{{- $name -}}_out={{- $.GoOutV1 }}{{- end -}}
39 {{- else -}}
40 {{- range $gen := .Generators }} --{{- $gen.Name -}}_out={{- $gen.OutputDir }}
41 {{- range $k, $v := $gen.Parameters }} --{{- $gen.Name -}}_opt={{- $k -}}={{- $v -}}{{- end -}}
42 {{- end -}}
43 {{- end -}}
44
45 {{- range .Files}} {{.}}{{end -}}
46 `))
47 )
48
49 type generatorscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/generator# struct {
50 Namescip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/generator#Name. string
51 OutputDirscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/generator#OutputDir. string
52 Parametersscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/generator#Parameters. map[string]string
53 }
54
55 // protocParams defines inputs to a protoc command string.
56 type protocCmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd# struct {
57 Generatorsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Generators. []generatorscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/generator#
58 Includesscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Includes. []string
59 Descriptorsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Descriptors. string
60 Filesscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Files. []string
61 // Version is Protobuild's version.
62 Versionscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Version. int
63
64 // V1 fields
65 Namesscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Names. []string
66 OutputDirscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#OutputDir. string
67 PackageMapscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#PackageMap. map[string]string
68 Pluginsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Plugins. []string
69 ImportPathscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#ImportPath. string
70 }
71
72 func (p *protocCmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#) mkcmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#mkcmd().() (string, error) {
73 var buf bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#
74 if err := tmplscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/tmpl..Executescip-go gomod github.com/golang/go/src go1.13 `text/template`/Template#Execute().(&buf, p); err != nil {
75 return "", err
76 }
77
78 return buf.Stringscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#String().(), nil
79 }
80
81 // GoOutV1 returns the parameter for --go_out= for protoc-gen-go < 1.4.0.
82 // Note that plugins and import_path are no longer supported by
83 // newer protoc-gen-go versions.
84 func (p *protocCmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#) GoOutV1scip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#GoOutV1().() string {
85 var result string
86 if len(p.Pluginsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Plugins.) > 0 {
87 result += "plugins=" + stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Joinscip-go gomod github.com/golang/go/src go1.13 strings/Join().(p.Pluginsscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#Plugins., "+") + ","
88 }
89 result += "import_path=" + p.ImportPathscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#ImportPath.
90
91 for proto, pkg := range p.PackageMapscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#PackageMap. {
92 result += fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().(",M%s=%s", proto, pkg)
93 }
94 result += ":" + p.OutputDirscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#OutputDir.
95
96 return result
97 }
98
99 func (p *protocCmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#) runscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#run().() error {
100 arg, err := p.mkcmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/protocCmd#mkcmd().()
101 if err != nil {
102 return err
103 }
104
105 // pass to sh -c so we don't need to re-split here.
106 args := []string{shArgscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/shArg., arg}
107 cmd := execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Command().(shCmdscip-go gomod github.com/containerd/protobuild . `github.com/containerd/protobuild`/shCmd., args...)
108 cmd.Stderrscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Stderr. = osscip-go gomod github.com/golang/go/src go1.13 os/.Stderrscip-go gomod github.com/golang/go/src go1.13 os/Stderr.
109 cmd.Stdoutscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Stdout. = osscip-go gomod github.com/golang/go/src go1.13 os/.Stdoutscip-go gomod github.com/golang/go/src go1.13 os/Stdout.
110 return cmd.Runscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Run().()
111 }