Skip to content

Commit 620e166

Browse files
committed
Properly catch user defined transitions that use 'attr'
1 parent c7d3d52 commit 620e166

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

pkg/model/analysis/user_defined_transition.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/buildbarn/bonanza/pkg/storage/object"
2626

2727
"google.golang.org/protobuf/proto"
28+
"google.golang.org/protobuf/types/known/emptypb"
2829

2930
"go.starlark.net/starlark"
3031
)
@@ -496,6 +497,19 @@ func (c *baseComputer) ComputeUserDefinedTransitionValue(ctx context.Context, ke
496497
/* kwargs = */ nil,
497498
)
498499
if err != nil {
500+
if errors.Is(err, errTransitionDependsOnAttrs) {
501+
// Can't compute the transition indepently of
502+
// the rule in which it is referenced. Return
503+
// this to the caller, so that it can apply the
504+
// transition directly.
505+
return model_core.NewSimplePatchedMessage[dag.ObjectContentsWalker](
506+
&model_analysis_pb.UserDefinedTransition_Value{
507+
Result: &model_analysis_pb.UserDefinedTransition_Value_TransitionDependsOnAttrs{
508+
TransitionDependsOnAttrs: &emptypb.Empty{},
509+
},
510+
},
511+
), nil
512+
}
499513
if !errors.Is(err, evaluation.ErrMissingDependency) {
500514
var evalErr *starlark.EvalError
501515
if errors.As(err, &evalErr) {
@@ -579,7 +593,7 @@ func (c *baseComputer) ComputeUserDefinedTransitionValue(ctx context.Context, ke
579593

580594
type stubbedTransitionAttr struct{}
581595

582-
var _ starlark.Mapping = stubbedTransitionAttr{}
596+
var _ starlark.HasAttrs = stubbedTransitionAttr{}
583597

584598
func (stubbedTransitionAttr) String() string {
585599
return "<transition_attr>"
@@ -599,9 +613,13 @@ func (stubbedTransitionAttr) Hash(thread *starlark.Thread) (uint32, error) {
599613
return 0, errors.New("transition_attr cannot be hashed")
600614
}
601615

602-
func (stubbedTransitionAttr) Get(*starlark.Thread, starlark.Value) (starlark.Value, bool, error) {
603-
// TODO: This should return an error that
604-
// ComputeUserDefinedTransitionValue() catches and turns into a
605-
// special response.
606-
return nil, false, errors.New("transition depends on rule attrs, which are not available in this context")
616+
var errTransitionDependsOnAttrs = errors.New("transition depends on rule attrs, which are not available in this context")
617+
618+
func (stubbedTransitionAttr) Attr(*starlark.Thread, string) (starlark.Value, error) {
619+
return nil, errTransitionDependsOnAttrs
620+
}
621+
622+
func (stubbedTransitionAttr) AttrNames() []string {
623+
// TODO: This should also be able to return an error.
624+
return nil
607625
}

0 commit comments

Comments
 (0)