Commit b61cb051 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Find original sources for main-is when creating sdist

Also add a package sanity check that main-is must specify a .hs or .lhs file.
So the bahaviour is now that main-is specifies the main source file, even if
that is generated by a pre-processor. This isn't really a change in behaviour
since previously if you specified main-is: main.hsc then it would try to
pass the .hsc file to ghc dirctly which would not work. For ticket #14 things
were fixed to that it would look for main.hsc if you used main-is: main.hs an
that file did not exist directy. This completes the other half, of actually
being able to make a src distribution. So this should fix bug #217.
Note that this still needs some work, we do not run platform-independent
preprocessors and put the result into the tarball for main-is files.
Generally, main-is has been the second class citizen compared to normal
modules. We should try and refactor so both use the same code paths.
parent 58c9693a
......@@ -128,7 +128,7 @@ import Distribution.Simple.Utils(currentDir, die, dieWithLocation, warn, notice)
import Language.Haskell.Extension(Extension(..))
import Distribution.Compat.ReadP as ReadP hiding (get)
import System.FilePath((<.>))
import System.FilePath((<.>), takeExtension)
import Data.Monoid
......@@ -1324,11 +1324,15 @@ sanityCheckLib ml = do
sanityCheckExe :: Executable -> Maybe String
sanityCheckExe exe
= if null (modulePath exe)
then Just ("No 'Main-Is' field found for executable " ++ exeName exe
| null (modulePath exe)
= Just ("No 'Main-Is' field found for executable " ++ exeName exe
++ "Fields of the executable section:\n"
++ (render $ nest 4 $ ppFields exe executableFieldDescrs))
else Nothing
| ext `notElem` [".hs", ".lhs"]
= Just ("The 'Main-Is' field must specify a '.hs' or '.lhs' file\n"
++" (even if it is generated by a preprocessor).")
| otherwise = Nothing
where ext = takeExtension (modulePath exe)
checkSanity :: Bool -> String -> Maybe String
checkSanity = toMaybe
......@@ -141,7 +141,11 @@ prepareTree pkg_descr verbosity mb_lbi snapshot tmpDir pps date = do
-- move the executables into place
withExe pkg_descr $ \ (Executable _ mainPath exeBi) -> do
prepareDir verbosity targetDir pps [] exeBi
srcMainFile <- findFile (hsSourceDirs exeBi) mainPath
srcMainFile <- do
ppFile <- findFileWithExtension (ppSuffixes pps) (hsSourceDirs exeBi) (dropExtension mainPath)
case ppFile of
Nothing -> findFile (hsSourceDirs exeBi) mainPath
Just pp -> return pp
copyFileTo verbosity targetDir srcMainFile
flip mapM_ (dataFiles pkg_descr) $ \ file -> do
let dir = takeDirectory file
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