Bug 1355671 - Build the brotli command line tool as a host program. r=gps
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 "###"