]> Cypherpunks repositories - gostls13.git/commitdiff
build: change how cmd/api is run in run.bash and run.bat
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 7 Aug 2013 20:49:37 +0000 (13:49 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 7 Aug 2013 20:49:37 +0000 (13:49 -0700)
In prep for Robert's forthcoming cmd/api rewrite which
depends on the go.tools subrepo, we'll need to be more
careful about how and when we run cmd/api.

Rather than implement this policy in both run.bash and
run.bat, this change moves the policy and mechanism into
cmd/api/run.go, which will then evolve.

The plan is in a TODO in run.go.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/12482044

misc/dist/bindist.go
src/cmd/api/run.go [new file with mode: 0644]
src/run.bash
src/run.bat

index f56a88dc6b518c97d7b548bdbd84c89371ed4f9b..754bd280c234e4be2c984034c3f1d3ae0bce8250 100644 (file)
@@ -50,7 +50,6 @@ const (
 var preBuildCleanFiles = []string{
        "lib/codereview",
        "misc/dashboard/godashboard",
-       "src/cmd/api",
        "src/cmd/cov",
        "src/cmd/prof",
        "src/pkg/exp",
diff --git a/src/cmd/api/run.go b/src/cmd/api/run.go
new file mode 100644 (file)
index 0000000..8137b23
--- /dev/null
@@ -0,0 +1,65 @@
+// +build from_src_run
+
+// Copyright 2013 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// The run program is invoked via "go run" from src/run.bash or
+// src/run.bat conditionally builds and runs the cmd/api tool.
+//
+// TODO(bradfitz): the "conditional" condition is always true.
+// We should only do this if the user has the hg codereview extension
+// enabled and verifies that the go.tools subrepo is checked out with
+// a suitably recently version. In prep for the cmd/api rewrite.
+package main
+
+import (
+       "fmt"
+       "log"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "strconv"
+)
+
+var goroot string
+
+func main() {
+       log.SetFlags(0)
+       goroot = os.Getenv("GOROOT") // should be set by run.{bash,bat}
+       if goroot == "" {
+               log.Fatal("No $GOROOT set.")
+       }
+       isGoDeveloper := exec.Command("hg", "pq").Run() == nil
+       if !isGoDeveloper && !forceAPICheck() {
+               fmt.Println("Skipping cmd/api checks; hg codereview extension not available and GO_FORCE_API_CHECK not set")
+               return
+       }
+
+       out, err := exec.Command("go", "install", "--tags=api_tool", "cmd/api").CombinedOutput()
+       if err != nil {
+               log.Fatalf("Error installing cmd/api: %v\n%s", err, out)
+       }
+       out, err = exec.Command("go", "tool", "api",
+               "-c", file("go1", "go1.1"),
+               "-next", file("next"),
+               "-except", file("except")).CombinedOutput()
+       if err != nil {
+               log.Fatalf("Error running API checker: %v\n%s", err, out)
+       }
+}
+
+// file expands s to $GOROOT/api/s.txt.
+// If there are more than 1, they're comma-separated.
+func file(s ...string) string {
+       if len(s) > 1 {
+               return file(s[0]) + "," + file(s[1:]...)
+       }
+       return filepath.Join(goroot, "api", s[0]+".txt")
+}
+
+// GO_FORCE_API_CHECK is set by builders.
+func forceAPICheck() bool {
+       v, _ := strconv.ParseBool(os.Getenv("GO_FORCE_API_CHECK"))
+       return v
+}
index ded465b66853d1b6ca48fbad35e612aa8ac29c39..178290327a7e1bc027a0ce6e4f07532ef81d6849 100755 (executable)
@@ -180,12 +180,9 @@ unset GOMAXPROCS
 time go run run.go || exit 1
 ) || exit $?
 
-if [ -d "$GOROOT/src/cmd/api" ]
-then
-       echo
-       echo '# Checking API compatibility.'
-       go tool api -c $GOROOT/api/go1.txt,$GOROOT/api/go1.1.txt -next $GOROOT/api/next.txt -except $GOROOT/api/except.txt
-fi
+echo
+echo '# Checking API compatibility.'
+go run --tags=from_src_run $GOROOT/src/cmd/api/run.go
 
 echo
 echo ALL TESTS PASSED
index 724ae2d9f52aa7b61947b07eb9172484dda937c7..36f594bb879ad015647c2fc19194fade5074f7f8 100644 (file)
@@ -121,7 +121,7 @@ set GOMAXPROCS=%OLDGOMAXPROCS%
 set OLDGOMAXPROCS=
 
 echo # Checking API compatibility.
-go tool api -c ..\api\go1.txt,..\api\go1.1.txt -next ..\api\next.txt -except ..\api\except.txt
+go run --tags=from_src_run "%GOROOT%\src\cmd\api\run.go"
 if errorlevel 1 goto fail
 echo.