Skip to content

Commit

Permalink
dist-git: make script working again for Py3 and Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 30, 2021
1 parent f58faa6 commit c5fb911
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
24 changes: 18 additions & 6 deletions cMake/FreeCAD_Helpers/CreatePackagingTargets.cmake
Expand Up @@ -5,25 +5,37 @@ macro(CreatePackagingTargets)
#add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
add_custom_target(dist-git
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/makedist.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR}
--bindir=${CMAKE_BINARY_DIR}
--major=${PACKAGE_VERSION_MAJOR}
--minor=${PACKAGE_VERSION_MINOR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(distdfsg-git
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/makedist.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR} --dfsg
--bindir=${CMAKE_BINARY_DIR}
--major=${PACKAGE_VERSION_MAJOR}
--minor=${PACKAGE_VERSION_MINOR}
--dfsg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
if(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX OR MINGW)
add_custom_target(distcheck-git
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/makedist.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR} --check
--bindir=${CMAKE_BINARY_DIR}
--major=${PACKAGE_VERSION_MAJOR}
--minor=${PACKAGE_VERSION_MINOR}
--check
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(distcheckdfsg-git
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/Tools/makedist.py
--srcdir=${CMAKE_SOURCE_DIR} --bindir=${CMAKE_BINARY_DIR} --dfsg --check
--bindir=${CMAKE_BINARY_DIR}
--major=${PACKAGE_VERSION_MAJOR}
--minor=${PACKAGE_VERSION_MINOR}
--dfsg
--check
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
endif()

endmacro(CreatePackagingTargets)
44 changes: 30 additions & 14 deletions src/Tools/makedist.py
Expand Up @@ -5,23 +5,29 @@
# Python script to make source tarballs.
#

import sys, os, getopt, tarfile, gzip, time, io, platform, shutil
import sys, os, getopt, tarfile, gzip, time, io, platform, shutil, subprocess

def main():
bindir="."
major="0"
minor="0"
dfsg=False
check=False
wta=""
wta=None
try:
opts, args = getopt.getopt(sys.argv[1:], "sb:", ["srcdir=","bindir=","dfsg", "check"])
opts, args = getopt.getopt(sys.argv[1:], "sb:", ["srcdir=","bindir=","major=","minor=","dfsg", "check"])
except getopt.GetoptError:
pass

for o, a in opts:
if o in ("-s", "--srcdir"):
print("%s is deprecated -- ignoring" % (o))
print("{} is deprecated -- ignoring".format(o))
if o in ("-b", "--bindir"):
bindir = a
if o in ("--major"):
major = a
if o in ("--minor"):
minor = a
if o in ("--dfsg"):
dfsg = True
wta = "--worktree-attributes"
Expand All @@ -41,14 +47,15 @@ def main():
info=os.popen("git rev-list HEAD").read()
revision='%04d' % (info.count('\n'))

verfile = open("%s/src/Build/Version.h" % (bindir), 'r')
verstream = io.StringIO(verfile.read())
verfile = open("{}/src/Build/Version.h".format(bindir), 'rb')
verstream = io.BytesIO(verfile.read())
verfile.close()

version_minor = verstream.getvalue().split('FCVersionMinor "')[1][:2]
version_major = major
version_minor = minor

PACKAGE_NAME = 'freecad'
version = "0.%s.%s" % (version_minor, revision)
version = "{}.{}.{}".format(version_major, version_minor, revision)

DIRNAME = "%(p)s-%(v)s" % {'p': PACKAGE_NAME, 'v': version}
TARNAME = DIRNAME + '.tar'
Expand All @@ -61,10 +68,13 @@ def main():
verinfo.size = len(verstream.getvalue())
verinfo.mtime = time.time()

print(("git archive %s --prefix=%s/ HEAD" % (wta, DIRNAME)))
if wta is None:
print(("git archive --prefix={}/ HEAD".format(DIRNAME)))
else:
print(("git archive {} --prefix={}/ HEAD".format(wta, DIRNAME)))

if platform.system() == 'Windows':
os.popen("git archive %s --prefix=%s/ --output=%s HEAD"
% (wta, DIRNAME, TARNAME)).read()
os.popen("git archive {} --prefix={}/ --output={} HEAD".format(wta, DIRNAME, TARNAME)).read()

tar = tarfile.TarFile(mode="a", name=TARNAME)
tar.addfile(verinfo, verstream)
Expand All @@ -77,9 +87,15 @@ def main():
tardata.close()
os.remove(TARNAME)
else:
tardata = os.popen("git archive %s --prefix=%s/ HEAD"
% (wta, DIRNAME)).read()
tarstream = io.StringIO(tardata)
cmd_line = ["git", "archive"]
if not wta is None:
cmd_line.append(wta)
cmd_line.append("--prefix={}/".format(DIRNAME))
cmd_line.append("HEAD")

tardata = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = tardata.communicate()
tarstream = io.BytesIO(out)

tar = tarfile.TarFile(mode="a", fileobj=tarstream)
tar.addfile(verinfo, verstream)
Expand Down

0 comments on commit c5fb911

Please sign in to comment.