X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fghc-cabal%2Fghc-cabal.hs;h=3d9cf13dcb9fbc16311908230c352de873fa9a34;hb=930421d4ed09e5389e0ef4c5eef36075a6809cc0;hp=5979fb52da981560b4cc371903712d3471ba6a04;hpb=c25a472771baa1ba58118a8b0949795200928850;p=ghc-hetmet.git diff --git a/utils/ghc-cabal/ghc-cabal.hs b/utils/ghc-cabal/ghc-cabal.hs index 5979fb5..3d9cf13 100644 --- a/utils/ghc-cabal/ghc-cabal.hs +++ b/utils/ghc-cabal/ghc-cabal.hs @@ -3,12 +3,14 @@ module Main (main) where import qualified Distribution.ModuleName as ModuleName import Distribution.PackageDescription +import Distribution.PackageDescription.Check hiding (doesFileExist) import Distribution.PackageDescription.Configuration import Distribution.PackageDescription.Parse import Distribution.Simple import Distribution.Simple.Configure import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Program +import Distribution.Simple.Program.HcPkg import Distribution.Simple.Utils (defaultPackageDesc, writeFileAtomic) import Distribution.Simple.Build (writeAutogenFiles) import Distribution.Simple.Register @@ -17,21 +19,25 @@ import Distribution.Verbosity import qualified Distribution.InstalledPackageInfo as Installed import qualified Distribution.Simple.PackageIndex as PackageIndex +import Data.List import Data.Maybe import System.IO import System.Directory import System.Environment import System.Exit import System.FilePath +import Data.Char main :: IO () main = do args <- getArgs case args of "haddock" : distDir : dir : args' -> runHaddock distDir dir args' - "install" : ghcpkg : ghcpkgconfig : directory : distDir + "check" : dir : [] -> + doCheck dir + "install" : ghc : ghcpkg : topdir : directory : distDir : myDestDir : myPrefix : myLibdir : myDocdir : args' -> - doInstall ghcpkg ghcpkgconfig directory distDir + doInstall ghc ghcpkg topdir directory distDir myDestDir myPrefix myLibdir myDocdir args' "configure" : args' -> case break (== "--") args' of (config_args, "--" : distdir : directories) -> @@ -64,6 +70,20 @@ withCurrentDirectory directory io userHooks :: UserHooks userHooks = autoconfUserHooks +doCheck :: FilePath -> IO () +doCheck directory + = withCurrentDirectory directory + $ do let verbosity = normal + gpdFile <- defaultPackageDesc verbosity + gpd <- readPackageDescription verbosity gpdFile + case partition isFailure $ checkPackage gpd Nothing of + ([], []) -> return () + ([], warnings) -> mapM_ print warnings + (errs, _) -> do mapM_ print errs + exitWith (ExitFailure 1) + where isFailure (PackageDistSuspicious {}) = False + isFailure _ = True + runHaddock :: FilePath -> FilePath -> [String] -> IO () runHaddock distdir directory args = withCurrentDirectory directory @@ -92,8 +112,9 @@ runHaddock distdir directory args = f pd lbi us flags doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath - -> FilePath -> FilePath -> FilePath -> [String] -> IO () -doInstall ghcpkg ghcpkgconf directory distDir myDestDir myPrefix myLibdir myDocdir args + -> FilePath -> FilePath -> FilePath -> FilePath -> [String] + -> IO () +doInstall ghc ghcpkg topdir directory distDir myDestDir myPrefix myLibdir myDocdir args = withCurrentDirectory directory $ do defaultMainWithHooksArgs hooks (["copy", "--builddir", distDir] ++ (if null myDestDir then [] @@ -120,28 +141,76 @@ doInstall ghcpkg ghcpkgconf directory distDir myDestDir myPrefix myLibdir myDocd | otherwise = pd in f pd' lbi us flags modHook f pd lbi us flags - = let idts = installDirTemplates lbi - idts' = idts { prefix = toPathTemplate myPrefix, - libdir = toPathTemplate myLibdir, - libsubdir = toPathTemplate "$pkgid", - docdir = toPathTemplate (myDocdir "$pkgid"), - htmldir = toPathTemplate "$docdir" } - progs = withPrograms lbi - prog = ConfiguredProgram { - programId = programName ghcPkgProgram, - programVersion = Nothing, - programArgs = ["--global-conf", ghcpkgconf] - ++ if not (null myDestDir) - then ["--force"] - else [], - programLocation = UserSpecified ghcpkg + = do let verbosity = normal + idts = installDirTemplates lbi + idts' = idts { prefix = toPathTemplate myPrefix, + libdir = toPathTemplate myLibdir, + libsubdir = toPathTemplate "$pkgid", + docdir = toPathTemplate (myDocdir "$pkg"), + htmldir = toPathTemplate "$docdir" } + progs = withPrograms lbi + ghcProg = ConfiguredProgram { + programId = programName ghcProgram, + programVersion = Nothing, + programArgs = ["-B" ++ topdir], + programLocation = UserSpecified ghc + } + ghcpkgconf = topdir "package.conf.d" + ghcPkgProg = ConfiguredProgram { + programId = programName ghcPkgProgram, + programVersion = Nothing, + programArgs = ["--global-conf", + ghcpkgconf] + ++ if not (null myDestDir) + then ["--force"] + else [], + programLocation = UserSpecified ghcpkg + } + progs' = updateProgram ghcProg + $ updateProgram ghcPkgProg progs + instInfos <- dump verbosity ghcPkgProg GlobalPackageDB + let installedPkgs' = PackageIndex.listToInstalledPackageIndex + instInfos + let mlc = libraryConfig lbi + mlc' = case mlc of + Just lc -> + let cipds = componentInstalledPackageDeps lc + cipds' = map (fixupPackageId instInfos) cipds + in Just $ lc { + componentInstalledPackageDeps = cipds' + } + Nothing -> Nothing + lbi' = lbi { + libraryConfig = mlc', + installedPkgs = installedPkgs', + installDirTemplates = idts', + withPrograms = progs' } - progs' = updateProgram prog progs - lbi' = lbi { - installDirTemplates = idts', - withPrograms = progs' - } - in f pd lbi' us flags + f pd lbi' us flags + +-- The packages are built with the package ID ending in "-inplace", but +-- when they're installed they get the package hash appended. We need to +-- fix up the package deps so that they use the hash package IDs, not +-- the inplace package IDs. +fixupPackageId :: [Installed.InstalledPackageInfo] + -> InstalledPackageId + -> InstalledPackageId +fixupPackageId _ x@(InstalledPackageId ipi) + | "builtin:" `isPrefixOf` ipi = x +fixupPackageId ipinfos (InstalledPackageId ipi) + = case stripPrefix (reverse "-inplace") $ reverse ipi of + Nothing -> + error ("Installed package ID doesn't end in -inplace: " ++ show ipi) + Just x -> + let ipi' = reverse ('-' : x) + f (ipinfo : ipinfos') = case Installed.installedPackageId ipinfo of + y@(InstalledPackageId ipinfoid) + | ipi' `isPrefixOf` ipinfoid -> + y + _ -> + f ipinfos' + f [] = error ("Installed package ID not registered: " ++ show ipi) + in f ipinfos generate :: [String] -> FilePath -> FilePath -> IO () generate config_args distdir directory @@ -190,9 +259,11 @@ generate config_args distdir directory (Nothing, Nothing) -> return () (Just lib, Just clbi) -> do cwd <- getCurrentDirectory + let ipid = InstalledPackageId (display (packageId pd) ++ "-inplace") let installedPkgInfo = inplaceInstalledPackageInfo cwd distdir pd lib lbi clbi - content = Installed.showInstalledPackageInfo installedPkgInfo ++ "\n" + final_ipi = installedPkgInfo{ Installed.installedPackageId = ipid } + content = Installed.showInstalledPackageInfo final_ipi ++ "\n" writeFileAtomic (distdir "inplace-pkg-config") content _ -> error "Inconsistent lib components; can't happen?" @@ -224,16 +295,19 @@ generate config_args distdir directory -- stricter than gnu ld). Thus we remove the ldOptions for -- GHC's rts package: hackRtsPackage index = - case PackageIndex.lookupPackageName index (PackageName "rts") of - [rts] -> PackageIndex.insert rts { Installed.ldOptions = [] } index + case PackageIndex.lookupInstalledPackageByName index (PackageName "rts") of + [rts] -> PackageIndex.addToInstalledPackageIndex rts { Installed.ldOptions = [] } index _ -> error "No (or multiple) ghc rts package is registered!!" + dep_ids = map (packageId.getLocalPackageInfo lbi) $ + externalPackageDeps lbi + let variablePrefix = directory ++ '_':distdir let xs = [variablePrefix ++ "_VERSION = " ++ display (pkgVersion (package pd)), variablePrefix ++ "_MODULES = " ++ unwords (map display modules), variablePrefix ++ "_HS_SRC_DIRS = " ++ unwords (hsSourceDirs bi), - variablePrefix ++ "_DEPS = " ++ unwords (map display (externalPackageDeps lbi)), - variablePrefix ++ "_DEP_NAMES = " ++ unwords (map (display . packageName) (externalPackageDeps lbi)), + variablePrefix ++ "_DEPS = " ++ unwords (map display dep_ids), + variablePrefix ++ "_DEP_NAMES = " ++ unwords (map (display . packageName) dep_ids), variablePrefix ++ "_INCLUDE_DIRS = " ++ unwords (includeDirs bi), variablePrefix ++ "_INCLUDES = " ++ unwords (includes bi), variablePrefix ++ "_INSTALL_INCLUDES = " ++ unwords (installIncludes bi),