From 88c3e48ba3aa4be5f8896c61db4ccc80a679a410 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 5 Feb 2012 17:44:11 +0100 Subject: [PATCH] Add makedist script and custom build target --- CMakeLists.txt | 6 +++++ src/Tools/makedist.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/Tools/makedist.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fccee3948..31c52b74e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,3 +467,9 @@ if(FREECAD_MAINTAINERS_BUILD AND NOT WIN32) #ADD_CUSTOM_TARGET(DIST make package_source) endif(FREECAD_MAINTAINERS_BUILD AND NOT WIN32) + add_custom_target(dist-git + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/makedist.py + --srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + diff --git a/src/Tools/makedist.py b/src/Tools/makedist.py new file mode 100644 index 0000000000..d5590874c2 --- /dev/null +++ b/src/Tools/makedist.py @@ -0,0 +1,57 @@ +#! python +# -*- coding: utf-8 -*- +# (c) 2006 Werner Mayer LGPL +# +# Python script to make source tarballs. +# + +import sys, os, getopt, tarfile, gzip, time, StringIO + +def main(): + srcdir="." + bindir="." + try: + opts, args = getopt.getopt(sys.argv[1:], "sb:", ["srcdir=","bindir="]) + except getopt.GetoptError: + pass + + for o, a in opts: + if o in ("-s", "--srcdir"): + srcdir = a + if o in ("-b", "--bindir"): + bindir = a + + # revision number + info=os.popen("git rev-list HEAD").read() + revision='%04d' % (info.count('\n')) + + PACKAGE_NAME = 'freecad' + version = "0.13.%s" % (revision) + + DIRNAME = "%(p)s-%(v)s" % {'p': PACKAGE_NAME, 'v': version} + TARNAME = DIRNAME + '.tar.gz' + + verfile = open("%s/src/Build/Version.h" % (bindir), 'r') + verstream = StringIO.StringIO(verfile.read()) + verfile.close() + verinfo = tarfile.TarInfo(DIRNAME + "/src/Build/Version.h") + verinfo.mode = 0660 + verinfo.size = len(verstream.getvalue()) + verinfo.mtime = time.time() + + print "git archive --worktree-attributes --prefix=%s/ HEAD" % (DIRNAME) + tardata = os.popen("git archive --worktree-attributes --prefix=%s/ HEAD" + % (DIRNAME)).read() + tarstream = StringIO.StringIO(tardata) + + tar = tarfile.TarFile(mode="a", fileobj=tarstream) + tar.addfile(verinfo, verstream) + tar.close() + + out = gzip.open(TARNAME, "wb") + out.write(tarstream.getvalue()) + out.close() + print "Created " + TARNAME + +if __name__ == "__main__": + main()