This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
sconstruct
executable file
·328 lines (285 loc) · 12.9 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
###
#This file is a part of the NVDA project.
#URL: http://www.nvda-project.org/
#Copyright 2010 James Teh <[email protected]>.
#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 sys
import os
import _winreg
from glob import glob
# Import NVDA's versionInfo module.
import gettext
gettext.install("nvda", unicode=True)
sys.path.append("source")
import versionInfo
del sys.path[-1]
# Get the path to signtool.
try:
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Microsoft SDKs\Windows") as sdksKey:
signtool = os.path.join(_winreg.QueryValueEx(sdksKey, "CurrentInstallFolder")[0], "Bin", "signtool.exe")
except WindowsError:
signtool = "signtool"
# 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"
# Get the path to makensis.
try:
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\NSIS") as nsisKey:
makensis = os.path.join(_winreg.QueryValueEx(nsisKey, None)[0], "makensis.exe")
except WindowsError:
makensis = "makensis"
# Get the path to xgettext.
XGETTEXT = os.path.abspath(os.path.join("tools", "xgettext.exe"))
# Get the path to epydoc.
EPYDOC = os.path.join(sys.exec_prefix, "scripts", "epydoc.py")
def keyCommandsDocTool(env):
import keyCommandsDoc
kcdAction=env.Action(
lambda target,source,env: not keyCommandsDoc.KeyCommandsMaker(source[0].path,target[0].path).make(),
lambda target,source,env: 'Generating %s'%target[0],
)
kcdBuilder=env.Builder(
action=kcdAction,
suffix='.t2t',
src_suffix='.t2t',
)
env['BUILDERS']['keyCommandsDoc']=kcdBuilder
keyCommandsLangBlacklist=set([])
vars = Variables()
vars.Add("version", "The version of this build", versionInfo.version)
vars.Add(BoolVariable("release", "Whether this is a release version", False))
vars.Add("publisher", "The publisher of this build", versionInfo.publisher)
vars.Add("updateVersionType", "The version type for which to check for updates", versionInfo.updateVersionType or "")
vars.Add(PathVariable("certFile", "The certificate file with which to sign executables", "",
lambda key, val, env: not val or PathVariable.PathIsFile(key, val, env)))
vars.Add("certPassword", "The password for the private key in the signing certificate", "")
vars.Add("certTimestampServer", "The URL of the timestamping server to use to timestamp authenticode signatures", "")
vars.Add(PathVariable("outputDir", "The directory where the final built archives and such will be placed", "output",PathVariable.PathIsDirCreate))
vars.Add(ListVariable('targetArchitectures','Which architectures should NVDA support?','all',['x86','x86_64']))
vars.Add(ListVariable("nvdaHelperDebugFlags", "a list of debugging features you require", 'symbols', ["symbols","debugCRT","RTC","noOptimize"]))
vars.Add(EnumVariable('nvdaHelperLogLevel','The level of logging you wish to see, lower is more verbose','15',allowed_values=[str(x) for x in xrange(60)]))
#Base environment for this and sub sconscripts
env = Environment(variables=vars,tools=["textfile","gettext","t2t",keyCommandsDocTool,'doxygen'])
#Check for any unknown variables
unknown=vars.UnknownVariables().keys()
if len(unknown)>0:
print "Unknown commandline variables: %s"%unknown
Exit(1)
env["copyright"]=versionInfo.copyright
version = env["version"]
release = env["release"]
publisher = env["publisher"]
certFile = env["certFile"]
certPassword = env["certPassword"]
certTimestampServer = env["certTimestampServer"]
userDocsDir=Dir('user_docs')
sourceDir = Dir("source")
Export('sourceDir')
clientDir=Dir('extras/controllerClient')
Export('clientDir')
sourceLibDir=sourceDir.Dir('lib')
Export('sourceLibDir')
sourceTypelibDir=sourceDir.Dir('typelibs')
Export('sourceTypelibDir')
sourceLibDir64=sourceDir.Dir('lib64')
Export('sourceLibDir64')
buildDir = Dir("build")
outFilePrefix = "nvda{type}_{version}".format(type="" if release else "_snapshot", version=version)
outputDir=Dir(env['outputDir'])
devDocsOutputDir=outputDir.Dir('devDocs')
env.SConscript('source/comInterfaces_sconscript',exports=['env'])
#Process nvdaHelper scons files
env.SConscript('nvdaHelper/sconscript',exports=['env'])
#Allow all NVDA's gettext po files to be compiled in source/locale
for po in env.Glob(sourceDir.path+'/locale/*/lc_messages/*.po'):
env.gettextMoFile(po)
#Allow all key command t2t files to be generated from their userGuide t2t sources
for lang in os.listdir(userDocsDir.path):
if lang in keyCommandsLangBlacklist: continue
for ug in glob(os.path.join(userDocsDir.path,lang,'userGuide.t2t')):
env.keyCommandsDoc(File(ug).File('keyCommands.t2t'),ug)
t2tBuildConf = env.Textfile(userDocsDir.File("build.t2tConf"), [
# We need to do this one as PostProc so it gets converted for the title.
r"%!PostProc: NVDA_VERSION {}".format(version),
r"%!PreProc: NVDA_URL {}".format(versionInfo.url),
r"%!PreProc: NVDA_COPYRIGHT_YEARS {}".format(versionInfo.copyrightYears),
])
#Allow all t2t files to be converted to html in user_docs
#As we use scons Glob this will also include the keyCommands.t2t files
for t2tFile in env.Glob(os.path.join(userDocsDir.path,'*','*.t2t')):
htmlFile=env.txt2tags(t2tFile)
#txt2tags can not be run in parallel so make sure scons knows this
env.SideEffect('_txt2tags',htmlFile)
# All of our t2t files require build.t2tConf.
env.Depends(htmlFile,t2tBuildConf)
#And also build the developer guide -- which must be moved at some point
htmlFile=env.txt2tags('developerGuide.t2t')
env.SideEffect('_txt2tags',htmlFile)
devGuide=env.Command(devDocsOutputDir.File('developerGuide.html'),htmlFile,Move('$TARGET','$SOURCE'))
env.Alias("developerGuide",devGuide)
#Generate all needed comtypes COM interfaces
#command = ['cd', sourceDir.path, '&&', sys.executable]
#if release:
# command.append('-O')
#command.append('generateComInterfaces.py')
#comInterfaces = env.Command(sourceDir.Dir('comInterfaces'), None, [command])
#env.AlwaysBuild(comInterfaces)
#env.Depends(comInterfaces,sourceDir.Dir('typelibs'))
# A builder to generate an NVDA distribution.
def NVDADistGenerator(target, source, env, for_signature):
buildVersionFn = os.path.join(str(source[0]), "_buildVersion.py")
# Make the NVDA build use the specified version.
# We don't do this using normal scons mechanisms because we want it to be cleaned up immediately after this builder
# and py2exe will cause bytecode files to be created for it which scons doesn't know about.
updateVersionType = env["updateVersionType"] or None
action = [lambda target, source, env: file(buildVersionFn, "w").write(
'version = {version!r}\r\n'
'publisher = {publisher!r}\r\n'
'updateVersionType = {updateVersionType!r}\r\n'
.format(version=version, publisher=publisher, updateVersionType=updateVersionType))]
buildCmd = ["cd", source[0].path, "&&",
sys.executable]
if release:
buildCmd.append("-O")
buildCmd.extend(("setup.py", "build", "--build-base", buildDir.abspath,
"py2exe", "--dist-dir", target[0].abspath))
if release:
buildCmd.append("-O1")
action.append(buildCmd)
if env.get("uiAccess"):
buildCmd.append("--enable-uiAccess")
if certFile:
for prog in "nvda_noUIAccess", "nvda_uiAccess", "nvda_slave", "nvda_service":
action.append(signExec[:-1] + [os.path.join(target[0].path, "%s.exe" % prog)])
for ext in "", "c", "o":
action.append(Delete(buildVersionFn + ext))
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)
# An action to sign an executable with certFile.
signExec = [signtool, "sign", "/f", certFile]
if certPassword:
signExec.extend(("/p", certPassword))
if certTimestampServer:
signExec.extend(("/t", certTimestampServer))
signExec.append("$TARGET")
uninstFile=File("dist/uninstall.exe")
uninstGen = env.Command(File("uninstaller/uninstGen.exe"), "uninstaller/uninst.nsi",
[[makensis, "/V2",
"/DVERSION=$version", '/DPUBLISHER="$publisher"','/DCOPYRIGHT="$copyright"',
"/DUNINSTEXE=%s"%uninstFile.abspath,
"/DINSTEXE=${TARGET.abspath}",
"$SOURCE"]])
uninstaller=env.Command(uninstFile,uninstGen,[uninstGen])
if certFile:
env.AddPostAction(uninstaller, [signExec])
dist = env.NVDADist("dist", [sourceDir,userDocsDir], uiAccess=bool(certFile))
env.Depends(dist,uninstaller)
# Dir node targets don't get cleaned, so cleaning of the dist nodes has to be explicitly specified.
env.Clean(dist, dist)
# Clean the intermediate build directory.
env.Clean([dist], buildDir)
launcher = env.Command(outputDir.File("%s.exe" % outFilePrefix), ["launcher/nvdaLauncher.nsi", dist],
[[makensis, "/V2",
"/DVERSION=$version", '/DPUBLISHER="$publisher"','/DCOPYRIGHT="$copyright"',
"/DNVDADistDir=${SOURCES[1].abspath}", "/DLAUNCHEREXE=${TARGET.abspath}",
"$SOURCE"]])
if certFile:
env.AddPostAction(launcher, [signExec])
env.Alias("launcher", launcher)
clientArchive = env.SzArchive(outputDir.File("%s_controllerClient.zip" % outFilePrefix), clientDir, relativeToSourceDir=True)
env.Alias("client", clientArchive)
changesFile=env.Command(outputDir.File("%s_changes.html" % outFilePrefix),userDocsDir.File('en/changes.html'),Copy('$TARGET','$SOURCE'))
env.Alias('changes',changesFile)
userGuideFile=env.Command(outputDir.File("userGuide.html"),userDocsDir.File('en/userGuide.html'),Copy('$TARGET','$SOURCE'))
env.Alias('userGuide',userGuideFile)
def makePot(target, source, env):
# Generate the pot.
if env.Execute([["cd", sourceDir, "&&",
XGETTEXT,
"-o", target[0].abspath,
"--package-name", versionInfo.name, "--package-version", version,
"--foreign-user",
"--add-comments=Translators:",
"--keyword=pgettext:1c,2",
] + [os.path.relpath(str(f), str(sourceDir)) for f in source]
]) != 0:
raise RuntimeError("xgettext failed")
# Tweak the headers.
potFn = str(target[0])
tmpFn = "%s.tmp" % potFn
with file(potFn, "rt") as inp, file(tmpFn, "wt") as out:
for lineNum, line in enumerate(inp):
if lineNum == 1:
line = "# %s\n" % versionInfo.copyright
elif lineNum == 2:
# Delete line.
continue
elif lineNum == 15:
line = line.replace("CHARSET", "UTF-8")
out.write(line)
os.remove(potFn)
os.rename(tmpFn, potFn)
devDocs_nvdaHelper_temp=env.Doxygen(source='nvdaHelper/doxyfile')
devDocs_nvdaHelper=env.Command(devDocsOutputDir.Dir('nvdaHelper'),devDocs_nvdaHelper_temp,Move('$TARGET','$SOURCE'))
env.Alias('devDocs_nvdaHelper', devDocs_nvdaHelper)
env.Clean('devDocs_nvdaHelper', devDocs_nvdaHelper)
devDocs_nvda = env.Command(devDocsOutputDir.Dir("nvda"), None, [[
"cd", sourceDir.path, "&&",
sys.executable, EPYDOC,
"--output", "${TARGET.abspath}",
"--quiet", "--html", "--include-log", "--no-frames",
"--name", "NVDA", "--url", "http://www.nvda-project.org/",
"*.py", "appModules", "brailleDisplayDrivers", r"comInterfaces\__init__.py",
"config", "globalPlugins", "gui", "NVDAObjects",
"synthDrivers", "textInfos", "virtualBuffers",
]])
env.Alias('devDocs', [devGuide, devDocs_nvda])
env.Clean('devDocs', [devGuide, devDocs_nvda])
pot = env.Command(outputDir.File("%s.pot" % outFilePrefix),
# Don't use sourceDir as the source, as this depends on comInterfaces and nvdaHelper.
# We only depend on the Python files.
[f for pattern in ("*.py", r"*\*.py", r"*\*\*.py") for f in env.Glob(os.path.join(sourceDir.path, pattern))],
makePot)
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)
env.Alias("symbolsArchive", symbolsArchive)
env.Default(dist)