mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-09 16:16:23 +00:00
hack/update-vendor.sh
This commit is contained in:
103
vendor/github.com/bazelbuild/buildtools/build/rule.go
generated
vendored
103
vendor/github.com/bazelbuild/buildtools/build/rule.go
generated
vendored
@@ -19,8 +19,8 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
package build
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// A Rule represents a single BUILD rule.
|
||||
@@ -29,6 +29,11 @@ type Rule struct {
|
||||
ImplicitName string // The name which should be used if the name attribute is not set. See the comment on File.implicitRuleName.
|
||||
}
|
||||
|
||||
// NewRule is a simple constructor for Rule.
|
||||
func NewRule(call *CallExpr) *Rule {
|
||||
return &Rule{call, ""}
|
||||
}
|
||||
|
||||
func (f *File) Rule(call *CallExpr) *Rule {
|
||||
r := &Rule{call, ""}
|
||||
if r.AttrString("name") == "" {
|
||||
@@ -43,15 +48,26 @@ func (f *File) Rules(kind string) []*Rule {
|
||||
var all []*Rule
|
||||
|
||||
for _, stmt := range f.Stmt {
|
||||
call, ok := stmt.(*CallExpr)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
rule := f.Rule(call)
|
||||
if kind != "" && rule.Kind() != kind {
|
||||
continue
|
||||
}
|
||||
all = append(all, rule)
|
||||
Walk(stmt, func(x Expr, stk []Expr) {
|
||||
call, ok := x.(*CallExpr)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Skip nested calls.
|
||||
for _, frame := range stk {
|
||||
if _, ok := frame.(*CallExpr); ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the rule kind is correct.
|
||||
rule := f.Rule(call)
|
||||
if kind != "" && rule.Kind() != kind {
|
||||
return
|
||||
}
|
||||
all = append(all, rule)
|
||||
})
|
||||
}
|
||||
|
||||
return all
|
||||
@@ -145,11 +161,11 @@ func (r *Rule) Kind() string {
|
||||
names = append(names, x.Name)
|
||||
expr = x.X
|
||||
}
|
||||
x, ok := expr.(*LiteralExpr)
|
||||
x, ok := expr.(*Ident)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
names = append(names, x.Token)
|
||||
names = append(names, x.Name)
|
||||
// Reverse the elements since the deepest expression contains the leading literal
|
||||
for l, r := 0, len(names)-1; l < r; l, r = l+1, r-1 {
|
||||
names[l], names[r] = names[r], names[l]
|
||||
@@ -161,18 +177,23 @@ func (r *Rule) Kind() string {
|
||||
func (r *Rule) SetKind(kind string) {
|
||||
names := strings.Split(kind, ".")
|
||||
var expr Expr
|
||||
expr = &LiteralExpr{Token: names[0]}
|
||||
expr = &Ident{Name: names[0]}
|
||||
for _, name := range names[1:] {
|
||||
expr = &DotExpr{X: expr, Name: name}
|
||||
}
|
||||
r.Call.X = expr
|
||||
}
|
||||
|
||||
// ExplicitName returns the rule's target name if it's explicitly provided as a string value, "" otherwise.
|
||||
func (r *Rule) ExplicitName() string {
|
||||
return r.AttrString("name")
|
||||
}
|
||||
|
||||
// Name returns the rule's target name.
|
||||
// If the rule has no explicit target name, Name returns the implicit name if there is one, else the empty string.
|
||||
func (r *Rule) Name() string {
|
||||
explicitName := r.AttrString("name")
|
||||
if explicitName == "" {
|
||||
explicitName := r.ExplicitName()
|
||||
if explicitName == "" && r.Kind() != "package" {
|
||||
return r.ImplicitName
|
||||
}
|
||||
return explicitName
|
||||
@@ -182,26 +203,25 @@ func (r *Rule) Name() string {
|
||||
func (r *Rule) AttrKeys() []string {
|
||||
var keys []string
|
||||
for _, expr := range r.Call.List {
|
||||
if binExpr, ok := expr.(*BinaryExpr); ok && binExpr.Op == "=" {
|
||||
if keyExpr, ok := binExpr.X.(*LiteralExpr); ok {
|
||||
keys = append(keys, keyExpr.Token)
|
||||
if as, ok := expr.(*AssignExpr); ok {
|
||||
if keyExpr, ok := as.LHS.(*Ident); ok {
|
||||
keys = append(keys, keyExpr.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// AttrDefn returns the BinaryExpr defining the rule's attribute with the given key.
|
||||
// That is, the result is a *BinaryExpr with Op == "=".
|
||||
// AttrDefn returns the AssignExpr defining the rule's attribute with the given key.
|
||||
// If the rule has no such attribute, AttrDefn returns nil.
|
||||
func (r *Rule) AttrDefn(key string) *BinaryExpr {
|
||||
func (r *Rule) AttrDefn(key string) *AssignExpr {
|
||||
for _, kv := range r.Call.List {
|
||||
as, ok := kv.(*BinaryExpr)
|
||||
if !ok || as.Op != "=" {
|
||||
as, ok := kv.(*AssignExpr)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
k, ok := as.X.(*LiteralExpr)
|
||||
if !ok || k.Token != key {
|
||||
k, ok := as.LHS.(*Ident)
|
||||
if !ok || k.Name != key {
|
||||
continue
|
||||
}
|
||||
return as
|
||||
@@ -217,7 +237,7 @@ func (r *Rule) Attr(key string) Expr {
|
||||
if as == nil {
|
||||
return nil
|
||||
}
|
||||
return as.Y
|
||||
return as.RHS
|
||||
}
|
||||
|
||||
// DelAttr deletes the rule's attribute with the named key.
|
||||
@@ -225,17 +245,17 @@ func (r *Rule) Attr(key string) Expr {
|
||||
func (r *Rule) DelAttr(key string) Expr {
|
||||
list := r.Call.List
|
||||
for i, kv := range list {
|
||||
as, ok := kv.(*BinaryExpr)
|
||||
if !ok || as.Op != "=" {
|
||||
as, ok := kv.(*AssignExpr)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
k, ok := as.X.(*LiteralExpr)
|
||||
if !ok || k.Token != key {
|
||||
k, ok := as.LHS.(*Ident)
|
||||
if !ok || k.Name != key {
|
||||
continue
|
||||
}
|
||||
copy(list[i:], list[i+1:])
|
||||
r.Call.List = list[:len(list)-1]
|
||||
return as.Y
|
||||
return as.RHS
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -246,15 +266,15 @@ func (r *Rule) DelAttr(key string) Expr {
|
||||
func (r *Rule) SetAttr(key string, val Expr) {
|
||||
as := r.AttrDefn(key)
|
||||
if as != nil {
|
||||
as.Y = val
|
||||
as.RHS = val
|
||||
return
|
||||
}
|
||||
|
||||
r.Call.List = append(r.Call.List,
|
||||
&BinaryExpr{
|
||||
X: &LiteralExpr{Token: key},
|
||||
Op: "=",
|
||||
Y: val,
|
||||
&AssignExpr{
|
||||
LHS: &Ident{Name: key},
|
||||
Op: "=",
|
||||
RHS: val,
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -265,11 +285,14 @@ func (r *Rule) SetAttr(key string, val Expr) {
|
||||
// If the rule has no such attribute or the attribute is not an identifier or number,
|
||||
// AttrLiteral returns "".
|
||||
func (r *Rule) AttrLiteral(key string) string {
|
||||
lit, ok := r.Attr(key).(*LiteralExpr)
|
||||
if !ok {
|
||||
return ""
|
||||
value := r.Attr(key)
|
||||
if ident, ok := value.(*Ident); ok {
|
||||
return ident.Name
|
||||
}
|
||||
return lit.Token
|
||||
if literal, ok := value.(*LiteralExpr); ok {
|
||||
return literal.Token
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// AttrString returns the value of the rule's attribute
|
||||
|
||||
Reference in New Issue
Block a user