Skip to content

Commit

Permalink
Merge pull request #3598 from commercialhaskell/3534-run-autoreconf
Browse files Browse the repository at this point in the history
Automatically run autoreconf -i when needed #3534
  • Loading branch information
mgsloan authored Nov 23, 2017
2 parents a04aca3 + cf3e6f2 commit c1fd7d2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
7 changes: 7 additions & 0 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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 ()
Expand Down
16 changes: 16 additions & 0 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Stack/SDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ getSDistFileList lp =
, taskAllInOne = True
, taskCachePkgSrc = CacheSrcLocal (toFilePath (lpDir lp))
, taskAnyMissing = True
, taskBuildTypeConfig = False
}

normalizeTarballPaths :: HasRunner env => [FilePath] -> RIO env [FilePath]
Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c1fd7d2

Please sign in to comment.