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/.
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',
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
):
45 # update gyp build files
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
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
:
70 new_moz_yaml
= re
.sub(r
'\n\s+release:.+\n',
71 '\n release: "%s (%s)"\n' % (commit
, commitdate
),
74 if moz_yaml
!= new_moz_yaml
:
75 with
open(moz_yaml_file
, 'w') as f
:
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()
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
)
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__':