author Tom Ritter <>
Wed, 09 Jan 2019 10:51:07 -0600
changeset 453621 c5b64daf4dddabb8346cc0fa193720f9eaf7d777
parent 447945 6ee93495fe0c47bdad591490f9a4439cbcb09be5
child 472486 cd666f0befca97073d92bf1c46f39ead6eff3646
permissions -rwxr-xr-x
Bug 1518856 - Remove -I$TOOLTOOL_DIR/clang/lib/clang/8.0.0/include from the Stylo BINDGEN_CFLAGS r=dmajory

#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at
import argparse
import datetime
import os
import re
import shutil
import tarfile
import urllib
from subprocess import Popen, PIPE, STDOUT

def prepare_upstream(base, commit):
    upstream_url = ''
    tarball_file = os.path.join(base, 'libyuv.tar.gz')
    lib_path = os.path.join(base, 'libyuv')

    print(upstream_url + '/+archive/' + commit + '.tar.gz')
    urllib.urlretrieve(upstream_url + '/+archive/' + commit + '.tar.gz',

    shutil.copy2(os.path.join(lib_path, "LICENSE"), os.path.join(base, "LICENSE"))

def get_commit_date(commit):
    upstream_url = '' + commit
    text = urllib.urlopen(upstream_url).read()
    regex = r'<tr><th class="Metadata-title">committer</th>' \
            r'<td>.+</td><td>[^\s]+ ([0-9a-zA-Z: ]+)\s*\+*[0-9]*</td></tr>'
    date =, text).group(1)
    return datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y")

def cleanup_upstream(base):
    os.remove(os.path.join(base, 'libyuv/.gitignore'))

def apply_patches(base):
    patches = [
        # update gyp build files
        # fix build errors
        # make mjpeg printfs optional at build time
        # allow disabling of inline ASM and AVX2 code
        # add H444ToARGB() variant
        # avoid selecting neon codepaths on AArch64 Windows
        # fix the x86 mingw-clang build

    for patch in patches:
        print('\nApplying patch %s' % patch)
        with open(os.path.join(base, patch)) as f:
            Popen(["patch", "-p3"], stdin=f, cwd=base).wait()

def update_moz_yaml(base, commit, commitdate):
    moz_yaml_file = os.path.join(base, 'moz.yaml')
    with open(moz_yaml_file) as f:
        moz_yaml =

    new_moz_yaml = re.sub(r'\n\s+release:.+\n',
                          '\n  release: "%s (%s)"\n' % (commit, commitdate),

    if moz_yaml != new_moz_yaml:
        with open(moz_yaml_file, 'w') as f:

def main():
    parser = argparse.ArgumentParser(description='Update libyuv')
    parser.add_argument('--no-patches', dest='no_patches', action="store_true")
    parser.add_argument('--commit', dest='commit', default='master')
    args = parser.parse_args()

    commit = args.commit
    no_patches = args.no_patches
    base = os.path.realpath(os.path.dirname(__file__))

    prepare_upstream(base, commit)
    commitdate = get_commit_date(commit)

    if not no_patches:

    update_moz_yaml(base, commit, commitdate)

    print('\nPatches applied; '
          'run "hg addremove --similarity 70 libyuv" before committing changes')


if __name__ == '__main__':