Commit c204ca97 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Optimise rules by removing a loop over all possible ways.

parent be568c02
......@@ -7,10 +7,14 @@ import Builder
import Expression
import qualified Target
import Oracles.DependencyList
import Settings.Ways
import Settings.TargetDirectory
import Rules.Actions
import Rules.Resources
import Data.Maybe
matchBuildResult :: FilePath -> String -> FilePath -> Bool
matchBuildResult buildPath extension file =
(buildPath <//> "*" ++ extension) ?== file && (isJust . detectWay $ file)
compilePackage :: Resources -> StagePackageTarget -> Rules ()
compilePackage _ target = do
......@@ -21,20 +25,20 @@ compilePackage _ target = do
cDepsFile = buildPath -/- "c.deps"
hDepsFile = buildPath -/- "haskell.deps"
forM_ knownWays $ \way -> do
(buildPath <//> "*." ++ hisuf way) %> \hi -> do
let obj = hi -<.> osuf way
need [obj]
matchBuildResult buildPath "hi" ?> \hi -> do
let way = fromJust . detectWay $ hi -- fromJust is safe
need [hi -<.> osuf way]
(buildPath <//> "*." ++ osuf way) %> \obj -> do
let vanillaObjName = takeFileName obj -<.> "o"
cDeps <- dependencyList cDepsFile vanillaObjName
hDeps <- dependencyList hDepsFile obj
let hSrcDeps = filter ("//*hs" ?==) hDeps
matchBuildResult buildPath "o" ?> \obj -> do
let way = fromJust . detectWay $ obj -- fromJust is safe
vanillaObj = takeFileName obj -<.> "o"
cDeps <- dependencyList cDepsFile vanillaObj
hDeps <- dependencyList hDepsFile obj
let hSrcDeps = filter ("//*hs" ?==) hDeps
when (null cDeps && null hDeps) $
putError_ $ "Cannot determine sources for '" ++ obj ++ "'."
when (null cDeps && null hDeps) $
putError $ "Cannot determine sources for '" ++ obj ++ "'."
if null cDeps
then build $ fullTargetWithWay target hSrcDeps (Ghc stage) way [obj]
else build $ fullTarget target cDeps (Gcc stage) [obj]
if null cDeps
then build $ fullTargetWithWay target hSrcDeps (Ghc stage) way [obj]
else build $ fullTarget target cDeps (Gcc stage) [obj]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment