Repository: goplus/gop
Pull request #994 (2021-12-01 00:35:57)

gopmod.IsDirty


Patch:
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index b541ff26..00000000
--- a/.gitattributes
+++ /dev/null
@@ -1,5 +0,0 @@
-*.expect text eol=lf
-*.golden text eol=lf
-
-*.gop text eol=lf
-*.go text eol=lf
\ No newline at end of file
diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml
deleted file mode 100644
index f2406b3b..00000000
--- a/.github/workflows/release-build.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-name: Release Build
-
-on:
-  push:
-    tags:
-      - "v*.*.*"
-
-jobs:
-  build:
-    runs-on: ubuntu-latest
-    steps:
-    - uses: actions/checkout@v2
-
-    - name: Checkout tag
-      run: |
-        git fetch --depth=1 origin +refs/tags/*:refs/tags/*
-        tag_name="${GITHUB_REF##*/}"
-        echo Current tag: $tag_name
-        git checkout $tag_name
-        echo "TAG_NAME=${tag_name}" >> $GITHUB_ENV
-
-    - name: Set up Go
-      uses: actions/setup-go@v2
-      with:
-        go-version: 1.17
-
-    - name: Build
-      run: |
-        make release-all -j$(nproc)
-
-    - name: Release
-      uses: svenstaro/upload-release-action@v2
-      with:
-        repo_token: ${{ secrets.GITHUB_TOKEN }}
-        tag: ${{ env.TAG_NAME }}
-        file: ./gop-*.zip
-        file_glob: true
-        prerelease: true
\ No newline at end of file
diff --git a/Makefile b/Makefile
deleted file mode 100644
index bce14f8a..00000000
--- a/Makefile
+++ /dev/null
@@ -1,119 +0,0 @@
-NAME := gop
-PACKAGE_NAME := github.com/goplus/gop
-RELEASE_VERSION := `git describe --tags`
-COMMIT := `git rev-parse --short HEAD`
-BUILD_DATE := `date -u +"%Y-%m-%d_%H-%M-%S"`
-
-PLATFORM := linux
-BUILD_DIR=.
-BUILD_ROOT_DIR := build-dir
-BUILD_LDFLAGS := -X 'github.com/goplus/gop/env.buildDate=$(BUILD_DATE)'
-BUILD_LDFLAGS +=  -X '$(PACKAGE_NAME).buildCommit=$(COMMIT)'
-BUILD_LDFLAGS +=  -X '$(PACKAGE_NAME).buildVersion=$(RELEASE_VERSION)'
-
-EXE_SUFFIX=
-
-.PHONY: clean all
-all:
-	cd cmd; go install -v ./...
-
-clean:
-	rm -rf $(BUILD_ROOT_DIR)
-	rm -f *.zip
-	rm -f gop gopfmt
-
-
-release:
-  # the release action expects the generated binaries placed in the path where make runs.
-  # Refer: https://github.com/marketplace/actions/go-release-binaries
-	CGO_ENABLED=0 go build -o $(BUILD_DIR)/gop$(EXE_SUFFIX) -ldflags "$(BUILD_LDFLAGS)" github.com/goplus/gop/cmd/gop
-	CGO_ENABLED=0 go build -o $(BUILD_DIR)/gopfmt$(EXE_SUFFIX) -ldflags "$(BUILD_LDFLAGS)" github.com/goplus/gop/cmd/gopfmt
-
-gop:
-	mkdir -p $(BUILD_DIR)
-	$(MAKE) release
-
-release-all: darwin-amd64.zip darwin-arm64.zip linux-386.zip linux-amd64.zip \
-	linux-arm.zip linux-armv5.zip linux-armv6.zip linux-armv7.zip linux-armv8.zip \
-	linux-mips-softfloat.zip linux-mips-hardfloat.zip linux-mipsle-softfloat.zip linux-mipsle-hardfloat.zip \
-	linux-mips64.zip linux-mips64le.zip freebsd-386.zip freebsd-amd64.zip \
-	windows-386.zip windows-amd64.zip windows-arm.zip windows-armv6.zip windows-armv7.zip windows-arm64.zip
-
-%.zip: %
-	@echo "Building $(NAME)-$(RELEASE_VERSION)-$@"
-	@mkdir -p $(BUILD_ROOT_DIR)/$</bin
-	
-	@rm -f $(NAME)-$(RELEASE_VERSION)-$@
-	@cd $(BUILD_ROOT_DIR)/$</ && zip -r ../../$(NAME)-$(RELEASE_VERSION)-$@ bin
-	@zip -dur $(NAME)-$(RELEASE_VERSION)-$@ builtin go.mod go.sum LICENSE README*.md
-	@echo "$(NAME)-$(RELEASE_VERSION)-$@ Done"
-	
-
-darwin-amd64:
-	$(MAKE) GOARCH=amd64 GOOS=darwin BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-darwin-arm64:
-	$(MAKE) GOARCH=arm64 GOOS=darwin BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-386:
-	$(MAKE) GOARCH=386 GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-amd64:
-	$(MAKE) GOARCH=amd64 GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-arm:
-	$(MAKE) GOARCH=arm GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-armv5:
-	$(MAKE) GOARCH=arm GOOS=linux GOARM=5 BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-armv6:
-	$(MAKE) GOARCH=arm GOOS=linux GOARM=6 BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-armv7:
-	$(MAKE) GOARCH=arm GOOS=linux GOARM=7 BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-armv8:
-	$(MAKE) GOARCH=arm64 GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mips-softfloat:
-	$(MAKE) GOARCH=mips GOMIPS=softfloat GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mips-hardfloat:
-	$(MAKE) GOARCH=mips GOMIPS=hardfloat GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mipsle-softfloat:
-	$(MAKE) GOARCH=mipsle GOMIPS=softfloat GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mipsle-hardfloat:
-	$(MAKE) GOARCH=mipsle GOMIPS=hardfloat GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mips64:
-	$(MAKE) GOARCH=mips64 GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-linux-mips64le:
-	$(MAKE) GOARCH=mips64le GOOS=linux BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-freebsd-386:
-	$(MAKE) GOARCH=386 GOOS=freebsd BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-freebsd-amd64:
-	$(MAKE) GOARCH=amd64 GOOS=freebsd BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-386:
-	$(MAKE) GOARCH=386 GOOS=windows EXE_SUFFIX=.exe BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-amd64:
-	$(MAKE) GOARCH=amd64 GOOS=windows EXE_SUFFIX=.exe BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-arm:
-	$(MAKE) GOARCH=arm GOOS=windows EXE_SUFFIX=.exe BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-armv6:
-	$(MAKE) GOARCH=arm GOOS=windows EXE_SUFFIX=.exe GOARM=6 BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-armv7:
-	$(MAKE) GOARCH=arm GOOS=windows EXE_SUFFIX=.exe GOARM=7 BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
-
-windows-arm64:
-	$(MAKE) GOARCH=arm64 GOOS=windows EXE_SUFFIX=.exe BUILD_DIR=$(BUILD_ROOT_DIR)/$@/bin release
\ No newline at end of file
diff --git a/README.md b/README.md
index 6df130a6..369fcfdd 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ For now, we suggest you install Go+ from source code.
 git clone https://github.com/goplus/gop.git
 cd gop
 
-# On mac/linux run:
+# On linux run:
 ./all.bash
 # On Windows run:
 all.bat
diff --git a/README_zh.md b/README_zh.md
index 93c1f8a0..03734118 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -7,11 +7,11 @@
 [![Tutorials](https://img.shields.io/badge/tutorial-Go+-blue.svg)](https://tutorial.goplus.org/)
 [![Playground](https://img.shields.io/badge/playground-Go+-blue.svg)](https://play.goplus.org/)
 [![VSCode](https://img.shields.io/badge/vscode-Go+-teal.svg)](https://github.com/gopcode/vscode-goplus)
-[![Readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87-teal.svg)](https://github.com/goplus/gop/blob/main/README.md)
+[![Readme](https://img.shields.io/badge/README-%E4%B8%AD%E6%96%87-teal.svg)](https://github.com/goplus/gop/blob/main/README_zh.md)
 
--   **对于工程领域而言** ：意味着大家将会使用一门简单、易学、好用的编程语言。
--   **对于 STEM 教育而言** ：掌握一门可能会在将来工作中用到的工程语言将大有裨益。
--   **对于数据科学家而言** ：意味着你们将和工程师使用同一种语言进行合作和交流。
+* **对于工程领域而言** ：意味着大家将会使用一门简单、易学、好用的编程语言。
+* **对于 STEM 教育而言** ：掌握一门可能会在将来工作中用到的工程语言将大有裨益。
+* **对于数据科学家而言** ：意味着你们将和工程师使用同一种语言进行合作和交流。
 
 ## 如何安装 Go+?
 
@@ -20,15 +20,9 @@
 ```bash
 git clone https://github.com/goplus/gop.git
 cd gop
-
-# On linux run:
 ./all.bash
-# On Windows run:
-all.bat
 ```
 
-实际上， `all.bash` 和 `all.bat` 内部都会执行 `go run cmd/install.go`
-
 ## 代码风格（很重要）
 
 -   [https://tutorial.goplus.org/hello-world](https://tutorial.goplus.org/hello-world)
@@ -39,7 +33,7 @@ all.bat
 
 -   一种静态类型语言。
 -   完全兼容 [Go 语言](https://github.com/golang/go) 。
--   类似脚本语言的风格，代码比 Go 更易读。
+-   脚本化的风格，以及比 Go 更易读的数据科学代码。
 
 例如，以下是合法的 Go+ 源代码：
 
diff --git a/cl/compile.go b/cl/compile.go
index 4bf51367..5c150ebc 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -560,15 +560,6 @@ func preloadFile(p *gox.Package, parent *pkgCtx, file string, f *ast.File, targe
 				}
 				for _, v := range specs {
 					spec := v.(*ast.ValueSpec)
-					if spec.Type == nil {
-						pos := ctx.Position(v.Pos())
-						ctx.handleCodeErrorf(&pos, "missing field type in class file")
-						continue
-					}
-					if len(spec.Values) > 0 {
-						pos := ctx.Position(v.Pos())
-						ctx.handleCodeErrorf(&pos, "cannot assign value to field in class file")
-					}
 					typ := toType(ctx, spec.Type)
 					for _, name := range spec.Names {
 						flds = append(flds, types.NewField(name.Pos(), pkg, name.Name, typ, false))
diff --git a/cmd/internal/clean/clean.go b/cmd/internal/clean/clean.go
index e0e896b2..cac9e97b 100644
--- a/cmd/internal/clean/clean.go
+++ b/cmd/internal/clean/clean.go
@@ -18,13 +18,12 @@ package clean
 
 import (
 	"fmt"
+	"github.com/qiniu/x/log"
 	"io/ioutil"
 	"os"
 	"path/filepath"
 	"strings"
 
-	"github.com/qiniu/x/log"
-
 	"github.com/goplus/gop/cmd/internal/base"
 )
 
@@ -84,7 +83,7 @@ func removeGopDir(dir string) {
 
 // -----------------------------------------------------------------------------
 
-// Cmd - gop clean
+// Cmd - gop build
 var Cmd = &base.Command{
 	UsageLine: "gop clean [-v] <gopSrcDir>",
 	Short:     "Clean all Go+ auto generated files",
diff --git a/cmd/internal/env/env.go b/cmd/internal/env/env.go
index bc502bab..1bba50ff 100644
--- a/cmd/internal/env/env.go
+++ b/cmd/internal/env/env.go
@@ -74,23 +74,10 @@ func runCmd(_ *base.Command, args []string) {
 	gopEnv["GOPMOD"], _ = env.GOPMOD("")
 	gopEnv["HOME"] = env.HOME()
 
+	onlyValues := false
 	vars := flag.Args()
-
-	outputEnvVars(gopEnv, vars, *envJson)
-}
-
-func outputEnvVars(gopEnv map[string]interface{}, vars []string, outputJson bool) {
-	onlyValues := true
-
-	if len(vars) == 0 {
-		onlyValues = false
-
-		vars = make([]string, 0, len(gopEnv))
-		for k := range gopEnv {
-			vars = append(vars, k)
-		}
-		sort.Strings(vars)
-	} else {
+	if len(vars) > 0 {
+		onlyValues = true
 		newEnv := make(map[string]interface{})
 		for _, v := range vars {
 			if value, ok := gopEnv[v]; ok {
@@ -102,6 +89,10 @@ func outputEnvVars(gopEnv map[string]interface{}, vars []string, outputJson bool
 		gopEnv = newEnv
 	}
 
+	outputEnvVars(gopEnv, onlyValues, *envJson)
+}
+
+func outputEnvVars(gopEnv map[string]interface{}, onlyValues bool, outputJson bool) {
 	if outputJson {
 		b, err := json.Marshal(gopEnv)
 		if err != nil {
@@ -109,10 +100,15 @@ func outputEnvVars(gopEnv map[string]interface{}, vars []string, outputJson bool
 		}
 
 		var out bytes.Buffer
-		json.Indent(&out, b, "", "\t")
+		json.Indent(&out, b, "", "  ")
 		fmt.Println(out.String())
 	} else {
-		for _, k := range vars {
+		keys := make([]string, 0, len(gopEnv))
+		for k := range gopEnv {
+			keys = append(keys, k)
+		}
+		sort.Strings(keys)
+		for _, k := range keys {
 			v := gopEnv[k]
 			if onlyValues {
 				fmt.Printf("%v\n", v)
diff --git a/cmd/internal/modload/modload.go b/cmd/internal/modload/modload.go
index cd30b4c1..ece6af3e 100644
--- a/cmd/internal/modload/modload.go
+++ b/cmd/internal/modload/modload.go
@@ -219,9 +219,6 @@ func CreateModFile(modPath string) {
 
 func Load() {
 	LoadModFile()
-	if modRoot == "" {
-		return
-	}
 	SyncGoMod()
 	if classModFile != nil && classModFile.Classfile != nil {
 		gengo.RegisterPkgFlags(classModFile.Classfile.ProjExt, gengo.PkgFlagGmx)
@@ -263,9 +260,6 @@ func fixGoVersion(fixed *bool) gomodfile.VersionFixer {
 // -mod wasn't set explicitly and automatic vendoring should be enabled.
 func LoadModFile() {
 	Init()
-	if modRoot == "" {
-		return
-	}
 	// If gop.mod does not exist, then modroot does not exist,
 	// and if go.mod exists then a copy of go.mod will be synchronized to gop.mod
 	gopmod := GopModFilePath()
diff --git a/x/gopmod/gopfiles.go b/x/gopmod/gopfiles.go
index 7a6ebfc6..eed29908 100644
--- a/x/gopmod/gopfiles.go
+++ b/x/gopmod/gopfiles.go
@@ -64,6 +64,9 @@ func (p *gopFiles) Fingerp() [20]byte { // source code fingerprint
 }
 
 func (p *gopFiles) IsDirty(outFile string, temp bool) bool {
+	if fi, err := os.Lstat(outFile); err == nil { // TODO: more strictly
+		return fi.IsDir()
+	}
 	return true
 }
 


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index 04b20236..db874b23 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -73,50 +73,6 @@ func gopSpxTestEx(t *testing.T, gmx, spxcode, expected, gmxfile, spxfile string)
 	}
 }
 
-func gopSpxErrorTestEx(t *testing.T, msg, gmx, spxcode, gmxfile, spxfile string) {
-	fs := newTwoFileFS("/foo", spxfile, spxcode, gmxfile, gmx)
-	pkgs, err := parser.ParseFSDir(gblFset, fs, "/foo", nil, 0)
-	if err != nil {
-		scanner.PrintError(os.Stderr, err)
-		t.Fatal("ParseFSDir:", err)
-	}
-	conf := *baseConf.Ensure()
-	conf.NoFileLine = false
-	conf.WorkingDir = "/foo"
-	conf.TargetDir = "/foo"
-	bar := pkgs["main"]
-	_, err = cl.NewPackage("", bar, &conf)
-	if err == nil {
-		t.Fatal("no error?")
-	}
-	if ret := err.Error(); ret != msg {
-		t.Fatalf("\nError: \"%s\"\nExpected: \"%s\"\n", ret, msg)
-	}
-}
-
-func TestSpxError(t *testing.T) {
-	gopSpxErrorTestEx(t, `./Game.tgmx:4:2: cannot assign value to field in class file`, `
-var (
-	Kai Kai
-	userScore int = 100
-)
-`, `
-println "hi"
-`, "Game.tgmx", "Kai.tspx")
-
-	gopSpxErrorTestEx(t, `./Kai.tspx:3:2: missing field type in class file`, `
-var (
-	Kai Kai
-	userScore int
-)
-`, `
-var (
-	id = 100
-)
-println "hi"
-`, "Game.tgmx", "Kai.tspx")
-}
-
 func TestSpxBasic(t *testing.T) {
 	gopSpxTestEx(t, `
 func onInit() {
diff --git a/parser/parserdir_test.go b/parser/parserdir_test.go
index 9db148cb..3624a7dc 100644
--- a/parser/parserdir_test.go
+++ b/parser/parserdir_test.go
@@ -22,6 +22,7 @@ import (
 	"os"
 	"path"
 	"reflect"
+	"runtime"
 	"strings"
 	"testing"
 
@@ -132,6 +133,9 @@ func TestParseGoFiles(t *testing.T) {
 }
 
 func TestFromTestdata(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		return // TODO: how to pass this testcase in windows
+	}
 	sel := ""
 	dir, err := os.Getwd()
 	if err != nil {
diff --git a/printer/gop_test.go b/printer/gop_test.go
index 13cd9703..aa776a31 100644
--- a/printer/gop_test.go
+++ b/printer/gop_test.go
@@ -21,6 +21,7 @@ import (
 	"io/ioutil"
 	"os"
 	"path/filepath"
+	"runtime"
 	"testing"
 
 	"github.com/goplus/gop/ast"
@@ -117,6 +118,9 @@ func testFrom(t *testing.T, fpath string) {
 }
 
 func TestFromTestdata(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		return // TODO: how to pass this testcase in windows
+	}
 	dir, err := os.Getwd()
 	if err != nil {
 		t.Fatal("Getwd failed:", err)
@@ -135,6 +139,9 @@ func TestFromTestdata(t *testing.T) {
 }
 
 func TestFromParse(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		return // TODO: how to pass this testcase in windows
+	}
 	dir, err := os.Getwd()
 	if err != nil {
 		t.Fatal("Getwd failed:", err)
diff --git a/x/mod/modfile/read_test.go b/x/mod/modfile/read_test.go
index 054013a9..c278ef07 100644
--- a/x/mod/modfile/read_test.go
+++ b/x/mod/modfile/read_test.go
@@ -23,6 +23,7 @@ import (
 	"os/exec"
 	"path/filepath"
 	"reflect"
+	"runtime"
 	"strings"
 	"testing"
 )
@@ -30,6 +31,9 @@ import (
 // Test that reading and then writing the golden files
 // does not change their output.
 func TestPrintGolden(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		return // TODO: how to pass this testcase in windows
+	}
 	outs, err := filepath.Glob("testdata/*.golden")
 	if err != nil {
 		t.Fatal(err)
@@ -150,6 +154,9 @@ func TestParseLax(t *testing.T) {
 // and printed and parsed again, we get the same parse tree
 // both times.
 func TestPrintParse(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		return // TODO: how to pass this testcase in windows
+	}
 	outs, err := filepath.Glob("testdata/*")
 	if err != nil {
 		t.Fatal(err)