Add build time, hash and version info to binaries
Add urfave/cli to the doodle.exe binary to add a --version command. Both
doodle.exe and doodad.exe will now print their git commit hash and build
date along with their version number when asked.
% ./bin/doodle --version
doodle version 0.0.7-alpha build a316baf
. Built on 2018-12-30T14:44:43-08:00
This commit is contained in:
parent
a316bafb12
commit
f473609bb5
3
Makefile
3
Makefile
|
@ -2,10 +2,11 @@ SHELL := /bin/bash
|
||||||
|
|
||||||
VERSION=$(shell grep -e 'Version' doodle.go | head -n 1 | cut -d '"' -f 2)
|
VERSION=$(shell grep -e 'Version' doodle.go | head -n 1 | cut -d '"' -f 2)
|
||||||
BUILD=$(shell git describe --always)
|
BUILD=$(shell git describe --always)
|
||||||
|
BUILD_DATE=$(shell date -Iseconds)
|
||||||
CURDIR=$(shell curdir)
|
CURDIR=$(shell curdir)
|
||||||
|
|
||||||
# Inject the build version (commit hash) into the executable.
|
# Inject the build version (commit hash) into the executable.
|
||||||
LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
|
LDFLAGS := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE)"
|
||||||
|
|
||||||
# `make setup` to set up a new environment, pull dependencies, etc.
|
# `make setup` to set up a new environment, pull dependencies, etc.
|
||||||
.PHONY: setup
|
.PHONY: setup
|
||||||
|
|
|
@ -11,10 +11,10 @@ import (
|
||||||
|
|
||||||
"image/png"
|
"image/png"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle"
|
|
||||||
"git.kirsle.net/apps/doodle/doodads"
|
|
||||||
"git.kirsle.net/apps/doodle/level"
|
|
||||||
"git.kirsle.net/apps/doodle/lib/render"
|
"git.kirsle.net/apps/doodle/lib/render"
|
||||||
|
"git.kirsle.net/apps/doodle/src"
|
||||||
|
"git.kirsle.net/apps/doodle/src/doodads"
|
||||||
|
"git.kirsle.net/apps/doodle/src/level"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"golang.org/x/image/bmp"
|
"golang.org/x/image/bmp"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,22 +2,38 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle"
|
|
||||||
"git.kirsle.net/apps/doodle/cmd/doodad/commands"
|
"git.kirsle.net/apps/doodle/cmd/doodad/commands"
|
||||||
|
"git.kirsle.net/apps/doodle/src"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Build = "N/A"
|
// Build number is the git commit hash.
|
||||||
|
var (
|
||||||
|
Build = "<dynamic>"
|
||||||
|
BuildDate string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if BuildDate == "" {
|
||||||
|
BuildDate = time.Now().Format(time.RFC3339)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "doodad"
|
app.Name = "doodad"
|
||||||
app.Usage = "command line interface for Doodle"
|
app.Usage = "command line interface for Doodle"
|
||||||
app.Version = doodle.Version + " build " + Build
|
app.Version = fmt.Sprintf("%s build %s. Built on %s",
|
||||||
|
doodle.Version,
|
||||||
|
Build,
|
||||||
|
BuildDate,
|
||||||
|
)
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
|
|
|
@ -1,59 +1,101 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/lib/render/sdl"
|
"git.kirsle.net/apps/doodle/lib/render/sdl"
|
||||||
"git.kirsle.net/apps/doodle/src"
|
"git.kirsle.net/apps/doodle/src"
|
||||||
"git.kirsle.net/apps/doodle/src/balance"
|
"git.kirsle.net/apps/doodle/src/balance"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Build number is the git commit hash.
|
// Build number is the git commit hash.
|
||||||
var Build string
|
|
||||||
|
|
||||||
// Command line args
|
|
||||||
var (
|
var (
|
||||||
debug bool
|
Build = "<dynamic>"
|
||||||
edit bool
|
BuildDate string
|
||||||
guitest bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&debug, "debug", false, "Debug mode")
|
if BuildDate == "" {
|
||||||
flag.BoolVar(&edit, "edit", false, "Edit the map given on the command line. Default is to play the map.")
|
BuildDate = time.Now().Format(time.RFC3339)
|
||||||
flag.BoolVar(&guitest, "guitest", false, "Enter the GUI Test scene.")
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
args := flag.Args()
|
app := cli.NewApp()
|
||||||
var filename string
|
app.Name = "doodle"
|
||||||
if len(args) > 0 {
|
app.Usage = "command line interface for Doodle"
|
||||||
filename = args[0]
|
app.Version = fmt.Sprintf("%s build %s. Built on %s",
|
||||||
}
|
doodle.Version,
|
||||||
|
Build,
|
||||||
// SDL engine.
|
BuildDate,
|
||||||
engine := sdl.New(
|
|
||||||
"Doodle v"+doodle.Version,
|
|
||||||
balance.Width,
|
|
||||||
balance.Height,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
app := doodle.New(debug, engine)
|
app.Flags = []cli.Flag{
|
||||||
app.SetupEngine()
|
cli.BoolFlag{
|
||||||
if guitest {
|
Name: "debug, d",
|
||||||
app.Goto(&doodle.GUITestScene{})
|
Usage: "enable debug level logging",
|
||||||
} else if filename != "" {
|
},
|
||||||
if edit {
|
cli.BoolFlag{
|
||||||
app.EditFile(filename)
|
Name: "edit, e",
|
||||||
} else {
|
Usage: "edit the map given on the command line (instead of play it)",
|
||||||
app.PlayLevel(filename)
|
},
|
||||||
}
|
cli.BoolFlag{
|
||||||
|
Name: "guitest",
|
||||||
|
Usage: "enter the GUI Test scene on startup",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Action = func(c *cli.Context) error {
|
||||||
|
if c.Bool("version") {
|
||||||
|
fmt.Printf("This is Project Doodle, v%s build %s ",
|
||||||
|
doodle.Version,
|
||||||
|
Build,
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var filename string
|
||||||
|
if c.NArg() > 0 {
|
||||||
|
filename = c.Args().Get(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDL engine.
|
||||||
|
engine := sdl.New(
|
||||||
|
"Doodle v"+doodle.Version,
|
||||||
|
balance.Width,
|
||||||
|
balance.Height,
|
||||||
|
)
|
||||||
|
|
||||||
|
game := doodle.New(c.Bool("debug"), engine)
|
||||||
|
game.SetupEngine()
|
||||||
|
if c.Bool("guitest") {
|
||||||
|
game.Goto(&doodle.GUITestScene{})
|
||||||
|
} else if filename != "" {
|
||||||
|
if c.Bool("edit") {
|
||||||
|
game.EditFile(filename)
|
||||||
|
} else {
|
||||||
|
game.PlayLevel(filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
game.Run()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(cli.FlagsByName(app.Flags))
|
||||||
|
sort.Sort(cli.CommandsByName(app.Commands))
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
app.Run()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/userdir"
|
|
||||||
"git.kirsle.net/apps/doodle/lib/render"
|
"git.kirsle.net/apps/doodle/lib/render"
|
||||||
|
"git.kirsle.net/apps/doodle/pkg/userdir"
|
||||||
"golang.org/x/image/bmp"
|
"golang.org/x/image/bmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/lib/render"
|
"git.kirsle.net/apps/doodle/lib/render"
|
||||||
|
"git.kirsle.net/apps/doodle/lib/ui"
|
||||||
"git.kirsle.net/apps/doodle/src/balance"
|
"git.kirsle.net/apps/doodle/src/balance"
|
||||||
"git.kirsle.net/apps/doodle/src/events"
|
"git.kirsle.net/apps/doodle/src/events"
|
||||||
"git.kirsle.net/apps/doodle/lib/ui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GUITestScene implements the main menu of Doodle.
|
// GUITestScene implements the main menu of Doodle.
|
||||||
|
|
|
@ -2,9 +2,9 @@ package doodle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kirsle.net/apps/doodle/lib/render"
|
"git.kirsle.net/apps/doodle/lib/render"
|
||||||
|
"git.kirsle.net/apps/doodle/lib/ui"
|
||||||
"git.kirsle.net/apps/doodle/src/balance"
|
"git.kirsle.net/apps/doodle/src/balance"
|
||||||
"git.kirsle.net/apps/doodle/src/events"
|
"git.kirsle.net/apps/doodle/src/events"
|
||||||
"git.kirsle.net/apps/doodle/lib/ui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MainScene implements the main menu of Doodle.
|
// MainScene implements the main menu of Doodle.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user