Skip to content

Commit

Permalink
Merge branch 'main' into binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 authored Oct 16, 2023
2 parents de96842 + 55aff09 commit 21088cd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion dhall-lsp-server/dhall-lsp-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ library
, lsp >= 1.2.0.0 && < 1.5
, rope-utf16-splay >= 0.3.1.0 && < 0.5
, hslogger >= 1.2.10 && < 1.4
, lens >= 4.16.1 && < 5.2
, lens >= 4.16.1 && < 5.3
-- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469
, megaparsec >= 7.0.2 && < 10
, mtl >= 2.2.2 && < 2.3
Expand Down
8 changes: 6 additions & 2 deletions dhall/dhall.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
139 changes: 78 additions & 61 deletions dhall/src/Dhall/DirectoryTree.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
Expand Down Expand Up @@ -54,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:
Expand Down Expand Up @@ -263,12 +268,24 @@ 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) =

Check warning on line 271 in dhall/src/Dhall/DirectoryTree.hs

View workflow job for this annotation

GitHub Actions / windows-latest

Defined but not used: `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
getGroup (GroupId gid) = return gid
getGroup (GroupName name) = Posix.groupID <$> Posix.getGroupEntryForName name
getGroup (GroupName name) =

Check warning on line 282 in dhall/src/Dhall/DirectoryTree.hs

View workflow job for this annotation

GitHub Actions / windows-latest

Defined but not used: `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.
Expand Down Expand Up @@ -409,57 +426,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
Expand All @@ -475,11 +492,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"
7 changes: 6 additions & 1 deletion dhall/src/Dhall/TH.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 21088cd

Please sign in to comment.