From 37f67421e5f60a652dae8b071207853c01c77c16 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sat, 2 Sep 2023 23:30:01 +1200 Subject: [PATCH 1/2] Fix use of NumJobs From `Cabal/src/Distribution/Types/ParStrat.hs` ``` data ParStratX sem = -- | Compile in parallel with the given number of jobs (`-jN` or `-j`). NumJobs (Maybe Int) ... ``` However in `Cabal/src/Distribution/Simple/Program/GHC.hs` show is applied to the `Maybe Int` and we get errors like: ``` ghc-9.9.20230901: on the commandline: malformed integer argument in -jJust 4 ``` This change should correct the behavior in `Simple/Program/GHC.hs` to match the comment in `Types/ParStrat.hs`. --- Cabal/src/Distribution/Simple/Program/GHC.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index 1f525fd9f39..537e008c17f 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -701,7 +701,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts if jsemSupported comp then ["-jsem " ++ name] else [] - Flag (NumJobs n) -> ["-j" ++ show n] + Flag (NumJobs n) -> ["-j" ++ maybe "" show n] else [] , -------------------- -- Creating libraries From 7b624afe595d71dee73c42b924d8b68dafe689b6 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Mon, 4 Sep 2023 21:29:30 +1200 Subject: [PATCH 2/2] Add test --- .../Distribution/Simple/Program/GHC.hs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs b/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs index 985c91f8eae..8244285915f 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs @@ -1,11 +1,16 @@ module UnitTests.Distribution.Simple.Program.GHC (tests) where +import qualified Data.Map as Map import Data.Algorithm.Diff (PolyDiff (..), getDiff) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit +import Distribution.System (Platform(..), Arch(X86_64), OS(Linux)) +import Distribution.Types.ParStrat +import Distribution.Simple.Flag +import Distribution.Simple.Compiler (Compiler(..), CompilerId(..), CompilerFlavor(..), AbiTag(NoAbiTag)) import Distribution.PackageDescription (emptyPackageDescription) -import Distribution.Simple.Program.GHC (normaliseGhcArgs) +import Distribution.Simple.Program.GHC (normaliseGhcArgs, renderGhcOptions, ghcOptNumJobs) import Distribution.Version (mkVersion) tests :: TestTree @@ -38,6 +43,22 @@ tests = testGroup "Distribution.Simple.Program.GHC" assertListEquals flags options_9_0_affects ] + , testGroup "renderGhcOptions" + [ testCase "options" $ do + let flags :: [String] + flags = renderGhcOptions + (Compiler + { compilerId = CompilerId GHC (mkVersion [9,8,1]) + , compilerAbiTag = NoAbiTag + , compilerCompat = [] + , compilerLanguages = [] + , compilerExtensions = [] + , compilerProperties = Map.singleton "Support parallel --make" "YES" + }) + (Platform X86_64 Linux) + (mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) }) + assertListEquals flags ["-j4", "-clear-package-db"] + ] ] assertListEquals :: (Eq a, Show a) => [a] -> [a] -> Assertion