implicit-hie-cradle (empty) → 0.1.0.0
raw patch · 7 files changed
+292/−0 lines, 7 filesdep +basedep +base16-bytestringdep +bytestringsetup-changed
Dependencies added: base, base16-bytestring, bytestring, containers, directory, extra, filepath, hie-bios, hslogger, implicit-hie, implicit-hie-cradle, process, temporary, text, time, transformers, unix-compat, unordered-containers, vector, yaml
Files
- ChangeLog.md +3/−0
- LICENSE +30/−0
- README.md +1/−0
- Setup.hs +2/−0
- implicit-hie-cradle.cabal +73/−0
- src/Hie/Implicit/Cradle.hs +181/−0
- test/Spec.hs +2/−0
+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for implicit-hie-cradle++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Avi Dessauer (c) 2020++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Avi Dessauer nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# implicit-hie-cradle
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ implicit-hie-cradle.cabal view
@@ -0,0 +1,73 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.33.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: 5c092074b2128d5593e67e2ace6e214ab27a89b73a7a71a71b212a4b34868b86++name: implicit-hie-cradle+version: 0.1.0.0+description: Auto generate a stack or cabal multi component cradles+category: Development, Tools, Hie, HLS+synopsis: Auto generate hie-bios cradles+homepage: https://github.com/Avi-D-coder/implicit-hie-cradle#readme+bug-reports: https://github.com/Avi-D-coder/implicit-hie-cradle/issues+author: Avi Dessauer+maintainer: avi.the.coder@gmail.com+copyright: 2020+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://github.com/Avi-D-coder/implicit-hie-cradle++library+ exposed-modules: Hie.Implicit.Cradle+ other-modules: Paths_implicit_hie_cradle+ autogen-modules: Paths_implicit_hie_cradle+ hs-source-dirs: src+ build-depends:+ base >=4.8 && <5+ , base16-bytestring >=0.1.1 && <0.2+ , bytestring >=0.10.8 && <0.11+ , containers >=0.5.10 && <0.7+ , directory >=1.3.0 && <1.4+ , extra >=1.6.14 && <1.8+ , filepath >=1.4.1 && <1.5+ , hie-bios >=0.5.1+ , hslogger >=1.2 && <1.4+ , implicit-hie+ , process >=1.6.1 && <1.7+ , temporary >=1.2 && <1.4+ , text >=1.2.3 && <1.3+ , time >=1.8.0 && <1.10+ , transformers >=0.5.2 && <0.6+ , unix-compat >=0.5.1 && <0.6+ , unordered-containers >=0.2.9 && <0.3+ , vector >=0.12.0 && <0.13+ , yaml >=0.8.32 && <0.12++ default-language: Haskell2010+ ghc-options:+ -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns+ -fno-warn-unused-imports -fno-warn-unused-binds+ -fno-warn-name-shadowing -fwarn-redundant-constraints++test-suite implicit-hie-cradle-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules: Paths_implicit_hie_cradle+ autogen-modules: Paths_implicit_hie_cradle+ hs-source-dirs: test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , implicit-hie-cradle++ default-language: Haskell2010
+ src/Hie/Implicit/Cradle.hs view
@@ -0,0 +1,181 @@+{-# LANGUAGE ScopedTypeVariables #-}++-- Code is derived from https://github.com/mpickering/hie-bios/blob/master/src/HIE/Bios/Cradle.hs+-- git commit: 6460ab40709fe5cc6209b2094d32f80d46c889fd+-- Derived code subject to hie-bios's BSD 3-Clause "New" or "Revised" License+-- Hie-bios's license is distributed with the hie-bios dependency+-- Initial differences can be found at https://github.com/mpickering/hie-bios/pull/178++module Hie.Implicit.Cradle+ ( loadImplicitHieCradle,+ )+where++import Control.Applicative ((<|>))+import Control.Exception (handleJust)+import Control.Monad+import Control.Monad.IO.Class+import Control.Monad.Trans.Maybe+import Data.List+import Data.Maybe+import Data.Ord (Down (..))+import qualified Data.Text as T+import Data.Void+import qualified Data.Yaml as Yaml+import GHC.Fingerprint (fingerprintString)+import HIE.Bios.Config+import HIE.Bios.Cradle+import HIE.Bios.Environment (getCacheDir)+import HIE.Bios.Types hiding (ActionName (..))+import qualified HIE.Bios.Types as Types+import HIE.Bios.Wrappers+import Hie.Cabal.Parser+import Hie.Locate+import Hie.Yaml+import System.Directory hiding (findFile)+import System.Environment+import System.Exit+import System.FilePath+import System.IO+import System.IO.Error (isPermissionError)+import System.IO.Temp+import System.Info.Extra (isWindows)+import System.PosixCompat.Files+import System.Process++-- | Given root\/foo\/bar.hs, load an implicit cradle+loadImplicitHieCradle :: FilePath -> IO (Cradle a)+loadImplicitHieCradle wfile = do+ let wdir = takeDirectory wfile+ cfg <- runMaybeT (implicitConfig wdir)+ return $ case cfg of+ Just bc -> getCradle absurd bc+ Nothing -> defaultCradle wdir++implicitConfig :: FilePath -> MaybeT IO (CradleConfig a, FilePath)+implicitConfig fp = do+ (crdType, wdir) <- implicitConfig' fp+ return (CradleConfig [] crdType, wdir)++implicitConfig' :: FilePath -> MaybeT IO (CradleType a, FilePath)+implicitConfig' fp =+ ( \wdir ->+ (Bios (wdir </> ".hie-bios") Nothing, wdir)+ )+ <$> biosWorkDir fp+ -- <|> (Obelisk,) <$> obeliskWorkDir fp+ -- <|> (Bazel,) <$> rulesHaskellWorkDir fp+ <|> (cabalExecutable >> cabalProjectDir fp >> cabalDistDir fp >>= cabal)+ <|> (stackExecutable >> stackYamlDir fp >> stackWorkDir fp >>= stack)+ <|> (cabalExecutable >> cabalProjectDir fp >>= cabal)+ <|> (stackExecutable >> stackYamlDir fp >>= stack)+ <|> (cabalExecutable >> cabalFile fp >>= cabal)+ where+ readPkgs f gp p = do+ cfs <- gp p+ pkgs <- liftIO $ catMaybes <$> mapM (nestedPkg p) cfs+ pure $ concatMap (components f) pkgs+ build cn cc gp p = do+ c <- cn <$> readPkgs cc gp p+ pure (c, p)+ cabal :: FilePath -> MaybeT IO (CradleType a, FilePath)+ cabal = build CabalMulti cabalComponent cabalPkgs+ stack = build StackMulti stackComponent stackYamlPkgs+ components f (Package n cs) = map (f n) cs++------------------------------------------------------------------------+-- Cabal Cradle+-- Works for new-build by invoking `v2-repl` does not support components+-- yet.+cabalCradleDependencies :: FilePath -> IO [FilePath]+cabalCradleDependencies rootDir = do+ cabalFiles <- findCabalFiles rootDir+ return $ cabalFiles ++ ["cabal.project", "cabal.project.local"]++findCabalFiles :: FilePath -> IO [FilePath]+findCabalFiles wdir = do+ dirContent <- listDirectory wdir+ return $ filter ((== ".cabal") . takeExtension) dirContent++-- | GHC process information.+-- Consists of the filepath to the ghc executable and+-- arguments to the executable.+type GhcProc = (FilePath, [String])++cabalExecutable :: MaybeT IO FilePath+cabalExecutable = MaybeT $ findExecutable "cabal"++cabalDistDir :: FilePath -> MaybeT IO FilePath+cabalDistDir = findFileUpwards isCabal+ where+ -- TODO do old style dist builds work?+ isCabal name = name == "dist-newstyle" || name == "dist"++cabalProjectDir :: FilePath -> MaybeT IO FilePath+cabalProjectDir = findFileUpwards isCabal+ where+ isCabal name = name == "cabal.project"++cabalFile :: FilePath -> MaybeT IO FilePath+cabalFile = findFileUpwards isCabal+ where+ isCabal = (".cabal" ==) . takeExtension++------------------------------------------------------------------------+-- Stack Cradle+-- Works for by invoking `stack repl` with a wrapper script++stackCradleDependencies :: FilePath -> IO [FilePath]+stackCradleDependencies wdir = do+ cabalFiles <- findCabalFiles wdir+ return $ cabalFiles ++ ["package.yaml", "stack.yaml"]++combineExitCodes :: [ExitCode] -> ExitCode+combineExitCodes = foldr go ExitSuccess+ where+ go ExitSuccess b = b+ go a _ = a++stackExecutable :: MaybeT IO FilePath+stackExecutable = MaybeT $ findExecutable "stack"++stackWorkDir :: FilePath -> MaybeT IO FilePath+stackWorkDir = findFileUpwards isStack+ where+ isStack name = name == ".stack-work"++stackYamlDir :: FilePath -> MaybeT IO FilePath+stackYamlDir = findFileUpwards isStack+ where+ isStack name = name == "stack.yaml"++-- | Searches upwards for the first directory containing a file to match+-- the predicate.+findFileUpwards :: (FilePath -> Bool) -> FilePath -> MaybeT IO FilePath+findFileUpwards p dir = do+ cnts <-+ liftIO $+ handleJust+ -- Catch permission errors+ (\(e :: IOError) -> if isPermissionError e then Just [] else Nothing)+ pure+ (findFile p dir)+ case cnts of+ []+ | dir' == dir -> fail "No cabal files"+ | otherwise -> findFileUpwards p dir'+ _ : _ -> return dir+ where+ dir' = takeDirectory dir++-- | Sees if any file in the directory matches the predicate+findFile :: (FilePath -> Bool) -> FilePath -> IO [FilePath]+findFile p dir = do+ b <- doesDirectoryExist dir+ if b then getFiles else pure []+ where+ getFiles = filter p <$> getDirectoryContents dir+ doesPredFileExist file = doesFileExist $ dir </> file++biosWorkDir :: FilePath -> MaybeT IO FilePath+biosWorkDir = findFileUpwards (".hie-bios" ==)
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"