Skip to content

Commit

Permalink
Merge branch 'master' into colton/haskell#8864
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored May 18, 2023
2 parents f152568 + 3674900 commit 62610f9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 15 deletions.
4 changes: 3 additions & 1 deletion Cabal/src/Distribution/Simple/BuildTarget.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Distribution.Utils.Path

import qualified Distribution.Compat.CharParsing as P

import Control.Arrow ( (&&&) )
import Control.Monad ( msum )
import Data.List ( stripPrefix, groupBy )
import qualified Data.List.NonEmpty as NE
Expand Down Expand Up @@ -320,7 +321,8 @@ resolveBuildTarget pkg userTarget fexists =
where
classifyMatchErrors errs
| Just expected' <- NE.nonEmpty expected
= let (things, got:|_) = NE.unzip expected' in
= let unzip' = fmap fst &&& fmap snd
(things, got:|_) = unzip' expected' in
BuildTargetExpected userTarget (NE.toList things) got
| not (null nosuch) = BuildTargetNoSuch userTarget nosuch
| otherwise = error $ "resolveBuildTarget: internal error in matching"
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Setup/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defaultTestFlags = TestFlags {
testVerbosity = Flag normal,
testHumanLog = toFlag $ toPathTemplate $ "$pkgid-$test-suite.log",
testMachineLog = toFlag $ toPathTemplate $ "$pkgid.log",
testShowDetails = toFlag Failures,
testShowDetails = toFlag Direct,
testKeepTix = toFlag False,
testWrapper = NoFlag,
testFailWhenNoTestSuites = toFlag False,
Expand Down
31 changes: 25 additions & 6 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import Distribution.Simple.Configure
( configCompilerEx )
import Distribution.Simple.Compiler
( Compiler(..), CompilerId(..), CompilerFlavor(..)
, PackageDBStack )
, PackageDBStack, PackageDB(..) )
import Distribution.Simple.GHC
( ghcPlatformAndVersionString, getGhcAppDir
, GhcImplInfo(..), getImplInfo
Expand All @@ -123,11 +123,13 @@ import Distribution.Verbosity
import Distribution.Simple.Utils
( wrapText, die', notice, warn
, withTempDirectory, createDirectoryIfMissingVerbose
, ordNub )
, ordNub, safeHead )
import Distribution.Utils.Generic
( writeFileAtomic )

import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Ord
( Down(..) )
import qualified Data.Map as Map
import qualified Data.Set as S
import qualified Data.List.NonEmpty as NE
Expand Down Expand Up @@ -424,7 +426,7 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
unless dryRun $
if installLibs
then installLibraries verbosity
buildCtx compiler packageDbs envFile nonGlobalEnvEntries'
buildCtx installedIndex compiler packageDbs envFile nonGlobalEnvEntries'
else installExes verbosity
baseCtx buildCtx platform compiler configFlags clientInstallFlags
where
Expand Down Expand Up @@ -687,20 +689,31 @@ installExes verbosity baseCtx buildCtx platform compiler
installLibraries
:: Verbosity
-> ProjectBuildContext
-> PI.PackageIndex InstalledPackageInfo
-> Compiler
-> PackageDBStack
-> FilePath -- ^ Environment file
-> [GhcEnvironmentFileEntry]
-> IO ()
installLibraries verbosity buildCtx compiler
packageDbs envFile envEntries = do
installLibraries verbosity buildCtx installedIndex compiler
packageDbs' envFile envEntries = do
if supportsPkgEnvFiles $ getImplInfo compiler
then do
let validDb (SpecificPackageDB fp) = doesPathExist fp
validDb _ = pure True
-- if a user "installs" a global package and no existing cabal db exists, none will be created.
-- this ensures we don't add the "phantom" path to the file.
packageDbs <- filterM validDb packageDbs'
let
getLatest = (=<<) (maybeToList . safeHead . snd) . take 1 . sortBy (comparing (Down . fst))
. PI.lookupPackageName installedIndex
globalLatest = concat (getLatest <$> globalPackages)
globalEntries = GhcEnvFilePackageId . installedUnitId <$> globalLatest
baseEntries =
GhcEnvFileClearPackageDbStack : fmap GhcEnvFilePackageDb packageDbs
pkgEntries = ordNub $
envEntries
globalEntries
++ envEntries
++ entriesForLibraryComponents (targetsMap buildCtx)
contents' = renderGhcEnvironmentFile (baseEntries ++ pkgEntries)
createDirectoryIfMissing True (takeDirectory envFile)
Expand All @@ -711,6 +724,12 @@ installLibraries verbosity buildCtx compiler
++ "so only executables will be available. (Library installation is "
++ "supported on GHC 8.0+ only)"

-- See ticket #8894. This is safe to include any nonreinstallable boot pkg,
-- but the particular package users will always expect to be in scope without specific installation
-- is base, so that they can access prelude, regardles of if they specifically asked for it.
globalPackages :: [PackageName]
globalPackages = mkPackageName <$> [ "base" ]

warnIfNoExes :: Verbosity -> ProjectBuildContext -> IO ()
warnIfNoExes verbosity buildCtx =
when noExes $
Expand Down
15 changes: 15 additions & 0 deletions changelog.d/issue-7817
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
synopsis: Make --(test-)show-details=direct the default
packages: Cabal cabal-install
prs: #8942

description: {

This option leaves it up to the testing framework to decide what and how to print out,
potentially leading to a prettier output. For example, most of the testing frameworks
use colors, which wouldn't be seen with any other option.

This comes with a tradeoff, though: Cabal will not create a log file with this option.
If you prefer a log file, consider setting `--test-show-details=streaming` (or something
else) manually.

}
9 changes: 9 additions & 0 deletions changelog.d/pr-8903
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
synopsis: add base to cabal install --lib default env file
packages: cabal-install
prs: #8903

description: {

This adds base by default to the env file created by `cabal install --lib`. Further it ensures that packagedbs have been created before adding them to the env file.

}
13 changes: 9 additions & 4 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ http://cabal.readthedocs.io/

### How to build it

Building the documentation requires Python 3 be installed
* `> make users-guide`
* Python on Mac OS X dislikes `LC_CTYPE=UTF-8`, unset the env var in
terminal preferences and instead set `LC_ALL=en_US.UTF-8` or something
Building the documentation requires Python 3 and PIP. From the root of cabal
repository run:

``` console
make users-guide
```

Note: Python on Mac OS X dislikes `LC_CTYPE=UTF-8`, so unset the variable
and instead set `LC_ALL=en_US.UTF-8`.

### Gitpod workflow

Expand Down
11 changes: 10 additions & 1 deletion doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ legacy sections. We talk in detail about some global and package commands.

run Run an executable.
repl Open an interactive session for the given component.
test Run test-suites.
test Run test suites.
bench Run benchmarks.

sdist Generate a source distribution file (.tar.gz).
Expand Down Expand Up @@ -970,13 +970,22 @@ cabal bench
(all the benchmarks in the current package by default), first ensuring
they are up to date.

``cabal bench`` inherits flags of the ``bench`` subcommand of ``Setup.hs``,
:ref:`see the corresponding section <setup-bench>`.

cabal test
^^^^^^^^^^

``cabal test [TARGETS] [OPTIONS]`` runs the specified test suites
(all the test suites in the current package by default), first ensuring
they are up to date.

``cabal test`` inherits flags of the ``test`` subcommand of ``Setup.hs``
(:ref:`see the corresponding section <setup-test>`) with one caveat: every
``Setup.hs test`` flag receives the ``test-`` prefix if it already does
not have one; e.g. ``--show-details`` becomes ``--test-show-details`` but
``--test-wrapper`` remains the same.

cabal exec
^^^^^^^^^^

Expand Down
10 changes: 8 additions & 2 deletions doc/setup-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,14 @@ the package.

Determines if the results of individual test cases are shown on the
terminal. May be ``always`` (always show), ``never`` (never show),
``failures`` (show only failed results), or ``streaming`` (show all
results in real time).
``failures`` (show only failed results), ``streaming`` (show all
results in real time) and ``direct`` (same as ``streaming`` but no log
file and possibly prettier).

Default value is ``direct``: it leaves test output untouched and does not
produce a log. This allows for colored output, which is popular with testing
frameworks. (On the other hand, ``streaming`` creates a log but looses
coloring.)

.. option:: --test-options=options

Expand Down

0 comments on commit 62610f9

Please sign in to comment.