From b303575d794e107daf5c12896f7c39c53bbac45b Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 29 Jan 2020 14:03:25 +0100 Subject: [PATCH 1/6] Add -fwarn-incomplete-uni-patterns --- cabal-helper.cabal | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cabal-helper.cabal b/cabal-helper.cabal index 2d735ba..ff2b1b7 100644 --- a/cabal-helper.cabal +++ b/cabal-helper.cabal @@ -110,7 +110,7 @@ common build-deps build-depends: unix-compat < 0.6 && >= 0.4.3.1 if flag(dev) - ghc-options: -Wall + ghc-options: -Wall -fwarn-incomplete-uni-patterns common c-h-internal @@ -174,14 +174,14 @@ test-suite compile-test main-is: CompileTest.hs other-modules: TestOptions hs-source-dirs: tests - ghc-options: -Wall + ghc-options: -Wall -fwarn-incomplete-uni-patterns test-suite programs-test import: build-deps, extensions, c-h-internal type: exitcode-stdio-1.0 main-is: ProgramsTest.hs hs-source-dirs: tests - ghc-options: -Wall + ghc-options: -Wall -fwarn-incomplete-uni-patterns build-depends: pretty-show test-suite ghc-session @@ -190,7 +190,7 @@ test-suite ghc-session main-is: GhcSession.hs other-modules: TestOptions hs-source-dirs: tests - ghc-options: -Wall + ghc-options: -Wall -fwarn-incomplete-uni-patterns build-depends: ghc < 8.9 && >= 8.0.2 , pretty-show < 1.9 && >= 1.8.1 @@ -199,7 +199,7 @@ test-suite examples type: exitcode-stdio-1.0 main-is: Examples.hs hs-source-dirs: tests - ghc-options: -Wall + ghc-options: -Wall -fwarn-incomplete-uni-patterns executable cabal-helper-main default-language: Haskell2010 @@ -220,7 +220,7 @@ executable cabal-helper-main else buildable: False - ghc-options: -Wall -fno-warn-unused-imports + ghc-options: -Wall -fno-warn-unused-imports -fwarn-incomplete-uni-patterns build-depends: base < 5 && >= 4.9.1.0 , Cabal , containers From b874e2074c8436dc8f0b23f14f301168a85ed5b0 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 29 Jan 2020 14:05:09 +0100 Subject: [PATCH 2/6] Fallback to create symlink from cwd if no executable --- src/CabalHelper/Compiletime/CompPrograms.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/CabalHelper/Compiletime/CompPrograms.hs b/src/CabalHelper/Compiletime/CompPrograms.hs index 020bab4..f80f2c7 100644 --- a/src/CabalHelper/Compiletime/CompPrograms.hs +++ b/src/CabalHelper/Compiletime/CompPrograms.hs @@ -92,8 +92,11 @@ patchBuildToolProgs SStack progs = do createProgSymlink :: FilePath -> FilePath -> IO () createProgSymlink bindir target | [exe] <- splitPath target = do - Just exe_path <- findExecutable exe - createSymbolicLink exe_path (bindir takeFileName target) - | otherwise = do - cwd <- getCurrentDirectory - createSymbolicLink (cwd target) (bindir takeFileName target) + mb_exe_path <- findExecutable exe + case mb_exe_path of + Just exe_path -> createSymbolicLink exe_path (bindir takeFileName target) + Nothing -> createSymLinkFromCwd + | otherwise = createSymLinkFromCwd + where createSymLinkFromCwd = do + cwd <- getCurrentDirectory + createSymbolicLink (cwd target) (bindir takeFileName target) From 2812d434c93e53db90d5f814dcf06b39568341b4 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 29 Jan 2020 14:05:55 +0100 Subject: [PATCH 3/6] Avoid pattern match error extracting stack path --- src/CabalHelper/Compiletime/Program/Stack.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CabalHelper/Compiletime/Program/Stack.hs b/src/CabalHelper/Compiletime/Program/Stack.hs index d057d65..dc0b0e5 100644 --- a/src/CabalHelper/Compiletime/Program/Stack.hs +++ b/src/CabalHelper/Compiletime/Program/Stack.hs @@ -85,7 +85,7 @@ paths qe@QueryEnv{qeProjLoc=ProjLocStackYaml stack_yaml} cwd workdirArg qe ++ [ "path", "--stack-yaml="++stack_yaml ] return $ \k -> let Just x = lookup k $ map split $ lines out in x where - split l = let (key, ' ' : val) = span (not . isSpace) l in (key, val) + split l = let (key, val) = break isSpace l in (key, dropWhile isSpace val) listPackageCabalFiles :: QueryEnvI c 'Stack -> IO [CabalFile] listPackageCabalFiles qe@QueryEnv{qeProjLoc} From 87f41cfb50ff513e4d301ca1c2754d2af86d1812 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 10 Feb 2020 10:17:48 +0100 Subject: [PATCH 4/6] Do not create symlink if program name is simple --- src/CabalHelper/Compiletime/CompPrograms.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/CabalHelper/Compiletime/CompPrograms.hs b/src/CabalHelper/Compiletime/CompPrograms.hs index f80f2c7..929e760 100644 --- a/src/CabalHelper/Compiletime/CompPrograms.hs +++ b/src/CabalHelper/Compiletime/CompPrograms.hs @@ -2,6 +2,7 @@ module CabalHelper.Compiletime.CompPrograms where +import Control.Monad (when) import Data.List import Data.Maybe import System.Directory @@ -80,9 +81,12 @@ patchBuildToolProgs SStack progs = do -- being able to pass executable paths straight through to stack but -- currently there is no option to let us do that. withSystemTempDirectory "cabal-helper-symlinks" $ \bindir -> do - createProgSymlink bindir $ ghcProgram progs - createProgSymlink bindir $ ghcPkgProgram progs - createProgSymlink bindir $ haddockProgram progs + when (ghcProgram progs /= "ghc") $ + createProgSymlink bindir $ ghcProgram progs + when (ghcPkgProgram progs /= "ghc-pkg") $ + createProgSymlink bindir $ ghcPkgProgram progs + when (haddockProgram progs /= "haddock") $ + createProgSymlink bindir $ haddockProgram progs return $ progs { stackEnv = [("PATH", EnvPrepend $ bindir ++ [searchPathSeparator])] ++ @@ -95,8 +99,8 @@ createProgSymlink bindir target mb_exe_path <- findExecutable exe case mb_exe_path of Just exe_path -> createSymbolicLink exe_path (bindir takeFileName target) - Nothing -> createSymLinkFromCwd - | otherwise = createSymLinkFromCwd - where createSymLinkFromCwd = do - cwd <- getCurrentDirectory - createSymbolicLink (cwd target) (bindir takeFileName target) + Nothing -> error $ "Error trying to create symlink to " ++ target ++ ": " + ++ exe ++ " executable not found." + | otherwise = do + cwd <- getCurrentDirectory + createSymbolicLink (cwd target) (bindir takeFileName target) From 83f1af4b5cf0fe5d83fbb00c557e83e73481c96f Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 10 Feb 2020 12:51:14 +0100 Subject: [PATCH 5/6] Skip symlink only for haddock --- src/CabalHelper/Compiletime/CompPrograms.hs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/CabalHelper/Compiletime/CompPrograms.hs b/src/CabalHelper/Compiletime/CompPrograms.hs index 929e760..1c8c892 100644 --- a/src/CabalHelper/Compiletime/CompPrograms.hs +++ b/src/CabalHelper/Compiletime/CompPrograms.hs @@ -81,26 +81,23 @@ patchBuildToolProgs SStack progs = do -- being able to pass executable paths straight through to stack but -- currently there is no option to let us do that. withSystemTempDirectory "cabal-helper-symlinks" $ \bindir -> do - when (ghcProgram progs /= "ghc") $ - createProgSymlink bindir $ ghcProgram progs - when (ghcPkgProgram progs /= "ghc-pkg") $ - createProgSymlink bindir $ ghcPkgProgram progs - when (haddockProgram progs /= "haddock") $ - createProgSymlink bindir $ haddockProgram progs + createProgSymlink True bindir $ ghcProgram progs + createProgSymlink True bindir $ ghcPkgProgram progs + createProgSymlink False bindir $ haddockProgram progs return $ progs { stackEnv = [("PATH", EnvPrepend $ bindir ++ [searchPathSeparator])] ++ stackEnv progs } -createProgSymlink :: FilePath -> FilePath -> IO () -createProgSymlink bindir target +createProgSymlink :: Bool -> FilePath -> FilePath -> IO () +createProgSymlink required bindir target | [exe] <- splitPath target = do mb_exe_path <- findExecutable exe case mb_exe_path of Just exe_path -> createSymbolicLink exe_path (bindir takeFileName target) - Nothing -> error $ "Error trying to create symlink to " ++ target ++ ": " - ++ exe ++ " executable not found." + Nothing -> when required $ error $ "Error trying to create symlink to " ++ target ++ ": " + ++ exe ++ " executable not found." | otherwise = do cwd <- getCurrentDirectory createSymbolicLink (cwd target) (bindir takeFileName target) From 30a89217d350a557e40cb31b0fe170e32c2a0266 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 10 Feb 2020 13:21:45 +0100 Subject: [PATCH 6/6] Use single quotes and panicIO in error handling --- src/CabalHelper/Compiletime/CompPrograms.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CabalHelper/Compiletime/CompPrograms.hs b/src/CabalHelper/Compiletime/CompPrograms.hs index 1c8c892..24bc50f 100644 --- a/src/CabalHelper/Compiletime/CompPrograms.hs +++ b/src/CabalHelper/Compiletime/CompPrograms.hs @@ -11,6 +11,7 @@ import System.IO.Temp import CabalHelper.Compiletime.Types import CabalHelper.Compiletime.Cabal (getCabalVerbosity) +import CabalHelper.Shared.Common (panicIO) import Symlink (createSymbolicLink) import Distribution.Simple.GHC as GHC (configure) @@ -96,8 +97,8 @@ createProgSymlink required bindir target mb_exe_path <- findExecutable exe case mb_exe_path of Just exe_path -> createSymbolicLink exe_path (bindir takeFileName target) - Nothing -> when required $ error $ "Error trying to create symlink to " ++ target ++ ": " - ++ exe ++ " executable not found." + Nothing -> when required $ panicIO $ "Error trying to create symlink to '" ++ target ++ "': " + ++ "'" ++ exe ++ "'" ++ " executable not found." | otherwise = do cwd <- getCurrentDirectory createSymbolicLink (cwd target) (bindir takeFileName target)