Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerChrome.py

Issue 29350281: Issue 4047 - Improved configuration of converted JS files (Closed)
Patch Set: Use defaultdict(list) instead lambda Created Aug. 30, 2016, 2:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import errno 5 import errno
6 import io 6 import io
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 from StringIO import StringIO 10 from StringIO import StringIO
11 import struct 11 import struct
12 import sys 12 import sys
13 import collections
13 14
14 import packager 15 import packager
15 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files 16 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files
16 17
17 defaultLocale = 'en_US' 18 defaultLocale = 'en_US'
18 19
19 20
20 def getIgnoredFiles(params): 21 def getIgnoredFiles(params):
21 return {'store.description'} 22 return {'store.description'}
22 23
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 139
139 140
140 def createInfoModule(params): 141 def createInfoModule(params):
141 template = getTemplate('chromeInfo.js.tmpl') 142 template = getTemplate('chromeInfo.js.tmpl')
142 return template.render(params).encode('utf-8') 143 return template.render(params).encode('utf-8')
143 144
144 145
145 def convertJS(params, files): 146 def convertJS(params, files):
146 from jshydra.abp_rewrite import rewrite_js 147 from jshydra.abp_rewrite import rewrite_js
147 148
149 output_files = collections.OrderedDict()
150 args = collections.defaultdict(list)
151
148 for item in params['metadata'].items('convert_js'): 152 for item in params['metadata'].items('convert_js'):
149 file, sources = item 153 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups()
150 baseDir = os.path.dirname(item.source) 154 if arg is None:
155 output_files[filename] = (item[1].split(), item.source)
156 else:
157 args[filename].append('{}={}'.format(arg, item[1]))
151 158
152 # Make sure the file is inside an included directory 159 for filename, (input_files, origin) in output_files.iteritems():
153 if '/' in file and not files.isIncluded(file): 160 if '/' in filename and not files.isIncluded(filename):
154 continue 161 continue
155 162
156 sourceFiles = sources.split() 163 base_dir = os.path.dirname(origin)
157 args = [] 164 jshydra_args = ['--arg', ' '.join(args[filename])]
158 try:
159 argsStart = sourceFiles.index('--arg')
160 args = sourceFiles[argsStart + 1:]
161 sourceFiles = sourceFiles[0:argsStart]
162 except ValueError:
163 pass
164 165
165 # Source files of the conversion shouldn't be part of the build 166 for input_filename in input_files:
166 for sourceFile in sourceFiles: 167 jshydra_args.append(os.path.join(base_dir, input_filename))
167 if sourceFile in files: 168 files.pop(input_filename, None)
168 del files[sourceFile]
169 169
170 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), s ourceFiles) 170 files[filename] = rewrite_js(jshydra_args)
171 files[file] = rewrite_js(['--arg', ' '.join(args)] + sourceFiles)
172 171
173 172
174 def toJson(data): 173 def toJson(data):
175 return json.dumps( 174 return json.dumps(
176 data, ensure_ascii=False, sort_keys=True, 175 data, ensure_ascii=False, sort_keys=True,
177 indent=2, separators=(',', ': ') 176 indent=2, separators=(',', ': ')
178 ).encode('utf-8') + '\n' 177 ).encode('utf-8') + '\n'
179 178
180 179
181 def importGeckoLocales(params, files): 180 def importGeckoLocales(params, files):
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', 384 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
386 ('general', 'testScripts')) 385 ('general', 'testScripts'))
387 386
388 zipdata = files.zipToString() 387 zipdata = files.zipToString()
389 signature = None 388 signature = None
390 pubkey = None 389 pubkey = None
391 if keyFile != None: 390 if keyFile != None:
392 signature = signBinary(zipdata, keyFile) 391 signature = signBinary(zipdata, keyFile)
393 pubkey = getPublicKey(keyFile) 392 pubkey = getPublicKey(keyFile)
394 writePackage(outFile, pubkey, signature, zipdata) 393 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld