Skip to content

Commit

Permalink
Merge pull request #72 from jneira/dhall
Browse files Browse the repository at this point in the history
Integration of dhall
  • Loading branch information
rahulmutt authored Sep 4, 2018
2 parents e1359f4 + cb37ef3 commit e9b0966
Show file tree
Hide file tree
Showing 27 changed files with 512 additions and 277 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "hackage-security"]
path = hackage-security
url = https://github.com/Jyothsnasrinivas/hackage-security.git
[submodule "dhall-to-etlas"]
path = dhall-to-etlas
url = https://github.com/eta-lang/dhall-to-etlas
1 change: 1 addition & 0 deletions dhall-to-etlas
Submodule dhall-to-etlas added at 428ee1
33 changes: 20 additions & 13 deletions etlas-cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,19 +1781,26 @@ findPackageDesc :: Monad m => CheckPackageContentOps m
-> m (Either PackageCheck FilePath) -- ^<pkgname>.cabal
findPackageDesc ops
= do let dir = "."
files <- getDirectoryContents ops dir
-- to make sure we do not mistake a ~/.cabal/ dir for a <pkgname>.cabal
-- file we filter to exclude dirs and null base file names:
cabalFiles <- filterM (doesFileExist ops)
[ dir </> file
| file <- files
, let (name, ext) = splitExtension file
, not (null name) && ext == ".cabal" ]
case cabalFiles of
[] -> return (Left $ PackageBuildImpossible noDesc)
[cabalFile] -> return (Right cabalFile)
multiple -> return (Left $ PackageBuildImpossible
$ multiDesc multiple)
dhallFile = dir </> "etlas.dhall"

existDhallFile <- doesFileExist ops dhallFile

if existDhallFile then return (Right dhallFile)
else do

files <- getDirectoryContents ops dir
-- to make sure we do not mistake a ~/.cabal/ dir for a <pkgname>.cabal
-- file we filter to exclude dirs and null base file names:
cabalFiles <- filterM (doesFileExist ops)
[ dir </> file
| file <- files
, let (name, ext) = splitExtension file
, not (null name) && ext == ".cabal" ]
case cabalFiles of
[] -> return (Left $ PackageBuildImpossible noDesc)
[cabalFile] -> return (Right cabalFile)
multiple -> return (Left $ PackageBuildImpossible
$ multiDesc multiple)

where
noDesc :: String
Expand Down
10 changes: 5 additions & 5 deletions etlas-cabal/Distribution/Parsec/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Functor.Identity (Identity)
import qualified Distribution.Compat.Parsec as P
import Distribution.Parsec.Types.Common
(PWarnType (..), PWarning (..), Position (..))
import Distribution.Utils.Generic (lowercase)
import qualified Text.Parsec as Parsec
import qualified Text.Parsec.Language as Parsec
import qualified Text.Parsec.Token as Parsec
Expand Down Expand Up @@ -125,12 +126,11 @@ instance Parsec ModuleName where
validModuleChar c = isAlphaNum c || c == '_' || c == '\''

instance Parsec FlagName where
parsec = mkFlagName . map toLower . intercalate "-" <$> P.sepBy1 component (P.char '-')
parsec = mkFlagName . lowercase <$> parsec'
where
-- http://hackage.haskell.org/package/cabal-debian-4.24.8/cabal-debian.cabal
-- has flag with all digit component: pretty-112
component :: P.Stream s Identity Char => P.Parsec s [PWarning] String
component = P.munch1 (\c -> isAlphaNum c || c `elem` "_")
parsec' = (:) <$> lead <*> rest
lead = P.satisfy (\c -> isAlphaNum c || c == '_')
rest = P.munch (\c -> isAlphaNum c || c == '_' || c == '-')

instance Parsec Dependency where
parsec = do
Expand Down
17 changes: 11 additions & 6 deletions etlas-cabal/Distribution/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ module Distribution.Simple (
module Distribution.Simple.Compiler,
module Language.Haskell.Extension,
-- * Simple interface
defaultMain, defaultMainNoRead, defaultMainArgs,
defaultMain, defaultMainNoRead,
defaultMainNoReadArgs, defaultMainArgs,
-- * Customization
UserHooks(..), Args,
defaultMainWithHooks, defaultMainWithHooksArgs,
defaultMainWithHooksNoRead,
defaultMainWithHooksNoRead, defaultMainWithHooksNoReadArgs,
-- ** Standard sets of hooks
simpleUserHooks,
autoconfUserHooks,
Expand Down Expand Up @@ -139,10 +140,17 @@ defaultMainWithHooksArgs = defaultMainHelper
defaultMainNoRead :: GenericPackageDescription -> IO ()
defaultMainNoRead = defaultMainWithHooksNoRead simpleUserHooks

defaultMainNoReadArgs :: GenericPackageDescription -> [String] -> IO ()
defaultMainNoReadArgs = defaultMainWithHooksNoReadArgs simpleUserHooks

-- | A customizable version of 'defaultMainNoRead'.
defaultMainWithHooksNoRead :: UserHooks -> GenericPackageDescription -> IO ()
defaultMainWithHooksNoRead hooks pkg_descr =
getArgs >>=
getArgs >>= defaultMainWithHooksNoReadArgs hooks pkg_descr

defaultMainWithHooksNoReadArgs :: UserHooks -> GenericPackageDescription
-> [String] -> IO ()
defaultMainWithHooksNoReadArgs hooks pkg_descr =
defaultMainHelper hooks { readDesc = return (Just pkg_descr) }

defaultMainHelper :: UserHooks -> Args -> IO ()
Expand Down Expand Up @@ -239,9 +247,6 @@ confPkgDescr hooks verbosity mb_path = do
pdfile <- case mb_path of
Nothing -> defaultPackageDesc verbosity
Just path -> return path
#ifdef CABAL_PARSEC
info verbosity "Using Parsec parser"
#endif
descr <- readGenericPackageDescription verbosity pdfile
return (Just pdfile, descr)

Expand Down
32 changes: 19 additions & 13 deletions etlas-cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,22 +1472,28 @@ defaultPackageDesc :: Verbosity -> IO FilePath
defaultPackageDesc _verbosity = tryFindPackageDesc currentDir

-- |Find a package description file in the given directory. Looks for
-- @.cabal@ files.
-- an @etlas.dhall@ file or @.cabal@ files.
findPackageDesc :: FilePath -- ^Where to look
-> NoCallStackIO (Either String FilePath) -- ^<pkgname>.cabal
findPackageDesc dir
= do files <- getDirectoryContents dir
-- to make sure we do not mistake a ~/.cabal/ dir for a <pkgname>.cabal
-- file we filter to exclude dirs and null base file names:
cabalFiles <- filterM doesFileExist
[ dir </> file
| file <- files
, let (name, ext) = splitExtension file
, not (null name) && ext == ".cabal" ]
case cabalFiles of
[] -> return (Left noDesc)
[cabalFile] -> return (Right cabalFile)
multiple -> return (Left $ multiDesc multiple)
= do let dhallFile = dir </> "etlas.dhall"

existDhallFile <- doesFileExist dhallFile

if existDhallFile then return (Right dhallFile)
else do
files <- getDirectoryContents dir
-- to make sure we do not mistake a ~/.cabal/ dir for a <pkgname>.cabal
-- file we filter to exclude dirs and null base file names:
cabalFiles <- filterM doesFileExist
[ dir </> file
| file <- files
, let (name, ext) = splitExtension file
, not (null name) && ext == ".cabal" ]
case cabalFiles of
[] -> return (Left noDesc)
[cabalFile] -> return (Right cabalFile)
multiple -> return (Left $ multiDesc multiple)

where
noDesc :: String
Expand Down
2 changes: 1 addition & 1 deletion etlas-cabal/etlas-cabal.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: etlas-cabal
-- @VERSION
version: 1.5.1.0
version: 1.6.0.0
copyright: 2017, TypeLead, Inc.
license: BSD3
license-file: LICENSE
Expand Down
15 changes: 5 additions & 10 deletions etlas/Distribution/Client/BinaryDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ import Distribution.PackageDescription
( PackageDescription )
import Distribution.PackageDescription.Configuration
( flattenPackageDescription )
#ifdef CABAL_PARSEC
import Distribution.PackageDescription.Parsec
import Distribution.Client.PackageDescription.Dhall
( readGenericPackageDescription )
#else
import Distribution.PackageDescription.Parse
( readGenericPackageDescription )
#endif
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, defaultPackageDesc
, withTempDirectory )
Expand All @@ -38,13 +33,13 @@ import Distribution.Simple.BuildPaths ( binPref )
import Distribution.Text ( display )

import System.FilePath ((</>))
import Control.Monad (liftM)

-- |Create a binary distribution.
bdist :: BDistFlags -> BDistExFlags -> IO ()
bdist flags exflags = do
pkg <- liftM flattenPackageDescription
(readGenericPackageDescription verbosity =<< defaultPackageDesc verbosity)
genPkg <- readGenericPackageDescription verbosity =<< defaultPackageDesc verbosity
let pkg = flattenPackageDescription genPkg

let withDir :: (FilePath -> IO a) -> IO a
withDir = withTempDirectory verbosity tmpTargetDir "bdist."

Expand All @@ -57,7 +52,7 @@ bdist flags exflags = do
createDirectoryIfMissingVerbose verbosity True outDir
createDirectoryIfMissingVerbose verbosity True tarBallPath

setupWrapper verbosity setupOpts (Just pkg) bdistCommand (const flags') []
setupWrapper verbosity setupOpts (Just genPkg) (Just pkg) bdistCommand (const flags') []

createArchive verbosity pkg tmpDir tarBallPath

Expand Down
7 changes: 2 additions & 5 deletions etlas/Distribution/Client/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ module Distribution.Client.Check (

import Control.Monad ( when, unless )

#ifdef CABAL_PARSEC
import Distribution.PackageDescription.Parsec ( readGenericPackageDescription )
#else
import Distribution.PackageDescription.Parse ( readGenericPackageDescription )
#endif
import Distribution.Client.PackageDescription.Dhall
( readGenericPackageDescription )

import Distribution.PackageDescription.Check
import Distribution.PackageDescription.Configuration
Expand Down
11 changes: 3 additions & 8 deletions etlas/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ import Distribution.Package
import Distribution.Types.Dependency
( Dependency(..), thisPackageVersion )
import qualified Distribution.PackageDescription as PkgDesc
#ifdef CABAL_PARSEC
import Distribution.PackageDescription.Parsec
import Distribution.Client.PackageDescription.Dhall
( readGenericPackageDescription )
#else
import Distribution.PackageDescription.Parse
( readGenericPackageDescription )
#endif
import Distribution.PackageDescription.Configuration
( finalizePD )
import Distribution.Version
Expand Down Expand Up @@ -144,7 +139,7 @@ configure verbosity packageDBs repoCtxt binariesPath comp platform progdb
++ message
++ "\nTrying configure anyway."
setupWrapper verbosity (setupScriptOptions installedPkgIndex Nothing)
Nothing configureCommand (const configFlags) extraArgs
Nothing Nothing configureCommand (const configFlags) extraArgs

Right installPlan0 ->
let installPlan = InstallPlan.configureInstallPlan configFlags installPlan0
Expand Down Expand Up @@ -397,7 +392,7 @@ configurePackage verbosity platform comp scriptOptions configFlags
extraArgs =

setupWrapper verbosity
scriptOptions (Just pkg) configureCommand configureFlags extraArgs
scriptOptions (Just gpkg) (Just pkg) configureCommand configureFlags extraArgs

where
gpkg = packageDescription spkg
Expand Down
7 changes: 1 addition & 6 deletions etlas/Distribution/Client/GenBounds.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ import Distribution.PackageDescription
( buildDepends )
import Distribution.PackageDescription.Configuration
( finalizePD )
#ifdef CABAL_PARSEC
import Distribution.PackageDescription.Parsec
import Distribution.Client.PackageDescription.Dhall
( readGenericPackageDescription )
#else
import Distribution.PackageDescription.Parse
( readGenericPackageDescription )
#endif
import Distribution.Types.ComponentRequestedSpec
( defaultComponentRequestedSpec )
import Distribution.Types.Dependency
Expand Down
4 changes: 2 additions & 2 deletions etlas/Distribution/Client/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do

checkTarget :: Verbosity -> UserTarget -> IO ()
checkTarget verbosity target = case target of
UserTargetLocalDir dir -> die' verbosity (notTarball dir)
UserTargetLocalCabalFile file -> die' verbosity (notTarball file)
UserTargetLocalDir dir -> die' verbosity (notTarball dir)
UserTargetLocalPkgConfigFile file -> die' verbosity (notTarball file)
_ -> return ()
where
notTarball t =
Expand Down
Loading

0 comments on commit e9b0966

Please sign in to comment.