gobuffalo / buffalo

Rapid Web Development w/ Go
http://gobuffalo.io
MIT License
8.08k stars 577 forks source link

grifts tasks list - package grifts is not in GOROOT .../src/grifts - go 1.17 #2288

Closed sebd71 closed 2 years ago

sebd71 commented 2 years ago

Description

Grifts tasks seems not work / build with go 1.17. Command task list returns following error :

buffalo task list
.grifter/main.go:9:2: package grifts is not in GOROOT (/home/seb/local/go/install/go1.17.10/src/grifts)
Usage:
  buffalo task [flags]

Aliases:
  task, t, tasks

Flags:
  -h, --help   help for task

ERRO[0000] Error: exit status 1  

Steps to Reproduce the Problem

Create simple example, eg. coke and list grifts tasks

seb@seb-laptop: /tmp$ go version
go version go1.17.10 linux/amd64

seb@seb-laptop: /tmp$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/seb/.cache/go-build"
GOENV="/home/seb/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/seb/local/go/pkg/mod"
GOOS="linux"
GOPATH="/home/seb/local/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/seb/local/go/install/go1.17.10"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/seb/local/go/install/go1.17.10/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.10"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/seb/Work/redpesk/src/gobuffalo/grift/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2729777693=/tmp/go-build -gno-record-gcc-switches"

seb@seb-laptop: /tmp$ buffalo version
INFO[0000] Buffalo version is: v0.18.4                  

seb@seb-laptop: /tmp$ buffalo new coke --api 
DEBU[2022-07-04T21:30:08+02:00] Step: a9d806f3
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] Exec: go mod init coke
go: creating new go.mod: module coke
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/README.md
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/actions/actions_test.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/actions/app.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/actions/home.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/actions/home_test.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/actions/render.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/cmd/app/main.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/.codeclimate.yml
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/.env
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/fixtures/sample.toml
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/grifts/init.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/inflections.json
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/config/buffalo-app.toml
DEBU[2022-07-04T21:30:08+02:00] Step: 311cf205
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/Dockerfile
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/.dockerignore
DEBU[2022-07-04T21:30:08+02:00] Step: c567c8f2
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/grifts/db.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/models/models.go
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/models/models_test.go
DEBU[2022-07-04T21:30:08+02:00] Step: 71c6d882
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/database.yml
DEBU[2022-07-04T21:30:08+02:00] Step: b02cc6d8
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] File: /tmp/coke/.buffalo.dev.yml
DEBU[2022-07-04T21:30:08+02:00] Step: e4f6e26b
DEBU[2022-07-04T21:30:08+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:08+02:00] Exec: go install github.com/gobuffalo/buffalo-pop/v3@latest
go: downloading golang.org/x/sys v0.0.0-20211205182925-97ca703d548d
go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
go: downloading golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
DEBU[2022-07-04T21:30:14+02:00] Step: 5e04f5ee
DEBU[2022-07-04T21:30:14+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/config/buffalo-plugins.toml
DEBU[2022-07-04T21:30:14+02:00] Step: 22500801
DEBU[2022-07-04T21:30:14+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/actions/app.go
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/actions/home.go
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/actions/home_test.go
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/actions/render.go
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/locales/all.en-us.yaml
DEBU[2022-07-04T21:30:14+02:00] File: /tmp/coke/locales/embed.go
DEBU[2022-07-04T21:30:14+02:00] Step: 404ac23a
DEBU[2022-07-04T21:30:14+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:14+02:00] Exec: go mod tidy
go: finding module for package github.com/gobuffalo/buffalo
go: finding module for package github.com/gobuffalo/mw-forcessl
go: finding module for package github.com/gobuffalo/envy
go: finding module for package github.com/gobuffalo/mw-contenttype
go: finding module for package github.com/gobuffalo/mw-paramlogger
go: finding module for package github.com/gobuffalo/mw-i18n/v2
go: finding module for package github.com/gobuffalo/buffalo-pop/v3/pop/popmw
go: finding module for package github.com/gobuffalo/buffalo/render
go: finding module for package github.com/gobuffalo/x/sessions
go: finding module for package github.com/rs/cors
go: downloading github.com/gobuffalo/mw-contenttype v0.0.0-20190224202710-36c73cc938f3
go: downloading github.com/rs/cors v1.8.2
go: downloading github.com/gobuffalo/mw-paramlogger v1.0.0
go: downloading github.com/gobuffalo/mw-forcessl v0.0.0-20220514125302-be60179938a4
go: downloading github.com/gobuffalo/x v0.1.0
go: finding module for package github.com/unrolled/secure
go: finding module for package github.com/markbates/grift/grift
go: downloading github.com/gobuffalo/mw-i18n v1.1.0
go: finding module for package github.com/gobuffalo/pop/v6
go: finding module for package github.com/gobuffalo/suite/v4
go: downloading github.com/unrolled/secure v1.11.0
go: downloading github.com/gobuffalo/suite v2.8.2+incompatible
go: found github.com/gobuffalo/buffalo in github.com/gobuffalo/buffalo v0.18.7
go: found github.com/gobuffalo/buffalo-pop/v3/pop/popmw in github.com/gobuffalo/buffalo-pop/v3 v3.0.4
go: found github.com/gobuffalo/buffalo/render in github.com/gobuffalo/buffalo v0.18.7
go: found github.com/gobuffalo/envy in github.com/gobuffalo/envy v1.10.1
go: found github.com/gobuffalo/mw-contenttype in github.com/gobuffalo/mw-contenttype v0.0.0-20190224202710-36c73cc938f3
go: found github.com/gobuffalo/mw-forcessl in github.com/gobuffalo/mw-forcessl v0.0.0-20220514125302-be60179938a4
go: found github.com/gobuffalo/mw-i18n/v2 in github.com/gobuffalo/mw-i18n/v2 v2.0.1
go: found github.com/gobuffalo/mw-paramlogger in github.com/gobuffalo/mw-paramlogger v1.0.0
go: found github.com/gobuffalo/x/sessions in github.com/gobuffalo/x v0.1.0
go: found github.com/rs/cors in github.com/rs/cors v1.8.2
go: found github.com/unrolled/secure in github.com/unrolled/secure v1.11.0
go: found github.com/markbates/grift/grift in github.com/markbates/grift v1.5.0
go: found github.com/gobuffalo/pop/v6 in github.com/gobuffalo/pop/v6 v6.0.4
go: found github.com/gobuffalo/suite/v4 in github.com/gobuffalo/suite/v4 v4.0.2
go: downloading github.com/gobuffalo/validate v2.0.3+incompatible
go: downloading github.com/mattn/go-sqlite3 v1.14.9
go: downloading golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
go: downloading github.com/felixge/httpsnoop v1.0.1
go: downloading github.com/pelletier/go-toml v1.9.3
DEBU[2022-07-04T21:30:24+02:00] Exec: go mod download
DEBU[2022-07-04T21:30:26+02:00] Step: a431a84c
DEBU[2022-07-04T21:30:26+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:26+02:00] Step: 628b683d
DEBU[2022-07-04T21:30:26+02:00] Chdir: /tmp/coke
DEBU[2022-07-04T21:30:26+02:00] File: /tmp/coke/.gitignore
DEBU[2022-07-04T21:30:26+02:00] Exec: git init
Initialized empty Git repository in /tmp/coke/.git/
DEBU[2022-07-04T21:30:26+02:00] Exec: git add .
DEBU[2022-07-04T21:30:26+02:00] Exec: git commit -q -m Initial Commit
INFO[2022-07-04T21:30:26+02:00] Congratulations! Your application, coke, has been successfully generated!
INFO[2022-07-04T21:30:26+02:00] You can find your new application at: /tmp/coke
INFO[2022-07-04T21:30:26+02:00] Please read the README.md file in your new application for next steps on running your application.

seb@seb-laptop: /tmp/coke(master)$ buffalo build

seb@seb-laptop: /tmp/coke(master)$ cat go.mod 
module coke

go 1.17

require (
        github.com/gobuffalo/buffalo v0.18.7
        github.com/gobuffalo/buffalo-pop/v3 v3.0.4
        github.com/gobuffalo/envy v1.10.1
        github.com/gobuffalo/mw-contenttype v0.0.0-20190224202710-36c73cc938f3
        github.com/gobuffalo/mw-forcessl v0.0.0-20220514125302-be60179938a4
        github.com/gobuffalo/mw-i18n/v2 v2.0.1
        github.com/gobuffalo/mw-paramlogger v1.0.0
        github.com/gobuffalo/pop/v6 v6.0.4
        github.com/gobuffalo/suite/v4 v4.0.2
        github.com/gobuffalo/x v0.1.0
        github.com/markbates/grift v1.5.0
        github.com/rs/cors v1.8.2
        github.com/unrolled/secure v1.11.0
)

require (
        github.com/BurntSushi/toml v1.1.0 // indirect
        github.com/Masterminds/semver/v3 v3.1.1 // indirect
        github.com/aymerick/douceur v0.2.0 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/dustin/go-humanize v1.0.0 // indirect
        github.com/fatih/color v1.13.0 // indirect
        github.com/fatih/structs v1.1.0 // indirect
        github.com/felixge/httpsnoop v1.0.1 // indirect
        github.com/fsnotify/fsnotify v1.5.1 // indirect
        github.com/go-sql-driver/mysql v1.6.0 // indirect
        github.com/gobuffalo/events v1.4.2 // indirect
        github.com/gobuffalo/fizz v1.14.0 // indirect
        github.com/gobuffalo/flect v0.2.5 // indirect
        github.com/gobuffalo/github_flavored_markdown v1.1.1 // indirect
        github.com/gobuffalo/helpers v0.6.4 // indirect
        github.com/gobuffalo/httptest v1.5.1 // indirect
        github.com/gobuffalo/logger v1.0.6 // indirect
        github.com/gobuffalo/meta v0.3.1 // indirect
        github.com/gobuffalo/mw-csrf v1.0.0 // indirect
        github.com/gobuffalo/nulls v0.4.1 // indirect
        github.com/gobuffalo/plush/v4 v4.1.11 // indirect
        github.com/gobuffalo/tags/v3 v3.1.2 // indirect
        github.com/gobuffalo/validate/v3 v3.3.1 // indirect
        github.com/gofrs/uuid v4.2.0+incompatible // indirect
        github.com/gorilla/css v1.0.0 // indirect
        github.com/gorilla/handlers v1.5.1 // indirect
        github.com/gorilla/mux v1.8.0 // indirect
        github.com/gorilla/securecookie v1.1.1 // indirect
        github.com/gorilla/sessions v1.2.1 // indirect
        github.com/inconshreveable/mousetrap v1.0.0 // indirect
        github.com/jackc/chunkreader/v2 v2.0.1 // indirect
        github.com/jackc/pgconn v1.12.1 // indirect
        github.com/jackc/pgio v1.0.0 // indirect
        github.com/jackc/pgpassfile v1.0.0 // indirect
        github.com/jackc/pgproto3/v2 v2.3.0 // indirect
        github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
        github.com/jackc/pgtype v1.11.0 // indirect
        github.com/jackc/pgx/v4 v4.16.1 // indirect
        github.com/jmoiron/sqlx v1.3.5 // indirect
        github.com/joho/godotenv v1.4.0 // indirect
        github.com/karrick/godirwalk v1.16.1 // indirect
        github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
        github.com/luna-duclos/instrumentedsql v1.1.3 // indirect
        github.com/markbates/oncer v1.0.0 // indirect
        github.com/markbates/refresh v1.12.0 // indirect
        github.com/markbates/safe v1.0.1 // indirect
        github.com/mattn/go-colorable v0.1.12 // indirect
        github.com/mattn/go-isatty v0.0.14 // indirect
        github.com/mattn/go-sqlite3 v1.14.9 // indirect
        github.com/microcosm-cc/bluemonday v1.0.16 // indirect
        github.com/mitchellh/go-homedir v1.1.0 // indirect
        github.com/monoculum/formam v3.5.5+incompatible // indirect
        github.com/nicksnyder/go-i18n v1.10.1 // indirect
        github.com/pelletier/go-toml v1.9.3 // indirect
        github.com/pkg/errors v0.9.1 // indirect
        github.com/pmezard/go-difflib v1.0.0 // indirect
        github.com/rogpeppe/go-internal v1.8.0 // indirect
        github.com/sergi/go-diff v1.2.0 // indirect
        github.com/sirupsen/logrus v1.8.1 // indirect
        github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
        github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
        github.com/spf13/cobra v1.4.0 // indirect
        github.com/spf13/pflag v1.0.5 // indirect
        github.com/stretchr/testify v1.7.1 // indirect
        golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
        golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
        golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
        golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
        golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
        golang.org/x/text v0.3.7 // indirect
        gopkg.in/yaml.v2 v2.4.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

seb@seb-laptop: /tmp/coke(master)$ ls -l
total 232K
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 actions/
drwxrwxr-x 2 seb seb 4,0K juil.  4 21:31 bin/
drwxr-xr-x 3 seb seb 4,0K juil.  4 21:30 cmd/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 config/
-rw-rw-r-- 1 seb seb  371 juil.  4 21:30 database.yml
-rw-rw-r-- 1 seb seb  972 juil.  4 21:30 Dockerfile
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 fixtures/
-rw-rw-r-- 1 seb seb 4,3K juil.  4 21:31 go.mod
-rw-rw-r-- 1 seb seb 172K juil.  4 21:30 go.sum
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 grifts/
-rw-rw-r-- 1 seb seb   26 juil.  4 21:30 inflections.json
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 locales/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:31 migrations/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 models/
-rw-rw-r-- 1 seb seb 1,3K juil.  4 21:30 README.md

seb@seb-laptop: /tmp/coke(master)$  bin/coke 
DEBU[2022-07-04T21:31:12+02:00] starting application
INFO[2022-07-04T21:31:12+02:00] starting simple server on 127.0.0.1:3000
INFO[2022-07-04T21:31:12+02:00] starting Simple background worker
^CINFO[2022-07-04T21:31:14+02:00] shutting down application
INFO[2022-07-04T21:31:14+02:00] shutting down servers
WARN[2022-07-04T21:31:14+02:00] stopping application: http: Server closed
INFO[2022-07-04T21:31:14+02:00] shutting down worker
INFO[2022-07-04T21:31:14+02:00] stopping Simple background worker
INFO[2022-07-04T21:31:14+02:00] all background jobs stopped completely
INFO[2022-07-04T21:31:14+02:00] shutdown completed

seb@seb-laptop: /tmp/coke(master)$ buffalo task list
.grifter/main.go:9:2: package grifts is not in GOROOT (/home/seb/local/go/install/go1.17.10/src/grifts)
Usage:
  buffalo task [flags]

Aliases:
  task, t, tasks

Flags:
  -h, --help   help for task

ERRO[0000] Error: exit status 1  

Expected Behavior

buffalo task list should work as expected.

Questions

Is something wrong in my setup or is it a bug with grift tasks and new go 1.17 behavior ? I read and try to play with GO111MODULE=off/auto/on without succes.

sebd71 commented 2 years ago

Additional information :

after more investigations, it seems that info.Module.Path is empty when running buffalo task list / grift tool (grift/cli/run.go#L27). info.Module.Path is set by here package using go list -json command (see dir.go#33 ) and go list -json no longer works due to the fact that there is no main.go in the root directory of coke app (main.go is now under cmd/app/main.go.

seb@seb-laptop: /tmp/coke(master)$ cd coke
seb@seb-laptop: /tmp/coke(master)$ ls -l
total 232K
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 actions/
drwxrwxr-x 2 seb seb 4,0K juil.  4 21:31 bin/
drwxr-xr-x 3 seb seb 4,0K juil.  4 21:30 cmd/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 config/
-rw-rw-r-- 1 seb seb  371 juil.  4 21:30 database.yml
-rw-rw-r-- 1 seb seb  972 juil.  4 21:30 Dockerfile
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 fixtures/
-rw-rw-r-- 1 seb seb 4,3K juil.  4 21:31 go.mod
-rw-rw-r-- 1 seb seb 172K juil.  4 21:30 go.sum
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 grifts/
-rw-rw-r-- 1 seb seb   26 juil.  4 21:30 inflections.json
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 locales/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:31 migrations/
drwxr-xr-x 2 seb seb 4,0K juil.  4 21:30 models/
-rw-rw-r-- 1 seb seb 1,3K juil.  4 21:30 README.md

seb@seb-laptop: /tmp/coke(master)$ go list -json
no Go files in /tmp/coke

If I create a "fake" / empty main.go, all is back to normal :

seb@seb-laptop: /tmp/coke(master)$ echo "package main" > main.go
seb@seb-laptop: /tmp/coke(master)$ go list -json
{
        "Dir": "/tmp/coke",
        "ImportPath": "coke",
        "Name": "main",
        "Target": "/home/seb/local/go/bin/coke",
        "Root": "/tmp/coke",
        "Module": {
                "Path": "coke",
                "Main": true,
                "Dir": "/tmp/coke",
                "GoMod": "/tmp/coke/go.mod",
                "GoVersion": "1.17"
        },
        "Match": [
                "."
        ],
        "Stale": true,
        "StaleReason": "build ID mismatch",
        "GoFiles": [
                "main.go"
        ],
        "Deps": [
                "internal/abi",
                "internal/bytealg",
                "internal/cpu",
                "internal/goexperiment",
                "runtime",
                "runtime/internal/atomic",
                "runtime/internal/math",
                "runtime/internal/sys",
                "unsafe"
        ]
}

seb@seb-laptop: /tmp/coke(master)$ buffalo task list
Available grifts
================
buffalo task db:seed       # Seeds a database
buffalo task middleware    # Prints out your middleware stack
buffalo task routes        # Print out all defined routes
buffalo task secret        # Generate a cryptographically secure secret key

So is there a way to make go list working even if there is no .go file in root directory ? or does here code must be updated in order to retrieve ImportPath even if there is no .go file in root directory ?

Let me know if it's better to log a bug in here package.

sio4 commented 2 years ago

Thanks for filing a report!

This is a duplicate of gobuffalo/cli#142 and #2268. (The buffalo command is provided by cli package).

The buffalo v0.18.5 and above (the latest version is v0.18.6) was shipped with the fix.

sebd71 commented 2 years ago

Thanks a lot and sorry for the dups. I had looked at the issues but did not see those ones.

sio4 commented 2 years ago

Thanks a lot and sorry for the dups. I had looked at the issues but did not see those ones.

No problem at all! Your report will help others to find the solution of the issue too, and we are sorry for inconvenience!