|
1 | 1 | {-# LANGUAGE TupleSections #-}
|
2 | 2 | {-# LANGUAGE CPP #-}
|
3 | 3 | {-# LANGUAGE DeriveDataTypeable #-}
|
| 4 | +{-# LANGUAGE FlexibleContexts #-} |
4 | 5 | {-# LANGUAGE OverloadedStrings #-}
|
5 | 6 | {-# LANGUAGE ScopedTypeVariables #-}
|
6 | 7 | {-# LANGUAGE TemplateHaskell #-}
|
@@ -61,6 +62,7 @@ import Stack.Coverage
|
61 | 62 | import qualified Stack.Docker as Docker
|
62 | 63 | import Stack.Dot
|
63 | 64 | import Stack.Exec
|
| 65 | +import Stack.GhcPkg (findGhcPkgField) |
64 | 66 | import qualified Stack.Nix as Nix
|
65 | 67 | import Stack.Fetch
|
66 | 68 | import Stack.FileWatch
|
@@ -740,28 +742,40 @@ execCmd ExecOpts {..} go@GlobalOpts{..} =
|
740 | 742 | Nothing -- Unlocked already above.
|
741 | 743 | ExecOptsEmbellished {..} ->
|
742 | 744 | withBuildConfigAndLock go $ \lk -> do
|
| 745 | + let targets = concatMap words eoPackages |
| 746 | + unless (null targets) $ |
| 747 | + Stack.Build.build (const $ return ()) lk defaultBuildOptsCLI |
| 748 | + { boptsCLITargets = map T.pack targets |
| 749 | + } |
| 750 | + |
743 | 751 | config <- asks getConfig
|
| 752 | + menv <- liftIO $ configEnvOverride config eoEnvSettings |
744 | 753 | (cmd, args) <- case (eoCmd, eoArgs) of
|
745 | 754 | (ExecCmd cmd, args) -> return (cmd, args)
|
746 |
| - (ExecGhc, args) -> execCompiler "" args |
| 755 | + (ExecGhc, args) -> getGhcCmd menv eoPackages [] args |
747 | 756 | -- NOTE: this won't currently work for GHCJS, because it doesn't have
|
748 | 757 | -- a runghcjs binary. It probably will someday, though.
|
749 | 758 | (ExecRunGhc, args) ->
|
750 |
| - let opts = concatMap (\x -> ["-package", x]) eoPackages |
751 |
| - in execCompiler "" (opts ++ ("-e" : "Main.main" : args)) |
752 |
| - let targets = concatMap words eoPackages |
753 |
| - unless (null targets) $ |
754 |
| - Stack.Build.build (const $ return ()) lk defaultBuildOptsCLI |
755 |
| - { boptsCLITargets = map T.pack targets |
756 |
| - } |
| 759 | + getGhcCmd menv eoPackages ["-e", "Main.main"] args |
757 | 760 | munlockFile lk -- Unlock before transferring control away.
|
758 |
| - menv <- liftIO $ configEnvOverride config eoEnvSettings |
759 | 761 | exec menv cmd args
|
760 | 762 | where
|
761 |
| - execCompiler cmdPrefix args = do |
762 |
| - wc <- getWhichCompiler |
763 |
| - let cmd = cmdPrefix ++ compilerExeName wc |
764 |
| - return (cmd, args) |
| 763 | + -- return the package-id of the first package in GHC_PACKAGE_PATH |
| 764 | + getPkgId menv wc name = do |
| 765 | + mId <- findGhcPkgField menv wc [] name "id" |
| 766 | + case mId of |
| 767 | + Just i -> return (head $ words (T.unpack i)) |
| 768 | + -- should never happen as we have already installed the packages |
| 769 | + _ -> error ("Could not find package id of package " ++ name) |
| 770 | + |
| 771 | + getPkgOpts menv wc pkgs = do |
| 772 | + ids <- mapM (getPkgId menv wc) pkgs |
| 773 | + return $ concatMap (\x -> ["-package-id", x]) ids |
| 774 | + |
| 775 | + getGhcCmd menv pkgs prefix args = do |
| 776 | + wc <- getWhichCompiler |
| 777 | + pkgopts <- getPkgOpts menv wc pkgs |
| 778 | + return (compilerExeName wc, prefix ++ pkgopts ++ args) |
765 | 779 |
|
766 | 780 | -- | Evaluate some haskell code inline.
|
767 | 781 | evalCmd :: EvalOpts -> GlobalOpts -> IO ()
|
|
0 commit comments