Skip to content

Commit

Permalink
Add symlink and install exe haddocks
Browse files Browse the repository at this point in the history
As requested in review
  • Loading branch information
philderbeast committed Dec 12, 2023
1 parent 4606c35 commit eb46bdc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 12 additions & 3 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ data InstallCfg = InstallCfg
, installClientFlags :: ClientInstallFlags
}

-- | A record of install method, install directory and file path functions
-- needed by actions that either check if an install is possible or actually
-- perform an installation. This is for installation of executables only.
data InstallExe = InstallExe
{ installMethod :: InstallMethod
, installDir :: FilePath
Expand Down Expand Up @@ -638,10 +641,11 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
cliConfig = addLocalConfigToTargets baseCliConfig targetStrings
globalConfigFlag = projectConfigConfigFile (projectConfigShared cliConfig)

-- Do the install action for each executable in the install configuration.
traverseInstall :: InstallAction -> InstallCfg -> IO ()
traverseInstall action cfg@InstallCfg{verbosity = v, buildCtx, installClientFlags} = do
let overwritePolicy = fromFlagOrDefault NeverOverwrite $ cinstOverwritePolicy installClientFlags
actionOnExe <- action v overwritePolicy <$> installExesPrep cfg
actionOnExe <- action v overwritePolicy <$> prepareExeInstall cfg
traverse_ actionOnExe . Map.toList $ targetsMap buildCtx

-- | Treat all direct targets of install command as local packages: #8637
Expand Down Expand Up @@ -827,8 +831,11 @@ constructProjectBuildContext verbosity baseCtx targetSelectors = do

return (prunedElaboratedPlan, targets)

installExesPrep :: InstallCfg -> IO InstallExe
installExesPrep
-- | From an install configuration, prepare the record needed by actions that
-- will either check if an install of a single executable is possible or
-- actually perform its installation.
prepareExeInstall :: InstallCfg -> IO InstallExe
prepareExeInstall
InstallCfg{verbosity, baseCtx, buildCtx, platform, compiler, installConfigFlags, installClientFlags} = do
installPath <- defaultInstallPath
let storeDirLayout = cabalStoreDirLayout $ cabalDirLayout baseCtx
Expand Down Expand Up @@ -997,6 +1004,8 @@ disableTestsBenchsByDefault configFlags =
, configBenchmarks = Flag False <> configBenchmarks configFlags
}

-- | Prepares a record containing the information needed to either symlink or
-- copy an executable.
symlink :: OverwritePolicy -> InstallExe -> UnitId -> UnqualComponentName -> Symlink
symlink
overwritePolicy
Expand Down
10 changes: 9 additions & 1 deletion cabal-install/src/Distribution/Client/InstallSymlink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ symlinkBinaries
cinfo = compilerInfo comp
(CompilerId compilerFlavor _) = compilerInfoId cinfo

-- | A record needed to either check if a symlink is possible or to create a
-- symlink. Also used if copying instead of symlinking.
data Symlink = Symlink
{ overwritePolicy :: OverwritePolicy
-- ^ Whether to force overwrite an existing file.
Expand All @@ -265,7 +267,12 @@ data Symlink = Symlink
-- ^ The name of the executable to in the private bin dir, eg @foo-1.0@.
}

-- | How to handle symlinking a binary.
-- | After checking if a target is writeable given the overwrite policy,
-- dispatch to an appropriate action;
-- * @onMissing@ if the target doesn't exist
-- * @onOverwrite@ if the target exists and we are allowed to overwrite it
-- * @onNever@ if the target exists and we are never allowed to overwrite it
-- * @onPrompt@ if the target exists and we are allowed to overwrite after prompting
onSymlinkBinary
:: IO a
-- ^ Missing action
Expand All @@ -274,6 +281,7 @@ onSymlinkBinary
-> IO a
-- ^ Never action
-> IO a
-- ^ Prompt action
-> Symlink
-> IO a
onSymlinkBinary
Expand Down

0 comments on commit eb46bdc

Please sign in to comment.