go: cmd/go: "malformed import path" in Go 1.16 for packages with path elements containing a leading dot
What version of Go are you using (go version
)?
$ go version go version devel +076a45acd5 Tue Oct 13 19:15:53 2020 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/myitcv/.cache/go-build" GOENV="/home/myitcv/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/myitcv/gostuff/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/myitcv/gostuff" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/myitcv/dev/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/myitcv/dev/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" 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-build308834115=/tmp/go-build -gno-record-gcc-switches"
What did you do?
testscript -v <<'EOD'
go list ./.github/workflows
stdout 'rubbish/\.github/workflows'
-- go.mod --
module rubbish
-- .github/workflows/gen.go --
package gen
EOD
What did you expect to see?
Passing test
What did you see instead?
malformed import path "rubbish/.github/workflows": leading dot in path element
This has the effect of breaking commands like go generate ./.github/workflows
I bisected this to 3a65abfbdac7ab29f693d69bd1eb12b2148a11ae
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (13 by maintainers)
Commits related to this issue
- doc/go1.16: note that package path elements beginning with '.' are disallowed For #43985 Change-Id: I1a16f66800c5c648703f0a0d2ad75024525a710f Reviewed-on: https://go-review.googlesource.com/c/go/+/2... — committed to golang/go by bcmills 3 years ago
- Downgrade to Golang 1.15 Due to import restrictions: https://github.com/golang/go/issues/43985 — committed to gardener/terraformer by timuthy 3 years ago
- Downgrade to Golang 1.15 (#82) Due to import restrictions: https://github.com/golang/go/issues/43985 — committed to gardener/terraformer by timuthy 3 years ago
- module: allow leading dots in import path elements These were always disallowed, but the restriction wasn't enforced in most cases until Go 1.16. That's broken more projects than we hoped. This chan... — committed to golang/mod by deleted user 3 years ago
- cmd/go: test remote lookup of packages with leading dots in path elements Follow-up to CL 297530. For #43985 For #34992 Change-Id: I2cfa6c41c013e627c3464c383ca42f5c9ebe521a Reviewed-on: https://go-... — committed to golang/go by deleted user 3 years ago
It sounds like this issue is affecting more people than we’d hoped. I’ll look at relaxing the constraint that import paths can’t have path elements starting with dots. We’ll aim to backport that to 1.16.1.
We’ll continue to disallow trailing dots in import path elements, since those names aren’t allowed on Windows. We’ll also continue disallowing leading dots in module path elements.
The Gardener project (https://github.com/gardener) is affected by this change, too. We use modules to define cross repo dependencies in the Gardener org, also some of the modules don’t contain Go code at all: For example, https://github.com/gardener/gardener/tree/master/.github/ISSUE_TEMPLATE allows us to re-use Github templates across our repositories with the same dependency management tool (go mod) already used for Go dependencies.
I think we should keep this open since it used to work, and in most other situations, the go command allows a package with an invalid import path to be named using a file path. Probably not for 1.16 at this point in the freeze though.
@odeke-em, I don’t think this issue should be rolled forward to Go 1.17 since we don’t plan to do anything more about it. Perhaps it should just be closed, but we discourage folks from commenting on closed issues and we are actually interested in receiving comments about concrete examples here.
Maybe Unplanned is the right milestone for that.
I did some investigation, and found that the prohibition on leading-dot elements was added in CL 124378, back in July 2018.
We attempted to investigate the prevalence of these paths in the wild using the
pkg.go.dev
index, but it does not index imports of these paths (which further argues for disallowing them — so far no one seems to have reported the packages as missing there).The only specific affected module we know of so far is
go.uber.org/cadence
, but because the affectedimport
statement is aninternal
package it could be fixed for external consumers by an internal-only change within a patch release for that module (namely, moving the packages currently in the.gen
subdirectory to another location and updating the imports within the module).After discussion with @rsc, @jayconrod, and @matloob, we’re planning to leave this validation in place for Go 1.16.
If we find more severe examples after the release, we can consider whether to relax the check in Go 1.16.1. If you are affected, please comment on this issue with the affected module path(s) and versions.
For a bit of context, I’m doing this because having a
go:generate
directive within$modroot/.github/workflows
aligns the location of the directive with the target of the generation step. However, the argument against this is precisely the point that @bcmills makes - a simplego generate ./...
doesn’t end up running this directive. Rather awkwardly I actually use anothergo:generate
directive in another package to run the “hidden” one, which kind of defeats the purpose. So whilst the original goal was perhaps admirable/sensible, the workaround arguably makes it more confusing/convoluted. Which perhaps points to this being a bad idea generally, and hence one that we should not support.I’ll leave it to @bcmills and @jayconrod to determine whether it’s necessary to continue supporting this pattern given it used ti work in
1.15x
or not. From my perspective I think you’ve helped talk me round so this issue can otherwise be closed 😄Hrm, I’m not sure. We disallow a leading dot in general because it can make code harder to audit: in environments that hide dotfiles by default we don’t want to hide the source code for the dependencies of a Go package, and path elements beginning with
_
and.
are ignored bygo mod tidy
andgo list ./...
(compare #37376).