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

Side by Side Diff: convert_js.py

Issue 9846017: Make JavaScript sources compile into the library; convert JavaScript files on the fly (Closed)
Patch Set: Created March 14, 2013, 10:02 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # coding: utf-8
3
4 import sys, os, codecs, re
5 base_dir = os.path.abspath(os.path.dirname(__file__))
Felix Dahlke 2013/03/15 15:18:36 Everything else is named using camel case, why not
6 sys.path.append(os.path.join(base_dir, '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(base_dir, 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)
OLDNEW
« no previous file with comments | « .hgsubstate ('k') | include/AdblockPlus/JsEngine.h » ('j') | include/AdblockPlus/JsEngine.h » ('J')

Powered by Google App Engine
This is Rietveld