|
64 | 64 | writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.")
|
65 | 65 | writeGenerateDirective = flag.Bool("write_generate_directive", false, "Add //go:generate directive to regenerate the mock")
|
66 | 66 | copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header")
|
| 67 | + buildConstraint = flag.String("build_constraint", "", "If non-empty, added as //go:build <constraint>") |
67 | 68 | typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function")
|
68 | 69 | imports = flag.String("imports", "", "(source mode) Comma-separated name=path pairs of explicit imports to use.")
|
69 | 70 | auxFiles = flag.String("aux_files", "", "(source mode) Comma-separated pkg=path pairs of auxiliary Go source files.")
|
@@ -143,7 +144,9 @@ func main() {
|
143 | 144 | }
|
144 | 145 | }
|
145 | 146 |
|
146 |
| - g := new(generator) |
| 147 | + g := &generator{ |
| 148 | + buildConstraint: *buildConstraint, |
| 149 | + } |
147 | 150 | if *source != "" {
|
148 | 151 | g.filename = *source
|
149 | 152 | } else {
|
@@ -251,6 +254,7 @@ type generator struct {
|
251 | 254 | destination string // may be empty
|
252 | 255 | srcPackage, srcInterfaces string // may be empty
|
253 | 256 | copyrightHeader string
|
| 257 | + buildConstraint string // may be empty |
254 | 258 |
|
255 | 259 | packageMap map[string]string // map from import path to package name
|
256 | 260 | }
|
@@ -306,6 +310,12 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
|
306 | 310 | g.p("")
|
307 | 311 | }
|
308 | 312 |
|
| 313 | + if g.buildConstraint != "" { |
| 314 | + g.p("//go:build %s", g.buildConstraint) |
| 315 | + // https://pkg.go.dev/cmd/go#hdr-Build_constraints:~:text=a%20build%20constraint%20should%20be%20followed%20by%20a%20blank%20line |
| 316 | + g.p("") |
| 317 | + } |
| 318 | + |
309 | 319 | g.p("// Code generated by MockGen. DO NOT EDIT.")
|
310 | 320 | if *writeSourceComment {
|
311 | 321 | if g.filename != "" {
|
|
0 commit comments