Skip to content

Commit

Permalink
(#8984) Fix #8920 - m4/1.4.19: Runtime assertion windows pops up on M…
Browse files Browse the repository at this point in the history
…SVC in Debug mode

* #8920 - Define HAVE_MSVC_INVALID_PARAMETER_HANDLER

* #8920 - Add a patch to call _CrtSetReportMode early in main

* Wrong macro check

* HELP2MAN=/bin/true?

* - workaround make calling help2man (don't care, as we are not interested in man pages)

Signed-off-by: SSE4 <tomskside@gmail.com>

* - fix MSVC

Signed-off-by: SSE4 <tomskside@gmail.com>

Co-authored-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
jmarrec and SSE4 committed Mar 7, 2022
1 parent 3fcd880 commit b00bb73
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 2 additions & 0 deletions recipes/m4/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ patches:
base_path: "source_subfolder"
- patch_file: "patches/1.4.19-0002-ar-lib.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.4.19-0003-msvc-debug-assertion.patch"
base_path: "source_subfolder"
"1.4.18":
- patch_file: "patches/1.4.18-0001-fflush-adjust-to-glibc-2.28-libio.h-removal.patch"
base_path: "source_subfolder"
Expand Down
21 changes: 15 additions & 6 deletions recipes/m4/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _settings_build(self):

@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"
return self.settings.compiler == "Visual Studio" or self.settings.compiler == "msvc"

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
Expand All @@ -46,7 +46,7 @@ def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=self._settings_build.os == "Windows")
build_canonical_name = None
host_canonical_name = None
if self.settings.compiler == "Visual Studio":
if self._is_msvc:
# The somewhat older configure script of m4 does not understand the canonical names of Visual Studio
build_canonical_name = False
host_canonical_name = False
Expand All @@ -62,14 +62,18 @@ def _configure_autotools(self):
elif self.settings.compiler == "clang":
if tools.Version(self.version) < "1.4.19":
autotools.flags.extend(["-rtlib=compiler-rt", "-Wno-unused-command-line-argument"])
if self.settings.os == 'Windows':
conf_args.extend(["ac_cv_func__set_invalid_parameter_handler=yes"])

autotools.configure(args=conf_args, configure_dir=self._source_subfolder, build=build_canonical_name, host=host_canonical_name)
return autotools

@contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
env = {"PATH": [os.path.abspath(self._source_subfolder)]}
if self._is_msvc:
with tools.vcvars(self.settings):
env = {
env.update({
"AR": "{}/build-aux/ar-lib lib".format(tools.unix_path(self._source_subfolder)),
"CC": "cl -nologo",
"CXX": "cl -nologo",
Expand All @@ -78,17 +82,22 @@ def _build_context(self):
"OBJDUMP": ":",
"RANLIB": ":",
"STRIP": ":",
}
})
with tools.environment_append(env):
yield
else:
yield
with tools.environment_append(env):
yield

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

def build(self):
with tools.chdir(self._source_subfolder):
tools.save("help2man", '#!/usr/bin/env bash\n:')
if os.name == 'posix':
os.chmod("help2man", os.stat("help2man").st_mode | 0o111)
self._patch_sources()
with self._build_context():
autotools = self._configure_autotools()
Expand Down
31 changes: 31 additions & 0 deletions recipes/m4/all/patches/1.4.19-0003-msvc-debug-assertion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/src/m4.c b/src/m4.c
index 2bd57750..ca3ded62 100644
--- a/src/m4.c
+++ b/src/m4.c
@@ -36,6 +36,10 @@
# include "assert.h"
#endif

+#ifdef _WIN32
+# include <crtdbg.h>
+#endif
+
/* TRANSLATORS: This is a non-ASCII name: The first name is (with
Unicode escapes) "Ren\u00e9" or (with HTML entities) "Ren&eacute;". */
#define AUTHORS proper_name_utf8 ("Rene' Seindal", "Ren\xC3\xA9 Seindal")
@@ -423,6 +427,15 @@ main (int argc, char *const *argv)
textdomain (PACKAGE);
atexit (close_stdin);

+#ifdef _WIN32
+ _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+ _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
+#endif
+
include_init ();
debug_init ();

0 comments on commit b00bb73

Please sign in to comment.