Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish new-install #5399

Merged
merged 39 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bbbb833
Allow resolveTargets to know about Hackage packages
typedrat Jun 12, 2018
ceb0db8
Remove redundant import
typedrat Jun 12, 2018
97f4a47
Teach new-install to build non-local exes
typedrat Jun 13, 2018
78cb12b
WIP, waiting on a way to make a SourceHash of a local file. `sdist`?
typedrat Jun 13, 2018
da8c04d
Unbreak broken things
typedrat Jun 19, 2018
067b467
Add local target support
typedrat Jun 26, 2018
72c9db4
Fix new-install outside of packages
typedrat Jun 26, 2018
ccbf77a
Add library component installation support
typedrat Jun 27, 2018
57f6c92
Restructure code, fix library new-install solving on macOS
typedrat Jul 6, 2018
6df9877
Fix typo
typedrat Jul 6, 2018
c217882
Fix typo 2: fix harder
typedrat Jul 6, 2018
f1deb37
Add warning when library installation isn't possible
typedrat Jul 6, 2018
ab3392b
Document new-install's completion
typedrat Jul 6, 2018
9d050f9
Fix missing imports
typedrat Jul 7, 2018
3e4bf39
Remove unneeded imports (Fix -Werror failure)
typedrat Jul 7, 2018
945a40f
Use correct program DB
typedrat Jul 7, 2018
802c57a
Remove old TODOs [ci skip]
typedrat Jul 7, 2018
c931050
Use updated program DB.
typedrat Jul 7, 2018
fd1cec6
Add correct prefix to sdists
typedrat Jul 7, 2018
0d9afdd
Fix logic error in CmdInstall
typedrat Jul 7, 2018
8030619
Drop Parsec dependency in cabal-install
typedrat Jul 7, 2018
063efa8
(Hopefully) fix GHC 7.10
typedrat Jul 7, 2018
1fb3464
Fix incorrect environment parser
typedrat Jul 7, 2018
c28caec
Expose `parseGhcEnvironmentFile`.
typedrat Jul 7, 2018
7935920
Add warning if environment file is unparsable
typedrat Jul 7, 2018
f0d374d
Add GHC core libraries to environment file by default
typedrat Jul 7, 2018
9068961
Fix sdist tests
typedrat Jul 7, 2018
4467a90
Fix zip sdists as well
typedrat Jul 7, 2018
f100994
Remove redundant import
typedrat Jul 7, 2018
12479ba
Add `--lib` option
typedrat Jul 10, 2018
11e2d0d
Add flag to control library installation
typedrat Jul 10, 2018
1f5225e
Fix new-install by 'PackageId'
typedrat Jul 10, 2018
4bff0e4
Add --env-cwd
typedrat Jul 10, 2018
e0ee808
Change environment flag to mirror GHC
typedrat Jul 10, 2018
832a532
Fix code clean-up error
typedrat Jul 10, 2018
ec97ec0
Update documentation with accurate usage
typedrat Jul 12, 2018
1fc266e
Fix verbosity-parsing bug.
typedrat Jul 12, 2018
7d961eb
Make packageToSdist restore $OLDPWD
typedrat Jul 12, 2018
6b06e6a
Fix ProjectPlanning so not all SpecificSourcePackages are local
typedrat Jul 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ library
Distribution.GetOpt
Distribution.Lex
Distribution.Utils.String
Distribution.Simple.GHC.EnvironmentParser
Distribution.Simple.GHC.Internal
Distribution.Simple.GHC.IPI642
Distribution.Simple.GHC.IPIConvert
Expand Down
1 change: 1 addition & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 2.4.0.0 (current development version)
* Add `readGhcEnvironmentFile` to parse GHC environment files.
* Drop support for GHC 7.4, since it is out of our support window
(and has been for over a year!)
* Deprecate `preSDist`, `sDistHook`, and `postSDist` in service of
Expand Down
8 changes: 7 additions & 1 deletion Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ module Distribution.Simple.GHC (
isDynamic,
getGlobalPackageDB,
pkgRoot,
-- * Constructing GHC environment files
-- * Constructing and deconstructing GHC environment files
Internal.GhcEnvironmentFileEntry(..),
Internal.simpleGhcEnvironmentFile,
Internal.renderGhcEnvironmentFile,
Internal.writeGhcEnvironmentFile,
Internal.ghcPlatformAndVersionString,
readGhcEnvironmentFile,
parseGhcEnvironmentFile,
ParseErrorExc(..),
-- * Version-specific implementation quirks
getImplInfo,
GhcImplInfo(..)
Expand All @@ -68,6 +73,7 @@ import Distribution.Compat.Prelude
import qualified Distribution.Simple.GHC.IPI642 as IPI642
import qualified Distribution.Simple.GHC.Internal as Internal
import Distribution.Simple.GHC.ImplInfo
import Distribution.Simple.GHC.EnvironmentParser
import Distribution.PackageDescription.Utils (cabalBug)
import Distribution.PackageDescription as PD
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
Expand Down
51 changes: 51 additions & 0 deletions Cabal/Distribution/Simple/GHC/EnvironmentParser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module Distribution.Simple.GHC.EnvironmentParser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GHC has code for parsing these files in DynFlags, but this code is better and we should have an eye on reusing it in GHC. Specifically, I think exporting parseEnvironmentFile along with GhcEnvironmentFileEntry and its constructors from a non-internal module ought to be enough (which we ought to do anyway, since it's mentioned in the types of this non-internal module).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already exposed in Distribution.Simple.GHC. When we get this merged and available to GHC, I'd be happy to write a patch to use this instead. :)

( parseGhcEnvironmentFile, readGhcEnvironmentFile, ParseErrorExc(..) ) where

import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Simple.Compiler
( PackageDB(..) )
import Distribution.Simple.GHC.Internal
( GhcEnvironmentFileEntry(..) )
import Distribution.Types.UnitId
( mkUnitId )

import Control.Exception
( Exception, throwIO )
import qualified Text.Parsec as P
import Text.Parsec.String
( Parser, parseFromFile )

parseEnvironmentFileLine :: Parser GhcEnvironmentFileEntry
parseEnvironmentFileLine = GhcEnvFileComment <$> comment
<|> GhcEnvFilePackageId <$> unitId
<|> GhcEnvFilePackageDb <$> packageDb
<|> pure GhcEnvFileClearPackageDbStack <* clearDb
where
comment = P.string "--" *> P.many (P.noneOf "\r\n")
unitId = P.try $ P.string "package-id" *> P.spaces *>
(mkUnitId <$> P.many1 (P.satisfy $ \c -> isAlphaNum c || c `elem` "-_.+"))
packageDb = (P.string "global-package-db" *> pure GlobalPackageDB)
<|> (P.string "user-package-db" *> pure UserPackageDB)
<|> (P.string "package-db" *> P.spaces *> (SpecificPackageDB <$> P.many1 (P.noneOf "\r\n") <* P.lookAhead P.endOfLine))
clearDb = P.string "clear-package-db"

newtype ParseErrorExc = ParseErrorExc P.ParseError
deriving (Show, Typeable)

instance Exception ParseErrorExc

parseGhcEnvironmentFile :: Parser [GhcEnvironmentFileEntry]
parseGhcEnvironmentFile = parseEnvironmentFileLine `P.sepEndBy` P.endOfLine <* P.eof

readGhcEnvironmentFile :: FilePath -> IO [GhcEnvironmentFileEntry]
readGhcEnvironmentFile path =
either (throwIO . ParseErrorExc) return =<<
parseFromFile parseGhcEnvironmentFile path
1 change: 1 addition & 0 deletions Cabal/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ data GhcEnvironmentFileEntry =
-- @user-package-db@ or
-- @package-db blah/package.conf.d/@
| GhcEnvFileClearPackageDbStack -- ^ @clear-package-db@
deriving (Eq, Ord, Show)

-- | Make entries for a GHC environment file based on a 'PackageDBStack' and
-- a bunch of package (unit) ids.
Expand Down
75 changes: 59 additions & 16 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ A major deficiency in the current implementation of new-build is that
there is no programmatic way to access the location of build products.
The location of the build products is intended to be an internal
implementation detail of new-build, but we also understand that many
unimplemented features (e.g., ``new-install``) can only be reasonably
worked around by accessing build products directly.
unimplemented features can only be reasonably worked around by
accessing build products directly.

The location where build products can be found varies depending on the
version of cabal-install:
Expand Down Expand Up @@ -461,8 +461,8 @@ invocations and bringing the project's executables into scope.
cabal new-install
-----------------

``cabal new-install [FLAGS] PACKAGES`` builds the specified nonlocal packages
and symlinks their executables in ``symlink-bindir`` (usually ``~/.cabal/bin``).
``cabal new-install [FLAGS] PACKAGES`` builds the specified packages and
symlinks their executables in ``symlink-bindir`` (usually ``~/.cabal/bin``).

For example this command will build the latest ``cabal-install`` and symlink
its ``cabal`` executable:
Expand All @@ -471,8 +471,61 @@ its ``cabal`` executable:

$ cabal new-install cabal-install

For libraries and local packages see
`Unsupported commands <#unsupported-commands>`__
In addition, it's possible to use ``cabal new-install`` to install components
of a local project. For example, with an up-to-date Git clone of the Cabal
repository, this command will build cabal-install HEAD and symlink the
``cabal`` executable:

::

$ cabal new-install exe:cabal

It is also possible to "install" libraries using the ``--lib`` flag. For
example, this command will build the latest Cabal library and install it:

::

$ cabal new-install --lib Cabal

This works by managing GHC environments. By default, it is writing to the
global environment in ``~/.ghc/$ARCH-$OS-$GHCVER/environments/default``.
``new-install`` provides the ``--package-env`` flag to control which of
these environments is modified.

This command will modify the environment file in the current directory:

::

$ cabal new-install --lib Cabal --package-env .

This command will modify the enviroment file in the ``~/foo`` directory:

::

$ cabal new-install --lib Cabal --package-env foo/

Do note that the results of the previous two commands will be overwritten by
the use of other new-style commands, so it is not reccomended to use them inside
a project directory.

This command will modify the environment in the "local.env" file in the
current directory:

::

$ cabal new-install --lib Cabal --package-env local.env

This command will modify the ``myenv`` named global environment:

::

$ cabal new-install --lib Cabal --package-env myenv

If you wish to create a named environment file in the current directory where
the name does not contain an extension, you must reference it as ``./myenv``.

You can learn more about how to use these environments in `this section of the
GHC manual <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments>`_.

cabal new-clean
---------------
Expand Down Expand Up @@ -515,16 +568,6 @@ byte) that must be satisfied for it to function correctly in the larger new-buil
``autogen-modules`` is able to replace uses of the hooks to add generated modules, along with
the custom publishing of Haddock documentation to Hackage.

Unsupported commands
--------------------

The following commands are not currently supported:

``cabal new-install`` (libraries and local executables)
(:issue:`3737` and :issue:`4558`)
Workaround: no good workaround at the moment. (But note that you no
longer need to install libraries before building!)

Configuring builds with cabal.project
=====================================

Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ benchAction (configFlags, configExFlags, installFlags, haddockFlags)
selectComponentTarget
TargetProblemCommon
elaboratedPlan
Nothing
targetSelectors

let elaboratedPlan' = pruneInstallPlanToTargets
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ buildAction (configFlags, configExFlags, installFlags, haddockFlags)
selectComponentTarget
TargetProblemCommon
elaboratedPlan
Nothing
targetSelectors

let elaboratedPlan' = pruneInstallPlanToTargets
Expand Down
6 changes: 6 additions & 0 deletions cabal-install/Distribution/Client/CmdErrorMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ renderTargetProblemCommon verb (TargetNotInProject pkgname) =
++ "in this project (either directly or indirectly). If you want to add it "
++ "to the project then edit the cabal.project file."

renderTargetProblemCommon verb (TargetAvailableInIndex pkgname) =
"Cannot " ++ verb ++ " the package " ++ display pkgname ++ ", it is not "
++ "in this project (either directly or indirectly), but it is in the current "
++ "package index. If you want to add it to the project then edit the "
++ "cabal.project file."

renderTargetProblemCommon verb (TargetComponentNotProjectLocal pkgid cname _) =
"Cannot " ++ verb ++ " the " ++ showComponentName cname ++ " because the "
++ "package " ++ display pkgid ++ " is not local to the project, and cabal "
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ haddockAction (configFlags, configExFlags, installFlags, haddockFlags)
selectComponentTarget
TargetProblemCommon
elaboratedPlan
Nothing
targetSelectors

let elaboratedPlan' = pruneInstallPlanToTargets
Expand Down
Loading