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