On Sun, Dec 17, 2017 at 7:11 PM, Ally  Dale <vipa...@gmail.com> wrote:
>
> Thanks a lot, but I tried to pass timestamp by
> "-X=runtime.buildtimestamp=xxxx" to linker, it fails with the same message.
> I guess the timestamp makes the dependence packages always STALE, maybe I
> have to check logic of command "go list".

Sorry, I did not mean to suggest that you use something like
-X=runtime.buildtimestamp.  I agree that that is problematic.  I meant
to suggest that you use the -X option to set a variable in your own
package, not in the runtime package.  There's no reason to add a
variable to the runtime package for this.

Ian


>
> 在 2017年12月16日星期六 UTC+8上午5:11:00,Ian Lance Taylor写道:
>>
>> On Fri, Dec 15, 2017 at 3:08 AM, Ally  Dale <vip...@gmail.com> wrote:
>> > Hi all,
>> > I just need a function to report the timestamp when my app compiled.
>> >
>> > func main() {
>> >
>> >
>> >         unix := runtime.BuildTimestamp()
>> >
>> >
>> >         t := time.Unix(unix, 0)
>> >
>> >
>> >         println("hello world")
>> >
>> >
>> >         println("buildtimestamp:", unix)
>> >
>> >
>> >         println("buildtime     :", t.String())
>> >
>> >
>> >         // Output:
>> >
>> >
>> >         // hello world
>> >
>> >
>> >         // buildtimestamp: 1513329454
>> >
>> >
>> >         // buildtime     : 2017-12-15 17:17:34 +0800 CST
>> >
>> >
>> > }
>> >
>> >
>> >
>> >
>> > [runtime.BuildTimestamp()](https://github.com/vipally/go/blob/ally_build_time/src/runtime/symtab.go#L399)
>> > use a variable defined in
>> >
>> > [runtime.firstmoduledata.buildtimestamp](https://github.com/vipally/go/blob/ally_build_time/src/runtime/symtab.go#L372)
>> > which will be written by
>> >
>> > [cmd/link](https://github.com/vipally/go/blob/ally_build_time/src/cmd/link/internal/ld/symtab.go#L562)
>> >
>> > My trouble is, if cmd/link use time.Now().Unix() to get unix timestamp,
>> > it
>> > will make a new dependence of time for cmd/link.
>> > And this dependence will cause a STALE error when go_bootstrap building.
>> > go tool dist: unexpected stale targets reported by
>> > E:\go\pkg\tool\windows_amd64\go_bootstrap list -gcflags="" -ldflags=""
>> > for [cmd/asm cmd/cgo cmd/compile cmd/link runtime/internal/sys]:
>> >         STALE cmd/asm: stale dependency: runtime/internal/atomic
>> >         STALE cmd/cgo: stale dependency: runtime/internal/atomic
>> >         STALE cmd/compile: stale dependency: runtime/internal/atomic
>> >         STALE cmd/link: stale dependency: runtime/internal/atomic
>> >         STALE runtime/internal/sys: build ID mismatch
>> >
>> >
>> > So, my question is, if I cannot use time.Now().Unix() or runtime.now()
>> > to
>> > get unix timestamp in cmd/link. How can I get unix timestamp in
>> > linker(cmd/link)?
>>
>> Use something like -ldflags=-X=`VAR=date`.  The -X option is
>> documented at https://golang.org/cmd/link.
>>
>> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to