Skip to content

Commit

Permalink
Add !ignore_autogenerated build tag (#330)
Browse files Browse the repository at this point in the history
This appears to be officially supported by `gopls` and is also generated into the deepcopy files that `controller-gen` builds. Let’s use it as well.
  • Loading branch information
Porges authored Nov 19, 2020
1 parent 177a095 commit 7e55f85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
9 changes: 6 additions & 3 deletions hack/generator/pkg/astmodel/file_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ func (file *FileDefinition) AsAst() ast.Node {
})
}

header, headerLen := createComments(
var comments []string
comments = append(comments, CodeGenerationComments...)
comments = append(comments,
"Copyright (c) Microsoft Corporation.",
"Licensed under the MIT license.",
CodeGenerationComment)
"Licensed under the MIT license.")

header, headerLen := createComments(comments...)

packageName := file.packageReference.PackageName()

Expand Down
12 changes: 10 additions & 2 deletions hack/generator/pkg/astmodel/generation_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

package astmodel

var (
CodeGenerationComments []string = []string{
// Compiler-readable comment, must be first in file:
"+build !ignore_autogenerated",

// Note that this format is actually an official specification in go: https://github.com/golang/go/issues/13560
"Code generated by k8s-infra. DO NOT EDIT.", // TODO: Update this when the generated is moved/renamed
}
)

const (
// Note that this format is actually an official specification in go: https://github.com/golang/go/issues/13560
CodeGenerationComment = "Code generated by k8s-infra-gen. DO NOT EDIT." // TODO: Update this when the generated is moved/renamed
CodeGeneratedFileSuffix = "_gen.go"
)
6 changes: 4 additions & 2 deletions hack/generator/pkg/codegen/pipeline_delete_generated_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ func isFileGenerated(filename string) (bool, error) {
return false, err
}

if strings.Contains(line, astmodel.CodeGenerationComment) {
return true, nil
for _, codeGenComment := range astmodel.CodeGenerationComments {
if strings.Contains(line, codeGenComment) {
return true, nil
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// +build !ignore_autogenerated
// Code generated by k8s-infra. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Code generated by k8s-infra-gen. DO NOT EDIT.
package v20200101

import (
Expand Down

0 comments on commit 7e55f85

Please sign in to comment.