Commit 1047fac4 authored by Andreas Klebinger's avatar Andreas Klebinger

Done removing MAIN special cases, start on EXCLUDED_SRCS

parent 98aeb07c
......@@ -158,7 +158,7 @@ main = do
{ shakeThreads = threads
, shakeFiles = output ++ "/"
, shakeReport = [output ++ "/shake_report.html"]
, shakeStaunch = True
, shakeStaunch = False
, shakeVerbosity = Development.Shake.Loud
}
......@@ -171,8 +171,7 @@ main = do
-- we care about:
--
-- * config.txt - a cleaned up version of the configuration out of Makefile,
-- created by convertConfig. Also contains "MAIN" which points at the name
-- of the Main module.
-- created by convertConfig.
--
-- * Main.exe - the actual binary, produced by ghc linking everything.
--
......@@ -187,6 +186,10 @@ main = do
buildRules :: Nofib -> Rules ()
buildRules nofib@Build{..} = do
linkerResource <- newResource "ghc linker" 1
-- _make/foo/bar -> bar
let asSrcPath :: String -> String
asSrcPath = drop (length output + 1)
let resultDir :: TestName -> FilePath
resultDir (TestName t) = output </> t
......@@ -265,16 +268,20 @@ buildRules nofib@Build{..} = do
liftIO $ writeFile out ""
-- Benchmark rules
"//config.txt" %> \out -> do
"_make//config.txt" %> \out -> do
let test = unoutput out
let dir = testDir test
src <- readFileLines $ dir </> "Makefile"
let poss = ["Main.hs","Main.lhs","Era.hs","SumEuler.hs",takeFileName dir <.> "hs",takeFileName dir <.> "lhs"]
bs <- filterM (doesFileExist . (dir </>)) poss
let mainMod = case bs of
[] -> error $ "Could not find Main file for " ++ dir
x:_ -> "MAIN = " ++ x
writeFileLines out $ mainMod : convertConfig src
let src_dir = testDir test
printM $ "config:out:" ++ out
printM $ "config:test:" ++ show test
printM $ "config:src_dir:" ++ src_dir
src <- readFileLines $ src_dir </> "Makefile"
-- let poss = ["Main.hs","Main.lhs","Era.hs","SumEuler.hs",takeFileName dir <.> "hs",takeFileName dir <.> "lhs"]
-- bs <- filterM (doesFileExist . (dir </>)) poss
-- let mainMod = case bs of
-- [] -> error $ "Could not find Main file for " ++ dir
-- x:_ -> "MAIN = " ++ x
-- writeFileLines out $ mainMod : convertConfig src
writeFileLines out $ convertConfig src
-- Main.exe : Link object files
["//Main" <.> exe, "//Main.link.tsv"] &%> \[out, resultsTsv] -> do
......@@ -297,9 +304,13 @@ buildRules nofib@Build{..} = do
if null config_srcs
then do
deps <- readFile' $ replaceFileName out ".depends"
return $ nub
[ output </> x -- Foo.o => _make/test/bench/Foo.o
| x <- words deps, takeExtension x == ".o"]
let hs_objects = [ x | x <- words deps, takeExtension x == ".o"]
-- Not recursive, the make system ignores files in subfolders.
c_srcs <- getDirectoryFiles "" [src_dir ++ "/*.c"]
need c_srcs
printM $ "c_srcs" ++ show c_srcs
let c_objects = map (\c_file -> replaceExtension (output </> c_file) "o") c_srcs
return $ nub $ hs_objects ++ c_objects
else do
map (obj_dir </>) <$> mapM oFromSrc config_srcs
......@@ -362,40 +373,49 @@ buildRules nofib@Build{..} = do
-- Needed for build dependencies/src files
need $ [obj_dir </> ".depends"]
-- But we only care about lines starting with the current .o file
deps <- filter (\x -> head (words x) `equalFilePath` (src_dir </> o_name)) <$>
deps <- filter (\x -> head (words x) `equalFilePath` o) <$>
readFileLines (obj_dir </> ".depends")
printM $ "deps:"
printM $ deps
-- Figure out source location
-- For Main.o it's recording in .config
-- For haskell sources in .depends
-- Otherwise it should be foo.c for any foo.o
let src = fromMaybe (getCSrc o_name src_dir)
(getMainSrc o_name src_dir config <|> getHaskellSrcFromDeps (src_dir </> o_name) deps)
-- Haskell sources are recorded in .depends so look there first.
-- It will be the first line mentioning the .o file.
-- Otherwise we assume it's a C file.
let src
| (x:_) <- deps
, (_ : ":" : rhs : _) <- words x
= rhs
| otherwise
= replaceExtension (asSrcPath o) "c"
-- We don't expect the source to change, but it makes debugging
-- easier to fail here. If some started depending on a .cmm or cpp
-- file in the future for example.
need [src]
printM $ "src1:" ++ src
-- src <- do b <- doesFileExist $ src_dir </> o_name <.> "hs"
-- return $ src_dir </> o_name <.> (if b then "hs" else "lhs")
printM $ "mod_name:" ++ o_name
printM $ "src:" ++ src
-- Figure out build dependencies
let mkNeed rhs =
if takeExtension rhs `elem` [".hs",".lhs"]
then replaceExtension rhs ".o"
else output </> rhs
let needs = [ mkNeed r
| lhs:":":rhss <- map words $ deps
, -- equalFilePath is required so that foo/bar and foo\bar match.
-- This can happen on windows.
equalFilePath (src_dir </> o_name) lhs
, r <- rhss
-- For a dependency of Main.o : Main.hs there is nothing to do
, not (equalFilePath r src)
]
-- let mkNeed rhs =
-- if takeExtension rhs `elem` [".hs",".lhs"]
-- then replaceExtension rhs ".o"
-- else output </> rhs
-- let needs = [ mkNeed r
-- | lhs:":":rhss <- map words $ deps
-- , -- equalFilePath is required so that foo/bar and foo\bar match.
-- -- This can happen on windows.
-- equalFilePath (obj_dir </> o_name) lhs
-- , r <- rhss
-- -- For a dependency of Main.o : Main.hs there is nothing to do
-- , not (equalFilePath r src)
-- ]
let needs = [ drop 2 . dropWhile (/= ':') $ x | x <- deps]
liftIO $ do
print "needs"
mapM_ print needs
......@@ -422,22 +442,24 @@ buildRules nofib@Build{..} = do
"//.depends" %> \out -> do
let test = unoutput out
src_dir = testDir test -- eg. spectral/simple
obj_dir = output </> src_dir -- eg. _make/foo/spectral/simple
config <- readConfig' $ takeDirectory out </> "config.txt"
compileArgs <- getTestCompileArgs nofib test
deps_args <- buildDepsArgs test
hs_files <- map (src_dir </>) <$> getDirectoryFiles src_dir ["//*.hs", "//*.lhs"]
hs_files <- map (src_dir </>) <$> getDirectoryFiles src_dir ["/*.hs", "/*.lhs"]
cmd_ compiler $
[ "-w"
, "-M",unwords hs_files--src_dir </> config "MAIN"
, "-i" ++ src_dir
, "-dep-makefile=" ++ out
, "-dep-suffix", ""
] ++ compileArgs ++
-- It's unlikely but possible that flags could affect dependencies.
compiler_args ++
deps_args
, "-odir="++obj_dir,"-hidir="++obj_dir -- Required for Main module .o handling.
-- See ghc issue #18575
] ++ ["-M"] ++ hs_files--src_dir </> config "MAIN"
++ compileArgs ++
-- It's unlikely but possible that flags could affect dependencies.
compiler_args ++
deps_args
src <- liftIO $ readFile out
need [x | x <- words src, takeExtension x `elem` [".hs",".lhs",".h"]]
......@@ -618,7 +640,8 @@ convertConfig xs =
, let (a,b) = separate x
, a `elem` keep
]
keep = words "PROG_ARGS SRCS SRC_HC_OPTS SLOW_OPTS NORM_OPTS FAST_OPTS STDIN_FILE SRC_DEPS SUBDIRS"
keep = words $ "PROG_ARGS SRCS EXCLUDED_SRCS SRC_HC_OPTS SLOW_OPTS" ++
"NORM_OPTS FAST_OPTS STDIN_FILE SRC_DEPS SUBDIRS"
separate x = (name,rest)
where (name,x2) = span (\c -> isAlpha c || c == '_') x
......
......@@ -3,6 +3,7 @@ module Utils where
import Control.Monad
import System.FilePath as IO
import Development.Shake
import Data.Maybe
import Prelude hiding (lines)
......@@ -24,20 +25,20 @@ dropPathPrefix prefix path =
-- | Try to find the source in the .depends file
--
-- E.g. gc/linear/Matrix.o => Just gc/linear/Matrix.lhs
-- We already filtered out any lines *not* specifying a dep
-- for the current file. So if there are deps the first line will
-- give the source file.
getHaskellSrcFromDeps :: String -> [String] -> Maybe String
getHaskellSrcFromDeps _ [] = Nothing
getHaskellSrcFromDeps o_file (x:xs)
-- Look for Foo.o : Foo.[l]hs
| (lhs : ":" : rhs : _) <- words x
, dropExtension lhs `equalFilePath` dropExtension rhs
= Just rhs
| otherwise = getHaskellSrcFromDeps o_file xs
-- There is always one Main.o file for which the source file is recorded
-- in the .config file
getMainSrc :: String -> String -> (String -> String) -> Maybe String
getMainSrc "Main.o" dir config = Just $! (dir </> (config "MAIN"))
getMainSrc _ _ _ = Nothing
getHaskellSrcFromDeps _ (x:_)
| (_ : ":" : rhs : _) <- words x
= Just rhs
getHaskellSrcFromDeps _ _ = Nothing
-- -- There is always one Main.o file for which the source file is recorded
-- -- in the .config file
-- getMainSrc :: String -> String -> (String -> String) -> Maybe String
-- getMainSrc "Main.o" dir config = Just $! (dir </> (config "MAIN"))
-- getMainSrc _ _ _ = Nothing
-- | Generic case, for foo.o look for foo.c
--
......
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