Bug 641212 Part 7 - Replace libbz2 with XZ in the mbsdiff tool. r?rstrong draft
authorMatt Howell <mhowell@mozilla.com>
Sun, 09 Jul 2017 11:17:28 -0700
changeset 607659 596043d866cae0bc6850a4c8a31d973e38416cd1
parent 607658 f40d4bc50c3546e508771e0214401242f54391e1
child 607660 1e61076163f728086dbd98b3c6516969249f748a
child 607675 e1afe3a47e76b5755cf13d7f087ba211fd1aa27b
push id68072
push usermhowell@mozilla.com
push dateWed, 12 Jul 2017 17:32:12 +0000
reviewersrstrong
bugs641212
milestone56.0a1
Bug 641212 Part 7 - Replace libbz2 with XZ in the mbsdiff tool. r?rstrong BZ2 isn't needed in mbsdiff for compression purposes, it's only used for CRC32 calculation. liblzma contains code for that, so use it instead. MozReview-Commit-ID: 86khl2DOWB
config/external/moz.build
other-licenses/bsdiff/bsdiff.c
other-licenses/bsdiff/moz.build
toolkit/toolkit.mozbuild
--- a/config/external/moz.build
+++ b/config/external/moz.build
@@ -9,17 +9,17 @@ external_dirs = []
 DIRS += [
     'lgpllibs',
     'sqlite',
 ]
 if not CONFIG['MOZ_SYSTEM_JPEG']:
     external_dirs += ['media/libjpeg']
 
 if CONFIG['MOZ_UPDATER']:
-    if not CONFIG['MOZ_SYSTEM_BZ2']:
+    if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android'
         external_dirs += ['modules/libbz2']
 
 # There's no "native" brotli or woff2 yet, but probably in the future...
 external_dirs += ['modules/brotli']
 external_dirs += ['modules/woff2']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     external_dirs += ['modules/xz']
--- a/other-licenses/bsdiff/bsdiff.c
+++ b/other-licenses/bsdiff/bsdiff.c
@@ -18,50 +18,31 @@
 
 #include "bspatch.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
 #include <stdarg.h>
+#include "lzma.h"
 #ifdef XP_WIN
 #include <io.h>
 #include <winsock2.h>
 #else
 #include <unistd.h>
 #include <arpa/inet.h>
 #define _O_BINARY 0
 #endif
 
 #undef MIN
 #define MIN(x,y) (((x)<(y)) ? (x) : (y))
 
 /*---------------------------------------------------------------------------*/
 
-/* This variable lives in libbz2.  It's declared in bzlib_private.h, so we just
- * declare it here to avoid including that entire header file.
- */
-extern unsigned int BZ2_crc32Table[256];
-
-static unsigned int
-crc32(const unsigned char *buf, unsigned int len)
-{
-	unsigned int crc = 0xffffffffL;
-
-	const unsigned char *end = buf + len;
-	for (; buf != end; ++buf)
-		crc = (crc << 8) ^ BZ2_crc32Table[(crc >> 24) ^ *buf];
-
-	crc = ~crc;
-	return crc;
-}
-
-/*---------------------------------------------------------------------------*/
-
 static void
 reporterr(int e, const char *fmt, ...)
 {
 	if (fmt) {
 		va_list args;
 		va_start(args, fmt);
 		vfprintf(stderr, fmt, args);
 		va_end(args);
@@ -244,17 +225,17 @@ int main(int argc,char *argv[])
 	if(((fd=open(argv[1],O_RDONLY|_O_BINARY,0))<0) ||
 		((oldsize=lseek(fd,0,SEEK_END))==-1) ||
 		((old=(unsigned char*) malloc(oldsize+1))==NULL) ||
 		(lseek(fd,0,SEEK_SET)!=0) ||
 		(read(fd,old,oldsize)!=oldsize) ||
 		(close(fd)==-1))
 		reporterr(1,"%s\n",argv[1]);
 
-	scrc = crc32(old, oldsize);
+	scrc = lzma_crc32(old, oldsize, 0);
 
 	if(((I=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL) ||
 		((V=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL))
 		reporterr(1,NULL);
 
 	qsufsort(I,V,old,oldsize);
 
 	free(V);
--- a/other-licenses/bsdiff/moz.build
+++ b/other-licenses/bsdiff/moz.build
@@ -5,26 +5,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 HOST_SOURCES += [
     'bsdiff.c',
 ]
 
 HostProgram('mbsdiff')
 
-if CONFIG['MOZ_SYSTEM_BZ2']:
-    HOST_OS_LIBS += CONFIG['MOZ_BZ2_LIBS']
-else:
-    HOST_USE_LIBS += [
-        'hostbz2',
-    ]
+HOST_USE_LIBS += [
+    'hostlzma',
+]
+
+HOST_DEFINES['LZMA_API_STATIC'] = 1
 
 if CONFIG['HOST_OS_ARCH'] == 'WINNT':
     HOST_OS_LIBS += [
         'ws2_32',
     ]
     USE_STATIC_LIBS = True
 
 LOCAL_INCLUDES += [
     '/toolkit/mozapps/update/updater',
 ]
-
-HOST_CXXFLAGS += CONFIG['MOZ_BZ2_CFLAGS']
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -30,17 +30,17 @@ DIRS += [
     '/modules/libpref',
     '/intl',
     '/netwerk',
 ]
 
 if CONFIG['MOZ_AUTH_EXTENSION']:
     DIRS += ['/extensions/auth']
 
-if CONFIG['MOZ_UPDATER']:
+if CONFIG['MOZ_UPDATER'] and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     DIRS += ['/other-licenses/bsdiff']
 
 # Gecko/Core components.
 
 DIRS += [
     '/ipc',
     '/js/ipc',
     '/hal',