From 838bd1d7342d5ca023ec8f695232d4760484e8c5 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Fri, 25 Aug 2023 13:16:17 +1000 Subject: [PATCH 1/6] chore: enable CPP in Dhall.DirectoryTree Adding a \ to the escaped newlines appears to make CPP generate valid haskell without getting stuck. --- dhall/src/Dhall/DirectoryTree.hs | 117 ++++++++++++++++--------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/dhall/src/Dhall/DirectoryTree.hs b/dhall/src/Dhall/DirectoryTree.hs index 405931e9b..2a960ba06 100644 --- a/dhall/src/Dhall/DirectoryTree.hs +++ b/dhall/src/Dhall/DirectoryTree.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} @@ -409,57 +410,57 @@ instance Show FilesystemError where Pretty.renderString (Dhall.Pretty.layout message) where message = - Util._ERROR <> ": Not a valid directory tree expression \n\ - \ \n\ - \Explanation: Only a subset of Dhall expressions can be converted to a directory \n\ - \tree. Specifically, record literals or maps can be converted to directories, \n\ - \❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n\ - \❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n\ - \they are an alternative which has a non-nullary constructor whose argument is of \n\ - \an otherwise convertible type. Furthermore, there is a more advanced approach to \n\ - \constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n\ - \documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n\ - \further information on that. \n\ - \No other type of value can be translated to a directory tree. \n\ - \ \n\ - \For example, this is a valid expression that can be translated to a directory \n\ - \tree: \n\ - \ \n\ - \ \n\ - \ ┌──────────────────────────────────┐ \n\ - \ │ { `example.json` = \"[1, true]\" } │ \n\ - \ └──────────────────────────────────┘ \n\ - \ \n\ - \ \n\ - \In contrast, the following expression is not allowed due to containing a \n\ - \❰Natural❱ field, which cannot be translated in this way: \n\ - \ \n\ - \ \n\ - \ ┌───────────────────────┐ \n\ - \ │ { `example.txt` = 1 } │ \n\ - \ └───────────────────────┘ \n\ - \ \n\ - \ \n\ - \Note that key names cannot contain path separators: \n\ - \ \n\ - \ \n\ - \ ┌─────────────────────────────────────┐ \n\ - \ │ { `directory/example.txt` = \"ABC\" } │ Invalid: Key contains a forward slash\n\ - \ └─────────────────────────────────────┘ \n\ - \ \n\ - \ \n\ - \Instead, you need to refactor the expression to use nested records instead: \n\ - \ \n\ - \ \n\ - \ ┌───────────────────────────────────────────┐ \n\ - \ │ { directory = { `example.txt` = \"ABC\" } } │ \n\ - \ └───────────────────────────────────────────┘ \n\ - \ \n\ - \ \n\ - \You tried to translate the following expression to a directory tree: \n\ - \ \n\ - \" <> Util.insert unexpectedExpression <> "\n\ - \ \n\ + Util._ERROR <> ": Not a valid directory tree expression \n\\ + \ \n\\ + \Explanation: Only a subset of Dhall expressions can be converted to a directory \n\\ + \tree. Specifically, record literals or maps can be converted to directories, \n\\ + \❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n\\ + \❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n\\ + \they are an alternative which has a non-nullary constructor whose argument is of \n\\ + \an otherwise convertible type. Furthermore, there is a more advanced approach to \n\\ + \constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n\\ + \documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n\\ + \further information on that. \n\\ + \No other type of value can be translated to a directory tree. \n\\ + \ \n\\ + \For example, this is a valid expression that can be translated to a directory \n\\ + \tree: \n\\ + \ \n\\ + \ \n\\ + \ ┌──────────────────────────────────┐ \n\\ + \ │ { `example.json` = \"[1, true]\" } │ \n\\ + \ └──────────────────────────────────┘ \n\\ + \ \n\\ + \ \n\\ + \In contrast, the following expression is not allowed due to containing a \n\\ + \❰Natural❱ field, which cannot be translated in this way: \n\\ + \ \n\\ + \ \n\\ + \ ┌───────────────────────┐ \n\\ + \ │ { `example.txt` = 1 } │ \n\\ + \ └───────────────────────┘ \n\\ + \ \n\\ + \ \n\\ + \Note that key names cannot contain path separators: \n\\ + \ \n\\ + \ \n\\ + \ ┌─────────────────────────────────────┐ \n\\ + \ │ { `directory/example.txt` = \"ABC\" } │ Invalid: Key contains a forward slash\n\\ + \ └─────────────────────────────────────┘ \n\\ + \ \n\\ + \ \n\\ + \Instead, you need to refactor the expression to use nested records instead: \n\\ + \ \n\\ + \ \n\\ + \ ┌───────────────────────────────────────────┐ \n\\ + \ │ { directory = { `example.txt` = \"ABC\" } } │ \n\\ + \ └───────────────────────────────────────────┘ \n\\ + \ \n\\ + \ \n\\ + \You tried to translate the following expression to a directory tree: \n\\ + \ \n\\ + \" <> Util.insert unexpectedExpression <> "\n\\ + \ \n\\ \... which is not an expression that can be translated to a directory tree. \n" {- | This error indicates that you want to set some metadata for a file or @@ -475,11 +476,11 @@ instance Show MetadataUnsupportedError where Pretty.renderString (Dhall.Pretty.layout message) where message = - Util._ERROR <> ": Setting metadata is not supported on this platform. \n\ - \ \n\ - \Explanation: Your Dhall expression indicates that you intend to set some metadata \n\ - \like ownership or permissions for the following file or directory: \n\ - \ \n\ - \" <> Pretty.pretty metadataForPath <> "\n\ - \ \n\ + Util._ERROR <> ": Setting metadata is not supported on this platform. \n\\ + \ \n\\ + \Explanation: Your Dhall expression indicates that you intend to set some metadata \n\\ + \like ownership or permissions for the following file or directory: \n\\ + \ \n\\ + \" <> Pretty.pretty metadataForPath <> "\n\\ + \ \n\\ \... which is not supported on your platform. \n" From 11285ecce7066dfd6dd62070f040d76c1f5cc740 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Fri, 25 Aug 2023 13:30:52 +1000 Subject: [PATCH 2/6] feat: support unix-compat 0.8 In unix-compat 0.7, `getUserEntryForName` threw an exception when called on Windows. unix-compat 0.8 removes it entirely. To increase likelihood of this change being merged, the behaviour of the 0.7 version has been incorporated into Dhall.DirectoryTree. --- dhall/dhall.cabal | 6 +++++- dhall/src/Dhall/DirectoryTree.hs | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dhall/dhall.cabal b/dhall/dhall.cabal index 3732d1c99..794976695 100644 --- a/dhall/dhall.cabal +++ b/dhall/dhall.cabal @@ -251,10 +251,14 @@ Common common th-lift-instances >= 0.1.13 && < 0.2 , time >= 1.9 && < 1.13, transformers >= 0.5.2.0 && < 0.7 , - unix-compat >= 0.4.2 && < 0.7 , + unix-compat >= 0.4.2 && < 0.8 , unordered-containers >= 0.1.3.0 && < 0.3 , vector >= 0.11.0.0 && < 0.14 + if !os(windows) + Build-Depends: + unix >= 2.7 && < 2.9 , + if flag(with-http) CPP-Options: -DWITH_HTTP diff --git a/dhall/src/Dhall/DirectoryTree.hs b/dhall/src/Dhall/DirectoryTree.hs index 2a960ba06..772019c58 100644 --- a/dhall/src/Dhall/DirectoryTree.hs +++ b/dhall/src/Dhall/DirectoryTree.hs @@ -55,8 +55,12 @@ import qualified Prettyprinter as Pretty import qualified Prettyprinter.Render.String as Pretty import qualified System.Directory as Directory import qualified System.FilePath as FilePath +#ifdef mingw32_HOST_OS +import System.IO.Error (illegalOperationErrorType, mkIOError) +#else +import qualified System.Posix.User as Posix +#endif import qualified System.PosixCompat.Files as Posix -import qualified System.PosixCompat.User as Posix {-| Attempt to transform a Dhall record into a directory tree where: @@ -264,7 +268,13 @@ makeType = Record . Map.fromList <$> sequenceA -- | Resolve a `User` to a numerical id. getUser :: User -> IO UserID getUser (UserId uid) = return uid -getUser (UserName name) = Posix.userID <$> Posix.getUserEntryForName name +getUser (UserName name) = +#ifdef mingw32_HOST_OS + ioError $ mkIOError illegalOperationErrorType x Nothing Nothing + where x = "System.Posix.User.getUserEntryForName: not supported" +#else + Posix.userID <$> Posix.getUserEntryForName name +#endif -- | Resolve a `Group` to a numerical id. getGroup :: Group -> IO GroupID From bb1ced23e0c7b6bcbbe8c1de0f8e271107ffe8fd Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Fri, 25 Aug 2023 14:03:51 +1000 Subject: [PATCH 3/6] chore: fix template-haskell bound dhall does not compile with template-haskell >=2.17 due to signature change of Language.Haskell.TH.Syntax.PlainTV. --- dhall/dhall.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhall/dhall.cabal b/dhall/dhall.cabal index 794976695..56ebac657 100644 --- a/dhall/dhall.cabal +++ b/dhall/dhall.cabal @@ -244,7 +244,7 @@ Common common repline >= 0.4.0.0 && < 0.5 , serialise >= 0.2.0.0 && < 0.3 , scientific >= 0.3.0.0 && < 0.4 , - template-haskell >= 2.13.0.0 && < 2.20, + template-haskell >= 2.13.0.0 && < 2.17, text >= 0.11.1.0 && < 2.1 , text-manipulate >= 0.2.0.1 && < 0.4 , text-short >= 0.1 && < 0.2 , From dd99ed8d4a48c35ce0acab9083f92e16cc0f4ed7 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Fri, 25 Aug 2023 14:09:46 +1000 Subject: [PATCH 4/6] chore: support template-haskell 2.17 through 2.19 In particular this enables building with GHC 9.4. --- dhall/dhall.cabal | 2 +- dhall/src/Dhall/TH.hs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dhall/dhall.cabal b/dhall/dhall.cabal index 56ebac657..794976695 100644 --- a/dhall/dhall.cabal +++ b/dhall/dhall.cabal @@ -244,7 +244,7 @@ Common common repline >= 0.4.0.0 && < 0.5 , serialise >= 0.2.0.0 && < 0.3 , scientific >= 0.3.0.0 && < 0.4 , - template-haskell >= 2.13.0.0 && < 2.17, + template-haskell >= 2.13.0.0 && < 2.20, text >= 0.11.1.0 && < 2.1 , text-manipulate >= 0.2.0.1 && < 0.4 , text-short >= 0.1 && < 0.2 , diff --git a/dhall/src/Dhall/TH.hs b/dhall/src/Dhall/TH.hs index ed08d0334..203ec662f 100644 --- a/dhall/src/Dhall/TH.hs +++ b/dhall/src/Dhall/TH.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} @@ -263,7 +264,11 @@ toDeclaration generateOptions@GenerateOptions{..} haskellTypes typ = interpretOptions = generateToInterpretOptions generateOptions typ - toTypeVar (V n i) = Syntax.PlainTV $ Syntax.mkName (Text.unpack n ++ show i) +#if MIN_VERSION_template_haskell(2,17,0) + toTypeVar (V n i) = Syntax.PlainTV (Syntax.mkName (Text.unpack n ++ show i)) () +#else + toTypeVar (V n i) = Syntax.PlainTV (Syntax.mkName (Text.unpack n ++ show i)) +#endif toDataD typeName typeParams constructors = do let name = Syntax.mkName (Text.unpack typeName) From 065e81b1c9da9e7391be2339bccb83bbf64a6201 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Fri, 25 Aug 2023 14:35:15 +1000 Subject: [PATCH 5/6] chore(dhall): version 1.42.1 --- dhall/dhall.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhall/dhall.cabal b/dhall/dhall.cabal index 794976695..f36fb2682 100644 --- a/dhall/dhall.cabal +++ b/dhall/dhall.cabal @@ -1,6 +1,6 @@ Cabal-Version: 2.4 Name: dhall -Version: 1.42.0 +Version: 1.42.1 Build-Type: Simple License: BSD-3-Clause License-File: LICENSE From 2e8aa43abf04bd7d723d7973b7ba270806a35482 Mon Sep 17 00:00:00 2001 From: Luke Worth Date: Mon, 4 Sep 2023 13:12:17 +1000 Subject: [PATCH 6/6] fix: System.Posix.User.getGroupEntryForName does not exist on Windows --- dhall/src/Dhall/DirectoryTree.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dhall/src/Dhall/DirectoryTree.hs b/dhall/src/Dhall/DirectoryTree.hs index 772019c58..fec32bea4 100644 --- a/dhall/src/Dhall/DirectoryTree.hs +++ b/dhall/src/Dhall/DirectoryTree.hs @@ -279,7 +279,13 @@ getUser (UserName name) = -- | Resolve a `Group` to a numerical id. getGroup :: Group -> IO GroupID getGroup (GroupId gid) = return gid -getGroup (GroupName name) = Posix.groupID <$> Posix.getGroupEntryForName name +getGroup (GroupName name) = +#ifdef mingw32_HOST_OS + ioError $ mkIOError illegalOperationErrorType x Nothing Nothing + where x = "System.Posix.User.getGroupEntryForName: not supported" +#else + Posix.groupID <$> Posix.getGroupEntryForName name +#endif -- | Process a `FilesystemEntry`. Writes the content to disk and apply the -- metadata to the newly created item.