@@ -29,7 +29,7 @@ import (
29
29
"k8s.io/gengo/namer"
30
30
"k8s.io/gengo/types"
31
31
32
- "github.com/golang/glog "
32
+ "k8s.io/klog "
33
33
34
34
conversionargs "k8s.io/code-generator/cmd/conversion-gen/args"
35
35
)
@@ -124,10 +124,10 @@ type conversionFuncMap map[conversionPair]*types.Type
124
124
// Returns all manually-defined conversion functions in the package.
125
125
func getManualConversionFunctions (context * generator.Context , pkg * types.Package , manualMap conversionFuncMap ) {
126
126
if pkg == nil {
127
- glog .Warningf ("Skipping nil package passed to getManualConversionFunctions" )
127
+ klog .Warningf ("Skipping nil package passed to getManualConversionFunctions" )
128
128
return
129
129
}
130
- glog .V (5 ).Infof ("Scanning for conversion functions in %v" , pkg .Name )
130
+ klog .V (5 ).Infof ("Scanning for conversion functions in %v" , pkg .Name )
131
131
132
132
scopeName := types .Ref (conversionPackagePath , "Scope" ).Name
133
133
errorName := types .Ref ("" , "error" ).Name
@@ -136,42 +136,42 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
136
136
137
137
for _ , f := range pkg .Functions {
138
138
if f .Underlying == nil || f .Underlying .Kind != types .Func {
139
- glog .Errorf ("Malformed function: %#v" , f )
139
+ klog .Errorf ("Malformed function: %#v" , f )
140
140
continue
141
141
}
142
142
if f .Underlying .Signature == nil {
143
- glog .Errorf ("Function without signature: %#v" , f )
143
+ klog .Errorf ("Function without signature: %#v" , f )
144
144
continue
145
145
}
146
- glog .V (8 ).Infof ("Considering function %s" , f .Name )
146
+ klog .V (8 ).Infof ("Considering function %s" , f .Name )
147
147
signature := f .Underlying .Signature
148
148
// Check whether the function is conversion function.
149
149
// Note that all of them have signature:
150
150
// func Convert_inType_To_outType(inType, outType, conversion.Scope) error
151
151
if signature .Receiver != nil {
152
- glog .V (8 ).Infof ("%s has a receiver" , f .Name )
152
+ klog .V (8 ).Infof ("%s has a receiver" , f .Name )
153
153
continue
154
154
}
155
155
if len (signature .Parameters ) != 3 || signature .Parameters [2 ].Name != scopeName {
156
- glog .V (8 ).Infof ("%s has wrong parameters" , f .Name )
156
+ klog .V (8 ).Infof ("%s has wrong parameters" , f .Name )
157
157
continue
158
158
}
159
159
if len (signature .Results ) != 1 || signature .Results [0 ].Name != errorName {
160
- glog .V (8 ).Infof ("%s has wrong results" , f .Name )
160
+ klog .V (8 ).Infof ("%s has wrong results" , f .Name )
161
161
continue
162
162
}
163
163
inType := signature .Parameters [0 ]
164
164
outType := signature .Parameters [1 ]
165
165
if inType .Kind != types .Pointer || outType .Kind != types .Pointer {
166
- glog .V (8 ).Infof ("%s has wrong parameter types" , f .Name )
166
+ klog .V (8 ).Infof ("%s has wrong parameter types" , f .Name )
167
167
continue
168
168
}
169
169
// Now check if the name satisfies the convention.
170
170
// TODO: This should call the Namer directly.
171
171
args := argsFromType (inType .Elem , outType .Elem )
172
172
sw .Do ("Convert_$.inType|public$_To_$.outType|public$" , args )
173
173
if f .Name .Name == buffer .String () {
174
- glog .V (4 ).Infof ("Found conversion function %s" , f .Name )
174
+ klog .V (4 ).Infof ("Found conversion function %s" , f .Name )
175
175
key := conversionPair {inType .Elem , outType .Elem }
176
176
// We might scan the same package twice, and that's OK.
177
177
if v , ok := manualMap [key ]; ok && v != nil && v .Name .Package != pkg .Path {
@@ -181,9 +181,9 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
181
181
} else {
182
182
// prevent user error when they don't get the correct conversion signature
183
183
if strings .HasPrefix (f .Name .Name , "Convert_" ) {
184
- glog .Errorf ("Rename function %s %s -> %s to match expected conversion signature" , f .Name .Package , f .Name .Name , buffer .String ())
184
+ klog .Errorf ("Rename function %s %s -> %s to match expected conversion signature" , f .Name .Package , f .Name .Name , buffer .String ())
185
185
}
186
- glog .V (8 ).Infof ("%s has wrong name" , f .Name )
186
+ klog .V (8 ).Infof ("%s has wrong name" , f .Name )
187
187
}
188
188
buffer .Reset ()
189
189
}
@@ -192,7 +192,7 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
192
192
func Packages (context * generator.Context , arguments * args.GeneratorArgs ) generator.Packages {
193
193
boilerplate , err := arguments .LoadGoBoilerplate ()
194
194
if err != nil {
195
- glog .Fatalf ("Failed loading boilerplate: %v" , err )
195
+ klog .Fatalf ("Failed loading boilerplate: %v" , err )
196
196
}
197
197
198
198
packages := generator.Packages {}
@@ -220,7 +220,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
220
220
}
221
221
processed [i ] = true
222
222
223
- glog .V (5 ).Infof ("considering pkg %q" , i )
223
+ klog .V (5 ).Infof ("considering pkg %q" , i )
224
224
pkg := context .Universe [i ]
225
225
// typesPkg is where the versioned types are defined. Sometimes it is
226
226
// different from pkg. For example, kubernetes core/v1 types are defined
@@ -239,9 +239,9 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
239
239
// in their doc.go file.
240
240
peerPkgs := extractTag (pkg .Comments )
241
241
if peerPkgs != nil {
242
- glog .V (5 ).Infof (" tags: %q" , peerPkgs )
242
+ klog .V (5 ).Infof (" tags: %q" , peerPkgs )
243
243
} else {
244
- glog .V (5 ).Infof (" no tag" )
244
+ klog .V (5 ).Infof (" no tag" )
245
245
continue
246
246
}
247
247
skipUnsafe := false
@@ -255,14 +255,14 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
255
255
externalTypesValues := extractExternalTypesTag (pkg .Comments )
256
256
if externalTypesValues != nil {
257
257
if len (externalTypesValues ) != 1 {
258
- glog .Fatalf (" expect only one value for %q tag, got: %q" , externalTypesTagName , externalTypesValues )
258
+ klog .Fatalf (" expect only one value for %q tag, got: %q" , externalTypesTagName , externalTypesValues )
259
259
}
260
260
externalTypes := externalTypesValues [0 ]
261
- glog .V (5 ).Infof (" external types tags: %q" , externalTypes )
261
+ klog .V (5 ).Infof (" external types tags: %q" , externalTypes )
262
262
var err error
263
263
typesPkg , err = context .AddDirectory (externalTypes )
264
264
if err != nil {
265
- glog .Fatalf ("cannot import package %s" , externalTypes )
265
+ klog .Fatalf ("cannot import package %s" , externalTypes )
266
266
}
267
267
// update context.Order to the latest context.Universe
268
268
orderer := namer.Orderer {Namer : namer .NewPublicNamer (1 )}
@@ -291,7 +291,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
291
291
context .AddDir (pp )
292
292
p := context .Universe [pp ]
293
293
if nil == p {
294
- glog .Fatalf ("failed to find pkg: %s" , pp )
294
+ klog .Fatalf ("failed to find pkg: %s" , pp )
295
295
}
296
296
getManualConversionFunctions (context , p , manualConversions )
297
297
}
@@ -335,7 +335,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
335
335
// from being a candidate for unsafe conversion
336
336
for k , v := range manualConversions {
337
337
if isCopyOnly (v .CommentLines ) {
338
- glog .V (5 ).Infof ("Conversion function %s will not block memory copy because it is copy-only" , v .Name )
338
+ klog .V (5 ).Infof ("Conversion function %s will not block memory copy because it is copy-only" , v .Name )
339
339
continue
340
340
}
341
341
// this type should be excluded from all equivalence, because the converter must be called.
@@ -518,9 +518,9 @@ func (g *genConversion) convertibleOnlyWithinPackage(inType, outType *types.Type
518
518
tagvals := extractTag (t .CommentLines )
519
519
if tagvals != nil {
520
520
if tagvals [0 ] != "false" {
521
- glog .Fatalf ("Type %v: unsupported %s value: %q" , t , tagName , tagvals [0 ])
521
+ klog .Fatalf ("Type %v: unsupported %s value: %q" , t , tagName , tagvals [0 ])
522
522
}
523
- glog .V (5 ).Infof ("type %v requests no conversion generation, skipping" , t )
523
+ klog .V (5 ).Infof ("type %v requests no conversion generation, skipping" , t )
524
524
return false
525
525
}
526
526
// TODO: Consider generating functions for other kinds too.
@@ -582,10 +582,10 @@ func (g *genConversion) preexists(inType, outType *types.Type) (*types.Type, boo
582
582
}
583
583
584
584
func (g * genConversion ) Init (c * generator.Context , w io.Writer ) error {
585
- if glog .V (5 ) {
585
+ if klog .V (5 ) {
586
586
if m , ok := g .useUnsafe .(equalMemoryTypes ); ok {
587
587
var result []string
588
- glog .Infof ("All objects without identical memory layout:" )
588
+ klog .Infof ("All objects without identical memory layout:" )
589
589
for k , v := range m {
590
590
if v {
591
591
continue
@@ -594,7 +594,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
594
594
}
595
595
sort .Strings (result )
596
596
for _ , s := range result {
597
- glog .Infof (s )
597
+ klog .Infof (s )
598
598
}
599
599
}
600
600
}
@@ -643,7 +643,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
643
643
}
644
644
645
645
func (g * genConversion ) GenerateType (c * generator.Context , t * types.Type , w io.Writer ) error {
646
- glog .V (5 ).Infof ("generating for type %v" , t )
646
+ klog .V (5 ).Infof ("generating for type %v" , t )
647
647
peerType := getPeerTypeFor (c , t , g .peerPackages )
648
648
sw := generator .NewSnippetWriter (w , c , "$" , "$" )
649
649
g .generateConversion (t , peerType , sw )
@@ -664,10 +664,10 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
664
664
// There is a public manual Conversion method: use it.
665
665
} else if skipped := g .skippedFields [inType ]; len (skipped ) != 0 {
666
666
// The inType had some fields we could not generate.
667
- glog .Errorf ("Warning: could not find nor generate a final Conversion function for %v -> %v" , inType , outType )
668
- glog .Errorf (" the following fields need manual conversion:" )
667
+ klog .Errorf ("Warning: could not find nor generate a final Conversion function for %v -> %v" , inType , outType )
668
+ klog .Errorf (" the following fields need manual conversion:" )
669
669
for _ , f := range skipped {
670
- glog .Errorf (" - %v" , f )
670
+ klog .Errorf (" - %v" , f )
671
671
}
672
672
} else {
673
673
// Emit a public conversion function.
@@ -682,7 +682,7 @@ func (g *genConversion) generateConversion(inType, outType *types.Type, sw *gene
682
682
// at any nesting level. This makes the autogenerator easy to understand, and
683
683
// the compiler shouldn't care.
684
684
func (g * genConversion ) generateFor (inType , outType * types.Type , sw * generator.SnippetWriter ) {
685
- glog .V (5 ).Infof ("generating %v -> %v" , inType , outType )
685
+ klog .V (5 ).Infof ("generating %v -> %v" , inType , outType )
686
686
var f func (* types.Type , * types.Type , * generator.SnippetWriter )
687
687
688
688
switch inType .Kind {
@@ -853,7 +853,7 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
853
853
sw .Do ("}\n " , nil )
854
854
continue
855
855
}
856
- glog .V (5 ).Infof ("Skipped function %s because it is copy-only and we can use direct assignment" , function .Name )
856
+ klog .V (5 ).Infof ("Skipped function %s because it is copy-only and we can use direct assignment" , function .Name )
857
857
}
858
858
859
859
// If we can't auto-convert, punt before we emit any code.
0 commit comments