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

Delta Between Two Patch Sets: convert_js.py

Issue 9846017: Make JavaScript sources compile into the library; convert JavaScript files on the fly (Closed)
Left Patch Set: Split various fake modules out of the large compat script Created March 14, 2013, 10:24 p.m.
Right Patch Set: Review comments addressed Created March 15, 2013, 3:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « .hgsubstate ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 #!/usr/bin/env python
2 # coding: utf-8
3
4 import sys, os, codecs, re
5 baseDir = os.path.abspath(os.path.dirname(__file__))
6 sys.path.append(os.path.join(baseDir, 'adblockplus', 'buildtools', 'jshydra'))
7 from abp_rewrite import doRewrite
8
9 def toCString(string):
10 string = string.replace('\\', '\\\\').replace('"', '\\"')
11 string = string.replace('\r', '').replace('\n', '\\n')
12 return '"%s"' % string.encode('utf-8')
13
14 def convert(convertFiles, verbatimFiles, outFile):
15 outHandle = open(outFile, 'wb')
16 print >>outHandle, 'const char* jsSources[] = {'
17
18 for file in verbatimFiles:
19 fileHandle = codecs.open(file, 'rb', encoding='utf-8')
20 print >>outHandle, toCString(os.path.basename(file)) + ','
21 print >>outHandle, toCString(fileHandle.read()) + ','
22 fileHandle.close()
23
24 convertFiles = map(lambda f: f if os.path.isabs(f) else os.path.join(baseDir, f), convertFiles)
25 converted = doRewrite(convertFiles, ['module=true', 'source_repo=https://hg.ad blockplus.org/adblockplus/'])
26 print >>outHandle, toCString('adblockplus.js') + ','
27 print >>outHandle, toCString(converted) + ','
28
29 print >>outHandle, '0, 0'
30 print >>outHandle, '};'
31
32 if __name__ == '__main__':
33 args = sys.argv[1:]
34 outFile = args.pop()
35
36 verbatimFiles = []
37 while len(args):
38 file = args.pop()
39 if file == '--':
40 break
41 else:
42 verbatimFiles.insert(0, file)
43
44 convertFiles = args
45 convert(convertFiles, verbatimFiles, outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld