Skip to content

Fix #8920 - m4/1.4.19: Runtime assertion windows pops up on MSVC in Debug mode #8984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparing compiler might be a better condition here, but that's fine as well

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)
Comment on lines +97 to +100
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever! thanks for the workaround @SSE4 !

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 ();