From 01879b59e104251aa9aee9332acdccac3d71bda9 Mon Sep 17 00:00:00 2001
From: Mike Hommey <mh+mozilla@glandium.org>
Date: Fri, 28 Feb 2020 12:33:03 +0000
Subject: [PATCH] Bug 1618766 - Properly find and use MT on Windows
 cross-builds. r=froydnj

- Remove the separate option() for MT, because it dates back from when
  we needed `MT` not being an absolute path, but that hasn't been true
  since bug 1290040.

- Extend what was done in bug 1617794 to MT, although the long term move
  is to not rely on MT at all.

- Patch leftovers from bug 1613799.

Differential Revision: https://phabricator.services.mozilla.com/D64712

--HG--
extra : moz-landing-system : lando
---
 build/moz.configure/windows.configure | 22 ++++++++++------------
 config/rules.mk                       | 12 ++++++------
 moz.configure                         | 12 +++++++-----
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/build/moz.configure/windows.configure b/build/moz.configure/windows.configure
index abd1e9682631a..5eb5fc36cfe65 100644
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -433,13 +433,6 @@ set_config('HOST_LINKER_LIBPATHS', host_linker_libpaths)
 set_config('HOST_LINKER_LIBPATHS_BAT', host_linker_libpaths_bat)
 
 
-# The when is technically wrong and should be removed and the code that
-# @depends on the option will need to be adapted when actual support for
-# clang-cl cross-builds emerge.
-option(env='MT', nargs=1, help='Path to the Microsoft Manifest Tool',
-       when=host_is_windows)
-
-
 @depends(valid_windows_sdk_dir, valid_ucrt_sdk_dir, host)
 @imports(_from='os', _import='environ')
 def sdk_bin_path(valid_windows_sdk_dir, valid_ucrt_sdk_dir, host):
@@ -464,16 +457,21 @@ def sdk_bin_path(valid_windows_sdk_dir, valid_ucrt_sdk_dir, host):
     return result
 
 
-mt = check_prog('MT', ('mt.exe',), input='MT',
-                paths=sdk_bin_path, when=host_is_windows)
+# allow_missing=True for mingw builds, until bug 1617793
+mt = check_prog('MT', ('mt.exe',), allow_missing=True, paths=sdk_bin_path)
 
 
 # Check that MT is not something unexpected like "magnetic tape manipulation
 # utility".
-@depends_if(mt)
+@depends(mt, wine)
 @checking('whether MT is really Microsoft Manifest Tool', lambda x: bool(x))
-def valid_mt(path):
-    out = check_cmd_output(path, onerror=lambda: '').splitlines()
+def valid_mt(path, wine):
+    if not path:
+        return None
+    if wine and path.lower().endswith('.exe'):
+        out = check_cmd_output(wine, path, onerror=lambda: '').splitlines()
+    else:
+        out = check_cmd_output(path, onerror=lambda: '').splitlines()
     out = '\n'.join(l for l in out
                     if 'Microsoft (R) Manifest Tool' in l)
     if out:
diff --git a/config/rules.mk b/config/rules.mk
index c21e614cb65ac..2345df2ad8f9c 100644
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -469,7 +469,7 @@ ifdef MSMANIFEST_TOOL
 		exit 1; \
 	elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
 		echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest'; \
-		$(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
+		$(call WINEWRAP,$(MT)) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
 	fi
 endif	# MSVC with manifest tool
 else # !WINNT || GNU_CC
@@ -494,7 +494,7 @@ ifdef MSMANIFEST_TOOL
 		exit 1; \
 	elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
 		echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest'; \
-		$(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
+		$(call WINEWRAP,$(MT)) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
 	fi
 endif	# MSVC with manifest tool
 else
@@ -522,10 +522,10 @@ ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
 	$(LINKER) -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
 ifdef MSMANIFEST_TOOL
 	@if test -f $@.manifest; then \
-		$(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
-		rm -f $@.manifest; \
+		echo "Manifest in objdir is not supported"; \
+		exit 1; \
 	elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
-		$(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
+		$(call WINEWRAP,$(MT)) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
 	fi
 endif	# MSVC with manifest tool
 else
@@ -620,7 +620,7 @@ ifdef EMBED_MANIFEST_AT
 		exit 1; \
 	elif test -f '$(srcdir)/$@.manifest'; then \
 		echo 'Embedding manifest from $(srcdir_rel)/$@.manifest'; \
-		$(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$@.manifest' -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
+		$(call WINEWRAP,$(MT)) -NOLOGO -MANIFEST '$(srcdir_rel)/$@.manifest' -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
 	fi
 endif   # EMBED_MANIFEST_AT
 endif	# MSVC with manifest tool
diff --git a/moz.configure b/moz.configure
index 71c7d457c2991..ac45ced0d4506 100755
--- a/moz.configure
+++ b/moz.configure
@@ -133,6 +133,13 @@ js_option(env='MOZ_PGO', help='Build with profile guided optimizations')
 
 set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
 
+
+wine = check_prog(
+    'WINE', ['wine'], allow_missing=True,
+    when=depends(target, host, compile_environment)(
+        lambda t, h, c: c and t.kernel == 'WINNT' and h.kernel == 'Linux'))
+
+
 include('build/moz.configure/toolchain.configure',
         when='--enable-compile-environment')
 
@@ -536,11 +543,6 @@ check_prog('HFS_TOOL', extra_programs.HFS_TOOL,
 check_prog('RPMBUILD', extra_programs.RPMBUILD,
            allow_missing=True)
 
-wine = check_prog(
-    'WINE', ['wine'], allow_missing=True,
-    when=depends(target, host, compile_environment)(
-        lambda t, h, c: c and t.kernel == 'WINNT' and h.kernel == 'Linux'))
-
 
 @depends(target)
 @imports('os')
-- 
GitLab