-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAOS-13471 control: Add structured version info to utilities
Allow consumers to grab structured build/version information. Centralizes JSON output logic to a single implementation in the cmdutil package. Includes updates to control/version.py to use the structured version information instead of scraping stdout. Includes changes made for DAOS-13236 to include build info in version output and DAOS-13878 to install golang >= 1.18 as a daos-tests dependency. Required-githooks: true Signed-off-by: Michael MacDonald <mjmac.macdonald@intel.com>
- Loading branch information
Showing
42 changed files
with
545 additions
and
478 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
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
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
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,39 @@ | ||
// | ||
// (C) Copyright 2023 Intel Corporation. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
// | ||
|
||
//go:build go1.18 | ||
|
||
package build | ||
|
||
import ( | ||
"runtime/debug" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func init() { | ||
info, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return | ||
} | ||
|
||
for _, setting := range info.Settings { | ||
switch setting.Key { | ||
case "vcs": | ||
VCS = setting.Value | ||
case "vcs.revision": | ||
Revision = setting.Value | ||
case "vcs.modified": | ||
DirtyBuild = setting.Value == "true" | ||
case "vcs.time": | ||
LastCommit, _ = time.Parse(time.RFC3339, setting.Value) | ||
case "-tags": | ||
if strings.Contains(setting.Value, "release") { | ||
ReleaseBuild = true | ||
} | ||
} | ||
} | ||
} |
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,57 @@ | ||
// | ||
// (C) Copyright 2023 Intel Corporation. | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
// | ||
|
||
package build | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func revString(version string) string { | ||
if ReleaseBuild { | ||
return version | ||
} | ||
|
||
revParts := []string{version} | ||
if Revision != "" { | ||
switch VCS { | ||
case "git": | ||
revParts = append(revParts, fmt.Sprintf("g%7s", Revision)[0:7]) | ||
default: | ||
revParts = append(revParts, Revision) | ||
} | ||
if DirtyBuild { | ||
revParts = append(revParts, "dirty") | ||
} | ||
} | ||
return strings.Join(revParts, "-") | ||
} | ||
|
||
// String returns a string containing the name, version, and for non-release builds, | ||
// the revision of the binary. | ||
func String(name string) string { | ||
return fmt.Sprintf("%s version %s", name, revString(DaosVersion)) | ||
} | ||
|
||
// MarshalJSON returns a JSON string containing a structured representation of | ||
// the binary build info. | ||
func MarshalJSON(name string) ([]byte, error) { | ||
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: name, | ||
Version: DaosVersion, | ||
Revision: Revision, | ||
Dirty: DirtyBuild, | ||
Release: ReleaseBuild, | ||
}) | ||
} |
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
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
Oops, something went wrong.