Prebuilts built with MSVC2015

Change-Id: I74d2f14a325c48bfd7a633ded7dce9822856e3dc
diff --git a/Debug/libprotobuf-lite.lib b/Debug/libprotobuf-lite.lib
index c65cfe9..92bf1d4 100755
--- a/Debug/libprotobuf-lite.lib
+++ b/Debug/libprotobuf-lite.lib
Binary files differ
diff --git a/Debug/libprotobuf-lite.pdb b/Debug/libprotobuf-lite.pdb
new file mode 100755
index 0000000..6ebcdbf
--- /dev/null
+++ b/Debug/libprotobuf-lite.pdb
Binary files differ
diff --git a/Debug/libprotobuf.lib b/Debug/libprotobuf.lib
index e238019..5b4f7a3 100755
--- a/Debug/libprotobuf.lib
+++ b/Debug/libprotobuf.lib
Binary files differ
diff --git a/Debug/libprotobuf.pdb b/Debug/libprotobuf.pdb
new file mode 100755
index 0000000..69d0d86
--- /dev/null
+++ b/Debug/libprotobuf.pdb
Binary files differ
diff --git a/Debug/libprotoc.lib b/Debug/libprotoc.lib
index eff9b16..e98a4ae 100755
--- a/Debug/libprotoc.lib
+++ b/Debug/libprotoc.lib
Binary files differ
diff --git a/Debug/libprotoc.pdb b/Debug/libprotoc.pdb
new file mode 100755
index 0000000..4c70edb
--- /dev/null
+++ b/Debug/libprotoc.pdb
Binary files differ
diff --git a/Debug/lite-test.exe b/Debug/lite-test.exe
index 1b84662..c3e4ae9 100755
--- a/Debug/lite-test.exe
+++ b/Debug/lite-test.exe
Binary files differ
diff --git a/Debug/lite-test.ilk b/Debug/lite-test.ilk
index 15e1801..6b5d8e2 100755
--- a/Debug/lite-test.ilk
+++ b/Debug/lite-test.ilk
Binary files differ
diff --git a/Debug/lite-test.pdb b/Debug/lite-test.pdb
index 53c9570..726933f 100755
--- a/Debug/lite-test.pdb
+++ b/Debug/lite-test.pdb
Binary files differ
diff --git a/Debug/protoc.exe b/Debug/protoc.exe
index fb9d37a..d16dd9b 100755
--- a/Debug/protoc.exe
+++ b/Debug/protoc.exe
Binary files differ
diff --git a/Debug/protoc.ilk b/Debug/protoc.ilk
index 2bd253f..20d764b 100755
--- a/Debug/protoc.ilk
+++ b/Debug/protoc.ilk
Binary files differ
diff --git a/Debug/protoc.pdb b/Debug/protoc.pdb
index e2568c0..f5b09a7 100755
--- a/Debug/protoc.pdb
+++ b/Debug/protoc.pdb
Binary files differ
diff --git a/Debug/test_plugin.exe b/Debug/test_plugin.exe
index ba10f21..ec7ba8a 100755
--- a/Debug/test_plugin.exe
+++ b/Debug/test_plugin.exe
Binary files differ
diff --git a/Debug/test_plugin.ilk b/Debug/test_plugin.ilk
index b82e6ba..9bd4028 100755
--- a/Debug/test_plugin.ilk
+++ b/Debug/test_plugin.ilk
Binary files differ
diff --git a/Debug/test_plugin.pdb b/Debug/test_plugin.pdb
index 7f8a783..7b5005f 100755
--- a/Debug/test_plugin.pdb
+++ b/Debug/test_plugin.pdb
Binary files differ
diff --git a/Debug/tests.exe b/Debug/tests.exe
index cde5100..bd59bf9 100755
--- a/Debug/tests.exe
+++ b/Debug/tests.exe
Binary files differ
diff --git a/Debug/tests.ilk b/Debug/tests.ilk
index f987fa4..10e001e 100755
--- a/Debug/tests.ilk
+++ b/Debug/tests.ilk
Binary files differ
diff --git a/Debug/tests.pdb b/Debug/tests.pdb
index cd78a29..5464a28 100755
--- a/Debug/tests.pdb
+++ b/Debug/tests.pdb
Binary files differ
diff --git a/Release/libprotobuf-lite.lib b/Release/libprotobuf-lite.lib
index d267896..9ba7018 100755
--- a/Release/libprotobuf-lite.lib
+++ b/Release/libprotobuf-lite.lib
Binary files differ
diff --git a/Release/libprotobuf.lib b/Release/libprotobuf.lib
index 4ce9fa0..72b6d7a 100755
--- a/Release/libprotobuf.lib
+++ b/Release/libprotobuf.lib
Binary files differ
diff --git a/Release/libprotoc.lib b/Release/libprotoc.lib
index 62c2562..75ac940 100755
--- a/Release/libprotoc.lib
+++ b/Release/libprotoc.lib
Binary files differ
diff --git a/Release/lite-test.exe b/Release/lite-test.exe
index c8ae304..f439f69 100755
--- a/Release/lite-test.exe
+++ b/Release/lite-test.exe
Binary files differ
diff --git a/Release/lite-test.pdb b/Release/lite-test.pdb
index 972179b..71d272a 100755
--- a/Release/lite-test.pdb
+++ b/Release/lite-test.pdb
Binary files differ
diff --git a/Release/protoc.exe b/Release/protoc.exe
index 2bcaebb..d30aa63 100755
--- a/Release/protoc.exe
+++ b/Release/protoc.exe
Binary files differ
diff --git a/Release/protoc.pdb b/Release/protoc.pdb
index fdad2bb..bd3b313 100755
--- a/Release/protoc.pdb
+++ b/Release/protoc.pdb
Binary files differ
diff --git a/Release/test_plugin.exe b/Release/test_plugin.exe
index 5a3d0c9..f92cb1d 100755
--- a/Release/test_plugin.exe
+++ b/Release/test_plugin.exe
Binary files differ
diff --git a/Release/test_plugin.pdb b/Release/test_plugin.pdb
index 171f318..b98ad4f 100755
--- a/Release/test_plugin.pdb
+++ b/Release/test_plugin.pdb
Binary files differ
diff --git a/Release/tests.exe b/Release/tests.exe
index cd6fba7..5ab99e6 100755
--- a/Release/tests.exe
+++ b/Release/tests.exe
Binary files differ
diff --git a/Release/tests.pdb b/Release/tests.pdb
index f7dd590..b1025ad 100755
--- a/Release/tests.pdb
+++ b/Release/tests.pdb
Binary files differ
diff --git a/build-common.sh b/build-common.sh
index 70c3a70..1ab2249 100755
--- a/build-common.sh
+++ b/build-common.sh
@@ -4,27 +4,69 @@
 # inputs
 # $PROJ - project name
 # $VER - project version
-# $1 - name of this file
+# $1 - (temporary) output directory
+# $2 - build directory for build artefacts
+# $3 - build number
 #
 # this file does the following:
 #
 # 1) define the following env vars
 #    OS - linux|darwin|windows
-#    USER - username
 #    CORES - numer of cores (for parallel builds)
 #    PATH (with appropriate compilers)
 #    CFLAGS/CXXFLAGS/LDFLAGS
 #    RD - root directory for source and object files
-#    INSTALL - install directory/git repo root
+#    INSTALL - install directory
 #    SCRIPT_FILE - absolute path to the parent build script
 #    SCRIPT_DIR - absolute path to the parent build script's directory
 #    COMMON_FILE - absolute path to this file
-# 2) create an empty tmp directory at /tmp/$PROJ-$USER
-# 3) checkout the destination git repo to /tmp/prebuilts/$PROJ/$OS-x86/$VER
-# 4) cd $RD
+# 2) cd $RD
+#
+# after placing all your build products into $INSTALL you should call finalize_build to produce
+# the final build artifact
+
+# exit on error
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd -P)"
+SCRIPT_FILE="$SCRIPT_DIR/$(basename "${BASH_SOURCE[1]}")"
+COMMON_FILE="$SCRIPT_DIR/$(basename "${BASH_SOURCE[0]}")"
+
+# calculate the root directory from the script path
+# this script lives three directories down from the root
+# external/lldb-utils/prebuilts/build-common.sh
+ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
+cd "$ROOT_DIR"
+
+function die() {
+	echo "$*" > /dev/stderr
+	echo "Usage: $0 <out_dir> <dest_dir> <build_number>" > /dev/stderr
+	exit 1
+}
+
+(($# > 3)) && die "[$0] Unknown parameter: $4"
+
+OUT="$1"
+DEST="$2"
+BNUM="$3"
+
+[ ! "$OUT"  ] && die "## Error: Missing out folder"
+[ ! "$DEST" ] && die "## Error: Missing destination folder"
+[ ! "$BNUM" ] && die "## Error: Missing build number"
+
+mkdir -p "$OUT" "$DEST"
+OUT="$(cd "$OUT" && pwd -P)"
+DEST="$(cd "$DEST" && pwd -P)"
+
+cat <<END_INFO
+## Building $PROJ ##
+## Out Dir  : $OUT
+## Dest Dir : $DEST
+## Build Num: $BNUM
+
+END_INFO
 
 UNAME="$(uname)"
-SCRATCH=/tmp
 UPSTREAM=sso://googleplex-android/platform/prebuilts
 case "$UNAME" in
 Linux)
@@ -38,14 +80,19 @@
     export CXX=$CC++
     export CFLAGS="$CFLAGS -mmacosx-version-min=$OSX_MIN"
     export CXXFLAGS="$CXXFLAGS -mmacosx-version-min=$OSX_MIN -stdlib=libc++"
+    export LDFLAGS="$LDFLAGS -mmacosx-version-min=$OSX_MIN"
     INSTALL_VER=$VER
     ;;
 *_NT-*)
-    USER=$USERNAME
     OS='windows'
     CORES=$NUMBER_OF_PROCESSORS
-    # VS2013 x64 Native Tools Command Prompt
     case "$MSVS" in
+    2015)
+        devenv() {
+            cmd /c "${VS140COMNTOOLS}VsDevCmd.bat" '&' devenv.com "$@"
+        }
+        INSTALL_VER=${VER}_${MSVS}
+        ;;
     2013)
         devenv() {
             cmd /c "${VS120COMNTOOLS}VsDevCmd.bat" '&' devenv.com "$@"
@@ -65,18 +112,9 @@
     ;;
 esac
 
-RD=$SCRATCH/$PROJ-$USER
+RD=$OUT/$PROJ
 INSTALL="$RD/install"
 
-# OSX lacks a "realpath" bash command
-realpath() {
-    [[ "$1" == /* ]] && echo "$1" || echo "$PWD/${1#./}"
-}
-
-SCRIPT_FILE=$(realpath "$0")
-SCRIPT_DIR="$(dirname "$SCRIPT_FILE")"
-COMMON_FILE="$SCRIPT_DIR/$1"
-
 cd /tmp # windows can't delete if you're in the dir
 rm -rf $RD
 mkdir -p $INSTALL
@@ -86,44 +124,30 @@
 # clone prebuilt gcc
 case "$OS" in
 linux)
-    CLANG_DIR=$RD/clang
+    # can't get prebuilt clang working so we're using host clang-3.5 https://b/22748915
+    #CLANG_DIR=$RD/clang
+    #git clone $UPSTREAM/clang/linux-x86/host/3.6 $CLANG_DIR
+    #export CC="$CLANG_DIR/bin/clang"
+    #export CXX="$CC++"
+    export CC=clang-3.5
+    export CXX=clang++-3.5
+
     GCC_DIR=$RD/gcc
-    git clone $UPSTREAM/clang/linux-x86/host/3.6 $CLANG_DIR
     git clone $UPSTREAM/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8 $GCC_DIR
 
     find "$GCC_DIR" -name x86_64-linux -exec ln -fns {} {}-gnu \;
 
-    export CC="$CLANG_DIR/bin/clang"
-    export CXX="$CC++"
     FLAGS+=(-fuse-ld=gold)
     FLAGS+=(--gcc-toolchain="$GCC_DIR")
     FLAGS+=(--sysroot "$GCC_DIR/sysroot")
     FLAGS+=(-B"$GCC_DIR/bin/x86_64-linux-")
     export CFLAGS="$CFLAGS ${FLAGS[*]}"
     export CXXFLAGS="$CXXFLAGS ${FLAGS[*]}"
+    export LDFLAGS="$LDFLAGS -m64"
     ;;
 esac
 
-commit_and_push()
-{
-    BRANCH=studio-master-dev
-    # check into a local git clone
-    rm -rf $SCRATCH/prebuilts/$PROJ/
-    mkdir -p $SCRATCH/prebuilts/$PROJ/
-    cd $SCRATCH/prebuilts/$PROJ/
-    git clone $UPSTREAM/$PROJ/$OS-x86 -b $BRANCH
-    GIT_REPO="$SCRATCH/prebuilts/$PROJ/$OS-x86"
-    cd $GIT_REPO
-    rm -rf *
-    mv $INSTALL/* $GIT_REPO
-    cp $SCRIPT_FILE $GIT_REPO
-    cp $COMMON_FILE $GIT_REPO
-
-    git add .
-    git commit -m "Adding binaries for $INSTALL_VER"
-
-    # execute this command to upload
-    #git push origin HEAD:refs/for/$BRANCH
-
-    rm -rf $RD
+function finalize_build() {
+    cp "$SCRIPT_FILE" "$COMMON_FILE" "$INSTALL"
+    (cd "$INSTALL" && zip --symlinks -r "$DEST/$PROJ-$BNUM.zip" .)
 }
diff --git a/build-protobuf.sh b/build-protobuf.sh
index d72b998..7b48863 100755
--- a/build-protobuf.sh
+++ b/build-protobuf.sh
@@ -9,9 +9,9 @@
 
 PROJ=libprotobuf
 VER=2.6.1
-MSVS=2013
+MSVS=2015
 
-source $(dirname "$0")/build-common.sh build-common.sh
+source "$(dirname "${BASH_SOURCE[0]}")/build-common.sh" "$@"
 
 BASE=${PROJ#lib}-$VER
 TGZ=v${VER}.tar.gz
@@ -20,6 +20,7 @@
 
 tar xzf $TGZ || cat $TGZ # if this fails, we're probably getting an http error
 cd $BASE
+patch -p1 <"$SCRIPT_DIR/protobuf.patches"
 ./autogen.sh
 
 case "$OS" in
@@ -27,8 +28,8 @@
 		cd vsprojects
 		sed -i 's/\(IntermediateDirectory=\)".*"/\1"$(OutDir)$(ProjectName)"/' *.vcproj
 		devenv protobuf.sln /Upgrade
-		devenv protobuf.sln /Build Debug
-		devenv protobuf.sln /Build Release
+		CL=/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS devenv protobuf.sln /Build Debug
+		CL=/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS devenv protobuf.sln /Build Release
 		mkdir -p $INSTALL/Debug $INSTALL/Release
 		cp -a Debug/*.* $INSTALL/Debug
 		cp -a Release/*.* $INSTALL/Release
@@ -62,4 +63,4 @@
 		;;
 esac
 
-commit_and_push
+finalize_build
diff --git a/protobuf.patches b/protobuf.patches
new file mode 100644
index 0000000..4e848c8
--- /dev/null
+++ b/protobuf.patches
@@ -0,0 +1,80 @@
+diff -aur protobuf-2.6.1x/src/google/protobuf/compiler/command_line_interface_unittest.cc protobuf-2.6.1/src/google/protobuf/compiler/command_line_interface_unittest.cc
+--- protobuf-2.6.1x/src/google/protobuf/compiler/command_line_interface_unittest.cc     2014-10-20 17:06:06.000000000 -0700
++++ protobuf-2.6.1/src/google/protobuf/compiler/command_line_interface_unittest.cc      2016-02-04 07:47:59.893962900 -0800
+@@ -714,7 +714,7 @@
+ #endif
+
+   Run("protocol_compiler --test_out=$tmpdir "
+-      "--proto_path=$tmpdir/a"PATH_SEPARATOR"$tmpdir/b foo.proto");
++      "--proto_path=$tmpdir/a" PATH_SEPARATOR "$tmpdir/b foo.proto");
+
+ #undef PATH_SEPARATOR
+
+diff -aur protobuf-2.6.1x/src/google/protobuf/compiler/parser_unittest.cc protobuf-2.6.1/src/google/protobuf/compiler/parser_unittest.cc
+--- protobuf-2.6.1x/src/google/protobuf/compiler/parser_unittest.cc     2014-10-20 17:06:06.000000000 -0700
++++ protobuf-2.6.1/src/google/protobuf/compiler/parser_unittest.cc      2016-02-04 07:47:54.215562900 -0800
+@@ -365,35 +365,35 @@
+ #define ETC "name:\"foo\" label:LABEL_REQUIRED number:1"
+     "message_type {"
+     "  name: \"TestMessage\""
+-    "  field { type:TYPE_INT32   default_value:\"1\"         "ETC" }"
+-    "  field { type:TYPE_INT32   default_value:\"-2\"        "ETC" }"
+-    "  field { type:TYPE_INT64   default_value:\"3\"         "ETC" }"
+-    "  field { type:TYPE_INT64   default_value:\"-4\"        "ETC" }"
+-    "  field { type:TYPE_UINT32  default_value:\"5\"         "ETC" }"
+-    "  field { type:TYPE_UINT64  default_value:\"6\"         "ETC" }"
+-    "  field { type:TYPE_FLOAT   default_value:\"7.5\"       "ETC" }"
+-    "  field { type:TYPE_FLOAT   default_value:\"-8.5\"      "ETC" }"
+-    "  field { type:TYPE_FLOAT   default_value:\"9\"         "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"10.5\"      "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"-11.5\"     "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"12\"        "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"inf\"       "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"-inf\"      "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"nan\"       "ETC" }"
+-    "  field { type:TYPE_STRING  default_value:\"13\\001\"   "ETC" }"
+-    "  field { type:TYPE_STRING  default_value:\"abc\"       "ETC" }"
+-    "  field { type:TYPE_BYTES   default_value:\"14\\\\002\" "ETC" }"
+-    "  field { type:TYPE_BYTES   default_value:\"abc\"       "ETC" }"
+-    "  field { type:TYPE_BOOL    default_value:\"true\"      "ETC" }"
+-    "  field { type_name:\"Foo\" default_value:\"FOO\"       "ETC" }"
++    "  field { type:TYPE_INT32   default_value:\"1\"         " ETC " }"
++    "  field { type:TYPE_INT32   default_value:\"-2\"        " ETC " }"
++    "  field { type:TYPE_INT64   default_value:\"3\"         " ETC " }"
++    "  field { type:TYPE_INT64   default_value:\"-4\"        " ETC " }"
++    "  field { type:TYPE_UINT32  default_value:\"5\"         " ETC " }"
++    "  field { type:TYPE_UINT64  default_value:\"6\"         " ETC " }"
++    "  field { type:TYPE_FLOAT   default_value:\"7.5\"       " ETC " }"
++    "  field { type:TYPE_FLOAT   default_value:\"-8.5\"      " ETC " }"
++    "  field { type:TYPE_FLOAT   default_value:\"9\"         " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"10.5\"      " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"-11.5\"     " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"12\"        " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"inf\"       " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"-inf\"      " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"nan\"       " ETC " }"
++    "  field { type:TYPE_STRING  default_value:\"13\\001\"   " ETC " }"
++    "  field { type:TYPE_STRING  default_value:\"abc\"       " ETC " }"
++    "  field { type:TYPE_BYTES   default_value:\"14\\\\002\" " ETC " }"
++    "  field { type:TYPE_BYTES   default_value:\"abc\"       " ETC " }"
++    "  field { type:TYPE_BOOL    default_value:\"true\"      " ETC " }"
++    "  field { type_name:\"Foo\" default_value:\"FOO\"       " ETC " }"
+
+-    "  field { type:TYPE_INT32   default_value:\"2147483647\"           "ETC" }"
+-    "  field { type:TYPE_INT32   default_value:\"-2147483648\"          "ETC" }"
+-    "  field { type:TYPE_UINT32  default_value:\"4294967295\"           "ETC" }"
+-    "  field { type:TYPE_INT64   default_value:\"9223372036854775807\"  "ETC" }"
+-    "  field { type:TYPE_INT64   default_value:\"-9223372036854775808\" "ETC" }"
+-    "  field { type:TYPE_UINT64  default_value:\"18446744073709551615\" "ETC" }"
+-    "  field { type:TYPE_DOUBLE  default_value:\"43981\"                "ETC" }"
++    "  field { type:TYPE_INT32   default_value:\"2147483647\"           " ETC " }"
++    "  field { type:TYPE_INT32   default_value:\"-2147483648\"          " ETC " }"
++    "  field { type:TYPE_UINT32  default_value:\"4294967295\"           " ETC " }"
++    "  field { type:TYPE_INT64   default_value:\"9223372036854775807\"  " ETC " }"
++    "  field { type:TYPE_INT64   default_value:\"-9223372036854775808\" " ETC " }"
++    "  field { type:TYPE_UINT64  default_value:\"18446744073709551615\" " ETC " }"
++    "  field { type:TYPE_DOUBLE  default_value:\"43981\"                " ETC " }"
+     "}");
+ #undef ETC
+ }
+