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: Avoid error if input arguments seens before input files Created Aug. 30, 2016, 12:37 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 from collections import OrderedDict
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 = OrderedDict()
150 args = {}
148 for item in params['metadata'].items('convert_js'): 151 for item in params['metadata'].items('convert_js'):
149 file, sources = item 152 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups()
150 baseDir = os.path.dirname(item.source) 153 if arg is None:
154 output_files[filename] = (item[1].split(), item.source)
155 else:
156 args.setdefault(filename, []).append('{}={}'.format(arg, item[1]))
151 157
152 # Make sure the file is inside an included directory 158 for filename, (input_files, origin) in output_files.iteritems():
153 if '/' in file and not files.isIncluded(file): 159 if '/' in filename and not files.isIncluded(filename):
154 continue 160 continue
155 161
156 sourceFiles = sources.split() 162 base_dir = os.path.dirname(origin)
157 args = [] 163 jshydra_args = ['--arg', ' '.join(args.get(filename, []))]
158 try:
159 argsStart = sourceFiles.index('--arg')
160 args = sourceFiles[argsStart + 1:]
161 sourceFiles = sourceFiles[0:argsStart]
162 except ValueError:
163 pass
164 164
165 # Source files of the conversion shouldn't be part of the build 165 for input_filename in input_files:
166 for sourceFile in sourceFiles: 166 jshydra_args.append(os.path.join(base_dir, input_filename))
167 if sourceFile in files: 167 files.pop(input_filename, None)
168 del files[sourceFile]
169 168
170 sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), s ourceFiles) 169 files[filename] = rewrite_js(jshydra_args)
171 files[file] = rewrite_js(['--arg', ' '.join(args)] + sourceFiles)
172 170
173 171
174 def toJson(data): 172 def toJson(data):
175 return json.dumps( 173 return json.dumps(
176 data, ensure_ascii=False, sort_keys=True, 174 data, ensure_ascii=False, sort_keys=True,
177 indent=2, separators=(',', ': ') 175 indent=2, separators=(',', ': ')
178 ).encode('utf-8') + '\n' 176 ).encode('utf-8') + '\n'
179 177
180 178
181 def importGeckoLocales(params, files): 179 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', 383 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
386 ('general', 'testScripts')) 384 ('general', 'testScripts'))
387 385
388 zipdata = files.zipToString() 386 zipdata = files.zipToString()
389 signature = None 387 signature = None
390 pubkey = None 388 pubkey = None
391 if keyFile != None: 389 if keyFile != None:
392 signature = signBinary(zipdata, keyFile) 390 signature = signBinary(zipdata, keyFile)
393 pubkey = getPublicKey(keyFile) 391 pubkey = getPublicKey(keyFile)
394 writePackage(outFile, pubkey, signature, zipdata) 392 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