Bug 1507051 - replace libyuv's README_MOZILLA with moz.yaml; r=jesup
authorbyron jones <glob@mozilla.com>
Fri, 23 Nov 2018 13:00:07 +0000
changeset 504381 6ee93495fe0c47bdad591490f9a4439cbcb09be5
parent 504380 c65a0f1862dd7cbd485b9ea44618155b85156486
child 504383 14ae1910a4f5dd1cdea7fcb4855a3aa86ed3731b
child 504384 6c108d9038c36d16fb6424a27054454110df7489
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1507051, 1491848
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507051 - replace libyuv's README_MOZILLA with moz.yaml; r=jesup Replace README_MOZILLA with moz.yaml, various fixups for update.py, and create a missing patch file from Bug 1491848. Differential Revision: https://phabricator.services.mozilla.com/D11891
media/libyuv/LICENSE
media/libyuv/README_MOZILLA
media/libyuv/bug_1491848.patch
media/libyuv/moz.yaml
media/libyuv/update.py
new file mode 100644
--- /dev/null
+++ b/media/libyuv/LICENSE
@@ -0,0 +1,29 @@
+Copyright 2011 The LibYuv Project Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+  * Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in
+    the documentation and/or other materials provided with the
+    distribution.
+
+  * Neither the name of Google nor the names of its contributors may
+    be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
deleted file mode 100644
--- a/media/libyuv/README_MOZILLA
+++ /dev/null
@@ -1,12 +0,0 @@
-YUV-format image scaling and conversion library
-
-The source in this directory was copied from upstream by running the
-update.py script from media/libyuv. Any changes made relative to upstream
-should be reflected in that script, e.g. by applying patch files after the
-copy step.
-
-The upstream repository is https://chromium.googlesource.com/libyuv/libyuv
-Updates before this file was added were done manually; the last import was
-r1602 (svn).
-
-The git commit ID last used to import was 98a0a157dcf5dee0882b2dfcc9578ab1f44afb12 (2018-03-02 19:09:38)
new file mode 100644
--- /dev/null
+++ b/media/libyuv/bug_1491848.patch
@@ -0,0 +1,59 @@
+diff --git a/media/libyuv/libyuv/include/libyuv/compare_row.h b/media/libyuv/libyuv/include/libyuv/compare_row.h
+--- a/media/libyuv/libyuv/include/libyuv/compare_row.h
++++ b/media/libyuv/libyuv/include/libyuv/compare_row.h
+@@ -40,32 +40,26 @@ extern "C" {
+ 
+ // clang >= 3.4.0 required for AVX2.
+ #if defined(__clang__) && (defined(__x86_64__) || defined(__i386__))
+ #if (__clang_major__ > 3) || (__clang_major__ == 3 && (__clang_minor__ >= 4))
+ #define CLANG_HAS_AVX2 1
+ #endif  // clang >= 3.4
+ #endif  // __clang__
+ 
+-// The following are available for Visual C:
+-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && \
+-    (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
+-#define HAS_HASHDJB2_AVX2
+-#endif
+-
+ // The following are available for Visual C and GCC:
+ #if !defined(LIBYUV_DISABLE_X86) && \
+     (defined(__x86_64__) || defined(__i386__) || defined(_M_IX86))
+ #define HAS_HASHDJB2_SSE41
+ #define HAS_SUMSQUAREERROR_SSE2
+ #define HAS_HAMMINGDISTANCE_SSE42
+ #endif
+ 
+ // The following are available for Visual C and clangcl 32 bit:
+-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && \
++#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
+     (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
+ #define HAS_HASHDJB2_AVX2
+ #define HAS_SUMSQUAREERROR_AVX2
+ #endif
+ 
+ // The following are available for GCC and clangcl 64 bit:
+ #if !defined(LIBYUV_DISABLE_X86) && \
+     (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+diff --git a/media/libyuv/libyuv/include/libyuv/row.h b/media/libyuv/libyuv/include/libyuv/row.h
+--- a/media/libyuv/libyuv/include/libyuv/row.h
++++ b/media/libyuv/libyuv/include/libyuv/row.h
+@@ -227,17 +227,17 @@ extern "C" {
+ // TODO(fbarchard): fix build error on android_full_debug=1
+ // https://code.google.com/p/libyuv/issues/detail?id=517
+ #define HAS_I422ALPHATOARGBROW_AVX2
+ #endif
+ #endif
+ 
+ // The following are available for AVX2 Visual C and clangcl 32 bit:
+ // TODO(fbarchard): Port to gcc.
+-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && \
++#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
+     (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
+ #define HAS_ARGB1555TOARGBROW_AVX2
+ #define HAS_ARGB4444TOARGBROW_AVX2
+ #define HAS_ARGBTOARGB1555ROW_AVX2
+ #define HAS_ARGBTOARGB4444ROW_AVX2
+ #define HAS_ARGBTORGB565ROW_AVX2
+ #define HAS_J400TOARGBROW_AVX2
+ #define HAS_RGB565TOARGBROW_AVX2
new file mode 100644
--- /dev/null
+++ b/media/libyuv/moz.yaml
@@ -0,0 +1,23 @@
+# Version of this schema
+schema: 1
+
+bugzilla:
+  # Bugzilla product and component for this directory and subdirectories
+  product: "Core"
+  component: "Graphics"
+
+# The source in this directory was copied from upstream by running the
+# update.py script from media/libyuv. Any changes made relative to upstream
+# should be reflected in that script, e.g. by applying patch files after the
+# copy step.
+
+origin:
+  name: "libyuv"
+  description: "YUV-format image scaling and conversion library"
+
+  url: "https://chromium.googlesource.com/libyuv/libyuv"
+  license: "BSD-3-Clause-Clear"
+
+  # update.sh will update this value
+  release: "98a0a157dcf5dee0882b2dfcc9578ab1f44afb12 (2018-03-02 19:09:38)"
+
--- a/media/libyuv/update.py
+++ b/media/libyuv/update.py
@@ -1,91 +1,106 @@
 #!/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 http://mozilla.org/MPL/2.0/.
 import argparse
+import datetime
 import os
 import re
 import shutil
-import sys
-import datetime
-import subprocess
 import tarfile
 import urllib
-from pprint import pprint
-from StringIO import StringIO
+from subprocess import Popen, PIPE, STDOUT
+
 
-def prepare_upstream(prefix, commit=None):
+def prepare_upstream(base, commit):
     upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv'
-    shutil.rmtree(os.path.join(base, 'libyuv/'))
+    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', 'libyuv.tar.gz')
-    tarfile.open('libyuv.tar.gz').extractall(path='libyuv')
-    os.remove(os.path.join(base, 'libyuv.tar.gz'))
-    os.chdir(base)
-    return commit
+    urllib.urlretrieve(upstream_url + '/+archive/' + commit + '.tar.gz',
+                       tarball_file)
+    shutil.rmtree(lib_path)
+    tarfile.open(tarball_file).extractall(path=lib_path)
+    os.remove(tarball_file)
+
+    shutil.copy2(os.path.join(lib_path, "LICENSE"), os.path.join(base, "LICENSE"))
 
-def get_commit_date(prefix, commit=None):
+
+def get_commit_date(commit):
     upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv/+/' + commit
-    text = urllib.urlopen(upstream_url).readlines()
-    text = "".join(text)
-    regex = '<tr><th class="Metadata-title">committer</th><td>.+</td><td>[^\s]+ ([0-9a-zA-Z: ]+)\s*\+*[0-9]*</td></tr>'
-    date = re.search(regex, text).groups(0)[0]
+    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 = re.search(regex, text).group(1)
     return datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y")
 
-def cleanup_upstream():
+
+def cleanup_upstream(base):
     os.remove(os.path.join(base, 'libyuv/.gitignore'))
 
-def apply_patches():
-    # Patch to update gyp build files
-    os.system("patch -p3 < update_gyp.patch")
-    # Patch to fix build errors
-    os.system("patch -p3 < fix_build_errors.patch")
-    # Patch to make mjpeg printfs optional at build time
-    os.system("patch -p3 < make_mjpeg_printfs_optional.patch")
-    # Patch to allow disabling of inline ASM and AVX2 code
-    os.system("patch -p3 < allow_disabling_asm_avx2.patch")
-    # Patch to add H444ToARGB() variant
-    os.system("patch -p3 < add_H444ToARGB.patch")
-    # Patch to avoid selecting neon codepaths on AArch64 Windows
-    os.system("patch -p3 < aarch64-windows-noneon.patch")
+
+def apply_patches(base):
+    patches = [
+        # update gyp build files
+        "update_gyp.patch",
+        # fix build errors
+        'fix_build_errors.patch',
+        # make mjpeg printfs optional at build time
+        'make_mjpeg_printfs_optional.patch',
+        # allow disabling of inline ASM and AVX2 code
+        'allow_disabling_asm_avx2.patch',
+        # add H444ToARGB() variant
+        'add_H444ToARGB.patch',
+        # avoid selecting neon codepaths on AArch64 Windows
+        'aarch64-windows-noneon.patch',
+        # fix the x86 mingw-clang build
+        'bug_1491848.patch',
+    ]
 
-def update_readme(commit, commitdate):
-    with open('README_MOZILLA') as f:
-        readme = f.read()
+    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()
 
-    if 'The git commit ID last used to import was ' in readme:
-        new_readme = re.sub('The git commit ID last used to import was [v\.a-f0-9]+ \(.+\)',
-            'The git commit ID last used to import was %s (%s)' % (commit, commitdate), readme)
-    else:
-        new_readme = "%s\n\nThe git commit ID last used to import was %s\n" % (readme, commit)
+
+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 = f.read()
 
-    if readme != new_readme:
-        with open('README_MOZILLA', 'w') as f:
-            f.write(new_readme)
+    new_moz_yaml = re.sub(r'\n\s+release:.+\n',
+                          '\n  release: "%s (%s)"\n' % (commit, commitdate),
+                          moz_yaml)
 
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description='''Update libyuv''')
-    parser.add_argument('--debug', dest='debug', action="store_true")
+    if moz_yaml != new_moz_yaml:
+        with open(moz_yaml_file, 'w') as f:
+            f.write(new_moz_yaml)
+
+
+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', type=str, default='master')
-
+    parser.add_argument('--commit', dest='commit', default='master')
     args = parser.parse_args()
 
     commit = args.commit
-    DEBUG = args.debug
     no_patches = args.no_patches
+    base = os.path.realpath(os.path.dirname(__file__))
 
-    base = os.path.abspath(os.curdir)
-    prefix = os.path.join(base, 'libyuv/')
-
-    commit = prepare_upstream(prefix, commit)
-    commitdate = get_commit_date(prefix, commit)
+    prepare_upstream(base, commit)
+    commitdate = get_commit_date(commit)
 
     if not no_patches:
-        apply_patches()
+        apply_patches(base)
 
-    update_readme(commit, commitdate)
+    update_moz_yaml(base, commit, commitdate)
 
-    print('Patches applied; run "hg addremove --similarity 70 libyuv" before committing changes')
+    print('\nPatches applied; '
+          'run "hg addremove --similarity 70 libyuv" before committing changes')
 
-    cleanup_upstream()
+    cleanup_upstream(base)
+
+
+if __name__ == '__main__':
+    main()