OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
3 # for details. All rights reserved. Use of this source code is governed by a | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 | |
6 import optparse | |
7 import os | |
8 import os.path | |
9 import re | |
10 import shutil | |
11 import subprocess | |
12 import sys | |
13 | |
14 SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) | |
15 DART_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, '..', '..', '..', '..')) | |
16 | |
17 # Path to install latest IDL. | |
18 IDL_PATH = os.path.join(DART_PATH, 'third_party', 'WebCore') | |
19 | |
20 # Whitelist of files to keep. | |
21 WHITELIST = [ | |
22 r'LICENSE(\S+)', | |
23 r'(\S+)\.idl'] | |
24 | |
25 # README file to generate. | |
26 README = os.path.join(IDL_PATH, 'README') | |
27 | |
28 # SVN URL to latest Dartium version of WebKit. | |
29 DEPS = 'http://dart.googlecode.com/svn/branches/bleeding_edge/deps/dartium.deps/
DEPS' | |
30 URL_PATTERN = r'"dartium_webkit_trunk": "(\S+)",' | |
31 REV_PATTERN = r'"dartium_webkit_revision": "(\d+)",' | |
32 WEBCORE_SUBPATH = 'Source/WebCore' | |
33 | |
34 | |
35 def RunCommand(cmd): | |
36 """Executes a shell command and return its stdout.""" | |
37 print ' '.join(cmd) | |
38 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
39 output = pipe.communicate() | |
40 if pipe.returncode == 0: | |
41 return output[0] | |
42 else: | |
43 print output[1] | |
44 print 'FAILED. RET_CODE=%d' % pipe.returncode | |
45 sys.exit(pipe.returncode) | |
46 | |
47 | |
48 def GetWebkitSvnRevision(): | |
49 """Returns a tuple with the (dartium webkit repo, latest revision).""" | |
50 deps = RunCommand(['svn', 'cat', DEPS]) | |
51 url = re.search(URL_PATTERN, deps).group(1) | |
52 revision = re.search(REV_PATTERN, deps).group(1) | |
53 return (url, revision) | |
54 | |
55 | |
56 def RefreshIDL(url, revision): | |
57 """Refreshes the IDL to specific WebKit url / revision.""" | |
58 cwd = os.getcwd() | |
59 try: | |
60 shutil.rmtree(IDL_PATH) | |
61 os.chdir(os.path.dirname(IDL_PATH)) | |
62 RunCommand(['svn', 'export', '-r', revision, url + '/' + WEBCORE_SUBPATH]) | |
63 finally: | |
64 os.chdir(cwd) | |
65 | |
66 | |
67 def PruneExtraFiles(): | |
68 """Removes all files that do not match the whitelist.""" | |
69 pattern = re.compile(reduce(lambda x,y: '%s|%s' % (x,y), | |
70 map(lambda z: '(%s)' % z, WHITELIST))) | |
71 for (root, dirs, files) in os.walk(IDL_PATH, topdown=False): | |
72 for f in files: | |
73 if not pattern.match(f): | |
74 os.remove(os.path.join(root, f)) | |
75 for d in dirs: | |
76 dirpath = os.path.join(root, d) | |
77 if not os.listdir(dirpath): | |
78 shutil.rmtree(dirpath) | |
79 | |
80 | |
81 def ParseOptions(): | |
82 parser = optparse.OptionParser() | |
83 parser.add_option('--revision', '-r', dest='revision', | |
84 help='Revision to install', default=None) | |
85 args, _ = parser.parse_args() | |
86 return args.revision | |
87 | |
88 | |
89 def GenerateReadme(url, revision): | |
90 readme = """This directory contains a copy of WebKit/WebCore IDL files. | |
91 See the attached LICENSE-* files in this directory. | |
92 | |
93 Please do not modify the files here. They are periodically copied | |
94 using the script: $DART_ROOT/sdk/lib/html/scripts/%(script)s | |
95 | |
96 The current version corresponds to: | |
97 URL: %(url)s | |
98 Current revision: %(revision)s | |
99 """ % { | |
100 'script': os.path.basename(__file__), | |
101 'url': url, | |
102 'revision': revision } | |
103 out = open(README, 'w') | |
104 out.write(readme) | |
105 out.close() | |
106 | |
107 | |
108 def main(): | |
109 revision = ParseOptions() | |
110 url, latest = GetWebkitSvnRevision() | |
111 if not revision: | |
112 revision = latest | |
113 RefreshIDL(url, revision) | |
114 PruneExtraFiles() | |
115 GenerateReadme(url, revision) | |
116 | |
117 | |
118 if __name__ == '__main__': | |
119 main() | |
OLD | NEW |