Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions buffalo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,3 @@ Buffalo helps you to generate a web project that already has everything from fro
Buffalo **isn't just a framework**, it's a holistic web development environment and project structure that **lets developers get straight to the business** of, well, building their business.
*/
package buffalo

// we need to import the runtime package
// as its needed by `buffalo build` and without
// this import the package doesn't get vendored
// by go mod vendor or by dep. this import fixes
// this problem.
import _ "github.com/gobuffalo/buffalo/runtime" // Load the runtime package variables
97 changes: 86 additions & 11 deletions runtime/build.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,113 @@
// Deprecated: This package is deprecated and will be removed in a future version.
// Use runtime/debug.ReadBuildInfo() directly instead.
//
// This package previously provided build information for buffalo applications.
// Starting with Go 1.18, the standard library's runtime/debug package provides
// equivalent functionality through ReadBuildInfo(), which includes VCS information
// (commit hash, time) and module version.
//
// Migration example:
//
// import "runtime/debug"
//
// info, ok := debug.ReadBuildInfo()
// if ok {
// // Use info.Main.Version for version
// // Use info.Settings for VCS info (vcs.revision, vcs.time)
// }
//
// For applications built with "buffalo build", build information is now
// automatically embedded by Go's build system and can be accessed via
// runtime/debug.ReadBuildInfo().
package runtime

import (
"fmt"
"runtime/debug"
"sync"
"time"
)

// BuildInfo holds information about the build
// Version is the current version of the buffalo binary.
// Deprecated: Use runtime/debug.ReadBuildInfo().Main.Version instead.
var Version = "dev"

// BuildInfo holds information about the build.
// Deprecated: Use runtime/debug.BuildInfo instead.
type BuildInfo struct {
Version string `json:"version"`
Time time.Time `json:"-"`
}

// String implements fmt.String
// String implements fmt.Stringer
func (b BuildInfo) String() string {
return fmt.Sprintf("%s (%s)", b.Version, b.Time)
if b.Time.IsZero() {
return b.Version
}
return b.Version + " (" + b.Time.Format(time.RFC3339) + ")"
}

var build = BuildInfo{
Version: "",
Time: time.Time{},
}
var (
build BuildInfo
once sync.Once
)

// Build returns the information about the current build
// of the application. In development mode this will almost
// always run zero values for BuildInfo.
// Build returns the information about the current build of the application.
// In development mode this will almost always return zero values for BuildInfo.
//
// Deprecated: Use runtime/debug.ReadBuildInfo() instead. This function now
// returns information derived from the standard library's build info.
//
// For backward compatibility, this function caches the build info after first call.
func Build() BuildInfo {
once.Do(func() {
build = loadBuildInfo()
})
return build
}

// loadBuildInfo reads build information from runtime/debug and converts it
// to the legacy BuildInfo format for backward compatibility.
func loadBuildInfo() BuildInfo {
info, ok := debug.ReadBuildInfo()
if !ok {
return BuildInfo{
Version: "dev",
Time: time.Time{},
}
}

bi := BuildInfo{
Version: info.Main.Version,
Time: time.Time{},
}

// Handle development builds
if bi.Version == "" || bi.Version == "(devel)" {
bi.Version = "dev"
}

// Try to extract build time from VCS info
for _, setting := range info.Settings {
if setting.Key == "vcs.time" {
if t, err := time.Parse(time.RFC3339, setting.Value); err == nil {
bi.Time = t
}
break
}
}

return bi
}

var so sync.Once

// SetBuild allows the setting of build information only once.
// This is typically managed by the binary built by `buffalo build`.
//
// Deprecated: This function is no longer necessary. Build information is now
// automatically embedded by the Go toolchain and can be accessed via
// runtime/debug.ReadBuildInfo(). This function is kept for backward compatibility
// but has no effect when called after Build() has been called.
func SetBuild(b BuildInfo) {
so.Do(func() {
build = b
Expand Down
4 changes: 0 additions & 4 deletions runtime/version.go

This file was deleted.

Loading