Commit 07da0039d3f496871d746305fbbf76ee9bde9862

Authored by Jay Berkenbilt
1 parent a58918bb

Link with setargv or wsetargv with MSVC (fixes #224)

For wildcard expansion to work properly with the msvc binary, it is
necessary to link with setargv.obj or wsetargv.obj, depending on
whether wmain is in use.
ChangeLog
1 2019-11-09 Jay Berkenbilt <ejb@ql.org> 1 2019-11-09 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Improve behavior of wildcard expansion for msvc executable when
  4 + run from the Windows cmd.exe shell. The behavior is not identical
  5 + to UNIX or to running the mingw executable in that, for msvc,
  6 + wildcard expansion is performed transparently by qpdf.exe itself.
  7 + That means that *.pdf and "*.pdf*" are interpreted identically. If
  8 + you need to specify the name of a file that has a * or ? in its
  9 + actual filename on the Windows CLI with the msvc-built executable,
  10 + you can write the name of the file in another file and use the
  11 + @file syntax to prevent expansion. Fixes #224.
  12 +
3 * When reading /P from the encryption dictionary, use static_cast 13 * When reading /P from the encryption dictionary, use static_cast
4 instead of QIntC to convert the value to a signed integer. The 14 instead of QIntC to convert the value to a signed integer. The
5 value of /P is a bit field, and PDF files have been found in the 15 value of /P is a bit field, and PDF files have been found in the
@@ -132,6 +132,33 @@ Page splitting/merging @@ -132,6 +132,33 @@ Page splitting/merging
132 132
133 * Form fields: should be similar to outlines. 133 * Form fields: should be similar to outlines.
134 134
  135 +MSVC Wildcard Expansion
  136 +=======================
  137 +
  138 +(This section is referenced in azure_pipelines.yml.)
  139 +
  140 +The qpdf executable built with msvc is linked with setargv.obj or
  141 +wsetargv.obj so that wildcard expansion works. It doesn't work exactly
  142 +the way a UNIX system would work in that the program itself does the
  143 +expansion (rather than the shell), which means that invoking qpdf.exe
  144 +as built by msvc will expand "*.pdf" just as it will expand *.pdf. In
  145 +some earlier versions, wildcard expansion didn't work with the msvc
  146 +executable. The way to make this work appears to be different in some
  147 +versions of MSVC than in others. As such, if upgrading MSVC or
  148 +changing the build environment, the wildcard expansion behavior of the
  149 +qpdf executable in Windows should be retested manually.
  150 +
  151 +Unfortunately, there is no automated test for wildcard expansion with
  152 +MSVC because I can't figure out how to prevent qtest from expanding
  153 +the wildcards before passing them in, and explicitly running "cmd /c
  154 +..." from qtest doesn't seem to work in Azure Pipelines, though I can
  155 +make it work locally.
  156 +
  157 +Ideally, we should figure out a way to test this in CI by having a
  158 +test that fails if wildcard expansion is broken. In the absence of
  159 +this, it will be necessary to test the behavior manually in both mingw
  160 +and msvc when run from cmd and from msys bash.
  161 +
135 General 162 General
136 ======= 163 =======
137 164
autoconf.mk.in
@@ -47,6 +47,8 @@ IS_32BIT=@IS_32BIT@ @@ -47,6 +47,8 @@ IS_32BIT=@IS_32BIT@
47 WINDOWS_WORDSIZE=@WINDOWS_WORDSIZE@ 47 WINDOWS_WORDSIZE=@WINDOWS_WORDSIZE@
48 WINDOWS_WMAIN_COMPILE=@WINDOWS_WMAIN_COMPILE@ 48 WINDOWS_WMAIN_COMPILE=@WINDOWS_WMAIN_COMPILE@
49 WINDOWS_WMAIN_LINK=@WINDOWS_WMAIN_LINK@ 49 WINDOWS_WMAIN_LINK=@WINDOWS_WMAIN_LINK@
  50 +WINDOWS_WMAIN_XLINK_FLAGS=@WINDOWS_WMAIN_XLINK_FLAGS@
  51 +WINDOWS_MAIN_XLINK_FLAGS=@WINDOWS_MAIN_XLINK_FLAGS@
50 SHOW_FAILED_TEST_OUTPUT=@SHOW_FAILED_TEST_OUTPUT@ 52 SHOW_FAILED_TEST_OUTPUT=@SHOW_FAILED_TEST_OUTPUT@
51 # Allow environment variable to override 53 # Allow environment variable to override
52 QPDF_LARGE_FILE_TEST_PATH?=@QPDF_LARGE_FILE_TEST_PATH@ 54 QPDF_LARGE_FILE_TEST_PATH?=@QPDF_LARGE_FILE_TEST_PATH@
autofiles.sums
1 -97f3ed3cd8b491f0ceeb57baa40f4ed9c4be188692da1d13c93ef318c45cc4ae configure.ac 1 +50057c548d9af98d7b070a8a7716352a777b1f52e7ba44719f94ede65fc27cee configure.ac
2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4 2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4
3 2e4cd495837be1b8454a4d8aef541b000988634be89d9c05a9cf5de67dffef5e libqpdf/qpdf/qpdf-config.h.in 3 2e4cd495837be1b8454a4d8aef541b000988634be89d9c05a9cf5de67dffef5e libqpdf/qpdf/qpdf-config.h.in
4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4 4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4
azure-pipelines.yml
@@ -23,6 +23,7 @@ jobs: @@ -23,6 +23,7 @@ jobs:
23 buildPlatform: Linux 23 buildPlatform: Linux
24 - job: Windows 24 - job: Windows
25 pool: 25 pool:
  26 + # If updating this, see note in TODO about MSVC wildcard expansion.
26 vmImage: windows-2019 27 vmImage: windows-2019
27 strategy: 28 strategy:
28 matrix: 29 matrix:
configure
@@ -647,6 +647,8 @@ USE_CRYPTO_GNUTLS @@ -647,6 +647,8 @@ USE_CRYPTO_GNUTLS
647 pc_gnutls_LIBS 647 pc_gnutls_LIBS
648 pc_gnutls_CFLAGS 648 pc_gnutls_CFLAGS
649 USE_CRYPTO_NATIVE 649 USE_CRYPTO_NATIVE
  650 +WINDOWS_MAIN_XLINK_FLAGS
  651 +WINDOWS_WMAIN_XLINK_FLAGS
650 CXXWFLAGS 652 CXXWFLAGS
651 WFLAGS 653 WFLAGS
652 BUILDRULES 654 BUILDRULES
@@ -17595,6 +17597,13 @@ fi @@ -17595,6 +17597,13 @@ fi
17595 17597
17596 17598
17597 17599
  17600 +if test "$BUILDRULES" = "msvc"; then
  17601 + WINDOWS_WMAIN_XLINK_FLAGS="-link wsetargv.obj"
  17602 + WINDOWS_MAIN_XLINK_FLAGS="-link setargv.obj"
  17603 +fi
  17604 +
  17605 +
  17606 +
17598 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for whether to use implicit crypto" >&5 17607 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for whether to use implicit crypto" >&5
17599 $as_echo_n "checking for whether to use implicit crypto... " >&6; } 17608 $as_echo_n "checking for whether to use implicit crypto... " >&6; }
17600 # Check whether --enable-implicit-crypto was given. 17609 # Check whether --enable-implicit-crypto was given.
configure.ac
@@ -465,6 +465,13 @@ else @@ -465,6 +465,13 @@ else
465 AC_MSG_RESULT(no) 465 AC_MSG_RESULT(no)
466 fi 466 fi
467 467
  468 +AC_SUBST(WINDOWS_WMAIN_XLINK_FLAGS)
  469 +AC_SUBST(WINDOWS_MAIN_XLINK_FLAGS)
  470 +if test "$BUILDRULES" = "msvc"; then
  471 + WINDOWS_WMAIN_XLINK_FLAGS="-link wsetargv.obj"
  472 + WINDOWS_MAIN_XLINK_FLAGS="-link setargv.obj"
  473 +fi
  474 +
468 dnl BEGIN CRYPTO 475 dnl BEGIN CRYPTO
469 476
470 dnl By default, we build in support for every crypto provider that we 477 dnl By default, we build in support for every crypto provider that we
make/libtool.mk
@@ -98,10 +98,10 @@ define makelib @@ -98,10 +98,10 @@ define makelib
98 -rpath $(libdir) -version-info $(5):$(6):$(7) -no-undefined 98 -rpath $(libdir) -version-info $(5):$(6):$(7) -no-undefined
99 endef 99 endef
100 100
101 -# 1 2 3 4  
102 -# Usage: $(call makebin,objs,binary,ldflags,libs) 101 +# 1 2 3 4 5
  102 +# Usage: $(call makebin,objs,binary,ldflags,libs,xlinkflags)
103 define makebin 103 define makebin
104 - $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(1) -o $(2) $(3) $(4) 104 + $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(5) $(1) -o $(2) $(3) $(4)
105 endef 105 endef
106 106
107 # Install target 107 # Install target
make/mingw.mk
@@ -67,10 +67,10 @@ define makelib @@ -67,10 +67,10 @@ define makelib
67 $(1) $(3) $(4) 67 $(1) $(3) $(4)
68 endef 68 endef
69 69
70 -# 1 2 3 4  
71 -# Usage: $(call makebin,objs,binary,ldflags,libs) 70 +# 1 2 3 4 5
  71 +# Usage: $(call makebin,objs,binary,ldflags,libs,xlinkflags)
72 define makebin 72 define makebin
73 - $(CXX) $(CXXFLAGS) $(1) -o $(2) $(3) $(4) 73 + $(CXX) $(CXXFLAGS) $(5) $(1) -o $(2) $(3) $(4)
74 endef 74 endef
75 75
76 # Install target 76 # Install target
make/msvc.mk
@@ -76,10 +76,11 @@ define makelib @@ -76,10 +76,11 @@ define makelib
76 mv $(basename $(2))$(shell expr $(5) - $(7)).lib $(2) 76 mv $(basename $(2))$(shell expr $(5) - $(7)).lib $(2)
77 endef 77 endef
78 78
79 -# 1 2 3 4  
80 -# Usage: $(call makebin,objs,binary,ldflags,libs) 79 +# 1 2 3 4 5
  80 +# Usage: $(call makebin,objs,binary,ldflags,libs,xlinkflags)
81 define makebin 81 define makebin
82 cl -nologo -O2 -Zi -Gy -EHsc -MD $(1) \ 82 cl -nologo -O2 -Zi -Gy -EHsc -MD $(1) \
  83 + $(if $(5),$(5),$(WINDOWS_MAIN_XLINK_FLAGS)) \
83 -link -SUBSYSTEM:CONSOLE,5.01 -incremental:no -OUT:$(2) \ 84 -link -SUBSYSTEM:CONSOLE,5.01 -incremental:no -OUT:$(2) \
84 $(foreach L,$(subst -L,,$(3)),-LIBPATH:$(L)) \ 85 $(foreach L,$(subst -L,,$(3)),-LIBPATH:$(L)) \
85 $(foreach L,$(subst -l,,$(4)),$(L).lib) 86 $(foreach L,$(subst -l,,$(4)),$(L).lib)
manual/qpdf-manual.xml
@@ -4685,6 +4685,13 @@ print &quot;\n&quot;; @@ -4685,6 +4685,13 @@ print &quot;\n&quot;;
4685 or odd pages from among the pages specified in the range. 4685 or odd pages from among the pages specified in the range.
4686 </para> 4686 </para>
4687 </listitem> 4687 </listitem>
  4688 + <listitem>
  4689 + <para>
  4690 + Improve shell wildcard expansion behavior
  4691 + (<literal>*</literal> and <literal>?</literal>) of the
  4692 + <command>qpdf.exe</command> as built my MSVC.
  4693 + </para>
  4694 + </listitem>
4688 </itemizedlist> 4695 </itemizedlist>
4689 </listitem> 4696 </listitem>
4690 </itemizedlist> 4697 </itemizedlist>
qpdf/build.mk
@@ -26,6 +26,8 @@ XCXXFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_COMPILE) @@ -26,6 +26,8 @@ XCXXFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_COMPILE)
26 XLDFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_LINK) 26 XLDFLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_LINK)
27 XCXXFLAGS_qpdf_test_unicode_filenames := $(WINDOWS_WMAIN_COMPILE) 27 XCXXFLAGS_qpdf_test_unicode_filenames := $(WINDOWS_WMAIN_COMPILE)
28 XLDFLAGS_qpdf_test_unicode_filenames := $(WINDOWS_WMAIN_LINK) 28 XLDFLAGS_qpdf_test_unicode_filenames := $(WINDOWS_WMAIN_LINK)
  29 +XLINK_FLAGS_qpdf_qpdf := $(WINDOWS_WMAIN_XLINK_FLAGS)
  30 +XLINK_FLAGS_qpdf_test_unicode_filenames := $(WINDOWS_WMAIN_XLINK_FLAGS)
29 31
30 $(foreach B,$(BINS_qpdf),$(eval \ 32 $(foreach B,$(BINS_qpdf),$(eval \
31 OBJS_$(B) = $(call src_to_obj,qpdf/$(B).cc))) 33 OBJS_$(B) = $(call src_to_obj,qpdf/$(B).cc)))
@@ -46,4 +48,4 @@ $(foreach B,$(CBINS_qpdf),$(eval \ @@ -46,4 +48,4 @@ $(foreach B,$(CBINS_qpdf),$(eval \
46 48
47 $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \ 49 $(foreach B,$(BINS_qpdf) $(CBINS_qpdf),$(eval \
48 qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \ 50 qpdf/$(OUTPUT_DIR)/$(call binname,$(B)): $(OBJS_$(B)) ; \
49 - $(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS) $(XLDFLAGS_qpdf_$(B)),$(LIBS_libqpdf) $(LIBS)))) 51 + $(call makebin,$(OBJS_$(B)),$$@,$(LDFLAGS_libqpdf) $(LDFLAGS) $(XLDFLAGS_qpdf_$(B)),$(LIBS_libqpdf) $(LIBS),$(XLINK_FLAGS_qpdf_$(B)))))