-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsconstruct
94 lines (82 loc) · 3.25 KB
/
sconstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
###
#This file is a part of the NV Speech Player project.
#URL: https://bitbucket.org/nvaccess/speechplayer
#Copyright 2014 NV Access Limited.
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License version 2.0, as published by
#the Free Software Foundation.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#This license can be found at:
#http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
###
import os
gitRev=None
gitDir = os.path.join(Dir('#').abspath,'.git')
if os.path.isfile(gitDir):
line=open(gitDir).readline().rstrip()
start="gitdir: "
if line.startswith(start):
gitDir=File(gitDir).Dir(line[len(start):]).abspath
try:
head = open(os.path.join(gitDir, "HEAD"), "r").read().rstrip()
if not head.startswith("ref: "):
# Detached head.
gitRev = "DETACHED-%s" % head[:7]
else:
# Strip the "ref: " prefix to get the ref.
ref = head[5:]
commit = open(os.path.join(gitDir, ref), "r").read().rstrip()
gitRev = "%s-%s" % (os.path.basename(ref),commit[:7])
except RuntimeError:
pass
vars=Variables()
vars.Add(BoolVariable('release','Set to true to build a release version',True))
vars.Add('version','version',gitRev)
vars.Add('author','author',default='unknown')
env=Environment(tools=['default','textfile'],variables=vars,HOST_ARCH='x86',TARGET_ARCH='x86')
# 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)
speechPlayerLib=env.SConscript('src/sconscript',exports=['env'],variant_dir='build/speechPlayerLib')
env.Clean(speechPlayerLib,'build')
nvdaAddon=env.SConscript('nvdaAddon/sconscript',exports=['env'],variant_dir='build/nvdaAddon')
installed=env.Install('.',[speechPlayerLib,nvdaAddon])
env.Alias("nvdaAddon",nvdaAddon)
env.Default([installed])