Go 1.4 src/pkg → src
Russ Cox
June 2014
[If you found this document because your Go tree is not building, skip to the Updating section at the end.]
Abstract
We propose to delete the “pkg” level of the $GOROOT directory hierarchy.
Background
The structure of the main Go repo has evolved with Go.
Originally, in March 2008, there was a src/lib directory containing fmt.go and sys.go, for package fmt and package sys. The rest of the repo held the Go compiler and other support tools. src/lib was the (eventually standard) library.
In July 2008, we started placing larger packages such as syscall in their own directories. Small packages stayed in single files.
In May 2009, we decided to place all packages, regardless of size, in their own directories.
In June 2009, we renamed src/lib to src/pkg, matching the name of the directory where compiled packages live. There was still a fair amount of non-Go in other src directories.
In April 2011, after a few months of discussion, we introduced $GOPATH to allow developers to work on code outside the standard tree. The form of a $GOPATH directory mimics the main repo, but because it’s all Go, we shortened src/pkg to src. The extra “pkg” element is a special case in the go command that makes the $GOROOT workspace different from the $GOPATH workspaces.
Proposal
We propose to move all directories in $GOROOT/src/pkg to $GOROOT/src.
Other files and directories in $GOROOT/src stay where they are.
This will make the $GOROOT workspace have same layout as the $GOPATH workspaces, which will remove special cases in the go command. It will stop confusing users who compare the two or try to set up their $GOPATH like $GOROOT.
It also gives an import path for internal packages built as part of commands. For example, assuming that the internal packages rules are adopted, code in $GOROOT/src/cmd/asm/internal can be imported using
import “cmd/asm/internal”
It also simplifies the rules needed for internal packages. Without moving the library, the internal packages proposal needs a special rule to ignore pkg, or else $GOROOT/src/cmd/... code cannot import code -from $GOROOT/src/pkg/internal/.
Implementation
This will cause churn, especially for people who have pending modifications to files in $GOROOT/src/pkg/.
On the other hand, if we are ever going to remove this irregularity, sooner is better than later. There will only be more files and more people working on them in the future.
Perhaps the best time to make this change is September 1, at the start of the Go 1.4 release freeze. There should not be many people with pending changes, and we would still have three months to shake out any possible build problems. Until September we would live with special cases in the go command, including in the support for internal packages.
Updating
Go contributors working in the main repository will need to do three things to update their trees:
1. Run “hg sync” to get the changes.
2. Look at $GOROOT/src/pkg, which is likely to be full of untracked files.
Copy those you want to keep elsewhere, and then rm -rf $GOROOT/src/pkg.
3. Code review metadata will still refer to the old files.
Reassign files in pending CLs by running “hg change ###”.
有疑问加站长微信联系(非本文作者)