| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import optparse | 6 import optparse |
| 7 import os | 7 import os |
| 8 import os.path | 8 import os.path |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) | 14 SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) |
| 15 DART_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, '..', '..', '..')) | 15 DART_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, '..', '..', '..')) |
| 16 | 16 |
| 17 # Path to install latest IDL. | 17 # Dartium DEPS file with Chrome and WebKit revisions. |
| 18 IDL_PATH = os.path.join(DART_PATH, 'third_party', 'WebCore') | 18 DEPS = ('http://dart.googlecode.com/svn/branches/' |
| 19 'bleeding_edge/deps/dartium.deps/DEPS') |
| 19 | 20 |
| 20 # Whitelist of files to keep. | 21 # Whitelist of files to keep. |
| 21 WHITELIST = [ | 22 WHITELIST = [ |
| 22 r'LICENSE(\S+)', | 23 r'LICENSE(\S+)', |
| 23 r'(\S+)\.idl'] | 24 r'(\S+)\.idl', |
| 25 r'(\S+)\.json', |
| 26 r'(\S+)\.py', |
| 27 ] |
| 24 | 28 |
| 25 # README file to generate. | 29 # WebKit / WebCore info. |
| 26 README = os.path.join(IDL_PATH, 'README') | 30 WEBKIT_URL_PATTERN = r'"dartium_webkit_trunk": "(\S+)",' |
| 31 WEBKIT_REV_PATTERN = r'"dartium_webkit_revision": "(\d+)",' |
| 32 WEBCORE_SUBPATH = 'Source/WebCore' |
| 33 LOCAL_WEBKIT_IDL_PATH = os.path.join(DART_PATH, 'third_party', 'WebCore') |
| 34 LOCAL_WEBKIT_README = os.path.join(LOCAL_WEBKIT_IDL_PATH, 'README') |
| 35 LOCAL_WEBKIT_README = """\ |
| 36 This directory contains a copy of WebKit/WebCore IDL files. |
| 37 See the attached LICENSE-* files in this directory. |
| 27 | 38 |
| 28 # SVN URL to latest Dartium version of WebKit. | 39 Please do not modify the files here. They are periodically copied |
| 29 DEPS = 'http://dart.googlecode.com/svn/branches/bleeding_edge/deps/dartium.deps/
DEPS' | 40 using the script: $DART_ROOT/sdk/lib/html/scripts/%(script)s |
| 30 URL_PATTERN = r'"dartium_webkit_trunk": "(\S+)",' | 41 |
| 31 REV_PATTERN = r'"dartium_webkit_revision": "(\d+)",' | 42 The current version corresponds to: |
| 32 WEBCORE_SUBPATH = 'Source/WebCore' | 43 URL: %(url)s |
| 44 Current revision: %(revision)s |
| 45 """ |
| 46 |
| 47 # Chrome info. |
| 48 CHROME_URL_PATTERN = r'"chromium_url": "(\S+)",' |
| 49 CHROME_REV_PATTERN = r'"chromium_revision": "(\d+)",' |
| 50 CHROME_IDL_SUBPATH = 'trunk/src/chrome/common/extensions/api' |
| 51 CHROME_TOOLS_SUBPATH = 'trunk/src/tools/json_schema_compiler' |
| 52 LOCAL_CHROME_IDL_PATH = os.path.join(DART_PATH, 'third_party', 'chrome', 'idl') |
| 53 LOCAL_CHROME_TOOLS_PATH = os.path.join(DART_PATH, 'third_party', 'chrome', |
| 54 'tools') |
| 55 LOCAL_CHROME_README = """\ |
| 56 This directory contains a copy of Chromium IDL and generation scripts |
| 57 used to generate Dart APIs for Chrome Apps. |
| 58 |
| 59 The original files are from: |
| 60 URL: %(url)s |
| 61 Current revision: %(revision)s |
| 62 |
| 63 Please see the corresponding LICENSE file at |
| 64 %(url)s/trunk/src/LICENSE. |
| 65 """ |
| 66 |
| 67 # Regular expressions corresponding to URL/revision patters in the |
| 68 # DEPS file. |
| 69 DEPS_PATTERNS = { |
| 70 'webkit': (WEBKIT_URL_PATTERN, WEBKIT_REV_PATTERN), |
| 71 'chrome': (CHROME_URL_PATTERN, CHROME_REV_PATTERN), |
| 72 } |
| 73 |
| 74 # List of components to update. |
| 75 UPDATE_LIST = [ |
| 76 # (component, remote subpath, local path, local readme file) |
| 77 |
| 78 # WebKit IDL. |
| 79 ('webkit', WEBCORE_SUBPATH, LOCAL_WEBKIT_IDL_PATH, LOCAL_WEBKIT_README), |
| 80 # Chrome IDL. |
| 81 ('chrome', CHROME_IDL_SUBPATH, LOCAL_CHROME_IDL_PATH, LOCAL_CHROME_README), |
| 82 # Chrome IDL compiler files. |
| 83 ('chrome', CHROME_TOOLS_SUBPATH, LOCAL_CHROME_TOOLS_PATH, |
| 84 LOCAL_CHROME_README), |
| 85 ] |
| 33 | 86 |
| 34 | 87 |
| 35 def RunCommand(cmd): | 88 def RunCommand(cmd): |
| 36 """Executes a shell command and return its stdout.""" | 89 """Executes a shell command and return its stdout.""" |
| 37 print ' '.join(cmd) | 90 print ' '.join(cmd) |
| 38 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 91 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 39 output = pipe.communicate() | 92 output = pipe.communicate() |
| 40 if pipe.returncode == 0: | 93 if pipe.returncode == 0: |
| 41 return output[0] | 94 return output[0] |
| 42 else: | 95 else: |
| 43 print output[1] | 96 print output[1] |
| 44 print 'FAILED. RET_CODE=%d' % pipe.returncode | 97 print 'FAILED. RET_CODE=%d' % pipe.returncode |
| 45 sys.exit(pipe.returncode) | 98 sys.exit(pipe.returncode) |
| 46 | 99 |
| 47 | 100 |
| 48 def GetWebkitSvnRevision(): | 101 def GetDeps(): |
| 102 """Returns the DEPS file contents with pinned revision info.""" |
| 103 return RunCommand(['svn', 'cat', DEPS]) |
| 104 |
| 105 |
| 106 def GetSvnRevision(deps, component): |
| 49 """Returns a tuple with the (dartium webkit repo, latest revision).""" | 107 """Returns a tuple with the (dartium webkit repo, latest revision).""" |
| 50 deps = RunCommand(['svn', 'cat', DEPS]) | 108 url_pattern, rev_pattern = DEPS_PATTERNS[component] |
| 51 url = re.search(URL_PATTERN, deps).group(1) | 109 url = re.search(url_pattern, deps).group(1) |
| 52 revision = re.search(REV_PATTERN, deps).group(1) | 110 revision = re.search(rev_pattern, deps).group(1) |
| 53 return (url, revision) | 111 return (url, revision) |
| 54 | 112 |
| 55 | 113 |
| 56 def RefreshIDL(url, revision): | 114 def RefreshIDL(url, revision, remote_path, local_path): |
| 57 """Refreshes the IDL to specific WebKit url / revision.""" | 115 """Refreshes refreshes files in the local_path to specific url / |
| 116 revision / remote_path.""" |
| 58 cwd = os.getcwd() | 117 cwd = os.getcwd() |
| 59 try: | 118 try: |
| 60 shutil.rmtree(IDL_PATH) | 119 if os.path.exists(local_path): |
| 61 os.chdir(os.path.dirname(IDL_PATH)) | 120 shutil.rmtree(local_path) |
| 62 RunCommand(['svn', 'export', '-r', revision, url + '/' + WEBCORE_SUBPATH]) | 121 head, tail = os.path.split(local_path) |
| 122 if not os.path.exists(head): |
| 123 os.makedirs(head) |
| 124 os.chdir(head) |
| 125 RunCommand(['svn', 'export', '-r', revision, url + '/' + remote_path, tail]) |
| 63 finally: | 126 finally: |
| 64 os.chdir(cwd) | 127 os.chdir(cwd) |
| 65 | 128 |
| 66 | 129 |
| 67 def PruneExtraFiles(): | 130 def PruneExtraFiles(local_path): |
| 68 """Removes all files that do not match the whitelist.""" | 131 """Removes all files that do not match the whitelist.""" |
| 69 pattern = re.compile(reduce(lambda x,y: '%s|%s' % (x,y), | 132 pattern = re.compile(reduce(lambda x,y: '%s|%s' % (x,y), |
| 70 map(lambda z: '(%s)' % z, WHITELIST))) | 133 map(lambda z: '(%s)' % z, WHITELIST))) |
| 71 for (root, dirs, files) in os.walk(IDL_PATH, topdown=False): | 134 for (root, dirs, files) in os.walk(local_path, topdown=False): |
| 72 for f in files: | 135 for f in files: |
| 73 if not pattern.match(f): | 136 if not pattern.match(f): |
| 74 os.remove(os.path.join(root, f)) | 137 os.remove(os.path.join(root, f)) |
| 75 for d in dirs: | 138 for d in dirs: |
| 76 dirpath = os.path.join(root, d) | 139 dirpath = os.path.join(root, d) |
| 77 if not os.listdir(dirpath): | 140 if not os.listdir(dirpath): |
| 78 shutil.rmtree(dirpath) | 141 shutil.rmtree(dirpath) |
| 79 | 142 |
| 80 | 143 |
| 144 def GenerateReadme(local_path, template, url, revision): |
| 145 readme = template % { |
| 146 'script': os.path.basename(__file__), |
| 147 'url': url, |
| 148 'revision': revision } |
| 149 |
| 150 readme_path = os.path.join(local_path, 'README') |
| 151 out = open(readme_path, 'w') |
| 152 out.write(readme) |
| 153 out.close() |
| 154 |
| 155 |
| 81 def ParseOptions(): | 156 def ParseOptions(): |
| 82 parser = optparse.OptionParser() | 157 parser = optparse.OptionParser() |
| 83 parser.add_option('--revision', '-r', dest='revision', | 158 parser.add_option('--webkit-revision', '-w', dest='webkit_revision', |
| 84 help='Revision to install', default=None) | 159 help='WebKit IDL revision to install', default=None) |
| 160 parser.add_option('--chrome-revision', '-c', dest='chrome_revision', |
| 161 help='Chrome IDL revision to install', default=None) |
| 162 parser.add_option('--update', '-u', dest='update', |
| 163 help='IDL to update (webkit | chrome | all)', |
| 164 default='webkit') |
| 85 args, _ = parser.parse_args() | 165 args, _ = parser.parse_args() |
| 86 return args.revision | 166 update = {} |
| 87 | 167 if args.update == 'all' or args.update == 'chrome': |
| 88 | 168 update['chrome'] = args.chrome_revision |
| 89 def GenerateReadme(url, revision): | 169 if args.update == 'all' or args.update == 'webkit': |
| 90 readme = """This directory contains a copy of WebKit/WebCore IDL files. | 170 update['webkit'] = args.webkit_revision |
| 91 See the attached LICENSE-* files in this directory. | 171 return update |
| 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 | 172 |
| 107 | 173 |
| 108 def main(): | 174 def main(): |
| 109 revision = ParseOptions() | 175 deps = GetDeps() |
| 110 url, latest = GetWebkitSvnRevision() | 176 update = ParseOptions() |
| 111 if not revision: | 177 for (component, remote_path, local_path, readme) in UPDATE_LIST: |
| 112 revision = latest | 178 if component in update.keys(): |
| 113 RefreshIDL(url, revision) | 179 revision = update[component] |
| 114 PruneExtraFiles() | 180 url, latest = GetSvnRevision(deps, component) |
| 115 GenerateReadme(url, revision) | 181 if not revision: |
| 182 revision = latest |
| 183 RefreshIDL(url, revision, remote_path, local_path) |
| 184 PruneExtraFiles(local_path) |
| 185 GenerateReadme(local_path, readme, url, revision) |
| 116 | 186 |
| 117 | 187 |
| 118 if __name__ == '__main__': | 188 if __name__ == '__main__': |
| 119 main() | 189 main() |
| OLD | NEW |