forked from bazelbuild/rules_go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the stamp attribute is true in go_binary, bazel-out/volatile-status.txt and stable-status.txt will be concatenated and written into the binary using a -X linker flag. Developers can access stamp information by adding a dependency on @io_bazel_rules_go//buildstamp:go_default_library. Fixes bazelbuild#233
- Loading branch information
Jay Conrod
committed
Feb 15, 2017
1 parent
bfa3601
commit b5dd879
Showing
4 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("//go:def.bzl", "go_library", "go_prefix") | ||
|
||
go_prefix("github.com/bazelbuild/rules_go") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = glob(["*.go"]), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package buildstamp | ||
|
||
import "strings" | ||
|
||
var rawStampData string | ||
var stampData map[string]string | ||
|
||
func init() { | ||
if len(rawStampData) > 0 { | ||
stampData = make(map[string]string) | ||
for _, line := range strings.Split(rawStampData, "\n") { | ||
line = strings.TrimSpace(line) | ||
if len(line) == 0 || strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
var key, value string | ||
if space := strings.IndexAny(line, " \t"); space == -1 { | ||
key = line | ||
} else { | ||
key = line[:space] | ||
value = strings.TrimSpace(line[space+1:]) | ||
} | ||
stampData[key] = value | ||
} | ||
} | ||
} | ||
|
||
func HaveStampData() bool { | ||
return stampData != nil | ||
} | ||
|
||
func RawStampData() string { | ||
return rawStampData | ||
} | ||
|
||
func GetStampKeys() []string { | ||
if stampData == nil { | ||
return nil | ||
} | ||
keys := make([]string, 0, len(stampData)) | ||
for k, _ := range stampData { | ||
keys = append(keys, k) | ||
} | ||
return keys | ||
} | ||
|
||
func GetStampValue(key string) (value string, ok bool) { | ||
if stampData == nil { | ||
return "", false | ||
} | ||
value, ok = stampData[key] | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters