Add makedist script and custom build target

This commit is contained in:
wmayer
2012-02-05 17:44:11 +01:00
parent e94ec3ee99
commit dcc5f1fa80
2 changed files with 63 additions and 0 deletions

View File

@@ -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}
)

57
src/Tools/makedist.py Normal file
View File

@@ -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()