Index: packagerGecko.py |
=================================================================== |
--- a/packagerGecko.py |
+++ b/packagerGecko.py |
@@ -48,17 +48,17 @@ def getChromeSubdirs(baseDir, locales): |
chromeDir = getChromeDir(baseDir) |
for subdir in ('content', 'skin'): |
result[subdir] = os.path.join(chromeDir, subdir) |
for locale in locales: |
result['locale/%s' % locale] = os.path.join(chromeDir, 'locale', locale) |
return result |
def getPackageFiles(params): |
- result = set(('chrome', 'components', 'modules', 'lib', 'resources', 'defaults', 'chrome.manifest', 'icon.png', 'icon64.png',)) |
+ result = set(('chrome', 'components', 'modules', 'lib', 'resources', 'chrome.manifest', 'icon.png', 'icon64.png',)) |
baseDir = params['baseDir'] |
for file in os.listdir(baseDir): |
if file.endswith('.js') or file.endswith('.xml'): |
result.add(file) |
return result |
def getIgnoredFiles(params): |
@@ -204,47 +204,53 @@ def fixupLocales(params, files): |
if path in files: |
data = localeTools.parseString(files[path].decode('utf-8'), path) |
for key, value in reference[file].iteritems(): |
if not key in data: |
files[path] += localeTools.generateStringEntry(key, value, path).encode('utf-8') |
else: |
files[path] = reference[file]['_origData'].encode('utf-8') |
+def processJSONFiles(params, files): |
+ prefix = 'lib/' |
+ for name, content in files.iteritems(): |
+ if name.startswith(prefix) and name.endswith('.json'): |
+ params['jsonRequires'][name[len(prefix):]] = json.loads(content) |
+ for name in params['jsonRequires'].iterkeys(): |
+ del files[prefix + name] |
+ |
def addMissingFiles(params, files): |
templateData = { |
'hasChrome': False, |
'hasChromeRequires': False, |
'hasShutdownHandlers': False, |
'hasXMLHttpRequest': False, |
- 'hasVersionPref': False, |
'chromeWindows': [], |
- 'requires': {}, |
+ 'requires': set(), |
+ 'jsonRequires': params['jsonRequires'], |
'metadata': params['metadata'], |
'multicompartment': params['multicompartment'], |
'applications': dict((v, k) for k, v in KNOWN_APPS.iteritems()), |
} |
def checkScript(name): |
content = files[name] |
for match in re.finditer(r'(?:^|\s)require\(\s*"([\w\-]+)"\s*\)', content): |
- templateData['requires'][match.group(1)] = True |
+ templateData['requires'].add(match.group(1)) |
if name.startswith('chrome/content/'): |
templateData['hasChromeRequires'] = True |
if name.startswith('lib/') and re.search(r'\bXMLHttpRequest\b', content): |
templateData['hasXMLHttpRequest'] = True |
if not '/' in name or name.startswith('lib/'): |
if re.search(r'(?:^|\s)onShutdown\.', content): |
templateData['hasShutdownHandlers'] = True |
for name, content in files.iteritems(): |
if name == 'chrome.manifest': |
templateData['hasChrome'] = True |
- elif name == 'defaults/prefs.json': |
- templateData['hasVersionPref'] = 'currentVersion' in json.loads(content).get('defaults', {}) |
elif name.endswith('.js'): |
checkScript(name) |
elif name.endswith('.xul'): |
match = re.search(r'<(?:window|dialog)\s[^>]*\bwindowtype="([^">]+)"', content) |
if match: |
templateData['chromeWindows'].append(match.group(1)) |
while True: |
@@ -331,30 +337,32 @@ def createBuild(baseDir, type="gecko", o |
params = { |
'baseDir': baseDir, |
'locales': locales, |
'releaseBuild': releaseBuild, |
'version': version.encode('utf-8'), |
'metadata': metadata, |
'contributors': contributors, |
'multicompartment': multicompartment, |
+ 'jsonRequires': {}, |
} |
mapped = metadata.items('mapping') if metadata.has_section('mapping') else [] |
skip = [opt for opt, _ in mapped] + ['chrome'] |
files = Files(getPackageFiles(params), getIgnoredFiles(params), |
process=lambda path, data: processFile(path, data, params)) |
files['install.rdf'] = createManifest(params) |
files.readMappedFiles(mapped) |
files.read(baseDir, skip=skip) |
for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): |
if os.path.isdir(path): |
files.read(path, 'chrome/%s' % name, skip=skip) |
importLocales(params, files) |
fixupLocales(params, files) |
+ processJSONFiles(params, files) |
if not 'bootstrap.js' in files: |
addMissingFiles(params, files) |
if metadata.has_section('preprocess'): |
files.preprocess([f for f, _ in metadata.items('preprocess')]) |
if keyFile: |
signFiles(files, keyFile) |
files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x) |