• R/O
  • HTTP
  • SSH
  • HTTPS

equity: 提交

Based on BUTXO Programming Language


Commit MetaInfo

修订版d5a12d46fbc37feafeed18deebe26e81f22f34af (tree)
时间2019-03-15 14:45:50
作者oysheng <33340252+oysheng@user...>
CommiterPaladz

Log Message

add release version (#35)

* add release version

* Makefile add release

更改概述

差异

--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,43 @@
1+ifndef GOOS
2+ GOOS := linux
3+endif
4+
15 PACKAGES := $(shell go list ./... | grep -v '/vendor/')
6+BUILD_FLAGS := -ldflags "-X github.com/equity/compiler.GitCommit=`git rev-parse HEAD`"
7+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 "\" ")
8+EQUITY_RELEASE := equity-$(VERSION)-$(GOOS)
9+
10+all: test cmd equity
11+
12+cmd:
13+ @echo "Building equitycmd to target/equitycmd"
14+ @go build $(BUILD_FLAGS) -o target/equitycmd compiler/cmd/equitycmd/equitycmd.go
215
3-all: test equitycmd
16+equity:
17+ @echo "Building equity to target/equity"
18+ @go build $(BUILD_FLAGS) -o target/equity equity/main.go
419
5-equitycmd:
6- @echo "Building equitycmd to compiler/cmd/equitycmd/equitycmd"
7- @go build -o compiler/cmd/equitycmd/equitycmd compiler/cmd/equitycmd/equitycmd.go
20+ifeq ($(GOOS),windows)
21+release: equity
22+ cd target && cp -f equity $(EQUITY_RELEASE).exe
23+ cd target && md5sum $(EQUITY_RELEASE).exe > $(EQUITY_RELEASE).md5
24+ cd target && zip $(EQUITY_RELEASE).zip $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
25+ cd target && rm -f $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
26+else
27+release: equity
28+ cd target && cp -f equity $(EQUITY_RELEASE)
29+ cd target && md5sum $(EQUITY_RELEASE) > $(EQUITY_RELEASE).md5
30+ cd target && tar -czf $(EQUITY_RELEASE).tgz $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
31+ cd target && rm -f $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
32+endif
833
9-tool:
10- @echo "Building equity to equity/equity"
11- @go build -o equity/equity equity/main.go
34+release-all: clean
35+ GOOS=linux make release
36+ GOOS=windows make release
1237
1338 clean:
14- @echo "Cleaning binaries built..."
15- @rm -rf compiler/cmd/equitycmd/equitycmd
16- @echo "Done."
39+ @rm -rf target
40+ @echo "Cleaning target binaries successfully."
1741
1842 test:
1943 @echo "====> Running go test"
@@ -21,4 +45,4 @@ test:
2145
2246 ci: test
2347
24-.PHONY: all clean test ci
48+.PHONY: all clean test ci cmd equity
--- a/README.md
+++ b/README.md
@@ -9,10 +9,10 @@ The equity compiler tool is the equity commandline compiler.
99 Build source code, the build target of the equity compiler commandline tool is `equity`.
1010
1111 ```bash
12-$ make tool
12+$ make equity
1313 ```
1414
15-then change directory to `equity`, and you can find the tool `equity` :
15+then change directory to `equity`, and you can find the commandline tool `equity` :
1616 ```bash
1717 $ cd equity
1818 ```
--- /dev/null
+++ b/compiler/version.go
@@ -0,0 +1,29 @@
1+package compiler
2+
3+import "fmt"
4+
5+const (
6+ // VersionMajor is the Major version component of the current release
7+ VersionMajor = 0
8+ // VersionMinor is the Minor version component of the current release
9+ VersionMinor = 1
10+ // VersionPatch is the Patch version component of the current release
11+ VersionPatch = 1
12+)
13+
14+// Git SHA1 commit hash of the release (set via linker flags)
15+var GitCommit = ""
16+
17+// Version holds the textual version string.
18+var Version = func() string {
19+ return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
20+}()
21+
22+// VersionWithCommit holds the textual version and the first 8 character of git commit.
23+func VersionWithCommit(gitCommit string) string {
24+ version := Version
25+ if len(gitCommit) >= 8 {
26+ version += "+" + gitCommit[:8]
27+ }
28+ return version
29+}
--- a/equity/main.go
+++ b/equity/main.go
@@ -18,6 +18,7 @@ const (
1818 strShift string = "shift"
1919 strInstance string = "instance"
2020 strAst string = "ast"
21+ strVersion string = "version"
2122 )
2223
2324 var (
@@ -25,6 +26,7 @@ var (
2526 shift = false
2627 instance = false
2728 ast = false
29+ version = false
2830 )
2931
3032 func init() {
@@ -32,6 +34,7 @@ func init() {
3234 equityCmd.PersistentFlags().BoolVar(&shift, strShift, false, "Function shift of the contracts.")
3335 equityCmd.PersistentFlags().BoolVar(&instance, strInstance, false, "Object of the Instantiated contracts.")
3436 equityCmd.PersistentFlags().BoolVar(&ast, strAst, false, "AST of the contracts.")
37+ equityCmd.PersistentFlags().BoolVar(&version, strVersion, false, "Version of equity compiler.")
3538 }
3639
3740 func main() {
@@ -45,8 +48,14 @@ var equityCmd = &cobra.Command{
4548 Use: "equity <input_file>",
4649 Short: "equity commandline compiler",
4750 Example: "equity contract_name [contract_args...] --bin --instance",
48- Args: cobra.RangeArgs(1, 100),
51+ Args: cobra.RangeArgs(0, 100),
4952 Run: func(cmd *cobra.Command, args []string) {
53+ if version {
54+ version := compiler.VersionWithCommit(compiler.GitCommit)
55+ fmt.Println("Version:", version)
56+ os.Exit(0)
57+ }
58+
5059 if len(args) < 1 {
5160 cmd.Usage()
5261 }
Show on old repository browser