Skip to content

Commit

Permalink
Fix use of --ghc-options with GHCJS #2714
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Oct 18, 2016
1 parent 83cff8c commit d94b1f0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
8 changes: 4 additions & 4 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ Bug fixes:
module to load. [#2603](https://github.com/commercialhaskell/stack/pull/2603)
* Build Setup.hs files with the threaded RTS, mirroring the behavior of
cabal-install and enabling more complex build systems in those files.
* Fixed dirtiness checking for GHCJS packages by assuming dirtiness, since we
don't get .ddump-hi info. See
[#2341](https://github.com/commercialhaskell/stack/issues/2341) and
[ghcjs/#533](https://github.com/ghcjs/ghcjs/issues/533)
* Fixed a bug in passing along `--ghc-options` to ghcjs. They were being
provided as `--ghc-options` to Cabal, when it needs to be `--ghcjs-options`.
[#2714](https://github.com/commercialhaskell/stack/issues/2714)


## 1.2.0

Expand Down
20 changes: 13 additions & 7 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ import Stack.Build.Haddock
import Stack.Build.Installed
import Stack.Build.Source
import Stack.BuildPlan
import Stack.Constants
import Stack.Package
import Stack.PackageDump
import Stack.PackageIndex
import Stack.PrettyPrint
import Stack.Types.Build
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.FlagName
import Stack.Types.GhcPkgId
Expand Down Expand Up @@ -605,18 +607,22 @@ describeConfigDiff config old new
go
where
go [] = []
go ("--ghc-option":x:xs) = go' x xs
go ("--ghc-options":x:xs) = go' x xs
go ((T.stripPrefix "--ghc-option=" -> Just x):xs) = go' x xs
go ((T.stripPrefix "--ghc-options=" -> Just x):xs) = go' x xs
go ("--ghc-option":x:xs) = go' Ghc x xs
go ("--ghc-options":x:xs) = go' Ghc x xs
go ((T.stripPrefix "--ghc-option=" -> Just x):xs) = go' Ghc x xs
go ((T.stripPrefix "--ghc-options=" -> Just x):xs) = go' Ghc x xs
go ("--ghcjs-option":x:xs) = go' Ghcjs x xs
go ("--ghcjs-options":x:xs) = go' Ghcjs x xs
go ((T.stripPrefix "--ghcjs-option=" -> Just x):xs) = go' Ghcjs x xs
go ((T.stripPrefix "--ghcjs-options=" -> Just x):xs) = go' Ghcjs x xs
go (x:xs) = x : go xs

go' x xs = checkKeepers x $ go xs
go' wc x xs = checkKeepers wc x $ go xs

checkKeepers x xs =
checkKeepers wc x xs =
case filter isKeeper $ T.words x of
[] -> xs
keepers -> "--ghc-options" : T.unwords keepers : xs
keepers -> T.pack (compilerOptionsCabalFlag wc) : T.unwords keepers : xs

-- GHC options which affect build results and therefore should always
-- force a rebuild
Expand Down
11 changes: 6 additions & 5 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ singleBuild runInBase ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} in

() <- announce ("build" <> annSuffix)
config <- asks getConfig
extraOpts <- extraBuildOptions eeBuildOpts
extraOpts <- extraBuildOptions wc eeBuildOpts
cabal (configHideTHLoading config) (("build" :) $ (++ extraOpts) $
case (taskType, taskAllInOne, isFinalBuild) of
(_, True, True) -> fail "Invariant violated: cannot have an all-in-one build that also has a final build step."
Expand Down Expand Up @@ -1573,15 +1573,16 @@ getSetupHs dir = do
-- Do not pass `-hpcdir` as GHC option if the coverage is not enabled.
-- This helps running stack-compiled programs with dynamic interpreters like `hint`.
-- Cfr: https://github.com/commercialhaskell/stack/issues/997
extraBuildOptions :: M env m => BuildOpts -> m [String]
extraBuildOptions bopts = do
extraBuildOptions :: M env m => WhichCompiler -> BuildOpts -> m [String]
extraBuildOptions wc bopts = do
let ddumpOpts = " -ddump-hi -ddump-to-file"
optsFlag = compilerOptionsCabalFlag wc
if toCoverage (boptsTestOpts bopts)
then do
hpcIndexDir <- toFilePathNoTrailingSep <$> hpcRelativeDir
return ["--ghc-options", "-hpcdir " ++ hpcIndexDir ++ ddumpOpts]
return [optsFlag, "-hpcdir " ++ hpcIndexDir ++ ddumpOpts]
else
return ["--ghc-options", ddumpOpts]
return [optsFlag, ddumpOpts]

-- Library and executable build components.
primaryComponentOptions :: LocalPackage -> [String]
Expand Down
7 changes: 7 additions & 0 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Stack.Constants
,defaultGlobalConfigPathDeprecated
,defaultGlobalConfigPath
,platformVariantEnvVar
,compilerOptionsCabalFlag
)
where

Expand Down Expand Up @@ -341,3 +342,9 @@ buildPlanDir = (</> $(mkRelDir "build-plan"))
-- names. Used to ensure incompatible binaries aren't shared between Docker builds and host
platformVariantEnvVar :: String
platformVariantEnvVar = stackProgNameUpper ++ "_PLATFORM_VARIANT"

-- | Provides --ghc-options for 'Ghc', and similarly, --ghcjs-options
-- for 'Ghcjs'.
compilerOptionsCabalFlag :: WhichCompiler -> String
compilerOptionsCabalFlag Ghc = "--ghc-options"
compilerOptionsCabalFlag Ghcjs = "--ghcjs-options"
1 change: 1 addition & 0 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ getPackageOptsAndTargetFiles pwd pkg = do
maybe [] (\cabalMacros -> ["-optP-include", "-optP" <> toFilePath cabalMacros]) (bioCabalMacros bio)
return
( ("--dist-dir=" <> toFilePathNoTrailingSep dist) :
-- FIXME: use compilerOptionsCabalFlag
map ("--ghc-option=" ++) (concatMap (ghcOptions . snd) (ghciPkgOpts pkg))
, mapMaybe
(fmap toFilePath . stripDir pwd)
Expand Down
4 changes: 3 additions & 1 deletion src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import GHC.Generics (Generic)
import Path (Path, Abs, File, Dir, mkRelDir, toFilePath, parseRelDir, (</>))
import Path.Extra (toFilePathNoTrailingSep)
import Prelude
import Stack.Constants
import Stack.Types.BuildPlan (GitSHA1)
import Stack.Types.Compiler
import Stack.Types.Config
Expand Down Expand Up @@ -541,14 +542,15 @@ configureOptsNoDir econfig bco deps isLocal package = concat
else "-") <>
flagNameString name)
(Map.toList flags)
, concatMap (\x -> ["--ghc-options", T.unpack x]) (packageGhcOptions package)
, concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) (packageGhcOptions package)
, map (("--extra-include-dirs=" ++) . toFilePathNoTrailingSep) (Set.toList (configExtraIncludeDirs config))
, map (("--extra-lib-dirs=" ++) . toFilePathNoTrailingSep) (Set.toList (configExtraLibDirs config))
, maybe [] (\customGcc -> ["--with-gcc=" ++ toFilePath customGcc]) (configOverrideGccPath config)
, ["--ghcjs" | whichCompiler (envConfigCompilerVersion econfig) == Ghcjs]
, ["--exact-configuration" | useExactConf]
]
where
wc = whichCompiler (envConfigCompilerVersion econfig)
config = getConfig econfig
bopts = bcoBuildOpts bco

Expand Down

0 comments on commit d94b1f0

Please sign in to comment.