Commit 8f5f347e authored by Russ Cox's avatar Russ Cox

cmd/go: many improvements

* correct dependency calculations
* comment meaning of action fields
* new alias "std" like "all" but standard packages only
* add -o flag to 'go build'
* set up for parallel build (still serial)
* understand that import "C" depends on cgo, runtime/cgo

R=golang-dev, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/5502055
parent 83610567
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -27,6 +27,9 @@ The special import path "all" expands to all package directories
found in all the GOPATH trees. For example, 'go list all'
lists all the packages on the local system.
The special import path "std" is like all but expands to just the
packages in the standard Go library.
An import path can also name a package to be downloaded from
a remote repository. Run 'go help remote' for details.
......
......@@ -33,11 +33,12 @@ being passed to the template is:
ImportPath string // import path of package in dir
Dir string // directory containing package sources
Version string // version of installed package (TODO)
Stale bool // would 'go install' do anything for this package?
// Source files
GoFiles []string // .go source files (excluding CgoFiles)
CFiles []string // .c source files
HFiles []string // .h source files
HFiles []string // .h source files
SFiles []string // .s source files
CgoFiles []string // .go sources files that import "C"
......
......@@ -185,8 +185,10 @@ func help(args []string) {
// importPaths returns the import paths to use for the given command line.
func importPaths(args []string) []string {
if len(args) == 1 && args[0] == "all" {
return allPackages()
if len(args) == 1 {
if args[0] == "all" || args[0] == "std" {
return allPackages(args[0])
}
}
if len(args) == 0 {
return []string{"."}
......@@ -236,10 +238,13 @@ func run(cmdline ...string) {
// allPackages returns all the packages that can be found
// under the $GOPATH directories and $GOROOT.
func allPackages() []string {
func allPackages(what string) []string {
have := map[string]bool{
"builtin": true, // ignore pseudo-package that exists only for documentation
}
if !build.DefaultContext.CgoEnabled {
have["runtime/cgo"] = true // ignore during walk
}
var pkgs []string
// Commands
......@@ -270,6 +275,9 @@ func allPackages() []string {
})
for _, t := range build.Path {
if what == "std" && !t.Goroot {
continue
}
src := t.SrcDir() + string(filepath.Separator)
filepath.Walk(src, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() {
......@@ -281,15 +289,21 @@ func allPackages() []string {
return filepath.SkipDir
}
name := filepath.ToSlash(path[len(src):])
if what == "std" && strings.Contains(name, ".") {
return filepath.SkipDir
}
if have[name] {
return nil
}
_, err = build.ScanDir(path)
if err != nil {
return nil
}
name := filepath.ToSlash(path[len(src):])
if !have[name] {
pkgs = append(pkgs, name)
have[name] = true
}
pkgs = append(pkgs, name)
have[name] = true
// Avoid go/build test data.
// TODO: Move it into a testdata directory.
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ func runRun(cmd *Command, args []string) {
var b builder
b.init(*runA, *runN, *runX)
p := goFilesPackage(args, "")
p.targ = "" // force rebuild - no up-to-date copy anywhere
p.target = "" // must build - not up to date
a1 := b.action(modeBuild, modeBuild, p)
a := &action{f: (*builder).runProgram, deps: []*action{a1}}
b.do(a)
......@@ -42,6 +42,6 @@ func runRun(cmd *Command, args []string) {
// runProgram is the action for running a binary that has already
// been compiled. We ignore exit status.
func (b *builder) runProgram(a *action) error {
run(a.deps[0].pkgbin)
run(a.deps[0].target)
return nil
}
This diff is collapsed.
......@@ -89,7 +89,7 @@ echo; echo; echo %%%% making runtime generated files %%%%; echo
(
cd "$GOROOT"/src/pkg/runtime
./autogen.sh
gomake install # copy runtime.h to pkg directory
gomake install; gomake clean # copy runtime.h to pkg directory
) || exit 1
if $USE_GO_TOOL; then
......@@ -98,7 +98,7 @@ if $USE_GO_TOOL; then
./buildscript_${GOOS}_$GOARCH.sh
echo '# Building Go code.'
GOPATH="" go install -a all
go install -a std
else
echo; echo; echo %%%% making pkg %%%%; echo
gomake -C pkg install
......
......@@ -34,7 +34,7 @@ if $rebuild; then
if $USE_GO_TOOL; then
echo
echo '# Package builds'
time GOPATH="" go install -a all
time go install -a std
else
(xcd pkg
gomake clean
......@@ -46,7 +46,7 @@ fi
if $USE_GO_TOOL; then
echo
echo '# Package tests'
time GOPATH="" go test all -short
time go test std -short
else
(xcd pkg
gomake testshort
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment