packages feed

ats-setup (empty) → 0.1.0.0

raw patch · 5 files changed

+153/−0 lines, 5 filesdep +Cabaldep +basedep +directorysetup-changed

Dependencies added: Cabal, base, directory, http-client, http-client-tls, parallel-io, tar, zlib

Files

+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2018++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,5 @@+# ats-setup++## Installation++## Configuration
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ats-setup.cabal view
@@ -0,0 +1,41 @@+name:                ats-setup+version:             0.1.0.0+synopsis:            ATS scripts for Cabal builds+description:         This package contains various scripts that go in a package's @Setup.hs@ to make building libraries with ATS dependencies easier.+license:             BSD3+license-file:        LICENSE+author:              Vanessa McHale+maintainer:          vamchale@gmail.com+copyright:           Copyright: (c) 2018 Vanessa McHale+category:            ATS, Development, Cabal+build-type:          Simple+extra-doc-files:     README.md+cabal-version:       1.18++Flag development {+  Description: Enable `-Werror`+  manual: True+  default: False+}++library+  hs-source-dirs:      src+  exposed-modules:     Distribution.ATS+  build-depends:       base >= 4.8 && < 5+                     , Cabal >= 2.0+                     , directory+                     , zlib+                     , http-client-tls+                     , tar+                     , http-client+                     , parallel-io+  default-language:    Haskell2010+  if flag(development)+    ghc-options:       -Werror+  if impl(ghc >= 8.0)+    ghc-options:       -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat+  ghc-options:         -Wall++source-repository head+  type:     darcs+  location: https://hub.darcs.net/vmchale/ats
+ src/Distribution/ATS.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE OverloadedStrings #-}++module Distribution.ATS ( cleanATSCabal+                        , atsUserHooks+                        , fetchDependencies+                        -- * Types+                        , ATSVersion+                        , ATSDependency (..)+                        -- * Libraries+                        , libgmp+                        , intinf+                        , atsPrelude+                        ) where++import qualified Codec.Archive.Tar                    as Tar+import           Codec.Compression.GZip               (decompress)+import           Control.Concurrent.ParallelIO.Global+import           Control.Monad+import           Data.List                            (intercalate)+import           Distribution.PackageDescription+import           Distribution.Simple+import           Distribution.Simple.LocalBuildInfo+import           Distribution.Simple.Setup+import           Network.HTTP.Client                  hiding (decompress)+import           Network.HTTP.Client.TLS              (tlsManagerSettings)+import           System.Directory++-- | ATS library version to use, e.g. @[0,3,8]@ for @0.3.8@.+type ATSVersion = [Integer]++data ATSDependency = ATSDependency { _libName  :: String -- ^ Library name+                                   , _filepath :: FilePath -- ^ Directory to unpack library into+                                   , _url      :: String -- ^ URL of tarball containing ATS library.+                                   }++maybeCleanBuild :: LocalBuildInfo -> IO ()+maybeCleanBuild li =+    let cf = configConfigurationsFlags (configFlags li) in++    unless ((mkFlagName "development", True) `elem` cf) $+        putStrLn "Cleaning up ATS dependencies..." >>+        cleanATSCabal++-- | This generates user hooks for a Cabal distribution that has some ATS+-- library dependencies. For an example of its use, see the @Setup.hs@ of+-- [fast-arithmetic](https://hackage.haskell.org/package/fast-arithmetic)+atsUserHooks :: [ATSDependency] -> UserHooks+atsUserHooks deps = simpleUserHooks { preConf = \_ _ -> fetchDependencies deps >> pure emptyHookedBuildInfo+                                    , postBuild = \_ _ _ -> maybeCleanBuild+                                    }++cleanATSCabal :: IO ()+cleanATSCabal = removeDirectoryRecursive "ats-deps"++-- | GMP bindings for ATS+libgmp :: ATSDependency+libgmp = ATSDependency "atscntrb-libgmp-1.0.4" "ats-deps/contrib/atscntrb-libgmp" "https://registry.npmjs.org/atscntrb-libgmp/-/atscntrb-libgmp-1.0.4.tgz"++-- | Arbitrary-precision arithmetic library for ATS+intinf :: ATSDependency+intinf = ATSDependency "atscntrb-hs-intinf-1.0.6" "ats-deps/contrib/atscntrb-hx-intinf" "https://registry.npmjs.org/atscntrb-hx-intinf/-/atscntrb-hx-intinf-1.0.6.tgz"++-- https://registry.npmjs.org/ats-postiats-include/-/ats-postiats-include-1.0.0.tgz++-- | ATS prelude+atsPrelude :: ATSVersion -> ATSDependency+atsPrelude v = ATSDependency ("ats2-postiats-" ++ vString ++ "-prelude") "ats-deps/prelude" ("https://downloads.sourceforge.net/project/ats2-lang/ats2-lang/ats2-postiats-" ++ vString ++ "/ATS2-Postiats-include-" ++ vString ++ ".tgz")+    where vString = intercalate "," . fmap show $ v++fetchDependencies :: [ATSDependency] -> IO ()+fetchDependencies = (>> stopGlobalPool) . parallel_ . fmap fetchDependency++fetchDependency :: ATSDependency -> IO ()+fetchDependency (ATSDependency libNameATS dirName url) = do++    needsSetup <- not <$> doesDirectoryExist dirName++    when needsSetup $ do++        let doing str = putStrLn (str ++ " library " ++ libNameATS ++ "...")+        doing "Fetching"+        manager <- newManager tlsManagerSettings+        initialRequest <- parseRequest url+        response <- responseBody <$> httpLbs (initialRequest { method = "GET" }) manager++        doing "Unpacking"+        Tar.unpack dirName . Tar.read . decompress $ response++        doing "Setting up"+        needsMove <- doesDirectoryExist (dirName ++ "/package")+        when needsMove $ do+            renameDirectory (dirName ++ "/package") "tempdir"+            removeDirectoryRecursive dirName+            renameDirectory "tempdir" dirName