shake-futhark (empty) → 0.1.0.0
raw patch · 5 files changed
+124/−0 lines, 5 filesdep +basedep +containersdep +filepath
Dependencies added: base, containers, filepath, futhark, shake, text
Files
- CHANGELOG.md +5/−0
- LICENSE +11/−0
- README.md +7/−0
- shake-futhark.cabal +48/−0
- src/Development/Shake/Futhark.hs +53/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# shake-futhark++## 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-futhark++Get transitive dependencies via the [futhark+library](http://hackage.haskell.org/package/futhark).++This can be used with [shake](https://shakebuild.com/) for sensible dependency+tracking.
+ shake-futhark.cabal view
@@ -0,0 +1,48 @@+cabal-version: 1.18+name: shake-futhark+version: 0.1.0.0+license: BSD3+license-file: LICENSE+copyright: Copyright: (c) 2020 Vanessa McHale+maintainer: vamchale@gmail.com+author: Vanessa McHale+synopsis: Dependency tracking for Futhark+description:+ Dependency trakcing using the [futhark library](http://hackage.haskell.org/package/futhark) for transitive dependencies in Futhark projects++category: Futhark, Shake, Development, Build+build-type: Simple+extra-doc-files:+ README.md+ CHANGELOG.md++source-repository head+ type: git+ location: https://github.com/vmchale/shake-futhark++library+ exposed-modules: Development.Shake.Futhark+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall+ build-depends:+ base >=4.3 && <5,+ futhark >=0.15,+ shake -any,+ text -any,+ filepath -any,+ containers >=0.6++ 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/Futhark.hs view
@@ -0,0 +1,53 @@+module Development.Shake.Futhark ( getFutDeps+ , getAllFutDeps+ , needFut+ ) where++import Control.Monad.IO.Class (liftIO)+import Data.Containers.ListUtils (nubOrd)+import qualified Data.Text.IO as TIO+import Development.Shake (Action, need)+import Language.Futhark.Parser (parseFuthark)+import Language.Futhark.Syntax (DecBase (..), ModBindBase (ModBind), ModExpBase (..), ProgBase (Prog))+import System.FilePath (takeDirectory, (<.>), (</>))++-- | @'need'@ a file and all its dependencies+needFut :: [FilePath] -> Action ()+needFut fps =+ need =<< liftIO (mconcat . (fps :) <$> traverse getAllFutDeps fps)++getFutDeps :: FilePath -> IO [FilePath]+getFutDeps fp = do+ contents <- TIO.readFile fp+ let dirFile = takeDirectory fp+ parsed = either (error.show) id $ parseFuthark fp contents+ pure ((dirFile </>) . (<.> "fut") <$> extractFromProgBase parsed)++-- | Get all transitive dependencies+getAllFutDeps :: FilePath -> IO [FilePath]+getAllFutDeps fp = do+ deps <- getFutDeps fp+ level <- traverse getFutDeps deps+ let next = nubOrd (mconcat (deps : level))+ pure $ if null level then deps else next++extractFromProgBase :: ProgBase f vn -> [FilePath]+extractFromProgBase (Prog _ ds) = concatMap extractFromDecBase ds++extractFromDecBase :: DecBase f vn -> [FilePath]+extractFromDecBase (ImportDec fp _ _) = [fp]+extractFromDecBase (LocalDec d _) = extractFromDecBase d+extractFromDecBase (OpenDec d _) = extractFromModExpBase d+extractFromDecBase (ModDec (ModBind _ _ _ m _ _)) = extractFromModExpBase m+extractFromDecBase ValDec{} = []+extractFromDecBase TypeDec{} = []+extractFromDecBase SigDec{} = []++extractFromModExpBase :: ModExpBase f vn -> [FilePath]+extractFromModExpBase (ModParens m _) = extractFromModExpBase m+extractFromModExpBase (ModImport fp _ _) = [fp]+extractFromModExpBase (ModDecs ds _) = concatMap extractFromDecBase ds+extractFromModExpBase (ModApply m m' _ _ _) = concatMap extractFromModExpBase [m, m']+extractFromModExpBase (ModAscript m _ _ _) = extractFromModExpBase m+extractFromModExpBase (ModLambda _ _ m _) = extractFromModExpBase m+extractFromModExpBase ModVar{} = []