From 16ab40f44d79ea3a0cebfee77a609f7c3c798a28 Mon Sep 17 00:00:00 2001 From: Bazaah Date: Fri, 9 Dec 2022 12:38:58 +0000 Subject: [PATCH] buildinfo: compile time variables These expose entrypoints for -ldflag injections at compile time, containing metadata about build env + SCM --- buildinfo/build.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 buildinfo/build.go diff --git a/buildinfo/build.go b/buildinfo/build.go new file mode 100644 index 0000000..d5ff320 --- /dev/null +++ b/buildinfo/build.go @@ -0,0 +1,46 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package build + +import ( + "strings" + + "golang.org/x/exp/slices" +) + +var ( + // Git tag of this binary + Version = "v0.0.0+devel" + // Git hash of this binary + CommitHash = "0000000000000000000000000000000000000000" + // Enabled features of this binary + Features = "" + + knownFeatures = map[string]bool{} +) + +// Get the short Git hash +func ShortHash() string { + return CommitHash[:7] +} + +// Get list of features enabled +func FeaturesList() []string { + out := []string{} + active := strings.Split(Features, ",") + + for feature, _ := range knownFeatures { + sy := "-" + if slices.Contains(active, feature) { + sy = "+" + } + out = append(out, sy+feature) + } + slices.Sort(out) + + return out +}