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

Fix new-install symlink location #5188

Merged
merged 3 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 19 additions & 13 deletions cabal-install/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Distribution.Client.CmdErrorMessages

import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
import qualified Distribution.Client.Setup as Client
import Distribution.Client.Types
( PackageSpecifier(NamedPackage), UnresolvedSourcePackage )
import Distribution.Client.ProjectPlanning.Types
Expand Down Expand Up @@ -59,7 +58,8 @@ import Distribution.Types.UnqualComponentName
import Distribution.Verbosity
( Verbosity, normal )
import Distribution.Simple.Utils
( wrapText, die', withTempDirectory, createDirectoryIfMissingVerbose )
( wrapText, die', notice
, withTempDirectory, createDirectoryIfMissingVerbose )

import qualified Data.Map as Map
import System.Directory ( getTemporaryDirectory, makeAbsolute )
Expand Down Expand Up @@ -187,12 +187,16 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags)
(compilerId compiler)

-- If there are exes, symlink them
let defaultSymlinkBindir = error $
"TODO: how do I get the default ~/.cabal (or ~/.local) directory?"
++ " (use --symlink-bindir explicitly for now)" </> "bin"
symlinkBindir <- makeAbsolute $ fromFlagOrDefault defaultSymlinkBindir
(Client.installSymlinkBinDir installFlags)
traverse_ (symlinkBuiltPackage mkPkgBinDir symlinkBindir)
let symlinkBindirUnknown =
"symlink-bindir is not defined. Set it in your cabal config file "
++ "or use --symlink-bindir=<path>"
symlinkBindir <- fromFlagOrDefault (die' verbosity symlinkBindirUnknown)
$ fmap makeAbsolute
$ projectConfigSymlinkBinDir
$ projectConfigBuildOnly
$ projectConfig $ baseCtx
createDirectoryIfMissingVerbose verbosity False symlinkBindir
traverse_ (symlinkBuiltPackage verbosity mkPkgBinDir symlinkBindir)
$ Map.toList $ targetsMap buildCtx
runProjectPostBuildPhase verbosity baseCtx buildCtx buildOutcomes
where
Expand All @@ -210,22 +214,24 @@ disableTestsBenchsByDefault configFlags =
, configBenchmarks = Flag False <> configBenchmarks configFlags }

-- | Symlink every exe from a package from the store to a given location
symlinkBuiltPackage :: (UnitId -> FilePath) -- ^ A function to get an UnitId's
symlinkBuiltPackage :: Verbosity
-> (UnitId -> FilePath) -- ^ A function to get an UnitId's
-- store directory
-> FilePath -- ^ Where to put the symlink
-> ( UnitId
, [(ComponentTarget, [TargetSelector])] )
-> IO ()
symlinkBuiltPackage mkSourceBinDir destDir (pkg, components) =
traverse_ (symlinkBuiltExe (mkSourceBinDir pkg) destDir) exes
symlinkBuiltPackage verbosity mkSourceBinDir destDir (pkg, components) =
traverse_ (symlinkBuiltExe verbosity (mkSourceBinDir pkg) destDir) exes
where
exes = catMaybes $ (exeMaybe . fst) <$> components
exeMaybe (ComponentTarget (CExeName exe) _) = Just exe
exeMaybe _ = Nothing

-- | Symlink a specific exe.
symlinkBuiltExe :: FilePath -> FilePath -> UnqualComponentName -> IO Bool
symlinkBuiltExe sourceDir destDir exe =
symlinkBuiltExe :: Verbosity -> FilePath -> FilePath -> UnqualComponentName -> IO Bool
symlinkBuiltExe verbosity sourceDir destDir exe = do
notice verbosity $ "Symlinking " ++ unUnqualComponentName exe
symlinkBinary
destDir
sourceDir
Expand Down
9 changes: 8 additions & 1 deletion cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ initialSavedConfig = do
logsDir <- defaultLogsDir
worldFile <- defaultWorldFile
extraPath <- defaultExtraPath
symlinkPath <- defaultSymlinkPath
return mempty {
savedGlobalFlags = mempty {
globalCacheDir = toFlag cacheDir,
Expand All @@ -475,7 +476,8 @@ initialSavedConfig = do
savedInstallFlags = mempty {
installSummaryFile = toNubList [toPathTemplate (logsDir </> "build.log")],
installBuildReports= toFlag AnonymousReports,
installNumJobs = toFlag Nothing
installNumJobs = toFlag Nothing,
installSymlinkBinDir = toFlag symlinkPath
}
}

Expand Down Expand Up @@ -510,6 +512,11 @@ defaultExtraPath = do
dir <- defaultCabalDir
return [dir </> "bin"]

defaultSymlinkPath :: IO FilePath
defaultSymlinkPath = do
dir <- defaultCabalDir
return (dir </> "bin")

defaultCompiler :: CompilerFlavor
defaultCompiler = fromMaybe GHC defaultCompilerFlavor

Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Completed the 'new-exec' command (#3638). Same as above.
* Added a preliminary 'new-install' command (#4558, nonlocal exes
part) which allows to quickly install executables from Hackage.
* Set symlink-bindir (used by new-install) to .cabal/bin by default on
.cabal/config initialization.
* 'cabal update' now supports '--index-state' which can be used to
roll back the index to an earlier state.
* '--allow-{newer,older}' syntax has been enhanced. Dependency
Expand Down