From a2f17434edc1ef61547ca54396598c7f9c3ff12a Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Tue, 30 Nov 2021 21:25:37 +0000 Subject: [PATCH 1/4] Fix typo --- Cabal/src/Distribution/Compat/Process.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cabal/src/Distribution/Compat/Process.hs b/Cabal/src/Distribution/Compat/Process.hs index 7d02ba9fe59..0c2e5fb0d05 100644 --- a/Cabal/src/Distribution/Compat/Process.hs +++ b/Cabal/src/Distribution/Compat/Process.hs @@ -27,7 +27,7 @@ import System.Process (waitForProcess) -- -- Unfortunately the process job support is badly broken in @process@ releases -- prior to 1.6.9, so we disable it in these versions, despite the fact that --- this means we may see sporatic build failures without jobs. +-- this means we may see sporadic build failures without jobs. enableProcessJobs :: CreateProcess -> CreateProcess #ifdef MIN_VERSION_process #if MIN_VERSION_process(1,6,9) From ccf4ea8760743b263b0e9c0beca41c4265a3c32a Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Tue, 30 Nov 2021 21:31:17 +0000 Subject: [PATCH 2/4] Disable process jobs on Windows 7 and earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If they’re enabled on Windows 7 the cabal spawned with "actas-setup" flag is not able to spawn any processes since it already inherits a job from the toplevel cabal. --- Cabal/src/Distribution/Compat/Process.hs | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Cabal/src/Distribution/Compat/Process.hs b/Cabal/src/Distribution/Compat/Process.hs index 0c2e5fb0d05..093f42c776f 100644 --- a/Cabal/src/Distribution/Compat/Process.hs +++ b/Cabal/src/Distribution/Compat/Process.hs @@ -18,23 +18,41 @@ import qualified System.Process as Process import System.Process (waitForProcess) #endif +#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9) +import System.IO.Unsafe (unsafePerformIO) +import System.Win32.Info.Version (dwMajorVersion, dwMinorVersion, getVersionEx) +#endif + ------------------------------------------------------------------------------- -- enableProcessJobs ------------------------------------------------------------------------------- +#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9) +{-# NOINLINE isWindows8OrLater #-} +isWindows8OrLater :: Bool +isWindows8OrLater = unsafePerformIO $ do + v <- getVersionEx + pure $ (dwMajorVersion v, dwMinorVersion v) >= (6, 2) +#endif + -- | Enable process jobs to ensure accurate determination of process completion -- in the presence of @exec(3)@ on Windows. -- -- Unfortunately the process job support is badly broken in @process@ releases -- prior to 1.6.9, so we disable it in these versions, despite the fact that -- this means we may see sporadic build failures without jobs. +-- +-- On Windows 7 or before the jobs are disabled due to the fact that +-- processes on these systems can only have one job. This prevents +-- spawned process from assigning jobs to its own children. Suppose +-- processs A spawns process B. The B process has a job assigned (call +-- it J1) and when it tries to spawn a new process C the C +-- automatically inherits the job. But at it also tries to assign a +-- new job J2 to C since it doesn’t have access J1. This fails on +-- Windows 7 or before. enableProcessJobs :: CreateProcess -> CreateProcess -#ifdef MIN_VERSION_process -#if MIN_VERSION_process(1,6,9) -enableProcessJobs cp = cp {Process.use_process_jobs = True} -#else -enableProcessJobs cp = cp -#endif +#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9) +enableProcessJobs cp = cp {Process.use_process_jobs = isWindows8OrLater} #else enableProcessJobs cp = cp #endif From a5e866a23336ca7b5a70082a5d123b2a802cbce7 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Tue, 30 Nov 2021 23:13:17 +0000 Subject: [PATCH 3/4] Add changelog --- changelog.d/pr-7844 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog.d/pr-7844 diff --git a/changelog.d/pr-7844 b/changelog.d/pr-7844 new file mode 100644 index 00000000000..c46b59d2cca --- /dev/null +++ b/changelog.d/pr-7844 @@ -0,0 +1,8 @@ +synopsis: Disable job management on Windows 7 +packages: Cabal +prs: #7844 +significance: significant + +description: { +- cabal now works on Windows 7 +} From c8841f67fce393a8da5fde0ba02ec542eed783d4 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Fri, 3 Dec 2021 20:14:07 +0000 Subject: [PATCH 4/4] Add note on when the workaround can be safely removed --- Cabal/src/Distribution/Compat/Process.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cabal/src/Distribution/Compat/Process.hs b/Cabal/src/Distribution/Compat/Process.hs index 093f42c776f..b7c8be87280 100644 --- a/Cabal/src/Distribution/Compat/Process.hs +++ b/Cabal/src/Distribution/Compat/Process.hs @@ -28,6 +28,9 @@ import System.Win32.Info.Version (dwMajorVersion, dwMinorVersion, getV ------------------------------------------------------------------------------- #if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9) +-- This exception, needed to support Windows 7, could be removed when +-- the lowest GHC version cabal supports is a GHC that doesn’t support +-- Windows 7 any more. {-# NOINLINE isWindows8OrLater #-} isWindows8OrLater :: Bool isWindows8OrLater = unsafePerformIO $ do