@@ -10,6 +10,7 @@ module Stack.Build.ConstructPlan
1010
1111import Control.Monad.RWS.Strict
1212 ( RWST , get , modify , modify' , pass , put , runRWST , tell )
13+ import Control.Monad.Trans.Maybe ( MaybeT (.. ) )
1314import qualified Data.List as L
1415import qualified Data.Map.Merge.Strict as Map
1516import qualified Data.Map.Strict as Map
@@ -1206,18 +1207,28 @@ psLocation PSRemote{} = Snap
12061207-- tool dependencies.
12071208checkAndWarnForUnknownTools :: Package -> M ()
12081209checkAndWarnForUnknownTools p = do
1209- -- Check whether the tool is on the PATH before warning about it.
1210- warnings <- fmap catMaybes $ forM (Set. toList $ packageUnknownTools p) $
1211- \ name@ (ExeName toolName) -> do
1212- let settings = minimalEnvSettings { esIncludeLocals = True }
1213- config <- view configL
1214- menv <- liftIO $ configProcessContextSettings config settings
1215- mfound <- runRIO menv $ findExecutable $ T. unpack toolName
1216- case mfound of
1217- Left _ -> pure $ Just $ ToolWarning name (packageName p)
1218- Right _ -> pure Nothing
1210+ let unknownTools = Set. toList $ packageUnknownTools p
1211+ -- Check whether the tool is on the PATH or a package executable before
1212+ -- warning about it.
1213+ warnings <-
1214+ fmap catMaybes $ forM unknownTools $ \ name@ (ExeName toolName) ->
1215+ runMaybeT $ notOnPath toolName *> notPackageExe toolName *> warn name
12191216 tell mempty { wWarnings = (map toolWarningText warnings ++ ) }
12201217 pure ()
1218+ where
1219+ -- From Cabal 2.0, build-tools can specify a pre-built executable that should
1220+ -- already be on the PATH.
1221+ notOnPath toolName = MaybeT $ do
1222+ let settings = minimalEnvSettings { esIncludeLocals = True }
1223+ config <- view configL
1224+ menv <- liftIO $ configProcessContextSettings config settings
1225+ eFound <- runRIO menv $ findExecutable $ T. unpack toolName
1226+ skipIf $ isRight eFound
1227+ -- From Cabal 1.12, build-tools can specify another executable in the same
1228+ -- package.
1229+ notPackageExe toolName = MaybeT $ skipIf $ toolName `Set.member` packageExes p
1230+ warn name = MaybeT . pure . Just $ ToolWarning name (packageName p)
1231+ skipIf p' = pure $ if p' then Nothing else Just ()
12211232
12221233-- | Warn about tools in the snapshot definition. States the tool name
12231234-- expected and the package name using it.
0 commit comments