Bug 1708519 [wpt PR 28744] - Fix #28743: make the status checkboxes on the th.js...
[gecko.git] / media / libyuv / update.py
blob44a905834beae9a8320e417156a70f087a09ffc6
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import argparse
6 import datetime
7 import os
8 import re
9 import shutil
10 import tarfile
11 import urllib
12 from subprocess import Popen, PIPE, STDOUT
15 def prepare_upstream(base, commit):
16 upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv'
17 tarball_file = os.path.join(base, 'libyuv.tar.gz')
18 lib_path = os.path.join(base, 'libyuv')
20 print(upstream_url + '/+archive/' + commit + '.tar.gz')
21 urllib.urlretrieve(upstream_url + '/+archive/' + commit + '.tar.gz',
22 tarball_file)
23 shutil.rmtree(lib_path)
24 tarfile.open(tarball_file).extractall(path=lib_path)
25 os.remove(tarball_file)
27 shutil.copy2(os.path.join(lib_path, "LICENSE"), os.path.join(base, "LICENSE"))
30 def get_commit_date(commit):
31 upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv/+/' + commit
32 text = urllib.urlopen(upstream_url).read()
33 regex = r'<tr><th class="Metadata-title">committer</th>' \
34 r'<td>.+</td><td>[^\s]+ ([0-9a-zA-Z: ]+)\s*\+*[0-9]*</td></tr>'
35 date = re.search(regex, text).group(1)
36 return datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y")
39 def cleanup_upstream(base):
40 os.remove(os.path.join(base, 'libyuv/.gitignore'))
43 def apply_patches(base):
44 patches = [
45 # update gyp build files
46 "update_gyp.patch",
47 # fix build errors
48 'fix_build_errors.patch',
49 # make mjpeg printfs optional at build time
50 'make_mjpeg_printfs_optional.patch',
51 # allow disabling of inline ASM and AVX2 code
52 'allow_disabling_asm_avx2.patch',
53 # add H444ToARGB() variant
54 'add_H444ToARGB.patch',
55 # fix the x86 mingw-clang build
56 'bug_1491848.patch',
59 for patch in patches:
60 print('\nApplying patch %s' % patch)
61 with open(os.path.join(base, patch)) as f:
62 Popen(["patch", "-p3"], stdin=f, cwd=base).wait()
65 def update_moz_yaml(base, commit, commitdate):
66 moz_yaml_file = os.path.join(base, 'moz.yaml')
67 with open(moz_yaml_file) as f:
68 moz_yaml = f.read()
70 new_moz_yaml = re.sub(r'\n\s+release:.+\n',
71 '\n release: "%s (%s)"\n' % (commit, commitdate),
72 moz_yaml)
74 if moz_yaml != new_moz_yaml:
75 with open(moz_yaml_file, 'w') as f:
76 f.write(new_moz_yaml)
79 def main():
80 parser = argparse.ArgumentParser(description='Update libyuv')
81 parser.add_argument('--no-patches', dest='no_patches', action="store_true")
82 parser.add_argument('--commit', dest='commit', default='master')
83 args = parser.parse_args()
85 commit = args.commit
86 no_patches = args.no_patches
87 base = os.path.realpath(os.path.dirname(__file__))
89 prepare_upstream(base, commit)
90 commitdate = get_commit_date(commit)
92 if not no_patches:
93 apply_patches(base)
95 update_moz_yaml(base, commit, commitdate)
97 print('\nPatches applied; '
98 'run "hg addremove --similarity 70 libyuv" before committing changes')
100 cleanup_upstream(base)
103 if __name__ == '__main__':
104 main()