From 3e3fe72a2df2893213acce6fa21342ab566dcbd1 Mon Sep 17 00:00:00 2001 From: Lennart Augustsson Date: Sat, 4 Oct 2025 14:21:54 +0200 Subject: [PATCH 1/2] Make it compile with MicroHs --- .gitignore | 1 + System/FilePath/Internal.hs | 2 +- System/OsPath/Common.hs | 14 +++++++++++--- System/OsPath/Internal.hs | 10 ++++++++-- System/OsPath/Posix.hs | 3 +++ System/OsPath/Windows.hs | 3 ++- filepath.cabal | 7 ++++++- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index dcfd17f2..e41e6fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ GNUmakefile dist-install/ dist-newstyle/ +dist-mcabal/ dist/ ghc.mk .stack-work/ diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs index eeb11f35..5f714c4f 100644 --- a/System/FilePath/Internal.hs +++ b/System/FilePath/Internal.hs @@ -132,7 +132,7 @@ import Data.List(stripPrefix, isSuffixOf, uncons, dropWhileEnd) import Prelude (fromIntegral, return, IO, Either(..)) import Control.Exception ( catch, displayException, evaluate, fromException, toException, throwIO, Exception, SomeAsyncException(..), SomeException ) import Control.DeepSeq (force) -import GHC.IO (unsafePerformIO) +import System.IO.Unsafe (unsafePerformIO) import qualified Data.Char as C #ifdef WINDOWS import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) diff --git a/System/OsPath/Common.hs b/System/OsPath/Common.hs index 5058b0e1..a7e36e0a 100644 --- a/System/OsPath/Common.hs +++ b/System/OsPath/Common.hs @@ -45,11 +45,13 @@ module System.OsPath , PS.unsafeEncodeUtf , PS.encodeWith , encodeFS +#if !defined(__MHS__) #if defined(WINDOWS) || defined(POSIX) , pstr #else , osp #endif +#endif /* !defined(__MHS__) */ , PS.pack -- * Filepath deconstruction @@ -124,22 +126,26 @@ import System.OsString.Windows as PS import Data.Bifunctor ( bimap ) import qualified System.OsPath.Windows.Internal as C import GHC.IO.Encoding.UTF16 ( mkUTF16le ) +#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) +#endif import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import Control.Monad ( when ) #elif defined(POSIX) import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import Control.Monad ( when ) +#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) - +#endif import GHC.IO.Encoding.UTF8 ( mkUTF8 ) + import System.OsPath.Types import System.OsString.Posix as PS ( unsafeFromChar @@ -158,14 +164,16 @@ import qualified System.OsPath.Posix.Internal as C #else import System.OsPath.Internal as PS - ( osp - , decodeUtf + ( decodeUtf , decodeWith , pack , encodeUtf , unsafeEncodeUtf , encodeWith , unpack +#if !defined(__MHS__) + , osp +#endif ) import System.OsPath.Types ( OsPath ) diff --git a/System/OsPath/Internal.hs b/System/OsPath/Internal.hs index bc1d5a9b..22c6a37d 100644 --- a/System/OsPath/Internal.hs +++ b/System/OsPath/Internal.hs @@ -15,17 +15,21 @@ import Control.Monad.Catch ( MonadThrow ) import Data.ByteString ( ByteString ) +#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) +import System.IO + ( TextEncoding ) +#else +import GHC.IO.Encoding.Types ( TextEncoding ) +#endif import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import System.OsString.Internal.Types import System.OsPath.Encoding import Control.Monad (when) -import System.IO - ( TextEncoding ) #if defined(mingw32_HOST_OS) || defined(__MINGW32__) import qualified System.OsPath.Windows as PF @@ -124,6 +128,7 @@ fromBytes = OS.fromBytes +#if !defined(__MHS__) -- | QuasiQuote an 'OsPath'. This accepts Unicode characters -- and encodes as UTF-8 on unix and UTF-16LE on windows. Runs 'isValid' -- on the input. If used as a pattern, requires turning on the @ViewPatterns@ @@ -159,6 +164,7 @@ osp = QuasiQuoter fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } #endif +#endif /* !defined(__MHS__) */ -- | Unpack an 'OsPath' to a list of 'OsChar'. diff --git a/System/OsPath/Posix.hs b/System/OsPath/Posix.hs index fc62c86b..72310d9b 100644 --- a/System/OsPath/Posix.hs +++ b/System/OsPath/Posix.hs @@ -11,6 +11,7 @@ #include "Common.hs" +#if !defined(__MHS__) -- | QuasiQuote a 'PosixPath'. This accepts Unicode characters -- and encodes as UTF-8. Runs 'isValid' on the input. pstr :: QuasiQuoter @@ -29,3 +30,5 @@ pstr = , quoteDec = \_ -> fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } +#endif /* !defined(__MHS__) */ + diff --git a/System/OsPath/Windows.hs b/System/OsPath/Windows.hs index ab9efc03..c29b0c13 100644 --- a/System/OsPath/Windows.hs +++ b/System/OsPath/Windows.hs @@ -11,7 +11,7 @@ #include "Common.hs" - +#if !defined(__MHS__) -- | QuasiQuote a 'WindowsPath'. This accepts Unicode characters -- and encodes as UTF-16LE. Runs 'isValid' on the input. pstr :: QuasiQuoter @@ -30,3 +30,4 @@ pstr = , quoteDec = \_ -> fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } +#endif /* !defined(__MHS__) */ diff --git a/filepath.cabal b/filepath.cabal index d9c91b24..4f5445a2 100644 --- a/filepath.cabal +++ b/filepath.cabal @@ -95,8 +95,13 @@ library , bytestring >=0.11.3.0 , deepseq , exceptions - , template-haskell , os-string >=2.0.1 + if impl(ghc) + build-depends: + template-haskell + if impl(mhs) + build-depends: + ghc-compat ghc-options: -Wall From da729ecb93cd2293b910ad9d1fb9ad783e34ced4 Mon Sep 17 00:00:00 2001 From: Lennart Augustsson Date: Sun, 5 Oct 2025 11:42:41 +0200 Subject: [PATCH 2/2] Minimize __MHS__ differences. --- System/OsPath/Common.hs | 14 +++----------- System/OsPath/Internal.hs | 19 +++++++++++-------- System/OsPath/Posix.hs | 7 +++++-- System/OsPath/Windows.hs | 7 +++++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/System/OsPath/Common.hs b/System/OsPath/Common.hs index a7e36e0a..5058b0e1 100644 --- a/System/OsPath/Common.hs +++ b/System/OsPath/Common.hs @@ -45,13 +45,11 @@ module System.OsPath , PS.unsafeEncodeUtf , PS.encodeWith , encodeFS -#if !defined(__MHS__) #if defined(WINDOWS) || defined(POSIX) , pstr #else , osp #endif -#endif /* !defined(__MHS__) */ , PS.pack -- * Filepath deconstruction @@ -126,26 +124,22 @@ import System.OsString.Windows as PS import Data.Bifunctor ( bimap ) import qualified System.OsPath.Windows.Internal as C import GHC.IO.Encoding.UTF16 ( mkUTF16le ) -#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) -#endif import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import Control.Monad ( when ) #elif defined(POSIX) import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import Control.Monad ( when ) -#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) -#endif -import GHC.IO.Encoding.UTF8 ( mkUTF8 ) +import GHC.IO.Encoding.UTF8 ( mkUTF8 ) import System.OsPath.Types import System.OsString.Posix as PS ( unsafeFromChar @@ -164,16 +158,14 @@ import qualified System.OsPath.Posix.Internal as C #else import System.OsPath.Internal as PS - ( decodeUtf + ( osp + , decodeUtf , decodeWith , pack , encodeUtf , unsafeEncodeUtf , encodeWith , unpack -#if !defined(__MHS__) - , osp -#endif ) import System.OsPath.Types ( OsPath ) diff --git a/System/OsPath/Internal.hs b/System/OsPath/Internal.hs index 22c6a37d..43ecd71a 100644 --- a/System/OsPath/Internal.hs +++ b/System/OsPath/Internal.hs @@ -15,21 +15,21 @@ import Control.Monad.Catch ( MonadThrow ) import Data.ByteString ( ByteString ) -#if !defined(__MHS__) import Language.Haskell.TH.Quote ( QuasiQuoter (..) ) import Language.Haskell.TH.Syntax ( Lift (..), lift ) -import System.IO - ( TextEncoding ) -#else -import GHC.IO.Encoding.Types ( TextEncoding ) -#endif import GHC.IO.Encoding.Failure ( CodingFailureMode(..) ) import System.OsString.Internal.Types import System.OsPath.Encoding import Control.Monad (when) +#if !defined(__MHS__) +import System.IO + ( TextEncoding ) +#else +import GHC.IO.Encoding.Types ( TextEncoding ) +#endif #if defined(mingw32_HOST_OS) || defined(__MINGW32__) import qualified System.OsPath.Windows as PF @@ -128,7 +128,7 @@ fromBytes = OS.fromBytes -#if !defined(__MHS__) +#if defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) -- | QuasiQuote an 'OsPath'. This accepts Unicode characters -- and encodes as UTF-8 on unix and UTF-16LE on windows. Runs 'isValid' -- on the input. If used as a pattern, requires turning on the @ViewPatterns@ @@ -164,7 +164,10 @@ osp = QuasiQuoter fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } #endif -#endif /* !defined(__MHS__) */ +#else +osp :: a +osp = error "Systen.OsPath.Internal.ostr: no Template Haskell" +#endif /* defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) */ -- | Unpack an 'OsPath' to a list of 'OsChar'. diff --git a/System/OsPath/Posix.hs b/System/OsPath/Posix.hs index 72310d9b..98e611d5 100644 --- a/System/OsPath/Posix.hs +++ b/System/OsPath/Posix.hs @@ -11,7 +11,7 @@ #include "Common.hs" -#if !defined(__MHS__) +#if defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) -- | QuasiQuote a 'PosixPath'. This accepts Unicode characters -- and encodes as UTF-8. Runs 'isValid' on the input. pstr :: QuasiQuoter @@ -30,5 +30,8 @@ pstr = , quoteDec = \_ -> fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } -#endif /* !defined(__MHS__) */ +#else +pstr :: a +pstr = error "Systen.OsPath.Posix.pstr: no Template Haskell" +#endif /* defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) */ diff --git a/System/OsPath/Windows.hs b/System/OsPath/Windows.hs index c29b0c13..b3028f9f 100644 --- a/System/OsPath/Windows.hs +++ b/System/OsPath/Windows.hs @@ -11,7 +11,7 @@ #include "Common.hs" -#if !defined(__MHS__) +#if defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) -- | QuasiQuote a 'WindowsPath'. This accepts Unicode characters -- and encodes as UTF-16LE. Runs 'isValid' on the input. pstr :: QuasiQuoter @@ -30,4 +30,7 @@ pstr = , quoteDec = \_ -> fail "illegal QuasiQuote (allowed as expression or pattern only, used as a declaration)" } -#endif /* !defined(__MHS__) */ +#else +pstr :: a +pstr = error "Systen.OsPath.Windows.pstr: no Template Haskell" +#endif /* defined(MIN_VERSION_template_haskell) || defined(MIN_VERSION_template_haskell_quasi_quoter) */