Skip to content

Commit

Permalink
Fix regression in build dependency error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Oct 6, 2020
1 parent 30b4005 commit 7b3bd1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog][], and this project adheres to

[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/

## [0.3.1][]

Version 0.3.1 fixes an issue with error handling during builds.

[0.3.1]: https://github.com/yourbase/yb/releases/tag/v0.3.1

### Fixed

- Fixed a regression where if a dependent target fails, it did not stop
the build.

## [0.3.0][]

Version 0.3 is the first release with our new release automation.
Expand Down
40 changes: 15 additions & 25 deletions cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"io/ioutil"
"os"
"os/signal"
"os/user"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -211,15 +210,10 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
mount := fmt.Sprintf("%s:%s", targetPackage.Path, sourceMapDir)
containerDef.Mounts = append(containerDef.Mounts, mount)

if false {
u, _ := user.Current()
fmt.Printf("U! %s", u.Uid)
}

// Do our build in a container - don't do the build locally
buildErr := b.BuildInsideContainer(ctx, target, containerDef, buildData, b.ExecPrefix, b.ReuseContainers)
if buildErr != nil {
log.Errorf(ctx, "Unable to build %s inside container: %v", target.Name, buildErr)
err := b.BuildInsideContainer(ctx, target, containerDef, buildData, b.ExecPrefix, b.ReuseContainers)
if err != nil {
log.Errorf(ctx, "Unable to build %s inside container: %v", target.Name, err)
return subcommands.ExitFailure
}

Expand All @@ -243,8 +237,6 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
}
}

var buildError error

startSection("BUILD")

config := BuildConfiguration{
Expand All @@ -261,16 +253,17 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
log.Infof(ctx, " - %s", target.Name)
}

var buildError error
for _, target := range buildTargets {
targetCtx, targetSpan := tracer().Start(ctx, target.Name, trace.WithAttributes(
label.String("target", target.Name),
))
err := targetPackage.SetupBuildDependencies(targetCtx, target)
if err != nil {
targetSpan.SetStatus(codes.Internal, err.Error())
buildError = targetPackage.SetupBuildDependencies(targetCtx, target)
if buildError != nil {
buildError = fmt.Errorf("setting up dependencies for target %s: %w", target.Name, buildError)
targetSpan.SetStatus(codes.Internal, buildError.Error())
targetSpan.End()
log.Infof(ctx, "Error setting up dependencies for target %s: %v", target.Name, err)
return subcommands.ExitFailure
break
}

if b.DependenciesOnly {
Expand All @@ -280,27 +273,24 @@ func (b *BuildCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
config.Target = target
buildData.ExportEnvironmentPublicly(ctx)
log.Infof(ctx, "Executing build steps...")
err = RunCommands(targetCtx, config)
if err != nil {
targetSpan.SetStatus(codes.Unknown, err.Error())
buildError = RunCommands(targetCtx, config)
if buildError != nil {
buildError = fmt.Errorf("running commands for target %s: %w", target.Name, buildError)
targetSpan.SetStatus(codes.Unknown, buildError.Error())
}
targetSpan.End()
buildData.UnexportEnvironmentPublicly(ctx)
if buildError != nil {
break
}
}
if b.DependenciesOnly {
log.Infof(ctx, "Only installing dependencies; done!")
return subcommands.ExitSuccess
}

if buildError != nil {
span.SetStatus(codes.Unknown, buildError.Error())
}
endTime := time.Now()
span.End()
endTime := time.Now()
buildTime := endTime.Sub(startTime)

time.Sleep(100 * time.Millisecond)

log.Infof(ctx, "")
Expand Down

0 comments on commit 7b3bd1a

Please sign in to comment.