Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAOS-15055 tools: Add build host/time to JSON version
Browse files Browse the repository at this point in the history
Include build timestamp in all builds. Only
include build host in non-release builds.

Change-Id: I2d5525c21da2537a9583e9dbd57265e34639913f
Required-githooks: true
Signed-off-by: Michael MacDonald <mjmac@google.com>
mjmac committed Jan 22, 2024
1 parent 6491317 commit 100014b
Showing 3 changed files with 34 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/control/SConscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Build DAOS Control Plane"""
# pylint: disable=too-many-locals
import os
import socket
from datetime import datetime, timezone
from binascii import b2a_hex
from os import urandom
from os.path import join
@@ -43,13 +45,19 @@ def gen_build_id():
return '0x' + buildid.decode()


def go_ldflags():
def go_ldflags(benv):
"Create the ldflags option for the Go build."

build_host = ''
if not is_release_build(benv):
build_host = socket.getfqdn()
build_time = datetime.now(timezone.utc).astimezone().isoformat()
Import('daos_version', 'conf_dir')
path = 'github.com/daos-stack/daos/src/control/build'
return ' '.join([f'-X {path}.DaosVersion={daos_version}',
f'-X {path}.ConfigDir={conf_dir}',
f'-X {path}.BuildTime={build_time}',
f'-X {path}.BuildHost={build_host}',
f'-B $({gen_build_id()}$)'])


@@ -72,7 +80,7 @@ def install_go_bin(env, name, libs=None, install_man=False):

target = env.d_run_command(name, sources, libs,
f'cd {gosrc}; {env.d_go_bin} build -mod vendor '
+ f'-ldflags "{go_ldflags()}" '
+ f'-ldflags "{go_ldflags(env)}" '
+ f'{get_build_flags(env)} '
+ f'{get_build_tags(env)} '
+ f'-o {build_bin} {install_src}')
28 changes: 18 additions & 10 deletions src/control/build/string.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"
)

func revString(version string) string {
@@ -41,17 +42,24 @@ func String(name string) string {
// MarshalJSON returns a JSON string containing a structured representation of
// the binary build info.
func MarshalJSON(name string) ([]byte, error) {
// Not a fatal error if the build time can't be parsed.
buildTime, _ := time.Parse(time.RFC3339, BuildTime)

return json.Marshal(&struct {
Name string `json:"name"`
Version string `json:"version"`
Revision string `json:"revision,omitempty"`
Dirty bool `json:"dirty,omitempty"`
Release bool `json:"release,omitempty"`
Name string `json:"name"`
Version string `json:"version"`
Revision string `json:"revision,omitempty"`
Dirty bool `json:"dirty,omitempty"`
Release bool `json:"release,omitempty"`
BuildHost string `json:"build_host,omitempty"`
BuildTime time.Time `json:"build_time,omitempty"`
}{
Name: name,
Version: DaosVersion,
Revision: Revision,
Dirty: DirtyBuild,
Release: ReleaseBuild,
Name: name,
Version: DaosVersion,
Revision: Revision,
Dirty: DirtyBuild,
Release: ReleaseBuild,
BuildHost: BuildHost,
BuildTime: buildTime,
})
}
8 changes: 6 additions & 2 deletions src/control/build/variables.go
Original file line number Diff line number Diff line change
@@ -11,9 +11,13 @@ import "time"

var (
// ConfigDir should be set via linker flag using the value of CONF_DIR.
ConfigDir string = "./"
ConfigDir = "./"
// DaosVersion should be set via linker flag using the value of DAOS_VERSION.
DaosVersion string = "unset"
DaosVersion = "unset"
// BuildTime should be set via linker flag using the value of BUILD_TIME.
BuildTime = ""
// BuildHost should be set via linker flag using the value of BUILD_HOST.
BuildHost = ""
// ControlPlaneName defines a consistent name for the control plane server.
ControlPlaneName = "DAOS Control Server"
// DataPlaneName defines a consistent name for the engine.

0 comments on commit 100014b

Please sign in to comment.