From 7da89e26da2a1636d443ad84ced19a4ec10f8bd6 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Thu, 17 Feb 2022 10:07:36 -0300 Subject: [PATCH] fix: do not copy binary by default closes #2913 Signed-off-by: Carlos A Becker --- cmd/build.go | 9 +++++---- cmd/build_test.go | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 7ce4e4ef462..c81c5fa846c 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -94,7 +94,7 @@ defaulting to the current's machine target if not set. cmd.Flags().BoolVar(&root.opts.singleTarget, "single-target", false, "Builds only for current GOOS and GOARCH") cmd.Flags().StringVar(&root.opts.id, "id", "", "Builds only the specified build id") cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only") - cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Path to the binary, defaults to the distribution folder according to configs. Only taked into account when using --single-target and a single id (either with --id or if config only has one build)") + cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Copy the binary to thie path after the build. Only taked into account when using --single-target and a single id (either with --id or if config only has one build)") _ = cmd.Flags().MarkHidden("deprecated") root.cmd = cmd @@ -129,7 +129,7 @@ func buildProject(options buildOpts) (*context.Context, error) { } func setupPipeline(ctx *context.Context, options buildOpts) []pipeline.Piper { - if options.singleTarget && (options.id != "" || len(ctx.Config.Builds) == 1) { + if options.output != "" && options.singleTarget && (options.id != "" || len(ctx.Config.Builds) == 1) { return append(pipeline.BuildCmdPipeline, withOutputPipe{options.output}) } return pipeline.BuildCmdPipeline @@ -215,9 +215,10 @@ func (w withOutputPipe) String() string { func (w withOutputPipe) Run(ctx *context.Context) error { path := ctx.Artifacts.Filter(artifact.ByType(artifact.Binary)).List()[0].Path + name := filepath.Base(path) out := w.output - if out == "" { - out = filepath.Base(path) + if out == "." { + out = name } return gio.Copy(path, out) } diff --git a/cmd/build_test.go b/cmd/build_test.go index b6d2c415e37..5bb879df0f8 100644 --- a/cmd/build_test.go +++ b/cmd/build_test.go @@ -63,10 +63,22 @@ func TestSetupPipeline(t *testing.T) { t.Run("single-target and id", func(t *testing.T) { require.Equal( t, - append(pipeline.BuildCmdPipeline, withOutputPipe{""}), + pipeline.BuildCmdPipeline, + setupPipeline(context.New(config.Project{}), buildOpts{ + singleTarget: true, + id: "foo", + }), + ) + }) + + t.Run("single-target and id, given output", func(t *testing.T) { + require.Equal( + t, + append(pipeline.BuildCmdPipeline, withOutputPipe{"foobar"}), setupPipeline(context.New(config.Project{}), buildOpts{ singleTarget: true, id: "foo", + output: ".", }), ) }) @@ -74,7 +86,7 @@ func TestSetupPipeline(t *testing.T) { t.Run("single-target and single build on config", func(t *testing.T) { require.Equal( t, - append(pipeline.BuildCmdPipeline, withOutputPipe{""}), + pipeline.BuildCmdPipeline, setupPipeline( context.New(config.Project{ Builds: []config.Build{{}},