Commit a8b963cc authored by ijones's avatar ijones
Browse files

clean target. needs some work.

-- |FIX: Doesn't remove directories created.  Perhaps it should just
-- delete the .hi and .o files?  Perhaps it should just delete the
-- entire build location recursively?
parent dd9d7703
......@@ -50,7 +50,7 @@ module Distribution.Package (
parsePackageDesc,
#ifdef DEBUG
hunitTests,
main
test
#endif
) where
......@@ -403,5 +403,5 @@ assertRight mes expected actual
isError (Left _) = True
isError _ = False
main = runTestTT (TestList hunitTests)
test = runTestTT (TestList hunitTests)
#endif
......@@ -80,6 +80,7 @@ type CommandLineOpts = (Action,
data Action = ConfigCmd ConfigFlags -- config
| BuildCmd -- build
| CleanCmd -- clean
| InstallCmd (Maybe FilePath) Bool -- install (install-prefix) (--user flag)
| SDistCmd -- sdist
| RegisterCmd Bool -- register (--user flag)
......@@ -119,6 +120,7 @@ parseArgs args
"configure" -> parseConfigure flags unkFlags
"install" -> parseInstall flags unkFlags
"build" -> noFlags str BuildCmd flags unkFlags
"clean" -> noFlags str CleanCmd flags unkFlags
"sdist" -> noFlags str SDistCmd flags unkFlags
"register" -> parseRegister flags unkFlags
"unregister" -> noFlags str UnregisterCmd flags unkFlags
......
......@@ -58,6 +58,7 @@ import Distribution.Package --must not specify imports, since we're exporting mo
import Distribution.Setup(parseArgs, Action(..), optionHelpString)
import Distribution.Simple.Build ( build )
import Distribution.Simple.Clean ( clean )
import Distribution.Simple.SrcDist ( sdist )
import Distribution.Simple.Register ( register, unregister )
......@@ -115,6 +116,10 @@ defaultMainNoRead pkg_descr
localbuildinfo <- getPersistBuildConfig
build buildPref pkg_descr localbuildinfo
Right (CleanCmd, extra_flags) -> do
no_extra_flags extra_flags
clean buildPref pkg_descr
Right (InstallCmd install_prefixM userInst, extra_flags) -> do
no_extra_flags extra_flags
localbuildinfo <- getPersistBuildConfig
......
{-# OPTIONS -cpp -DDEBUG #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Clean
-- Copyright : Isaac Jones 2003-2004
--
-- Maintainer : Isaac Jones <ijones@syntaxpolice.org>
-- Stability : alpha
-- Portability :
--
{- Copyright (c) 2003-2004, Isaac Jones
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Isaac Jones nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Clean (
clean
#ifdef DEBUG
,hunitTests
#endif
) where
import Distribution.Simple.Utils (moduleToFilePath, mkLibName)
import Distribution.Package(PackageDescription(..), showPackageId)
import Control.Monad(when)
import Data.Maybe(catMaybes)
import Data.List(intersperse)
import System.Directory(removeFile)
#ifdef DEBUG
import HUnit (Test)
#endif
-- |FIX: Doesn't remove directories created. Perhaps it should just
-- delete the .hi and .o files? Perhaps it should just delete the
-- entire build location recursively?
clean :: FilePath -- ^Build location
-> PackageDescription
-> IO ()
clean buildLoc pkg_descr
= do let modules = (allModules pkg_descr) ++ (mainModules pkg_descr)
removeMeo <- sequence [moduleToFilePath buildLoc m ["o"] | m <- modules]
removeMehi <- sequence [moduleToFilePath buildLoc m ["hi"]| m <- modules]
removeMehs <- sequence [moduleToFilePath buildLoc m ["hs"]| m <- modules]
let lib = mkLibName buildLoc (showPackageId (package pkg_descr))
let removeMe = lib:(catMaybes (removeMeo ++ removeMehi ++ removeMehs))
when (not $ null removeMe)
(putStrLn $ "Removing: " ++ (concat (intersperse ", " (map show removeMe))))
sequence $ map removeFile removeMe
return ()
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: [Test]
hunitTests = []
#endif
......@@ -55,6 +55,7 @@ module Distribution.Simple.Utils (
maybeExit,
rawSystemPathExit,
moveSources,
moduleToFilePath,
hunitTests,
createIfNotExists,
mkLibName,
......
* misc
** clean target
** license parser parses either known strings, or a filename.
** Possibly create a (native?) zlib library?
** port code to windows
......
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