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