Skip to content

Commit

Permalink
sconstruct: Use Python's zipfile module to generate the symbols and c…
Browse files Browse the repository at this point in the history
…ontroller client archives instead of using 7-Zip.

This means we no longer depend on 7-Zip. The resulting archives are a bit larger, but this isn't a major issue and it's worth it to eliminate a dependency.
Fixes #3725.
  • Loading branch information
jcsteh committed Jan 12, 2014
1 parent a66c40b commit 38add5c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
1 change: 0 additions & 1 deletion readme.txt
Expand Up @@ -52,7 +52,6 @@ The following dependencies are included in Git submodules:
=== Other Dependencies ===
These dependencies are not included in Git submodules, but aren't needed by most people.
* If you want to be able to use the Handy Tech braille display driver when running from source code, you will need to install the Handy Tech universal driver: ftp://ftp.handytech.de/public/Software/BrailleDriver/bsd1206a.exe
* To create the NVDA controller client and symbols archives: 7-Zip: http://www.7-zip.org/
* To generate developer documentation for nvdaHelper: Doxygen Windows installer, version 1.7.3: http://www.stack.nl/~dimitri/doxygen/download.html

== Preparing the Source Tree ==
Expand Down
78 changes: 44 additions & 34 deletions sconstruct
Expand Up @@ -38,20 +38,6 @@ sys.path.append("source")
import versionInfo
del sys.path[-1]

# Get the path to 7z.
try:
szKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\7-Zip", 0, _winreg.KEY_READ)
except WindowsError:
try:
szKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\7-Zip", 0, _winreg.KEY_WOW64_64KEY | _winreg.KEY_READ)
except WindowsError:
szKey = None
if szKey:
with szKey:
sz = os.path.join(_winreg.QueryValueEx(szKey, "Path")[0], "7z.exe")
else:
sz = "7z"

makensis = "miscDeps\\tools\\NSIS\\makensis"

# Get the path to xgettext.
Expand Down Expand Up @@ -218,24 +204,48 @@ def NVDADistGenerator(target, source, env, for_signature):
return action
env["BUILDERS"]["NVDADist"] = Builder(generator=NVDADistGenerator, target_factory=Dir)

# A builder to generate an archive with 7-Zip.
def SzArchiveGenerator(target, source, env, for_signature):
cmd = []
relativeToSourceDir = env.get("relativeToSourceDir", False)
if relativeToSourceDir:
cmd.extend(("cd", source[0], "&&"))
cmd.extend((sz, "a", "-mx=9"))
ext = os.path.splitext(str(target[0]))[1]
if ext == ".7z":
cmd.append("-t7z")
elif ext == ".zip":
cmd.append("-tzip")
elif ext == ".exe":
cmd.append("-sfx7z.sfx")
cmd.extend((target[0].abspath,
"." if relativeToSourceDir else "$SOURCES"))
return [cmd]
env["BUILDERS"]["SzArchive"] = Builder(generator=SzArchiveGenerator)
# A builder to generate a zip archive.
# We roll our own instead of using env.Zip because we want to create some archives
# relative to a specified directory.
def ZipArchiveAction(target, source, env):
relativeTo = env.get("relativeTo", None)
if relativeTo:
relativeTo = relativeTo.path
def getArcName(origName):
arcName = os.path.relpath(origName, relativeTo)
if arcName.startswith(".."):
arcName = arcName.replace(".." + os.path.sep, "")
return "" if arcName == "." else arcName
else:
getArcName = lambda origName: "" if origName == "." else origName

# Nasty hack to make zipfile use best compression, since it isn't configurable.
# Tried setting memlevel to 9 as well, but it made compression slightly worse.
import zlib
origZDefComp = zlib.Z_DEFAULT_COMPRESSION
zlib.Z_DEFAULT_COMPRESSION = zlib.Z_BEST_COMPRESSION

import zipfile
zf = None
try:
zf = zipfile.ZipFile(target[0].path, "w", zipfile.ZIP_DEFLATED)
for s in source:
if os.path.isdir(s.path):
for path, dirs, files in os.walk(s.path):
arcPath = getArcName(path)
if arcPath:
zf.write(path, arcPath)
for f in files:
zf.write(os.path.join(path, f), os.path.join(arcPath, f))
else:
zf.write(s.path, getArcName(s.path))

finally:
if zf:
zf.close()
zlib.Z_DEFAULT_COMPRESSION = origZDefComp

env["BUILDERS"]["ZipArchive"] = Builder(action=ZipArchiveAction)

# An action to sign an executable with certFile.
signExec = ["signtool", "sign", "/f", certFile]
Expand Down Expand Up @@ -272,7 +282,7 @@ if certFile:
env.AddPostAction(launcher, [signExec])
env.Alias("launcher", launcher)

clientArchive = env.SzArchive(outputDir.File("%s_controllerClient.zip" % outFilePrefix), clientDir, relativeToSourceDir=True)
clientArchive = env.ZipArchive(outputDir.File("%s_controllerClient.zip" % outFilePrefix), clientDir, relativeTo=clientDir)
env.Alias("client", clientArchive)

changesFile=env.Command(outputDir.File("%s_changes.html" % outFilePrefix),userDocsDir.File('en/changes.html'),Copy('$TARGET','$SOURCE'))
Expand Down Expand Up @@ -339,7 +349,7 @@ env.Alias("pot", pot)
symbolsList=[]
symbolsList.extend(env.Glob(os.path.join(sourceLibDir.path,'*.pdb')))
symbolsList.extend(env.Glob(os.path.join(sourceLibDir64.path,'*.pdb')))
symbolsArchive = env.SzArchive(outputDir.File("%s_debugSymbols.zip" % outFilePrefix), symbolsList)
symbolsArchive = env.ZipArchive(outputDir.File("%s_debugSymbols.zip" % outFilePrefix), symbolsList)
env.Alias("symbolsArchive", symbolsArchive)

env.Default(dist)
Expand Down

0 comments on commit 38add5c

Please sign in to comment.