Repository: gobuffalo/buffalo
Pull request #1672 (2019-05-24 18:40:11)

Add --skip-build-deps option for build
When using vendored go modules, one may want to leave out `go get` part from `buffalo build` for various reasons.

My reason to leave module update out is that we have dependencies in private repositories that cannot(or is hard enough to) be fetched while building testing environment for larger set of applications within Docker container.

Other reasons:
* Network connection is down
* You are developing behind expensive mobile network
* There is broken server at GitHub and cannot access repository(has happened 3 times with npm modules for me.. yes, it is unbelievable)
* Dependencies can be saved somewhere and they are saved if they are removed from internet(known to happen) => build still works even though one cannot actually fetch dependencies
* I'm sure there is many other reasons too.

markbates: Looks like the tests are failing, would you mind taking at look? Thanks.
jani-hast: > Looks like the tests are failing, would you mind taking at look? Thanks.

Yes, will do asap.

> I was waiting for someone to add this! Thanks!

:) it is good thing  that others can use it too. Clad to help.
jani123: Okay, so there is actually two bugs in master now that prevents this pull requests pipelines to pass.

Another one is `Test_Template_Partial_Form` test which fails because it uses anonymous struct without ID field. I committed fix for this, but pipelines now finds some different version of some project and form doesn't actually contain action tag as it does on my environment:

```diff
-<form action="/users/user-id" id="user-form" method="POST"><div class="form-group"><label>Name</label><input class=" form-control" id="user-Name" name="Name" type="text" value="Mark" /></div></form>
+<form id="user-form" method="POST"><div class="form-group"><label>Name</label><input class=" form-control" id="user-Name" name="Name" type="text" value="Mark" /></div></form>
```

Another case is that there is this go module support bug which makes tests say:
```
go: unknown subcommand "mod"
```

So the question is that is someone already on those issues since they do happen on other branches too.. I do not have more time for this weekend so, for me this stalls here unfortunately.
markbates: @jani123 I think this PR should fix the underlying test issues. https://github.com/gobuffalo/buffalo/pull/1673 would love a review if you have a minute.
jani-hast: @markbates Yes, I inspected the PL through and it shows well who developed Buffalo and who started learning Go and Go Buffalo few weeks ago :D. Looks like that would solve issues. I will merge master here when it is ready.

And on side note, we have in Liana Technologies done now few pull requests with good response and changes has gone through quickly. So, I'd like to thank whole Core Team for that!
markbates: All passing now! Thanks again!

Patch:
diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go
index df43d545..e640b8d9 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 4fb100ce..e50f4865 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/options.go b/genny/build/options.go
index 3b5edc28..7bb7495a 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"`


Test patch:
diff --git a/genny/build/build_test.go b/genny/build/build_test.go
index d231d509..6b172548 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)
 		}
 	})
 }