Skip to content

Commit

Permalink
Merge pull request #1518 from xushiwei/gengo
Browse files Browse the repository at this point in the history
gop go -ignore-notated-error
  • Loading branch information
xushiwei committed Nov 3, 2023
2 parents fb14bb9 + 3e7540b commit 3785192
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 50 deletions.
5 changes: 2 additions & 3 deletions cmd/internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

// Package build implements the ``gop build'' command.
// Package build implements the gop build command.
package build

import (
Expand All @@ -23,7 +23,6 @@ import (
"os"
"path/filepath"
"reflect"
"syscall"

"github.com/goplus/gop"
"github.com/goplus/gop/cl"
Expand Down Expand Up @@ -105,7 +104,7 @@ func build(proj gopprojs.Proj, conf *gop.Config, build *gocmd.BuildConfig) {
default:
log.Panicln("`gop build` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
if gop.NotFound(err) {
fmt.Fprintf(os.Stderr, "gop build %v: not found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
3 changes: 1 addition & 2 deletions cmd/internal/doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"reflect"
"strconv"
"strings"
"syscall"

"github.com/goplus/gop"
"github.com/goplus/gop/cl"
Expand Down Expand Up @@ -95,7 +94,7 @@ func outlinePkg(proj gopprojs.Proj, conf *gop.Config) {
default:
log.Panicln("`gop doc` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
if gop.NotFound(err) {
fmt.Fprintf(os.Stderr, "gop doc %v: not Go/Go+ files found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
18 changes: 12 additions & 6 deletions cmd/internal/gengo/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ var Cmd = &base.Command{
}

var (
flag = &Cmd.Flag
flagVerbose = flag.Bool("v", false, "print verbose information.")
flagCheckMode = flag.Bool("t", false, "do check syntax only, no generate gop_autogen.go")
flagSingleMode = flag.Bool("s", false, "run in single file mode")
flag = &Cmd.Flag
flagVerbose = flag.Bool("v", false, "print verbose information")
flagCheckMode = flag.Bool("t", false, "do check syntax only, no generate gop_autogen.go")
flagSingleMode = flag.Bool("s", false, "run in single file mode")
flagIgnoreNotatedErr = flag.Bool(
"ignore-notated-error", false, "ignore notated errors, only available together with -t (check mode)")
)

func init() {
Expand Down Expand Up @@ -69,19 +71,23 @@ func runCmd(cmd *base.Command, args []string) {
cl.SetDisableRecover(true)
}

var conf *gop.Config
flags := gop.GenFlagPrintError | gop.GenFlagPrompt
if *flagCheckMode {
flags |= gop.GenFlagCheckOnly
if *flagIgnoreNotatedErr {
conf = &gop.Config{IgnoreNotatedError: true}
}
}
if *flagSingleMode {
flags |= gop.GenFlagSingleFile
}
for _, proj := range projs {
switch v := proj.(type) {
case *gopprojs.DirProj:
_, _, err = gop.GenGoEx(v.Dir, nil, true, flags)
_, _, err = gop.GenGoEx(v.Dir, conf, true, flags)
case *gopprojs.PkgPathProj:
_, _, err = gop.GenGoPkgPathEx("", v.Path, nil, true, flags)
_, _, err = gop.GenGoPkgPathEx("", v.Path, conf, true, flags)
default:
log.Panicln("`gop go` doesn't support", reflect.TypeOf(v))
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

// Package install implements the ``gop install'' command.
// Package install implements the gop install command.
package install

import (
"fmt"
"log"
"os"
"reflect"
"syscall"

"github.com/goplus/gop"
"github.com/goplus/gop/cl"
Expand Down Expand Up @@ -95,7 +94,7 @@ func install(proj gopprojs.Proj, conf *gop.Config, install *gocmd.InstallConfig)
default:
log.Panicln("`gop install` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
if gop.NotFound(err) {
fmt.Fprintf(os.Stderr, "gop install %v: not found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

// Package run implements the ``gop run'' command.
// Package run implements the gop run command.
package run

import (
"fmt"
"os"
"reflect"
"syscall"

"github.com/goplus/gop"
"github.com/goplus/gop/cl"
Expand Down Expand Up @@ -104,7 +103,7 @@ func run(proj gopprojs.Proj, args []string, chDir bool, conf *gop.Config, run *g
default:
log.Panicln("`gop run` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
if gop.NotFound(err) {
fmt.Fprintf(os.Stderr, "gop run %v: not found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

// Package test implements the ``gop test'' command.
// Package test implements the gop test command.
package test

import (
"fmt"
"log"
"os"
"reflect"
"syscall"

"github.com/goplus/gop"
"github.com/goplus/gop/cl"
Expand Down Expand Up @@ -95,7 +94,7 @@ func test(proj gopprojs.Proj, conf *gop.Config, test *gocmd.TestConfig) {
default:
log.Panicln("`gop test` doesn't support", reflect.TypeOf(v))
}
if err == syscall.ENOENT {
if gop.NotFound(err) {
fmt.Fprintf(os.Stderr, "gop test %v: not found\n", obj)
} else if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
22 changes: 14 additions & 8 deletions gengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func genGoDir(dir string, conf *Config, genTestPkg, recursively bool, flags GenF
if strings.HasPrefix(d.Name(), "_") { // skip _
return filepath.SkipDir
}
if e := genGoIn(path, conf, genTestPkg, flags); e != nil {
if e := genGoIn(path, conf, genTestPkg, flags); e != nil && notIgnNotated(e, conf) {
if flags&GenFlagPrintError != 0 {
fmt.Fprintln(os.Stderr, e)
}
Expand All @@ -106,21 +106,27 @@ func genGoDir(dir string, conf *Config, genTestPkg, recursively bool, flags GenF
}
return list.ToError()
}
err = genGoIn(dir, conf, genTestPkg, flags)
if err != nil && (flags&GenFlagPrintError) != 0 {
fmt.Fprintln(os.Stderr, err)
if e := genGoIn(dir, conf, genTestPkg, flags); e != nil && notIgnNotated(e, conf) {
if (flags & GenFlagPrintError) != 0 {
fmt.Fprintln(os.Stderr, e)
}
err = e
}
return
}

func notIgnNotated(e error, conf *Config) bool {
return !(conf != nil && conf.IgnoreNotatedError && IgnoreNotated(e))
}

func genGoEntry(list *errors.List, path string, d fs.DirEntry, conf *Config, flags GenFlags) error {
fname := d.Name()
if strings.HasPrefix(fname, "_") { // skip _
if d.IsDir() {
return filepath.SkipDir
}
} else if !d.IsDir() && strings.HasSuffix(fname, ".gop") {
if e := genGoSingleFile(path, conf, flags); e != nil {
if e := genGoSingleFile(path, conf, flags); e != nil && notIgnNotated(e, conf) {
if flags&GenFlagPrintError != 0 {
fmt.Fprintln(os.Stderr, e)
}
Expand All @@ -134,9 +140,9 @@ func genGoSingleFile(file string, conf *Config, flags GenFlags) (err error) {
dir, fname := filepath.Split(file)
autogen := dir + strings.TrimSuffix(fname, ".gop") + "_augogen.go"
if (flags & GenFlagPrompt) != 0 {
fmt.Println("GenGo", file, "...")
fmt.Fprintln(os.Stderr, "GenGo", file, "...")
}
out, err := LoadFiles([]string{file}, nil)
out, err := LoadFiles([]string{file}, conf)
if err != nil {
return errors.NewWith(err, `LoadFiles(files, conf)`, -2, "gop.LoadFiles", file)
}
Expand All @@ -152,7 +158,7 @@ func genGoSingleFile(file string, conf *Config, flags GenFlags) (err error) {
func genGoIn(dir string, conf *Config, genTestPkg bool, flags GenFlags, gen ...*bool) (err error) {
out, test, err := LoadDir(dir, conf, genTestPkg, (flags&GenFlagPrompt) != 0)
if err != nil {
if err == syscall.ENOENT { // no Go+ source files
if NotFound(err) { // no Go+ source files
return nil
}
return errors.NewWith(err, `LoadDir(dir, conf, genTestPkg)`, -5, "gop.LoadDir", dir, conf, genTestPkg)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.18

require (
github.com/fsnotify/fsnotify v1.7.0
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba
github.com/goplus/c2go v0.7.17-0.20231103102716-f59c28136a0b
github.com/goplus/gox v1.12.2-0.20231103090303-19b970256b0e
github.com/goplus/mod v0.11.8
github.com/qiniu/x v1.13.1
golang.org/x/tools v0.14.0
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3 h1:+/enB6wmQenM2Ihwv/v41lSgdTf3ARPi6A8FB1A/YH4=
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3/go.mod h1:DX0qhR2JSukHgIGMS9f6Vcu0N76LYBQy2tB+UnmIx3U=
github.com/goplus/gox v1.12.2-0.20231102132054-7ebd369dd022/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba h1:XPnDAw65OtpBFbR2XQkFz53HXN06ibEHX5xQIDffGXs=
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
github.com/goplus/c2go v0.7.17-0.20231103102716-f59c28136a0b h1:qtQfKpXI2wx1N1wc6qA2EQIsPS1vEKNPswftLaGrUHU=
github.com/goplus/c2go v0.7.17-0.20231103102716-f59c28136a0b/go.mod h1:fVpYuVxuvIQCrEhVrMkvivFwnWzr3EWWBQrnkfMMN+M=
github.com/goplus/gox v1.12.2-0.20231103090303-19b970256b0e h1:l1a+oX9m3xWuHWXVGRpnNo+/vag8qR8DQ933euQlS6w=
github.com/goplus/gox v1.12.2-0.20231103090303-19b970256b0e/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
github.com/goplus/mod v0.11.8 h1:90Kbg+MJhrdsonNGXYx3HUcW4IbBlRHYpIMssJaMMxM=
github.com/goplus/mod v0.11.8/go.mod h1:yl2QncBKTdXk+8UaNsdo4u2zSpGEJYA5JKjgD3K2h00=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down
Loading

0 comments on commit 3785192

Please sign in to comment.