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

Unified Diff: packagerChrome.py

Issue 9257092: More build tools improvements (Closed)
Patch Set: Added some more changes required to build Firefox and Chrome extensions from the same repository (s… Created Jan. 25, 2013, 1:47 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
===================================================================
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -39,24 +39,29 @@ def getPackageFiles(params):
result.add('qunit')
baseDir = params['baseDir']
for file in os.listdir(baseDir):
if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'):
result.add(file)
return result
+def processFile(path, data, params):
+ # We don't change anything yet, this function currently only exists here so
+ # that it can be overridden if necessary.
+ return data
+
def createManifest(params):
template = getTemplate('manifest.json.tmpl')
templateData = dict(params)
baseDir = templateData['baseDir']
metadata = templateData['metadata']
- if metadata.has_option('general', 'pageAction'):
+ if metadata.has_option('general', 'pageAction') and metadata.get('general', 'pageAction') != '':
icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1)
templateData['pageAction'] = {'icon': icon, 'popup': popup}
if metadata.has_option('general', 'icons'):
icons = {}
iconsDir = baseDir
for dir in metadata.get('general', 'icons').split('/')[0:-1]:
iconsDir = os.path.join(iconsDir, dir)
@@ -76,22 +81,24 @@ def createManifest(params):
if params['experimentalAPI']:
templateData['permissions'].append('experimental')
if metadata.has_option('general', 'backgroundScripts'):
templateData['backgroundScripts'] = re.split(r'\s+', metadata.get('general', 'backgroundScripts'))
if params['devenv']:
templateData['backgroundScripts'].append('devenvPoller__.js')
- if metadata.has_option('general', 'webAccessible'):
+ if metadata.has_option('general', 'webAccessible') and metadata.get('general', 'webAccessible') != '':
templateData['webAccessible'] = re.split(r'\s+', metadata.get('general', 'webAccessible'))
if metadata.has_section('contentScripts'):
contentScripts = []
for run_at, scripts in metadata.items('contentScripts'):
+ if scripts == '':
+ continue
contentScripts.append({
'matches': ['http://*/*', 'https://*/*'],
'js': re.split(r'\s+', scripts),
'run_at': run_at,
'all_frames': True,
})
templateData['contentScripts'] = contentScripts
@@ -107,35 +114,131 @@ def createManifest(params):
return manifest.encode('utf-8')
def createPoller(params):
template = getTemplate('chromeDevenvPoller__.js.tmpl')
return template.render(params).encode('utf-8');
def convertJS(params, files):
from jshydra.abp_rewrite import doRewrite
- baseDir = params['baseDir']
- for file, sources in params['metadata'].items('convert_js'):
+ for item in params['metadata'].items('convert_js'):
+ file, sources = item
+ baseDir = os.path.dirname(item.source)
+
# Make sure the file is inside an included directory
if '/' in file and not files.isIncluded(file):
continue
sourceFiles = re.split(r'\s+', sources)
args = []
try:
argsStart = sourceFiles.index('--arg')
args = sourceFiles[argsStart + 1:]
sourceFiles = sourceFiles[0:argsStart]
except ValueError:
pass
sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourceFiles)
files[file] = doRewrite(sourceFiles, args)
+def importGeckoLocales(params, files):
+ import localeTools
+
+ localeCodeMapping = {
+ 'ar': 'ar',
+ 'bg': 'bg',
+ 'ca': 'ca',
+ 'cs': 'cs',
+ 'da': 'da',
+ 'de': 'de',
+ 'el': 'el',
+ 'en-US': 'en_US',
+ 'en-GB': 'en_GB',
+ 'es-ES': 'es',
+ 'es-AR': 'es_419',
+ 'et': 'et',
+ 'fi': 'fi',
+ # '': 'fil', ???
+ 'fr': 'fr',
+ 'he': 'he',
+ 'hi-IN': 'hi',
+ 'hr': 'hr',
+ 'hu': 'hu',
+ 'id': 'id',
+ 'it': 'it',
+ 'ja': 'ja',
+ 'ko': 'ko',
+ 'lt': 'lt',
+ 'lv': 'lv',
+ 'nl': 'nl',
+ # 'nb-NO': 'no', ???
+ 'pl': 'pl',
+ 'pt-BR': 'pt_BR',
+ 'pt-PT': 'pt_PT',
+ 'ro': 'ro',
+ 'ru': 'ru',
+ 'sk': 'sk',
+ 'sl': 'sl',
+ 'sr': 'sr',
+ 'sv-SE': 'sv',
+ 'th': 'th',
+ 'tr': 'tr',
+ 'uk': 'uk',
+ 'vi': 'vi',
+ 'zh-CN': 'zh_CN',
+ 'zh-TW': 'zh_TW',
+ }
+
+ for source, target in localeCodeMapping.iteritems():
+ targetFile = '_locales/%s/messages.json' % target
+
+ for item in params['metadata'].items('import_locales'):
+ fileName, keys = item
+ parts = map(lambda n: source if n == '*' else n, fileName.split('/'))
+ sourceFile = os.path.join(os.path.dirname(item.source), *parts)
+ incompleteMarker = os.path.join(os.path.dirname(sourceFile), '.incomplete')
+ if not os.path.exists(sourceFile) or os.path.exists(incompleteMarker):
+ continue
+
+ data = {}
+ if targetFile in files:
+ data = json.loads(files[targetFile].decode('utf-8'))
+
+ try:
+ sourceData = localeTools.readFile(sourceFile)
+
+ # Resolve wildcard imports
+ if keys == '*' or keys == '=*':
+ importList = sourceData.keys()
+ importList = filter(lambda k: not k.startswith('_'), importList)
+ if keys == '=*':
+ importList = map(lambda k: '=' + k, importList)
+ keys = ' '.join(importList)
+
+ for stringID in re.split(r'\s+', keys):
+ noMangling = False
+ if stringID.startswith('='):
+ stringID = stringID[1:]
+ noMangling = True
+
+ if stringID in sourceData:
+ if noMangling:
+ key = re.sub(r'\W', '_', stringID)
+ else:
+ key = re.sub(r'\..*', '', parts[-1]) + '_' + re.sub(r'\W', '_', stringID)
+ if key in data:
+ print 'Warning: locale string %s defined multiple times' % key
+ data[key] = {'message': sourceData[stringID]}
+ except Exception, e:
+ print 'Warning: error importing locale data from %s: %s' % (sourceFile, e)
+
+ files[targetFile] = json.dumps(data, ensure_ascii=False, sort_keys=True,
+ indent=2, separators=(',', ': ')).encode('utf-8') + '\n'
+
def signBinary(zipdata, keyFile):
import M2Crypto
if not os.path.exists(keyFile):
M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
key = M2Crypto.EVP.load_key(keyFile)
key.sign_init()
key.sign_update(zipdata)
return key.final()
@@ -166,25 +269,29 @@ def createBuild(baseDir, outFile=None, b
'baseDir': baseDir,
'releaseBuild': releaseBuild,
'version': version,
'experimentalAPI': experimentalAPI,
'devenv': devenv,
'metadata': metadata,
}
- files = Files(getPackageFiles(params), getIgnoredFiles(params))
+ files = Files(getPackageFiles(params), getIgnoredFiles(params),
+ process=lambda path, data: processFile(path, data, params))
files['manifest.json'] = createManifest(params)
if metadata.has_section('mapping'):
- files.readMappedFiles(baseDir, metadata.items('mapping'))
+ files.readMappedFiles(metadata.items('mapping'))
files.read(baseDir)
if metadata.has_section('convert_js'):
convertJS(params, files)
+ if metadata.has_section('import_locales'):
+ importGeckoLocales(params, files)
+
if devenv:
files['devenvPoller__.js'] = createPoller(params)
zipdata = files.zipToString()
signature = None
pubkey = None
if keyFile != None:
signature = signBinary(zipdata, keyFile)
« no previous file with comments | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld