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

Side by Side Diff: packagerChrome.py

Issue 29399569: Issue 5060 - Move require into modules template, make info a module (Closed)
Patch Set: Don't redeclare require Created March 31, 2017, 6:48 a.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 | packagerEdge.py » ('j') | templates/chromeInfo.js.tmpl » ('J')
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
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 # Normalize JSON structure 131 # Normalize JSON structure
132 licenseComment = re.compile(r'/\*.*?\*/', re.S) 132 licenseComment = re.compile(r'/\*.*?\*/', re.S)
133 data = json.loads(re.sub(licenseComment, '', manifest, 1)) 133 data = json.loads(re.sub(licenseComment, '', manifest, 1))
134 if '_dummy' in data: 134 if '_dummy' in data:
135 del data['_dummy'] 135 del data['_dummy']
136 manifest = json.dumps(data, sort_keys=True, indent=2) 136 manifest = json.dumps(data, sort_keys=True, indent=2)
137 137
138 return manifest.encode('utf-8') 138 return manifest.encode('utf-8')
139 139
140 140
141 def createInfoModule(params):
142 if params['type'] == 'gecko-webext':
143 template = getTemplate('geckoInfo.js.tmpl')
144 else:
145 template = getTemplate('chromeInfo.js.tmpl')
146 return template.render(params).encode('utf-8')
147
148
149 def convertJS(params, files): 141 def convertJS(params, files):
150 output_files = collections.OrderedDict() 142 output_files = collections.OrderedDict()
151 args = {} 143 args = {}
152 144
145 info_module = None
Sebastian Noack 2017/03/31 10:42:01 How about merging chromeInfo.js.tmpl, geckoInfo.js
kzar 2017/03/31 14:03:01 Well I tried that and figured that repeating the m
Sebastian Noack 2017/03/31 14:50:45 We definitely should clean up that mess and target
146 info_template = {
147 'chrome': 'chromeInfo.js.tmpl',
148 'gecko-webext': 'geckoInfo.js.tmpl'
149 }.get(params['type'])
150 if info_template:
151 info_module = getTemplate(info_template).render(
152 basename=params['metadata'].get('general', 'basename'),
153 version=params['metadata'].get('general', 'version')
154 ).decode('utf-8')
155
153 for item in params['metadata'].items('convert_js'): 156 for item in params['metadata'].items('convert_js'):
154 name, value = item 157 name, value = item
155 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups() 158 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups()
156 if arg is None: 159 if arg is None:
157 output_files[filename] = (value.split(), item.source) 160 output_files[filename] = (value.split(), item.source)
158 else: 161 else:
159 args.setdefault(filename, {})[arg] = value 162 args.setdefault(filename, {})[arg] = value
160 163
161 template = getTemplate('modules.js.tmpl') 164 template = getTemplate('modules.js.tmpl')
162 165
163 for filename, (input_files, origin) in output_files.iteritems(): 166 for filename, (input_files, origin) in output_files.iteritems():
164 if '/' in filename and not files.isIncluded(filename): 167 if '/' in filename and not files.isIncluded(filename):
165 continue 168 continue
166 169
167 current_args = args.get(filename, {}) 170 current_args = args.get(filename, {})
168 current_args['autoload'] = [module for module in 171 current_args['autoload'] = [module for module in
169 current_args.get('autoload', '').split(',') 172 current_args.get('autoload', '').split(',')
170 if module != ''] 173 if module != '']
171 174
172 base_dir = os.path.dirname(origin) 175 base_dir = os.path.dirname(origin)
173 modules = [] 176 modules = []
174 177
178 if 'module' in current_args and info_module:
179 modules.append(('info', info_module))
180
175 for input_filename in input_files: 181 for input_filename in input_files:
176 module_name = os.path.splitext(os.path.basename(input_filename))[0] 182 module_name = os.path.splitext(os.path.basename(input_filename))[0]
177 prefix = os.path.basename(os.path.dirname(input_filename)) 183 prefix = os.path.basename(os.path.dirname(input_filename))
178 if prefix != 'lib': 184 if prefix != 'lib':
179 module_name = '{}_{}'.format(prefix, module_name) 185 module_name = '{}_{}'.format(prefix, module_name)
180 with open(os.path.join(base_dir, input_filename), 'r') as file: 186 with open(os.path.join(base_dir, input_filename), 'r') as file:
181 modules.append((module_name, file.read().decode('utf-8'))) 187 modules.append((module_name, file.read().decode('utf-8')))
182 files.pop(input_filename, None) 188 files.pop(input_filename, None)
183 189
184 files[filename] = template.render( 190 files[filename] = template.render(
185 args=current_args, 191 args=current_args,
186 modules=modules 192 modules=modules,
193 basename=params['metadata'].get('general', 'basename'),
194 version=params['metadata'].get('general', 'version')
187 ).encode('utf-8') 195 ).encode('utf-8')
188 196
189 197
190 def toJson(data): 198 def toJson(data):
191 return json.dumps( 199 return json.dumps(
192 data, ensure_ascii=False, sort_keys=True, 200 data, ensure_ascii=False, sort_keys=True,
193 indent=2, separators=(',', ': ') 201 indent=2, separators=(',', ': ')
194 ).encode('utf-8') + '\n' 202 ).encode('utf-8') + '\n'
195 203
196 204
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 files['manifest.json'] = createManifest(params, files) 397 files['manifest.json'] = createManifest(params, files)
390 if type == 'chrome': 398 if type == 'chrome':
391 fixTranslationsForCWS(files) 399 fixTranslationsForCWS(files)
392 400
393 if devenv: 401 if devenv:
394 import buildtools 402 import buildtools
395 import random 403 import random
396 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js') 404 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js')
397 files['devenvVersion__'] = str(random.random()) 405 files['devenvVersion__'] = str(random.random())
398 406
399 if (metadata.has_option('general', 'backgroundScripts') and
400 'lib/info.js' in metadata.get('general', 'backgroundScripts').split() an d
401 'lib/info.js' not in files):
402 files['lib/info.js'] = createInfoModule(params)
403
404 if metadata.has_option('general', 'testScripts'): 407 if metadata.has_option('general', 'testScripts'):
405 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', 408 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
406 ('general', 'testScripts')) 409 ('general', 'testScripts'))
407 410
408 zipdata = files.zipToString() 411 zipdata = files.zipToString()
409 signature = None 412 signature = None
410 pubkey = None 413 pubkey = None
411 if keyFile != None: 414 if keyFile != None:
412 signature = signBinary(zipdata, keyFile) 415 signature = signBinary(zipdata, keyFile)
413 pubkey = getPublicKey(keyFile) 416 pubkey = getPublicKey(keyFile)
414 writePackage(outFile, pubkey, signature, zipdata) 417 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « no previous file | packagerEdge.py » ('j') | templates/chromeInfo.js.tmpl » ('J')

Powered by Google App Engine
This is Rietveld