Skip to content

Commit

Permalink
Merge pull request #1487 from dgageot/fix-1467
Browse files Browse the repository at this point in the history
Pass bazel args to `bazel info hazel-bin`
  • Loading branch information
nkubala authored Jan 19, 2019
2 parents 4ec6b23 + 1195312 commit 51bcca6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pkg/skaffold/build/local/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *Builder) buildBazel(ctx context.Context, out io.Writer, workspace strin
return "", errors.Wrap(err, "running command")
}

bazelBin, err := bazelBin(ctx, workspace)
bazelBin, err := bazelBin(ctx, workspace, a)
if err != nil {
return "", errors.Wrap(err, "getting path of bazel-bin")
}
Expand All @@ -65,8 +65,11 @@ func (b *Builder) buildBazel(ctx context.Context, out io.Writer, workspace strin
return imageID, nil
}

func bazelBin(ctx context.Context, workspace string) (string, error) {
cmd := exec.CommandContext(ctx, "bazel", "info", "bazel-bin")
func bazelBin(ctx context.Context, workspace string, a *latest.BazelArtifact) (string, error) {
args := []string{"info", "bazel-bin"}
args = append(args, a.BuildArgs...)

cmd := exec.CommandContext(ctx, "bazel", args...)
cmd.Dir = workspace

buf, err := util.RunCmdOut(cmd)
Expand Down
7 changes: 5 additions & 2 deletions pkg/skaffold/build/local/bazel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ import (
"context"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestBazelBin(t *testing.T) {
defer func(c util.Command) { util.DefaultExecCommand = c }(util.DefaultExecCommand)
util.DefaultExecCommand = testutil.NewFakeCmd(t).WithRunOut(
"bazel info bazel-bin",
"bazel info bazel-bin --arg1 --arg2",
"/absolute/path/bin\n",
)

bazelBin, err := bazelBin(context.Background(), ".")
bazelBin, err := bazelBin(context.Background(), ".", &latest.BazelArtifact{
BuildArgs: []string{"--arg1", "--arg2"},
})

testutil.CheckErrorAndDeepEqual(t, false, err, "/absolute/path/bin", bazelBin)
}
Expand Down

0 comments on commit 51bcca6

Please sign in to comment.