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

Unified Diff: packagerChrome.py

Issue 29350281: Issue 4047 - Improved configuration of converted JS files (Closed)
Patch Set: Use defaultdict(list) instead lambda Created Aug. 30, 2016, 2:22 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 | « no previous file | no next file » | 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
@@ -10,6 +10,7 @@
from StringIO import StringIO
import struct
import sys
+import collections
import packager
from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuildVersion, getTemplate, Files
@@ -145,30 +146,28 @@
def convertJS(params, files):
from jshydra.abp_rewrite import rewrite_js
+ output_files = collections.OrderedDict()
+ args = collections.defaultdict(list)
+
for item in params['metadata'].items('convert_js'):
- file, sources = item
- baseDir = os.path.dirname(item.source)
+ filename, arg = re.search(r'^(.*?)(?:\[(.*)\])?$', item[0]).groups()
+ if arg is None:
+ output_files[filename] = (item[1].split(), item.source)
+ else:
+ args[filename].append('{}={}'.format(arg, item[1]))
- # Make sure the file is inside an included directory
- if '/' in file and not files.isIncluded(file):
+ for filename, (input_files, origin) in output_files.iteritems():
+ if '/' in filename and not files.isIncluded(filename):
continue
- sourceFiles = sources.split()
- args = []
- try:
- argsStart = sourceFiles.index('--arg')
- args = sourceFiles[argsStart + 1:]
- sourceFiles = sourceFiles[0:argsStart]
- except ValueError:
- pass
+ base_dir = os.path.dirname(origin)
+ jshydra_args = ['--arg', ' '.join(args[filename])]
- # Source files of the conversion shouldn't be part of the build
- for sourceFile in sourceFiles:
- if sourceFile in files:
- del files[sourceFile]
+ for input_filename in input_files:
+ jshydra_args.append(os.path.join(base_dir, input_filename))
+ files.pop(input_filename, None)
- sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourceFiles)
- files[file] = rewrite_js(['--arg', ' '.join(args)] + sourceFiles)
+ files[filename] = rewrite_js(jshydra_args)
def toJson(data):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld