├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── extract-dependencies ├── .gitignore ├── LICENSE ├── Setup.hs ├── extract-dependencies.cabal ├── src │ ├── Development │ │ └── ExtractDependencies.hs │ └── Main.hs └── stack.yaml ├── file-modules ├── .gitignore ├── LICENSE ├── Makefile ├── Setup.hs ├── file-modules.cabal ├── src │ ├── Development │ │ └── FileModules.hs │ └── Main.hs ├── stack-6.9.yaml ├── stack-new-hs-src-exts.yaml ├── stack-nightly.yaml └── stack.yaml ├── module-package ├── package-description-remote ├── LICENSE ├── Setup.hs ├── package-description-remote.cabal ├── src │ └── Distribution │ │ └── PackageDescription │ │ └── Remote.hs ├── stack.yaml └── test │ └── Spec.hs ├── stack-run-auto ├── LICENSE ├── Setup.hs ├── app │ ├── Main.hs │ └── ModulePackage.hs ├── src │ └── StackRunAuto.hs ├── stack-run-auto.cabal ├── stack.yaml └── test │ └── Spec.hs ├── stack-try └── test-files ├── DistributedProcess.hs ├── Test.hs └── Test2.hs /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .stack-work 3 | dist 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This file has been generated -- see https://github.com/hvr/multi-ghc-travis 2 | language: c 3 | sudo: false 4 | 5 | cache: 6 | directories: 7 | - $HOME/.cabsnap 8 | - $HOME/.cabal/packages 9 | 10 | before_cache: 11 | - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log 12 | - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar 13 | 14 | matrix: 15 | include: 16 | #- env: CABALVER=1.18 GHCVER=7.8.1 17 | #compiler: ": #GHC 7.8.1" 18 | #addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.1], sources: [hvr-ghc]}} 19 | #- env: CABALVER=1.18 GHCVER=7.8.2 20 | #compiler: ": #GHC 7.8.2" 21 | #addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.2], sources: [hvr-ghc]}} 22 | #- env: CABALVER=1.18 GHCVER=7.8.3 23 | #compiler: ": #GHC 7.8.3" 24 | #addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.3], sources: [hvr-ghc]}} 25 | #- env: CABALVER=1.18 GHCVER=7.8.4 26 | #compiler: ": #GHC 7.8.4" 27 | #addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}} 28 | - env: CABALVER=1.22 GHCVER=7.10.1 29 | compiler: ": #GHC 7.10.1" 30 | addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1], sources: [hvr-ghc]}} 31 | - env: CABALVER=1.22 GHCVER=7.10.2 32 | compiler: ": #GHC 7.10.2" 33 | addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2], sources: [hvr-ghc]}} 34 | - env: CABALVER=1.22 GHCVER=7.10.3 35 | compiler: ": #GHC 7.10.3" 36 | addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3], sources: [hvr-ghc]}} 37 | - env: CABALVER=head GHCVER=head 38 | compiler: ": #GHC head" 39 | addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}} 40 | 41 | allow_failures: 42 | - env: CABALVER=head GHCVER=head 43 | 44 | before_install: 45 | - unset CC 46 | - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH 47 | 48 | install: 49 | - cabal --version 50 | - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]" 51 | - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ]; 52 | then 53 | zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz > 54 | $HOME/.cabal/packages/hackage.haskell.org/00-index.tar; 55 | fi 56 | - travis_retry cabal update -v 57 | - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config 58 | - cd ./file-modules && cabal install --only-dependencies --enable-tests --enable-benchmarks -v && cd .. 59 | - cd ./extract-dependencies && cabal install --only-dependencies --enable-tests --enable-benchmarks -v && cd .. 60 | - cd ./package-description-remote && cabal install --only-dependencies --enable-tests --enable-benchmarks -v && cd .. 61 | - cd ./stack-run-auto && cabal install --only-dependencies --enable-tests --enable-benchmarks -v && cd .. 62 | 63 | # Here starts the actual work to be performed for the package under test; 64 | # any command which exits with a non-zero exit code causes the build to fail. 65 | script: 66 | - cd extract-dependencies && if [ -f configure.ac ]; then autoreconf -i; fi 67 | - cd extract-dependencies && cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging 68 | - cd extract-dependencies && cabal build # this builds all libraries and executables (including tests/benchmarks) 69 | - cd extract-dependencies && cabal test 70 | - cd extract-dependencies && cabal check 71 | - cd extract-dependencies && cabal sdist # tests that a source-distribution can be generated 72 | - cd package-description-remote && if [ -f configure.ac ]; then autoreconf -i; fi 73 | - cd package-description-remote && cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging 74 | - cd package-description-remote && cabal build # this builds all libraries and executables (including tests/benchmarks) 75 | - cd package-description-remote && cabal test 76 | - cd package-description-remote && cabal check 77 | - cd package-description-remote && cabal sdist # tests that a source-distribution can be generated 78 | - cd stack-run-auto && if [ -f configure.ac ]; then autoreconf -i; fi 79 | - cd stack-run-auto && cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging 80 | - cd stack-run-auto && cabal build # this builds all libraries and executables (including tests/benchmarks) 81 | - cd stack-run-auto && cabal test 82 | - cd stack-run-auto && cabal check 83 | - cd stack-run-auto && cabal sdist # tests that a source-distribution can be generated 84 | - cd file-modules && if [ -f configure.ac ]; then autoreconf -i; fi 85 | - cd file-modules && cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging 86 | - cd file-modules && cabal build # this builds all libraries and executables (including tests/benchmarks) 87 | - cd file-modules && cabal test 88 | - cd file-modules && cabal check 89 | - cd file-modules && cabal sdist # tests that a source-distribution can be generated 90 | 91 | # Check that the resulting source distribution can be built & installed. 92 | # If there are no other `.tar.gz` files in `dist`, this can be even simpler: 93 | # `cabal install --force-reinstalls dist/*-*.tar.gz` 94 | - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz && 95 | (cd dist && cabal install --force-reinstalls "$SRC_TGZ") 96 | 97 | # EOF 98 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pedro Tacla Yamada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | EXECS=file-modules extract-dependencies stack-run-auto 2 | 3 | all: $(EXECS) 4 | cd stack-run-auto && cp `stack path --dist-dir`/build/module-package/module-package ../dist/module-package 5 | 6 | $(EXECS): FORCE 7 | cd $@ && stack build && cp `stack path --dist-dir`/build/$@/$@ ../dist/$@ 8 | 9 | FORCE: 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | stack-run-auto 2 | ============== 3 | Automatically finds dependencies and runs a Haskell script (no cabal manifest, 4 | no stack.yaml, no project). 5 | 6 | ## Installation 7 | With stack: 8 | ``` 9 | stack install stack-run-auto 10 | ``` 11 | 12 | Manually *(recommended)*: 13 | ``` 14 | git clone https://github.com/yamadapc/stack-run-auto 15 | cd stack-run-auto/stack-run-auto 16 | stack install 17 | ``` 18 | 19 | ## Usage 20 | ``` 21 | stack-run-auto Test.hs 22 | ``` 23 | 24 | This will: 25 | - Find the imported modules from this Haskell file and it's local dependencies 26 | - Find the package containing each of these modules using the Hayoo 27 | search-engine to query for the module trying to find from which package it 28 | came from 29 | - Find dependencies for all the packages resolved 30 | - Cache this on `$HOME/.stack-run-auto` 31 | - Run `stack runghc File.hs --package package1 --package package2 ...` 32 | 33 | ## Example output on an Yesod project 34 | ``` 35 | ~ $ ./stack-run-auto Application.hs 36 | Parsing Application.hs 37 | ---> Parsed imports (0.009082s) 38 | Finding package for Yesod.Default.Config2... 39 | Finding package for Yesod.Core.Types... 40 | Finding package for Yesod.Static... 41 | Finding package for Yesod.Auth... 42 | Finding package for Yesod.Default.Util... 43 | Finding package for Network.Wai.Handler.Warp... 44 | Finding package for Language.Haskell.TH.Syntax... 45 | Finding package for Database.Persist.Postgresql... 46 | Finding package for Data.Yaml... 47 | Finding package for Data.FileEmbed... 48 | Finding package for Data.Aeson... 49 | Finding package for Control.Exception... 50 | Finding package for ClassyPrelude.Yesod... 51 | Finding package for Database.Persist.Quasi... 52 | Finding package for Yesod.Core.Unsafe... 53 | Finding package for Yesod.Auth.Message... 54 | Finding package for Yesod.Auth.Email... 55 | Finding package for Text.Jasmine... 56 | Finding package for Text.Hamlet... 57 | Finding package for Database.Persist.Sql... 58 | Finding package for System.Log.FastLogger... 59 | Finding package for Network.Wai.Middleware.RequestLogger... 60 | Finding package for Control.Monad.Logger... 61 | ---> Found package for Network.Wai.Handler.Warp (3.596237s) 62 | ---> Found package for Data.FileEmbed (3.613856s) 63 | ---> Found package for Database.Persist.Postgresql (3.628068s) 64 | ---> Found package for Database.Persist.Quasi (3.629282s) 65 | ---> Found package for Yesod.Default.Util (3.630724s) 66 | ---> Found package for Yesod.Core.Unsafe (3.633724s) 67 | ---> Found package for Yesod.Core.Types (3.634s) 68 | ---> Found package for Language.Haskell.TH.Syntax (3.640132s) 69 | ---> Found package for Yesod.Default.Config2 (3.640586s) 70 | ---> Found package for ClassyPrelude.Yesod (3.641378s) 71 | ---> Found package for Yesod.Auth.Message (3.64284s) 72 | ---> Found package for Yesod.Auth (3.646053s) 73 | ---> Found package for Data.Yaml (3.653229s) 74 | ---> Found package for Control.Monad.Logger (3.664165s) 75 | ---> Found package for Network.Wai.Middleware.RequestLogger (3.664609s) 76 | ---> Found package for Database.Persist.Sql (3.666917s) 77 | ---> Found package for Text.Hamlet (3.672066s) 78 | ---> Found package for Text.Jasmine (3.672255s) 79 | ---> Found package for Yesod.Auth.Email (3.679442s) 80 | ---> Found package for Data.Aeson (3.868004s) 81 | ---> Found package for Control.Exception (3.869141s) 82 | ---> Found package for Yesod.Static (3.909615s) 83 | ---> Found package for System.Log.FastLogger (3.914372s) 84 | Finding dependencies for yesod... 85 | Finding dependencies for yesod-core... 86 | Finding dependencies for yesod-auth... 87 | Finding dependencies for yesod-static... 88 | Finding dependencies for warp... 89 | Finding dependencies for template-haskell... 90 | Finding dependencies for persistent-postgresql... 91 | Finding dependencies for yaml... 92 | Finding dependencies for file-embed... 93 | Finding dependencies for aeson... 94 | Finding dependencies for base... 95 | Finding dependencies for classy-prelude-yesod... 96 | Finding dependencies for persistent... 97 | Finding dependencies for hjsmin... 98 | Finding dependencies for shakespeare... 99 | Finding dependencies for fast-logger... 100 | Finding dependencies for wai-extra... 101 | Finding dependencies for monad-logger... 102 | ---> Found dependencies for template-haskell (0.79311s) 103 | ---> Found dependencies for yesod-static (0.797071s) 104 | ---> Found dependencies for yesod (0.811596s) 105 | ---> Found dependencies for yesod-auth (0.831798s) 106 | ---> Found dependencies for file-embed (0.868215s) 107 | ---> Found dependencies for yesod-core (0.87035s) 108 | ---> Found dependencies for persistent-postgresql (0.892851s) 109 | ---> Found dependencies for yaml (0.900229s) 110 | ---> Found dependencies for classy-prelude-yesod (0.910601s) 111 | ---> Found dependencies for warp (0.912838s) 112 | ---> Found dependencies for shakespeare (0.917047s) 113 | ---> Found dependencies for aeson (0.923956s) 114 | ---> Found dependencies for fast-logger (0.928013s) 115 | ---> Found dependencies for persistent (0.9371s) 116 | ---> Found dependencies for monad-logger (0.93952s) 117 | ---> Found dependencies for wai-extra (0.942007s) 118 | ---> Found dependencies for hjsmin (0.942088s) 119 | ---> Found dependencies for base (0.947236s) 120 | stack runghc Application.hs --package yesod --package yesod-core --package yesod-auth --package yesod-static --package warp --package template-haskell --package persistent-postgresql --package yaml --package file-embed --package aeson --package base --package classy-prelude-yesod --package persistent --package hjsmin --package shakespeare --package fast-logger --package wai-extra --package monad-logger --package yesod-persistent --package yesod-form --package monad-control --package transformers --package wai --package blaze-html --package blaze-markup --package safe --package data-default --package unordered-containers --package text --package directory --package bytestring --package conduit-extra --package streaming-commons --package wai-logger --package semigroups --package time --package path-pieces --package blaze-builder --package mtl --package clientsession --package random --package cereal --package old-locale --package containers --package transformers-base --package cookie --package http-types --package case-insensitive --package parsec --package vector --package conduit --package resourcet --package lifted-base --package unix-compat --package exceptions --package deepseq --package mwc-random --package primitive --package word8 --package auto-update --package byteable --package authenticate --package base16-bytestring --package cryptohash --package mime-mail --package persistent-template --package http-client --package http-conduit --package email-validate --package base64-bytestring --package binary --package nonce --package old-time --package wai-app-static --package cryptohash-conduit --package mime-types --package filepath --package process --package async --package attoparsec --package css-text --package hashable --package array --package bytestring-builder --package ghc-prim --package iproute --package http2 --package simple-sendfile --package vault --package stm --package pretty --package postgresql-simple --package postgresql-libpq --package scientific --package enclosed-exceptions --package dlist --package syb --package classy-prelude --package classy-prelude-conduit --package yesod-newsfeed --package resource-pool --package http-api-data --package silently --package tagged --package language-javascript --package network --package data-default-class --package ansi-terminal --package void --package stringsearch --package zlib --package transformers-compat --package stm-chans --package monad-loops 121 | # Stack runs... 122 | ``` 123 | 124 | ## License 125 | This code is licensed under the MIT license. For more information please refer 126 | to the [LICENSE](/LICENSE) file. 127 | 128 | ## Donations 129 | Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y 130 | -------------------------------------------------------------------------------- /extract-dependencies/.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work/ 2 | TAGS 3 | -------------------------------------------------------------------------------- /extract-dependencies/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 André Barnabá 2 | 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /extract-dependencies/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /extract-dependencies/extract-dependencies.cabal: -------------------------------------------------------------------------------- 1 | name: extract-dependencies 2 | version: 0.2.0.1 3 | synopsis: Given a hackage package outputs the list of its dependencies. 4 | description: Given a hackage package outputs the list of its dependencies. See our GitHub README. This is part of stack-run-auto. 5 | homepage: https://github.com/yamadapc/stack-run-auto 6 | license: MIT 7 | license-file: LICENSE 8 | author: André Barnabá 9 | maintainer: asakeron@gmail.com 10 | copyright: 2015 André Barnabá 11 | category: Development 12 | build-type: Simple 13 | cabal-version: >=1.10 14 | 15 | executable extract-dependencies 16 | hs-source-dirs: src 17 | main-is: Main.hs 18 | other-modules: Development.ExtractDependencies 19 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 20 | build-depends: base >= 4.8 && < 5 21 | , async 22 | , containers 23 | , Cabal >= 1.22 && < 2 24 | , package-description-remote 25 | default-language: Haskell2010 26 | 27 | library 28 | hs-source-dirs: src 29 | exposed-modules: Development.ExtractDependencies 30 | build-depends: base >= 4.8 && < 5 31 | , async 32 | , containers 33 | , Cabal >= 1.22 && < 2 34 | , package-description-remote 35 | default-language: Haskell2010 36 | -------------------------------------------------------------------------------- /extract-dependencies/src/Development/ExtractDependencies.hs: -------------------------------------------------------------------------------- 1 | module Development.ExtractDependencies where 2 | 3 | import Distribution.Package 4 | import Distribution.PackageDescription 5 | import Distribution.PackageDescription.Parse 6 | import Distribution.PackageDescription.Remote 7 | 8 | extractDependencies :: String -> IO [String] 9 | extractDependencies npkg = do 10 | ppkg <- getPackageLatest npkg 11 | case ppkg of 12 | ParseOk _ info -> 13 | case condLibrary info of 14 | Just lib -> return $ dependencyName <$> condTreeConstraints lib 15 | Nothing -> error "Package is not a library" 16 | _ -> error "Failed to parse package description" 17 | where 18 | dependencyName (Dependency name _) = unPackageName name 19 | -------------------------------------------------------------------------------- /extract-dependencies/src/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Concurrent.Async 4 | import Control.Monad 5 | import qualified Data.Set as Set 6 | import Development.ExtractDependencies 7 | import System.Environment 8 | 9 | main :: IO () 10 | main = do 11 | npkgs <- getArgs 12 | deps <- mapConcurrently extractDependencies npkgs 13 | forM_ (uniq (concat deps)) putStrLn 14 | where 15 | uniq = uniq' Set.empty 16 | where 17 | uniq' _ [] = [] 18 | uniq' x (y:ys) = if Set.member y x 19 | then uniq' x ys 20 | else y : uniq' (Set.insert y x) ys 21 | -------------------------------------------------------------------------------- /extract-dependencies/stack.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-3.15 2 | packages: 3 | - '.' 4 | - '../package-description-remote' 5 | extra-deps: [] 6 | extra-package-dbs: [] 7 | -------------------------------------------------------------------------------- /file-modules/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/haskell 2 | 3 | ### Haskell ### 4 | dist 5 | cabal-dev 6 | *.o 7 | *.hi 8 | *.chi 9 | *.chs.h 10 | *.dyn_o 11 | *.dyn_hi 12 | .hpc 13 | .hsenv 14 | .cabal-sandbox/ 15 | cabal.sandbox.config 16 | *.prof 17 | *.aux 18 | *.hp 19 | .stack-work/ 20 | 21 | -------------------------------------------------------------------------------- /file-modules/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Pedro Tacla Yamada 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /file-modules/Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | stack build --stack-yaml ./stack-new-hs-src-exts.yaml 3 | stack build 4 | -------------------------------------------------------------------------------- /file-modules/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /file-modules/file-modules.cabal: -------------------------------------------------------------------------------- 1 | name: file-modules 2 | version: 0.1.2.4 3 | cabal-version: >=1.10 4 | build-type: Simple 5 | license: MIT 6 | license-file: LICENSE 7 | copyright: Copyright (c) Pedro Tacla Yamada 2015 8 | maintainer: tacla.yamada@gmail.com 9 | homepage: https://github.com/yamadapc/stack-run-auto 10 | synopsis: Takes a Haskell source-code file and outputs its modules. 11 | description: 12 | Uses @haskell-src-exts@ to parse module imports and follows links 13 | . to local modules in order to build a list of module dependencies. 14 | category: Development 15 | author: Pedro Tacla Yamada 16 | 17 | library 18 | exposed-modules: 19 | Development.FileModules 20 | build-depends: 21 | MissingH, 22 | async, 23 | base >=4.5 && <5, 24 | directory, 25 | filepath, 26 | haskell-src-exts >=1.17 && <2, 27 | regex-compat >= 0.95.1, 28 | regex-pcre 29 | default-language: Haskell2010 30 | hs-source-dirs: src 31 | 32 | executable file-modules 33 | main-is: Main.hs 34 | build-depends: 35 | MissingH, 36 | async, 37 | base >=4.5 && <5, 38 | directory, 39 | filepath, 40 | haskell-src-exts >=1.17 && <2, 41 | regex-compat >= 0.95.1, 42 | regex-pcre 43 | default-language: Haskell2010 44 | hs-source-dirs: src 45 | ghc-options: -O2 -threaded 46 | 47 | -------------------------------------------------------------------------------- /file-modules/src/Development/FileModules.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# LANGUAGE RecordWildCards #-} 3 | module Development.FileModules where 4 | 5 | import Control.Concurrent.Async (mapConcurrently) 6 | import Control.Monad (forM) 7 | import Data.String.Utils (split) 8 | import Language.Haskell.Exts (ImportDecl (..), 9 | ModuleHeadAndImports (..), 10 | ModuleName (..), NonGreedy (..), 11 | ParseResult (..), 12 | #ifdef MIN_VERSION_haskell_src_exts 13 | # if MIN_VERSION_haskell_src_exts(1,18,0) 14 | SrcSpanInfo, 15 | # endif 16 | #else 17 | SrcSpanInfo, 18 | #endif 19 | SrcLoc (..), parse) 20 | import System.Directory 21 | import System.FilePath 22 | import Text.Regex 23 | 24 | fileModulesRecur :: FilePath -> IO [String] 25 | fileModulesRecur fname = run fname 26 | where 27 | run f = do 28 | modules <- fileModules f 29 | modules' <- flip mapConcurrently modules $ \m -> do 30 | let pth = takeDirectory fname joinPath (split "." m) ++ ".hs" 31 | isLocalModule <- doesFileExist pth 32 | if isLocalModule 33 | -- If we're hitting a local modules, ignore it on the 34 | -- output (this may not be what we want) 35 | then run pth 36 | else return [m] 37 | return (concat modules') 38 | 39 | #ifdef MIN_VERSION_haskell_src_exts 40 | # if MIN_VERSION_haskell_src_exts(1,18,0) 41 | getImportsFromHead :: NonGreedy (ModuleHeadAndImports SrcSpanInfo) -> [String] 42 | getImportsFromHead (NonGreedy (ModuleHeadAndImports _ _ _ mimports)) = 43 | map (helper . importModule) mimports 44 | where 45 | helper (ModuleName _ iname) = iname 46 | # else 47 | {-# DEPRECATED getImportsFromHead "haskell-src-exts<1.18.0 will stoped being supported in file-modules" #-} 48 | getImportsFromHead (NonGreedy{..}) = 49 | map (helper . importModule) mimports 50 | where 51 | (ModuleHeadAndImports _ _ mimports) = unNonGreedy 52 | helper (ModuleName iname) = iname 53 | # endif 54 | #else 55 | {-# WARNING getImportsFromHead "Cabal macro to detect haskell-src-exts version not defined, assuming haskell-src-exts>1.18.0" #-} 56 | getImportsFromHead :: NonGreedy (ModuleHeadAndImports SrcSpanInfo) -> [String] 57 | getImportsFromHead (NonGreedy (ModuleHeadAndImports _ _ _ mimports)) = 58 | map (helper . importModule) mimports 59 | where 60 | helper (ModuleName _ iname) = iname 61 | #endif 62 | 63 | fileModules :: FilePath -> IO [String] 64 | fileModules fname = do 65 | fcontents <- readFile fname 66 | case parse $ sanitize fcontents of 67 | (ParseOk rheadAndImports) -> return (getImportsFromHead rheadAndImports) 68 | (ParseFailed (SrcLoc _ line col) err) -> error $ 69 | "Failed to parse module in " ++ fname ++ ":\n" ++ 70 | " (" ++ show line ++ ":" ++ show col ++ ") " ++ err ++ "\n" ++ 71 | " " ++ getLineCol fcontents (line, col) 72 | where 73 | sanitize = 74 | unlines . map (removeMagicHash . removeCpp) . lines 75 | removeCpp ('#':_) = "" 76 | removeCpp l = l 77 | removeMagicHash l = subRegex r l o 78 | where 79 | r = mkRegex "#" 80 | o = "" 81 | getLineCol fcontents (line, col) = 82 | ln ++ "\n" ++ 83 | " " ++ replicate (col' - 3) ' ' ++ "^^^" 84 | where 85 | ln = lines fcontents !! line 86 | col' = let l = length ln 87 | in if col > l then l else col 88 | -------------------------------------------------------------------------------- /file-modules/src/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Concurrent.Async (mapConcurrently) 4 | import Control.Monad (forM_) 5 | import Data.List.Utils (uniq) 6 | import Development.FileModules 7 | import System.Environment (getArgs) 8 | import System.Exit (exitFailure) 9 | 10 | main :: IO () 11 | main = do 12 | args <- getArgs 13 | case args of 14 | "--version":_ -> putStrLn "0.1.2.2" 15 | "--help":_ -> printUsage 16 | [] -> printUsage >> exitFailure 17 | ms -> do 18 | modules <- mapConcurrently fileModulesRecur ms 19 | forM_ (uniq (concat modules)) putStrLn 20 | where 21 | printUsage = putStrLn "Usage: file-modules " 22 | -------------------------------------------------------------------------------- /file-modules/stack-6.9.yaml: -------------------------------------------------------------------------------- 1 | resolver: lts-6.9 2 | packages: 3 | - '.' 4 | -------------------------------------------------------------------------------- /file-modules/stack-new-hs-src-exts.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md 2 | 3 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) 4 | resolver: ghc-7.10.2 5 | 6 | # Local packages, usually specified by relative directory name 7 | packages: 8 | - '.' 9 | 10 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) 11 | extra-deps: 12 | - HUnit-1.3.0.0 13 | - MissingH-1.3.0.1 14 | - async-2.0.2 15 | - base-prelude-0.1.19 16 | - cpphs-1.19.3 17 | - focus-0.1.4 18 | - hashable-1.2.3.3 19 | - haskell-src-exts-1.17.0 20 | - hslogger-1.2.9 21 | - list-t-0.4.5.1 22 | - loch-th-0.2.1 23 | - mmorph-1.0.4 24 | - monad-control-1.0.0.4 25 | - mtl-2.2.1 26 | - network-2.6.2.1 27 | - old-locale-1.0.0.7 28 | - old-time-1.1.0.3 29 | - parsec-3.1.9 30 | - placeholders-0.1 31 | - polyparse-1.11 32 | - primitive-0.6.1.0 33 | - random-1.1 34 | - regex-base-0.93.2 35 | - regex-pcre-0.94.4 36 | - regex-compat-0.95.1 37 | - regex-posix-0.95.2 38 | - stm-2.4.4 39 | - stm-containers-0.2.9 40 | - text-1.2.1.3 41 | - transformers-base-0.4.4 42 | - transformers-compat-0.4.0.4 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: 46 | text: 47 | integer-simple: false 48 | 49 | # Extra package databases containing global packages 50 | extra-package-dbs: [] 51 | 52 | # Control whether we use the GHC we find on the path 53 | # system-ghc: true 54 | 55 | # Require a specific version of stack, using version ranges 56 | # require-stack-version: -any # Default 57 | # require-stack-version: >= 0.1.4.0 58 | 59 | # Override the architecture used by stack, especially useful on Windows 60 | # arch: i386 61 | # arch: x86_64 62 | 63 | # Extra directories used by stack for building 64 | # extra-include-dirs: [/path/to/dir] 65 | # extra-lib-dirs: [/path/to/dir] 66 | -------------------------------------------------------------------------------- /file-modules/stack-nightly.yaml: -------------------------------------------------------------------------------- 1 | resolver: nightly-2016-07-27 2 | packages: 3 | - '.' 4 | -------------------------------------------------------------------------------- /file-modules/stack.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md 2 | 3 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) 4 | resolver: ghc-7.10.2 5 | 6 | # Local packages, usually specified by relative directory name 7 | packages: 8 | - '.' 9 | 10 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) 11 | extra-deps: 12 | - HUnit-1.3.0.0 13 | - MissingH-1.3.0.1 14 | - async-2.0.2 15 | - base-prelude-0.1.19 16 | - cpphs-1.19.3 17 | - focus-0.1.4 18 | - hashable-1.2.3.3 19 | - haskell-src-exts-1.17.0 20 | - hslogger-1.2.9 21 | - list-t-0.4.5.1 22 | - loch-th-0.2.1 23 | - mmorph-1.0.4 24 | - monad-control-1.0.0.4 25 | - mtl-2.2.1 26 | - network-2.6.2.1 27 | - old-locale-1.0.0.7 28 | - old-time-1.1.0.3 29 | - parsec-3.1.9 30 | - placeholders-0.1 31 | - polyparse-1.11 32 | - primitive-0.6.1.0 33 | - random-1.1 34 | - regex-base-0.93.2 35 | - regex-pcre-0.94.4 36 | - regex-compat-0.95.1 37 | - regex-posix-0.95.2 38 | - stm-2.4.4 39 | - stm-containers-0.2.9 40 | - text-1.2.1.3 41 | - transformers-base-0.4.4 42 | - transformers-compat-0.4.0.4 43 | 44 | # Override default flag values for local packages and extra-deps 45 | flags: 46 | text: 47 | integer-simple: false 48 | 49 | # Extra package databases containing global packages 50 | extra-package-dbs: [] 51 | 52 | # Control whether we use the GHC we find on the path 53 | # system-ghc: true 54 | 55 | # Require a specific version of stack, using version ranges 56 | # require-stack-version: -any # Default 57 | # require-stack-version: >= 0.1.4.0 58 | 59 | # Override the architecture used by stack, especially useful on Windows 60 | # arch: i386 61 | # arch: x86_64 62 | 63 | # Extra directories used by stack for building 64 | # extra-include-dirs: [/path/to/dir] 65 | # extra-lib-dirs: [/path/to/dir] 66 | -------------------------------------------------------------------------------- /module-package: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | curl -s -L http://hayoo.fh-wedel.de/json?query="module:$1" | 3 | jq -r '.result | map(select(.resultType == "module")) | .[].resultPackage' | 4 | uniq 5 | -------------------------------------------------------------------------------- /package-description-remote/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pedro Tacla Yamada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package-description-remote/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /package-description-remote/package-description-remote.cabal: -------------------------------------------------------------------------------- 1 | name: package-description-remote 2 | version: 0.2.0.0 3 | synopsis: Fetches a 'GenericPackageDescription' from Hackage 4 | description: Please see README.md 5 | homepage: http://github.com/yamadapc/stack-run-auto/package-description-remote 6 | license: MIT 7 | license-file: LICENSE 8 | author: Pedro Tacla Yamada 9 | maintainer: tacla.yamada@gmail.com 10 | copyright: Copyright (c) 2015 Pedro Tacla Yamada 11 | category: Web 12 | build-type: Simple 13 | cabal-version: >=1.10 14 | 15 | library 16 | hs-source-dirs: src 17 | exposed-modules: Distribution.PackageDescription.Remote 18 | build-depends: Cabal >= 1.22.4.0 19 | , base >= 4.7 && < 5 20 | , bytestring >= 0.10.6.0 21 | , lens >= 4.12.3 22 | , lens-aeson >= 1.0.0.5 23 | , wreq >= 0.4.0.0 24 | default-language: Haskell2010 25 | 26 | test-suite package-description-remote-test 27 | type: exitcode-stdio-1.0 28 | hs-source-dirs: test 29 | main-is: Spec.hs 30 | build-depends: base 31 | , package-description-remote 32 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 33 | default-language: Haskell2010 34 | 35 | source-repository head 36 | type: git 37 | location: https://github.com/yamadapc/stack-run-auto 38 | -------------------------------------------------------------------------------- /package-description-remote/src/Distribution/PackageDescription/Remote.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | module Distribution.PackageDescription.Remote 3 | where 4 | 5 | import Control.Lens ((&), (.~), (^.), (^..)) 6 | import Data.Aeson.Lens (key, values, _Integral) 7 | import Data.ByteString.Lazy.Char8 (unpack) 8 | import Distribution.PackageDescription (GenericPackageDescription) 9 | import Distribution.PackageDescription.Parse (ParseResult (..), 10 | parsePackageDescription) 11 | import Network.Wreq (defaults, get, getWith, 12 | header, responseBody) 13 | 14 | getPackage :: String -> Integer -> IO (ParseResult GenericPackageDescription) 15 | getPackage pkg revision = do 16 | res <- get uri 17 | return $ parsePackageDescription (unpack (res ^. responseBody)) 18 | where 19 | uri = "http://hackage.haskell.org/package/" ++ pkg ++ "/revision/" ++ 20 | show revision 21 | 22 | getPackageLatest :: String -> IO (ParseResult GenericPackageDescription) 23 | getPackageLatest pkg = do 24 | revision <- getPackageLatestRevision pkg 25 | getPackage pkg revision 26 | 27 | getPackageRevisions :: String -> IO [Integer] 28 | getPackageRevisions pkg = do 29 | res <- getWith opt uri 30 | return $ res ^.. responseBody . values . key "number" . _Integral 31 | where 32 | opt = defaults & header "Accept" .~ ["application/json"] 33 | uri = "http://hackage.haskell.org/package/" ++ pkg ++ "/revisions/" 34 | 35 | getPackageLatestRevision :: String -> IO Integer 36 | getPackageLatestRevision pkg = do 37 | revisions <- getPackageRevisions pkg 38 | return (maximum revisions) 39 | -------------------------------------------------------------------------------- /package-description-remote/stack.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md 2 | 3 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) 4 | resolver: lts-3.15 5 | 6 | # Local packages, usually specified by relative directory name 7 | packages: 8 | - '.' 9 | 10 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) 11 | extra-deps: [] 12 | 13 | # Override default flag values for local packages and extra-deps 14 | flags: {} 15 | 16 | # Extra package databases containing global packages 17 | extra-package-dbs: [] 18 | 19 | # Control whether we use the GHC we find on the path 20 | # system-ghc: true 21 | 22 | # Require a specific version of stack, using version ranges 23 | # require-stack-version: -any # Default 24 | # require-stack-version: >= 0.1.4.0 25 | 26 | # Override the architecture used by stack, especially useful on Windows 27 | # arch: i386 28 | # arch: x86_64 29 | 30 | # Extra directories used by stack for building 31 | # extra-include-dirs: [/path/to/dir] 32 | # extra-lib-dirs: [/path/to/dir] 33 | -------------------------------------------------------------------------------- /package-description-remote/test/Spec.hs: -------------------------------------------------------------------------------- 1 | main :: IO () 2 | main = putStrLn "Test suite not yet implemented" 3 | -------------------------------------------------------------------------------- /stack-run-auto/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pedro Tacla Yamada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /stack-run-auto/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /stack-run-auto/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import StackRunAuto 4 | import System.Environment (getArgs) 5 | import System.IO 6 | 7 | main :: IO () 8 | main = do 9 | args <- getArgs 10 | hSetBuffering stdout LineBuffering 11 | hSetBuffering stderr LineBuffering 12 | 13 | let (extras, args') = getExtras args 14 | 15 | case args' of 16 | [] -> error "Usage: stack-run-auto " 17 | ("--help":_) -> hPutStrLn stderr usage 18 | (fname:flags) -> run (Options fname extras flags) 19 | where 20 | usage = unlines [ "Usage: stack-run-auto [--extra ...] [...]" 21 | , "" 22 | , " --extra Adds an extra package that couldn't be resolved" 23 | , "" 24 | ] 25 | 26 | getExtras :: [String] -> ([String], [String]) 27 | getExtras args = go ([], args) 28 | where 29 | go (extras, "--extra":pkg:args') = go (pkg:extras, args') 30 | go i = i 31 | -------------------------------------------------------------------------------- /stack-run-auto/app/ModulePackage.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Control.Concurrent.Async 4 | import Control.Monad (forM_) 5 | import Data.Maybe (catMaybes) 6 | import StackRunAuto 7 | import System.Environment 8 | import System.IO 9 | 10 | main :: IO () 11 | main = do 12 | args <- getArgs 13 | hSetBuffering stdout LineBuffering 14 | hSetBuffering stderr LineBuffering 15 | pkgs <- mapConcurrently modulePackage args 16 | forM_ (catMaybes pkgs) putStrLn 17 | -------------------------------------------------------------------------------- /stack-run-auto/src/StackRunAuto.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | {-# LANGUAGE RecordWildCards #-} 3 | module StackRunAuto where 4 | 5 | import Control.Concurrent.Async 6 | import Control.Lens 7 | import Data.Aeson.Lens 8 | import Data.List.Utils (uniq) 9 | import Data.Maybe (catMaybes) 10 | import Data.Monoid 11 | import Data.String.Utils 12 | import qualified Data.Text as Text (pack, unpack) 13 | import Data.Time.Clock 14 | import Development.ExtractDependencies 15 | import Development.FileModules 16 | import Network.Wreq (defaults, getWith, param, 17 | responseBody) 18 | import System.Directory 19 | import System.Exit 20 | import System.FilePath 21 | import System.IO (hPutStrLn, stderr) 22 | import System.Process 23 | 24 | data Options = Options { optsFileName :: FilePath 25 | , optsExtras :: [String] 26 | , optsFlags :: [String] 27 | } 28 | 29 | run :: Options -> IO () 30 | run Options{..} = do 31 | modules <- fileModulesVerbose optsFileName 32 | packages <- catMaybes <$> mapConcurrently modulePackageVerbose modules 33 | allPackages <- mapConcurrently extractDependenciesVerbose (uniq packages) 34 | let argList = map ("--package " ++) 35 | (filter isValidPackage 36 | (uniq (packages ++ concat allPackages ++ optsExtras))) 37 | cmd = unwords [ "stack runghc " 38 | , optsFileName 39 | , unwords argList 40 | , unwords optsFlags 41 | ] 42 | putStrLn cmd 43 | ph <- runCommand cmd 44 | waitForProcess ph >>= exitWith 45 | 46 | timed :: String -> IO a -> IO a 47 | timed msg action = do 48 | start <- getCurrentTime 49 | ret <- action 50 | end <- getCurrentTime 51 | hPutStrLn stderr $ msg ++ " (" ++ show (diffUTCTime end start) ++ ")" 52 | return ret 53 | 54 | isValidPackage :: String -> Bool 55 | isValidPackage "rts" = False 56 | isValidPackage _ = True 57 | 58 | fileModulesVerbose :: String -> IO [String] 59 | fileModulesVerbose optsFileName = timed "---> Parsed imports" $ do 60 | hPutStrLn stderr $ "Parsing " ++ optsFileName 61 | uniq <$> fileModulesRecur optsFileName 62 | 63 | extractDependenciesVerbose :: String -> IO [String] 64 | extractDependenciesVerbose pkg = timed ("---> Found dependencies for " ++ pkg) $ do 65 | hPutStrLn stderr $ "Finding dependencies for " ++ pkg ++ "..." 66 | extractDependenciesCached pkg 67 | 68 | extractDependenciesCached :: String -> IO [String] 69 | extractDependenciesCached = cached "extract-dependencies" extractDependencies 70 | 71 | modulePackageVerbose :: String -> IO (Maybe String) 72 | modulePackageVerbose "" = do 73 | hPutStrLn stderr "Skipping parse error (empty string)..." 74 | return Nothing 75 | modulePackageVerbose m = timed ("---> Found package for " ++ m) $ do 76 | hPutStrLn stderr $ "Finding package for " ++ m ++ "..." 77 | modulePackageCached m 78 | 79 | cached :: (Read b, Show b) => String -> (FilePath -> IO b) -> FilePath -> IO b 80 | cached name fn arg = do 81 | home <- getHomeDirectory 82 | let cacheDir = home ".stack-run-auto" name 83 | cachePth = cacheDir arg 84 | createDirectoryIfMissing True cacheDir 85 | exists <- doesFileExist cachePth 86 | if exists 87 | then read <$> readFile cachePth 88 | else do 89 | r <- fn arg 90 | writeFile cachePth (show r) 91 | return r 92 | 93 | modulePackageCached :: String -> IO (Maybe String) 94 | modulePackageCached = cached "module-package" modulePackage 95 | 96 | modulePackage :: String -> IO (Maybe String) 97 | modulePackage m = do 98 | let url = "http://hayoo.fh-wedel.de/json" 99 | opts = defaults & param "query" .~ ["module:" <> Text.pack m] 100 | res <- getWith opts url 101 | let result = res ^.. responseBody . key "result" . values 102 | moduleResults = filter isModuleResult result 103 | case moduleResults of 104 | [] -> do 105 | let errMsg = "No package found for " ++ m 106 | hPutStrLn stderr errMsg 107 | let mparts = split "." m 108 | if not (null mparts) 109 | then modulePackageVerbose (join "." (init mparts)) 110 | else error $ "Couldn't resolve package for " ++ m 111 | (p:_) -> do 112 | let pkg = Text.unpack (p ^. key "resultPackage" . _String) 113 | return (Just pkg) 114 | where 115 | isModuleResult r = r ^. key "resultType" . _String == "module" 116 | -------------------------------------------------------------------------------- /stack-run-auto/stack-run-auto.cabal: -------------------------------------------------------------------------------- 1 | name: stack-run-auto 2 | version: 0.1.1.4 3 | synopsis: Initial project template from stack 4 | description: Please see README.md 5 | homepage: http://github.com/yamadapc/stack-run-auto#readme 6 | license: MIT 7 | license-file: LICENSE 8 | author: Pedro Tacla Yamada 9 | maintainer: tacla.yamada@gmail.com 10 | copyright: Copyright (c) 2015 Pedro Tacla Yamada 11 | category: Development 12 | build-type: Simple 13 | cabal-version: >=1.10 14 | 15 | library 16 | hs-source-dirs: src 17 | exposed-modules: StackRunAuto 18 | build-depends: base >= 4.7 && < 5 19 | , filepath 20 | , directory 21 | , time 22 | , process 23 | , text 24 | , lens-aeson 25 | , lens 26 | , wreq 27 | , MissingH 28 | , stm-containers 29 | , async 30 | , extract-dependencies 31 | , file-modules 32 | default-language: Haskell2010 33 | 34 | executable module-package 35 | hs-source-dirs: app 36 | main-is: ModulePackage.hs 37 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 38 | build-depends: base 39 | , filepath 40 | , directory 41 | , time 42 | , process 43 | , text 44 | , lens-aeson 45 | , lens 46 | , wreq 47 | , MissingH 48 | , stm-containers 49 | , async 50 | , extract-dependencies 51 | , file-modules 52 | , stack-run-auto 53 | default-language: Haskell2010 54 | 55 | executable stack-run-auto 56 | hs-source-dirs: app 57 | main-is: Main.hs 58 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 59 | build-depends: base 60 | , filepath 61 | , directory 62 | , time 63 | , process 64 | , text 65 | , lens-aeson 66 | , lens 67 | , wreq 68 | , MissingH 69 | , stm-containers 70 | , async 71 | , extract-dependencies 72 | , file-modules 73 | , stack-run-auto 74 | default-language: Haskell2010 75 | 76 | test-suite stack-run-auto-test 77 | type: exitcode-stdio-1.0 78 | hs-source-dirs: test 79 | main-is: Spec.hs 80 | build-depends: base 81 | , filepath 82 | , directory 83 | , time 84 | , process 85 | , text 86 | , lens-aeson 87 | , lens 88 | , wreq 89 | , MissingH 90 | , stm-containers 91 | , async 92 | , extract-dependencies 93 | , file-modules 94 | , stack-run-auto 95 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 96 | default-language: Haskell2010 97 | 98 | source-repository head 99 | type: git 100 | location: https://github.com/yamadapc/stack-run-auto 101 | -------------------------------------------------------------------------------- /stack-run-auto/stack.yaml: -------------------------------------------------------------------------------- 1 | # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md 2 | 3 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) 4 | resolver: lts-3.15 5 | 6 | # Local packages, usually specified by relative directory name 7 | packages: 8 | - '.' 9 | - '../file-modules' 10 | - '../extract-dependencies' 11 | 12 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) 13 | extra-deps: 14 | - haskell-src-exts-1.17.0 15 | - package-description-remote-0.1.1.0 16 | 17 | # Override default flag values for local packages and extra-deps 18 | flags: {} 19 | 20 | # Extra package databases containing global packages 21 | extra-package-dbs: [] 22 | 23 | # Control whether we use the GHC we find on the path 24 | # system-ghc: true 25 | 26 | # Require a specific version of stack, using version ranges 27 | # require-stack-version: -any # Default 28 | # require-stack-version: >= 0.1.4.0 29 | 30 | # Override the architecture used by stack, especially useful on Windows 31 | # arch: i386 32 | # arch: x86_64 33 | 34 | # Extra directories used by stack for building 35 | # extra-include-dirs: [/path/to/dir] 36 | # extra-lib-dirs: [/path/to/dir] 37 | -------------------------------------------------------------------------------- /stack-run-auto/test/Spec.hs: -------------------------------------------------------------------------------- 1 | main :: IO () 2 | main = putStrLn "Test suite not yet implemented" 3 | -------------------------------------------------------------------------------- /stack-try: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | function errcho { 5 | >&2 echo "$@" 6 | } 7 | 8 | function dependencies_for_package { 9 | if [ $1 = "base" ]; then 10 | return 11 | fi 12 | 13 | errcho "$ hackage-dependencies $1..." 14 | deps=$(echo $1; ./hackage-dependencies $1) 15 | for dep in $deps; do 16 | errcho "----> $dep" 17 | done 18 | echo $deps 19 | } 20 | 21 | packages=$@ 22 | all_packages=`for package in $packages; do dependencies_for_package $package; done` 23 | arg_list=`for package in $all_packages; do echo "--package $package"; done | sort | uniq` 24 | errcho "$ stack ghci `echo $arg_list`" 25 | stack ghci $arg_list 26 | -------------------------------------------------------------------------------- /test-files/DistributedProcess.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveDataTypeable,ScopedTypeVariables #-} 2 | module PingPong where 3 | import Control.Concurrent ( threadDelay ) 4 | import Control.Distributed.Process 5 | import Control.Distributed.Process.Node 6 | import Network.Transport ( closeTransport ) 7 | import Network.Transport.TCP 8 | import Test 9 | 10 | server :: DynamicT -> Process () 11 | server st = do 12 | (cid,x) :: (ProcessId,Int) <- expect 13 | liftIO $ putStrLn $ "Got a Ping with value : " ++ (show x) 14 | case x of 15 | 4 -> do 16 | liftIO $ putStrLn $ "UPGRADE" 17 | liftIO $ st 18 | _ -> do 19 | send cid x 20 | liftIO $ putStrLn $ "Sent a Pong with value : " ++ (show x) 21 | server st 22 | 23 | client :: DynamicT -> Int -> ProcessId -> Process () 24 | client st 10 sid = do 25 | liftIO $ putStrLn "DONE" 26 | client st c sid = do 27 | me <- getSelfPid 28 | send sid (me,c) 29 | liftIO $ putStrLn $ "Sent a Ping with value : " ++ (show c) 30 | (v :: Int) <- expect 31 | liftIO $ putStrLn $ "Got a Pong with value : " ++ (show v) 32 | client st (c+1) sid 33 | 34 | ignition :: DynamicT -> Process () 35 | ignition st= do 36 | -- start the server 37 | sid <- spawnLocal $ server st 38 | -- start the client 39 | cid <- spawnLocal $ client st 0 sid 40 | return () 41 | liftIO $ threadDelay 100000-- wait a while 42 | 43 | type DynamicT = IO () 44 | 45 | main :: DynamicT -> IO () 46 | main st = do 47 | Right transport <- createTransport "127.0.0.1" "8080" 48 | defaultTCPParameters 49 | node <- newLocalNode transport initRemoteTable 50 | runProcess node $ ignition st 51 | closeTransport transport 52 | -------------------------------------------------------------------------------- /test-files/Test.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Data.Aeson 4 | import qualified Data.Text 5 | import qualified Network.HTTP.Conduit (stuff) 6 | import System.Console.AsciiProgress 7 | 8 | main :: IO () 9 | main = error "Doesn't matter" 10 | -------------------------------------------------------------------------------- /test-files/Test2.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE OverloadedStrings #-} 2 | import Data.Text.IO as Text 3 | 4 | main = Text.putStrLn "Hello" 5 | --------------------------------------------------------------------------------