OSDN Git Service

add release version (#35)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Fri, 15 Mar 2019 05:45:50 +0000 (13:45 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 15 Mar 2019 05:45:50 +0000 (13:45 +0800)
* add release version

* Makefile add release

Makefile
README.md
compiler/version.go [new file with mode: 0644]
equity/main.go

index 6ee8f39..924761a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,43 @@
+ifndef GOOS
+       GOOS := linux
+endif
+
 PACKAGES    := $(shell go list ./... | grep -v '/vendor/')
+BUILD_FLAGS := -ldflags "-X github.com/equity/compiler.GitCommit=`git rev-parse HEAD`"
+VERSION := $(shell awk -F= '/VersionMajor =/ {print $$2}' compiler/version.go | tr -d "\" ").$(shell awk -F= '/VersionMinor =/ {print $$2}' compiler/version.go | tr -d "\" ").$(shell awk -F= '/VersionPatch =/ {print $$2}' compiler/version.go | tr -d "\" ")
+EQUITY_RELEASE := equity-$(VERSION)-$(GOOS)
+
+all: test cmd equity
+
+cmd:
+       @echo "Building equitycmd to target/equitycmd"
+       @go build $(BUILD_FLAGS) -o target/equitycmd compiler/cmd/equitycmd/equitycmd.go
 
-all: test equitycmd
+equity:
+       @echo "Building equity to target/equity"
+       @go build $(BUILD_FLAGS) -o target/equity equity/main.go
 
-equitycmd:
-       @echo "Building equitycmd to compiler/cmd/equitycmd/equitycmd"
-       @go build -o compiler/cmd/equitycmd/equitycmd compiler/cmd/equitycmd/equitycmd.go
+ifeq ($(GOOS),windows)
+release: equity
+       cd target && cp -f equity $(EQUITY_RELEASE).exe
+       cd target && md5sum $(EQUITY_RELEASE).exe > $(EQUITY_RELEASE).md5
+       cd target && zip $(EQUITY_RELEASE).zip $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
+       cd target && rm -f $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
+else
+release: equity
+       cd target && cp -f equity $(EQUITY_RELEASE)
+       cd target && md5sum $(EQUITY_RELEASE) > $(EQUITY_RELEASE).md5
+       cd target && tar -czf $(EQUITY_RELEASE).tgz $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
+       cd target && rm -f $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
+endif
 
-tool:
-       @echo "Building equity to equity/equity"
-       @go build -o equity/equity equity/main.go
+release-all: clean
+       GOOS=linux   make release
+       GOOS=windows make release
 
 clean:
-       @echo "Cleaning binaries built..."
-       @rm -rf compiler/cmd/equitycmd/equitycmd
-       @echo "Done."
+       @rm -rf target
+       @echo "Cleaning target binaries successfully."
 
 test:
        @echo "====> Running go test"
@@ -21,4 +45,4 @@ test:
 
 ci: test
 
-.PHONY: all clean test ci
+.PHONY: all clean test ci cmd equity
index 1612435..0a3c6b5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,10 +9,10 @@ The equity compiler tool is the equity commandline compiler.
 Build source code, the build target of the equity compiler commandline tool is `equity`.
 
 ```bash
-$ make tool
+$ make equity
 ```
 
-then change directory to `equity`, and you can find the tool `equity` :
+then change directory to `equity`, and you can find the commandline tool `equity` :
 ```bash
 $ cd equity
 ```
diff --git a/compiler/version.go b/compiler/version.go
new file mode 100644 (file)
index 0000000..c2a6c92
--- /dev/null
@@ -0,0 +1,29 @@
+package compiler
+
+import "fmt"
+
+const (
+       // VersionMajor is the Major version component of the current release
+       VersionMajor = 0
+       // VersionMinor is the Minor version component of the current release
+       VersionMinor = 1
+       // VersionPatch is the Patch version component of the current release
+       VersionPatch = 1
+)
+
+// Git SHA1 commit hash of the release (set via linker flags)
+var GitCommit = ""
+
+// Version holds the textual version string.
+var Version = func() string {
+       return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
+}()
+
+// VersionWithCommit holds the textual version and the first 8 character of git commit.
+func VersionWithCommit(gitCommit string) string {
+       version := Version
+       if len(gitCommit) >= 8 {
+               version += "+" + gitCommit[:8]
+       }
+       return version
+}
index ecb9636..367e8bc 100644 (file)
@@ -18,6 +18,7 @@ const (
        strShift    string = "shift"
        strInstance string = "instance"
        strAst      string = "ast"
+       strVersion  string = "version"
 )
 
 var (
@@ -25,6 +26,7 @@ var (
        shift    = false
        instance = false
        ast      = false
+       version  = false
 )
 
 func init() {
@@ -32,6 +34,7 @@ func init() {
        equityCmd.PersistentFlags().BoolVar(&shift, strShift, false, "Function shift of the contracts.")
        equityCmd.PersistentFlags().BoolVar(&instance, strInstance, false, "Object of the Instantiated contracts.")
        equityCmd.PersistentFlags().BoolVar(&ast, strAst, false, "AST of the contracts.")
+       equityCmd.PersistentFlags().BoolVar(&version, strVersion, false, "Version of equity compiler.")
 }
 
 func main() {
@@ -45,8 +48,14 @@ var equityCmd = &cobra.Command{
        Use:     "equity <input_file>",
        Short:   "equity commandline compiler",
        Example: "equity contract_name [contract_args...] --bin --instance",
-       Args:    cobra.RangeArgs(1, 100),
+       Args:    cobra.RangeArgs(0, 100),
        Run: func(cmd *cobra.Command, args []string) {
+               if version {
+                       version := compiler.VersionWithCommit(compiler.GitCommit)
+                       fmt.Println("Version:", version)
+                       os.Exit(0)
+               }
+
                if len(args) < 1 {
                        cmd.Usage()
                }