Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

adds quoting around build tags fixes #1114 #1126

Merged
merged 2 commits into from
Jun 22, 2018
Merged
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
1 change: 0 additions & 1 deletion buffalo/cmd/build/apkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (b *Builder) buildADatabase() error {
return errors.WithStack(err)
}
if bytes.Contains(bb.Bytes(), []byte("sqlite")) {
b.Tags = append(b.Tags, "sqlite")
if !b.Static {
logrus.Debug("you are building a SQLite application, please consider using the `--static` flag to compile a static binary")
}
Expand Down
5 changes: 3 additions & 2 deletions buffalo/cmd/build/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func (b *Builder) buildBin() error {
if b.Debug {
buildArgs = append(buildArgs, "-v")
}
b.Tags = append(b.Tags, b.Environment)
buildArgs = append(buildArgs, "-tags", strings.Join(b.Tags, " "))

tf := b.App.BuildTags(b.Environment, b.Tags...)
buildArgs = append(buildArgs, "-tags", tf.String())

buildArgs = append(buildArgs, "-o", b.Bin)

Expand Down
15 changes: 7 additions & 8 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package cmd

import (
"bytes"
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -114,13 +112,14 @@ func startDevServer(ctx context.Context) error {
return err
}
c.Debug = devOptions.Debug
tags := []string{"-tags", "development"}
if b, err := ioutil.ReadFile("database.yml"); err == nil {
if bytes.Contains(b, []byte("sqlite")) {
tags = append(tags, "sqlite")
}

app := meta.New(".")
bt := app.BuildTags("development")
var tf []string
for _, b := range bt {
tf = append(tf, "-tags", b)
}
c.BuildFlags = append(c.BuildFlags, tags...)
c.BuildFlags = append(c.BuildFlags, tf...)
r := refresh.NewWithContext(c, ctx)
return r.Start()
}
Expand Down
9 changes: 3 additions & 6 deletions buffalo/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bytes"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -214,11 +213,9 @@ func testPackages(givenArgs []string) ([]string, error) {

func newTestCmd(args []string) *exec.Cmd {
cargs := []string{"test", "-p", "1"}
if b, err := ioutil.ReadFile("database.yml"); err == nil {
if bytes.Contains(b, []byte("sqlite")) {
cargs = append(cargs, "-tags", "sqlite")
}
}
app := meta.New(".")
tf := "-tags " + app.BuildTags("development").String()
cargs = append(cargs, tf)
cargs = append(cargs, args...)
cmd := exec.Command(envy.Get("GO_BIN", "go"), cargs...)
cmd.Stdin = os.Stdin
Expand Down
30 changes: 30 additions & 0 deletions meta/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package meta

import (
"bytes"
"io/ioutil"
"strings"
)

// BuildTags are tags used for building apps
type BuildTags []string

// String returns the tags in the form of:
// "foo bar baz" (with the quotes!)
func (t BuildTags) String() string {
return `"` + strings.Join(t, " ") + `"`
}

// BuildTags combines the passed in env, and any additional tags,
// with tags that Buffalo decides the build process requires.
// An example would be adding the "sqlite" build tag if using
// SQLite3.
func (a App) BuildTags(env string, tags ...string) BuildTags {
tags = append(tags, env)
if b, err := ioutil.ReadFile("database.yml"); err == nil {
if bytes.Contains(b, []byte("sqlite")) {
tags = append(tags, "sqlite")
}
}
return BuildTags(tags)
}
47 changes: 47 additions & 0 deletions meta/tags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package meta

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func Test_BuildTags(t *testing.T) {
defer os.Remove("database.yml")
app := New(".")
t.Run("without database.yml", func(st *testing.T) {
r := require.New(st)
tags := app.BuildTags("dev")
r.Len(tags, 1)
r.Equal("dev", tags[0])
r.Equal(`"dev"`, tags.String())
})
t.Run("with database.yml", func(st *testing.T) {
t.Run("with sqlite", func(st *testing.T) {
r := require.New(st)
f, err := os.Create("database.yml")
r.NoError(err)
_, err = f.WriteString("sqlite")
r.NoError(err)

tags := app.BuildTags("dev")
r.Len(tags, 2)
r.Equal("dev", tags[0])
r.Equal("sqlite", tags[1])
r.Equal(`"dev sqlite"`, tags.String())
})
t.Run("without sqlite", func(st *testing.T) {
r := require.New(st)
f, err := os.Create("database.yml")
r.NoError(err)
_, err = f.WriteString("mysql")
r.NoError(err)

tags := app.BuildTags("dev")
r.Len(tags, 1)
r.Equal("dev", tags[0])
r.Equal(`"dev"`, tags.String())
})
})
}