Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Feb 10, 2024
1 parent 5b2a125 commit 9b410f5
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions cabal-install/src/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,12 @@ getExternalSetupMethod verbosity options pkgId bt = do
++ show (useDependenciesExclusive options)
createDirectoryIfMissingVerbose verbosity True setupDir

(cabalLibVersion, mCabalLibInstalledPkgId, options') <- cabalLibVersionToUse verbosity options pkgId bt
let SetupPaths {setupHs} = getSetupPaths options
(cabalLibVersion, mCabalLibInstalledPkgId, options') <-
cabalLibVersionToUse verbosity options pkgId bt
(updateSetupScript verbosity (workingDir options) setupHs bt)
(writeSetupVersionFile options)

debug verbosity $ "Using Cabal library version " ++ prettyShow cabalLibVersion

path <-
Expand Down Expand Up @@ -707,33 +712,45 @@ cabalLibVersionToUse
-> SetupScriptOptions
-> PackageId
-> BuildType
-> (Version -> IO ())
-> (Version -> IO ())
-> IO (Version, Maybe ComponentId, SetupScriptOptions)
cabalLibVersionToUse verbosity options pkgId bt =
cabalLibVersionToUse verbosity options pkgId bt updateSetupScript' writeSetupVersionFile' =
case find (isCabalPkgId . snd) (useDependencies options) of
Just (unitId, pkgId') -> do
let version = pkgVersion pkgId'
updateSetupScript verbosity (workingDir options) setupHs version bt
writeSetupVersionFile options version
updateSetupScript' version
writeSetupVersionFile' version
return (version, Just unitId, options)
Nothing ->
case useCabalSpecVersion options of
Just version -> do
updateSetupScript verbosity (workingDir options) setupHs version bt
writeSetupVersionFile options version
updateSetupScript' version
writeSetupVersionFile' version
return (version, Nothing, options)
Nothing -> do
savedVer <- readSetupVersionFile options

let installedVersion = do
let SetupScriptOptions{useCompiler, usePlatform, useProgramDb, usePackageIndex, usePackageDB} = options
(_comp, _platform, _progdb, index) <- configureCompiler verbosity useCompiler usePlatform useProgramDb usePackageIndex usePackageDB
let options' = options{usePackageIndex = Just index}
(version', mipkgid) <- installedCabalVersion verbosity index (useCabalVersion options') pkgId bt
updateSetupScript' version'
writeSetupVersionFile' version'
return (version', mipkgid, options')

case savedVer of
Just version | version `withinRange` useCabalVersion options ->
do
updateSetupScript verbosity (workingDir options) setupHs version bt
-- Does the previously compiled setup executable
-- still exist and is it up-to date?
useExisting <- canUseExistingSetup version
if useExisting
then return (version, Nothing, options)
else installedVersion verbosity options pkgId bt
_ -> installedVersion verbosity options pkgId bt
Just version | version `withinRange` useCabalVersion options -> do
updateSetupScript' version
-- Does the previously compiled setup executable still exist and is it up-to date?
useExisting <- canUseExistingSetup version
if useExisting
then return (version, Nothing, options)
else installedVersion

_ -> installedVersion

where
SetupPaths {..} = getSetupPaths options
-- This check duplicates the checks in 'getCachedSetupExecutable' /
Expand Down Expand Up @@ -767,23 +784,6 @@ readSetupVersionFile options = do
where
SetupPaths {..} = getSetupPaths options

installedVersion
:: Verbosity
-> SetupScriptOptions
-> PackageId
-> BuildType
-> IO (Version, Maybe InstalledPackageId, SetupScriptOptions)
installedVersion verbosity options pkgId bt = do
let SetupScriptOptions{useCompiler, usePlatform, useProgramDb, usePackageIndex, usePackageDB} = options
(_comp, _platform, _progdb, index) <- configureCompiler verbosity useCompiler usePlatform useProgramDb usePackageIndex usePackageDB
let options' = options{usePackageIndex = Just index}
(version, mipkgid) <- installedCabalVersion verbosity index (useCabalVersion options') pkgId bt
updateSetupScript verbosity (workingDir options') setupHs version bt
writeSetupVersionFile options' version
return (version, mipkgid, options')
where
SetupPaths{..} = getSetupPaths options

installedCabalVersion
:: Verbosity
-> InstalledPackageIndex
Expand Down Expand Up @@ -840,10 +840,10 @@ updateSetupScript
-- ^ Working directory
-> FilePath
-- ^ Path to Setup.hs
-> Version
-> BuildType
-> Version
-> IO ()
updateSetupScript verbosity workdir setupHs _cabalLibVersion Custom = do
updateSetupScript verbosity workdir setupHs Custom _cabalLibVersion = do
useHs <- doesFileExist customSetupHs
useLhs <- doesFileExist customSetupLhs
unless (useHs || useLhs) $
Expand All @@ -857,7 +857,7 @@ updateSetupScript verbosity workdir setupHs _cabalLibVersion Custom = do
where
customSetupHs = workdir </> "Setup.hs"
customSetupLhs = workdir </> "Setup.lhs"
updateSetupScript verbosity _workdir setupHs cabalLibVersion bt =
updateSetupScript verbosity _workdir setupHs bt cabalLibVersion =
rewriteFileLBS verbosity setupHs (buildTypeScript cabalLibVersion bt)

buildTypeScript :: Version -> BuildType -> BS.ByteString
Expand Down

0 comments on commit 9b410f5

Please sign in to comment.