summaryrefslogtreecommitdiff
path: root/src/cmd/goinstall/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/goinstall/main.go')
-rw-r--r--src/cmd/goinstall/main.go91
1 files changed, 75 insertions, 16 deletions
diff --git a/src/cmd/goinstall/main.go b/src/cmd/goinstall/main.go
index 60efdf082..b0f08efdf 100644
--- a/src/cmd/goinstall/main.go
+++ b/src/cmd/goinstall/main.go
@@ -11,28 +11,37 @@ import (
"exec"
"flag"
"fmt"
+ "go/token"
"io"
+ "io/ioutil"
"os"
"path"
+ "runtime"
"strings"
)
func usage() {
fmt.Fprint(os.Stderr, "usage: goinstall importpath...\n")
+ fmt.Fprintf(os.Stderr, "\tgoinstall -a\n")
flag.PrintDefaults()
os.Exit(2)
}
var (
- argv0 = os.Args[0]
- errors = false
- gobin = os.Getenv("GOBIN")
- parents = make(map[string]string)
- root = os.Getenv("GOROOT")
- visit = make(map[string]status)
+ fset = token.NewFileSet()
+ argv0 = os.Args[0]
+ errors = false
+ parents = make(map[string]string)
+ root = runtime.GOROOT()
+ visit = make(map[string]status)
+ logfile = path.Join(root, "goinstall.log")
+ installedPkgs = make(map[string]bool)
+ allpkg = flag.Bool("a", false, "install all previously installed packages")
reportToDashboard = flag.Bool("dashboard", true, "report public packages at "+dashboardURL)
+ logPkgs = flag.Bool("log", true, "log installed packages to $GOROOT/goinstall.log for use by -a")
update = flag.Bool("u", false, "update already-downloaded packages")
+ clean = flag.Bool("clean", false, "clean the package directory before installing")
verbose = flag.Bool("v", false, "verbose")
)
@@ -51,15 +60,30 @@ func main() {
os.Exit(1)
}
root += "/src/pkg/"
- if gobin == "" {
- gobin = os.Getenv("HOME") + "/bin"
- }
// special case - "unsafe" is already installed
visit["unsafe"] = done
- // install command line arguments
args := flag.Args()
+ if *allpkg || *logPkgs {
+ readPackageList()
+ }
+ if *allpkg {
+ if len(args) != 0 {
+ usage() // -a and package list both provided
+ }
+ // install all packages that were ever installed
+ if len(installedPkgs) == 0 {
+ fmt.Fprintf(os.Stderr, "%s: no installed packages\n", argv0)
+ os.Exit(1)
+ }
+ args = make([]string, len(installedPkgs), len(installedPkgs))
+ i := 0
+ for pkg := range installedPkgs {
+ args[i] = pkg
+ i++
+ }
+ }
if len(args) == 0 {
usage()
}
@@ -82,6 +106,29 @@ func printDeps(pkg string) {
fmt.Fprintf(os.Stderr, "\t%s ->\n", pkg)
}
+// readPackageList reads the list of installed packages from goinstall.log
+func readPackageList() {
+ pkglistdata, _ := ioutil.ReadFile(logfile)
+ pkglist := strings.Fields(string(pkglistdata))
+ for _, pkg := range pkglist {
+ installedPkgs[pkg] = true
+ }
+}
+
+// logPackage logs the named package as installed in goinstall.log, if the package is not found in there
+func logPackage(pkg string) {
+ if installedPkgs[pkg] {
+ return
+ }
+ fout, err := os.Open(logfile, os.O_WRONLY|os.O_APPEND|os.O_CREAT, 0644)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%s: %s\n", argv0, err)
+ return
+ }
+ fmt.Fprintf(fout, "%s\n", pkg)
+ fout.Close()
+}
+
// install installs the package named by path, which is needed by parent.
func install(pkg, parent string) {
// Make sure we're not already trying to install pkg.
@@ -104,6 +151,11 @@ func install(pkg, parent string) {
// If remote, download or update it.
var dir string
local := false
+ if strings.HasPrefix(pkg, "http://") {
+ fmt.Fprintf(os.Stderr, "%s: %s: 'http://' used in remote path, try '%s'\n", argv0, pkg, pkg[7:])
+ errors = true
+ return
+ }
if isLocalPath(pkg) {
dir = pkg
local = true
@@ -122,23 +174,25 @@ func install(pkg, parent string) {
}
// Install prerequisites.
- files, m, pkgname, err := goFiles(dir, parent == "")
+ dirInfo, err := scanDir(dir, parent == "")
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s: %s\n", argv0, pkg, err)
errors = true
visit[pkg] = done
return
}
- if len(files) == 0 {
+ if len(dirInfo.goFiles) == 0 {
fmt.Fprintf(os.Stderr, "%s: %s: package has no files\n", argv0, pkg)
errors = true
visit[pkg] = done
return
}
- for p := range m {
- install(p, pkg)
+ for _, p := range dirInfo.imports {
+ if p != "C" {
+ install(p, pkg)
+ }
}
- if pkgname == "main" {
+ if dirInfo.pkgName == "main" {
if !errors {
fmt.Fprintf(os.Stderr, "%s: %s's dependencies are installed.\n", argv0, pkg)
}
@@ -152,9 +206,11 @@ func install(pkg, parent string) {
if err := domake(dir, pkg, local); err != nil {
fmt.Fprintf(os.Stderr, "%s: installing %s: %s\n", argv0, pkg, err)
errors = true
+ } else if !local && *logPkgs {
+ // mark this package as installed in $GOROOT/goinstall.log
+ logPackage(pkg)
}
}
-
visit[pkg] = done
}
@@ -207,6 +263,9 @@ func genRun(dir string, stdin []byte, cmd []string, quiet bool) os.Error {
io.Copy(&buf, p.Stdout)
w, err := p.Wait(0)
p.Close()
+ if err != nil {
+ return err
+ }
if !w.Exited() || w.ExitStatus() != 0 {
if !quiet || *verbose {
if dir != "" {