Add buildslave target for builder.blender.org integration
authorNathan Letwory <nathan@letworyinteractive.com>
Tue, 22 Mar 2011 10:26:53 +0000 (10:26 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Tue, 22 Mar 2011 10:26:53 +0000 (10:26 +0000)
SConstruct
build_files/scons/tools/btools.py

index 49c5ae98249124474ab74177c9ac985d62ca4d48..583cc0b144be6d9a6ffafd6c5bd892a846732756 100644 (file)
@@ -669,7 +669,14 @@ if 'blenderlite' in B.targets:
 
 Depends(nsiscmd, allinstall)
 
+buildslave_action = env.Action(btools.buildslave, btools.buildslave_print)
+buildslave_cmd = env.Command('buildslave_exec', None, buildslave_action)
+buildslave_alias = env.Alias('buildslave', buildslave_cmd)
+
+Depends(buildslave_cmd, allinstall)
+
 Default(B.program_list)
 
 if not env['WITHOUT_BF_INSTALL']:
         Default(installtarget)
+
index 4554cad055dd074f9bc84483c0779c5b25455a98..3e1f497bec0c5a1f83869d55d43443e4e428b9c1 100644 (file)
@@ -56,10 +56,16 @@ def get_version():
 
     raise Exception("%s: missing version string" % fname)
 
+def get_revision():
+    build_rev = os.popen('svnversion').read()[:-1] # remove \n
+    if build_rev == '' or build_rev==None: 
+        build_rev = 'UNKNOWN'
+
+    return 'r' + build_rev
 
 # This is used in creating the local config directories
 VERSION, VERSION_DISPLAY = get_version()
-
+REVISION = get_revision()
 
 def print_arguments(args, bc):
     if len(args):
@@ -175,7 +181,7 @@ def print_targets(targs, bc):
 def validate_targets(targs, bc):
     valid_list = ['.', 'blender', 'blenderstatic', 'blenderplayer', 'webplugin',
             'blendernogame', 'blenderstaticnogame', 'blenderlite', 'release',
-            'everything', 'clean', 'install-bin', 'install', 'nsis']
+            'everything', 'clean', 'install-bin', 'install', 'nsis','buildslave']
     oklist = []
     for t in targs:
         if t in valid_list:
@@ -496,6 +502,67 @@ def read_opts(env, cfg, args):
 
     return localopts
 
+def buildbot_zip(src, dest, package_name, extension):
+    import zipfile
+    ln = len(src)+1 # one extra to remove leading os.sep when cleaning root for package_root
+    flist = list()
+
+    # create list of tuples containing file and archive name
+    for root, dirs, files in os.walk(src):
+        package_root = os.path.join(package_name, root[ln:])
+        flist.extend([(os.path.join(root, file), os.path.join(package_root, file)) for file in files])
+
+    if extension == '.zip':
+        package = zipfile.ZipFile(dest, 'w', zipfile.ZIP_DEFLATED)
+        package.comment = package_name + ' is a zip-file containing the Blender software. Visit http://www.blender.org for more information.'
+        for entry in flist:
+            package.write(entry[0], entry[1])
+        package.close()
+    else:
+        import tarfile
+        package = tarfile.open(dest, 'w:bz2')
+        for entry in flist:
+            package.add(entry[0], entry[1], recursive=False)
+        package.close()
+    bb_zip_name = os.path.normpath(src + os.sep + '..' + os.sep + 'buildbot_upload.zip')
+    print("creating %s" % (bb_zip_name))
+    bb_zip = zipfile.ZipFile(bb_zip_name, 'w', zipfile.ZIP_DEFLATED)
+    print("writing %s to %s" % (dest, bb_zip_name))
+    bb_zip.write(dest, os.path.split(dest)[1])
+    bb_zip.close()
+    print("done.")
+
+def buildslave_print(target, source, env):
+    return "Running buildslave target"
+
+def buildslave(target=None, source=None, env=None):
+    """
+    Builder for buildbot integration. Used by buildslaves of http://builder.blender.org only.
+    """
+
+    if env['OURPLATFORM'] in ('win32-vc', 'win64-vc', 'win32-mingw'):
+        extension = '.zip'
+    else:
+        extension = '.tar.bz2'
+
+    outdir = os.path.abspath(env['BF_INSTALLDIR'])
+    package_name = 'blender-' + env['OURPLATFORM'].split('-')[0] + '-'+VERSION+'-'+REVISION
+    package_dir = os.path.normpath(outdir + os.sep + '..' + os.sep + package_name)
+    package_archive = os.path.normpath(outdir + os.sep + '..' + os.sep + package_name + extension)
+
+    try:
+        if os.path.exists(package_archive):
+            os.remove(package_archive)
+        if os.path.exists(package_dir):
+            shutil.rmtree(package_dir)
+    except Exception, ex:
+        sys.stderr.write('Failed to clean up old package files: ' + str(ex) + '\n')
+        return 1
+
+    buildbot_zip(outdir, package_archive, package_name, extension)
+
+    return 0
+
 def NSIS_print(target, source, env):
     return "Creating NSIS installer for Blender"