瀏覽代碼

download/compile xz for building/decompressing tarball in OS X installer

On OS X, we previously packed a locally installed xz into the installation
package and unpacked it during installation, if xz is not available on the
target machine. This can lead to problems if xz was installed by a package
manager like Homebrew, as symlinks would get packed instead of the real
binary.

We now download and compile xz statically on the fly, which removes the
need for xz on both the developer and the deployment machine.
Michael Nitze 11 年之前
父節點
當前提交
9f5f41d7ef
共有 2 個文件被更改,包括 27 次插入29 次删除
  1. 5 6
      INSTALL.md
  2. 22 23
      scripts/build.py

+ 5 - 6
INSTALL.md

@@ -104,12 +104,11 @@ OS X
 ----
 ----
 
 
 Building is supported only on OS X 10.6 or newer. You will need to have the
 Building is supported only on OS X 10.6 or newer. You will need to have the
-the latest Xcode for your OS X version and also install
-[xz 5.0.5](http://downloads.sourceforge.net/project/macpkg/XZ/5.0.5/XZ.pkg).
-Additionally, you will need the command `sudo gem install fpm --no-ri --no-rdoc`
-in the terminal to install [fpm](https://github.com/jordansissel/fpm), which is
-used for building the package. Note that if you are using OS X 10.6, you will
-additionally need to install [git 1.8.4.2](https://git-osx-installer.googlecode.com/files/git-1.8.4.2-intel-universal-snow-leopard.dmg)
+latest Xcode for your OS X version. Additionally, you will need the command
+`sudo gem install fpm --no-ri --no-rdoc` in the terminal to install
+[fpm](https://github.com/jordansissel/fpm), which is used for building the package.
+Note that if you are using OS X 10.6, you will additionally need to install
+[git 1.8.4.2](https://git-osx-installer.googlecode.com/files/git-1.8.4.2-intel-universal-snow-leopard.dmg)
 and [Python 2.7.6](https://www.python.org/ftp/python/2.7.6/python-2.7.6-macosx10.6.dmg)
 and [Python 2.7.6](https://www.python.org/ftp/python/2.7.6/python-2.7.6-macosx10.6.dmg)
 (you may need to run the `Update Shell Profile.command` in `/Applications/Python 2.7`
 (you may need to run the `Update Shell Profile.command` in `/Applications/Python 2.7`
 to make it the default Python in the shell).
 to make it the default Python in the shell).

+ 22 - 23
scripts/build.py

@@ -224,7 +224,7 @@ FPM_SETUP = {
     'osx': {
     'osx': {
         '-t':                         'osxpkg',
         '-t':                         'osxpkg',
         '-C':                         'pkg',
         '-C':                         'pkg',
-        '--prefix':                   '/usr/local/share/installer/wkhtmltox',
+        '--prefix':                   '/usr/local/share/wkhtmltox-installer',
         '--osxpkg-identifier-prefix': 'org.wkhtmltopdf',
         '--osxpkg-identifier-prefix': 'org.wkhtmltopdf',
         '--after-install':            'extract.sh'
         '--after-install':            'extract.sh'
     }
     }
@@ -450,6 +450,20 @@ DEPENDENT_LIBS = {
                     'make install']
                     'make install']
             }
             }
         }
         }
+    },
+
+    'xz': {
+        'order' : 5,
+        'url' : 'http://tukaani.org/xz/xz-5.0.5.tar.gz',
+        'sha1': '26fec2c1e409f736e77a85e4ab314dc74987def0',
+        'build' : {
+            'osx*': {
+                'result': ['bin/xz'],
+                'commands': [
+                    'CFLAGS="-arch x86_64" ./configure --disable-nls --enable-small --disable-shared --disable-threads --prefix=%(destdir)s',
+                    'make -C src/liblzma', 'make -C src/xz', 'make install-strip']
+            }
+        }
     }
     }
 }
 }
 
 
@@ -1116,17 +1130,13 @@ def build_osx(config, basedir):
         info.gname = 'wheel'
         info.gname = 'wheel'
         return info
         return info
 
 
-    # create tarballs for application and unxz
+    # create tarball for application and copy xz
     os.chdir(get_dir('dist'))
     os.chdir(get_dir('dist'))
     with tarfile.open('../pkg/app.tar', 'w') as tar:
     with tarfile.open('../pkg/app.tar', 'w') as tar:
         tar.add('.', './', filter=_osx_tar)
         tar.add('.', './', filter=_osx_tar)
-    shell('xz --compress --force --verbose -9 ../pkg/app.tar')
-
-    with tarfile.open('../pkg/xz.tar.gz', 'w:gz') as tar:
-        xz   = get_output('which', 'xz')
-        lzma = os.path.join(os.path.dirname(xz), '..', 'lib', 'liblzma.5.dylib')
-        tar.add(xz, './bin/xz', filter=_osx_tar)
-        tar.add(lzma, './lib/liblzma.5.dylib', filter=_osx_tar)
+    xz = os.path.join(get_dir('deplibs'), 'bin', 'xz')
+    shell('%s --compress --force --verbose -9 ../pkg/app.tar' % xz)
+    shutil.copy(xz, '../pkg/')
 
 
     args, cfg = fpm_setup('osx')
     args, cfg = fpm_setup('osx')
     with open('../pkg/uninstall-wkhtmltox', 'w') as f:
     with open('../pkg/uninstall-wkhtmltox', 'w') as f:
@@ -1144,27 +1154,16 @@ fi
         for root, dirs, files in os.walk(get_dir('dist')):
         for root, dirs, files in os.walk(get_dir('dist')):
             for file in files:
             for file in files:
                 f.write('echo REMOVE /usr/local/%(name)s && rm -f %(name)s\n' % { 'name': os.path.relpath(os.path.join(root, file)) })
                 f.write('echo REMOVE /usr/local/%(name)s && rm -f %(name)s\n' % { 'name': os.path.relpath(os.path.join(root, file)) })
+        f.write('echo REMOVE /usr/local/include/wkhtmltox && rm -df /usr/local/include/wkhtmltox\n')
+        f.write('echo REMOVE /usr/local/bin/uninstall-wkhtmltox && rm -f /usr/local/bin/uninstall-wkhtmltox')
 
 
     open('../extract.sh', 'w').write("""#!/bin/bash
     open('../extract.sh', 'w').write("""#!/bin/bash
 TGTDIR=/usr/local
 TGTDIR=/usr/local
 BASEDIR=%s
 BASEDIR=%s
-HAS_XZ=1
-if [ ! -x $TGTDIR/bin/xz ]
-  then
-    HAS_XZ=0;
-    cd $TGTDIR;
-    tar zxf $BASEDIR/xz.tar.gz
-fi
 cd $BASEDIR
 cd $BASEDIR
-$TGTDIR/bin/xz --decompress $BASEDIR/app.tar.xz
+./xz --decompress app.tar.xz
 cd $TGTDIR
 cd $TGTDIR
 tar xf $BASEDIR/app.tar
 tar xf $BASEDIR/app.tar
-if [ $HAS_XZ -eq 0 ]
-  then
-    cd $TGTDIR;
-    tar ztf $BASEDIR/xz.tar.gz | xargs rm -f
-fi
-rm -f $BASEDIR/app.tar $BASEDIR/xz.tar.gz
 mv $BASEDIR/uninstall-wkhtmltox $TGTDIR/bin
 mv $BASEDIR/uninstall-wkhtmltox $TGTDIR/bin
 rm -fr $BASEDIR
 rm -fr $BASEDIR
 """ % cfg['--prefix'])
 """ % cfg['--prefix'])