packages feed

shake-dhall (empty) → 0.1.0.0

raw patch · 6 files changed

+124/−0 lines, 6 filesdep +basedep +containersdep +dhall

Dependencies added: base, containers, dhall, filepath, shake, text

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# shake-dhall++## 0.1.0.0++Initial release
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2020++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its 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 HOLDER 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,7 @@+# shake-dhall++shake-dhall uses the [dhall library](http://hackage.haskell.org/package/dhall)+to find local (filesystem) dependencies (imports).++This means that dhall can be used sensibly with+[shake](https://shakebuild.com/).
+ shake-dhall.cabal view
@@ -0,0 +1,49 @@+cabal-version:   1.18+name:            shake-dhall+version:         0.1.0.0+license:         BSD3+license-file:    LICENSE+copyright:       Copyright: (c) 2020 Vanessa McHale+maintainer:      vamchale@gmail.com+author:          Vanessa McHale+synopsis:        Dhall dependencies+description:     Dependency tracking in Dhall+category:        Language, Dhall+build-type:      Simple+extra-doc-files:+    README.md+    CHANGELOG.md++source-repository head+    type:     git+    location: https://github.com/vmchale/shake-dhall++library+    exposed-modules:+        Dhall.Dep+        Development.Shake.Dhall++    hs-source-dirs:   src+    default-language: Haskell2010+    ghc-options:      -Wall+    build-depends:+        base >=4.9 && <5,+        dhall >=1.25.0,+        text -any,+        containers >=0.6,+        shake -any,+        filepath -any++    if impl(ghc >=8.0)+        ghc-options:+            -Wincomplete-uni-patterns -Wincomplete-record-updates+            -Wredundant-constraints -Widentities++    if impl(ghc >=8.4)+        ghc-options: -Wmissing-export-lists++    if impl(ghc >=8.2)+        ghc-options: -Wcpp-undef++    if impl(ghc >=8.10)+        ghc-options: -Wunused-packages
+ src/Development/Shake/Dhall.hs view
@@ -0,0 +1,13 @@+module Development.Shake.Dhall ( needDhall+                               ) where++import           Control.Monad.IO.Class    (liftIO)+import           Data.Containers.ListUtils (nubOrd)+import           Development.Shake         (Action, need)+import           Dhall.Dep++-- | Need some @.dhall@ files and imported dependencies+needDhall :: [FilePath] -> Action ()+needDhall fps = do+    transDeps <- liftIO (concat <$> traverse getAllFileDeps fps)+    need (fps ++ nubOrd transDeps)
+ src/Dhall/Dep.hs view
@@ -0,0 +1,39 @@+module Dhall.Dep ( getFileDeps+                 , getAllFileDeps+                 ) where++import           Control.Exception         (throw)+import           Data.Containers.ListUtils (nubOrd)+import           Data.Foldable             (toList)+import           Data.Maybe                (catMaybes)+import qualified Data.Text.IO              as T+import           Dhall.Core                (Import, ImportType (..),+                                            importHashed, importType)+import           Dhall.Import              (localToPath)+import           Dhall.Parser              (exprFromText)+import           System.FilePath           (isAbsolute, takeDirectory, (</>))++-- | Given a path, the file paths it depends on+getFileDeps :: FilePath -> IO [FilePath]+getFileDeps fp = do+    contents <- T.readFile fp+    let fileDir = takeDirectory fp+        fileMod fp' = if isAbsolute fp' then fp' else fileDir </> fp'+        tree = either throw id (exprFromText fp contents)+        imports = toList tree+    catMaybes <$> traverse (fmap (fileMod <$>) . fromImport) imports++-- | Get all transitive dependencies+getAllFileDeps :: FilePath -> IO [FilePath]+getAllFileDeps fp = do+    deps <- getFileDeps fp+    level <- traverse getFileDeps deps+    let next = nubOrd (mconcat (deps : level))+    pure $ if null level then deps else next++fromImport :: Import -> IO (Maybe FilePath)+fromImport = fromImportType . importType . importHashed++fromImportType :: ImportType -> IO (Maybe FilePath)+fromImportType (Local pre fp) = Just <$> localToPath pre fp+fromImportType _              = pure Nothing