Skip to content

Commit

Permalink
Don't recompile C files unless needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexi committed Aug 25, 2015
1 parent b5199c2 commit eb46872
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
31 changes: 24 additions & 7 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import qualified Distribution.Simple.Program.Ld as Ld
import qualified Distribution.Simple.Program.Strip as Strip
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup
( toFlag, fromFlag, configCoverage, configDistPref )
( toFlag, fromFlag, fromFlagOrDefault, configCoverage, configDistPref )
import qualified Distribution.Simple.Setup as Cabal
( Flag(..) )
import Distribution.Simple.Compiler
Expand Down Expand Up @@ -542,10 +542,12 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
}
odir = fromFlag (ghcOptObjDir vanillaCcOpts)
createDirectoryIfMissingVerbose verbosity True odir
runGhcProg vanillaCcOpts
unless forRepl $
whenSharedLib forceSharedLib (runGhcProg sharedCcOpts)
unless forRepl $ whenProfLib (runGhcProg profCcOpts)
needsRecomp <- checkNeedsRecompilation filename vanillaCcOpts
when needsRecomp $ do
runGhcProg vanillaCcOpts
unless forRepl $
whenSharedLib forceSharedLib (runGhcProg sharedCcOpts)
unless forRepl $ whenProfLib (runGhcProg profCcOpts)
| filename <- cSources libBi]

-- TODO: problem here is we need the .c files built first, so we can load them
Expand Down Expand Up @@ -834,9 +836,11 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
else GhcStaticOnly),
ghcOptProfilingMode = toFlag (withProfExe lbi)
}
odir = fromFlag (ghcOptObjDir opts)
odir = fromFlag (ghcOptObjDir opts)
createDirectoryIfMissingVerbose verbosity True odir
runGhcProg opts
needsRecomp <- checkNeedsRecompilation filename opts
when needsRecomp $
runGhcProg opts
| filename <- cSrcs ]

-- TODO: problem here is we need the .c files built first, so we can load them
Expand All @@ -849,6 +853,19 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
info verbosity "Linking..."
runGhcProg linkOpts { ghcOptOutputFile = toFlag (targetDir </> exeNameReal) }

-- | Returns True if the modification date of the given source file is newer than
-- the object file we last compiled for it, or if no object file exists yet.
checkNeedsRecompilation :: FilePath -> GhcOptions -> IO Bool
checkNeedsRecompilation filename opts = filename `moreRecentFile` oname
where oname = getObjectFileName filename opts

-- | Finds the object file name of the given source file
getObjectFileName :: FilePath -> GhcOptions -> FilePath
getObjectFileName filename opts = oname
where odir = fromFlag (ghcOptObjDir opts)
oext = fromFlagOrDefault "o" (ghcOptObjSuffix opts)
oname = odir </> replaceExtension filename oext

-- | Calculate the RPATHs for the component we are building.
--
-- Calculates relative RPATHs when 'relocatable' is set.
Expand Down
4 changes: 3 additions & 1 deletion Cabal/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-*-change-log-*-
1.22.5.0
* Don't recompile C sources unless needed (#2601). (Luke Iannini)

1.22.4.0 Ryan Thomas <[email protected]> June 2015
* Add libname install-dirs variable, use it by default. Fixes #2437. (Edward Z. Yang)
* Reduce temporary directory name length, fixes #2502. (Edward Z. Yang)
Expand Down

0 comments on commit eb46872

Please sign in to comment.