diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea304fe2..b6527146 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Makefile.am b/Makefile.am index e20f646e..6d60a9bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/configure.ac b/configure.ac index f7067a43..304fb9af 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/jq.exe.manifest b/src/jq.exe.manifest new file mode 100644 index 00000000..6c8c9029 --- /dev/null +++ b/src/jq.exe.manifest @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + diff --git a/src/jq.rc b/src/jq.rc new file mode 100644 index 00000000..f6ba5ba4 --- /dev/null +++ b/src/jq.rc @@ -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" diff --git a/tests/long-paths.ps1 b/tests/long-paths.ps1 new file mode 100644 index 00000000..b4005e9f --- /dev/null +++ b/tests/long-paths.ps1 @@ -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 + } +}