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

Commit

Permalink
Merge branch 'development' into helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored May 26, 2019
2 parents 0d085a0 + 6c8bca6 commit 667026c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
3 changes: 3 additions & 0 deletions buffalo/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
var buildOptions = struct {
*build.Options
SkipAssets bool
SkipBuildDeps bool
Debug bool
Tags string
SkipTemplateValidation bool
Expand Down Expand Up @@ -47,6 +48,7 @@ var xbuildCmd = &cobra.Command{
}

buildOptions.Options.WithAssets = !buildOptions.SkipAssets
buildOptions.Options.WithBuildDeps = !buildOptions.SkipBuildDeps

run := genny.WetRunner(ctx)
if buildOptions.DryRun {
Expand Down Expand Up @@ -88,6 +90,7 @@ func init() {
xbuildCmd.Flags().StringVarP(&buildOptions.Tags, "tags", "t", "", "compile with specific build tags")
xbuildCmd.Flags().BoolVarP(&buildOptions.ExtractAssets, "extract-assets", "e", false, "extract the assets and put them in a distinct archive")
xbuildCmd.Flags().BoolVarP(&buildOptions.SkipAssets, "skip-assets", "k", false, "skip running webpack and building assets")
xbuildCmd.Flags().BoolVarP(&buildOptions.SkipBuildDeps, "skip-build-deps", "", false, "skip building dependencies")
xbuildCmd.Flags().BoolVarP(&buildOptions.Static, "static", "s", false, "build a static binary using --ldflags '-linkmode external -extldflags \"-static\"'")
xbuildCmd.Flags().StringVar(&buildOptions.LDFlags, "ldflags", "", "set any ldflags to be passed to the go build")
xbuildCmd.Flags().BoolVarP(&buildOptions.Verbose, "verbose", "v", false, "print debugging information")
Expand Down
12 changes: 7 additions & 5 deletions genny/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ func New(opts *Options) (*genny.Generator, error) {
g.Merge(ag)
}

// mount the build time dependency generator
dg, err := buildDeps(opts)
if err != nil {
return g, err
if opts.WithBuildDeps {
// mount the build time dependency generator
dg, err := buildDeps(opts)
if err != nil {
return g, err
}
g.Merge(dg)
}
g.Merge(dg)

g.RunFn(func(r *genny.Runner) error {
return jam.Pack(jam.PackOptions{})
Expand Down
52 changes: 41 additions & 11 deletions genny/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ var cokeRunner = func() *genny.Runner {
return run
}

var eq = func(r *require.Assertions, s string, c *exec.Cmd) {
if runtime.GOOS == "windows" {
s = strings.Replace(s, "bin/build", `bin\build.exe`, 1)
s = strings.Replace(s, "bin/foo", `bin\foo.exe`, 1)
}
r.Equal(s, strings.Join(c.Args, " "))
}

func Test_New(t *testing.T) {
envy.Temp(func() {
envy.Set(envy.GO111MODULE, "off")
Expand All @@ -34,9 +42,10 @@ func Test_New(t *testing.T) {
run := cokeRunner()

opts := &Options{
WithAssets: true,
Environment: "bar",
App: meta.New("."),
WithAssets: true,
WithBuildDeps: true,
Environment: "bar",
App: meta.New("."),
}
opts.App.Bin = "bin/foo"
r.NoError(run.WithNew(New(opts)))
Expand All @@ -49,18 +58,39 @@ func Test_New(t *testing.T) {
// we should never leave any files modified or dropped
r.Len(res.Files, 0)

eq := func(s string, c *exec.Cmd) {
if runtime.GOOS == "windows" {
s = strings.Replace(s, "bin/build", `bin\build.exe`, 1)
s = strings.Replace(s, "bin/foo", `bin\foo.exe`, 1)
}
r.Equal(s, strings.Join(c.Args, " "))
cmds := []string{"go get -tags bar ./...", "go build -i -tags bar -o bin/foo"}
r.Len(res.Commands, len(cmds))
for i, c := range res.Commands {
eq(r, cmds[i], c)
}
})
}

cmds := []string{"go get -tags bar ./...", "go build -i -tags bar -o bin/foo"}
func Test_NewWithoutBuildDeps(t *testing.T) {
envy.Temp(func() {
envy.Set(envy.GO111MODULE, "off")
r := require.New(t)

run := cokeRunner()

opts := &Options{
WithAssets: false,
WithBuildDeps: false,
Environment: "bar",
App: meta.New("."),
}
opts.App.Bin = "bin/foo"
r.NoError(run.WithNew(New(opts)))
run.Root = opts.App.Root

r.NoError(run.Run())

res := run.Results()

cmds := []string{"go build -i -tags bar -o bin/foo"}
r.Len(res.Commands, len(cmds))
for i, c := range res.Commands {
eq(cmds[i], c)
eq(r, cmds[i], c)
}
})
}
5 changes: 3 additions & 2 deletions genny/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type Options struct {
// b) to time.RFC3339 of BuildTime
BuildVersion string `json:"build_version,omitempty"`
// CleanAssets will remove the public/assets folder build compiling
CleanAssets bool `json:"clean_assets"`
WithAssets bool `json:"with_assets,omitempty"`
CleanAssets bool `json:"clean_assets"`
WithAssets bool `json:"with_assets,omitempty"`
WithBuildDeps bool `json:"with_build_deps,omitempty"`
// places ./public/assets into ./bin/assets.zip.
// requires WithAssets = true
ExtractAssets bool `json:"extract_assets,omitempty"`
Expand Down

0 comments on commit 667026c

Please sign in to comment.