Repository: goplus/gop
Pull request #1059 (2021-12-14 13:35:56)

remove env.BuildRevision


Patch:
diff --git a/cl/stmt.go b/cl/stmt.go
index 02b66f76..d8bc695a 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -81,9 +81,14 @@ func compileStmt(ctx *blockCtx, stmt ast.Stmt) {
 	commentStmt(ctx, stmt)
 	switch v := stmt.(type) {
 	case *ast.ExprStmt:
-		compileExpr(ctx, v.X)
-		if canAutoCall(v.X) && gox.IsFunc(ctx.cb.InternalStack().Get(-1).Type) {
+		if obj, ok := isBuiltinAutoCall(ctx, v.X); ok {
+			ctx.cb.Val(obj)
 			ctx.cb.Call(0)
+		} else {
+			compileExpr(ctx, v.X)
+			if canAutoCall(v.X) && gox.IsFunc(ctx.cb.InternalStack().Get(-1).Type) {
+				ctx.cb.Call(0)
+			}
 		}
 	case *ast.AssignStmt:
 		compileAssignStmt(ctx, v)
@@ -142,6 +147,19 @@ retry:
 	return false
 }
 
+func isBuiltinAutoCall(ctx *blockCtx, expr ast.Expr) (types.Object, bool) {
+	if ident, ok := expr.(*ast.Ident); ok {
+		switch ident.Name {
+		case "print", "println":
+			_, builtin := lookupType(ctx, ident.Name)
+			if isBuiltin(builtin) {
+				return builtin, true
+			}
+		}
+	}
+	return nil, false
+}
+
 func compileReturnStmt(ctx *blockCtx, expr *ast.ReturnStmt) {
 	var n = -1
 	var results *types.Tuple
diff --git a/cmd/internal/env/env.go b/cmd/internal/env/env.go
index bc502bab..020927e7 100644
--- a/cmd/internal/env/env.go
+++ b/cmd/internal/env/env.go
@@ -66,7 +66,6 @@ func runCmd(_ *base.Command, args []string) {
 	}
 
 	gopEnv["BUILDDATE"] = env.BuildDate()
-	gopEnv["BUILDREV"] = env.BuildRevision()
 	gopEnv["GOPVERSION"] = env.Version()
 	gopEnv["GOPROOT"] = env.GOPROOT()
 	gopEnv["GOPATH"] = env.GOPATH()
diff --git a/cmd/make.go b/cmd/make.go
index 7d8506d3..b510e7d2 100644
--- a/cmd/make.go
+++ b/cmd/make.go
@@ -109,6 +109,7 @@ func getRevCommit(tag string) string {
 	return strings.TrimRight(commit, "\n")
 }
 
+/*
 func getGitInfo() (string, bool) {
 	gitDir := filepath.Join(gopRoot, ".git")
 	if checkPathExist(gitDir, true) {
@@ -116,6 +117,7 @@ func getGitInfo() (string, bool) {
 	}
 	return "", false
 }
+*/
 
 func getBuildDateTime() string {
 	now := time.Now()
@@ -137,11 +139,8 @@ func getGopBuildFlags() string {
 	}
 	buildFlags := fmt.Sprintf("-X \"github.com/goplus/gop/env.defaultGopRoot=%s\"", defaultGopRoot)
 	buildFlags += fmt.Sprintf(" -X \"github.com/goplus/gop/env.buildDate=%s\"", getBuildDateTime())
-	if commit, ok := getGitInfo(); ok {
-		buildFlags += fmt.Sprintf(" -X github.com/goplus/gop/env.buildCommit=%s", commit)
-		if buildVer := getBuildVer(); buildVer != "" {
-			buildFlags += fmt.Sprintf(" -X github.com/goplus/gop/env.buildVersion=%s", buildVer)
-		}
+	if buildVer := getBuildVer(); buildVer != "" {
+		buildFlags += fmt.Sprintf(" -X github.com/goplus/gop/env.buildVersion=%s", buildVer)
 	}
 	return buildFlags
 }
diff --git a/env/build.go b/env/build.go
index 9b4e0d37..b7325414 100644
--- a/env/build.go
+++ b/env/build.go
@@ -17,17 +17,11 @@
 package env
 
 // The value of variables come form
-// `go build -ldflags '-X "buildDate=xxxxx" -X "buildCommit=xxxx"'`
+// `go build -ldflags '-X "buildDate=xxxxx"`
 var (
-	buildDate   string
-	buildCommit string
+	buildDate string
 )
 
 func BuildDate() string {
 	return buildDate
 }
-
-// BuildRevision returns build revision id.
-func BuildRevision() string {
-	return buildCommit
-}
diff --git a/x/gopmod/gocmd.go b/x/gopmod/gocmd.go
index b405ca85..7aa79f0a 100644
--- a/x/gopmod/gocmd.go
+++ b/x/gopmod/gocmd.go
@@ -30,23 +30,21 @@ import (
 const (
 	ldFlagVersion   = "-X \"github.com/goplus/gop/env.buildVersion=%s\""
 	ldFlagBuildDate = "-X \"github.com/goplus/gop/env.buildDate=%s\""
-	ldFlagBuildRev  = "-X \"github.com/goplus/gop/env.buildCommit=%s\""
 	ldFlagGopRoot   = "-X \"github.com/goplus/gop/env.defaultGopRoot=%s\""
 )
 
 const (
-	ldFlagAll = ldFlagVersion + " " + ldFlagBuildDate + " " + ldFlagBuildRev + " " + ldFlagGopRoot
+	ldFlagAll = ldFlagVersion + " " + ldFlagBuildDate + " " + ldFlagGopRoot
 )
 
 var (
 	GOPVERSION   = env.Version()
 	GOPBUILDDATE = env.BuildDate()
-	GOPBUILDREV  = env.BuildRevision()
 	GOPROOT      = env.GOPROOT()
 )
 
 func LoadFlags() string {
-	return fmt.Sprintf(ldFlagAll, GOPVERSION, GOPBUILDDATE, GOPBUILDREV, GOPROOT)
+	return fmt.Sprintf(ldFlagAll, GOPVERSION, GOPBUILDDATE, GOPROOT)
 }
 
 // -----------------------------------------------------------------------------


Test patch:
diff --git a/env/version_test.go b/env/version_test.go
index 20fb033b..5b51422d 100644
--- a/env/version_test.go
+++ b/env/version_test.go
@@ -30,9 +30,6 @@ func TestVersion(t *testing.T) {
 }
 
 func TestBuild(t *testing.T) {
-	if BuildRevision() != "" {
-		t.Fatal("BuildCommit failed:", BuildRevision())
-	}
 	if BuildDate() != "" {
 		t.Fatal("BuildInfo failed:", BuildDate())
 	}