Remove the $HOST_TAG from binutils and toolchains.

Turns out this complicates a lot of code unnecessarily because we need
to always check if we're a 32- or 64-bit NDK on Windows.

Bug: http://b/25454836
Change-Id: I50c53aee76fbc88f0be8c95d7ae6e7d550ca468e
diff --git a/build/core/init.mk b/build/core/init.mk
index 248a711..d2e2d7c 100644
--- a/build/core/init.mk
+++ b/build/core/init.mk
@@ -106,7 +106,7 @@
 # Returns  : The parent path of all toolchains for this host. Note that
 #            HOST_TAG64 == HOST_TAG for 32-bit systems.
 # -----------------------------------------------------------------------------
-host-toolchain-path = $1/toolchains/$(HOST_TAG64)
+host-toolchain-path = $1/toolchains
 
 # -----------------------------------------------------------------------------
 # Function : get-toolchain-root
@@ -122,7 +122,7 @@
 #            2: Toolchain name (no version number)
 # Returns  : Path to the given prebuilt binutils.
 # -----------------------------------------------------------------------------
-get-binutils-root = $1/binutils/$(HOST_TAG64)/$2
+get-binutils-root = $1/binutils/$2
 
 # -----------------------------------------------------------------------------
 # Function : get-gcclibs-path
diff --git a/build/tools/README.md b/build/tools/README.md
index e3357fb..dd27d97 100644
--- a/build/tools/README.md
+++ b/build/tools/README.md
@@ -240,9 +240,8 @@
 download-toolchain-sources.sh is now obsolete.
 
 The toolchains binaries are typically placed under the directory
-$NDK/toolchains/$SYSTEM/$NAME/prebuilt, where $NAME is the toolchain name's full
-name (e.g. arm-linux-androideabi-4.8), and $SYSTEM is the name of the host
-system it is meant to run on (e.g. `linux-x86`, `windows` or `darwin-x86`)
+$NDK/toolchains/$NAME/prebuilt, where $NAME is the toolchain name's full name
+(e.g. arm-linux-androideabi-4.8).
 
 I.2. Building the toolchains:
 -----------------------------
@@ -295,9 +294,8 @@
     $NDK/build/tools/build-gcc.sh --mingw \
         /tmp/ndk-$USER/src $NDK x86-4.8
 
-The corresponding binaries are installed under
-$NDK/toolchains/windows/$NAME/prebuilt. Note that these are native Windows
-programs, not Cygwin ones.
+The corresponding binaries are installed under $NDK/toolchains/$NAME/prebuilt.
+Note that these are native Windows programs, not Cygwin ones.
 
 Building the Windows toolchains under MSys and Cygwin is completely unsupported
 and highly un-recommended: even if it works, it will probably take several
@@ -340,13 +338,8 @@
 technical reasons, it must be copied into a debuggable project's output
 directory when `ndk-build` is called.
 
-The prebuilt binary is placed under $NDK/toolchains/$NAME/prebuilt/gdbserver in
-the final NDK installation. You can generate with `build-gdbserver.sh` and takes
-the same parameters than `build-gcc.sh`. So one can do:
-
-    $NDK/build/tools/build-gcc.sh /tmp/ndk-$USER/src $NDK \
-        arm-linux-androideabi-4.8
-    $NDK/build/tools/build-gcc.sh /tmp/ndk-$USER/src $NDK x86-4.8
+The prebuilt binary is placed under $NDK/gdbserver/$ARCH in the final NDK
+installation. You can generate them with `build-gdbserver.py`.
 
 
 III.3. Generating C++ runtime prebuilt binaries:
diff --git a/build/tools/build-gcc.py b/build/tools/build-gcc.py
index e0c054a..5560276 100755
--- a/build/tools/build-gcc.py
+++ b/build/tools/build-gcc.py
@@ -53,7 +53,7 @@
     package_name = 'gcc-{}-{}.tar.bz2'.format(arch, host_tag)
     package_path = os.path.join(package_dir, package_name)
     with tarfile.TarFile.open(package_path, 'w:bz2') as tarball:
-        arcname = os.path.join('toolchains', host_tag, toolchain_name)
+        arcname = os.path.join('toolchains', toolchain_name)
 
         def package_filter(tarinfo):
             if os.path.basename(tarinfo.name) == '.git':
diff --git a/build/tools/build-gdb-stub.sh b/build/tools/build-gdb-stub.sh
index b177657..be2c6cf 100755
--- a/build/tools/build-gdb-stub.sh
+++ b/build/tools/build-gdb-stub.sh
@@ -11,7 +11,7 @@
 check to see if there's a gdb-orig.exe there already and if so, 'undo'
 the process first by putting it back. Sample usage:
 
-$0 --gdb-executable-path=\$NDK/toolchains/windows/arm-linux-androideabi-4.8/prebuilt/bin/arm-linux-androideabi-gdb.exe \\
+$0 --gdb-executable-path=\$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/bin/arm-linux-androideabi-gdb.exe \\
    --python-prefix-dir=\$NDK/prebuilt/windows \\
    --mingw-w64-gcc-path=\$HOME/i686-w64-mingw32/bin/i686-w64-mingw32-gcc
 "
diff --git a/build/tools/build-llvm.py b/build/tools/build-llvm.py
index c56208f..6f013d5 100755
--- a/build/tools/build-llvm.py
+++ b/build/tools/build-llvm.py
@@ -64,7 +64,7 @@
     package_name = 'llvm-{}-{}.tar.bz2'.format(LLVM_VERSION, host)
     package_path = os.path.join(package_dir, package_name)
     with tarfile.TarFile.open(package_path, 'w:bz2') as tarball:
-        arcname = 'toolchains/{}/llvm-{}/prebuilt'.format(host, LLVM_VERSION)
+        arcname = 'toolchains/llvm-{}/prebuilt'.format(LLVM_VERSION)
 
         def package_filter(tarinfo):
             if os.path.basename(tarinfo.name) == '.git':
diff --git a/build/tools/make-standalone-toolchain.sh b/build/tools/make-standalone-toolchain.sh
index d3949f6..c080bfd 100755
--- a/build/tools/make-standalone-toolchain.sh
+++ b/build/tools/make-standalone-toolchain.sh
@@ -47,13 +47,6 @@
 NDK_DIR=`dirname $NDK_DIR`
 register_var_option "--ndk-dir=<path>" NDK_DIR "Take source files from NDK at <path>"
 
-if [ -d "$NDK_DIR/toolchains/$HOST_TAG" ]; then
-  SYSTEM=$HOST_TAG
-else
-  SYSTEM=$HOST_TAG32
-fi
-register_var_option "--system=<name>" SYSTEM "Specify host system"
-
 PACKAGE_DIR=$TMPDIR
 register_var_option "--package-dir=<path>" PACKAGE_DIR "Place package file in <path>"
 
@@ -177,11 +170,11 @@
 fi
 
 # Check toolchain name
-TOOLCHAIN_PATH="$NDK_DIR/toolchains/$SYSTEM/$TOOLCHAIN_NAME"
+TOOLCHAIN_PATH="$NDK_DIR/toolchains/$TOOLCHAIN_NAME"
 if [ ! -d "$TOOLCHAIN_PATH" ] ; then
     echo "Could not find toolchain: $TOOLCHAIN_PATH"
     echo "Please use --toolchain=<name> with the name of a toolchain supported by the source NDK."
-    echo "Try one of: " `(cd "$NDK_DIR/toolchains/$SYSTEM" && ls)`
+    echo "Try one of: " `(cd "$NDK_DIR/toolchains" && ls)`
     exit 1
 fi
 
@@ -230,7 +223,7 @@
 fi
 
 if [ -n "$LLVM_VERSION" ]; then
-    LLVM_TOOLCHAIN_PATH="$NDK_DIR/toolchains/$SYSTEM/llvm-$LLVM_VERSION"
+    LLVM_TOOLCHAIN_PATH="$NDK_DIR/toolchains/llvm-$LLVM_VERSION"
     # Check that we have any prebuilts LLVM toolchain here
     if [ ! -d "$LLVM_TOOLCHAIN_PATH/prebuilt" ] ; then
         echo "LLVM Toolchain is missing prebuilt files"
diff --git a/checkbuild.py b/checkbuild.py
index 20329aa..aa436c2 100644
--- a/checkbuild.py
+++ b/checkbuild.py
@@ -246,8 +246,7 @@
         triple = fixup_toolchain_triple(toolchain)
         tmpdir = tempfile.mkdtemp()
         try:
-            install_dir = os.path.join(tmpdir, 'binutils', host_tag,
-                                       toolchain)
+            install_dir = os.path.join(tmpdir, 'binutils', toolchain)
             os.makedirs(install_dir)
             is_windows = host_tag.startswith('windows')
             has_gold = not triple.startswith('mips') and not is_windows
diff --git a/ndk-build b/ndk-build
index b098ff9..9e06186 100755
--- a/ndk-build
+++ b/ndk-build
@@ -261,7 +261,7 @@
     APP_ABIS=`get_build_var APP_ABI`
     for ABI in $APP_ABIS; do
         TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $ABI`
-        LLVM_PATH=$PROGDIR/toolchains/llvm-${DEFAULT_LLVM_VERSION}/prebuilt/$HOST_TAG
+        LLVM_PATH=$PROGDIR/toolchains/llvm-${DEFAULT_LLVM_VERSION}/prebuilt
         perl $LLVM_PATH/tools/scan-build/scan-build \
             --use-analyzer $LLVM_PATH/bin/${ABI}/analyzer \
             --use-cc ${TOOLCHAIN_PREFIX}gcc \
diff --git a/remove-windows-symlink.sh b/remove-windows-symlink.sh
index e3c890a..bafaaae 100755
--- a/remove-windows-symlink.sh
+++ b/remove-windows-symlink.sh
@@ -2,10 +2,10 @@
 
 . `dirname $0`/build/tools/ndk-common.sh
 
-# Find all symlink in toolchains/windows and windows-x86_64 directories
-WIN_DIRS=`find toolchains \( -name "windows" -o -name "windows-x86_64" \)`
+# Find all symlink in toolchains directory.
+WIN_DIRS=`find toolchains`
 
 dereference_symlink $WIN_DIRS
 
 # The following should print nothing if we did good job
-find toolchains/ -type l | grep windows
+find toolchains/ -type l
diff --git a/sources/cxx-stl/llvm-libc++/libcxx/ndk-test.sh b/sources/cxx-stl/llvm-libc++/libcxx/ndk-test.sh
index 0ca71b5..4a6603f 100755
--- a/sources/cxx-stl/llvm-libc++/libcxx/ndk-test.sh
+++ b/sources/cxx-stl/llvm-libc++/libcxx/ndk-test.sh
@@ -48,7 +48,7 @@
 
 LIBCXX_DIR=$NDK/sources/cxx-stl/llvm-libc++/libcxx
 sed -e "s:%ABI%:$ABI:g" -e "s:%TRIPLE%:$TRIPLE:g" \
-    -e "s:%HOST_TAG%:$HOST_TAG:g" -e "s:%ARCH%:$ARCH:g" \
+    -e "s:%ARCH%:$ARCH:g" \
     $LIBCXX_DIR/test/lit.ndk.cfg.in > $LIBCXX_DIR/test/lit.site.cfg
 
 adb push $LIBCXX_DIR/../libs/$ABI/libc++_shared.so /data/local/tmp
diff --git a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
index 237ee83..b41eb9b 100644
--- a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
+++ b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
@@ -15,7 +15,7 @@
 libcxx_src_dir = os.path.join(libcxx_dir, 'libcxx')
 
 config.cxx_under_test = os.path.join(
-    ndk, "toolchains/%HOST_TAG%/llvm-3.6/prebuilt/bin/clang++")
+    ndk, "toolchains/llvm-3.6/prebuilt/bin/clang++")
 config.std = "c++11"
 config.libcxx_src_root = libcxx_src_dir
 config.libcxx_obj_root = libcxx_src_dir
@@ -31,7 +31,7 @@
 config.configuration_variant = "libcxx.ndk"
 config.target_triple = "%TRIPLE%"
 config.sysroot = os.path.join(ndk, "platforms/android-21/arch-%ARCH%/")
-config.binutils_path = os.path.join(ndk, "binutils/%HOST_TAG%/%TRIPLE%")
+config.binutils_path = os.path.join(ndk, "binutils/%TRIPLE%")
 
 # Let the main config do the real work.
 lit_config.load_config(
diff --git a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.site.cfg b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.site.cfg
index 7d6e99b..0fdc5f6 100644
--- a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.site.cfg
+++ b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.site.cfg
@@ -15,7 +15,7 @@
 libcxx_src_dir = os.path.join(libcxx_dir, 'libcxx')
 
 config.cxx_under_test = os.path.join(
-    ndk, "toolchains/linux-x86_64/llvm-3.6/prebuilt/bin/clang++")
+    ndk, "toolchains/llvm-3.6/prebuilt/bin/clang++")
 config.std = "c++11"
 config.libcxx_src_root = libcxx_src_dir
 config.libcxx_obj_root = libcxx_src_dir
@@ -32,7 +32,7 @@
 config.target_triple = "aarch64-linux-android"
 config.sysroot = os.path.join(ndk, "platforms/android-21/arch-arm64/")
 config.gcc_toolchain = os.path.join(
-    ndk, "toolchains/linux-x86_64/aarch64-linux-android-4.9")
+    ndk, "toolchains/aarch64-linux-android-4.9")
 
 # Let the main config do the real work.
 lit_config.load_config(
diff --git a/tests/build/check-armeabi-v7a-prebuilts/build.sh b/tests/build/check-armeabi-v7a-prebuilts/build.sh
index 0c8d283..6ef5b2c 100755
--- a/tests/build/check-armeabi-v7a-prebuilts/build.sh
+++ b/tests/build/check-armeabi-v7a-prebuilts/build.sh
@@ -242,7 +242,7 @@
       ;;
 esac
 
-ARM_READELF=$NDK/toolchains/$HOST_TAG/$ARM_TOOLCHAIN_NAME/prebuilt/bin/${ARM_TOOLCHAIN_PREFIX}-readelf
+ARM_READELF=$NDK/toolchains/$ARM_TOOLCHAIN_NAME/prebuilt/bin/${ARM_TOOLCHAIN_PREFIX}-readelf
 if [ ! -f "$ARM_READELF" ]; then
     echo "ERROR: Missing binary: $ARM_READELF" >&2
     exit 1
diff --git a/tests/build/warn-noabi/build.sh b/tests/build/warn-noabi/build.sh
index c3474b9..ae917de 100755
--- a/tests/build/warn-noabi/build.sh
+++ b/tests/build/warn-noabi/build.sh
@@ -33,10 +33,7 @@
   NULL="/dev/null"
 fi
 
-ARM_GPP=$NDK/toolchains/$SYSTEM/arm-linux-androideabi-$VERSION/prebuilt/bin/arm-linux-androideabi-g++${HOST_EXE}
-if [ ! -f "$ARM_GPP" ]; then
-    ARM_GPP=$NDK/toolchains/$SYSTEM64/arm-linux-androideabi-$VERSION/prebuilt/bin/arm-linux-androideabi-g++${HOST_EXE}
-fi
+ARM_GPP=$NDK/toolchains/arm-linux-androideabi-$VERSION/prebuilt/bin/arm-linux-androideabi-g++${HOST_EXE}
 if [ ! -f "$ARM_GPP" ]; then
     echo "ERROR: Can't locate compiler $ARM_GPP"
     exit 1