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

Side by Side Diff: packagerGecko.py

Issue 29337900: Issue 2850 - Get rid of synchronous XMLHttpRequest on startup, embed JSON files directly instead (Closed)
Patch Set: Created March 7, 2016, 12:26 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 | « lib/prefs.js ('k') | 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 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import os 7 import os
8 import sys 8 import sys
9 import re 9 import re
10 import hashlib 10 import hashlib
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 def getChromeSubdirs(baseDir, locales): 46 def getChromeSubdirs(baseDir, locales):
47 result = {} 47 result = {}
48 chromeDir = getChromeDir(baseDir) 48 chromeDir = getChromeDir(baseDir)
49 for subdir in ('content', 'skin'): 49 for subdir in ('content', 'skin'):
50 result[subdir] = os.path.join(chromeDir, subdir) 50 result[subdir] = os.path.join(chromeDir, subdir)
51 for locale in locales: 51 for locale in locales:
52 result['locale/%s' % locale] = os.path.join(chromeDir, 'locale', locale) 52 result['locale/%s' % locale] = os.path.join(chromeDir, 'locale', locale)
53 return result 53 return result
54 54
55 def getPackageFiles(params): 55 def getPackageFiles(params):
56 result = set(('chrome', 'components', 'modules', 'lib', 'resources', 'defaults ', 'chrome.manifest', 'icon.png', 'icon64.png',)) 56 result = set(('chrome', 'components', 'modules', 'lib', 'resources', 'chrome.m anifest', 'icon.png', 'icon64.png',))
57 57
58 baseDir = params['baseDir'] 58 baseDir = params['baseDir']
59 for file in os.listdir(baseDir): 59 for file in os.listdir(baseDir):
60 if file.endswith('.js') or file.endswith('.xml'): 60 if file.endswith('.js') or file.endswith('.xml'):
61 result.add(file) 61 result.add(file)
62 return result 62 return result
63 63
64 def getIgnoredFiles(params): 64 def getIgnoredFiles(params):
65 return {'.incomplete', 'meta.properties'} 65 return {'.incomplete', 'meta.properties'}
66 66
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for file in reference.iterkeys(): 202 for file in reference.iterkeys():
203 path = 'chrome/locale/%s/%s' % (locale, file) 203 path = 'chrome/locale/%s/%s' % (locale, file)
204 if path in files: 204 if path in files:
205 data = localeTools.parseString(files[path].decode('utf-8'), path) 205 data = localeTools.parseString(files[path].decode('utf-8'), path)
206 for key, value in reference[file].iteritems(): 206 for key, value in reference[file].iteritems():
207 if not key in data: 207 if not key in data:
208 files[path] += localeTools.generateStringEntry(key, value, path).enc ode('utf-8') 208 files[path] += localeTools.generateStringEntry(key, value, path).enc ode('utf-8')
209 else: 209 else:
210 files[path] = reference[file]['_origData'].encode('utf-8') 210 files[path] = reference[file]['_origData'].encode('utf-8')
211 211
212 def processJSONFiles(params, files):
213 prefix = 'lib/'
214 for name, content in files.iteritems():
215 if name.startswith(prefix) and name.endswith('.json'):
216 params['jsonRequires'][name[len(prefix):]] = json.loads(content)
217 for name in params['jsonRequires'].iterkeys():
218 del files[prefix + name]
219
212 def addMissingFiles(params, files): 220 def addMissingFiles(params, files):
213 templateData = { 221 templateData = {
214 'hasChrome': False, 222 'hasChrome': False,
215 'hasChromeRequires': False, 223 'hasChromeRequires': False,
216 'hasShutdownHandlers': False, 224 'hasShutdownHandlers': False,
217 'hasXMLHttpRequest': False, 225 'hasXMLHttpRequest': False,
218 'hasVersionPref': False,
219 'chromeWindows': [], 226 'chromeWindows': [],
220 'requires': {}, 227 'requires': set(),
228 'jsonRequires': params['jsonRequires'],
221 'metadata': params['metadata'], 229 'metadata': params['metadata'],
222 'multicompartment': params['multicompartment'], 230 'multicompartment': params['multicompartment'],
223 'applications': dict((v, k) for k, v in KNOWN_APPS.iteritems()), 231 'applications': dict((v, k) for k, v in KNOWN_APPS.iteritems()),
224 } 232 }
225 233
226 def checkScript(name): 234 def checkScript(name):
227 content = files[name] 235 content = files[name]
228 for match in re.finditer(r'(?:^|\s)require\(\s*"([\w\-]+)"\s*\)', content): 236 for match in re.finditer(r'(?:^|\s)require\(\s*"([\w\-]+)"\s*\)', content):
229 templateData['requires'][match.group(1)] = True 237 templateData['requires'].add(match.group(1))
230 if name.startswith('chrome/content/'): 238 if name.startswith('chrome/content/'):
231 templateData['hasChromeRequires'] = True 239 templateData['hasChromeRequires'] = True
232 if name.startswith('lib/') and re.search(r'\bXMLHttpRequest\b', content): 240 if name.startswith('lib/') and re.search(r'\bXMLHttpRequest\b', content):
233 templateData['hasXMLHttpRequest'] = True 241 templateData['hasXMLHttpRequest'] = True
234 if not '/' in name or name.startswith('lib/'): 242 if not '/' in name or name.startswith('lib/'):
235 if re.search(r'(?:^|\s)onShutdown\.', content): 243 if re.search(r'(?:^|\s)onShutdown\.', content):
236 templateData['hasShutdownHandlers'] = True 244 templateData['hasShutdownHandlers'] = True
237 245
238 for name, content in files.iteritems(): 246 for name, content in files.iteritems():
239 if name == 'chrome.manifest': 247 if name == 'chrome.manifest':
240 templateData['hasChrome'] = True 248 templateData['hasChrome'] = True
241 elif name == 'defaults/prefs.json':
242 templateData['hasVersionPref'] = 'currentVersion' in json.loads(content).g et('defaults', {})
243 elif name.endswith('.js'): 249 elif name.endswith('.js'):
244 checkScript(name) 250 checkScript(name)
245 elif name.endswith('.xul'): 251 elif name.endswith('.xul'):
246 match = re.search(r'<(?:window|dialog)\s[^>]*\bwindowtype="([^">]+)"', con tent) 252 match = re.search(r'<(?:window|dialog)\s[^>]*\bwindowtype="([^">]+)"', con tent)
247 if match: 253 if match:
248 templateData['chromeWindows'].append(match.group(1)) 254 templateData['chromeWindows'].append(match.group(1))
249 255
250 while True: 256 while True:
251 missing = [] 257 missing = []
252 for module in templateData['requires']: 258 for module in templateData['requires']:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 contributors = getContributors(metadata) 335 contributors = getContributors(metadata)
330 336
331 params = { 337 params = {
332 'baseDir': baseDir, 338 'baseDir': baseDir,
333 'locales': locales, 339 'locales': locales,
334 'releaseBuild': releaseBuild, 340 'releaseBuild': releaseBuild,
335 'version': version.encode('utf-8'), 341 'version': version.encode('utf-8'),
336 'metadata': metadata, 342 'metadata': metadata,
337 'contributors': contributors, 343 'contributors': contributors,
338 'multicompartment': multicompartment, 344 'multicompartment': multicompartment,
345 'jsonRequires': {},
339 } 346 }
340 347
341 mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] 348 mapped = metadata.items('mapping') if metadata.has_section('mapping') else []
342 skip = [opt for opt, _ in mapped] + ['chrome'] 349 skip = [opt for opt, _ in mapped] + ['chrome']
343 files = Files(getPackageFiles(params), getIgnoredFiles(params), 350 files = Files(getPackageFiles(params), getIgnoredFiles(params),
344 process=lambda path, data: processFile(path, data, params)) 351 process=lambda path, data: processFile(path, data, params))
345 files['install.rdf'] = createManifest(params) 352 files['install.rdf'] = createManifest(params)
346 files.readMappedFiles(mapped) 353 files.readMappedFiles(mapped)
347 files.read(baseDir, skip=skip) 354 files.read(baseDir, skip=skip)
348 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): 355 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems():
349 if os.path.isdir(path): 356 if os.path.isdir(path):
350 files.read(path, 'chrome/%s' % name, skip=skip) 357 files.read(path, 'chrome/%s' % name, skip=skip)
351 importLocales(params, files) 358 importLocales(params, files)
352 fixupLocales(params, files) 359 fixupLocales(params, files)
360 processJSONFiles(params, files)
353 if not 'bootstrap.js' in files: 361 if not 'bootstrap.js' in files:
354 addMissingFiles(params, files) 362 addMissingFiles(params, files)
355 if metadata.has_section('preprocess'): 363 if metadata.has_section('preprocess'):
356 files.preprocess([f for f, _ in metadata.items('preprocess')]) 364 files.preprocess([f for f, _ in metadata.items('preprocess')])
357 if keyFile: 365 if keyFile:
358 signFiles(files, keyFile) 366 signFiles(files, keyFile)
359 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x ) 367 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x )
360 368
361 def autoInstall(baseDir, type, host, port, multicompartment=False): 369 def autoInstall(baseDir, type, host, port, multicompartment=False):
362 fileBuffer = StringIO() 370 fileBuffer = StringIO()
363 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multicomp artment) 371 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multicomp artment)
364 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue()) 372 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue())
OLDNEW
« no previous file with comments | « lib/prefs.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld