1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:14:41 -07:00

misc/dist: add windows packaging support

R=golang-dev, bsiegert, jdpoirier
CC=golang-dev
https://golang.org/cl/5727059
This commit is contained in:
Andrew Gerrand 2012-03-06 08:55:53 +11:00
parent aa1aaee7fd
commit 5e46a8c9f9
3 changed files with 118 additions and 106 deletions

104
misc/dist/bindist.go vendored
View File

@ -7,6 +7,7 @@
package main package main
import ( import (
"bufio"
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"errors" "errors"
@ -52,7 +53,9 @@ func main() {
if flag.NArg() == 0 { if flag.NArg() == 0 {
flag.Usage() flag.Usage()
} }
readCredentials() if err := readCredentials(); err != nil {
log.Println("readCredentials:", err)
}
for _, targ := range flag.Args() { for _, targ := range flag.Args() {
p := strings.SplitN(targ, "-", 2) p := strings.SplitN(targ, "-", 2)
if len(p) != 2 { if len(p) != 2 {
@ -91,7 +94,11 @@ func (b *Build) Do() error {
} }
// Build. // 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 { if err != nil {
return err return err
} }
@ -103,6 +110,7 @@ func (b *Build) Do() error {
} }
v := bytes.SplitN(version, []byte(" "), 4) v := bytes.SplitN(version, []byte(" "), 4)
version = bytes.Join(v[2:], []byte(" ")) version = bytes.Join(v[2:], []byte(" "))
ver := string(v[2])
// Write VERSION file. // Write VERSION file.
err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), version, 0644) err = ioutil.WriteFile(filepath.Join(b.root, "VERSION"), version, 0644)
@ -119,7 +127,7 @@ func (b *Build) Do() error {
} }
// Create packages. // 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 { switch b.OS {
case "linux", "freebsd": case "linux", "freebsd":
// build tarball // build tarball
@ -159,6 +167,47 @@ func (b *Build) Do() error {
"--title", "Go", "--title", "Go",
"--version", "1.0", "--version", "1.0",
"--target", "10.5") "--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 != "" { if err == nil && password != "" {
err = b.upload(string(v[2]), targ) 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, env = append(env,
"GOARCH="+b.Arch, "GOARCH="+b.Arch,
"GOHOSTARCH="+b.Arch, "GOHOSTARCH="+b.Arch,
"GOHOSTOS="+b.OS, "GOHOSTOS="+b.OS,
"GOOS="+b.OS, "GOOS="+b.OS,
"GOROOT="+b.root, "GOROOT="+b.root,
"GOROOT_FINAL=/usr/local/go", "GOROOT_FINAL="+final,
) )
return env return env
} }
@ -230,6 +283,9 @@ func (b *Build) upload(version string, filename string) error {
case "darwin": case "darwin":
os_ = "Mac OS X" os_ = "Mac OS X"
labels = append(labels, "Type-Installer", "OpSys-OSX") 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) summary := fmt.Sprintf("Go %s %s (%s)", version, os_, arch)
@ -290,15 +346,41 @@ func exists(path string) bool {
return err == nil return err == nil
} }
func readCredentials() { func readCredentials() error {
name := filepath.Join(os.Getenv("HOME"), ".gobuildkey") name := filepath.Join(os.Getenv("HOME"), ".gobuildkey")
c, err := ioutil.ReadFile(name) f, err := os.Open(name)
if err != nil { if err != nil {
log.Println("readCredentials:", err) return err
return
} }
v := bytes.Split(c, []byte("\n")) defer f.Close()
if len(v) >= 3 { r := bufio.NewReader(f)
username, password = string(v[1]), string(v[2]) 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
} }

View File

@ -1,34 +1,25 @@
dist.bat packages the Go toolchain for Windows in both zip
and installer (msi) format. Windows build dependencies
Dependencies - Mercurial (hg): http://mercurial.selenic.com/
============ - MinGW: http://www.mingw.org/
- Windows Installer XML (WiX) toolset: http://wix.sourceforge.net/ - 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 in/added to the system's search PATH.
Packaging
========= Run bindist as normal, eg:
The dependencies must be callable from dist.bat, therefore, bindist windows-386
they'll need to be in/added to the system's search PATH.
TODO
The packaging needs to be done from within a tracked Go folder.
Packages are built by cloning the same version of the source tree - Documentation server shortcut checkbox option
that the Go tools were built from.
Misc
Run dist.bat from a command prompt or click on the batch file.
WiX box sizes:
TODO - banner size: 493x58
---- - left side of dialog: 164x312
- Write a Go program for dist.bat functionality - full dialog size: 493x312
- Documentation server shortcut checkbox option
Misc
----
WiX box sizes:
- banner size: 493x58
- left side of dialog: 164x312
- full dialog size: 493x312

View File

@ -1,61 +0,0 @@
:: 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