Skip to content

Commit 55aff09

Browse files
authored
Support GHC 9.4 (#2532)
* chore: enable CPP in Dhall.DirectoryTree Adding a \ to the escaped newlines appears to make CPP generate valid haskell without getting stuck. * 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. * chore: fix template-haskell bound dhall does not compile with template-haskell >=2.17 due to signature change of Language.Haskell.TH.Syntax.PlainTV. * chore: support template-haskell 2.17 through 2.19 In particular this enables building with GHC 9.4. * chore(dhall): version 1.42.1 * fix: System.Posix.User.getGroupEntryForName does not exist on Windows
1 parent 5e817a9 commit 55aff09

File tree

3 files changed

+90
-64
lines changed

3 files changed

+90
-64
lines changed

dhall/dhall.cabal

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Cabal-Version: 2.4
22
Name: dhall
3-
Version: 1.42.0
3+
Version: 1.42.1
44
Build-Type: Simple
55
License: BSD-3-Clause
66
License-File: LICENSE
@@ -251,10 +251,14 @@ Common common
251251
th-lift-instances >= 0.1.13 && < 0.2 ,
252252
time >= 1.9 && < 1.13,
253253
transformers >= 0.5.2.0 && < 0.7 ,
254-
unix-compat >= 0.4.2 && < 0.7 ,
254+
unix-compat >= 0.4.2 && < 0.8 ,
255255
unordered-containers >= 0.1.3.0 && < 0.3 ,
256256
vector >= 0.11.0.0 && < 0.14
257257

258+
if !os(windows)
259+
Build-Depends:
260+
unix >= 2.7 && < 2.9 ,
261+
258262
if flag(with-http)
259263
CPP-Options:
260264
-DWITH_HTTP

dhall/src/Dhall/DirectoryTree.hs

Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE OverloadedLists #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE RecordWildCards #-}
@@ -54,8 +55,12 @@ import qualified Prettyprinter as Pretty
5455
import qualified Prettyprinter.Render.String as Pretty
5556
import qualified System.Directory as Directory
5657
import qualified System.FilePath as FilePath
58+
#ifdef mingw32_HOST_OS
59+
import System.IO.Error (illegalOperationErrorType, mkIOError)
60+
#else
61+
import qualified System.Posix.User as Posix
62+
#endif
5763
import qualified System.PosixCompat.Files as Posix
58-
import qualified System.PosixCompat.User as Posix
5964

6065
{-| Attempt to transform a Dhall record into a directory tree where:
6166
@@ -263,12 +268,24 @@ makeType = Record . Map.fromList <$> sequenceA
263268
-- | Resolve a `User` to a numerical id.
264269
getUser :: User -> IO UserID
265270
getUser (UserId uid) = return uid
266-
getUser (UserName name) = Posix.userID <$> Posix.getUserEntryForName name
271+
getUser (UserName name) =
272+
#ifdef mingw32_HOST_OS
273+
ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
274+
where x = "System.Posix.User.getUserEntryForName: not supported"
275+
#else
276+
Posix.userID <$> Posix.getUserEntryForName name
277+
#endif
267278

268279
-- | Resolve a `Group` to a numerical id.
269280
getGroup :: Group -> IO GroupID
270281
getGroup (GroupId gid) = return gid
271-
getGroup (GroupName name) = Posix.groupID <$> Posix.getGroupEntryForName name
282+
getGroup (GroupName name) =
283+
#ifdef mingw32_HOST_OS
284+
ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
285+
where x = "System.Posix.User.getGroupEntryForName: not supported"
286+
#else
287+
Posix.groupID <$> Posix.getGroupEntryForName name
288+
#endif
272289

273290
-- | Process a `FilesystemEntry`. Writes the content to disk and apply the
274291
-- metadata to the newly created item.
@@ -409,57 +426,57 @@ instance Show FilesystemError where
409426
Pretty.renderString (Dhall.Pretty.layout message)
410427
where
411428
message =
412-
Util._ERROR <> ": Not a valid directory tree expression \n\
413-
\ \n\
414-
\Explanation: Only a subset of Dhall expressions can be converted to a directory \n\
415-
\tree. Specifically, record literals or maps can be converted to directories, \n\
416-
\❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n\
417-
\❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n\
418-
\they are an alternative which has a non-nullary constructor whose argument is of \n\
419-
\an otherwise convertible type. Furthermore, there is a more advanced approach to \n\
420-
\constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n\
421-
\documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n\
422-
\further information on that. \n\
423-
\No other type of value can be translated to a directory tree. \n\
424-
\ \n\
425-
\For example, this is a valid expression that can be translated to a directory \n\
426-
\tree: \n\
427-
\ \n\
428-
\ \n\
429-
\ ┌──────────────────────────────────┐ \n\
430-
\ │ { `example.json` = \"[1, true]\" } │ \n\
431-
\ └──────────────────────────────────┘ \n\
432-
\ \n\
433-
\ \n\
434-
\In contrast, the following expression is not allowed due to containing a \n\
435-
\❰Natural❱ field, which cannot be translated in this way: \n\
436-
\ \n\
437-
\ \n\
438-
\ ┌───────────────────────┐ \n\
439-
\ │ { `example.txt` = 1 } │ \n\
440-
\ └───────────────────────┘ \n\
441-
\ \n\
442-
\ \n\
443-
\Note that key names cannot contain path separators: \n\
444-
\ \n\
445-
\ \n\
446-
\ ┌─────────────────────────────────────┐ \n\
447-
\ │ { `directory/example.txt` = \"ABC\" } │ Invalid: Key contains a forward slash\n\
448-
\ └─────────────────────────────────────┘ \n\
449-
\ \n\
450-
\ \n\
451-
\Instead, you need to refactor the expression to use nested records instead: \n\
452-
\ \n\
453-
\ \n\
454-
\ ┌───────────────────────────────────────────┐ \n\
455-
\ │ { directory = { `example.txt` = \"ABC\" } } │ \n\
456-
\ └───────────────────────────────────────────┘ \n\
457-
\ \n\
458-
\ \n\
459-
\You tried to translate the following expression to a directory tree: \n\
460-
\ \n\
461-
\" <> Util.insert unexpectedExpression <> "\n\
462-
\ \n\
429+
Util._ERROR <> ": Not a valid directory tree expression \n\\
430+
\ \n\\
431+
\Explanation: Only a subset of Dhall expressions can be converted to a directory \n\\
432+
\tree. Specifically, record literals or maps can be converted to directories, \n\\
433+
\❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n\\
434+
\❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n\\
435+
\they are an alternative which has a non-nullary constructor whose argument is of \n\\
436+
\an otherwise convertible type. Furthermore, there is a more advanced approach to \n\\
437+
\constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n\\
438+
\documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n\\
439+
\further information on that. \n\\
440+
\No other type of value can be translated to a directory tree. \n\\
441+
\ \n\\
442+
\For example, this is a valid expression that can be translated to a directory \n\\
443+
\tree: \n\\
444+
\ \n\\
445+
\ \n\\
446+
\ ┌──────────────────────────────────┐ \n\\
447+
\ { `example.json` = \"[1, true]\" } │ \n\\
448+
\ └──────────────────────────────────┘ \n\\
449+
\ \n\\
450+
\ \n\\
451+
\In contrast, the following expression is not allowed due to containing a \n\\
452+
\❰Natural❱ field, which cannot be translated in this way: \n\\
453+
\ \n\\
454+
\ \n\\
455+
\ ┌───────────────────────┐ \n\\
456+
\ { `example.txt` = 1 } \n\\
457+
\ └───────────────────────┘ \n\\
458+
\ \n\\
459+
\ \n\\
460+
\Note that key names cannot contain path separators: \n\\
461+
\ \n\\
462+
\ \n\\
463+
\ ┌─────────────────────────────────────┐ \n\\
464+
\ { `directory/example.txt` = \"ABC\" } │ Invalid: Key contains a forward slash\n\\
465+
\ └─────────────────────────────────────┘ \n\\
466+
\ \n\\
467+
\ \n\\
468+
\Instead, you need to refactor the expression to use nested records instead: \n\\
469+
\ \n\\
470+
\ \n\\
471+
\ ┌───────────────────────────────────────────┐ \n\\
472+
\ { directory = { `example.txt` = \"ABC\" } } │ \n\\
473+
\ └───────────────────────────────────────────┘ \n\\
474+
\ \n\\
475+
\ \n\\
476+
\You tried to translate the following expression to a directory tree: \n\\
477+
\ \n\\
478+
\" <> Util.insert unexpectedExpression <> "\n\\
479+
\ \n\\
463480
\... which is not an expression that can be translated to a directory tree. \n"
464481
465482
{- | This error indicates that you want to set some metadata for a file or
@@ -475,11 +492,11 @@ instance Show MetadataUnsupportedError where
475492
Pretty.renderString (Dhall.Pretty.layout message)
476493
where
477494
message =
478-
Util._ERROR <> ": Setting metadata is not supported on this platform. \n\
479-
\ \n\
480-
\Explanation: Your Dhall expression indicates that you intend to set some metadata \n\
481-
\like ownership or permissions for the following file or directory: \n\
482-
\ \n\
483-
\" <> Pretty.pretty metadataForPath <> "\n\
484-
\ \n\
495+
Util._ERROR <> ": Setting metadata is not supported on this platform. \n\\
496+
\ \n\\
497+
\Explanation: Your Dhall expression indicates that you intend to set some metadata \n\\
498+
\like ownership or permissions for the following file or directory: \n\\
499+
\ \n\\
500+
\" <> Pretty.pretty metadataForPath <> "\n\\
501+
\ \n\\
485502
\... which is not supported on your platform. \n"

dhall/src/Dhall/TH.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DeriveTraversable #-}
23
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE OverloadedStrings #-}
@@ -263,7 +264,11 @@ toDeclaration generateOptions@GenerateOptions{..} haskellTypes typ =
263264

264265
interpretOptions = generateToInterpretOptions generateOptions typ
265266

266-
toTypeVar (V n i) = Syntax.PlainTV $ Syntax.mkName (Text.unpack n ++ show i)
267+
#if MIN_VERSION_template_haskell(2,17,0)
268+
toTypeVar (V n i) = Syntax.PlainTV (Syntax.mkName (Text.unpack n ++ show i)) ()
269+
#else
270+
toTypeVar (V n i) = Syntax.PlainTV (Syntax.mkName (Text.unpack n ++ show i))
271+
#endif
267272

268273
toDataD typeName typeParams constructors = do
269274
let name = Syntax.mkName (Text.unpack typeName)

0 commit comments

Comments
 (0)