Attachment 'nsis-changes-for-linux-and-includes.diff'
Download 1 Index: build/scons_tools/nsis.py
2 ===================================================================
3 --- build/scons_tools/nsis.py
4 +++ build/scons_tools/nsis.py
5 @@ -33,9 +33,11 @@
6 #import SCons.Sig
7 import os.path
8 import glob
9 +import platform
10
11 +is_linux = (platform.system() == 'Linux')
12
13 -def nsis_parse( sources, keyword, multiple ):
14 +def nsis_parse( sources, keyword, multiple, nsisdefines ):
15 """
16 A function that knows how to read a .nsi file and figure
17 out what files are referenced, or find the 'OutFile' line.
18 @@ -47,27 +49,44 @@
19 just want the first one.
20 """
21 stuff = []
22 + current_ignored = 0
23 for s in sources:
24 c = s.get_contents()
25 + linenum = 0
26 for l in c.split('\n'):
27 - semi = l.find(';')
28 - if (semi != -1):
29 - l = l[:semi]
30 - hash = l.find('#')
31 - if (hash != -1):
32 - l = l[:hash]
33 - # Look for the keyword
34 - l = l.strip()
35 - spl = l.split(None,1)
36 - if len(spl) > 1:
37 - if spl[0].capitalize() == keyword.capitalize():
38 - arg = spl[1]
39 - if arg.startswith('"') and arg.endswith('"'):
40 - arg = arg[1:-1]
41 - if multiple:
42 - stuff += [ arg ]
43 - else:
44 - return arg
45 + linenum += 1
46 + try:
47 + semi = l.find(';')
48 + if (semi != -1):
49 + l = l[:semi]
50 + hash = l.find('#')
51 + if (hash != -1):
52 + l = l[:hash]
53 + # Look for the keyword
54 + l = l.strip()
55 + spl = l.split(None,1)
56 + if len(spl) == 1 and current_ignored > 0 and spl[0].capitalize() == '!endif':
57 + current_ignored -= 1
58 + elif len(spl) > 1:
59 + if current_ignored > 0 and spl[0].capitalize() in [ '!ifdef', '!ifmacrodef', '!ifndef' ]:
60 + current_ignored += 1
61 + elif current_ignored == 0 and spl[0].capitalize() == '!ifdef' and spl[1] not in nsisdefines:
62 + current_ignored += 1
63 + elif current_ignored == 0 and spl[0].capitalize() == '!ifndef' and spl[1] in nsisdefines:
64 + current_ignored += 1
65 + elif current_ignored == 0 and spl[0].capitalize() == keyword.capitalize():
66 + arg = spl[1]
67 + if keyword.capitalize() == 'File' and arg.lower().startswith('/oname') and len(spl) > 1:
68 + arg = spl[2]
69 + if arg.startswith('"') and arg.endswith('"'):
70 + arg = arg[1:-1]
71 + if multiple:
72 + stuff += [ arg ]
73 + else:
74 + return arg
75 + except:
76 + print "in %(source)s, line %(linenum)d\n" % { 'source': s, 'linenum': linenum }
77 + raise
78 return stuff
79
80
81 @@ -94,7 +113,7 @@
82 return filename
83
84
85 -def nsis_scanner( node, env, path ):
86 +def nsis_scanner( node, env, path, source_dir = None):
87 """
88 The scanner that looks through the source .nsi files and finds all lines
89 that are the 'File' command, fixes the directories etc, and returns them.
90 @@ -103,16 +122,34 @@
91 if not node.exists():
92 return []
93 nodes = []
94 - source_dir = node.get_dir()
95 - for include in nsis_parse([node],'file',1):
96 + if source_dir is None:
97 + try:
98 + source_dir = env['NSISSRCDIR']
99 + except:
100 + source_dir = node.get_dir()
101 + for include in nsis_parse([node],'file',1, env['NSISDEFINES']):
102 exp = nsis_path(include,env['NSISDEFINES'],source_dir)
103 if type(exp) != list:
104 exp = [exp]
105 for p in exp:
106 - for filename in glob.glob( os.path.abspath(
107 + for filename in env.Glob( os.path.abspath(
108 os.path.join(str(source_dir),p))):
109 # Why absolute path? Cause it breaks mysteriously without it :(
110 nodes.append(filename)
111 + for include in nsis_parse([node],'!include',1, env['NSISDEFINES']):
112 + exp = nsis_path(include,env['NSISDEFINES'],source_dir)
113 + if type(exp) != list:
114 + exp = [exp]
115 + for p in exp:
116 + if p not in [ 'LogicLib.nsh', 'MUI2.nsh' ]:
117 + # get ../bin/makensis and go up two directories
118 + nsis_install_location = os.path.dirname(os.path.dirname(env['NSIS']))
119 + filename = os.path.abspath(os.path.join(nsis_install_location, 'share', 'nsis', 'Include', p))
120 + if not os.path.isfile(filename):
121 + filename = os.path.abspath(os.path.join(str(source_dir),p))
122 + # Why absolute path? Cause it breaks mysteriously without it :(
123 + nodes.append(filename)
124 + nodes += nsis_scanner(env.File(filename), env, path, source_dir = source_dir)
125 return nodes
126
127
128 @@ -121,7 +158,7 @@
129 The emitter changes the target name to match what the command actually will
130 output, which is the argument to the OutFile command.
131 """
132 - nsp = nsis_parse(source,'outfile',0)
133 + nsp = nsis_parse(source,'outfile',0, env['NSISDEFINES'])
134 if not nsp:
135 return (target,source)
136 x = (
137 @@ -160,10 +197,15 @@
138 ret += ' '
139 if env.has_key('NSISDEFINES'):
140 for d in env['NSISDEFINES']:
141 - ret += '/D'+d
142 + if is_linux:
143 + ret += '-D'+d
144 + else:
145 + ret += '/D'+d
146 if env['NSISDEFINES'][d]:
147 ret +='='+quoteIfSpaced(toString(env['NSISDEFINES'][d],env))
148 ret += ' '
149 + if is_linux:
150 + ret += '-- '
151 for s in source:
152 ret += quoteIfSpaced(str(s))
153 return ret
154 @@ -176,7 +218,7 @@
155 src_suffix='.nsi',
156 emitter=nsis_emitter)
157 env.Append(SCANNERS = SCons.Scanner.Scanner( function = nsis_scanner,
158 - skeys = ['.nsi']))
159 + skeys = ['.nsi','.nsh']))
160 if not env.has_key('NSISDEFINES'):
161 env['NSISDEFINES'] = {}
162 env['NSIS'] = find_nsis(env)
163 @@ -199,8 +241,9 @@
164 return None
165 except:
166 pass # Couldn't find the key, just act like we can't read the registry
167 +
168 # Hope it's on the path
169 - return env.WhereIs('makensis.exe')
170 + return env.WhereIs('makensis' + env['PROGSUFFIX'])
171
172 def exists(env):
173 """
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2013-03-30 18:18:25, 5.7 KB) [[attachment:nsis-changes-for-linux-and-includes.diff]]
- [get | view] (2013-03-30 18:18:25, 8.3 KB) [[attachment:nsis-with-modifications-for-linux-and-includes.py]]
You are not allowed to attach a file to this page.
