Enable long file paths in Windows builds (#3711)
On Windows, jq could not open files whose paths exceed MAX_PATH (260 characters), even with LongPathsEnabled set, because the executable did not declare longPathAware in its application manifest. Embed an application manifest in jq.exe through a resource compiled with windres, detected by configure for native Windows hosts. The manifest keeps the asInvoker and supportedOS entries of the MinGW default manifest it replaces and adds longPathAware. It uses a non-zero resource language so that the linker drops the default manifest. Add a PowerShell test that reads a file through a path longer than MAX_PATH in the Windows CI jobs. Co-authored-by: BaalEvan <baalevan@outlook.com>
This commit is contained in:
1 parent
19752f50a9
commit
22c22bcc30
6 files changed
+100
-1
No files matched your search
@@ -249,6 +249,11 @@ jobs:
|
||||
run: |
|
||||
make check VERBOSE=yes
|
||||
git diff --exit-code
|
||||
- name: Test long Windows paths
|
||||
shell: pwsh
|
||||
run: |
|
||||
Set-ItemProperty -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name LongPathsEnabled -Value 1
|
||||
./tests/long-paths.ps1 -Jq ./jq.exe
|
||||
- name: Upload Test Logs
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@v7
|
||||
|
||||
+10
-1
@@ -135,6 +135,15 @@ bin_PROGRAMS = jq
|
||||
jq_SOURCES = src/main.c
|
||||
jq_LDADD = libjq.la -lm
|
||||
|
||||
if WIN32
|
||||
# Embed src/jq.exe.manifest (longPathAware) into jq.exe
|
||||
src/jq-res.o: $(srcdir)/src/jq.rc $(srcdir)/src/jq.exe.manifest
|
||||
mkdir -p src
|
||||
$(AM_V_GEN) $(WINDRES) -I $(srcdir)/src -i $(srcdir)/src/jq.rc -o $@
|
||||
jq_LDADD += src/jq-res.o
|
||||
CLEANFILES += src/jq-res.o
|
||||
endif
|
||||
|
||||
if ENABLE_ALL_STATIC
|
||||
jq_LDFLAGS = -all-static
|
||||
endif
|
||||
@@ -232,7 +241,7 @@ DOC_FILES = docs/content docs/public docs/templates \
|
||||
EXTRA_DIST = $(DOC_FILES) $(man_MANS) $(TESTS) $(TEST_LOG_COMPILER) \
|
||||
jq.1.prebuilt jq.spec src/lexer.c src/lexer.h src/parser.c \
|
||||
src/parser.h src/version.h src/builtin.jq scripts/version \
|
||||
libjq.pc \
|
||||
libjq.pc src/jq.rc src/jq.exe.manifest tests/long-paths.ps1 \
|
||||
tests/modules/a.jq tests/modules/b/b.jq tests/modules/c/c.jq \
|
||||
tests/modules/c/d.jq tests/modules/data.json \
|
||||
tests/modules/deep1.jq tests/modules/deep2a.jq \
|
||||
|
||||
@@ -50,6 +50,11 @@ AC_CHECK_FUNCS(memmem)
|
||||
AC_CHECK_HEADER("sys/cygwin.h", [have_cygwin=1;])
|
||||
AC_CHECK_HEADER("shlwapi.h",[have_shlwapi=1;])
|
||||
AM_CONDITIONAL([WIN32], [test "x$have_shlwapi" = x1 && test ! "x$have_cygwin" = x1])
|
||||
AS_IF([test "x$have_shlwapi" = x1 && test ! "x$have_cygwin" = x1], [
|
||||
AC_CHECK_TOOL([WINDRES], [windres])
|
||||
AS_IF([test -z "$WINDRES"],
|
||||
[AC_MSG_ERROR([windres is required to embed the jq.exe manifest])])
|
||||
])
|
||||
|
||||
dnl Running tests with Valgrind is slow. It is faster to iterate on
|
||||
dnl code without Valgrind until tests pass, then enable Valgrind and
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows Vista -->
|
||||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
|
||||
<!-- Windows 7 -->
|
||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||
<!-- Windows 8 -->
|
||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||
<!-- Windows 8.1 -->
|
||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||
<!-- Windows 10 and 11 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<!-- Paths longer than MAX_PATH (260) work when the
|
||||
LongPathsEnabled registry value is set (Windows 10 1607+). -->
|
||||
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Windows resources for jq.exe.
|
||||
*
|
||||
* The language must be non-zero: GCC on MinGW also links a default
|
||||
* manifest with language 0, and ld only drops that one in favour of a
|
||||
* manifest with a non-zero language. */
|
||||
LANGUAGE 0x09, 0x01 /* LANG_ENGLISH, SUBLANG_ENGLISH_US */
|
||||
|
||||
/* CREATE_PROCESS_MANIFEST_RESOURCE_ID, RT_MANIFEST */
|
||||
1 24 "jq.exe.manifest"
|
||||
@@ -0,0 +1,40 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string] $Jq
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$jqPath = (Resolve-Path -LiteralPath $Jq).Path
|
||||
$policy = Get-ItemPropertyValue -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name LongPathsEnabled
|
||||
if ($policy -ne 1) {
|
||||
throw 'This test requires LongPathsEnabled=1.'
|
||||
}
|
||||
|
||||
$tempPath = [IO.Path]::GetFullPath([IO.Path]::GetTempPath())
|
||||
$root = Join-Path $tempPath ('jq-long-path-' + [Guid]::NewGuid().ToString('N'))
|
||||
try {
|
||||
$directory = $root
|
||||
foreach ($i in 1..6) {
|
||||
$directory = Join-Path $directory ("segment$i" + ('x' * 50))
|
||||
}
|
||||
[IO.Directory]::CreateDirectory($directory) | Out-Null
|
||||
$inputFile = Join-Path $directory 'input.json'
|
||||
[IO.File]::WriteAllText($inputFile, '{"ok":true}')
|
||||
if ($inputFile.Length -le 260) {
|
||||
throw 'Test input path must exceed MAX_PATH.'
|
||||
}
|
||||
$output = & $jqPath -e -c '.ok' $inputFile
|
||||
if ($LASTEXITCODE -ne 0 -or $output -ne 'true') {
|
||||
throw "jq failed to read a $($inputFile.Length)-character path."
|
||||
}
|
||||
}
|
||||
finally {
|
||||
# Delete only the temporary directory created by this test.
|
||||
$resolvedRoot = [IO.Path]::GetFullPath($root)
|
||||
if ([IO.Path]::GetDirectoryName($resolvedRoot) -ne $tempPath.TrimEnd('\', '/')) {
|
||||
throw 'Unexpected temporary directory location.'
|
||||
}
|
||||
if (Test-Path -LiteralPath $resolvedRoot) {
|
||||
Remove-Item -LiteralPath $resolvedRoot -Recurse -Force
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user