Skip to content

Commit

Permalink
Merge pull request #4650 from commercialhaskell/4527-order-dependent-…
Browse files Browse the repository at this point in the history
…search-path

Make libs and includes order-dependent (fixes #4527)
  • Loading branch information
snoyberg authored Mar 25, 2019
2 parents 8b4d2df + 2d282ec commit 8369ea3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ Bug fixes:
* Using `--ghc-options` with `stack script --compile` now works.
* Ensure the detailed-0.9 type tests work.
See [#4453](https://github.com/commercialhaskell/stack/issues/4453).
* Extra include and lib dirs are now order-dependent. See
[#4527](https://github.com/commercialhaskell/stack/issues/4527).

## v1.9.3

Expand Down
9 changes: 4 additions & 5 deletions src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module Stack.Options.ConfigParser where

import Data.Char
import qualified Data.Set as Set
import Options.Applicative
import Options.Applicative.Builder.Extra
import Path
Expand Down Expand Up @@ -88,20 +87,20 @@ configOptsParser currentDir hide0 =
<> help "Number of concurrent jobs to run"
<> hide
))
<*> fmap Set.fromList (many ((currentDir FilePath.</>) <$> strOption
<*> many ((currentDir FilePath.</>) <$> strOption
( long "extra-include-dirs"
<> metavar "DIR"
<> completer dirCompleter
<> help "Extra directories to check for C header files"
<> hide
)))
<*> fmap Set.fromList (many ((currentDir FilePath.</>) <$> strOption
))
<*> many ((currentDir FilePath.</>) <$> strOption
( long "extra-lib-dirs"
<> metavar "DIR"
<> completer dirCompleter
<> help "Extra directories to check for libraries"
<> hide
)))
))
<*> optionalFirst (absFileOption
( long "with-gcc"
<> metavar "PATH-TO-GCC"
Expand Down
10 changes: 4 additions & 6 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ data BioInput = BioInput
, biAddPackages :: ![PackageName]
, biBuildInfo :: !BuildInfo
, biDotCabalPaths :: ![DotCabalPath]
, biConfigLibDirs :: !(Set FilePath)
, biConfigIncludeDirs :: !(Set FilePath)
, biConfigLibDirs :: ![FilePath]
, biConfigIncludeDirs :: ![FilePath]
, biComponentName :: !NamedComponent
, biCabalVersion :: !Version
}
Expand Down Expand Up @@ -407,17 +407,15 @@ generateBuildInfoOpts BioInput {..} =
toIncludeDir "." = Just biCabalDir
toIncludeDir relDir = concatAndColapseAbsDir biCabalDir relDir
includeOpts =
map ("-I" <>) (configExtraIncludeDirs <> pkgIncludeOpts)
configExtraIncludeDirs = S.toList biConfigIncludeDirs
map ("-I" <>) (biConfigIncludeDirs <> pkgIncludeOpts)
pkgIncludeOpts =
[ toFilePathNoTrailingSep absDir
| dir <- includeDirs biBuildInfo
, absDir <- handleDir dir
]
libOpts =
map ("-l" <>) (extraLibs biBuildInfo) <>
map ("-L" <>) (configExtraLibDirs <> pkgLibDirs)
configExtraLibDirs = S.toList biConfigLibDirs
map ("-L" <>) (biConfigLibDirs <> pkgLibDirs)
pkgLibDirs =
[ toFilePathNoTrailingSep absDir
| dir <- extraLibDirs biBuildInfo
Expand Down
5 changes: 2 additions & 3 deletions src/Stack/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Stack.Path

import Stack.Prelude
import Data.List (intercalate)
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Lens.Micro (lens)
Expand Down Expand Up @@ -186,10 +185,10 @@ paths =
, WithoutHaddocks $ view $ configL.to configLocalBin.to toFilePathNoTrailingSep.to T.pack)
, ( "Extra include directories"
, "extra-include-dirs"
, WithoutHaddocks $ T.intercalate ", " . map T.pack . Set.elems . configExtraIncludeDirs . view configL )
, WithoutHaddocks $ T.intercalate ", " . map T.pack . configExtraIncludeDirs . view configL )
, ( "Extra library directories"
, "extra-library-dirs"
, WithoutHaddocks $ T.intercalate ", " . map T.pack . Set.elems . configExtraLibDirs . view configL )
, WithoutHaddocks $ T.intercalate ", " . map T.pack . configExtraLibDirs . view configL )
, ( "Snapshot package database"
, "snapshot-pkg-db"
, WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piSnapDb )
Expand Down
12 changes: 6 additions & 6 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ withNewLocalBuildTargets targets f = do
-- | Add the include and lib paths to the given Config
addIncludeLib :: ExtraDirs -> Config -> Config
addIncludeLib (ExtraDirs _bins includes libs) config = config
{ configExtraIncludeDirs = Set.union
(configExtraIncludeDirs config)
(Set.fromList (map toFilePathNoTrailingSep includes))
, configExtraLibDirs = Set.union
(configExtraLibDirs config)
(Set.fromList (map toFilePathNoTrailingSep libs))
{ configExtraIncludeDirs =
configExtraIncludeDirs config ++
map toFilePathNoTrailingSep includes
, configExtraLibDirs =
configExtraLibDirs config ++
map toFilePathNoTrailingSep libs
}

-- | Ensure compiler (ghc or ghcjs) is installed and provide the PATHs to add if necessary
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ configureOptsNoDir econfig bco deps isLocal package = concat
flagNameString name)
(Map.toList flags)
, concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) (packageGhcOptions package)
, map ("--extra-include-dirs=" ++) (Set.toList (configExtraIncludeDirs config))
, map ("--extra-lib-dirs=" ++) (Set.toList (configExtraLibDirs config))
, map ("--extra-include-dirs=" ++) (configExtraIncludeDirs config)
, map ("--extra-lib-dirs=" ++) (configExtraLibDirs config)
, maybe [] (\customGcc -> ["--with-gcc=" ++ toFilePath customGcc]) (configOverrideGccPath config)
, ["--ghcjs" | wc == Ghcjs]
, ["--exact-configuration" | useExactConf]
Expand Down
16 changes: 8 additions & 8 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ data Config =
-- ^ How many concurrent jobs to run, defaults to number of capabilities
,configOverrideGccPath :: !(Maybe (Path Abs File))
-- ^ Optional gcc override path
,configExtraIncludeDirs :: !(Set FilePath)
,configExtraIncludeDirs :: ![FilePath]
-- ^ --extra-include-dirs arguments
,configExtraLibDirs :: !(Set FilePath)
,configExtraLibDirs :: ![FilePath]
-- ^ --extra-lib-dirs arguments
,configConcurrentTests :: !Bool
-- ^ Run test suites concurrently
Expand Down Expand Up @@ -703,9 +703,9 @@ data ConfigMonoid =
-- ^ Used for overriding the GHC build
,configMonoidJobs :: !(First Int)
-- ^ See: 'configJobs'
,configMonoidExtraIncludeDirs :: !(Set FilePath)
,configMonoidExtraIncludeDirs :: ![FilePath]
-- ^ See: 'configExtraIncludeDirs'
,configMonoidExtraLibDirs :: !(Set FilePath)
,configMonoidExtraLibDirs :: ![FilePath]
-- ^ See: 'configExtraLibDirs'
, configMonoidOverrideGccPath :: !(First (Path Abs File))
-- ^ Allow users to override the path to gcc
Expand Down Expand Up @@ -808,10 +808,10 @@ parseConfigMonoidObject rootDir obj = do
configMonoidGHCVariant <- First <$> obj ..:? configMonoidGHCVariantName
configMonoidGHCBuild <- First <$> obj ..:? configMonoidGHCBuildName
configMonoidJobs <- First <$> obj ..:? configMonoidJobsName
configMonoidExtraIncludeDirs <- fmap (Set.map (toFilePath rootDir FilePath.</>)) $
obj ..:? configMonoidExtraIncludeDirsName ..!= Set.empty
configMonoidExtraLibDirs <- fmap (Set.map (toFilePath rootDir FilePath.</>)) $
obj ..:? configMonoidExtraLibDirsName ..!= Set.empty
configMonoidExtraIncludeDirs <- map (toFilePath rootDir FilePath.</>) <$>
obj ..:? configMonoidExtraIncludeDirsName ..!= []
configMonoidExtraLibDirs <- map (toFilePath rootDir FilePath.</>) <$>
obj ..:? configMonoidExtraLibDirsName ..!= []
configMonoidOverrideGccPath <- First <$> obj ..:? configMonoidOverrideGccPathName
configMonoidOverrideHpack <- First <$> obj ..:? configMonoidOverrideHpackName
configMonoidConcurrentTests <- First <$> obj ..:? configMonoidConcurrentTestsName
Expand Down

0 comments on commit 8369ea3

Please sign in to comment.