diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs index 5f009aa286e..b8f179ec94e 100644 --- a/cabal-install/src/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs @@ -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 <- @@ -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' / @@ -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 @@ -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) $ @@ -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