on master help sign in
command: Restore preference for relative paths in GHCi config
commitbc81a43ddcc07a52f0df048ca9d3d4500f5f4ec3 authorElliot Cameron <eacameron@gmail.com> dateFri 10 Apr 2020, 18:36 (7 years ago) parent4dacf45
1 file changed+13−7
lib/command/src/Obelisk/Command/Run.hs+13−7
lib/command/src/Obelisk/Command/Run.hs+13−7
@@ -426,15 +426,21 @@ getGhciSessionSettings
426426 -> FilePath -- ^ All paths written to the .ghci file will be relative to this path
427427 -> m [String]
428428getGhciSessionSettings (toList -> packageInfos) pathBase = do
429− selfExe <- liftIO getExecutablePath
430− -- TODO: Shell escape
429+ -- N.B. ghci settings do NOT support escaping in any way. To minimize the likelihood that
430+ -- paths-with-spaces ruin our day, we first canonicalize everything, and then relativize
431+ -- all paths to 'pathBase'.
432+ selfExe <- liftIO $ canonicalizePath =<< getExecutablePath
433+ canonicalPathBase <- liftIO $ canonicalizePath pathBase
434+
435+ (pkgFiles, pkgSrcPaths :: [NonEmpty FilePath]) <- fmap unzip $ liftIO $ for packageInfos $ \pkg -> do
436+ canonicalSrcDirs <- traverse canonicalizePath $ (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg
437+ canonicalPkgFile <- canonicalizePath $ _cabalPackageInfo_packageFile pkg
438+ pure (makeRelative canonicalPathBase canonicalPkgFile, makeRelative canonicalPathBase <$> canonicalSrcDirs)
439+
431440 pure
432441 $ ["-F", "-pgmF", selfExe, "-optF", preprocessorIdentifier]
433− <> concatMap (\p -> ["-optF", makeRelative pathBase $ _cabalPackageInfo_packageFile p]) packageInfos
434− <> [ "-i" <> intercalate ":" (packageInfos >>= rootedSourceDirs) ]
435− where
436− rootedSourceDirs pkg = NE.toList $
437− makeRelative pathBase . (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg
442+ <> concatMap (\p -> ["-optF", p]) pkgFiles
443+ <> [ "-i" <> intercalate ":" (concatMap toList pkgSrcPaths) ]
438444
439445-- | Run ghci repl
440446runGhciRepl