github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/cmd/bpf2go/flags.go (about) 1 package main 2 3 import ( 4 "flag" 5 "go/build/constraint" 6 ) 7 8 // buildTags is a comma-separated list of build tags. 9 // 10 // This follows the pre-Go 1.17 syntax and is kept for compatibility reasons. 11 type buildTags struct { 12 Expr constraint.Expr 13 } 14 15 var _ flag.Value = (*buildTags)(nil) 16 17 func (bt *buildTags) String() string { 18 if bt.Expr == nil { 19 return "" 20 } 21 22 return (bt.Expr).String() 23 } 24 25 func (bt *buildTags) Set(value string) error { 26 ct, err := constraint.Parse("// +build " + value) 27 if err != nil { 28 return err 29 } 30 31 bt.Expr = ct 32 return nil 33 } 34 35 func andConstraints(x, y constraint.Expr) constraint.Expr { 36 if x == nil { 37 return y 38 } 39 40 if y == nil { 41 return x 42 } 43 44 return &constraint.AndExpr{X: x, Y: y} 45 } 46 47 func orConstraints(x, y constraint.Expr) constraint.Expr { 48 if x == nil { 49 return y 50 } 51 52 if y == nil { 53 return x 54 } 55 56 return &constraint.OrExpr{X: x, Y: y} 57 }