Skip to content

cmd/go: preserve basic GOPATH mode indefinitely #60915

Closed
@rsc

Description

@rsc

In Feb 2021 (https://go.dev/blog/go116-module-changes), we wrote:

It's still possible to build packages in GOPATH mode by setting the GO111MODULE environment variable to off. ... We plan to drop support for GOPATH mode in Go 1.17. In other words, Go 1.17 will ignore GO111MODULE. If you have projects that do not build in module-aware mode, now is the time to migrate. If there is a problem preventing you from migrating, please consider filing an issue or an experience report.

The time has come to decide what to do about GOPATH mode. There are at least two important problems with maintaining GOPATH mode as it exists today:

  • The old, GOPATH-mode go get is being left behind as far as security improvements like the module proxy, checksum databases, and so on. All the focus is on modules.

  • The old, GOPATH-mode source layout does not provide a way to identify the language version used by the source code. There is a bit of divergence here in that a go.mod with no go line assumes Go 1.16, while in GOPATH mode we assume the latest version of Go. This means if someone has downloadable packages they develop in GOPATH mode, they can use language features introduced after Go 1.16, like generics, but when clients download that code in module mode as a "legacy" module, the code is interpreted as Go 1.16 and does not compile. The divergence will become greater over time as other language features or changes are made, such as spec: less error-prone loop variable scoping #60078.

On the other hand, GOPATH mode remains the only way to work on dependency-free legacy packages that existing module code may still depend on (so-called "+incompatible" modules), and it remains the only way to build historical source code that predates modules, especially code that depends on the multiple layers of vendoring that Go 1.5 introduced (and modules removed).

Given these tensions, I propose that we do the following:

  1. Commit to preserving the ability to build GOPATH-layout source trees when GO111MODULE=off, indefinitely.
  2. Disable go get completely in GOPATH mode, since there is increasingly little code that it can download successfully and provides a worse and worse experience.
  3. Assume a language setting of Go 1.21 in GOPATH mode, instead of continuing to assume "the latest Go version". This will ensure that if we change for loops in Go 1.22 (spec: less error-prone loop variable scoping #60078) or make other changes in the future, the old, legacy code we are aiming to keep compiling does keep compiling as written.

We would make these changes for Go 1.22. The GOPATH mode enabler would continue to be GO111MODULE=off rather than introducing a cleaner name like GOMODULE=off, because there's little point to upsetting whatever scripts people with legacy trees have already written.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions