mirror of
https://github.com/golang/go
synced 2024-11-25 09:57:57 -07:00
misc/dist: prepare source archives
Fixes #95. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5756066
This commit is contained in:
parent
25f15d5f22
commit
243ac1613e
103
misc/dist/bindist.go
vendored
103
misc/dist/bindist.go
vendored
@ -43,6 +43,11 @@ var cleanFiles = []string{
|
|||||||
"VERSION.cache",
|
"VERSION.cache",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sourceCleanFiles = []string{
|
||||||
|
"bin",
|
||||||
|
"pkg",
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, "usage: %s [flags] targets...\n", os.Args[0])
|
fmt.Fprintf(os.Stderr, "usage: %s [flags] targets...\n", os.Args[0])
|
||||||
@ -57,12 +62,18 @@ func main() {
|
|||||||
log.Println("readCredentials:", err)
|
log.Println("readCredentials:", err)
|
||||||
}
|
}
|
||||||
for _, targ := range flag.Args() {
|
for _, targ := range flag.Args() {
|
||||||
p := strings.SplitN(targ, "-", 2)
|
var b Build
|
||||||
if len(p) != 2 {
|
if targ == "source" {
|
||||||
log.Println("Ignoring unrecognized target:", targ)
|
b.Source = true
|
||||||
continue
|
} else {
|
||||||
|
p := strings.SplitN(targ, "-", 2)
|
||||||
|
if len(p) != 2 {
|
||||||
|
log.Println("Ignoring unrecognized target:", targ)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
b.OS = p[0]
|
||||||
|
b.Arch = p[1]
|
||||||
}
|
}
|
||||||
b := Build{OS: p[0], Arch: p[1]}
|
|
||||||
if err := b.Do(); err != nil {
|
if err := b.Do(); err != nil {
|
||||||
log.Printf("%s: %v", targ, err)
|
log.Printf("%s: %v", targ, err)
|
||||||
}
|
}
|
||||||
@ -70,9 +81,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Build struct {
|
type Build struct {
|
||||||
OS string
|
Source bool // if true, OS and Arch must be empty
|
||||||
Arch string
|
OS string
|
||||||
root string
|
Arch string
|
||||||
|
root string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Build) Do() error {
|
func (b *Build) Do() error {
|
||||||
@ -93,44 +105,66 @@ func (b *Build) Do() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build.
|
src := filepath.Join(b.root, "src")
|
||||||
if b.OS == "windows" {
|
if b.Source {
|
||||||
_, err = b.run(filepath.Join(b.root, "src"), "cmd", "/C", "make.bat")
|
// Build dist tool only.
|
||||||
|
_, err = b.run(src, "bash", "make.bash", "--dist-tool")
|
||||||
} else {
|
} else {
|
||||||
_, err = b.run(filepath.Join(b.root, "src"), "bash", "make.bash")
|
// Build.
|
||||||
|
if b.OS == "windows" {
|
||||||
|
_, err = b.run(src, "cmd", "/C", "make.bat")
|
||||||
|
} else {
|
||||||
|
_, err = b.run(src, "bash", "make.bash")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get version string.
|
// Get version strings.
|
||||||
version, err := b.run("", filepath.Join(b.root, "bin/go"), "version")
|
var (
|
||||||
|
version string // "weekly.2012-03-04"
|
||||||
|
fullVersion []byte // "weekly.2012-03-04 9353aa1efdf3"
|
||||||
|
)
|
||||||
|
pat := b.root + "/pkg/tool/*/dist"
|
||||||
|
m, err := filepath.Glob(pat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v := bytes.SplitN(version, []byte(" "), 4)
|
if len(m) == 0 {
|
||||||
version = bytes.Join(v[2:], []byte(" "))
|
return fmt.Errorf("couldn't find dist in %q", pat)
|
||||||
ver := string(v[2])
|
}
|
||||||
|
fullVersion, err = b.run("", m[0], "version")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
v := bytes.SplitN(fullVersion, []byte(" "), 2)
|
||||||
|
version = string(v[0])
|
||||||
|
|
||||||
// Write VERSION file.
|
// Write VERSION file.
|
||||||
err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), version, 0644)
|
err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), fullVersion, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean goroot.
|
// Clean goroot.
|
||||||
for _, name := range cleanFiles {
|
if err := b.clean(cleanFiles); err != nil {
|
||||||
err = os.RemoveAll(filepath.Join(b.root, name))
|
return err
|
||||||
if err != nil {
|
}
|
||||||
|
if b.Source {
|
||||||
|
if err := b.clean(sourceCleanFiles); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create packages.
|
// Create packages.
|
||||||
targ := fmt.Sprintf("go.%s.%s-%s", ver, b.OS, b.Arch)
|
targ := fmt.Sprintf("go.%s.%s-%s", version, b.OS, b.Arch)
|
||||||
switch b.OS {
|
switch b.OS {
|
||||||
case "linux", "freebsd":
|
case "linux", "freebsd", "":
|
||||||
// build tarball
|
// build tarball
|
||||||
|
if b.Source {
|
||||||
|
targ = fmt.Sprintf("go.%s.src", version)
|
||||||
|
}
|
||||||
targ += ".tar.gz"
|
targ += ".tar.gz"
|
||||||
_, err = b.run("", "tar", "czf", targ, "-C", work, "go")
|
_, err = b.run("", "tar", "czf", targ, "-C", work, "go")
|
||||||
case "darwin":
|
case "darwin":
|
||||||
@ -187,7 +221,7 @@ func (b *Build) Do() error {
|
|||||||
// Build package.
|
// Build package.
|
||||||
_, err = b.run(work, "candle",
|
_, err = b.run(work, "candle",
|
||||||
"-nologo",
|
"-nologo",
|
||||||
"-dVersion="+ver,
|
"-dVersion="+version,
|
||||||
"-dArch="+b.Arch,
|
"-dArch="+b.Arch,
|
||||||
"-dSourceDir=go",
|
"-dSourceDir=go",
|
||||||
installer, appfiles)
|
installer, appfiles)
|
||||||
@ -210,7 +244,7 @@ func (b *Build) Do() error {
|
|||||||
err = cp(targ, msi)
|
err = cp(targ, msi)
|
||||||
}
|
}
|
||||||
if err == nil && password != "" {
|
if err == nil && password != "" {
|
||||||
err = b.upload(string(v[2]), targ)
|
err = b.upload(version, targ)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -265,7 +299,7 @@ func (b *Build) env() []string {
|
|||||||
|
|
||||||
func (b *Build) upload(version string, filename string) error {
|
func (b *Build) upload(version string, filename string) error {
|
||||||
// Prepare upload metadata.
|
// Prepare upload metadata.
|
||||||
labels := []string{"Arch-" + b.Arch}
|
var labels []string
|
||||||
os_, arch := b.OS, b.Arch
|
os_, arch := b.OS, b.Arch
|
||||||
switch b.Arch {
|
switch b.Arch {
|
||||||
case "386":
|
case "386":
|
||||||
@ -273,6 +307,9 @@ func (b *Build) upload(version string, filename string) error {
|
|||||||
case "amd64":
|
case "amd64":
|
||||||
arch = "64-bit"
|
arch = "64-bit"
|
||||||
}
|
}
|
||||||
|
if arch != "" {
|
||||||
|
labels = append(labels, "Arch-"+b.Arch)
|
||||||
|
}
|
||||||
switch b.OS {
|
switch b.OS {
|
||||||
case "linux":
|
case "linux":
|
||||||
os_ = "Linux"
|
os_ = "Linux"
|
||||||
@ -288,6 +325,10 @@ func (b *Build) upload(version string, filename string) error {
|
|||||||
labels = append(labels, "Type-Installer", "OpSys-Windows")
|
labels = append(labels, "Type-Installer", "OpSys-Windows")
|
||||||
}
|
}
|
||||||
summary := fmt.Sprintf("Go %s %s (%s)", version, os_, arch)
|
summary := fmt.Sprintf("Go %s %s (%s)", version, os_, arch)
|
||||||
|
if b.Source {
|
||||||
|
labels = append(labels, "Type-Source")
|
||||||
|
summary = fmt.Sprintf("Go %s (source only)", version)
|
||||||
|
}
|
||||||
|
|
||||||
// Open file to upload.
|
// Open file to upload.
|
||||||
f, err := os.Open(filename)
|
f, err := os.Open(filename)
|
||||||
@ -341,6 +382,16 @@ func (b *Build) upload(version string, filename string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Build) clean(files []string) error {
|
||||||
|
for _, name := range files {
|
||||||
|
err := os.RemoveAll(filepath.Join(b.root, name))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func exists(path string) bool {
|
func exists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
return err == nil
|
return err == nil
|
||||||
|
Loading…
Reference in New Issue
Block a user