Skip to content

Commit e3b8d2c

Browse files
authored
Merge branch 'master' into less-noisy-ghc-pkg
2 parents 3ec000d + 127add2 commit e3b8d2c

31 files changed

Lines changed: 245 additions & 11 deletions

File tree

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ Behavior changes:
1111

1212
Other enhancements:
1313

14+
* On Windows, recognise a 'mintty' (false) terminal as a terminal, by default
15+
1416
Bug fixes:
1517

1618
* `~/.stack/config.yaml` and `stack.yaml` terminating by newline
1719
* The previous released caused a regression where some `stderr` from the
1820
`ghc-pkg` command showed up in the terminal. This output is now silenced.
21+
* A regression in recompilation checking introduced in v1.7.1 has been fixed.
22+
See [#4001](https://github.com/commercialhaskell/stack/issues/4001)
23+
* `stack ghci` on a package with internal libraries was erroneously looking
24+
for a wrong package corresponding to the internal library and failing to
25+
load any module. This has been fixed now and changes to the code in the
26+
library and the sublibrary are properly tracked. See
27+
[#3926](https://github.com/commercialhaskell/stack/issues/3926).
1928

2029

2130
## v1.7.1

package.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ghc-options:
3333
- -fwarn-tabs
3434
- -fwarn-incomplete-uni-patterns
3535
- -fwarn-incomplete-record-updates
36+
- -optP-Wno-nonportable-include-path # workaround [Filename case on macOS · Issue #4739 · haskell/cabal](https://github.com/haskell/cabal/issues/4739)
3637
dependencies:
3738
- Cabal
3839
- aeson
@@ -120,7 +121,7 @@ when:
120121
then:
121122
cpp-options: -DWINDOWS
122123
dependencies:
123-
- Win32
124+
- Win32 >= 2.5.3.0
124125
else:
125126
build-tools:
126127
- hsc2hs

src/Stack/Build/Execute.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
14211421
unless (null warnings) $ prettyWarn $
14221422
"The following modules should be added to exposed-modules or other-modules in" <+>
14231423
display cabalfp <> ":" <> line <>
1424-
indent 4 (mconcat $ map showModuleWarning warnings) <>
1424+
indent 4 (mconcat $ intersperse line $ map showModuleWarning warnings) <>
14251425
line <> line <>
14261426
"Missing modules in the cabal file are likely to cause undefined reference errors from the linker, along with other problems."
14271427

src/Stack/Build/Source.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ getPackageFilesForTargets
437437
getPackageFilesForTargets pkg cabalFP nonLibComponents = do
438438
(components',compFiles,otherFiles,warnings) <-
439439
getPackageFiles (packageFiles pkg) cabalFP
440-
let components = M.keysSet components' `Set.union` nonLibComponents
440+
let necessaryComponents = Set.insert CLib $ Set.filter isCInternalLib (M.keysSet components')
441+
components = necessaryComponents `Set.union` nonLibComponents
441442
componentsFiles =
442443
M.map (\files -> Set.union otherFiles (Set.map dotCabalGetPath files)) $
443444
M.filterWithKey (\component _ -> component `Set.member` components) compFiles

src/Stack/Docker.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ runContainerAndExit getCmdArgs
243243
(env,isStdinTerminal,isStderrTerminal,homeDir) <- liftIO $
244244
(,,,)
245245
<$> getEnvironment
246-
<*> hIsTerminalDevice stdin
247-
<*> hIsTerminalDevice stderr
246+
<*> hIsTerminalDeviceOrMinTTY stdin
247+
<*> hIsTerminalDeviceOrMinTTY stderr
248248
<*> (parseAbsDir =<< getHomeDirectory)
249249
isStdoutTerminal <- view terminalL
250250
let dockerHost = lookup "DOCKER_HOST" env

src/Stack/FileWatch.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fileWatchConf :: WatchConfig
3535
-> IO ()
3636
fileWatchConf cfg out inner = withManagerConf cfg $ \manager -> do
3737
let putLn = hPutStrLn out
38-
outputIsTerminal <- hIsTerminalDevice out
38+
outputIsTerminal <- hIsTerminalDeviceOrMinTTY out
3939
let withColor color str = putLn $ do
4040
if outputIsTerminal
4141
then concat [color, str, reset]

src/Stack/Ghci.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,9 @@ wantedPackageComponents _ (TargetComps cs) _ = cs
661661
wantedPackageComponents bopts (TargetAll ProjectPackage) pkg = S.fromList $
662662
(case packageLibraries pkg of
663663
NoLibraries -> []
664-
HasLibraries _names -> [CLib]) ++ -- FIXME. This ignores sub libraries and foreign libraries. Is that OK?
664+
HasLibraries names -> CLib : map CInternalLib (S.toList names)) ++
665665
map CExe (S.toList (packageExes pkg)) <>
666+
map CInternalLib (S.toList $ packageInternalLibraries pkg) <>
666667
(if boptsTests bopts then map CTest (M.keys (packageTests pkg)) else []) <>
667668
(if boptsBenchmarks bopts then map CBench (S.toList (packageBenchmarks pkg)) else [])
668669
wantedPackageComponents _ _ _ = S.empty

src/Stack/Package.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import qualified Distribution.Types.CondTree as Cabal
6464
import qualified Distribution.Types.ExeDependency as Cabal
6565
import Distribution.Types.ForeignLib
6666
import qualified Distribution.Types.LegacyExeDependency as Cabal
67+
import Distribution.Types.MungedPackageName
6768
import qualified Distribution.Types.UnqualComponentName as Cabal
6869
import qualified Distribution.Verbosity as D
6970
import Lens.Micro (lens)
@@ -279,6 +280,7 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
279280
| null extraLibNames -> NoLibraries
280281
| otherwise -> error "Package has buildable sublibraries but no buildable libraries, I'm giving up"
281282
Just _ -> HasLibraries foreignLibNames
283+
, packageInternalLibraries = subLibNames
282284
, packageTests = M.fromList
283285
[(T.pack (Cabal.unUnqualComponentName $ testName t), testInterface t)
284286
| t <- testSuites pkgNoMod
@@ -299,8 +301,13 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
299301
, packageOpts = GetPackageOpts $
300302
\sourceMap installedMap omitPkgs addPkgs cabalfp ->
301303
do (componentsModules,componentFiles,_,_) <- getPackageFiles pkgFiles cabalfp
304+
let internals = S.toList $ internalLibComponents $ M.keysSet componentsModules
305+
excludedInternals <- mapM parsePackageName internals
306+
mungedInternals <- mapM (parsePackageName . toInternalPackageMungedName) internals
302307
componentsOpts <-
303-
generatePkgDescOpts sourceMap installedMap omitPkgs addPkgs cabalfp pkg componentFiles
308+
generatePkgDescOpts sourceMap installedMap
309+
(excludedInternals ++ omitPkgs) (mungedInternals ++ addPkgs)
310+
cabalfp pkg componentFiles
304311
return (componentsModules,componentFiles,componentsOpts)
305312
, packageHasExposedModules = maybe
306313
False
@@ -325,6 +332,10 @@ packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkg
325332
$ filter (buildable . foreignLibBuildInfo)
326333
$ foreignLibs pkg
327334

335+
toInternalPackageMungedName
336+
= T.pack . unMungedPackageName . computeCompatPackageName (pkgName pkgId)
337+
. Just . Cabal.mkUnqualComponentName . T.unpack
338+
328339
-- Gets all of the modules, files, build files, and data files that
329340
-- constitute the package. This is primarily used for dirtiness
330341
-- checking during build, as well as use by "stack ghci"
@@ -411,6 +422,12 @@ generatePkgDescOpts sourceMap installedMap omitPkgs addPkgs cabalfp pkg componen
411422
[]
412423
(return . generate CLib . libBuildInfo)
413424
(library pkg)
425+
, mapMaybe
426+
(\sublib -> do
427+
let maybeLib = CInternalLib . T.pack . Cabal.unUnqualComponentName <$> libName sublib
428+
flip generate (libBuildInfo sublib) <$> maybeLib
429+
)
430+
(subLibraries pkg)
414431
, fmap
415432
(\exe ->
416433
generate
@@ -698,7 +715,7 @@ packageDescModulesAndFiles
698715
:: PackageDescription
699716
-> RIO Ctx (Map NamedComponent (Map ModuleName (Path Abs File)), Map NamedComponent (Set DotCabalPath), Set (Path Abs File), [PackageWarning])
700717
packageDescModulesAndFiles pkg = do
701-
(libraryMods,libDotCabalFiles,libWarnings) <- -- FIXME add in sub libraries
718+
(libraryMods,libDotCabalFiles,libWarnings) <-
702719
maybe
703720
(return (M.empty, M.empty, []))
704721
(asModuleAndFileMap libComponent libraryFiles)

src/Stack/Prelude.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE NoImplicitPrelude #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE ScopedTypeVariables #-}
@@ -13,6 +14,7 @@ module Stack.Prelude
1314
, readProcessNull
1415
, withProcessContext
1516
, stripCR
17+
, hIsTerminalDeviceOrMinTTY
1618
, module X
1719
) where
1820

@@ -30,6 +32,10 @@ import qualified System.Directory as Dir
3032
import qualified System.FilePath as FP
3133
import System.IO.Error (isDoesNotExistError)
3234

35+
#ifdef WINDOWS
36+
import System.Win32 (isMinTTYHandle, withHandleToHANDLE)
37+
#endif
38+
3339
import Data.Conduit.Binary (sourceHandle, sinkHandle)
3440
import qualified Data.Conduit.Binary as CB
3541
import qualified Data.Conduit.List as CL
@@ -151,3 +157,16 @@ withProcessContext pcNew inner = do
151157
-- | Remove a trailing carriage return if present
152158
stripCR :: Text -> Text
153159
stripCR = T.dropSuffix "\r"
160+
161+
-- | hIsTerminaDevice does not recognise handles to mintty terminals as terminal
162+
-- devices, but isMinTTYHandle does.
163+
hIsTerminalDeviceOrMinTTY :: MonadIO m => Handle -> m Bool
164+
#ifdef WINDOWS
165+
hIsTerminalDeviceOrMinTTY h = do
166+
isTD <- hIsTerminalDevice h
167+
if isTD
168+
then return True
169+
else liftIO $ withHandleToHANDLE h isMinTTYHandle
170+
#else
171+
hIsTerminalDeviceOrMinTTY = hIsTerminalDevice
172+
#endif

src/Stack/Types/NamedComponent.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ module Stack.Types.NamedComponent
88
, exeComponents
99
, testComponents
1010
, benchComponents
11+
, internalLibComponents
1112
, isCLib
13+
, isCInternalLib
1214
, isCExe
1315
, isCTest
1416
, isCBench
@@ -59,10 +61,20 @@ benchComponents = Set.fromList . mapMaybe mBenchName . Set.toList
5961
mBenchName (CBench name) = Just name
6062
mBenchName _ = Nothing
6163

64+
internalLibComponents :: Set NamedComponent -> Set Text
65+
internalLibComponents = Set.fromList . mapMaybe mInternalName . Set.toList
66+
where
67+
mInternalName (CInternalLib name) = Just name
68+
mInternalName _ = Nothing
69+
6270
isCLib :: NamedComponent -> Bool
6371
isCLib CLib{} = True
6472
isCLib _ = False
6573

74+
isCInternalLib :: NamedComponent -> Bool
75+
isCInternalLib CInternalLib{} = True
76+
isCInternalLib _ = False
77+
6678
isCExe :: NamedComponent -> Bool
6779
isCExe CExe{} = True
6880
isCExe _ = False

0 commit comments

Comments
 (0)