2

my working tree is like this:

/opt/go/src/tb-to-composer/
├── apis
│   └── rtb.go
├── config.yaml
├── jsondef
│   └── structures.go
├── LICENSE.md
├── README.md
├── tb-to-composer
└── thingsToComposer.go

when I do go build inside /opt/go/src/tb-to-composer/ the build doesn't recompile rtb.go and structures.go even though there was changes in them. In order to achieve build I need to run go build -a every time I do a change to rtb.go or structures.go, is that the expected behavior from go build? How to I recompile only custom libs inside my package folder without recompile the whole /opt/go/src tree?

  • 1
    Is `thingsToComposer.go` your `main`, and does it reference the `apis` and `jsondef` packages? When you build in a directory, it builds only what it needs to in order to make that binary. – Adrian Apr 12 '18 at 19:06
  • yes, thingsToComposer is my main imports tb-to-compose/apis and rtb.go imports tb-to-compose/jsondef – Vieira Neto Manoel Apr 12 '18 at 19:18

1 Answers1

0

You can try the -i flag, or (this does not work, sorry) specify the files in the directories explicitly as arguments to go build, i.e. go build thingsToComposer.go apis/rtb.go jsondef/structures.go

Slabgorb
  • 786
  • 6
  • 17
  • i've tried that: `go build thingsToComposer.go apis/rtb.go jsondef/structures.go` returns `named files must all be in one directory; have ./ and apis/` and `go build ./thingsToComposer.go ./apis/rtb.go ./jsondef/structures.go` same error – Vieira Neto Manoel Apr 12 '18 at 19:16
  • Sorry @viera, my fault. In my experience, when there are dependencies between my packages, all packages rebuild if dirty when I rebuild my main. Could you provide us with the import statements from your files? – Slabgorb Apr 12 '18 at 20:09
  • 1
    of course! [thingsToComposer.go](https://gist.github.com/vieiramanoel/15e2edcb884e32bbf0b5af7a8d028270) [rtb.go](https://gist.github.com/vieiramanoel/0c2c872b7a32ea7328b255f9d39fbf1b) – Vieira Neto Manoel Apr 12 '18 at 20:15
  • 1
    ok, so the package inside 'jsondefs' is named : `structures` - I would recommend having the package name be the same as the folder name. TBH, not sure if this is the source of the problem, though – Slabgorb Apr 12 '18 at 20:43