diff --git a/src/build/build_step.go b/src/build/build_step.go index 1c274c2ab..d028eb67d 100644 --- a/src/build/build_step.go +++ b/src/build/build_step.go @@ -343,6 +343,16 @@ func buildTarget(state *core.BuildState, target *core.BuildTarget, runRemotely b return err } + // Wait for any new dependencies added by post-build commands before continuing. + for _, dep := range target.Dependencies() { + dep.WaitForBuild() + if dep.State() >= core.DependencyFailed { // Either the target failed or its dependencies failed + // Give up and set the original target as dependency failed + target.SetState(core.DependencyFailed) + return fmt.Errorf("error in post-rule dependency for %s: %s", target.Label, dep.Label) + } + } + if runRemotely && len(outs) != len(target.Outputs()) { // postBuildFunction has changed the target - must rebuild it log.Info("Rebuilding %s after post-build function", target) diff --git a/src/core/build_target.go b/src/core/build_target.go index 166dbb515..fb91a935b 100644 --- a/src/core/build_target.go +++ b/src/core/build_target.go @@ -1653,6 +1653,16 @@ func (target *BuildTarget) AddMaybeExportedDependency(dep BuildLabel, exported, } } +// RegisterDependencyTarget registers a build target to be used for a dependency label on the given target. +func (target *BuildTarget) RegisterDependencyTarget(dep BuildLabel, deptarget *BuildTarget) { + info := target.dependencyInfo(dep) + if info == nil { + log.Fatalf("Target %s doesn't contain dependency %s.\n", target.Label, dep) + } else { + info.deps = append(info.deps, deptarget) + } +} + // IsTool returns true if the given build label is a tool used by this target. func (target *BuildTarget) IsTool(tool BuildLabel) bool { for _, t := range target.Tools { diff --git a/src/parse/asp/builtins.go b/src/parse/asp/builtins.go index e3a04b53a..cc82f74b6 100644 --- a/src/parse/asp/builtins.go +++ b/src/parse/asp/builtins.go @@ -1125,6 +1125,7 @@ func addDep(s *scope, args []pyObject) pyObject { dep := s.parseLabelInPackage(string(args[1].(pyString)), s.pkg) exported := args[2].IsTruthy() target.AddMaybeExportedDependency(dep, exported, false, false) + target.RegisterDependencyTarget(dep, s.state.Graph.Target(dep)) // Queue this dependency if it'll be needed. if target.State() > core.Inactive { err := s.state.QueueTarget(dep, target.Label, false, core.ParseModeNormal)