diff --git a/lib/builder.go b/lib/builder.go index 0181812..392ddb5 100644 --- a/lib/builder.go +++ b/lib/builder.go @@ -14,13 +14,14 @@ type Builder interface { } type builder struct { + execdir string dir string binary string errors string useGodep bool } -func NewBuilder(dir string, bin string, useGodep bool) Builder { +func NewBuilder(execdir string, dir string, bin string, useGodep bool) Builder { if len(bin) == 0 { bin = "bin" } @@ -32,7 +33,7 @@ func NewBuilder(dir string, bin string, useGodep bool) Builder { } } - return &builder{dir: dir, binary: bin, useGodep: useGodep} + return &builder{execdir: execdir, dir: dir, binary: bin, useGodep: useGodep} } func (b *builder) Binary() string { @@ -50,7 +51,7 @@ func (b *builder) Build() error { } else { command = exec.Command("go", "build", "-o", b.binary) } - command.Dir = b.dir + command.Dir = b.execdir output, err := command.CombinedOutput() diff --git a/lib/builder_test.go b/lib/builder_test.go index 73d039e..b782c08 100644 --- a/lib/builder_test.go +++ b/lib/builder_test.go @@ -15,7 +15,7 @@ func Test_Builder_Build_Success(t *testing.T) { bin += ".exe" } - builder := gin.NewBuilder(wd, bin, false) + builder := gin.NewBuilder(wd, wd, bin, false) err := builder.Build() expect(t, err, nil) diff --git a/main.go b/main.go index e9310a0..0b53494 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,11 @@ func main() { Value: ".", Usage: "Path to watch files from", }, + cli.StringFlag{ + Name: "execpath,e", + Value: "", + Usage: "Path to package that contains buildable artifact", + }, cli.BoolFlag{ Name: "immediate,i", Usage: "run the server immediately after it's built", @@ -82,6 +87,11 @@ func MainAction(c *cli.Context) { appPort := strconv.Itoa(c.GlobalInt("appPort")) immediate = c.GlobalBool("immediate") + execpath := c.GlobalString("execpath") + if len(execpath) == 0 { + c.GlobalString("path") + } + // Bootstrap the environment envy.Bootstrap() @@ -93,8 +103,8 @@ func MainAction(c *cli.Context) { logger.Fatal(err) } - builder := gin.NewBuilder(c.GlobalString("path"), c.GlobalString("bin"), c.GlobalBool("godep")) - runner := gin.NewRunner(filepath.Join(wd, builder.Binary()), c.Args()...) + builder := gin.NewBuilder(execpath, c.GlobalString("path"), c.GlobalString("bin"), c.GlobalBool("godep")) + runner := gin.NewRunner(filepath.Join(wd, execpath, builder.Binary()), c.Args()...) runner.SetWriter(os.Stdout) proxy := gin.NewProxy(builder, runner) @@ -170,6 +180,7 @@ func scanChanges(watchPath string, cb scanCallback) { } if filepath.Ext(path) == ".go" && info.ModTime().After(startTime) { + log.Printf("%s", path) cb(path) startTime = time.Now() return errors.New("done")