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: Improve check for require Created April 1, 2017, 1:27 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/modules.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
153 for item in params['metadata'].items('convert_js'): 145 for item in params['metadata'].items('convert_js'):
154 name, value = item 146 name, value = item
155 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups() 147 filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', name).groups()
156 if arg is None: 148 if arg is None:
157 output_files[filename] = (value.split(), item.source) 149 output_files[filename] = (value.split(), item.source)
158 else: 150 else:
(...skipping 17 matching lines...) Expand all
176 module_name = os.path.splitext(os.path.basename(input_filename))[0] 168 module_name = os.path.splitext(os.path.basename(input_filename))[0]
177 prefix = os.path.basename(os.path.dirname(input_filename)) 169 prefix = os.path.basename(os.path.dirname(input_filename))
178 if prefix != 'lib': 170 if prefix != 'lib':
179 module_name = '{}_{}'.format(prefix, module_name) 171 module_name = '{}_{}'.format(prefix, module_name)
180 with open(os.path.join(base_dir, input_filename), 'r') as file: 172 with open(os.path.join(base_dir, input_filename), 'r') as file:
181 modules.append((module_name, file.read().decode('utf-8'))) 173 modules.append((module_name, file.read().decode('utf-8')))
182 files.pop(input_filename, None) 174 files.pop(input_filename, None)
183 175
184 files[filename] = template.render( 176 files[filename] = template.render(
185 args=current_args, 177 args=current_args,
186 modules=modules 178 basename=params['metadata'].get('general', 'basename'),
179 modules=modules,
180 type=params['type'],
181 version=params['metadata'].get('general', 'version')
187 ).encode('utf-8') 182 ).encode('utf-8')
188 183
189 184
190 def toJson(data): 185 def toJson(data):
191 return json.dumps( 186 return json.dumps(
192 data, ensure_ascii=False, sort_keys=True, 187 data, ensure_ascii=False, sort_keys=True,
193 indent=2, separators=(',', ': ') 188 indent=2, separators=(',', ': ')
194 ).encode('utf-8') + '\n' 189 ).encode('utf-8') + '\n'
195 190
196 191
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 files['manifest.json'] = createManifest(params, files) 384 files['manifest.json'] = createManifest(params, files)
390 if type == 'chrome': 385 if type == 'chrome':
391 fixTranslationsForCWS(files) 386 fixTranslationsForCWS(files)
392 387
393 if devenv: 388 if devenv:
394 import buildtools 389 import buildtools
395 import random 390 import random
396 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js') 391 files.read(os.path.join(buildtools.__path__[0], 'chromeDevenvPoller__.js '), relpath='devenvPoller__.js')
397 files['devenvVersion__'] = str(random.random()) 392 files['devenvVersion__'] = str(random.random())
398 393
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'): 394 if metadata.has_option('general', 'testScripts'):
405 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l', 395 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp l',
406 ('general', 'testScripts')) 396 ('general', 'testScripts'))
407 397
408 zipdata = files.zipToString() 398 zipdata = files.zipToString()
409 signature = None 399 signature = None
410 pubkey = None 400 pubkey = None
411 if keyFile != None: 401 if keyFile != None:
412 signature = signBinary(zipdata, keyFile) 402 signature = signBinary(zipdata, keyFile)
413 pubkey = getPublicKey(keyFile) 403 pubkey = getPublicKey(keyFile)
414 writePackage(outFile, pubkey, signature, zipdata) 404 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « no previous file | packagerEdge.py » ('j') | templates/modules.js.tmpl » ('J')

Powered by Google App Engine
This is Rietveld