2012-02-29 21:49:37 -07:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
|
|
|
// This is a tool for packaging binary releases.
|
2013-10-10 19:37:32 -06:00
|
|
|
// It supports FreeBSD, Linux, NetBSD, OpenBSD, OS X, and Windows.
|
2012-02-29 21:49:37 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2012-03-12 00:07:38 -06:00
|
|
|
"archive/tar"
|
2012-03-11 22:02:40 -06:00
|
|
|
"archive/zip"
|
2012-03-05 14:55:53 -07:00
|
|
|
"bufio"
|
2012-02-29 21:49:37 -07:00
|
|
|
"bytes"
|
2012-03-12 00:07:38 -06:00
|
|
|
"compress/gzip"
|
2014-06-01 20:46:03 -06:00
|
|
|
"crypto/sha1"
|
|
|
|
"encoding/json"
|
2014-12-09 19:05:37 -07:00
|
|
|
"errors"
|
2012-02-29 21:49:37 -07:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2014-06-01 20:46:03 -06:00
|
|
|
"net/url"
|
2012-02-29 21:49:37 -07:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2013-10-10 19:37:32 -06:00
|
|
|
"path"
|
2012-02-29 21:49:37 -07:00
|
|
|
"path/filepath"
|
2012-03-27 19:24:43 -06:00
|
|
|
"regexp"
|
2012-03-08 18:57:38 -07:00
|
|
|
"runtime"
|
2012-02-29 21:49:37 -07:00
|
|
|
"strings"
|
2014-05-28 16:40:15 -06:00
|
|
|
|
2014-12-09 19:05:37 -07:00
|
|
|
storage "code.google.com/p/google-api-go-client/storage/v1"
|
2015-01-14 03:39:18 -07:00
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"golang.org/x/oauth2/google"
|
2012-02-29 21:49:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-01-14 03:39:18 -07:00
|
|
|
tag = flag.String("tag", "", "git revision to check out")
|
|
|
|
toolTag = flag.String("tool", defaultToolTag, "go.tools revision to check out")
|
2014-02-27 17:09:26 -07:00
|
|
|
tourTag = flag.String("tour", defaultTourTag, "go-tour tag to check out")
|
2015-01-14 03:39:18 -07:00
|
|
|
repo = flag.String("repo", "https://go.googlesource.com/go", "repo URL")
|
2013-04-03 21:21:19 -06:00
|
|
|
verbose = flag.Bool("v", false, "verbose output")
|
2014-02-27 17:09:26 -07:00
|
|
|
upload = flag.Bool("upload", false, "upload resulting files to Google Code")
|
2013-04-03 21:21:19 -06:00
|
|
|
addLabel = flag.String("label", "", "additional label to apply to file when uploading")
|
|
|
|
includeRace = flag.Bool("race", true, "build race detector packages")
|
|
|
|
versionOverride = flag.String("version", "", "override version name")
|
2013-10-02 18:14:54 -06:00
|
|
|
staticToolchain = flag.Bool("static", true, "try to build statically linked toolchain (only supported on ELF targets)")
|
2014-05-28 16:40:15 -06:00
|
|
|
tokenCache = flag.String("token", defaultCacheFile, "Authentication token cache file")
|
|
|
|
storageBucket = flag.String("bucket", "golang", "Cloud Storage Bucket")
|
2014-06-01 20:46:03 -06:00
|
|
|
uploadURL = flag.String("upload_url", defaultUploadURL, "Upload URL")
|
2012-02-29 21:49:37 -07:00
|
|
|
|
2014-05-28 16:40:15 -06:00
|
|
|
defaultCacheFile = filepath.Join(os.Getenv("HOME"), ".makerelease-request-token")
|
2014-06-01 20:46:03 -06:00
|
|
|
defaultUploadURL = "http://golang.org/dl/upload"
|
2012-02-29 21:49:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2014-11-09 15:15:57 -07:00
|
|
|
blogPath = "golang.org/x/blog"
|
|
|
|
toolPath = "golang.org/x/tools"
|
2013-09-19 00:51:29 -06:00
|
|
|
tourPath = "code.google.com/p/go-tour"
|
2014-11-16 17:27:53 -07:00
|
|
|
defaultToolTag = "release-branch.go1.4"
|
|
|
|
defaultTourTag = "release-branch.go1.4"
|
2012-02-29 21:49:37 -07:00
|
|
|
)
|
|
|
|
|
2013-09-12 18:28:30 -06:00
|
|
|
// Import paths for tool commands.
|
|
|
|
// These must be the command that cmd/go knows to install to $GOROOT/bin
|
|
|
|
// or $GOROOT/pkg/tool.
|
|
|
|
var toolPaths = []string{
|
2014-11-09 15:15:57 -07:00
|
|
|
"golang.org/x/tools/cmd/cover",
|
|
|
|
"golang.org/x/tools/cmd/godoc",
|
|
|
|
"golang.org/x/tools/cmd/vet",
|
2013-09-12 18:28:30 -06:00
|
|
|
}
|
|
|
|
|
2012-03-14 06:47:34 -06:00
|
|
|
var preBuildCleanFiles = []string{
|
2012-03-26 17:38:10 -06:00
|
|
|
"lib/codereview",
|
|
|
|
"misc/dashboard/godashboard",
|
2012-03-15 16:22:56 -06:00
|
|
|
"src/cmd/cov",
|
|
|
|
"src/cmd/prof",
|
2014-09-07 22:06:45 -06:00
|
|
|
"src/exp",
|
|
|
|
"src/old",
|
2012-03-14 06:47:34 -06:00
|
|
|
}
|
|
|
|
|
2012-02-29 21:49:37 -07:00
|
|
|
var cleanFiles = []string{
|
2015-01-14 03:39:18 -07:00
|
|
|
".git",
|
|
|
|
".gitignore",
|
|
|
|
".gitattributes",
|
2012-02-29 21:49:37 -07:00
|
|
|
"VERSION.cache",
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:13:26 -07:00
|
|
|
var sourceCleanFiles = []string{
|
|
|
|
"bin",
|
|
|
|
"pkg",
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:46:49 -07:00
|
|
|
var tourPackages = []string{
|
|
|
|
"pic",
|
|
|
|
"tree",
|
|
|
|
"wc",
|
|
|
|
}
|
|
|
|
|
|
|
|
var tourContent = []string{
|
2013-09-12 18:28:30 -06:00
|
|
|
"content",
|
2013-01-28 22:46:49 -07:00
|
|
|
"solutions",
|
|
|
|
"static",
|
|
|
|
"template",
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:51:29 -06:00
|
|
|
var blogContent = []string{
|
|
|
|
"content",
|
|
|
|
"template",
|
|
|
|
}
|
|
|
|
|
2013-04-03 21:46:54 -06:00
|
|
|
// The os-arches that support the race toolchain.
|
|
|
|
var raceAvailable = []string{
|
|
|
|
"darwin-amd64",
|
|
|
|
"linux-amd64",
|
|
|
|
"windows-amd64",
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:14:54 -06:00
|
|
|
// The OSes that support building statically linked toolchain
|
|
|
|
// Only ELF platforms are supported.
|
|
|
|
var staticLinkAvailable = []string{
|
|
|
|
"linux",
|
|
|
|
"freebsd",
|
|
|
|
"openbsd",
|
|
|
|
"netbsd",
|
|
|
|
}
|
|
|
|
|
2013-11-17 19:30:25 -07:00
|
|
|
var fileRe = regexp.MustCompile(`^(go[a-z0-9-.]+)\.(src|([a-z0-9]+)-([a-z0-9]+)(?:-([a-z0-9.]+))?)\.(tar\.gz|zip|pkg|msi)$`)
|
2012-03-27 19:24:43 -06:00
|
|
|
|
2014-05-28 16:40:15 -06:00
|
|
|
// OAuth2-authenticated HTTP client used to make calls to Cloud Storage.
|
|
|
|
var oauthClient *http.Client
|
|
|
|
|
|
|
|
// Builder key as specified in ~/.gobuildkey
|
|
|
|
var builderKey string
|
|
|
|
|
2012-02-29 21:49:37 -07:00
|
|
|
func main() {
|
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Fprintf(os.Stderr, "usage: %s [flags] targets...\n", os.Args[0])
|
|
|
|
flag.PrintDefaults()
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
flag.Parse()
|
2015-01-14 03:39:18 -07:00
|
|
|
if *tag == "" {
|
|
|
|
fmt.Fprintln(os.Stderr, "you must specify a -tag")
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
if flag.NArg() == 0 {
|
|
|
|
flag.Usage()
|
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
checkWindowsDeps()
|
|
|
|
}
|
|
|
|
|
|
|
|
if *upload {
|
|
|
|
if err := readCredentials(); err != nil {
|
2014-05-28 16:40:15 -06:00
|
|
|
log.Fatalln("readCredentials:", err)
|
|
|
|
}
|
|
|
|
if err := setupOAuthClient(); err != nil {
|
|
|
|
log.Fatalln("setupOAuthClient:", err)
|
2012-03-11 22:02:40 -06:00
|
|
|
}
|
2012-03-05 14:55:53 -07:00
|
|
|
}
|
2014-08-12 22:00:10 -06:00
|
|
|
ok := true
|
2012-02-29 21:49:37 -07:00
|
|
|
for _, targ := range flag.Args() {
|
2012-03-06 19:13:26 -07:00
|
|
|
var b Build
|
2012-03-27 19:24:43 -06:00
|
|
|
if m := fileRe.FindStringSubmatch(targ); m != nil {
|
|
|
|
// targ is a file name; upload it to googlecode.
|
|
|
|
version := m[1]
|
|
|
|
if m[2] == "src" {
|
|
|
|
b.Source = true
|
|
|
|
} else {
|
|
|
|
b.OS = m[3]
|
|
|
|
b.Arch = m[4]
|
2013-09-19 00:51:29 -06:00
|
|
|
b.Label = m[5]
|
2012-03-27 19:24:43 -06:00
|
|
|
}
|
|
|
|
if !*upload {
|
|
|
|
log.Printf("%s: -upload=false, skipping", targ)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := b.Upload(version, targ); err != nil {
|
2014-06-01 20:46:03 -06:00
|
|
|
log.Printf("uploading %s: %v", targ, err)
|
2012-03-27 19:24:43 -06:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2012-03-06 19:13:26 -07:00
|
|
|
if targ == "source" {
|
|
|
|
b.Source = true
|
|
|
|
} else {
|
2013-09-19 00:51:29 -06:00
|
|
|
p := strings.SplitN(targ, "-", 3)
|
|
|
|
if len(p) < 2 {
|
2012-03-06 19:13:26 -07:00
|
|
|
log.Println("Ignoring unrecognized target:", targ)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
b.OS = p[0]
|
|
|
|
b.Arch = p[1]
|
2013-09-19 00:51:29 -06:00
|
|
|
if len(p) >= 3 {
|
|
|
|
b.Label = p[2]
|
|
|
|
}
|
2013-04-03 21:46:54 -06:00
|
|
|
if *includeRace {
|
|
|
|
for _, t := range raceAvailable {
|
2013-10-18 00:03:41 -06:00
|
|
|
if t == targ || strings.HasPrefix(targ, t+"-") {
|
2013-04-03 21:46:54 -06:00
|
|
|
b.Race = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 18:14:54 -06:00
|
|
|
if *staticToolchain {
|
|
|
|
for _, os := range staticLinkAvailable {
|
|
|
|
if b.OS == os {
|
|
|
|
b.static = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
if err := b.Do(); err != nil {
|
|
|
|
log.Printf("%s: %v", targ, err)
|
2014-08-12 22:00:10 -06:00
|
|
|
ok = false
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
}
|
2014-08-12 22:00:10 -06:00
|
|
|
if !ok {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Build struct {
|
2012-03-06 19:13:26 -07:00
|
|
|
Source bool // if true, OS and Arch must be empty
|
2013-04-03 21:46:54 -06:00
|
|
|
Race bool // build race toolchain
|
2012-03-06 19:13:26 -07:00
|
|
|
OS string
|
|
|
|
Arch string
|
2013-09-19 00:51:29 -06:00
|
|
|
Label string
|
2012-03-06 19:13:26 -07:00
|
|
|
root string
|
2013-01-28 22:46:49 -07:00
|
|
|
gopath string
|
2013-10-02 18:14:54 -06:00
|
|
|
static bool // if true, build statically linked toolchain
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Build) Do() error {
|
2013-12-10 20:47:18 -07:00
|
|
|
work, err := ioutil.TempDir("", "makerelease")
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(work)
|
|
|
|
b.root = filepath.Join(work, "go")
|
2013-01-28 22:46:49 -07:00
|
|
|
b.gopath = work
|
2012-02-29 21:49:37 -07:00
|
|
|
|
|
|
|
// Clone Go distribution and update to tag.
|
2015-01-14 03:39:18 -07:00
|
|
|
_, err = b.run(work, "git", "clone", *repo, b.root)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-01-14 03:39:18 -07:00
|
|
|
_, err = b.run(b.root, "git", "checkout", *tag)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2012-03-14 06:47:34 -06:00
|
|
|
// Remove exp and old packages.
|
|
|
|
if err := b.clean(preBuildCleanFiles); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:13:26 -07:00
|
|
|
src := filepath.Join(b.root, "src")
|
|
|
|
if b.Source {
|
2012-03-11 22:02:40 -06:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
log.Print("Warning: running make.bash on Windows; source builds are intended to be run on a Unix machine")
|
|
|
|
}
|
2012-03-06 19:13:26 -07:00
|
|
|
// Build dist tool only.
|
|
|
|
_, err = b.run(src, "bash", "make.bash", "--dist-tool")
|
2012-03-05 14:55:53 -07:00
|
|
|
} else {
|
2012-03-06 19:13:26 -07:00
|
|
|
// Build.
|
|
|
|
if b.OS == "windows" {
|
|
|
|
_, err = b.run(src, "cmd", "/C", "make.bat")
|
|
|
|
} else {
|
|
|
|
_, err = b.run(src, "bash", "make.bash")
|
|
|
|
}
|
2013-04-03 21:46:54 -06:00
|
|
|
if b.Race {
|
2013-04-03 21:21:19 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
goCmd := filepath.Join(b.root, "bin", "go")
|
|
|
|
if b.OS == "windows" {
|
|
|
|
goCmd += ".exe"
|
|
|
|
}
|
|
|
|
_, err = b.run(src, goCmd, "install", "-race", "std")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-04-03 21:46:54 -06:00
|
|
|
// Re-install std without -race, so that we're not left
|
2013-08-01 00:48:31 -06:00
|
|
|
// with a slower, race-enabled cmd/go, etc.
|
2013-04-03 21:21:19 -06:00
|
|
|
_, err = b.run(src, goCmd, "install", "-a", "std")
|
2013-05-29 20:11:17 -06:00
|
|
|
// Re-building go command leaves old versions of go.exe as go.exe~ on windows.
|
|
|
|
// See (*builder).copyFile in $GOROOT/src/cmd/go/build.go for details.
|
|
|
|
// Remove it manually.
|
|
|
|
if b.OS == "windows" {
|
|
|
|
os.Remove(goCmd + "~")
|
|
|
|
}
|
2013-04-03 15:06:29 -06:00
|
|
|
}
|
2013-04-03 19:07:53 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-02-27 17:09:26 -07:00
|
|
|
err = b.extras()
|
2013-04-03 15:06:29 -06:00
|
|
|
}
|
2013-04-03 21:21:19 -06:00
|
|
|
if err != nil {
|
2013-01-28 22:46:49 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:13:26 -07:00
|
|
|
// Get version strings.
|
|
|
|
var (
|
|
|
|
version string // "weekly.2012-03-04"
|
|
|
|
fullVersion []byte // "weekly.2012-03-04 9353aa1efdf3"
|
|
|
|
)
|
2014-02-27 17:09:26 -07:00
|
|
|
pat := filepath.Join(b.root, "pkg/tool/*/dist*") // trailing * for .exe
|
2012-03-06 19:13:26 -07:00
|
|
|
m, err := filepath.Glob(pat)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-06 19:13:26 -07:00
|
|
|
if len(m) == 0 {
|
2014-02-27 17:09:26 -07:00
|
|
|
return fmt.Errorf("couldn't find dist in %q", pat)
|
2012-03-06 19:13:26 -07:00
|
|
|
}
|
|
|
|
fullVersion, err = b.run("", m[0], "version")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-12 22:31:39 -06:00
|
|
|
fullVersion = bytes.TrimSpace(fullVersion)
|
2012-03-06 19:13:26 -07:00
|
|
|
v := bytes.SplitN(fullVersion, []byte(" "), 2)
|
|
|
|
version = string(v[0])
|
2013-04-03 21:21:19 -06:00
|
|
|
if *versionOverride != "" {
|
|
|
|
version = *versionOverride
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
|
|
|
|
// Write VERSION file.
|
2012-03-06 19:13:26 -07:00
|
|
|
err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), fullVersion, 0644)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean goroot.
|
2012-03-06 19:13:26 -07:00
|
|
|
if err := b.clean(cleanFiles); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if b.Source {
|
|
|
|
if err := b.clean(sourceCleanFiles); err != nil {
|
2012-02-29 21:49:37 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create packages.
|
2012-04-26 14:25:53 -06:00
|
|
|
base := fmt.Sprintf("%s.%s-%s", version, b.OS, b.Arch)
|
2013-09-19 00:51:29 -06:00
|
|
|
if b.Label != "" {
|
|
|
|
base += "-" + b.Label
|
|
|
|
}
|
2012-04-26 14:25:53 -06:00
|
|
|
if !strings.HasPrefix(base, "go") {
|
|
|
|
base = "go." + base
|
|
|
|
}
|
2012-03-08 18:57:38 -07:00
|
|
|
var targs []string
|
2012-02-29 21:49:37 -07:00
|
|
|
switch b.OS {
|
2012-10-16 01:53:17 -06:00
|
|
|
case "linux", "freebsd", "netbsd", "":
|
2012-02-29 21:49:37 -07:00
|
|
|
// build tarball
|
2012-03-11 22:02:40 -06:00
|
|
|
targ := base
|
2012-03-06 19:13:26 -07:00
|
|
|
if b.Source {
|
2012-04-26 14:25:53 -06:00
|
|
|
targ = fmt.Sprintf("%s.src", version)
|
|
|
|
if !strings.HasPrefix(targ, "go") {
|
|
|
|
targ = "go." + targ
|
|
|
|
}
|
2012-03-06 19:13:26 -07:00
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
targ += ".tar.gz"
|
2012-03-12 00:07:38 -06:00
|
|
|
err = makeTar(targ, work)
|
2012-03-08 18:57:38 -07:00
|
|
|
targs = append(targs, targ)
|
2012-02-29 21:49:37 -07:00
|
|
|
case "darwin":
|
2012-09-17 17:59:16 -06:00
|
|
|
// build tarball
|
|
|
|
targ := base + ".tar.gz"
|
|
|
|
err = makeTar(targ, work)
|
|
|
|
targs = append(targs, targ)
|
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
makerelease := filepath.Join(runtime.GOROOT(), "misc/makerelease")
|
|
|
|
|
2012-09-17 17:59:16 -06:00
|
|
|
// build pkg
|
2012-02-29 21:49:37 -07:00
|
|
|
// arrange work so it's laid out as the dest filesystem
|
2014-02-27 17:09:26 -07:00
|
|
|
etc := filepath.Join(makerelease, "darwin/etc")
|
2012-02-29 21:49:37 -07:00
|
|
|
_, err = b.run(work, "cp", "-r", etc, ".")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
localDir := filepath.Join(work, "usr/local")
|
2012-04-23 15:56:03 -06:00
|
|
|
err = os.MkdirAll(localDir, 0755)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = b.run(work, "mv", "go", localDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// build package
|
2012-04-23 15:56:03 -06:00
|
|
|
pkgdest, err := ioutil.TempDir("", "pkgdest")
|
2012-04-02 00:34:11 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-04-23 15:56:03 -06:00
|
|
|
defer os.RemoveAll(pkgdest)
|
|
|
|
_, err = b.run("", "pkgbuild",
|
|
|
|
"--identifier", "com.googlecode.go",
|
2013-09-08 17:36:39 -06:00
|
|
|
"--version", version,
|
2013-12-10 20:47:18 -07:00
|
|
|
"--scripts", filepath.Join(makerelease, "darwin/scripts"),
|
2012-04-23 15:56:03 -06:00
|
|
|
"--root", work,
|
|
|
|
filepath.Join(pkgdest, "com.googlecode.go.pkg"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2012-09-17 17:59:16 -06:00
|
|
|
targ = base + ".pkg"
|
2012-04-23 15:56:03 -06:00
|
|
|
_, err = b.run("", "productbuild",
|
2013-12-10 20:47:18 -07:00
|
|
|
"--distribution", filepath.Join(makerelease, "darwin/Distribution"),
|
|
|
|
"--resources", filepath.Join(makerelease, "darwin/Resources"),
|
2012-04-23 15:56:03 -06:00
|
|
|
"--package-path", pkgdest,
|
|
|
|
targ)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-08 18:57:38 -07:00
|
|
|
targs = append(targs, targ)
|
2012-03-05 14:55:53 -07:00
|
|
|
case "windows":
|
2012-03-08 18:57:38 -07:00
|
|
|
// Create ZIP file.
|
|
|
|
zip := filepath.Join(work, base+".zip")
|
2012-03-11 22:02:40 -06:00
|
|
|
err = makeZip(zip, work)
|
2012-03-08 18:57:38 -07:00
|
|
|
// Copy zip to target file.
|
|
|
|
targ := base + ".zip"
|
|
|
|
err = cp(targ, zip)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
targs = append(targs, targ)
|
|
|
|
|
|
|
|
// Create MSI installer.
|
2014-03-02 18:50:29 -07:00
|
|
|
win := filepath.Join(runtime.GOROOT(), "misc/makerelease/windows")
|
2012-03-05 14:55:53 -07:00
|
|
|
installer := filepath.Join(win, "installer.wxs")
|
|
|
|
appfiles := filepath.Join(work, "AppFiles.wxs")
|
|
|
|
msi := filepath.Join(work, "installer.msi")
|
|
|
|
// Gather files.
|
|
|
|
_, err = b.run(work, "heat", "dir", "go",
|
|
|
|
"-nologo",
|
|
|
|
"-gg", "-g1", "-srd", "-sfrag",
|
|
|
|
"-cg", "AppFiles",
|
|
|
|
"-template", "fragment",
|
|
|
|
"-dr", "INSTALLDIR",
|
|
|
|
"-var", "var.SourceDir",
|
|
|
|
"-out", appfiles)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Build package.
|
|
|
|
_, err = b.run(work, "candle",
|
|
|
|
"-nologo",
|
2014-10-21 17:56:26 -06:00
|
|
|
"-dGoVersion="+version,
|
|
|
|
"-dWixGoVersion="+wixVersion(version),
|
2012-03-05 14:55:53 -07:00
|
|
|
"-dArch="+b.Arch,
|
|
|
|
"-dSourceDir=go",
|
|
|
|
installer, appfiles)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
appfiles = filepath.Join(work, "AppFiles.wixobj")
|
|
|
|
installer = filepath.Join(work, "installer.wixobj")
|
|
|
|
_, err = b.run(win, "light",
|
|
|
|
"-nologo",
|
|
|
|
"-ext", "WixUIExtension",
|
|
|
|
"-ext", "WixUtilExtension",
|
|
|
|
installer, appfiles,
|
|
|
|
"-o", msi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Copy installer to target file.
|
2012-03-08 18:57:38 -07:00
|
|
|
targ = base + ".msi"
|
2012-03-05 14:55:53 -07:00
|
|
|
err = cp(targ, msi)
|
2012-03-08 18:57:38 -07:00
|
|
|
targs = append(targs, targ)
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
if err == nil && *upload {
|
2012-03-08 18:57:38 -07:00
|
|
|
for _, targ := range targs {
|
2012-03-27 19:24:43 -06:00
|
|
|
err = b.Upload(version, targ)
|
2012-03-08 18:57:38 -07:00
|
|
|
if err != nil {
|
2014-06-01 20:46:03 -06:00
|
|
|
return fmt.Errorf("uploading %s: %v", targ, err)
|
2012-03-08 18:57:38 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-10-21 17:56:26 -06:00
|
|
|
var versionRe = regexp.MustCompile(`^go([0-9]+(\.[0-9]+)*)`)
|
|
|
|
|
|
|
|
// The Microsoft installer requires version format major.minor.build
|
|
|
|
// (http://msdn.microsoft.com/en-us/library/aa370859%28v=vs.85%29.aspx).
|
|
|
|
// Where the major and minor field has a maximum value of 255 and build 65535.
|
|
|
|
// The offical Go version format is goMAJOR.MINOR.PATCH at $GOROOT/VERSION.
|
|
|
|
// It's based on the Mercurial tag. Remove prefix and suffix to make the
|
|
|
|
// installer happy.
|
|
|
|
func wixVersion(v string) string {
|
|
|
|
m := versionRe.FindStringSubmatch(v)
|
|
|
|
if m == nil {
|
|
|
|
return "0.0.0"
|
|
|
|
}
|
|
|
|
return m[1]
|
|
|
|
}
|
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
// extras fetches the go.tools, go.blog, and go-tour repositories,
|
|
|
|
// builds them and copies the resulting binaries and static assets
|
|
|
|
// to the new GOROOT.
|
|
|
|
func (b *Build) extras() error {
|
2013-09-19 00:51:29 -06:00
|
|
|
defer b.cleanGopath()
|
2013-08-01 00:48:31 -06:00
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
if err := b.tools(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := b.blog(); err != nil {
|
2013-09-12 18:28:30 -06:00
|
|
|
return err
|
|
|
|
}
|
2014-02-27 17:09:26 -07:00
|
|
|
return b.tour()
|
|
|
|
}
|
2013-09-12 18:28:30 -06:00
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
func (b *Build) get(repoPath, revision string) error {
|
2014-12-14 16:17:00 -07:00
|
|
|
// Fetch the packages (without building/installing).
|
|
|
|
_, err := b.run(b.gopath, filepath.Join(b.root, "bin", "go"),
|
|
|
|
"get", "-d", repoPath+"/...")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2013-09-12 18:28:30 -06:00
|
|
|
}
|
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
// Update the repo to the specified revision.
|
2014-12-09 19:05:37 -07:00
|
|
|
dest := filepath.Join(b.gopath, "src", filepath.FromSlash(repoPath))
|
|
|
|
switch {
|
|
|
|
case exists(filepath.Join(dest, ".git")):
|
|
|
|
_, err = b.run(dest, "git", "checkout", revision)
|
|
|
|
case exists(filepath.Join(dest, ".hg")):
|
|
|
|
_, err = b.run(dest, "hg", "update", revision)
|
|
|
|
default:
|
|
|
|
err = errors.New("unknown version control system")
|
|
|
|
}
|
2014-02-27 17:09:26 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Build) tools() error {
|
|
|
|
// Fetch the go.tools repository.
|
|
|
|
if err := b.get(toolPath, *toolTag); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2013-09-12 18:28:30 -06:00
|
|
|
// Install tools.
|
2014-02-27 17:09:26 -07:00
|
|
|
args := append([]string{"install"}, toolPaths...)
|
|
|
|
_, err := b.run(b.gopath, filepath.Join(b.root, "bin", "go"), args...)
|
2013-10-10 19:37:32 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy doc.go from go.tools/cmd/$CMD to $GOROOT/src/cmd/$CMD
|
|
|
|
// while rewriting "package main" to "package documentation".
|
|
|
|
for _, p := range toolPaths {
|
|
|
|
d, err := ioutil.ReadFile(filepath.Join(b.gopath, "src",
|
|
|
|
filepath.FromSlash(p), "doc.go"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d = bytes.Replace(d, []byte("\npackage main\n"),
|
|
|
|
[]byte("\npackage documentation\n"), 1)
|
|
|
|
cmdDir := filepath.Join(b.root, "src", "cmd", path.Base(p))
|
|
|
|
if err := os.MkdirAll(cmdDir, 0755); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
docGo := filepath.Join(cmdDir, "doc.go")
|
|
|
|
if err := ioutil.WriteFile(docGo, d, 0644); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2013-08-01 00:48:31 -06:00
|
|
|
}
|
|
|
|
|
2013-09-19 00:51:29 -06:00
|
|
|
func (b *Build) blog() error {
|
|
|
|
// Fetch the blog repository.
|
|
|
|
_, err := b.run(b.gopath, filepath.Join(b.root, "bin", "go"), "get", "-d", blogPath+"/blog")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy blog content to $GOROOT/blog.
|
|
|
|
blogSrc := filepath.Join(b.gopath, "src", filepath.FromSlash(blogPath))
|
|
|
|
contentDir := filepath.Join(b.root, "blog")
|
|
|
|
return cpAllDir(contentDir, blogSrc, blogContent...)
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:46:49 -07:00
|
|
|
func (b *Build) tour() error {
|
2014-02-27 17:09:26 -07:00
|
|
|
// Fetch the go-tour repository.
|
|
|
|
if err := b.get(tourPath, *tourTag); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-07-07 19:45:33 -06:00
|
|
|
|
2014-02-27 17:09:26 -07:00
|
|
|
// Build tour binary.
|
|
|
|
_, err := b.run(b.gopath, filepath.Join(b.root, "bin", "go"),
|
|
|
|
"install", tourPath+"/gotour")
|
2013-01-28 22:46:49 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy all the tour content to $GOROOT/misc/tour.
|
2013-08-01 00:48:31 -06:00
|
|
|
importPath := filepath.FromSlash(tourPath)
|
2013-01-28 22:46:49 -07:00
|
|
|
tourSrc := filepath.Join(b.gopath, "src", importPath)
|
|
|
|
contentDir := filepath.Join(b.root, "misc", "tour")
|
|
|
|
if err = cpAllDir(contentDir, tourSrc, tourContent...); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the tour source code so it's accessible with $GOPATH pointing to $GOROOT/misc/tour.
|
|
|
|
if err = cpAllDir(filepath.Join(contentDir, "src", importPath), tourSrc, tourPackages...); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy gotour binary to tool directory as "tour"; invoked as "go tool tour".
|
|
|
|
return cp(
|
2013-08-01 00:48:31 -06:00
|
|
|
filepath.Join(b.root, "pkg", "tool", b.OS+"_"+b.Arch, "tour"+ext()),
|
|
|
|
filepath.Join(b.gopath, "bin", "gotour"+ext()),
|
2013-01-28 22:46:49 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:51:29 -06:00
|
|
|
func (b *Build) cleanGopath() {
|
|
|
|
for _, d := range []string{"bin", "pkg", "src"} {
|
|
|
|
os.RemoveAll(filepath.Join(b.gopath, d))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 00:48:31 -06:00
|
|
|
func ext() string {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return ".exe"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2012-02-29 21:49:37 -07:00
|
|
|
func (b *Build) run(dir, name string, args ...string) ([]byte, error) {
|
|
|
|
buf := new(bytes.Buffer)
|
2012-03-11 22:02:40 -06:00
|
|
|
absName, err := lookPath(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cmd := exec.Command(absName, args...)
|
|
|
|
var output io.Writer = buf
|
|
|
|
if *verbose {
|
|
|
|
log.Printf("Running %q %q", absName, args)
|
|
|
|
output = io.MultiWriter(buf, os.Stdout)
|
|
|
|
}
|
|
|
|
cmd.Stdout = output
|
|
|
|
cmd.Stderr = output
|
2012-02-29 21:49:37 -07:00
|
|
|
cmd.Dir = dir
|
|
|
|
cmd.Env = b.env()
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s", buf.Bytes())
|
|
|
|
return nil, fmt.Errorf("%s %s: %v", name, strings.Join(args, " "), err)
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var cleanEnv = []string{
|
|
|
|
"GOARCH",
|
|
|
|
"GOBIN",
|
|
|
|
"GOHOSTARCH",
|
|
|
|
"GOHOSTOS",
|
|
|
|
"GOOS",
|
|
|
|
"GOROOT",
|
|
|
|
"GOROOT_FINAL",
|
2013-01-28 22:46:49 -07:00
|
|
|
"GOPATH",
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Build) env() []string {
|
|
|
|
env := os.Environ()
|
|
|
|
for i := 0; i < len(env); i++ {
|
|
|
|
for _, c := range cleanEnv {
|
|
|
|
if strings.HasPrefix(env[i], c+"=") {
|
|
|
|
env = append(env[:i], env[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 14:55:53 -07:00
|
|
|
final := "/usr/local/go"
|
|
|
|
if b.OS == "windows" {
|
|
|
|
final = `c:\go`
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
env = append(env,
|
|
|
|
"GOARCH="+b.Arch,
|
|
|
|
"GOHOSTARCH="+b.Arch,
|
|
|
|
"GOHOSTOS="+b.OS,
|
|
|
|
"GOOS="+b.OS,
|
|
|
|
"GOROOT="+b.root,
|
2012-03-05 14:55:53 -07:00
|
|
|
"GOROOT_FINAL="+final,
|
2013-01-28 22:46:49 -07:00
|
|
|
"GOPATH="+b.gopath,
|
2012-02-29 21:49:37 -07:00
|
|
|
)
|
2013-10-02 18:14:54 -06:00
|
|
|
if b.static {
|
|
|
|
env = append(env, "GO_DISTFLAGS=-s")
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
2012-03-27 19:24:43 -06:00
|
|
|
func (b *Build) Upload(version string, filename string) error {
|
2014-06-01 20:46:03 -06:00
|
|
|
file, err := ioutil.ReadFile(filename)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-06-01 20:46:03 -06:00
|
|
|
svc, err := storage.New(oauthClient)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-05-28 16:40:15 -06:00
|
|
|
obj := &storage.Object{
|
|
|
|
Acl: []*storage.ObjectAccessControl{{Entity: "allUsers", Role: "READER"}},
|
|
|
|
Name: filename,
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2014-06-01 20:46:03 -06:00
|
|
|
_, err = svc.Objects.Insert(*storageBucket, obj).Media(bytes.NewReader(file)).Do()
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-06-01 20:46:03 -06:00
|
|
|
|
|
|
|
sum := fmt.Sprintf("%x", sha1.Sum(file))
|
|
|
|
kind := "unknown"
|
|
|
|
switch {
|
|
|
|
case b.Source:
|
|
|
|
kind = "source"
|
|
|
|
case strings.HasSuffix(filename, ".tar.gz"), strings.HasSuffix(filename, ".zip"):
|
|
|
|
kind = "archive"
|
|
|
|
case strings.HasSuffix(filename, ".msi"), strings.HasSuffix(filename, ".pkg"):
|
|
|
|
kind = "installer"
|
|
|
|
}
|
|
|
|
req, err := json.Marshal(File{
|
|
|
|
Filename: filename,
|
|
|
|
Version: version,
|
|
|
|
OS: b.OS,
|
|
|
|
Arch: b.Arch,
|
|
|
|
Checksum: sum,
|
|
|
|
Kind: kind,
|
|
|
|
})
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-06-01 20:46:03 -06:00
|
|
|
u := fmt.Sprintf("%s?%s", *uploadURL, url.Values{"key": []string{builderKey}}.Encode())
|
|
|
|
resp, err := http.Post(u, "application/json", bytes.NewReader(req))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return fmt.Errorf("upload status: %v", resp.Status)
|
|
|
|
}
|
2012-02-29 21:49:37 -07:00
|
|
|
|
2014-05-28 16:40:15 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-06-01 20:46:03 -06:00
|
|
|
type File struct {
|
|
|
|
Filename string
|
|
|
|
OS string
|
|
|
|
Arch string
|
|
|
|
Version string
|
|
|
|
Checksum string `datastore:",noindex"`
|
|
|
|
Kind string // "archive", "installer", "source"
|
|
|
|
}
|
|
|
|
|
2014-05-28 16:40:15 -06:00
|
|
|
func setupOAuthClient() error {
|
2015-01-14 03:39:18 -07:00
|
|
|
config := &oauth2.Config{
|
|
|
|
ClientID: "999119582588-h7kpj5pcm6d9solh5lgrbusmvvk4m9dn.apps.googleusercontent.com",
|
2014-06-02 00:26:08 -06:00
|
|
|
ClientSecret: "8YLFgOhXIELWbO-NtF3iqIQz",
|
2015-01-14 03:39:18 -07:00
|
|
|
Endpoint: google.Endpoint,
|
|
|
|
Scopes: []string{storage.DevstorageRead_writeScope},
|
|
|
|
}
|
|
|
|
url := config.AuthCodeURL("junk")
|
|
|
|
fmt.Println("Visit the following URL, obtain an authentication" +
|
|
|
|
"code, and enter it below.")
|
|
|
|
fmt.Println(url)
|
|
|
|
fmt.Print("Enter authentication code: ")
|
|
|
|
code := ""
|
|
|
|
if _, err := fmt.Scan(&code); err != nil {
|
|
|
|
return err
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2015-01-14 03:39:18 -07:00
|
|
|
tok, err := config.Exchange(oauth2.NoContext, code)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
oauthClient = config.Client(oauth2.NoContext, tok)
|
2012-02-29 21:49:37 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:13:26 -07:00
|
|
|
func (b *Build) clean(files []string) error {
|
|
|
|
for _, name := range files {
|
2015-01-15 15:11:17 -07:00
|
|
|
path := filepath.Join(b.root, name)
|
|
|
|
var err error
|
|
|
|
if b.OS == "windows" {
|
|
|
|
// Git sets some of its packfiles as 'read only',
|
|
|
|
// so os.RemoveAll will fail for the ".git" directory.
|
|
|
|
// Instead, shell out to cmd's 'del' subcommand.
|
|
|
|
cmd := exec.Command("cmd.exe", "/C", "del", "/Q", "/F", "/S", path)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
err = cmd.Run()
|
|
|
|
} else {
|
|
|
|
err = os.RemoveAll(path)
|
|
|
|
}
|
2012-03-06 19:13:26 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2012-02-29 21:49:37 -07:00
|
|
|
func exists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
return err == nil
|
|
|
|
}
|
|
|
|
|
2012-03-05 14:55:53 -07:00
|
|
|
func readCredentials() error {
|
2012-03-08 18:57:38 -07:00
|
|
|
name := os.Getenv("HOME")
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
name = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
|
|
|
}
|
|
|
|
name = filepath.Join(name, ".gobuildkey")
|
2012-03-05 14:55:53 -07:00
|
|
|
f, err := os.Open(name)
|
2012-02-29 21:49:37 -07:00
|
|
|
if err != nil {
|
2012-03-05 14:55:53 -07:00
|
|
|
return err
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2012-03-05 14:55:53 -07:00
|
|
|
defer f.Close()
|
2014-05-28 16:40:15 -06:00
|
|
|
s := bufio.NewScanner(f)
|
|
|
|
if s.Scan() {
|
|
|
|
builderKey = s.Text()
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2014-05-28 16:40:15 -06:00
|
|
|
return s.Err()
|
2012-03-05 14:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func cp(dst, src string) error {
|
|
|
|
sf, err := os.Open(src)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer sf.Close()
|
2013-01-29 16:17:39 -07:00
|
|
|
fi, err := sf.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-05 14:55:53 -07:00
|
|
|
df, err := os.Create(dst)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer df.Close()
|
2013-03-17 15:56:38 -06:00
|
|
|
// Windows doesn't currently implement Fchmod
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
if err := df.Chmod(fi.Mode()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-01-29 16:17:39 -07:00
|
|
|
}
|
2012-03-05 14:55:53 -07:00
|
|
|
_, err = io.Copy(df, sf)
|
|
|
|
return err
|
2012-02-29 21:49:37 -07:00
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
|
2013-01-28 22:46:49 -07:00
|
|
|
func cpDir(dst, src string) error {
|
|
|
|
walk := func(srcPath string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dstPath := filepath.Join(dst, srcPath[len(src):])
|
|
|
|
if info.IsDir() {
|
|
|
|
return os.MkdirAll(dstPath, 0755)
|
|
|
|
}
|
|
|
|
return cp(dstPath, srcPath)
|
|
|
|
}
|
|
|
|
return filepath.Walk(src, walk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func cpAllDir(dst, basePath string, dirs ...string) error {
|
|
|
|
for _, dir := range dirs {
|
|
|
|
if err := cpDir(filepath.Join(dst, dir), filepath.Join(basePath, dir)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2012-03-12 00:07:38 -06:00
|
|
|
func makeTar(targ, workdir string) error {
|
|
|
|
f, err := os.Create(targ)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
zout := gzip.NewWriter(f)
|
|
|
|
tw := tar.NewWriter(zout)
|
|
|
|
|
2012-04-03 13:33:22 -06:00
|
|
|
err = filepath.Walk(workdir, func(path string, fi os.FileInfo, err error) error {
|
2012-03-12 00:07:38 -06:00
|
|
|
if !strings.HasPrefix(path, workdir) {
|
|
|
|
log.Panicf("walked filename %q doesn't begin with workdir %q", path, workdir)
|
|
|
|
}
|
|
|
|
name := path[len(workdir):]
|
|
|
|
|
|
|
|
// Chop of any leading / from filename, leftover from removing workdir.
|
|
|
|
if strings.HasPrefix(name, "/") {
|
|
|
|
name = name[1:]
|
|
|
|
}
|
|
|
|
// Don't include things outside of the go subdirectory (for instance,
|
|
|
|
// the zip file that we're currently writing here.)
|
|
|
|
if !strings.HasPrefix(name, "go/") {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if *verbose {
|
|
|
|
log.Printf("adding to tar: %s", name)
|
|
|
|
}
|
2012-05-24 18:32:25 -06:00
|
|
|
target, _ := os.Readlink(path)
|
|
|
|
hdr, err := tar.FileInfoHeader(fi, target)
|
2012-03-12 22:49:43 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2012-03-12 00:07:38 -06:00
|
|
|
}
|
2012-03-12 22:49:43 -06:00
|
|
|
hdr.Name = name
|
|
|
|
hdr.Uname = "root"
|
|
|
|
hdr.Gname = "root"
|
|
|
|
hdr.Uid = 0
|
|
|
|
hdr.Gid = 0
|
|
|
|
|
2012-03-14 09:24:11 -06:00
|
|
|
// Force permissions to 0755 for executables, 0644 for everything else.
|
|
|
|
if fi.Mode().Perm()&0111 != 0 {
|
|
|
|
hdr.Mode = hdr.Mode&^0777 | 0755
|
2012-03-14 00:09:15 -06:00
|
|
|
} else {
|
2012-03-14 09:24:11 -06:00
|
|
|
hdr.Mode = hdr.Mode&^0777 | 0644
|
2012-03-14 00:09:15 -06:00
|
|
|
}
|
|
|
|
|
2012-03-12 00:07:38 -06:00
|
|
|
err = tw.WriteHeader(hdr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error writing file %q: %v", name, err)
|
|
|
|
}
|
2012-04-04 19:39:12 -06:00
|
|
|
if fi.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
2012-03-12 00:07:38 -06:00
|
|
|
r, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer r.Close()
|
|
|
|
_, err = io.Copy(tw, r)
|
|
|
|
return err
|
2012-04-03 13:33:22 -06:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-12 00:07:38 -06:00
|
|
|
if err := tw.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := zout.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return f.Close()
|
|
|
|
}
|
|
|
|
|
2012-03-11 22:02:40 -06:00
|
|
|
func makeZip(targ, workdir string) error {
|
|
|
|
f, err := os.Create(targ)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
zw := zip.NewWriter(f)
|
|
|
|
|
2012-04-03 13:33:22 -06:00
|
|
|
err = filepath.Walk(workdir, func(path string, fi os.FileInfo, err error) error {
|
2012-03-11 22:02:40 -06:00
|
|
|
if !strings.HasPrefix(path, workdir) {
|
|
|
|
log.Panicf("walked filename %q doesn't begin with workdir %q", path, workdir)
|
|
|
|
}
|
|
|
|
name := path[len(workdir):]
|
|
|
|
|
|
|
|
// Convert to Unix-style named paths, as that's the
|
|
|
|
// type of zip file that archive/zip creates.
|
|
|
|
name = strings.Replace(name, "\\", "/", -1)
|
|
|
|
// Chop of any leading / from filename, leftover from removing workdir.
|
|
|
|
if strings.HasPrefix(name, "/") {
|
|
|
|
name = name[1:]
|
|
|
|
}
|
|
|
|
// Don't include things outside of the go subdirectory (for instance,
|
|
|
|
// the zip file that we're currently writing here.)
|
|
|
|
if !strings.HasPrefix(name, "go/") {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if *verbose {
|
|
|
|
log.Printf("adding to zip: %s", name)
|
|
|
|
}
|
|
|
|
fh, err := zip.FileInfoHeader(fi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fh.Name = name
|
|
|
|
fh.Method = zip.Deflate
|
2012-04-04 19:39:12 -06:00
|
|
|
if fi.IsDir() {
|
|
|
|
fh.Name += "/" // append trailing slash
|
|
|
|
fh.Method = zip.Store // no need to deflate 0 byte files
|
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
w, err := zw.CreateHeader(fh)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-04-04 19:39:12 -06:00
|
|
|
if fi.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
r, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer r.Close()
|
|
|
|
_, err = io.Copy(w, r)
|
|
|
|
return err
|
2012-04-03 13:33:22 -06:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-03-11 22:02:40 -06:00
|
|
|
if err := zw.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return f.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
type tool struct {
|
|
|
|
name string
|
|
|
|
commonDirs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var wixTool = tool{
|
|
|
|
"http://wix.sourceforge.net/, version 3.5",
|
|
|
|
[]string{`C:\Program Files\Windows Installer XML v3.5\bin`,
|
|
|
|
`C:\Program Files (x86)\Windows Installer XML v3.5\bin`},
|
|
|
|
}
|
|
|
|
|
|
|
|
var hgTool = tool{
|
|
|
|
"http://mercurial.selenic.com/wiki/WindowsInstall",
|
|
|
|
[]string{`C:\Program Files\Mercurial`,
|
|
|
|
`C:\Program Files (x86)\Mercurial`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-01-14 03:39:18 -07:00
|
|
|
var gitTool = tool{
|
|
|
|
"http://git-scm.com/download/win",
|
|
|
|
[]string{`C:\Program Files\Git`, `C:\Program Files (x86)\Git`},
|
|
|
|
}
|
|
|
|
|
2012-03-11 22:02:40 -06:00
|
|
|
var gccTool = tool{
|
|
|
|
"Mingw gcc; http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/",
|
|
|
|
[]string{`C:\Mingw\bin`},
|
|
|
|
}
|
|
|
|
|
|
|
|
var windowsDeps = map[string]tool{
|
|
|
|
"gcc": gccTool,
|
|
|
|
"heat": wixTool,
|
|
|
|
"candle": wixTool,
|
|
|
|
"light": wixTool,
|
|
|
|
"cmd": {"Windows cmd.exe", nil},
|
2015-01-14 03:39:18 -07:00
|
|
|
"git": gitTool,
|
2012-03-11 22:02:40 -06:00
|
|
|
"hg": hgTool,
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkWindowsDeps() {
|
|
|
|
for prog, help := range windowsDeps {
|
|
|
|
absPath, err := lookPath(prog)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to find necessary binary %q in path or common locations; %s", prog, help)
|
|
|
|
}
|
|
|
|
if *verbose {
|
|
|
|
log.Printf("found windows dep %s at %s", prog, absPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func lookPath(prog string) (absPath string, err error) {
|
|
|
|
absPath, err = exec.LookPath(prog)
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t, ok := windowsDeps[prog]
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, dir := range t.commonDirs {
|
|
|
|
for _, ext := range []string{"exe", "bat"} {
|
|
|
|
absPath = filepath.Join(dir, prog+"."+ext)
|
|
|
|
if _, err1 := os.Stat(absPath); err1 == nil {
|
|
|
|
err = nil
|
|
|
|
os.Setenv("PATH", os.Getenv("PATH")+";"+dir)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|