]> Cypherpunks repositories - gostls13.git/commitdiff
misc/dist: require 10.6 or later for OS X .pkgs
authorMikkel Krautz <mikkel@krautz.dk>
Mon, 23 Apr 2012 21:56:03 +0000 (14:56 -0700)
committerAndrew Gerrand <adg@golang.org>
Mon, 23 Apr 2012 21:56:03 +0000 (14:56 -0700)
This changes the misc/dist program to generate OS X
packages using pkgbuild and productbuild.

The productbuild utility makes it easy to generate
packages with a custom Distribution file.  This allows
us to add an installcheck script that presents a
friendly message to users who are running on an old
version of Mac OS X.

The change also fixes a few issues with the
postinstall script:

 - In-repo version of the script has been made
   executable. Installers generated using the new
   tools couldn't execute it otherwise.

 - It now uses -d for checking for the existence
   of the Xcode specs directory.

 - The call to sudo.bash has been dropped since cov
   and prof aren't bundled with the binary
   distributions.

Fixes #3455.

Tested on 10.5.8, 10.6.0, 10.6.8 and 10.7.3.

R=adg, golang-dev
CC=golang-dev
https://golang.org/cl/5987044

misc/dist/bindist.go
misc/dist/darwin/Distribution [new file with mode: 0644]
misc/dist/darwin/scripts/postinstall [changed mode: 0644->0755]

index 77b7218ba0c0e7223a2bf59d2c3c91183c92587c..a2cfdd6a54ef10688bce6d5eb13ba2bd0f350143 100644 (file)
@@ -13,7 +13,6 @@ import (
        "bytes"
        "compress/gzip"
        "encoding/base64"
-       "errors"
        "flag"
        "fmt"
        "io"
@@ -41,8 +40,7 @@ var (
 )
 
 const (
-       packageMaker = "/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
-       uploadURL    = "https://go.googlecode.com/files"
+       uploadURL = "https://go.googlecode.com/files"
 )
 
 var preBuildCleanFiles = []string{
@@ -231,7 +229,7 @@ func (b *Build) Do() error {
                        return err
                }
                localDir := filepath.Join(work, "usr/local")
-               err = os.MkdirAll(localDir, 0744)
+               err = os.MkdirAll(localDir, 0755)
                if err != nil {
                        return err
                }
@@ -240,27 +238,29 @@ func (b *Build) Do() error {
                        return err
                }
                // build package
-               pkginfo, err := createPackageInfo(work)
+               pkgdest, err := ioutil.TempDir("", "pkgdest")
                if err != nil {
                        return err
                }
-               defer os.Remove(pkginfo)
-               pm := packageMaker
-               if !exists(pm) {
-                       pm = "/Developer" + pm
-                       if !exists(pm) {
-                               return errors.New("couldn't find PackageMaker")
-                       }
+               defer os.RemoveAll(pkgdest)
+               dist := filepath.Join(runtime.GOROOT(), "misc/dist")
+               _, err = b.run("", "pkgbuild",
+                       "--identifier", "com.googlecode.go",
+                       "--version", "1.0",
+                       "--scripts", filepath.Join(dist, "darwin/scripts"),
+                       "--root", work,
+                       filepath.Join(pkgdest, "com.googlecode.go.pkg"))
+               if err != nil {
+                       return err
                }
                targ := base + ".pkg"
-               scripts := filepath.Join(work, "usr/local/go/misc/dist/darwin/scripts")
-               _, err = b.run("", pm, "-v",
-                       "-r", work,
-                       "-o", targ,
-                       "--info", pkginfo,
-                       "--scripts", scripts,
-                       "--title", "Go",
-                       "--target", "10.5")
+               _, err = b.run("", "productbuild",
+                       "--distribution", filepath.Join(dist, "darwin/Distribution"),
+                       "--package-path", pkgdest,
+                       targ)
+               if err != nil {
+                       return err
+               }
                targs = append(targs, targ)
        case "windows":
                // Create ZIP file.
@@ -806,30 +806,3 @@ func tarFileInfoHeader(fi os.FileInfo, filename string) (*tar.Header, error) {
        }
        return h, nil
 }
-
-// createPackageInfo creates a PackageInfo template file for use with PackageMaker.
-// The returned filename points to a file in a temporary directory on the filesystem,
-// and should be removed after use.
-func createPackageInfo(work string) (filename string, err error) {
-       var size, nfiles int64
-       err = filepath.Walk(work, func(path string, info os.FileInfo, err error) error {
-               nfiles++
-               size += info.Size()
-               return nil
-       })
-       if err != nil {
-               return "", err
-       }
-       pi, err := ioutil.TempFile("", "PackageInfo")
-       if err != nil {
-               return "", err
-       }
-       defer pi.Close()
-       _, err = fmt.Fprintf(pi, "<pkg-info identifier=\"com.googlecode.go\" version=\"1.0\" followSymLinks=\"true\">\n"+
-               "\t<payload installKBytes=\"%v\" numberOfFiles=\"%v\"/>\n"+
-               "</pkg-info>\n", size/1024, nfiles)
-       if err != nil {
-               return "", err
-       }
-       return pi.Name(), nil
-}
diff --git a/misc/dist/darwin/Distribution b/misc/dist/darwin/Distribution
new file mode 100644 (file)
index 0000000..915d72d
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<installer-script minSpecVersion="1.000000">
+    <title>Go</title>
+    <options customize="never" allow-external-scripts="no"/>
+    <domains enable_localSystem="true" />
+    <installation-check script="installCheck();"/>
+    <script>
+function installCheck() {
+    if(!(system.compareVersions(system.version.ProductVersion, '10.6.0') >= 0)) {
+        my.result.title = 'Unable to install';
+        my.result.message = 'Go requires Mac OS X 10.6 or later.';
+        my.result.type = 'Fatal';
+        return false;
+    }
+    return true;
+}
+    </script>
+    <choices-outline>
+        <line choice="com.googlecode.go.choice"/>
+    </choices-outline>
+    <choice id="com.googlecode.go.choice" title="Go">
+        <pkg-ref id="com.googlecode.go.pkg"/>
+    </choice>
+    <pkg-ref id="com.googlecode.go.pkg" auth="Root">com.googlecode.go.pkg</pkg-ref>
+</installer-script>
old mode 100644 (file)
new mode 100755 (executable)
index 3748721..4410a30
@@ -9,14 +9,9 @@ find bin -exec chmod ugo+rx \{\} \;
 find . -type d -exec chmod ugo+rx \{\} \;
 chmod o-w .
 
-echo "Fixing debuggers via sudo.bash"
-# setgrp procmod the debuggers (sudo.bash)
-cd $GOROOT/src
-./sudo.bash
-
 echo "Installing miscellaneous files:"
 XCODE_MISC_DIR="/Library/Application Support/Developer/Shared/Xcode/Specifications/"
-if [ -f $XCODE_MISC_DIR ]; then
+if [ -d "$XCODE_MISC_DIR" ]; then
        echo "  XCode"
        cp $GOROOT/misc/xcode/* $XCODE_MISC_DIR
 fi