Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dependency check after post_build step. #3174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/build/build_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Build(state *core.BuildState, target *core.BuildTarget, remote bool) {
} else {
successfulLocalTargetBuildDuration.Observe(float64(time.Since(start).Milliseconds()))
}

// Mark the target as having finished building.
target.FinishBuild()
if target.IsTest() && state.NeedTests && state.IsOriginalTarget(target) {
Expand Down Expand Up @@ -343,6 +344,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)
Expand Down
17 changes: 17 additions & 0 deletions src/core/build_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,14 @@
defer target.mutex.RUnlock()
ret := make(BuildLabels, 0, len(target.dependencies))
for _, info := range target.dependencies {
logString := ""
for i, dep := range info.deps {
logString += dep.Label.Name
if i+1 < len(info.deps) {
logString += ", "
}
}
log.Info("Exported deps call for target %s: %s , exported: %t", target.Label, logString, info.exported)
if info.exported {
ret = append(ret, *info.declared)
}
Expand Down Expand Up @@ -1653,8 +1661,17 @@
}
}

// 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)
}
info.deps = append(info.deps, deptarget)
}

Check failure on line 1671 in src/core/build_target.go

View workflow job for this annotation

GitHub Actions / lint

SA5011(related information): this check suggests that the pointer can be nil (staticcheck)

// IsTool returns true if the given build label is a tool used by this target.
func (target *BuildTarget) IsTool(tool BuildLabel) bool {

Check failure on line 1674 in src/core/build_target.go

View workflow job for this annotation

GitHub Actions / lint

SA5011: possible nil pointer dereference (staticcheck)
for _, t := range target.Tools {
if label, ok := t.Label(); ok && label == tool {
return true
Expand Down
1 change: 1 addition & 0 deletions src/parse/asp/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading