| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 import argparse |
| 8 import os |
| 9 import os.path |
| 10 import shutil |
| 11 import subprocess |
| 12 import sys |
| 13 import tempfile |
| 14 |
| 15 # How to patch libxml2 in Chromium: |
| 16 # |
| 17 # 1. Write a .patch file and add it to third_party/libxml/chromium. |
| 18 # 2. Apply the patch in src: patch -p1 <../chromium/foo.patch |
| 19 # 3. Add the patch to the list of patches in this file. |
| 20 # 4. Update README.chromium with the provenance of the patch. |
| 21 # 5. Upload a change with the modified documentation, roll script, |
| 22 # patch, applied patch and any other relevant changes like |
| 23 # regression tests. Go through the usual review and commit process. |
| 24 # |
| 25 # How to roll libxml2 in Chromium: |
| 26 # |
| 27 # Prerequisites: |
| 28 # |
| 29 # 1. Check out Chromium somewhere on Linux, Mac and Windows. |
| 30 # 2. On each machine, add the experimental remote named 'wip': |
| 31 # git remote add -f wip \ |
| 32 # https://chromium.googlesource.com/experimental/chromium/src |
| 33 # 3. On Linux: |
| 34 # a. sudo apt-get install libicu-dev |
| 35 # b. git clone git://git.gnome.org/libxml2 somewhere |
| 36 # 4. On Mac, install these MacPorts: |
| 37 # autoconf automake libtool pkgconfig icu |
| 38 # |
| 39 # Procedure: |
| 40 # |
| 41 # Warning: This process is destructive. Run it on a clean branch. |
| 42 # |
| 43 # 1. On Linux, in the libxml2 repo directory: |
| 44 # a. git remote update origin |
| 45 # b. git checkout origin/master |
| 46 # |
| 47 # This will be the upstream version of libxml you are rolling to. |
| 48 # |
| 49 # 2. On Linux, in the Chromium src director: |
| 50 # a. third_party/libxml/chromium/roll.py --linux /path/to/libxml2 |
| 51 # |
| 52 # If this fails, it may be a patch no longer applies. Reset to |
| 53 # head; modify the patch files, this script, and |
| 54 # README.chromium; then commit the result and run it again. |
| 55 # |
| 56 # b. git push -f wip HEAD:refs/wip/$USER/roll_libxml |
| 57 # |
| 58 # 2. On Windows, in the Chromium src directory: |
| 59 # a. git fetch wip refs/wip/$USER/roll_libxml |
| 60 # b. git checkout FETCH_HEAD |
| 61 # c. third_party\libxml\chromium\roll.py --win32 |
| 62 # d. git push -f wip HEAD:refs/wip/$USER/roll_libxml |
| 63 # |
| 64 # 3. On Mac, in the Chromium src directory: |
| 65 # a. git fetch wip refs/wip/$USER/roll_libxml |
| 66 # b. git checkout -b roll_libxml_nnnn FETCH_HEAD |
| 67 # c. git branch --set-upstream-to origin/master |
| 68 # d. third_party/libxml/chromium/roll.py --mac |
| 69 # e. Make and commit any final changes to README.chromium, BUILD.gn, etc. |
| 70 # f. Complete the code review process as usual: git cl upload -d; |
| 71 # git cl try-results; etc. |
| 72 |
| 73 PATCHES = [ |
| 74 'chromium-issue-599427.patch', |
| 75 'chromium-issue-620679.patch', |
| 76 'chromium-issue-628581.patch', |
| 77 'chromium-issue-683629.patch', |
| 78 ] |
| 79 |
| 80 |
| 81 # See libxml2 configure.ac and win32/configure.js to learn what |
| 82 # options are available. |
| 83 |
| 84 # These two sets of options should be in sync. You can check the |
| 85 # generated #defines in (win32|mac|linux)/include/libxml.h to confirm |
| 86 # this. |
| 87 SHARED_XML_CONFIGURE_OPTIONS = [ |
| 88 # These options are turned ON |
| 89 ('--with-icu', 'icu=yes'), |
| 90 # These options are turned OFF |
| 91 ('--without-c14n', 'c14n=no'), |
| 92 ('--without-catalog', 'catalog=no'), |
| 93 ('--without-debug', 'xml_debug=no'), |
| 94 ('--without-docbook', 'docb=no'), |
| 95 ('--without-ftp', 'ftp=no'), |
| 96 ('--without-http', 'http=no'), |
| 97 ('--without-iconv', 'iconv=no'), |
| 98 ('--without-legacy', 'legacy=no'), |
| 99 ('--without-lzma', 'lzma=no'), |
| 100 ('--without-mem-debug', 'mem_debug=no'), |
| 101 ('--without-modules', 'modules=no'), |
| 102 ('--without-regexps', 'regexps=no'), |
| 103 ('--without-run-debug', 'run_debug=no'), |
| 104 ('--without-schemas', 'schemas=no'), |
| 105 ('--without-schematron', 'schematron=no'), |
| 106 ('--without-valid', 'valid=no'), |
| 107 ('--without-xinclude', 'xinclude=no'), |
| 108 ('--without-xptr', 'xptr=no'), |
| 109 ('--without-zlib', 'zlib=no'), |
| 110 ] |
| 111 |
| 112 |
| 113 # These options are only available in configure.ac for Linux and Mac. |
| 114 EXTRA_NIX_XML_CONFIGURE_OPTIONS = [ |
| 115 '--without-readline', |
| 116 '--without-history', |
| 117 ] |
| 118 |
| 119 |
| 120 # These options are only available in win32/configure.js for Windows. |
| 121 EXTRA_WIN32_XML_CONFIGURE_OPTIONS = [ |
| 122 'walker=no', |
| 123 ] |
| 124 |
| 125 |
| 126 XML_CONFIGURE_OPTIONS = ( |
| 127 [option[0] for option in SHARED_XML_CONFIGURE_OPTIONS] + |
| 128 EXTRA_NIX_XML_CONFIGURE_OPTIONS) |
| 129 |
| 130 |
| 131 XML_WIN32_CONFIGURE_OPTIONS = ( |
| 132 [option[1] for option in SHARED_XML_CONFIGURE_OPTIONS] + |
| 133 EXTRA_WIN32_XML_CONFIGURE_OPTIONS) |
| 134 |
| 135 |
| 136 FILES_TO_REMOVE = [ |
| 137 'src/DOCBparser.c', |
| 138 'src/HACKING', |
| 139 'src/INSTALL.libxml2', |
| 140 'src/MAINTAINERS', |
| 141 'src/Makefile.win', |
| 142 'src/README.cvs-commits', |
| 143 # This is unneeded "legacy" SAX API, even though we enable SAX1. |
| 144 'src/SAX.c', |
| 145 'src/VxWorks', |
| 146 'src/autogen.sh', |
| 147 'src/autom4te.cache', |
| 148 'src/bakefile', |
| 149 'src/build_glob.py', |
| 150 'src/c14n.c', |
| 151 'src/catalog.c', |
| 152 'src/chvalid.def', |
| 153 'src/debugXML.c', |
| 154 'src/doc', |
| 155 'src/example', |
| 156 'src/genChRanges.py', |
| 157 'src/global.data', |
| 158 'src/include/libxml/xmlversion.h', |
| 159 'src/include/libxml/xmlwin32version.h', |
| 160 'src/include/libxml/xmlwin32version.h.in', |
| 161 'src/legacy.c', |
| 162 'src/libxml2.doap', |
| 163 'src/macos/libxml2.mcp.xml.sit.hqx', |
| 164 'src/optim', |
| 165 'src/os400', |
| 166 'src/python', |
| 167 'src/relaxng.c', |
| 168 'src/result', |
| 169 'src/rngparser.c', |
| 170 'src/schematron.c', |
| 171 'src/test', |
| 172 'src/testOOM.c', |
| 173 'src/testOOMlib.c', |
| 174 'src/testOOMlib.h', |
| 175 'src/trio.c', |
| 176 'src/trio.h', |
| 177 'src/triop.h', |
| 178 'src/triostr.c', |
| 179 'src/triostr.h', |
| 180 'src/vms', |
| 181 'src/win32/VC10/config.h', |
| 182 'src/win32/wince', |
| 183 'src/xinclude.c', |
| 184 'src/xlink.c', |
| 185 'src/xml2-config.in', |
| 186 'src/xmlcatalog.c', |
| 187 'src/xmllint.c', |
| 188 'src/xmlmodule.c', |
| 189 'src/xmlregexp.c', |
| 190 'src/xmlschemas.c', |
| 191 'src/xmlschemastypes.c', |
| 192 'src/xpointer.c', |
| 193 'src/xstc', |
| 194 'src/xzlib.c', |
| 195 ] |
| 196 |
| 197 |
| 198 THIRD_PARTY_LIBXML_SRC = 'third_party/libxml/src' |
| 199 |
| 200 |
| 201 class WorkingDir(object): |
| 202 """"Changes the working directory and resets it on exit.""" |
| 203 def __init__(self, path): |
| 204 self.prev_path = os.getcwd() |
| 205 self.path = path |
| 206 |
| 207 def __enter__(self): |
| 208 os.chdir(self.path) |
| 209 |
| 210 def __exit__(self, exc_type, exc_value, traceback): |
| 211 if exc_value: |
| 212 print('was in %s; %s before that' % (self.path, self.prev_path)) |
| 213 os.chdir(self.prev_path) |
| 214 |
| 215 |
| 216 def git(*args): |
| 217 """Runs a git subcommand. |
| 218 |
| 219 On Windows this uses the shell because there's a git wrapper |
| 220 batch file in depot_tools. |
| 221 |
| 222 Arguments: |
| 223 args: The arguments to pass to git. |
| 224 """ |
| 225 command = ['git'] + list(args) |
| 226 subprocess.check_call(command, shell=(os.name == 'nt')) |
| 227 |
| 228 |
| 229 def remove_tracked_and_local_dir(path): |
| 230 """Removes the contents of a directory from git, and the filesystem. |
| 231 |
| 232 Arguments: |
| 233 path: The path to remove. |
| 234 """ |
| 235 remove_tracked_files([path]) |
| 236 shutil.rmtree(path, ignore_errors=True) |
| 237 os.mkdir(path) |
| 238 |
| 239 |
| 240 def remove_tracked_files(files_to_remove): |
| 241 """Removes tracked files from git. |
| 242 |
| 243 Arguments: |
| 244 files_to_remove: The files to remove. |
| 245 """ |
| 246 files_to_remove = [f for f in files_to_remove if os.path.exists(f)] |
| 247 git('rm', '-rf', *files_to_remove) |
| 248 |
| 249 |
| 250 def sed_in_place(input_filename, program): |
| 251 """Replaces text in a file. |
| 252 |
| 253 Arguments: |
| 254 input_filename: The file to edit. |
| 255 program: The sed program to perform edits on the file. |
| 256 """ |
| 257 # OS X's sed requires -e |
| 258 subprocess.check_call(['sed', '-i', '-e', program, input_filename]) |
| 259 |
| 260 |
| 261 def check_copying(full_path_to_third_party_libxml_src): |
| 262 path = os.path.join(full_path_to_third_party_libxml_src, 'COPYING') |
| 263 if not os.path.exists(path): |
| 264 return |
| 265 with open(path) as f: |
| 266 s = f.read() |
| 267 if 'GNU' in s: |
| 268 raise Exception('check COPYING') |
| 269 |
| 270 |
| 271 def prepare_libxml_distribution(libxml2_repo_path, temp_dir): |
| 272 """Makes a libxml2 distribution. |
| 273 |
| 274 Args: |
| 275 libxml2_repo_path: The path to the local clone of the libxml2 repo. |
| 276 temp_dir: A temporary directory to stage the distribution to. |
| 277 |
| 278 Returns: A tuple of commit hash and full path to the archive. |
| 279 """ |
| 280 # If it was necessary to push from a distribution prepared upstream, |
| 281 # this is the point to inject it: Return the version string and the |
| 282 # distribution tar file. |
| 283 |
| 284 # The libxml2 repo we're pulling changes from should not have |
| 285 # local changes. This *should* be a commit that's publicly visible |
| 286 # in the upstream repo; reviewers should check this. |
| 287 check_clean(libxml2_repo_path) |
| 288 |
| 289 temp_config_path = os.path.join(temp_dir, 'config') |
| 290 os.mkdir(temp_config_path) |
| 291 temp_src_path = os.path.join(temp_dir, 'src') |
| 292 os.mkdir(temp_src_path) |
| 293 |
| 294 with WorkingDir(libxml2_repo_path): |
| 295 commit = subprocess.check_output( |
| 296 ['git', 'log', '-n', '1', '--pretty=format:%H', 'HEAD']) |
| 297 subprocess.check_call( |
| 298 'git archive HEAD | tar -x -C "%s"' % temp_src_path, |
| 299 shell=True) |
| 300 with WorkingDir(temp_src_path): |
| 301 os.remove('.gitignore') |
| 302 with WorkingDir(temp_config_path): |
| 303 subprocess.check_call(['../src/autogen.sh'] + XML_CONFIGURE_OPTIONS) |
| 304 subprocess.check_call(['make', 'dist-all']) |
| 305 |
| 306 # Work out what it is called |
| 307 tar_file = subprocess.check_output( |
| 308 '''awk '/PACKAGE =/ {p=$3} /VERSION =/ {v=$3} ''' |
| 309 '''END {printf("%s-%s.tar.gz", p, v)}' Makefile''', |
| 310 shell=True) |
| 311 return commit, os.path.abspath(tar_file) |
| 312 |
| 313 |
| 314 def roll_libxml_linux(src_path, libxml2_repo_path): |
| 315 with WorkingDir(src_path): |
| 316 # Export the upstream git repo. |
| 317 try: |
| 318 temp_dir = tempfile.mkdtemp() |
| 319 print('temporary directory: %s' % temp_dir) |
| 320 |
| 321 commit, tar_file = prepare_libxml_distribution(libxml2_repo_path, |
| 322 temp_dir) |
| 323 |
| 324 # Remove all of the old libxml to ensure only desired cruft |
| 325 # accumulates |
| 326 remove_tracked_and_local_dir(THIRD_PARTY_LIBXML_SRC) |
| 327 |
| 328 # Update the libxml repo and export it to the Chromium tree |
| 329 with WorkingDir(THIRD_PARTY_LIBXML_SRC): |
| 330 subprocess.check_call( |
| 331 'tar xzf %s --strip-components=1' % tar_file, |
| 332 shell=True) |
| 333 finally: |
| 334 shutil.rmtree(temp_dir) |
| 335 |
| 336 with WorkingDir(THIRD_PARTY_LIBXML_SRC): |
| 337 # Put the version number is the README file |
| 338 sed_in_place('../README.chromium', |
| 339 's/Version: .*$/Version: %s/' % commit) |
| 340 |
| 341 for patch in PATCHES: |
| 342 subprocess.check_call('cat ../chromium/%s | patch -p1' % patch, |
| 343 shell=True) |
| 344 |
| 345 with WorkingDir('../linux'): |
| 346 subprocess.check_call( |
| 347 ['../src/autogen.sh'] + XML_CONFIGURE_OPTIONS) |
| 348 check_copying(os.getcwd()) |
| 349 sed_in_place('config.h', 's/#define HAVE_RAND_R 1//') |
| 350 |
| 351 # Add *everything* |
| 352 with WorkingDir('../src'): |
| 353 git('add', '*') |
| 354 git('commit', '-am', '%s libxml, linux' % commit) |
| 355 print('Now push to Windows and run steps there.') |
| 356 |
| 357 |
| 358 def roll_libxml_win32(src_path): |
| 359 with WorkingDir(src_path): |
| 360 # Run the configure script. |
| 361 with WorkingDir(os.path.join(THIRD_PARTY_LIBXML_SRC, 'win32')): |
| 362 subprocess.check_call( |
| 363 ['cscript', '//E:jscript', 'configure.js', 'compiler=msvc'] + |
| 364 XML_WIN32_CONFIGURE_OPTIONS) |
| 365 |
| 366 # Add and commit the result. |
| 367 shutil.move('VC10/config.h', '../../win32/config.h') |
| 368 git('add', '../../win32/config.h') |
| 369 shutil.move('../include/libxml/xmlversion.h', |
| 370 '../../win32/include/libxml/xmlversion.h') |
| 371 git('add', '../../win32/include/libxml/xmlversion.h') |
| 372 git('commit', '-m', 'Windows') |
| 373 git('clean', '-f') |
| 374 print('Now push to Mac and run steps there.') |
| 375 |
| 376 |
| 377 def roll_libxml_mac(src_path): |
| 378 full_path_to_third_party_libxml = os.path.join( |
| 379 src_path, THIRD_PARTY_LIBXML_SRC, '..') |
| 380 |
| 381 with WorkingDir(os.path.join(full_path_to_third_party_libxml, 'mac')): |
| 382 subprocess.check_call(['autoreconf', '-i', '../src']) |
| 383 subprocess.check_call(['../src/configure'] + XML_CONFIGURE_OPTIONS) |
| 384 sed_in_place('config.h', 's/#define HAVE_RAND_R 1//') |
| 385 |
| 386 with WorkingDir(full_path_to_third_party_libxml): |
| 387 commit = subprocess.check_output(['awk', '/Version:/ {print $2}', |
| 388 'README.chromium']) |
| 389 remove_tracked_files(FILES_TO_REMOVE) |
| 390 commit_message = 'Roll libxml to %s' % commit |
| 391 git('commit', '-am', commit_message) |
| 392 print('Now upload for review, etc.') |
| 393 |
| 394 |
| 395 def check_clean(path): |
| 396 with WorkingDir(path): |
| 397 status = subprocess.check_output(['git', 'status', '-s']) |
| 398 if len(status) > 0: |
| 399 raise Exception('repository at %s is not clean' % path) |
| 400 |
| 401 |
| 402 def main(): |
| 403 src_dir = os.getcwd() |
| 404 if not os.path.exists(os.path.join(src_dir, 'third_party')): |
| 405 print('error: run this script from the Chromium src directory') |
| 406 sys.exit(1) |
| 407 |
| 408 parser = argparse.ArgumentParser( |
| 409 description='Roll the libxml2 dependency in Chromium') |
| 410 platform = parser.add_mutually_exclusive_group(required=True) |
| 411 platform.add_argument('--linux', action='store_true') |
| 412 platform.add_argument('--win32', action='store_true') |
| 413 platform.add_argument('--mac', action='store_true') |
| 414 parser.add_argument( |
| 415 'libxml2_repo_path', |
| 416 type=str, |
| 417 nargs='?', |
| 418 help='The path to the local clone of the libxml2 git repo.') |
| 419 args = parser.parse_args() |
| 420 |
| 421 if args.linux: |
| 422 libxml2_repo_path = args.libxml2_repo_path |
| 423 if not libxml2_repo_path: |
| 424 print('Specify the path to the local libxml2 repo clone.') |
| 425 sys.exit(1) |
| 426 libxml2_repo_path = os.path.abspath(libxml2_repo_path) |
| 427 roll_libxml_linux(src_dir, libxml2_repo_path) |
| 428 elif args.win32: |
| 429 roll_libxml_win32(src_dir) |
| 430 elif args.mac: |
| 431 roll_libxml_mac(src_dir) |
| 432 |
| 433 |
| 434 if __name__ == '__main__': |
| 435 main() |
| OLD | NEW |