Skip to content

Commit

Permalink
Allow specifying default behaviour as a install-method flag input, ad…
Browse files Browse the repository at this point in the history
…d documentation
  • Loading branch information
phadej committed Jan 31, 2020
1 parent 7bae16f commit b85029f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Cabal/Distribution/Simple/Flag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Distribution.Simple.Flag (
toFlag,
fromFlag,
fromFlagOrDefault,
flagElim,
flagToMaybe,
flagToList,
maybeToFlag,
Expand Down Expand Up @@ -105,6 +106,11 @@ flagToMaybe :: Flag a -> Maybe a
flagToMaybe (Flag x) = Just x
flagToMaybe NoFlag = Nothing

-- | @since 3.4.0.0
flagElim :: b -> (a -> b) -> Flag a -> b
flagElim n _ NoFlag = n
flagElim _ f (Flag x) = f x

flagToList :: Flag a -> [a]
flagToList (Flag x) = [x]
flagToList NoFlag = []
Expand Down
5 changes: 3 additions & 2 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ repository, this command will build cabal-install HEAD and symlink the

$ cabal v2-install exe:cabal

Where symlinking is not possible (eg. on Windows), ``--install-method=copy``
can be used:
Where symlinking is not possible (eg. on Windows) the ``copy`` method
is used by default. You can specify the instll method
by using ``--install-method`` flag:

::

Expand Down
19 changes: 13 additions & 6 deletions cabal-install/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ import Distribution.Client.RebuildMonad
( runRebuild )
import Distribution.Client.InstallSymlink
( OverwritePolicy(..), symlinkBinary )
import Distribution.Simple.Flag
( fromFlagOrDefault, flagToMaybe, flagElim )
import Distribution.Simple.Setup
( Flag(..), HaddockFlags, TestFlags, BenchmarkFlags
, fromFlagOrDefault, flagToMaybe )
( Flag(..), HaddockFlags, TestFlags, BenchmarkFlags )
import Distribution.Solver.Types.SourcePackage
( SourcePackage(..) )
import Distribution.Simple.Command
Expand Down Expand Up @@ -660,6 +661,10 @@ installExes verbosity baseCtx buildCtx platform compiler
pure <$> cinstInstalldir clientInstallFlags
createDirectoryIfMissingVerbose verbosity False installdir
warnIfNoExes verbosity buildCtx

installMethod <- flagElim defaultMethod return $
cinstInstallMethod clientInstallFlags

let
doInstall = installUnitExes
verbosity
Expand All @@ -671,12 +676,14 @@ installExes verbosity baseCtx buildCtx platform compiler
overwritePolicy = fromFlagOrDefault NeverOverwrite $
cinstOverwritePolicy clientInstallFlags
isWindows = System.Info.os == "mingw32"

-- This is in IO as we will make environment checks,
-- to decide which method is best
defaultMethod :: IO InstallMethod
defaultMethod
-- Copy since windows doesn't support symlinks by default
| isWindows = InstallMethodCopy
| otherwise = InstallMethodSymlink
installMethod = fromFlagOrDefault defaultMethod $
cinstInstallMethod clientInstallFlags
| isWindows = return InstallMethodCopy
| otherwise = return InstallMethodSymlink

-- | Install any built library by adding it to the default ghc environment
installLibraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ clientInstallOptions _ =
"How to install the executables."
cinstInstallMethod (\v flags -> flags { cinstInstallMethod = v })
$ reqArg
"copy|symlink"
"default|copy|symlink"
readInstallMethodFlag
showInstallMethodFlag
, option [] ["installdir"]
Expand All @@ -103,6 +103,7 @@ showOverwritePolicyFlag NoFlag = []

readInstallMethodFlag :: ReadE (Flag InstallMethod)
readInstallMethodFlag = ReadE $ \case
"default" -> Right $ NoFlag
"copy" -> Right $ Flag InstallMethodCopy
"symlink" -> Right $ Flag InstallMethodSymlink
method -> Left $ "'" <> method <> "' isn't a valid install-method"
Expand Down

0 comments on commit b85029f

Please sign in to comment.