From 106fbe96e4efe93d20d52ea97591c3faff840346 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 31 Jul 2015 13:14:07 +1000 Subject: [PATCH] cmd/release: locate releaselet source in workspace This allows the release command to be run from any directory. Change-Id: Ia0cac8ad32fb5a232bdf429ec2d8901ffd773d57 Reviewed-on: https://go-review.googlesource.com/12915 Reviewed-by: Andrew Gerrand --- cmd/release/release.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/cmd/release/release.go b/cmd/release/release.go index cc262bc2..21cd8bcd 100644 --- a/cmd/release/release.go +++ b/cmd/release/release.go @@ -14,6 +14,7 @@ import ( "compress/gzip" "flag" "fmt" + gobuild "go/build" "io" "io/ioutil" "log" @@ -46,8 +47,6 @@ var ( var coordClient *buildlet.CoordinatorClient -const releaselet = "releaselet.go" - func main() { flag.Parse() @@ -58,8 +57,8 @@ func main() { return } - if _, err := os.Stat(releaselet); err != nil { - log.Fatalf("couldn't locate %q: %v", releaselet, err) + if err := findReleaselet(); err != nil { + log.Fatalf("couldn't find releaselet source: %v", err) } if *rev == "" { @@ -94,6 +93,28 @@ func main() { wg.Wait() } +var releaselet = "releaselet.go" + +func findReleaselet() error { + // First try the working directory. + if _, err := os.Stat(releaselet); err == nil { + return nil + } + + // Then, try to locate the release command in the workspace. + const importPath = "golang.org/x/build/cmd/release" + pkg, err := gobuild.Import(importPath, "", gobuild.FindOnly) + if err != nil { + return fmt.Errorf("finding %q: %v", importPath, err) + } + r := filepath.Join(pkg.Dir, releaselet) + if _, err := os.Stat(r); err != nil { + return err + } + releaselet = r + return nil +} + type Build struct { OS, Arch string Source bool @@ -362,7 +383,6 @@ func (b *Build) make() error { } b.logf("Pushing and running releaselet.") - // TODO(adg): locate releaselet.go in GOPATH f, err := os.Open(releaselet) if err != nil { return err