]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: add -buildid flag to write build ID into object file
authorRuss Cox <rsc@golang.org>
Mon, 20 Apr 2015 03:56:30 +0000 (23:56 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 3 Jun 2015 20:43:51 +0000 (20:43 +0000)
The build ID is an opaque token supplied by the build system.
The compiler writes it out early in the Go export metadata
(the second line), in a way that does not bother existing readers.

The intent is that the go command can use this to store information
about the sources for the generated code, so that it can detect
stale packages even in cases (like removed files) where mtimes fail.

Change-Id: Ib5082515d6cde8a07a8d4b5c69d1e8e4190cb5e1
Reviewed-on: https://go-review.googlesource.com/9153
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/lex.go

index 0d64fdb5f09a50061b143251f767df476f66bcd7..1043a7edbf8a98865a17c3be6969b546b1b18b12 100644 (file)
@@ -361,6 +361,9 @@ func dumpsym(s *Sym) {
 func dumpexport() {
        lno := lineno
 
+       if buildid != "" {
+               fmt.Fprintf(bout, "build id %q\n", buildid)
+       }
        fmt.Fprintf(bout, "\n$$\npackage %s", localpkg.Name)
        if safemode != 0 {
                fmt.Fprintf(bout, " safe")
index 93e405dbad959368afdc3c9b2c0ff7a0806c54a7..f79c199258d6c21b1730fe1efba929a31a83456f 100644 (file)
@@ -28,11 +28,12 @@ var yylast int
 
 var imported_unsafe int
 
-var goos string
-
-var goarch string
-
-var goroot string
+var (
+       goos    string
+       goarch  string
+       goroot  string
+       buildid string
+)
 
 var (
        Debug_wb     int
@@ -203,6 +204,7 @@ func Main() {
        obj.Flagfn0("V", "print compiler version", doversion)
        obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
        obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr)
+       obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid)
        obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
        obj.Flagstr("d", "print debug information about items in `list`", &debugstr)
        obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])