Repository: goplus/gop
Pull request #1658 (2024-01-22 07:40:53)

gmxMainFunc: check conf.NoAutoGenMain


Patch:
diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml
index 2e61bcb0..91acd95c 100644
--- a/.github/workflows/release-build.yml
+++ b/.github/workflows/release-build.yml
@@ -50,13 +50,3 @@ jobs:
       env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         WINGET_PKGS_PRIVATE_KEY: ${{ secrets.WINGET_PKGS_PRIVATE_KEY }}
-
-    - name: Upload deb/rpm to Fury.io
-      run: |
-        for file in dist/*.{deb,rpm}
-        do
-          echo "Uploading $file to Fury.io"
-          curl -sS -F package=@$file https://$FURY_TOKEN@push.fury.io/goplus/
-        done
-      env:
-        FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 36519f89..908dddb4 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -68,25 +68,12 @@ changelog:
       - "^test:"
 
 winget:
-  - name: goplus
+  - name: gop
     homepage: "https://goplus.org/"
     publisher: goplus
     publisher_url: https://github.com/goplus/gop
     publisher_support_url: "https://github.com/goplus/gop/issues/new"
     package_identifier: goplus.gop
-    path: "manifests/g/goplus/gop/{{.Version}}"
-    tags:
-      - golang
-      - go
-      - gop
-      - goplus
-      - programming
-      - language
-      - compiler
-      - interpreter
-      - data science
-      - engineering
-      - education
     short_description: The Go+ Programming Language
     description: |
       The Go+ programming language is designed for engineering, STEM education, and data science.
@@ -116,7 +103,7 @@ winget:
           branch: master
 
 nfpms:
-  - package_name: gop
+  - package_name: goplus-gop
     vendor: goplus
     homepage: https://goplus.org/
     maintainer: Li Jie <cpunion@gmail.com>
@@ -192,7 +179,7 @@ nfpms:
 
 snapcrafts:
   - id: gop
-    name: gop
+    name: goplus
     title: The Go+ Programming Language
     summary: The Go+ Programming Language
     description: |
diff --git a/README.md b/README.md
index f0f460e8..397bc498 100644
--- a/README.md
+++ b/README.md
@@ -47,41 +47,6 @@ For more details, see [Quick Start](doc/docs.md).
 
 ## How to install
 
-### on Windows
-
-```sh
-winget install goplus
-```
-
-Or
-
-```sh
-winget install goplus.gop
-```
-
-### on Debian/Ubuntu
-
-```sh
-sudo bash -c ' echo "deb [trusted=yes] https://pkgs.goplus.org/apt/ /" > /etc/apt/sources.list.d/goplus.list'
-sudo apt update
-sudo apt install gop
-```
-
-### on RedHat/CentOS/Fedora
-
-```sh
-sudo bash -c 'echo -e "[goplus]\nname=Go+ Repo\nbaseurl=https://pkgs.goplus.org/yum/\nenabled=1\ngpgcheck=0" > /etc/yum.repos.d/goplus.repo'
-sudo yum install gop
-```
-
-### on macOS/Linux(Homebrew)
-
-Install via [brew](https://brew.sh/)
-
-```sh
-$ brew install goplus
-```
-
 ### from source code
 
 For now, we suggest you install Go+ from source code.
@@ -98,6 +63,14 @@ cd gop
 all.bat
 ```
 
+### on macOS/Linux
+
+Install via [brew](https://brew.sh/)
+```sh
+$ brew install goplus
+```
+
+
 ## Go+ Applications
 
 ### 2D Games powered by Go+
diff --git a/cl/classfile.go b/cl/classfile.go
index d51e17d6..1b4e8e5d 100644
--- a/cl/classfile.go
+++ b/cl/classfile.go
@@ -185,7 +185,7 @@ func setBodyHandler(ctx *blockCtx) {
 	}
 }
 
-func gmxMainFunc(p *gox.Package, ctx *pkgCtx) func() {
+func gmxMainFunc(p *gox.Package, ctx *pkgCtx, noAutoGenMain bool) func() {
 	if len(ctx.projs) == 1 { // only one project file
 		var proj *gmxProject
 		for _, v := range ctx.projs {
@@ -193,7 +193,16 @@ func gmxMainFunc(p *gox.Package, ctx *pkgCtx) func() {
 			break
 		}
 		scope := p.Types.Scope()
-		if o := scope.Lookup(proj.gameClass); o != nil && hasMethod(o, "MainEntry") {
+		var o types.Object
+		if proj.gameClass != "" {
+			o = scope.Lookup(proj.gameClass)
+			if noAutoGenMain && o != nil && hasMethod(o, "MainEntry") {
+				noAutoGenMain = false
+			}
+		} else {
+			o = proj.game
+		}
+		if !noAutoGenMain && o != nil {
 			// new(Game).Main()
 			// new(Game).Main(workers...)
 			fn := p.NewFunc(nil, "main", nil, nil, false)
@@ -228,4 +237,17 @@ func gmxMainNarg(sig *types.Signature) int {
 	return sig.Params().Len()
 }
 
+func hasMethod(o types.Object, name string) bool {
+	if obj, ok := o.(*types.TypeName); ok {
+		if t, ok := obj.Type().(*types.Named); ok {
+			for i, n := 0, t.NumMethods(); i < n; i++ {
+				if t.Method(i).Name() == name {
+					return true
+				}
+			}
+		}
+	}
+	return false
+}
+
 // -----------------------------------------------------------------------------
diff --git a/cl/compile.go b/cl/compile.go
index edad1258..e053d30d 100644
--- a/cl/compile.go
+++ b/cl/compile.go
@@ -588,7 +588,7 @@ func NewPackage(pkgPath string, pkg *ast.Package, conf *Config) (p *gox.Package,
 		}
 	}
 	if genMain { // make classfile main func if need
-		gen = gmxMainFunc(p, ctx)
+		gen = gmxMainFunc(p, ctx, conf.NoAutoGenMain)
 	}
 
 	for _, f := range sfiles {
@@ -648,19 +648,6 @@ func initGopPkg(ctx *pkgCtx, pkg *gox.Package, gopSyms map[string]bool) {
 	initThisGopPkg(pkg.Types)
 }
 
-func hasMethod(o types.Object, name string) bool {
-	if obj, ok := o.(*types.TypeName); ok {
-		if t, ok := obj.Type().(*types.Named); ok {
-			for i, n := 0, t.NumMethods(); i < n; i++ {
-				if t.Method(i).Name() == name {
-					return true
-				}
-			}
-		}
-	}
-	return false
-}
-
 func getEntrypoint(f *ast.File) string {
 	switch {
 	case f.IsProj:
diff --git a/go.mod b/go.mod
index cb5cf206..18e69c35 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.18
 require (
 	github.com/fsnotify/fsnotify v1.7.0
 	github.com/goplus/c2go v0.7.20-0.20240115161159-762f74054b17
-	github.com/goplus/gox v1.13.1-0.20240122040255-a954f8e0b9c1
+	github.com/goplus/gox v1.13.1-0.20240122055409-d0400bc230e8
 	github.com/goplus/mod v0.12.2-0.20240122042636-7db361b76b12
 	github.com/qiniu/x v1.13.2
 	golang.org/x/tools v0.17.0
diff --git a/go.sum b/go.sum
index 41c036f3..804d365b 100644
--- a/go.sum
+++ b/go.sum
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
 github.com/goplus/c2go v0.7.20-0.20240115161159-762f74054b17 h1:2+AWW9KjzTwaM8pfvRZqhI3PCXs7cMxzsn98AqDpgH0=
 github.com/goplus/c2go v0.7.20-0.20240115161159-762f74054b17/go.mod h1:WFbERV86IVV4wJ2/mLa8756Fy6iSXtlwGQbEqkYoIR4=
 github.com/goplus/gox v1.13.1-0.20240115155941-e657d899cb2e/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
-github.com/goplus/gox v1.13.1-0.20240122040255-a954f8e0b9c1 h1:14sIjKTXsqx2jfwKxDw+damXZ5lk3bTF27AsOVm18tk=
-github.com/goplus/gox v1.13.1-0.20240122040255-a954f8e0b9c1/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
+github.com/goplus/gox v1.13.1-0.20240122055409-d0400bc230e8 h1:k3ZTzEEU1ct6ljE1gqCg5LH2iyOs9W69lCS5COYS9As=
+github.com/goplus/gox v1.13.1-0.20240122055409-d0400bc230e8/go.mod h1:G7Hz+cAOUyJyN9pPHrpqhfQPDUtiJNmoRVTwoaQ9nw0=
 github.com/goplus/mod v0.12.2-0.20240107203906-5044606d0c51/go.mod h1:ZtlS9wHOcAVxZ/zq7WLdKVes1HG/8Yn3KNuWZGcpeTs=
 github.com/goplus/mod v0.12.2-0.20240122042636-7db361b76b12 h1:oQX3E8MWcXznTsQ6mzXYXGbniwyfKW4GtPl5vSdOr9k=
 github.com/goplus/mod v0.12.2-0.20240122042636-7db361b76b12/go.mod h1:ZtlS9wHOcAVxZ/zq7WLdKVes1HG/8Yn3KNuWZGcpeTs=


Test patch:
diff --git a/cl/typeparams_test.go b/cl/typeparams_test.go
index 014d36b3..c4b53b2d 100644
--- a/cl/typeparams_test.go
+++ b/cl/typeparams_test.go
@@ -1,6 +1,3 @@
-//go:build go1.18
-// +build go1.18
-
 package cl_test
 
 import (
diff --git a/x/build/build_test.go b/x/build/build_test.go
index e4c692fc..82305e72 100644
--- a/x/build/build_test.go
+++ b/x/build/build_test.go
@@ -389,6 +389,10 @@ import (
 	"github.com/goplus/gop/cl/internal/spx"
 )
 
+func main() {
+	spx.Gopt_MyGame_Main(new(spx.MyGame))
+}
+
 type Cat struct {
 	spx.Sprite
 }
@@ -396,8 +400,6 @@ type Cat struct {
 func (this *Cat) Main() {
 	fmt.Println("hi")
 }
-func main() {
-}
 `)
 }