Skip to content

#44 Display build information #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
#44 Display build information
  • Loading branch information
kislenko-artem committed Jan 23, 2019
commit e01c60aa80362edae82b7faf9d70af42f79eb8aa
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This how we want to name the binary output
BINARY=gpython

# These are the values we want to pass for VERSION and BUILD
# git tag 1.0.1
# git commit -am "One more change after the tags"
VERSION=`git describe --abbrev=0 --tags`
DATE=`date +%FT%T%z`
COMMIT=`git rev-parse --verify HEAD`

# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-w -s -X main.version=${VERSION} -X main.date=${DATE} -X main.commit=${COMMIT}"

# Builds the project
build:
go build ${LDFLAGS} -o ${BINARY}

# Installs our project: copies binaries
install:
go install ${LDFLAGS}

# Cleans our project: deletes binaries
clean:
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi

.PHONY: clean install
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
args := flag.Args()
py.MustGetModule("sys").Globals["argv"] = pysys.MakeArgv(args)
if len(args) == 0 {
cli.RunREPL()
cli.RunREPL(version, commit, date)
return
}
prog := args[0]
Expand Down
9 changes: 6 additions & 3 deletions repl/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"

"github.com/go-python/gpython/py"
"github.com/go-python/gpython/repl"
Expand Down Expand Up @@ -119,7 +120,7 @@ func (rl *readline) Print(out string) {
}

// RunREPL starts the REPL loop
func RunREPL() {
func RunREPL(version, commit, date string) {
repl := repl.New()
rl := newReadline(repl)
repl.SetUI(rl)
Expand All @@ -129,8 +130,10 @@ func RunREPL() {
fmt.Printf("Failed to open history: %v\n", err)
}

fmt.Printf("Gpython 3.4.0\n")

fmt.Printf("Python 3.4.0 (%s, %s)\n", commit, date)
fmt.Printf("[Gpython %s]\n", version)
fmt.Printf("- os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("- go version: %s\n", runtime.Version())
for {
line, err := rl.Prompt(rl.prompt)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

var (
version = "dev"
commit = "none"
date = "unknown"
)