Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/stringer: Does not work with Go modules #27456

Closed
F21 opened this issue Sep 3, 2018 · 6 comments
Closed

x/tools/cmd/stringer: Does not work with Go modules #27456

F21 opened this issue Sep 3, 2018 · 6 comments

Comments

@F21
Copy link

F21 commented Sep 3, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/d/wprl"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/d/work/src/github.com/Boostport/address/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-build705666856=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I executed stringer -type=Field,FieldName -output=constant_string.go to generate strings for the following file:

package address

// Field is an address field type.
type Field int

const (
	Country Field = iota + 1
	Name
	Organization
	StreetAddress
	DependentLocality
	Locality
	AdministrativeArea
	PostCode
	SortingCode
)

// Key returns the corresponding one-letter abbreviation used by Google to refer to address fields.
// This is useful for parsing the address format for a country.
// See https://github.com/googlei18n/libaddressinput/wiki/AddressValidationMetadata for more information.
func (i Field) Key() string {

	switch i {
	case Country:
		return "country"
	case Name:
		return "N"
	case Organization:
		return "O"
	case StreetAddress:
		return "A"
	case DependentLocality:
		return "D"
	case Locality:
		return "C"
	case AdministrativeArea:
		return "S"
	case PostCode:
		return "Z"
	case SortingCode:
		return "X"
	}

	return ""
}

// FieldName is the name to be used when referring to a field.
// For example, in India, the post code is called PIN Code instead of Post Code.
// The field name allows you to display the appropriate form labels to the user.
type FieldName int

const (
	Area FieldName = iota + 1
	City
	County
	Department
	District
	DoSi
	Eircode
	Emirate
	Island
	Neighborhood
	Oblast
	PINCode
	Parish
	PostTown
	PostalCode
	Prefecture
	Province
	State
	Suburb
	Townland
	VillageTownship
	ZipCode
)

There is another file in the package that imports golang.org/x/text/collate, but it does not need any strings generated.

What did you expect to see?

Stringer works correctly

What did you see instead?

stringer: checking package: address.go:12:2: could not import golang.org/x/text/collate (type-checking package "golang.org/x/text/collate" failed (/d/work/pkg/mod/golang.org/x/text@v0.3.0/collate/collate.go:17:2: could not import golang.org/x/text/in
ternal/colltab (cannot find package "golang.org/x/text/internal/colltab" in any of:
        /usr/local/go/src/golang.org/x/text/internal/colltab (from $GOROOT)
        /d/work/src/golang.org/x/text/internal/colltab (from $GOPATH))))
@gopherbot gopherbot added this to the Unreleased milestone Sep 3, 2018
@fhs
Copy link
Contributor

fhs commented Sep 3, 2018

This falls under issue #24661

@agnivade
Copy link
Contributor

agnivade commented Sep 3, 2018

That is correct. Please subscribe/comment on that issue. It seems there is already an open CL in the works for it.

@andig
Copy link
Contributor

andig commented Jan 12, 2019

I've just been hit square in the face by this:

env GO111MODULE=on go generate ./...
stringer: checking package: meter.go:8:6: could not import github.com/sirupsen/logrus (type-checking package "github.com/sirupsen/logrus" failed (/Users/andig/go/pkg/mod/github.com/sirupsen/logrus@v1.3.0/terminal_check_notappengine.go:9:2: could not import golang.org/x/crypto/ssh/terminal (type-checking package "golang.org/x/crypto/ssh/terminal" failed (/Users/andig/go/pkg/mod/golang.org/x/crypto@v0.0.0-20180904163835-0709b304e793/ssh/terminal/util.go:20:2: could not import golang.org/x/sys/unix (cannot find package "golang.org/x/sys/unix" in any of:
        /usr/local/Cellar/go/1.11.4/libexec/src/golang.org/x/sys/unix (from $GOROOT)
        /Users/andig/go/src/golang.org/x/sys/unix (from $GOPATH))))))
exit status 1
meters/measurements.go:5: running "go": exit status 1
make: *** [assets] Error 1

The funny thing is that this worked perfectly find before I've restructured the codecase, i.e. move pieces to different locations. Its not a problem with the imports per se.

@andig
Copy link
Contributor

andig commented Jan 17, 2019

@fhs @agnivade this has been closed in favour of the tracking issue. #24661 refs a CL that has seen the last update in August last year afaiks. Imho stringer is a very basic and widely used tool.

Can we do anything to get more attention on resolving the stringer issue?

@agnivade
Copy link
Contributor

You are free to comment on the issue. But it is an open-source tool at the end of the day. The best way is to make a contribution yourself :).

@andig
Copy link
Contributor

andig commented Jan 17, 2019

Not being a go internals hacker I was seeing my contribution in highlighting that the efforts for fixing stringer as far as this and the tracking issue are concerned have come to an apparent stop and the tracking issue might not be enough to gain traction.
I didn't want to appear impolite or unappreciative (if thats an english word).

@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants