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