Commit 0e65d9c2461c3d583a48630f0c1901439bbb9bad

Authored by Jay Berkenbilt
1 parent 3ea83e99

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
@@ -247,6 +247,14 @@ if(MSVC) @@ -247,6 +247,14 @@ if(MSVC)
247 list(APPEND CMAKE_REQUIRED_LINK_OPTIONS -link setargv.obj) 247 list(APPEND CMAKE_REQUIRED_LINK_OPTIONS -link setargv.obj)
248 list(APPEND WINDOWS_WMAIN_LINK -link wsetargv.obj) 248 list(APPEND WINDOWS_WMAIN_LINK -link wsetargv.obj)
249 endif() 249 endif()
  250 +if(MINGW)
  251 + execute_process(
  252 + COMMAND gcc --print-file-name=CRT_glob.o
  253 + OUTPUT_VARIABLE CRT_GLOB_O
  254 + OUTPUT_STRIP_TRAILING_WHITESPACE
  255 + )
  256 + list(APPEND WINDOWS_WMAIN_LINK ${CRT_GLOB_O})
  257 +endif()
250 258
251 include(GNUInstallDirs) 259 include(GNUInstallDirs)
252 260
job.sums
1 # Generated by generate_auto_job 1 # Generated by generate_auto_job
2 -CMakeLists.txt 47752f33b17fa526d46fc608a25ad6b8c61feba9deb1bd659fddf93e6e08b102 2 +CMakeLists.txt 4aaa3d5df1713d9e3b9c6778101c6af3efa2131a2f4c069095abee269d5eaccc
3 generate_auto_job f64733b79dcee5a0e3e8ccc6976448e8ddf0e8b6529987a66a7d3ab2ebc10a86 3 generate_auto_job f64733b79dcee5a0e3e8ccc6976448e8ddf0e8b6529987a66a7d3ab2ebc10a86
4 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4 4 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
5 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42 5 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
qpdf/test_shell_glob.cc
@@ -7,14 +7,17 @@ realmain(int argc, char* argv[]) @@ -7,14 +7,17 @@ realmain(int argc, char* argv[])
7 // In Windows, shell globbing is handled by the runtime, so 7 // In Windows, shell globbing is handled by the runtime, so
8 // passing '*' as argument results in wildcard expansion. In 8 // passing '*' as argument results in wildcard expansion. In
9 // non-Windows, globbing is done by the shell, so passing '*' 9 // non-Windows, globbing is done by the shell, so passing '*'
10 - // shows up as '*'. In Windows with MSVC, it is necessary to link  
11 - // a certain way for this to work. To test this, we invoke this  
12 - // program with a single quoted argument containing a shell glob  
13 - // expression. In Windows, we expect to see multiple arguments,  
14 - // none of which contain '*'. Otherwise, we expected to see the  
15 - // exact glob string that was passed in. The effectiveness of this  
16 - // test was exercised by manually breaking the link options for  
17 - // msvc and seeing that the test fails under that condition. 10 + // shows up as '*'. In Windows, it is necessary to link a certain
  11 + // way for this to work. To test this, we invoke this program with
  12 + // a single quoted argument containing a shell glob expression. In
  13 + // Windows, we expect to see multiple arguments, none of which
  14 + // contain '*'. Otherwise, we expected to see the exact glob
  15 + // string that was passed in. The effectiveness of this test was
  16 + // exercised by manually breaking the link options for msvc and
  17 + // seeing that the test fails under that condition. Explicit link
  18 + // changes used to be needed only for MSVC, but as of late 2024,
  19 + // they are also neededed for mingw, which was found by CI failure
  20 + // of this test.
18 21
19 bool found_star = false; 22 bool found_star = false;
20 for (int i = 1; i < argc; ++i) { 23 for (int i = 1; i < argc; ++i) {