Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2671)

Side by Side Diff: Source/build/scripts/make-file-arrays.py

Issue 361693004: Remove make-css-file-arrays.pl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (C) 2012 Google Inc. All rights reserved. 2 # Copyright (C) 2012 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 os.path.dirname(__file__), 38 os.path.dirname(__file__),
39 "..", 39 "..",
40 "..", 40 "..",
41 "build", 41 "build",
42 "scripts")) 42 "scripts"))
43 sys.path.append(rjsmin_path) 43 sys.path.append(rjsmin_path)
44 import rjsmin 44 import rjsmin
45 45
46 46
47 def make_variable_name_and_read(file_name): 47 def make_variable_name_and_read(file_name):
48 result = re.match(r'([\w\d_]+)\.([\w\d_]+)', os.path.basename(file_name)) 48 base_name = os.path.basename(file_name)
49 # view-source.css -> viewSource.css
50 base_name = re.sub(r'-[a-zA-Z]', lambda match: match.group(0)[1:].upper(), b ase_name)
51 result = re.match(r'([\w\d_]+)\.([\w\d_]+)', base_name)
49 if not result: 52 if not result:
50 print 'Invalid input file name:', os.path.basename(file_name) 53 print 'Invalid input file name:', os.path.basename(file_name)
51 sys.exit(1) 54 sys.exit(1)
52 variable_name = result.group(1)[0].lower() + result.group(1)[1:] + result.gr oup(2).capitalize() 55 variable_name = result.group(1)[0].lower() + result.group(1)[1:] + result.gr oup(2).capitalize()
53 with open(file_name, 'rb') as f: 56 with open(file_name, 'rb') as f:
54 content = f.read() 57 content = f.read()
55 return variable_name, content 58 return variable_name, content
56 59
57 60
58 def strip_whitespace_and_comments(file_name, content): 61 def strip_whitespace_and_comments(file_name, content):
59 result = re.match(r'.*\.([^.]+)', file_name) 62 result = re.match(r'.*\.([^.]+)', file_name)
60 if not result: 63 if not result:
61 print 'The file name has no extension:', file_name 64 print 'The file name has no extension:', file_name
62 sys.exit(1) 65 sys.exit(1)
63 extension = result.group(1).lower() 66 extension = result.group(1).lower()
64 multi_line_comment = re.compile(r'/\*.*?\*/', re.MULTILINE | re.DOTALL) 67 multi_line_comment = re.compile(r'/\*.*?\*/', re.MULTILINE | re.DOTALL)
65 # Don't accidentally match URLs (http://...) 68 repeating_space = re.compile(r'\s+', re.MULTILINE)
tkent 2014/06/30 07:09:17 This is a bogus comment. leftover of http://src.c
66 repeating_space = re.compile(r'[ \t]+', re.MULTILINE)
67 leading_space = re.compile(r'^[ \t]+', re.MULTILINE) 69 leading_space = re.compile(r'^[ \t]+', re.MULTILINE)
68 trailing_space = re.compile(r'[ \t]+$', re.MULTILINE) 70 trailing_space = re.compile(r'[ \t]+$', re.MULTILINE)
haraken 2014/07/01 00:47:45 Shall we use [\s\t]+ for all of repeating_space, l
tkent 2014/07/01 01:05:45 Done.
69 empty_line = re.compile(r'\n+') 71 empty_line = re.compile(r'\n+')
70 if extension == 'js': 72 if extension == 'js':
71 content = rjsmin.jsmin(content) 73 content = rjsmin.jsmin(content)
72 elif extension == 'css': 74 elif extension == 'css':
73 content = multi_line_comment.sub('', content) 75 content = multi_line_comment.sub('', content)
74 content = repeating_space.sub(' ', content) 76 content = repeating_space.sub(' ', content)
75 content = leading_space.sub('', content) 77 content = leading_space.sub('', content)
76 content = trailing_space.sub('', content) 78 content = trailing_space.sub('', content)
77 content = empty_line.sub('\n', content) 79 content = empty_line.sub('\n', content)
78 return content 80 return content
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 151
150 names_and_contents = [process_file(file_name) for file_name in args] 152 names_and_contents = [process_file(file_name) for file_name in args]
151 153
152 if options.out_header: 154 if options.out_header:
153 write_header_file(options.out_header, options.flag, names_and_contents, options.namespace) 155 write_header_file(options.out_header, options.flag, names_and_contents, options.namespace)
154 write_cpp_file(options.out_cpp, options.flag, names_and_contents, options.ou t_header, options.namespace) 156 write_cpp_file(options.out_cpp, options.flag, names_and_contents, options.ou t_header, options.namespace)
155 157
156 158
157 if __name__ == '__main__': 159 if __name__ == '__main__':
158 sys.exit(main()) 160 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698