Based on BUTXO Programming Language
修订版 | d5a12d46fbc37feafeed18deebe26e81f22f34af (tree) |
---|---|
时间 | 2019-03-15 14:45:50 |
作者 | oysheng <33340252+oysheng@user...> |
Commiter | Paladz |
@@ -1,19 +1,43 @@ | ||
1 | +ifndef GOOS | |
2 | + GOOS := linux | |
3 | +endif | |
4 | + | |
1 | 5 | 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 | |
2 | 15 | |
3 | -all: test equitycmd | |
16 | +equity: | |
17 | + @echo "Building equity to target/equity" | |
18 | + @go build $(BUILD_FLAGS) -o target/equity equity/main.go | |
4 | 19 | |
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 | |
8 | 33 | |
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 | |
12 | 37 | |
13 | 38 | 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." | |
17 | 41 | |
18 | 42 | test: |
19 | 43 | @echo "====> Running go test" |
@@ -21,4 +45,4 @@ test: | ||
21 | 45 | |
22 | 46 | ci: test |
23 | 47 | |
24 | -.PHONY: all clean test ci | |
48 | +.PHONY: all clean test ci cmd equity |
@@ -9,10 +9,10 @@ The equity compiler tool is the equity commandline compiler. | ||
9 | 9 | Build source code, the build target of the equity compiler commandline tool is `equity`. |
10 | 10 | |
11 | 11 | ```bash |
12 | -$ make tool | |
12 | +$ make equity | |
13 | 13 | ``` |
14 | 14 | |
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` : | |
16 | 16 | ```bash |
17 | 17 | $ cd equity |
18 | 18 | ``` |
@@ -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 | +} |
@@ -18,6 +18,7 @@ const ( | ||
18 | 18 | strShift string = "shift" |
19 | 19 | strInstance string = "instance" |
20 | 20 | strAst string = "ast" |
21 | + strVersion string = "version" | |
21 | 22 | ) |
22 | 23 | |
23 | 24 | var ( |
@@ -25,6 +26,7 @@ var ( | ||
25 | 26 | shift = false |
26 | 27 | instance = false |
27 | 28 | ast = false |
29 | + version = false | |
28 | 30 | ) |
29 | 31 | |
30 | 32 | func init() { |
@@ -32,6 +34,7 @@ func init() { | ||
32 | 34 | equityCmd.PersistentFlags().BoolVar(&shift, strShift, false, "Function shift of the contracts.") |
33 | 35 | equityCmd.PersistentFlags().BoolVar(&instance, strInstance, false, "Object of the Instantiated contracts.") |
34 | 36 | equityCmd.PersistentFlags().BoolVar(&ast, strAst, false, "AST of the contracts.") |
37 | + equityCmd.PersistentFlags().BoolVar(&version, strVersion, false, "Version of equity compiler.") | |
35 | 38 | } |
36 | 39 | |
37 | 40 | func main() { |
@@ -45,8 +48,14 @@ var equityCmd = &cobra.Command{ | ||
45 | 48 | Use: "equity <input_file>", |
46 | 49 | Short: "equity commandline compiler", |
47 | 50 | Example: "equity contract_name [contract_args...] --bin --instance", |
48 | - Args: cobra.RangeArgs(1, 100), | |
51 | + Args: cobra.RangeArgs(0, 100), | |
49 | 52 | 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 | + | |
50 | 59 | if len(args) < 1 { |
51 | 60 | cmd.Usage() |
52 | 61 | } |