Commit 5e46a8c9 authored by Andrew Gerrand's avatar Andrew Gerrand

misc/dist: add windows packaging support

R=golang-dev, bsiegert, jdpoirier
CC=golang-dev
https://golang.org/cl/5727059
parent aa1aaee7
......@@ -7,6 +7,7 @@
package main
import (
"bufio"
"bytes"
"encoding/base64"
"errors"
......@@ -52,7 +53,9 @@ func main() {
if flag.NArg() == 0 {
flag.Usage()
}
readCredentials()
if err := readCredentials(); err != nil {
log.Println("readCredentials:", err)
}
for _, targ := range flag.Args() {
p := strings.SplitN(targ, "-", 2)
if len(p) != 2 {
......@@ -91,7 +94,11 @@ func (b *Build) Do() error {
}
// Build.
_, err = b.run(filepath.Join(work, "go/src"), "bash", "make.bash")
if b.OS == "windows" {
_, err = b.run(filepath.Join(b.root, "src"), "cmd", "/C", "make.bat")
} else {
_, err = b.run(filepath.Join(b.root, "src"), "bash", "make.bash")
}
if err != nil {
return err
}
......@@ -103,6 +110,7 @@ func (b *Build) Do() error {
}
v := bytes.SplitN(version, []byte(" "), 4)
version = bytes.Join(v[2:], []byte(" "))
ver := string(v[2])
// Write VERSION file.
err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), version, 0644)
......@@ -119,7 +127,7 @@ func (b *Build) Do() error {
}
// Create packages.
targ := fmt.Sprintf("go.%s.%s-%s", v[2], b.OS, b.Arch)
targ := fmt.Sprintf("go.%s.%s-%s", ver, b.OS, b.Arch)
switch b.OS {
case "linux", "freebsd":
// build tarball
......@@ -159,6 +167,47 @@ func (b *Build) Do() error {
"--title", "Go",
"--version", "1.0",
"--target", "10.5")
case "windows":
win := filepath.Join(b.root, "misc/dist/windows")
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",
"-dVersion="+ver,
"-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.
targ += ".msi"
err = cp(targ, msi)
}
if err == nil && password != "" {
err = b.upload(string(v[2]), targ)
......@@ -199,13 +248,17 @@ func (b *Build) env() []string {
}
}
}
final := "/usr/local/go"
if b.OS == "windows" {
final = `c:\go`
}
env = append(env,
"GOARCH="+b.Arch,
"GOHOSTARCH="+b.Arch,
"GOHOSTOS="+b.OS,
"GOOS="+b.OS,
"GOROOT="+b.root,
"GOROOT_FINAL=/usr/local/go",
"GOROOT_FINAL="+final,
)
return env
}
......@@ -230,6 +283,9 @@ func (b *Build) upload(version string, filename string) error {
case "darwin":
os_ = "Mac OS X"
labels = append(labels, "Type-Installer", "OpSys-OSX")
case "windows":
os_ = "Windows"
labels = append(labels, "Type-Installer", "OpSys-Windows")
}
summary := fmt.Sprintf("Go %s %s (%s)", version, os_, arch)
......@@ -290,15 +346,41 @@ func exists(path string) bool {
return err == nil
}
func readCredentials() {
func readCredentials() error {
name := filepath.Join(os.Getenv("HOME"), ".gobuildkey")
c, err := ioutil.ReadFile(name)
f, err := os.Open(name)
if err != nil {
log.Println("readCredentials:", err)
return
return err
}
v := bytes.Split(c, []byte("\n"))
if len(v) >= 3 {
username, password = string(v[1]), string(v[2])
defer f.Close()
r := bufio.NewReader(f)
for i := 0; i < 3; i++ {
b, _, err := r.ReadLine()
if err != nil {
return err
}
b = bytes.TrimSpace(b)
switch i {
case 1:
username = string(b)
case 2:
password = string(b)
}
}
return nil
}
func cp(dst, src string) error {
sf, err := os.Open(src)
if err != nil {
return err
}
defer sf.Close()
df, err := os.Create(dst)
if err != nil {
return err
}
defer df.Close()
_, err = io.Copy(df, sf)
return err
}
dist.bat packages the Go toolchain for Windows in both zip
and installer (msi) format.
Dependencies
============
- Windows Installer XML (WiX) toolset: http://wix.sourceforge.net/
- 7Zip (command line version): http://www.7-zip.org/download.html
- Mercurial (hg): http://mercurial.selenic.com/
Packaging
=========
The dependencies must be callable from dist.bat, therefore,
they'll need to be in/added to the system's search PATH.
The packaging needs to be done from within a tracked Go folder.
Packages are built by cloning the same version of the source tree
that the Go tools were built from.
Run dist.bat from a command prompt or click on the batch file.
TODO
----
- Write a Go program for dist.bat functionality
- Documentation server shortcut checkbox option
Misc
----
WiX box sizes:
- banner size: 493x58
- left side of dialog: 164x312
- full dialog size: 493x312
Windows build dependencies
- Mercurial (hg): http://mercurial.selenic.com/
- MinGW: http://www.mingw.org/
- Windows Installer XML (WiX) toolset: http://wix.sourceforge.net/
Packaging
The dependencies must be in/added to the system's search PATH.
Run bindist as normal, eg:
bindist windows-386
TODO
- Documentation server shortcut checkbox option
Misc
WiX box sizes:
- banner size: 493x58
- left side of dialog: 164x312
- full dialog size: 493x312
:: 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.
@echo off
setlocal
:: Requires Windows Installer XML (WiX), 7zip, and Mercurial (hg)
echo # Cleaning previous WiX output files
del /F /Q /S *.wixobj AppFiles.wxs *.wixpdb>NUL
echo # Setting some variables
for /f %%i in ('hg.exe root') do set ROOT=%%i
for /f "tokens=3" %%i in ('%ROOT%\bin\go.exe version') do set VER=%%i
for /f "tokens=4" %%i in ('%ROOT%\bin\go.exe version') do set ID=%%i
set ID=%ID:+=%
if errorlevel 1 goto end
echo # Getting GOARCH
%ROOT%\bin\go tool dist env -w>env.bat
call env.bat
del /F /Q /S env.bat>NUL
if errorlevel 1 goto end
rmdir /S /Q go>NUL
mkdir go
echo # Cloning the Go tree
hg clone -r %ID% %ROOT% go
if errorlevel 1 goto end
rmdir /S /Q go\.hg>NUL
del /F /Q /S go\.hgignore go\.hgtags>NUL
echo # Copying pkg, bin, and src/pkg/runtime/z*
xcopy %ROOT%\pkg go\pkg /V /E /Y /I
xcopy %ROOT%\bin go\bin /V /E /Y /I
xcopy %ROOT%\src\pkg\runtime\z*.c go\src\pkg\runtime /V /E /Y
xcopy %ROOT%\src\pkg\runtime\z*.go go\src\pkg\runtime /V /E /Y
xcopy %ROOT%\src\pkg\runtime\z*.h go\src\pkg\runtime /V /E /Y
echo # Starting zip packaging
7za a -tzip -mx=9 go.%VER%.windows-%GOARCH%.zip "go/"
if errorlevel 1 goto end
echo # Starting Go directory file harvesting
heat dir go -nologo -cg AppFiles -gg -g1 -srd -sfrag -template fragment -dr INSTALLDIR -var var.SourceDir -out AppFiles.wxs
if errorlevel 1 goto end
echo # Starting installer packaging
candle -nologo -dVersion=%VER% -dArch=%GOARCH% -dSourceDir=go installer.wxs AppFiles.wxs
light -nologo -ext WixUIExtension -ext WixUtilExtension installer.wixobj AppFiles.wixobj -o go.%VER%.windows-%GOARCH%.msi
if errorlevel 1 goto end
del /F /Q /S *.wixobj AppFiles.wxs *.wixpdb>NUL
:end
endlocal
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