diff options
author | kakkun61 <> | 2019-12-02 05:31:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2019-12-02 05:31:00 (GMT) |
commit | bbf6da4845513628afb9360b18a661a7b2721fb8 (patch) | |
tree | eb24d322002077da2979be70c75f3374b7bbb920 |
-rw-r--r-- | ChangeLog.md | 5 | ||||
-rw-r--r-- | LICENSE | 30 | ||||
-rw-r--r-- | README.md | 38 | ||||
-rw-r--r-- | Setup.hs | 2 | ||||
-rw-r--r-- | app/GhcLib.hs | 17 | ||||
-rw-r--r-- | app/exe.hs | 13 | ||||
-rw-r--r-- | app/ghc-pkg.hs | 19 | ||||
-rw-r--r-- | app/ghc.hs | 18 | ||||
-rw-r--r-- | app/ghci.hs | 19 | ||||
-rw-r--r-- | app/haddock.hs | 16 | ||||
-rw-r--r-- | app/hp2ps.hs | 16 | ||||
-rw-r--r-- | app/hsc2hs.hs | 16 | ||||
-rw-r--r-- | app/runghc.hs | 17 | ||||
-rw-r--r-- | app/runhaskell.hs | 17 | ||||
-rw-r--r-- | src/StackWrapper.hs | 58 | ||||
-rw-r--r-- | stack-wrapper.cabal | 177 |
16 files changed, 478 insertions, 0 deletions
diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..d926197 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,5 @@ +# Changelog for stack-wrapper + +## 0.1.0 + +The first release. @@ -0,0 +1,30 @@ +Copyright Kazuki Okamoto (c) 2018 + +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 Kazuki Okamoto 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b4b1a9 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# stack-wrapper + +When you invoke `ghc` of stack-wrapper, you can invoke the appropriate one which specified by the resolver of _stack.yaml_. + +This helps you when you are working with stack but developing tools etc. don't support stack. + +To check a stack-wrapper version, you give `--stack-wrapper` as the first option to commands. + +You can set the default executable files with environment variables. They are used when no executable files found except the stack-wrapper's ones. + +This package creates 2 types of executable files. + +## ghc etc. + +`ghc` runs like: + +1. search a compiler under stack environment +2. give the global, snapshot and local package DB to the compiler +3. run the compiler + +`ghc-pkg`, `ghci`, `haddock`, `hp2ps`, `hsc2hs`, `runghc` and `runhaskell` are also given. + +## exe + +An executable file which is renamed from `exe`, for example `hhpc`, runs new process `stack exec -- hhpc`. + +## Options + +- `--stack-wrapper` + - print the stack-wrapper version + +## Environment variables + +- `STACK_WRAPPER_GHC_DIR` + - the default directory which contains `ghc`, `ghc-pkg` etc. +- `STACK_WRAPPER_<exe name>` + - the default executable file for <exe name> + - on Windows remove the `.exe` extension diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/GhcLib.hs b/app/GhcLib.hs new file mode 100644 index 0000000..3c2bf60 --- /dev/null +++ b/app/GhcLib.hs @@ -0,0 +1,17 @@ +module GhcLib (run) where
+
+import StackWrapper (envPrefix)
+
+import System.Environment
+import System.FilePath
+import System.Process
+
+run :: String -> IO () -> IO ()
+run name act = do
+ args <- getArgs
+ mdefaultDir <- lookupEnv $ envPrefix <> "GHC_DIR"
+ case mdefaultDir of
+ Just defaultDir ->
+ callProcess (defaultDir </> name) args
+ Nothing ->
+ act
diff --git a/app/exe.hs b/app/exe.hs new file mode 100644 index 0000000..8171160 --- /dev/null +++ b/app/exe.hs @@ -0,0 +1,13 @@ +module Main where + +import StackWrapper + +import System.Process +import System.Environment + +main :: IO () +main = + run $ do + name <- getProgName + args <- getArgs + callProcess "stack" ("exec":"--":name:args) diff --git a/app/ghc-pkg.hs b/app/ghc-pkg.hs new file mode 100644 index 0000000..f7839df --- /dev/null +++ b/app/ghc-pkg.hs @@ -0,0 +1,19 @@ +module Main where
+
+import StackWrapper
+
+import qualified GhcLib as G
+
+import System.Environment
+import System.FilePath
+import System.Process
+
+main :: IO ()
+main =
+ run $ G.run "ghc-pkg" $ do
+ args <- getArgs
+ binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] ""
+ globalPackageDB <- head . lines <$> readProcess "stack" ["path", "--global-pkg-db"] ""
+ snapshotPackageDB <- head . lines <$> readProcess "stack" ["path", "--snapshot-pkg-db"] ""
+ localPackageDB <- head . lines <$> readProcess "stack" ["path", "--local-pkg-db"] ""
+ callProcess (binDir </> "ghc-pkg") ("--package-db":globalPackageDB:"--package-db":snapshotPackageDB:"--package-db":localPackageDB:args)
diff --git a/app/ghc.hs b/app/ghc.hs new file mode 100644 index 0000000..b6a1dda --- /dev/null +++ b/app/ghc.hs @@ -0,0 +1,18 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.Process + +main :: IO () +main = + run $ G.run "ghc" $ do + args <- getArgs + compilerExe <- head . lines <$> readProcess "stack" ["path", "--compiler-exe"] "" + globalPackageDB <- head . lines <$> readProcess "stack" ["path", "--global-pkg-db"] "" + snapshotPackageDB <- head . lines <$> readProcess "stack" ["path", "--snapshot-pkg-db"] "" + localPackageDB <- head . lines <$> readProcess "stack" ["path", "--local-pkg-db"] "" + callProcess compilerExe ("-package-db":globalPackageDB:"-package-db":snapshotPackageDB:"-package-db":localPackageDB:args) diff --git a/app/ghci.hs b/app/ghci.hs new file mode 100644 index 0000000..230cdde --- /dev/null +++ b/app/ghci.hs @@ -0,0 +1,19 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "ghci" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + globalPackageDB <- head . lines <$> readProcess "stack" ["path", "--global-pkg-db"] "" + snapshotPackageDB <- head . lines <$> readProcess "stack" ["path", "--snapshot-pkg-db"] "" + localPackageDB <- head . lines <$> readProcess "stack" ["path", "--local-pkg-db"] "" + callProcess (binDir </> "ghci") ("-package-db":globalPackageDB:"-package-db":snapshotPackageDB:"-package-db":localPackageDB:args) diff --git a/app/haddock.hs b/app/haddock.hs new file mode 100644 index 0000000..d6ab808 --- /dev/null +++ b/app/haddock.hs @@ -0,0 +1,16 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "haddock" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + callProcess (binDir </> "haddock") args diff --git a/app/hp2ps.hs b/app/hp2ps.hs new file mode 100644 index 0000000..ff06400 --- /dev/null +++ b/app/hp2ps.hs @@ -0,0 +1,16 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "hp2ps" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + callProcess (binDir </> "hp2ps") args diff --git a/app/hsc2hs.hs b/app/hsc2hs.hs new file mode 100644 index 0000000..076481a --- /dev/null +++ b/app/hsc2hs.hs @@ -0,0 +1,16 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "hsc2hs" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + callProcess (binDir </> "hsc2hs") args diff --git a/app/runghc.hs b/app/runghc.hs new file mode 100644 index 0000000..bc970af --- /dev/null +++ b/app/runghc.hs @@ -0,0 +1,17 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "runghc" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + -- use --ghc-arg option? + callProcess (binDir </> "runghc") args diff --git a/app/runhaskell.hs b/app/runhaskell.hs new file mode 100644 index 0000000..c998ca7 --- /dev/null +++ b/app/runhaskell.hs @@ -0,0 +1,17 @@ +module Main where + +import StackWrapper + +import qualified GhcLib as G + +import System.Environment +import System.FilePath +import System.Process + +main :: IO () +main = + run $ G.run "runhaskell" $ do + args <- getArgs + binDir <- head . lines <$> readProcess "stack" ["path", "--compiler-bin"] "" + -- use --ghc-arg option? + callProcess (binDir </> "runhaskell") args diff --git a/src/StackWrapper.hs b/src/StackWrapper.hs new file mode 100644 index 0000000..37cb72c --- /dev/null +++ b/src/StackWrapper.hs @@ -0,0 +1,58 @@ +{-# LANGUAGE CPP #-} + +module StackWrapper + ( run + , envPrefix + ) where + +import Paths_stack_wrapper (version) + +import Data.Version (showVersion) +import System.Environment (getArgs, getExecutablePath, getProgName, lookupEnv, setEnv) +import System.Exit (exitFailure, exitSuccess) +import System.IO (hPutStrLn, stderr) +import System.Process (callProcess) + +#ifdef mingw32_HOST_OS +import System.FilePath (takeBaseName) +#endif + +option :: String +option = "--stack-wrapper" + +envPrefix :: String +envPrefix = "STACK_WRAPPER_" + +callerEnv :: String +callerEnv = envPrefix <> "CALLER" + +run :: IO () -> IO () +run act = do + args <- getArgs + case args of + a0:_ | a0 == option -> do + putStrLn $ "stack-wrapper " <> showVersion version + exitSuccess + _ -> do + this <- getExecutablePath + mcaller <- lookupEnv callerEnv + case mcaller of + Just caller | this == caller -> do + name <- getProgBaseName + mdefaultExe <- lookupEnv $ envPrefix <> name + case mdefaultExe of + Just defaultExe -> + callProcess defaultExe args + Nothing -> do + hPutStrLn stderr "recursive call detected" + exitFailure + _ -> do + setEnv callerEnv this + act + +getProgBaseName :: IO String +#ifdef mingw32_HOST_OS +getProgBaseName = takeBaseName <$> getProgName +#else +getProgName = getProgName +#endif diff --git a/stack-wrapper.cabal b/stack-wrapper.cabal new file mode 100644 index 0000000..5e46113 --- /dev/null +++ b/stack-wrapper.cabal @@ -0,0 +1,177 @@ +cabal-version: 1.12
+ +-- This file has been generated from package.yaml by hpack version 0.31.1. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 6d5ae7d56e9f4ed0dcd9ab184b52c93efda2405f535518f2421764cec0375877 + +name: stack-wrapper +version: 0.1.0 +synopsis: Call ghc within stack by calling ghc +description: When you invoke ghc of stack-wrapper, you can invoke the appropriate one which specified by the resolver of stack.yaml. +category: Development +homepage: https://github.com/kakkun61/stack-wrapper#readme +bug-reports: https://github.com/kakkun61/stack-wrapper/issues +author: Kazuki Okamoto +maintainer: kazuki.okamoto@kakkun61.com +copyright: Kazuki Okamoto +license: BSD3 +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/kakkun61/stack-wrapper + +library + exposed-modules: + StackWrapper + other-modules: + Paths_stack_wrapper + hs-source-dirs: + src + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + default-language: Haskell2010 + +executable exe + main-is: exe.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable ghc + main-is: ghc.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable ghc-pkg + main-is: ghc-pkg.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable ghci + main-is: ghci.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable haddock + main-is: haddock.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable hp2ps + main-is: hp2ps.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable hsc2hs + main-is: hsc2hs.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable runghc + main-is: runghc.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 + +executable runhaskell + main-is: runhaskell.hs + other-modules: + GhcLib + Paths_stack_wrapper + hs-source-dirs: + app + ghc-options: -Wall -Wcompat + build-depends: + base >=4.7 && <4.8 + , filepath >=1.4 + , process >=1.2 + , stack-wrapper + default-language: Haskell2010 |