No. you will need other ways to embed timestamps in go binaries (using -ldflags -X).
On May 9, 2014 4:31 PM, "Hotei" <hote...@gmail.com> wrote:
>
> Marvin,
> You're right on both counts. :-( While the previous solution works for maybe 90% of my intended usage it is more fragile than I wished.
>
> On reflection, I decided on a slightly more complex strategy. I use makefiles to build so I can include go vet and gofmt all in one pass. I'll simply write a short program godatetime whose only function is to write something like this to stdout:
>
> package main
>
> var CompiledDate = 2014-04-09 (from time.Now() of course)
> var CompiledTime = 01:02:03
>
>
> Then I can use CompiledDate and CompiledTime inside the code I'm building.
instead of generating source file, why not use -ldflags -X? this way you don't need to recompile the package every time.
godoc cmd/ld has the documentation about -X.
On May 9, 2014 4:55 PM, "Hotei" <hote...@gmail.com> wrote:
>
> minux,
> Two reasons - primarily because I'm not familiar with the linker's operation, but also because I have the get the date / time strings from somewhere anyway. I'd need to generate the -X CompiledDate "date" and -X CompileTime "time" string values. While not a showstopper it's a two shell calls to extract them and save as variables in the makefile.
it's as simple as this:
// main.go
package main
var buildtime string
// ....
go build -ldflags "-X main.buildtime '`date`'"
actually much simpler than generating a new source file.
On May 9, 2014 8:16 PM, "Ian Dawes" <i...@dawesnet.net> wrote:
> I think it might be worth noting that embedding the compile time into the executable removes your ability to produce 100% reproducible builds without messing with your system clock.
embedding the build time and 100% reproducible builds are fundamentally incompatible goals.
the alternative is perhaps embedding the source code revision into the binary. and i think that makes more sense if you also want reproducible builds.
I'm curious why you want the compile time in there and not a timestamp of the last code change. If you compile the exact same code a week apart, why does the timestamp need to change? Wouldn't it be more useful if the second time you compiled that it was clear that the code is the same as the first time? Otherwise the second time you compile, it'll look like it's a new binary, even though it's exactly the same code as the previous build, which could be confusing.