Bläddra i källkod

improvements in the build script framework

* allow custom variables to be used when building dependent libraries
* handle chroot builds more easily
Ashish Kulkarni 10 år sedan
förälder
incheckning
a8babc123d
1 ändrade filer med 28 tillägg och 14 borttagningar
  1. 28 14
      scripts/build.py

+ 28 - 14
scripts/build.py

@@ -378,7 +378,7 @@ DEPENDENT_LIBS = {
             'mingw-w64-cross-win*': {
                 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
                 'commands': [
-                    'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw-w64)s- no-shared no-asm mingw64',
+                    'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw_w64)s- no-shared no-asm mingw64',
                     'make',
                     'make install_sw']
             }
@@ -404,7 +404,7 @@ DEPENDENT_LIBS = {
                     'include/zconf.h': 'zconf.h',
                     'lib/libz.a'     : 'libz.a'
                 },
-                'replace':  [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw-w64)s-')],
+                'replace':  [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw_w64)s-')],
                 'commands': ['make -f win32/Makefile.gcc']
             }
         }
@@ -437,9 +437,9 @@ DEPENDENT_LIBS = {
                 'replace': [
                     ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
                     ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
-                    ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw-w64)s-gcc'),
-                    ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw-w64)s-ar'),
-                    ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw-w64)s-ranlib')],
+                    ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw_w64)s-gcc'),
+                    ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw_w64)s-ar'),
+                    ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw_w64)s-ranlib')],
                 'commands': ['make -f scripts/makefile.gcc libpng.a']
             },
             'osx-carbon-i386': {
@@ -480,7 +480,7 @@ DEPENDENT_LIBS = {
             'mingw-w64-cross-win*': {
                 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
                 'commands': [
-                    './configure --host=%(mingw-w64)s --disable-shared --prefix=%(destdir)s',
+                    './configure --host=%(mingw_w64)s --disable-shared --prefix=%(destdir)s',
                     'make install']
             },
             'osx-carbon-i386': {
@@ -575,6 +575,11 @@ def shell(cmd):
     if ret != 0:
         error("%s\ncommand failed: exit code %d" % (cmd, ret))
 
+def chroot_shell(name, cmd):
+    ret = os.system('schroot -c wkhtmltopdf-%s -- %s ' % (name, cmd))
+    if ret != 0:
+        error("command inside chroot failed: exit code %d" % ret)
+
 def get_output(*cmd):
     try:
         return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
@@ -680,11 +685,12 @@ def _is_compiled(dst, loc):
         present = present and exists(os.path.join(dst, name))
     return present
 
-def build_deplibs(config, basedir):
+def build_deplibs(config, basedir, **kwargs):
     mkdir_p(os.path.join(basedir, config))
 
     dstdir = os.path.join(basedir, config, 'deplibs')
-    vars   = {'destdir': dstdir, 'mingw-w64': MINGW_W64_PREFIX.get(rchop(config, '-dbg'), '')}
+    vars   = {'destdir': dstdir }
+    vars.update(kwargs)
     for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
         cfg = None
         for key in DEPENDENT_LIBS[lib]['build']:
@@ -760,9 +766,13 @@ def build_setup_schroot(config, basedir):
             del ARCH[ARCH.index('i386')]
 
     for arch in ARCH:
-        message('******************* %s-%s\n' % (chroot, arch))
+        alias = '%s-%s' % (chroot, arch)
+        if command_list[0][0] == 'set_alias':
+            alias = command_list[0][1]
+            del command_list[0]
+        message('******************* %s\n' % alias)
         base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
-        root_dir = os.path.join(base_dir, 'wkhtmltopdf-%s-%s' % (chroot, arch))
+        root_dir = os.path.join(base_dir, alias)
         os.system('umount %s/proc' % root_dir)
         os.system('umount %s/sys'  % root_dir)
         rmdir(root_dir)
@@ -811,8 +821,8 @@ def build_setup_schroot(config, basedir):
                 open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
                 shell('chmod a+x %s' % loc)
             elif name == 'schroot_conf':
-                cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
-                cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))
+                cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s' % alias, 'w')
+                cfg.write('[wkhtmltopdf-%s]\n' % alias)
                 cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
                 cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
                 cfg.write('users=%s\nroot-users=root\n' % login)
@@ -973,7 +983,7 @@ def check_mingw64_cross(config):
 
 def build_mingw64_cross(config, basedir):
     version, simple_version = get_version(basedir)
-    build_deplibs(config, basedir)
+    build_deplibs(config, basedir, mingw_w64=MINGW_W64_PREFIX.get(rchop(config, '-dbg')))
 
     libdir = os.path.join(basedir, config, 'deplibs')
     qtdir  = os.path.join(basedir, config, 'qt')
@@ -1243,7 +1253,7 @@ def main():
         usage()
 
     for arg in sys.argv[2:]:
-        if not arg in ['-clean', '-debug']:
+        if not arg in ['-clean', '-debug', '-chroot-build']:
             usage()
 
     final_config = config
@@ -1255,6 +1265,10 @@ def main():
         rmdir(os.path.join(basedir, config))
 
     os.chdir(rootdir)
+    if '-chroot-build' in sys.argv[2:]:
+        globals()['chroot_build_%s' % BUILDERS[config]](final_config, basedir)
+        return
+
     globals()['check_%s' % BUILDERS[config]](final_config)
     globals()['build_%s' % BUILDERS[config]](final_config, basedir)