Bug 1355671 - Build the brotli command line tool as a host program. r=gps draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 07 Apr 2017 17:02:54 +0900
changeset 564744 545e3f1b399b35daa4cd5fe62e7d9f980f34a635
parent 564743 00cd3d063b0d3440a0af84fe4918c687884b70d6
child 564745 1e0f257db047a729d1a70470431875474d426e79
push id54688
push userbmo:mh+mozilla@glandium.org
push dateWed, 19 Apr 2017 00:40:29 +0000
reviewersgps
bugs1355671
milestone55.0a1
Bug 1355671 - Build the brotli command line tool as a host program. r=gps
modules/brotli/clang-cl-exceptions.patch
modules/brotli/moz.build
modules/brotli/tools/bro.cc
modules/brotli/update.sh
new file mode 100644
--- /dev/null
+++ b/modules/brotli/clang-cl-exceptions.patch
@@ -0,0 +1,39 @@
+diff --git a/tools/bro.cc b/tools/bro.cc
+index b254f0ffdb08..30d9858a95b3 100644
+--- a/tools/bro.cc
++++ b/tools/bro.cc
+@@ -282,29 +282,34 @@ int main(int argc, char** argv) {
+     FILE* fin = OpenInputFile(input_path);
+     FILE* fout = OpenOutputFile(output_path, force);
+     if (decompress) {
+       Decompresss(fin, fout);
+     } else {
+       brotli::BrotliParams params;
+       params.lgwin = lgwin;
+       params.quality = quality;
++/* clang-cl doesn't like exceptions */
++#if !defined(_MSC_VER) || !defined(__clang__)
+       try {
++#endif
+         brotli::BrotliFileIn in(fin, 1 << 16);
+         brotli::BrotliFileOut out(fout);
+         if (!BrotliCompress(params, &in, &out)) {
+           fprintf(stderr, "compression failed\n");
+           unlink(output_path);
+           exit(1);
+         }
++#if !defined(_MSC_VER) || !defined(__clang__)
+       } catch (std::bad_alloc&) {
+         fprintf(stderr, "not enough memory\n");
+         unlink(output_path);
+         exit(1);
+       }
++#endif
+     }
+     if (fclose(fin) != 0) {
+       perror("fclose");
+       exit(1);
+     }
+     if (fclose(fout) != 0) {
+       perror("fclose");
+       exit(1);
--- a/modules/brotli/moz.build
+++ b/modules/brotli/moz.build
@@ -16,8 +16,29 @@ UNIFIED_SOURCES += [
 ]
 
 # We allow warnings for third-party code that can be updated from upstream.
 ALLOW_COMPILER_WARNINGS = True
 
 CFLAGS += ['-DBROTLI_BUILD_PORTABLE']
 
 Library('brotli')
+
+HostProgram('bro')
+
+HOST_SOURCES += UNIFIED_SOURCES
+
+HOST_SOURCES += [
+    'enc/backward_references.cc',
+    'enc/block_splitter.cc',
+    'enc/brotli_bit_stream.cc',
+    'enc/compress_fragment.cc',
+    'enc/compress_fragment_two_pass.cc',
+    'enc/encode.cc',
+    'enc/entropy_encode.cc',
+    'enc/histogram.cc',
+    'enc/literal_cost.cc',
+    'enc/metablock.cc',
+    'enc/static_dict.cc',
+    'enc/streams.cc',
+    'enc/utf8_util.cc',
+    'tools/bro.cc',
+]
--- a/modules/brotli/tools/bro.cc
+++ b/modules/brotli/tools/bro.cc
@@ -282,29 +282,34 @@ int main(int argc, char** argv) {
     FILE* fin = OpenInputFile(input_path);
     FILE* fout = OpenOutputFile(output_path, force);
     if (decompress) {
       Decompresss(fin, fout);
     } else {
       brotli::BrotliParams params;
       params.lgwin = lgwin;
       params.quality = quality;
+/* clang-cl doesn't like exceptions */
+#if !defined(_MSC_VER) || !defined(__clang__)
       try {
+#endif
         brotli::BrotliFileIn in(fin, 1 << 16);
         brotli::BrotliFileOut out(fout);
         if (!BrotliCompress(params, &in, &out)) {
           fprintf(stderr, "compression failed\n");
           unlink(output_path);
           exit(1);
         }
+#if !defined(_MSC_VER) || !defined(__clang__)
       } catch (std::bad_alloc&) {
         fprintf(stderr, "not enough memory\n");
         unlink(output_path);
         exit(1);
       }
+#endif
     }
     if (fclose(fin) != 0) {
       perror("fclose");
       exit(1);
     }
     if (fclose(fout) != 0) {
       perror("fclose");
       exit(1);
--- a/modules/brotli/update.sh
+++ b/modules/brotli/update.sh
@@ -13,14 +13,17 @@ perl -p -i -e "s/\[commit [0-9a-f]{40}\]
 
 DIRS="dec enc tools"
 
 for d in $DIRS; do
 	rm -rf $d
 	mv ${MY_TEMP_DIR}/brotli/$d $d
 done
 rm -rf ${MY_TEMP_DIR}
+
+patch -p1 < clang-cl-exceptions.patch
+
 hg addremove $DIRS
 
 echo "###"
 echo "### Updated brotli/dec to $COMMIT."
 echo "### Remember to verify and commit the changes to source control!"
 echo "###"