Commit 6f062249 authored by ijones's avatar ijones
Browse files

cleanup and reorg

* Added Simple{Register,Configure}
* Moved Simple.Default to Simple.hs
* Moved some stuff out of Misc (into Register and configure)
* Invented new Compiler Extensions
parent b4996688
......@@ -2,7 +2,7 @@
module Distribution.InstalledPackageInfo where
import Distribution.Misc(License(..), Dependency, Opt, LocalBuildInfo)
import Distribution.Misc(License(..), Dependency, Opt)
import Distribution.Package(PackageIdentifier(..), PackageConfig)
data InstalledPackageInfo
......@@ -32,6 +32,3 @@ emptyInstalledPackageInfo :: InstalledPackageInfo
emptyInstalledPackageInfo = InstalledPackageInfo (PackageIdentifier "" (error "no version"))
AllRightsReserved "" "" "" False [] [] [] [] [] []
[] [] [] [] [] [] []
getUseInfo :: LocalBuildInfo -> PackageConfig -> InstalledPackageInfo
getUseInfo _ _ = emptyInstalledPackageInfo -- FIX
......@@ -41,47 +41,11 @@ 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.Misc(License(..), Dependency,
Extension, Opt, LocalBuildInfo(..),
CompilerFlavor(..), Compiler(..),
writePersistBuildConfig, getPersistBuildConfig)
module Distribution.Misc(License(..), Dependency, Extension, Opt)
where
import Distribution.Version(VersionRange)
-- ------------------------------------------------------------
-- * Compiler
-- ------------------------------------------------------------
data CompilerFlavor = GHC | NHC | Hugs | HBC | Helium | OtherCompiler String
deriving (Show, Eq)
data Compiler = Compiler {flavor :: CompilerFlavor,
path :: FilePath,
packagingTool :: FilePath}
deriving (Show, Eq)
emptyCompiler :: Compiler
emptyCompiler = Compiler (OtherCompiler "") "" ""
-- ------------------------------------------------------------
-- * build config
-- ------------------------------------------------------------
-- |Data cached after configuration step.
data LocalBuildInfo = LocalBuildInfo {prefix :: String,
compiler :: Compiler}
deriving (Show, Eq)
emptyLocalBuildInfo :: LocalBuildInfo
emptyLocalBuildInfo = LocalBuildInfo "" emptyCompiler
getPersistBuildConfig :: IO LocalBuildInfo
getPersistBuildConfig = return emptyLocalBuildInfo -- FIX
writePersistBuildConfig :: LocalBuildInfo -> IO ()
writePersistBuildConfig _ = return () --FIX
-- ------------------------------------------------------------
-- * Misc
-- ------------------------------------------------------------
......
......@@ -51,9 +51,11 @@ import Distribution.Misc()
import Distribution.Package()
import qualified Distribution.Setup(hunitTests)
import Distribution.Simple.Default()
import Distribution.Simple()
import Distribution.Simple.Install()
import Distribution.Simple.Build()
import Distribution.Simple.Configure()
import Distribution.Simple.Register()
import HUnit(runTestTT, Test(..))
......
......@@ -47,7 +47,8 @@ module Distribution.Package(PackageIdentifier(..),
where
import Distribution.Version(Version)
import Distribution.Misc(License, Dependency, Extension, CompilerFlavor)
import Distribution.Misc(License, Dependency, Extension)
import Distribution.Setup(CompilerFlavor)
data PackageIdentifier
= PackageIdentifier {pkgName::String, pkgVersion::Version}
......
......@@ -44,31 +44,37 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Setup (parseArgs, Action(..), ConfigFlags,
CompilerFlavor(..), Compiler(..),
#ifdef DEBUG
hunitTests,
#endif
) where
-- Local
import Distribution.Misc(LocalBuildInfo, CompilerFlavor(..),
Compiler(..), LocalBuildInfo(..))
import Distribution.GetOpt
-- Misc:
#ifdef DEBUG
import HUnit (Test(..), (~:), (~=?))
import Control.Monad.Error
-- Locate the compiler based on the flavor
exeLoc :: CompilerFlavor -> IO FilePath
exeLoc _ = return "error, not yet implemented" -- FIX
#endif
pkgLoc :: CompilerFlavor -> IO FilePath
pkgLoc _ = return "error, not yet implemented" -- FIX
import Control.Monad.Error
-- ------------------------------------------------------------
-- * Command Line Types and Exports
-- ------------------------------------------------------------
data CompilerFlavor = GHC | NHC | Hugs | HBC | Helium | OtherCompiler String
deriving (Show, Eq)
data Compiler = Compiler {compilerFlavor:: CompilerFlavor,
compilerPath :: FilePath,
compilerPkgTool :: FilePath}
deriving (Show, Eq)
emptyCompiler :: Compiler
emptyCompiler = Compiler (OtherCompiler "") "" ""
type CommandLineOpts = (Action,
[String]) -- The un-parsed remainder
......@@ -92,10 +98,10 @@ type ConfigFlags = (Maybe CompilerFlavor,
-- |Parse the standard command-line arguments.
parseArgs :: [String] -> Either [String] CommandLineOpts
parseArgs args
= let (flags, commands, unkFlags, ers) = getOpt Permute options args
= let (flags, commands', unkFlags, ers) = getOpt Permute options args
in case ers of
_:_ -> Left ers
[] -> case commands of
[] -> case commands' of
[] -> Left ["No command detected"]
[h] -> parseCommands h flags unkFlags
_:_ -> Left ["More than one command detected"]
......@@ -127,7 +133,7 @@ parseArgs args
= Left $ ["command line syntax error for command: " ++ c]
isInstallPrefix :: Flag -> Bool
isInstallPrefix (InstPrefix m) = True
isInstallPrefix (InstPrefix _) = True
isInstallPrefix _ = False
-- Converts the abstract "flag" type to a more concrete type.
......@@ -145,7 +151,7 @@ getConfigFlags flags
getOneOpt [] = return Nothing
getOneOpt [one] = return (Just one)
getOneOpt many = fail "Multiple prefix options"
getOneOpt _ = fail "Multiple prefix options"
-- ------------------------------------------------------------
-- * Option Specifications
......@@ -192,23 +198,18 @@ commands = [("configure", "configure this package"),
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
hunitTests :: IO [Test]
hunitTests =
do m <- sequence [do loc <- exeLoc comp
pkg <- pkgLoc comp
return (name, comp, loc, pkg)
| (name, comp) <- [("ghc", GHC),
("nhc", NHC),
("hugs", Hugs)]]
let (flags, commands, unkFlags, ers)
do let m = [("ghc", GHC), ("nhc", NHC), ("hugs", Hugs)]
let (flags, commands', unkFlags, ers)
= getOpt Permute options ["configure", "foobar", "--prefix=/foo", "--ghc", "--nhc", "--hugs", "--with-compiler=/comp", "--unknown1", "--unknown2", "--install-prefix=/foo"]
return $ [TestLabel "very basic option parsing" $ TestList [
"getOpt flags" ~: "failed" ~:
[Prefix "/foo", GhcFlag, NhcFlag, HugsFlag,
WithCompiler "/comp", InstPrefix "/foo"]
~=? flags,
"getOpt commands" ~: "failed" ~: ["configure", "foobar"] ~=? commands,
"getOpt commands" ~: "failed" ~: ["configure", "foobar"] ~=? commands',
"getOpt unknown opts" ~: "failed" ~:
["--unknown1", "--unknown2"] ~=? unkFlags,
"getOpt errors" ~: "failed" ~: [] ~=? ers],
......@@ -217,14 +218,14 @@ hunitTests =
["configure parsing for prefix and compiler flag" ~: "failed" ~:
(Right (ConfigCmd (Just comp, Nothing, Just "/usr/local"), []))
~=? (parseArgs ["--prefix=/usr/local", "--"++name, "configure"])
| (name, comp, comploc, pkgloc) <- m],
| (name, comp) <- m],
TestLabel "find the package tool" $ TestList
["configure parsing for prefix comp flag, withcompiler" ~: "failed" ~:
(Right (ConfigCmd (Just comp, Just "/foo/comp", Just "/usr/local"), []))
~=? (parseArgs ["--prefix=/usr/local", "--"++name,
"--with-compiler=/foo/comp", "configure"])
| (name, comp, comploc, pkgloc) <- m],
| (name, comp) <- m],
TestLabel "simpler commands" $ TestList
[flag ~: "failed" ~: (Right (flagCmd, [])) ~=? (parseArgs [flag])
......@@ -235,6 +236,7 @@ hunitTests =
("register", RegisterCmd)]
]
]
#endif
{- Testing ideas:
* IO to look for hugs and hugs-pkg (which hugs, etc)
......
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Default
-- Module : Distribution.Simple
-- Copyright : Isaac Jones 2003-2004
--
-- Maintainer : Isaac Jones <ijones@syntaxpolice.org>
......@@ -41,7 +41,7 @@ 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.Default (defaultMain)
module Distribution.Simple (defaultMain)
where
-- Base
......@@ -49,9 +49,9 @@ import System(getArgs)
import Distribution.Package(PackageConfig(..))
import Distribution.Setup(parseArgs, Action(..))
import Distribution.Misc(LocalBuildInfo(..), getPersistBuildConfig)
import Distribution.Simple.Build(build)
import Distribution.Simple.Configure(LocalBuildInfo(..), getPersistBuildConfig)
import Distribution.Simple.Install(install)
-- |Reads local build info, executes function
......
......@@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Build where
import Distribution.Package(PackageConfig)
import Distribution.Misc(LocalBuildInfo)
import Distribution.Simple.Configure(LocalBuildInfo)
build :: PackageConfig -> LocalBuildInfo -> IO ()
build _ _ = return ()
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Configure
-- Copyright : Isaac Jones 2003-2004
--
-- Maintainer : Isaac Jones <ijones@syntaxpolice.org>
-- Stability : alpha
-- Portability : GHC
--
-- Explanation: <FIX>
-- WHERE DOES THIS MODULE FIT IN AT A HIGH-LEVEL <FIX>
{- 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.Configure (writePersistBuildConfig,
getPersistBuildConfig,
LocalBuildInfo(..))
where
import Distribution.Setup(CompilerFlavor, Compiler)
-- |Data cached after configuration step.
data LocalBuildInfo = LocalBuildInfo {prefix :: String,
compiler :: Compiler}
deriving (Show, Eq)
emptyLocalBuildInfo :: LocalBuildInfo
emptyLocalBuildInfo = undefined
getPersistBuildConfig :: IO LocalBuildInfo
getPersistBuildConfig = return emptyLocalBuildInfo -- FIX
writePersistBuildConfig :: LocalBuildInfo -> IO ()
writePersistBuildConfig _ = return () --FIX
-- Locate the compiler based on the flavor
exeLoc :: CompilerFlavor -> IO FilePath
exeLoc _ = return "error, not yet implemented" -- FIX
pkgLoc :: CompilerFlavor -> IO FilePath
pkgLoc _ = return "error, not yet implemented" -- FIX
......@@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Install(install) where
import Distribution.Package(PackageConfig)
import Distribution.Misc(LocalBuildInfo)
import Distribution.Simple.Configure(LocalBuildInfo)
install :: PackageConfig -> LocalBuildInfo -> IO ()
install _ _ = return ()
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Simple.Register
-- Copyright : Isaac Jones 2003-2004
--
-- Maintainer : Isaac Jones <ijones@syntaxpolice.org>
-- Stability : alpha
-- Portability :
--
-- Explanation: <FIX>
-- WHERE DOES THIS MODULE FIT IN AT A HIGH-LEVEL <FIX>
{- 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.Register where
import Distribution.Simple.Configure(LocalBuildInfo)
import Distribution.Package(PackageConfig)
import Distribution.InstalledPackageInfo(InstalledPackageInfo)
getUseInfo :: LocalBuildInfo -> PackageConfig -> InstalledPackageInfo
getUseInfo _ _ = undefined
......@@ -3,7 +3,6 @@
** x-pkg command-line interface
* Code
** Version (simonMar)
** configure step
** cross-platform compiler location(simonmar?)
** help action without command... help command?
......
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