From 6c8bca63fca98ad433943463a55b3326e2f033fc Mon Sep 17 00:00:00 2001 From: Jani Hast Date: Sun, 26 May 2019 23:57:54 +0300 Subject: [PATCH] Add --skip-build-deps option for build (#1672) * Add --skip-build-deps option for build * Fixing failing test. form_for expects named struct and ID fields for form action. --- buffalo/cmd/build.go | 3 +++ genny/build/build.go | 12 +++++---- genny/build/build_test.go | 52 ++++++++++++++++++++++++++++++--------- genny/build/options.go | 5 ++-- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go index df43d5451..e640b8d94 100644 --- a/buffalo/cmd/build.go +++ b/buffalo/cmd/build.go @@ -19,6 +19,7 @@ import ( var buildOptions = struct { *build.Options SkipAssets bool + SkipBuildDeps bool Debug bool Tags string SkipTemplateValidation bool @@ -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 { @@ -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") diff --git a/genny/build/build.go b/genny/build/build.go index 4fb100ce3..e50f4865c 100644 --- a/genny/build/build.go +++ b/genny/build/build.go @@ -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{}) diff --git a/genny/build/build_test.go b/genny/build/build_test.go index d231d5099..6b1725487 100644 --- a/genny/build/build_test.go +++ b/genny/build/build_test.go @@ -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") @@ -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))) @@ -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) } }) } diff --git a/genny/build/options.go b/genny/build/options.go index 3b5edc28e..7bb7495a3 100644 --- a/genny/build/options.go +++ b/genny/build/options.go @@ -18,8 +18,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"`