From 145ae32069d830d9318b61a996633126141c25a7 Mon Sep 17 00:00:00 2001
From: Dan Willemsen <dwillemsen@google.com>
Date: Thu, 13 Aug 2015 14:31:36 -0700
Subject: [PATCH] Remove legacy windows platform build support

We still support HOST_OS=windows for the SDK host tools cross-builds, but
that's only when USE_MINGW is set when running under linux.

Change-Id: I37da87dc9fbbd69ba10ce4d7f2668ab3f6482d92
---
 core/combo/HOST_windows-x86.mk    | 32 ++-----------------
 core/combo/HOST_windows-x86_64.mk | 32 +++----------------
 core/combo/javac.mk               |  7 +----
 core/config.mk                    |  5 ---
 core/definitions.mk               |  7 +----
 core/envsetup.mk                  |  3 --
 core/main.mk                      | 10 ------
 libs/host/Android.mk              |  3 --
 libs/host/CopyFile.c              | 51 -------------------------------
 tools/acp/Android.mk              |  3 --
 10 files changed, 8 insertions(+), 145 deletions(-)

diff --git a/core/combo/HOST_windows-x86.mk b/core/combo/HOST_windows-x86.mk
index 5839e734b..eb1c49c13 100644
--- a/core/combo/HOST_windows-x86.mk
+++ b/core/combo/HOST_windows-x86.mk
@@ -14,19 +14,10 @@
 # limitations under the License.
 #
 
-# Configuration for Linux on x86.
+# Settings to use MinGW as a cross-compiler under Linux
 # Included by combo/select.make
 
-# right now we get these from the environment, but we should
-# pick them from the tree somewhere
-TOOLS_PREFIX := #prebuilt/windows/host/bin/
-TOOLS_EXE_SUFFIX := .exe
-
-# Settings to use MinGW has a cross-compiler under Linux
-ifneq ($(findstring Linux,$(UNAME)),)
-ifdef USE_MINGW
 HOST_ACP_UNAVAILABLE := true
-TOOLS_EXE_SUFFIX :=
 $(combo_2nd_arch_prefix)HOST_GLOBAL_CFLAGS += -DUSE_MINGW -DWIN32_LEAN_AND_MEAN
 $(combo_2nd_arch_prefix)HOST_GLOBAL_CFLAGS += -Wno-unused-parameter
 $(combo_2nd_arch_prefix)HOST_GLOBAL_CFLAGS += --sysroot=prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32
@@ -36,8 +27,6 @@ TOOLS_PREFIX := prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/bin/x86_64-w
 $(combo_2nd_arch_prefix)HOST_C_INCLUDES += prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/include
 $(combo_2nd_arch_prefix)HOST_C_INCLUDES += prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/lib/gcc/x86_64-w64-mingw32/4.8.3/include
 $(combo_2nd_arch_prefix)HOST_GLOBAL_LD_DIRS += -Lprebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/lib32
-endif # USE_MINGW
-endif # Linux
 
 # Workaround differences in inttypes.h between host and target.
 # See bug 12708004.
@@ -59,22 +48,6 @@ ifneq ($(strip $(BUILD_HOST_static)),)
 $(combo_2nd_arch_prefix)HOST_GLOBAL_LDFLAGS += -static
 endif # BUILD_HOST_static
 
-# when building under Cygwin, ensure that we use Mingw compilation by default.
-# you can disable this (i.e. to generate Cygwin executables) by defining the
-# USE_CYGWIN variable in your environment, e.g.:
-#
-#   export USE_CYGWIN=1
-#
-# note that the -mno-cygwin flags are not needed when cross-compiling the
-# Windows host tools on Linux
-#
-ifneq ($(findstring CYGWIN,$(UNAME)),)
-ifeq ($(strip $(USE_CYGWIN)),)
-$(combo_2nd_arch_prefix)HOST_GLOBAL_CFLAGS += -mno-cygwin
-$(combo_2nd_arch_prefix)HOST_GLOBAL_LDFLAGS += -mno-cygwin -mconsole
-endif
-endif
-
 ############################################################
 ## Macros after this line are shared by the 64-bit config.
 
@@ -82,7 +55,6 @@ HOST_SHLIB_SUFFIX := .dll
 HOST_EXECUTABLE_SUFFIX := .exe
 
 # $(1): The file to check
-# TODO: find out what format cygwin's stat(1) uses
 define get-file-size
-999999999
+stat --format "%s" "$(1)" | tr -d '\n'
 endef
diff --git a/core/combo/HOST_windows-x86_64.mk b/core/combo/HOST_windows-x86_64.mk
index c526f205f..b38c74c51 100644
--- a/core/combo/HOST_windows-x86_64.mk
+++ b/core/combo/HOST_windows-x86_64.mk
@@ -14,25 +14,17 @@
 # limitations under the License.
 #
 
-# Configuration for Windows on x86_64.
+# Settings to use MinGW as a cross-compiler under Linux
 # Included by combo/select.make
 
 # right now we get these from the environment, but we should
 # pick them from the tree somewhere
-TOOLS_PREFIX := #prebuilt/windows/host/bin/
-TOOLS_EXE_SUFFIX := .exe
-
-# Settings to use MinGW has a cross-compiler under Linux
-ifneq ($(findstring Linux,$(UNAME)),)
-ifdef USE_MINGW
-HOST_ACP_UNAVAILABLE := true
-TOOLS_EXE_SUFFIX :=
-HOST_GLOBAL_CFLAGS += -DUSE_MINGW
 TOOLS_PREFIX := /usr/bin/amd64-mingw32msvc-
+
+HOST_ACP_UNAVAILABLE := true
+HOST_GLOBAL_CFLAGS += -DUSE_MINGW
 HOST_C_INCLUDES += /usr/lib/gcc/amd64-mingw32msvc/4.4.2/include
 HOST_GLOBAL_LD_DIRS += -L/usr/amd64-mingw32msvc/lib
-endif # USE_MINGW
-endif # Linux
 
 # Workaround differences in inttypes.h between host and target.
 # See bug 12708004.
@@ -50,19 +42,3 @@ ifneq ($(strip $(BUILD_HOST_static)),)
 # Statically-linked binaries are desirable for sandboxed environment
 HOST_GLOBAL_LDFLAGS += -static
 endif # BUILD_HOST_static
-
-# when building under Cygwin, ensure that we use Mingw compilation by default.
-# you can disable this (i.e. to generate Cygwin executables) by defining the
-# USE_CYGWIN variable in your environment, e.g.:
-#
-#   export USE_CYGWIN=1
-#
-# note that the -mno-cygwin flags are not needed when cross-compiling the
-# Windows host tools on Linux
-#
-ifneq ($(findstring CYGWIN,$(UNAME)),)
-ifeq ($(strip $(USE_CYGWIN)),)
-HOST_GLOBAL_CFLAGS += -mno-cygwin
-HOST_GLOBAL_LDFLAGS += -mno-cygwin -mconsole
-endif
-endif
diff --git a/core/combo/javac.mk b/core/combo/javac.mk
index fb43ea44e..e3838a6db 100644
--- a/core/combo/javac.mk
+++ b/core/combo/javac.mk
@@ -26,12 +26,7 @@ ifdef JAVAC_WRAPPER
 endif
 
 # Whatever compiler is on this system.
-ifeq ($(BUILD_OS), windows)
-    COMMON_JAVAC := development/host/windows/prebuilt/javawrap.exe -J-Xmx256m \
-        $(common_jdk_flags)
-else
-    COMMON_JAVAC := $(JAVACC) -J-Xmx1024M $(common_jdk_flags)
-endif
+COMMON_JAVAC := $(JAVACC) -J-Xmx1024M $(common_jdk_flags)
 
 # Eclipse.
 ifeq ($(CUSTOM_JAVA_COMPILER), eclipse)
diff --git a/core/config.mk b/core/config.mk
index 498c79313..fb45e5145 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -493,12 +493,7 @@ ANDROID_MANIFEST_MERGER := java -classpath prebuilts/devtools/tools/lib/manifest
 
 YACC_HEADER_SUFFIX:= .hpp
 
-# Don't use column under Windows, cygwin or not
-ifeq ($(HOST_OS),windows)
-COLUMN:= cat
-else
 COLUMN:= column
-endif
 
 HOST_JDK_TOOLS_JAR:= $(shell $(BUILD_SYSTEM)/find-jdk-tools-jar.sh)
 
diff --git a/core/definitions.mk b/core/definitions.mk
index 35e3a7933..0f5aed321 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1645,11 +1645,7 @@ $(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
     $(addprefix --rename-instrumentation-target-package , $(PRIVATE_MANIFEST_INSTRUMENTATION_FOR))
 endef
 
-ifeq ($(HOST_OS),windows)
-xlint_unchecked :=
-else
 xlint_unchecked := -Xlint:unchecked
-endif
 
 ifeq (true, $(ENABLE_INCREMENTALJAVAC))
 incremental_dex := --incremental
@@ -1988,13 +1984,12 @@ endef
 
 #TODO: use a smaller -Xmx value for most libraries;
 #      only core.jar and framework.jar need a heap this big.
-# Avoid the memory arguments on Windows, dx fails to load for some reason with them.
 define transform-classes.jar-to-dex
 @echo "target Dex: $(PRIVATE_MODULE)"
 @mkdir -p $(dir $@)
 $(hide) rm -f $(dir $@)classes*.dex
 $(hide) $(DX) \
-    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
+    -JXms16M -JXmx2048M \
     --dex --output=$(dir $@) \
     $(incremental_dex) \
     $(if $(NO_OPTIMIZE_DX), \
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 0b681524b..c76e9a6b3 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -48,9 +48,6 @@ endif
 ifneq (,$(findstring Macintosh,$(UNAME)))
   HOST_OS := darwin
 endif
-ifneq (,$(findstring CYGWIN,$(UNAME)))
-  HOST_OS := windows
-endif
 
 # BUILD_OS is the real host doing the build.
 BUILD_OS := $(HOST_OS)
diff --git a/core/main.mk b/core/main.mk
index b290ce1a9..1d88c8eb4 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -38,8 +38,6 @@ endif
 #endif
 
 # Check for broken versions of make.
-# (Allow any version under Cygwin since we don't actually build the platform there.)
-ifeq (,$(findstring CYGWIN,$(shell uname -sm)))
 ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81)))
 $(warning ********************************************************************************)
 $(warning *  You are using version $(MAKE_VERSION) of make.)
@@ -48,7 +46,6 @@ $(warning *  see https://source.android.com/source/download.html)
 $(warning ********************************************************************************)
 $(error stopping)
 endif
-endif
 
 # Absolute path of the present working direcotry.
 # This overrides the shell variable $PWD, which does not necessarily points to
@@ -123,7 +120,6 @@ ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
 
 $(info Checking build tools versions...)
 
-ifneq ($(HOST_OS),windows)
 # check for a case sensitive file system
 ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
                 echo a > $(OUT_DIR)/casecheck.txt; \
@@ -135,7 +131,6 @@ $(warning Please move your source tree to a case-sensitive filesystem.)
 $(warning ************************************************************)
 $(error Case-insensitive filesystems not supported)
 endif
-endif
 
 # Make sure that there are no spaces in the absolute path; the
 # build system can't deal with them.
@@ -471,11 +466,6 @@ ifeq ($(SDK_ONLY),true)
 include $(TOPDIR)sdk/build/windows_sdk_whitelist.mk
 include $(TOPDIR)development/build/windows_sdk_whitelist.mk
 
-# Exclude tools/acp when cross-compiling windows under linux
-ifeq ($(findstring Linux,$(UNAME)),)
-subdirs += build/tools/acp
-endif
-
 else	# !SDK_ONLY
 #
 # Typical build; include any Android.mk files we can find.
diff --git a/libs/host/Android.mk b/libs/host/Android.mk
index d1d2e55c6..821f9b877 100644
--- a/libs/host/Android.mk
+++ b/libs/host/Android.mk
@@ -5,9 +5,6 @@ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_SRC_FILES:= \
     CopyFile.c
 
-ifeq ($(HOST_OS),cygwin)
-LOCAL_CFLAGS += -DWIN32_EXE
-endif
 ifeq ($(HOST_OS),darwin)
 LOCAL_CFLAGS += -DMACOSX_RSRC
 endif
diff --git a/libs/host/CopyFile.c b/libs/host/CopyFile.c
index 855a56534..c686144d5 100644
--- a/libs/host/CopyFile.c
+++ b/libs/host/CopyFile.c
@@ -546,57 +546,6 @@ static int copyFileRecursive(const char* src, const char* dst, bool isCmdLine, u
         statResult = stat(src, &srcStat);
     statErrno = errno;        /* preserve across .exe attempt */
 
-#ifdef WIN32_EXE
-    /*
-     * Here's the interesting part.  Under Cygwin, if you have a file
-     * called "foo.exe", stat("foo", ...) will succeed, but open("foo", ...)
-     * will fail.  We need to figure out what its name is supposed to be
-     * so we can create the correct destination file.
-     *
-     * If we don't have the "-e" flag set, we want "acp foo bar" to fail,
-     * not automatically find "foo.exe".  That way, if we really were
-     * trying to copy "foo", it doesn't grab something we don't want.
-     */
-    if (isCmdLine && statResult == 0) {
-        int tmpFd;
-        tmpFd = open(src, O_RDONLY | O_BINARY, 0);
-        if (tmpFd < 0) {
-            statResult = -1;
-            statErrno = ENOENT;
-        } else {
-            (void) close(tmpFd);
-        }
-    }
-
-    /*
-     * If we didn't find the file, try it again with ".exe".
-     */
-    if (isCmdLine && statResult < 0 && statErrno == ENOENT && (options & COPY_TRY_EXE)) {
-        srcExe = malloc(strlen(src) + 4 +1);
-        strcpy(srcExe, src);
-        strcat(srcExe, ".exe");
-
-        if (options & COPY_NO_DEREFERENCE)
-            statResult = lstat(srcExe, &srcStat);
-        else
-            statResult = stat(srcExe, &srcStat);
-
-        if (statResult == 0 && !S_ISREG(srcStat.st_mode))
-            statResult = -1;        /* fail, use original statErrno below */
-
-        if (statResult == 0) {
-            /* found a .exe, copy that instead */
-            dstExe = malloc(strlen(dst) + 4 +1);
-            strcpy(dstExe, dst);
-            strcat(dstExe, ".exe");
-
-            src = srcExe;
-            dst = dstExe;
-        } else {
-            DBUG(("---  couldn't find '%s' either\n", srcExe));
-        }
-    }
-#endif
     if (statResult < 0) {
         if (statErrno == ENOENT)
             fprintf(stderr, "acp: file '%s' does not exist\n", src);
diff --git a/tools/acp/Android.mk b/tools/acp/Android.mk
index fbdb7970e..e31ad3afb 100644
--- a/tools/acp/Android.mk
+++ b/tools/acp/Android.mk
@@ -9,9 +9,6 @@ LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_SRC_FILES := \
     acp.c
 
-ifeq ($(HOST_OS),cygwin)
-LOCAL_CFLAGS += -DWIN32_EXE
-endif
 ifeq ($(HOST_OS),darwin)
 LOCAL_CFLAGS += -DMACOSX_RSRC
 endif