From cf3e6f2e96df84dc84fcb3697acaaf0135ce5ba3 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 22 Nov 2017 19:26:24 +0200 Subject: [PATCH] Automatically run autoreconf -i when needed #3534 --- ChangeLog.md | 3 +++ src/Stack/Build/ConstructPlan.hs | 7 +++++++ src/Stack/Build/Execute.hs | 16 ++++++++++++++++ src/Stack/SDist.hs | 1 + src/Stack/Types/Build.hs | 3 +++ 5 files changed, 30 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 0394a4551e..0b11d33f1b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -124,6 +124,9 @@ Other enhancements: * Detect when user changed .cabal file instead of package.yaml. This was implemented upstream in hpack. See [#3383](https://github.com/commercialhaskell/stack/issues/3383). +* Automatically run `autoreconf -i` as necessary when a `configure` + script is missing. See + [#3534](https://github.com/commercialhaskell/stack/issues/3534) Bug fixes: diff --git a/src/Stack/Build/ConstructPlan.hs b/src/Stack/Build/ConstructPlan.hs index c6e7587570..fd8ed1c931 100644 --- a/src/Stack/Build/ConstructPlan.hs +++ b/src/Stack/Build/ConstructPlan.hs @@ -32,6 +32,7 @@ import Data.Text.Encoding (decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import qualified Distribution.Text as Cabal import qualified Distribution.Version as Cabal +import Distribution.Types.BuildType (BuildType (Configure)) import Generics.Deriving.Monoid (memptydefault, mappenddefault) import Lens.Micro (lens) import Stack.Build.Cache @@ -355,6 +356,7 @@ addFinal lp package isAllInOne = do , taskAllInOne = isAllInOne , taskCachePkgSrc = CacheSrcLocal (toFilePath (lpDir lp)) , taskAnyMissing = not $ Set.null missing + , taskBuildTypeConfig = packageBuildTypeConfig package } tell mempty { wFinals = Map.singleton (packageName package) res } @@ -571,8 +573,13 @@ installPackageGivenDeps isAllInOne ps package minstalled (missing, present, minL , taskAllInOne = isAllInOne , taskCachePkgSrc = toCachePkgSrc ps , taskAnyMissing = not $ Set.null missing + , taskBuildTypeConfig = packageBuildTypeConfig package } +-- | Is the build type of the package Configure +packageBuildTypeConfig :: Package -> Bool +packageBuildTypeConfig pkg = packageBuildType pkg == Just Configure + -- Update response in the lib map. If it is an error, and there's -- already an error about cyclic dependencies, prefer the cyclic error. updateLibMap :: PackageName -> Either ConstructPlanException AddDepRes -> M () diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 7f6e5ad90d..e25008fccb 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -813,6 +813,9 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = return $ fmap ignoreComponents mOldConfigCache /= Just (ignoreComponents newConfigCache) || mOldCabalMod /= Just newCabalMod let ConfigureOpts dirs nodirs = configCacheOpts newConfigCache + + when (taskBuildTypeConfig task) ensureConfigureScript + when needConfig $ withMVar eeConfigureLock $ \_ -> do deleteCaches pkgDir announce @@ -837,6 +840,19 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = writeCabalMod pkgDir newCabalMod return needConfig + where + -- When build-type is Configure, we need to have a configure + -- script in the local directory. If it doesn't exist, build it + -- with autoreconf -i. See: + -- https://github.com/commercialhaskell/stack/issues/3534 + ensureConfigureScript = do + let fp = pkgDir $(mkRelFile "configure") + exists <- doesFileExist fp + unless exists $ do + logInfo $ "Trying to generate configure with autoreconf in " <> T.pack (toFilePath pkgDir) + menv <- getMinimalEnvOverride + readProcessNull (Just pkgDir) menv "autoreconf" ["-i"] `catchAny` \ex -> + logWarn $ "Unable to run autoreconf: " <> T.pack (show ex) announceTask :: MonadLogger m => Task -> Text -> m () announceTask task x = logInfo $ T.concat diff --git a/src/Stack/SDist.hs b/src/Stack/SDist.hs index 301d29667b..8af1264657 100644 --- a/src/Stack/SDist.hs +++ b/src/Stack/SDist.hs @@ -349,6 +349,7 @@ getSDistFileList lp = , taskAllInOne = True , taskCachePkgSrc = CacheSrcLocal (toFilePath (lpDir lp)) , taskAnyMissing = True + , taskBuildTypeConfig = False } normalizeTarballPaths :: HasRunner env => [FilePath] -> RIO env [FilePath] diff --git a/src/Stack/Types/Build.hs b/src/Stack/Types/Build.hs index f6254f06c7..bd69475683 100644 --- a/src/Stack/Types/Build.hs +++ b/src/Stack/Types/Build.hs @@ -442,6 +442,9 @@ data Task = Task -- unnecessary, when in fact we _do_ need to reconfigure. The -- details here suck. We really need proper hashes for package -- identifiers. + , taskBuildTypeConfig :: !Bool + -- ^ Is the build type of this package Configure. Check out + -- ensureConfigureScript in Stack.Build.Execute for the motivation } deriving Show