From 0e65d9c2461c3d583a48630f0c1901439bbb9bad Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 13 Dec 2024 07:52:43 -0500 Subject: [PATCH] Fix shell globbing for mingw Why did this ever work? Hard to say...perhaps a library we linked against was setting `int _dowildcard = -1;` somewhere and no longer is. Apparently linking with CRT_glob.o has been the way to do this for a very long time, and we've just been lucky that it worked all this time. --- CMakeLists.txt | 8 ++++++++ job.sums | 2 +- qpdf/test_shell_glob.cc | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6caba84f..42468ff9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,6 +247,14 @@ if(MSVC) list(APPEND CMAKE_REQUIRED_LINK_OPTIONS -link setargv.obj) list(APPEND WINDOWS_WMAIN_LINK -link wsetargv.obj) endif() +if(MINGW) + execute_process( + COMMAND gcc --print-file-name=CRT_glob.o + OUTPUT_VARIABLE CRT_GLOB_O + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + list(APPEND WINDOWS_WMAIN_LINK ${CRT_GLOB_O}) +endif() include(GNUInstallDirs) diff --git a/job.sums b/job.sums index 0ad8c664..7b151fac 100644 --- a/job.sums +++ b/job.sums @@ -1,5 +1,5 @@ # Generated by generate_auto_job -CMakeLists.txt 47752f33b17fa526d46fc608a25ad6b8c61feba9deb1bd659fddf93e6e08b102 +CMakeLists.txt 4aaa3d5df1713d9e3b9c6778101c6af3efa2131a2f4c069095abee269d5eaccc generate_auto_job f64733b79dcee5a0e3e8ccc6976448e8ddf0e8b6529987a66a7d3ab2ebc10a86 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42 diff --git a/qpdf/test_shell_glob.cc b/qpdf/test_shell_glob.cc index 492e117d..ff73b1bd 100644 --- a/qpdf/test_shell_glob.cc +++ b/qpdf/test_shell_glob.cc @@ -7,14 +7,17 @@ realmain(int argc, char* argv[]) // In Windows, shell globbing is handled by the runtime, so // passing '*' as argument results in wildcard expansion. In // non-Windows, globbing is done by the shell, so passing '*' - // shows up as '*'. In Windows with MSVC, it is necessary to link - // a certain way for this to work. To test this, we invoke this - // program with a single quoted argument containing a shell glob - // expression. In Windows, we expect to see multiple arguments, - // none of which contain '*'. Otherwise, we expected to see the - // exact glob string that was passed in. The effectiveness of this - // test was exercised by manually breaking the link options for - // msvc and seeing that the test fails under that condition. + // shows up as '*'. In Windows, it is necessary to link a certain + // way for this to work. To test this, we invoke this program with + // a single quoted argument containing a shell glob expression. In + // Windows, we expect to see multiple arguments, none of which + // contain '*'. Otherwise, we expected to see the exact glob + // string that was passed in. The effectiveness of this test was + // exercised by manually breaking the link options for msvc and + // seeing that the test fails under that condition. Explicit link + // changes used to be needed only for MSVC, but as of late 2024, + // they are also neededed for mingw, which was found by CI failure + // of this test. bool found_star = false; for (int i = 1; i < argc; ++i) {