@@ -25,6 +25,7 @@ import (
25
25
"github.com/buildbarn/bonanza/pkg/storage/object"
26
26
27
27
"google.golang.org/protobuf/proto"
28
+ "google.golang.org/protobuf/types/known/emptypb"
28
29
29
30
"go.starlark.net/starlark"
30
31
)
@@ -496,6 +497,19 @@ func (c *baseComputer) ComputeUserDefinedTransitionValue(ctx context.Context, ke
496
497
/* kwargs = */ nil ,
497
498
)
498
499
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
+ }
499
513
if ! errors .Is (err , evaluation .ErrMissingDependency ) {
500
514
var evalErr * starlark.EvalError
501
515
if errors .As (err , & evalErr ) {
@@ -579,7 +593,7 @@ func (c *baseComputer) ComputeUserDefinedTransitionValue(ctx context.Context, ke
579
593
580
594
type stubbedTransitionAttr struct {}
581
595
582
- var _ starlark.Mapping = stubbedTransitionAttr {}
596
+ var _ starlark.HasAttrs = stubbedTransitionAttr {}
583
597
584
598
func (stubbedTransitionAttr ) String () string {
585
599
return "<transition_attr>"
@@ -599,9 +613,13 @@ func (stubbedTransitionAttr) Hash(thread *starlark.Thread) (uint32, error) {
599
613
return 0 , errors .New ("transition_attr cannot be hashed" )
600
614
}
601
615
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
607
625
}
0 commit comments