Commit e068b85b authored by Andrew Gerrand's avatar Andrew Gerrand

goinstall: wait for all commands to finish instead of timeout

goinstall: make ".git" repo suffix optional

R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/4643048
parent 20943bae
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
"time"
) )
const dashboardURL = "http://godashboard.appspot.com/package" const dashboardURL = "http://godashboard.appspot.com/package"
...@@ -58,7 +57,7 @@ type vcs struct { ...@@ -58,7 +57,7 @@ type vcs struct {
check string check string
protocols []string protocols []string
suffix string suffix string
findRepos bool tryPrefixes bool
defaultHosts []host defaultHosts []host
// Is this tool present? (set by findTools) // Is this tool present? (set by findTools)
...@@ -84,7 +83,7 @@ var hg = vcs{ ...@@ -84,7 +83,7 @@ var hg = vcs{
logReleaseFlag: "-rrelease", logReleaseFlag: "-rrelease",
check: "identify", check: "identify",
protocols: []string{"http"}, protocols: []string{"http"},
findRepos: true, tryPrefixes: true,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/hg)(/[a-z0-9A-Z_.\-/]*)?$`), "https"}, {regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/hg)(/[a-z0-9A-Z_.\-/]*)?$`), "https"},
{regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"}, {regexp.MustCompile(`^(bitbucket\.org/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
...@@ -106,7 +105,7 @@ var git = vcs{ ...@@ -106,7 +105,7 @@ var git = vcs{
check: "peek-remote", check: "peek-remote",
protocols: []string{"git", "http"}, protocols: []string{"git", "http"},
suffix: ".git", suffix: ".git",
findRepos: true, tryPrefixes: true,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"}, {regexp.MustCompile(`^(github\.com/[a-z0-9A-Z_.\-]+/[a-z0-9A-Z_.\-]+)(/[a-z0-9A-Z_.\-/]*)?$`), "http"},
}, },
...@@ -125,7 +124,7 @@ var svn = vcs{ ...@@ -125,7 +124,7 @@ var svn = vcs{
logReleaseFlag: "release", logReleaseFlag: "release",
check: "info", check: "info",
protocols: []string{"http", "svn"}, protocols: []string{"http", "svn"},
findRepos: false, tryPrefixes: false,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/svn)(/[a-z0-9A-Z_.\-/]*)?$`), "https"}, {regexp.MustCompile(`^([a-z0-9\-]+\.googlecode\.com/svn)(/[a-z0-9A-Z_.\-/]*)?$`), "https"},
}, },
...@@ -146,7 +145,7 @@ var bzr = vcs{ ...@@ -146,7 +145,7 @@ var bzr = vcs{
logReleaseFlag: "-rrelease", logReleaseFlag: "-rrelease",
check: "info", check: "info",
protocols: []string{"http", "bzr"}, protocols: []string{"http", "bzr"},
findRepos: true, tryPrefixes: true,
defaultHosts: []host{ defaultHosts: []host{
{regexp.MustCompile(`^(launchpad\.net/([a-z0-9A-Z_.\-]+(/[a-z0-9A-Z_.\-]+)?|~[a-z0-9A-Z_.\-]+/(\+junk|[a-z0-9A-Z_.\-]+)/[a-z0-9A-Z_.\-]+))(/[a-z0-9A-Z_.\-/]+)?$`), "https"}, {regexp.MustCompile(`^(launchpad\.net/([a-z0-9A-Z_.\-]+(/[a-z0-9A-Z_.\-]+)?|~[a-z0-9A-Z_.\-]+/(\+junk|[a-z0-9A-Z_.\-]+)/[a-z0-9A-Z_.\-]+))(/[a-z0-9A-Z_.\-/]+)?$`), "https"},
}, },
...@@ -154,29 +153,35 @@ var bzr = vcs{ ...@@ -154,29 +153,35 @@ var bzr = vcs{
var vcsList = []*vcs{&git, &hg, &bzr, &svn} var vcsList = []*vcs{&git, &hg, &bzr, &svn}
func potentialPrefixes(pkg string) []string { func potentialPrefixes(pkg string) (prefixes []string) {
prefixes := []string{}
parts := strings.Split(pkg, "/", -1) parts := strings.Split(pkg, "/", -1)
elem := parts[0] elem := parts[0]
for _, part := range parts[1:] { for _, part := range parts[1:] {
elem = path.Join(elem, part) elem = path.Join(elem, part)
prefixes = append(prefixes, elem) prefixes = append(prefixes, elem)
} }
return
return prefixes
} }
func tryCommand(c chan *vcsMatch, v *vcs, prefixes []string) { func tryCommand(c chan *vcsMatch, v *vcs, prefixes []string) {
// try empty suffix and v.suffix if non-empty
suffixes := []string{""}
if v.suffix != "" {
suffixes = append(suffixes, v.suffix)
}
for _, proto := range v.protocols { for _, proto := range v.protocols {
for _, prefix := range prefixes { for _, prefix := range prefixes {
repo := proto + "://" + prefix + v.suffix for _, suffix := range suffixes {
repo := proto + "://" + prefix + suffix
vlogf("try: %s %s %s\n", v.cmd, v.check, repo)
if exec.Command(v.cmd, v.check, repo).Run() == nil { if exec.Command(v.cmd, v.check, repo).Run() == nil {
c <- &vcsMatch{v, prefix, repo} c <- &vcsMatch{v, prefix, repo}
return return
} }
} }
} }
}
c <- nil
} }
var findToolsOnce sync.Once var findToolsOnce sync.Once
...@@ -198,33 +203,31 @@ func logMissingTools() { ...@@ -198,33 +203,31 @@ func logMissingTools() {
} }
func findVcs(pkg string) *vcsMatch { func findVcs(pkg string) *vcsMatch {
c := make(chan *vcsMatch, len(vcsList))
findToolsOnce.Do(findTools) findToolsOnce.Do(findTools)
// we don't know how much of the name constitutes the repository prefix, so // we don't know how much of the name constitutes the repository prefix
// build a list of possibilities // so build a list of possibilities
prefixes := potentialPrefixes(pkg) prefixes := potentialPrefixes(pkg)
c := make(chan *vcsMatch, len(vcsList))
for _, v := range vcsList { for _, v := range vcsList {
if !v.available { if !v.available {
c <- nil
continue continue
} }
if v.findRepos { if v.tryPrefixes {
go tryCommand(c, v, prefixes) go tryCommand(c, v, prefixes)
} else { } else {
go tryCommand(c, v, []string{pkg}) go tryCommand(c, v, []string{pkg})
} }
} }
for _ = range vcsList {
select { if m := <-c; m != nil {
case m := <-c:
return m return m
case <-time.After(20 * 1e9): }
} }
logMissingToolsOnce.Do(logMissingTools) logMissingToolsOnce.Do(logMissingTools)
return nil return nil
} }
......
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