------------------------------------------------------------------------------- |-- Module : Distribution.Simple.Register-- Copyright : Isaac Jones 2003-2004---- Maintainer : cabal-devel@haskell.org-- Portability : portable---- This module deals with registering and unregistering packages. There are a-- couple ways it can do this, one is to do it directly. Another is to generate-- a script that can be run later to do it. The idea here being that the user-- is shielded from the details of what command to use for package registration-- for a particular compiler. In practice this aspect was not especially-- popular so we also provide a way to simply generate the package registration-- file which then must be manually passed to @ghc-pkg@. It is possible to-- generate registration information for where the package is to be installed,-- or alternatively to register the package inplace in the build tree. The-- latter is occasionally handy, and will become more important when we try to-- build multi-package systems.---- This module does not delegate anything to the per-compiler modules but just-- mixes it all in in this module, which is rather unsatisfactory. The script-- generation and the unregister feature are not well used or tested.{- 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. -}moduleDistribution.Simple.Register(register,unregister,registerPackage,generateRegistrationInfo,inplaceInstalledPackageInfo,absoluteInstalledPackageInfo,generalInstalledPackageInfo,)whereimportDistribution.Simple.LocalBuildInfo(LocalBuildInfo(..),ComponentLocalBuildInfo(..),InstallDirs(..),absoluteInstallDirs)importDistribution.Simple.BuildPaths(haddockName)importqualifiedDistribution.Simple.GHCasGHCimportqualifiedDistribution.Simple.LHCasLHCimportqualifiedDistribution.Simple.HugsasHugsimportqualifiedDistribution.Simple.UHCasUHCimportDistribution.Simple.Compiler(compilerVersion,CompilerFlavor(..),compilerFlavor,PackageDBStack,registrationPackageDB)importDistribution.Simple.Program(ConfiguredProgram,runProgramInvocation,requireProgram,lookupProgram,ghcPkgProgram,lhcPkgProgram)importDistribution.Simple.Program.Script(invocationAsSystemScript)importqualifiedDistribution.Simple.Program.HcPkgasHcPkgimportDistribution.Simple.Setup(RegisterFlags(..),CopyDest(..),fromFlag,fromFlagOrDefault,flagToMaybe)importDistribution.PackageDescription(PackageDescription(..),Library(..),BuildInfo(..),hcOptions)importDistribution.Package(Package(..),packageName,InstalledPackageId(..))importDistribution.InstalledPackageInfo(InstalledPackageInfo,InstalledPackageInfo_(InstalledPackageInfo),showInstalledPackageInfo)importqualifiedDistribution.InstalledPackageInfoasIPIimportDistribution.Simple.Utils(writeUTF8File,writeFileAtomic,setFileExecutable,die,notice,setupMessage)importDistribution.System(OS(..),buildOS)importDistribution.Text(display)importDistribution.Version(Version(..))importDistribution.VerbosityasVerbosity(Verbosity,normal)importDistribution.Compat.Exception(tryIO)importSystem.FilePath((</>),(<.>),isAbsolute)importSystem.Directory(getCurrentDirectory,removeDirectoryRecursive)importData.Maybe(isJust,fromMaybe,maybeToList)importData.List(partition,nub)-- ------------------------------------------------------------------------------- Registrationregister::PackageDescription->LocalBuildInfo->RegisterFlags-- ^Install in the user's database?; verbose->IO()registerpkg@PackageDescription{library=Justlib}lbi@LocalBuildInfo{libraryConfig=Justclbi}regFlags=doinstalledPkgInfo<-generateRegistrationInfoverbositypkgliblbiclbiinplacedistPref-- Three different modes:case()of_|modeGenerateRegFile->writeRegistrationFileinstalledPkgInfo|modeGenerateRegScript->writeRegisterScriptinstalledPkgInfo|otherwise->registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbswheremodeGenerateRegFile=isJust(flagToMaybe(regGenPkgConfregFlags))regFile=fromMaybe(display(packageIdpkg)<.>"conf")(fromFlag(regGenPkgConfregFlags))modeGenerateRegScript=fromFlag(regGenScriptregFlags)inplace=fromFlag(regInPlaceregFlags)-- FIXME: there's really no guarantee this will work.-- registering into a totally different db stack can-- fail if dependencies cannot be satisfied.packageDbs=nub$withPackageDBlbi++maybeToList(flagToMaybe(regPackageDBregFlags))distPref=fromFlag(regDistPrefregFlags)verbosity=fromFlag(regVerbosityregFlags)writeRegistrationFileinstalledPkgInfo=donoticeverbosity("Creating package registration file: "++regFile)writeUTF8FileregFile(showInstalledPackageInfoinstalledPkgInfo)writeRegisterScriptinstalledPkgInfo=casecompilerFlavor(compilerlbi)ofGHC->do(ghcPkg,_)<-requireProgramverbosityghcPkgProgram(withProgramslbi)writeHcPkgRegisterScriptverbosityinstalledPkgInfoghcPkgpackageDbsLHC->do(lhcPkg,_)<-requireProgramverbositylhcPkgProgram(withProgramslbi)writeHcPkgRegisterScriptverbosityinstalledPkgInfolhcPkgpackageDbsHugs->noticeverbosity"Registration scripts not needed for hugs"JHC->noticeverbosity"Registration scripts not needed for jhc"NHC->noticeverbosity"Registration scripts not needed for nhc98"UHC->noticeverbosity"Registration scripts not needed for uhc"_->die"Registration scripts are not implemented for this compiler"register__regFlags=noticeverbosity"No package to register"whereverbosity=fromFlag(regVerbosityregFlags)generateRegistrationInfo::Verbosity->PackageDescription->Library->LocalBuildInfo->ComponentLocalBuildInfo->Bool->FilePath->IOInstalledPackageInfogenerateRegistrationInfoverbositypkgliblbiclbiinplacedistPref=do--TODO: eliminate pwd!pwd<-getCurrentDirectory--TODO: the method of setting the InstalledPackageId is compiler specific-- this aspect should be delegated to a per-compiler helper.letcomp=compilerlbiipid<-casecompilerFlavorcompofGHC|compilerVersioncomp>=Version[6,11][]->dos<-GHC.libAbiHashverbositypkglbilibclbireturn(InstalledPackageId(display(packageIdpkg)++'-':s))_other->doreturn(InstalledPackageId(display(packageIdpkg)))letinstalledPkgInfo|inplace=inplaceInstalledPackageInfopwddistPrefpkgliblbiclbi|otherwise=absoluteInstalledPackageInfopkgliblbiclbireturninstalledPkgInfo{IPI.installedPackageId=ipid}registerPackage::Verbosity->InstalledPackageInfo->PackageDescription->LocalBuildInfo->Bool->PackageDBStack->IO()registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbs=doletmsg=ifinplacethen"In-place registering"else"Registering"setupMessageverbositymsg(packageIdpkg)casecompilerFlavor(compilerlbi)ofGHC->GHC.registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbsLHC->LHC.registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbsHugs->Hugs.registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbsUHC->UHC.registerPackageverbosityinstalledPkgInfopkglbiinplacepackageDbsJHC->noticeverbosity"Registering for jhc (nothing to do)"NHC->noticeverbosity"Registering for nhc98 (nothing to do)"_->die"Registering is not implemented for this compiler"writeHcPkgRegisterScript::Verbosity->InstalledPackageInfo->ConfiguredProgram->PackageDBStack->IO()writeHcPkgRegisterScriptverbosityinstalledPkgInfohcPkgpackageDbs=doletinvocation=HcPkg.reregisterInvocationhcPkgVerbosity.normalpackageDbs(RightinstalledPkgInfo)regScript=invocationAsSystemScriptbuildOSinvocationnoticeverbosity("Creating package registration script: "++regScriptFileName)writeUTF8FileregScriptFileNameregScriptsetFileExecutableregScriptFileNameregScriptFileName::FilePathregScriptFileName=casebuildOSofWindows->"register.bat"_->"register.sh"-- ------------------------------------------------------------------------------- Making the InstalledPackageInfo-- | Construct 'InstalledPackageInfo' for a library in a package, given a set-- of installation directories.--generalInstalledPackageInfo::([FilePath]->[FilePath])-- ^ Translate relative include dir paths to-- absolute paths.->PackageDescription->Library->ComponentLocalBuildInfo->InstallDirsFilePath->InstalledPackageInfogeneralInstalledPackageInfoadjustRelIncDirspkglibclbiinstallDirs=InstalledPackageInfo{--TODO: do not open-code this conversion from PackageId to InstalledPackageIdIPI.installedPackageId=InstalledPackageId(display(packageIdpkg)),IPI.sourcePackageId=packageIdpkg,IPI.license=licensepkg,IPI.copyright=copyrightpkg,IPI.maintainer=maintainerpkg,IPI.author=authorpkg,IPI.stability=stabilitypkg,IPI.homepage=homepagepkg,IPI.pkgUrl=pkgUrlpkg,IPI.synopsis=synopsispkg,IPI.description=descriptionpkg,IPI.category=categorypkg,IPI.exposed=libExposedlib,IPI.exposedModules=exposedModuleslib,IPI.hiddenModules=otherModulesbi,IPI.trusted=IPI.trustedIPI.emptyInstalledPackageInfo,IPI.importDirs=[libdirinstallDirs|hasModules],IPI.libraryDirs=ifhasLibrarythenlibdirinstallDirs:extraLibDirsbielseextraLibDirsbi,IPI.hsLibraries=["HS"++display(packageIdpkg)|hasLibrary],IPI.extraLibraries=extraLibsbi,IPI.extraGHCiLibraries=[],IPI.includeDirs=absinc++adjustRelIncDirsrelinc,IPI.includes=includesbi,IPI.depends=mapfst(componentPackageDepsclbi),IPI.hugsOptions=hcOptionsHugsbi,IPI.ccOptions=[],-- Note. NOT ccOptions bi!-- We don't want cc-options to be propagated-- to C compilations in other packages.IPI.ldOptions=ldOptionsbi,IPI.frameworkDirs=[],IPI.frameworks=frameworksbi,IPI.haddockInterfaces=[haddockdirinstallDirs</>haddockNamepkg],IPI.haddockHTMLs=[htmldirinstallDirs]}wherebi=libBuildInfolib(absinc,relinc)=partitionisAbsolute(includeDirsbi)hasModules=not$null(exposedModuleslib)&&null(otherModulesbi)hasLibrary=hasModules||not(null(cSourcesbi))-- | Construct 'InstalledPackageInfo' for a library that is inplace in the-- build tree.---- This function knows about the layout of inplace packages.--inplaceInstalledPackageInfo::FilePath-- ^ top of the build tree->FilePath-- ^ location of the dist tree->PackageDescription->Library->LocalBuildInfo->ComponentLocalBuildInfo->InstalledPackageInfoinplaceInstalledPackageInfoinplaceDirdistPrefpkgliblbiclbi=generalInstalledPackageInfoadjustRelativeIncludeDirspkglibclbiinstallDirswhereadjustRelativeIncludeDirs=map(inplaceDir</>)installDirs=(absoluteInstallDirspkglbiNoCopyDest){libdir=inplaceDir</>buildDirlbi,datadir=inplaceDir,datasubdir=distPref,docdir=inplaceDocdir,htmldir=inplaceHtmldir,haddockdir=inplaceHtmldir}inplaceDocdir=inplaceDir</>distPref</>"doc"inplaceHtmldir=inplaceDocdir</>"html"</>display(packageNamepkg)-- | Construct 'InstalledPackageInfo' for the final install location of a-- library package.---- This function knows about the layout of installed packages.--absoluteInstalledPackageInfo::PackageDescription->Library->LocalBuildInfo->ComponentLocalBuildInfo->InstalledPackageInfoabsoluteInstalledPackageInfopkgliblbiclbi=generalInstalledPackageInfoadjustReativeIncludeDirspkglibclbiinstallDirswhere-- For installed packages we install all include files into one dir,-- whereas in the build tree they may live in multiple local dirs.adjustReativeIncludeDirs_|null(installIncludesbi)=[]|otherwise=[includedirinstallDirs]bi=libBuildInfolibinstallDirs=absoluteInstallDirspkglbiNoCopyDest-- ------------------------------------------------------------------------------- Unregistrationunregister::PackageDescription->LocalBuildInfo->RegisterFlags->IO()unregisterpkglbiregFlags=doletpkgid=packageIdpkggenScript=fromFlag(regGenScriptregFlags)verbosity=fromFlag(regVerbosityregFlags)packageDb=fromFlagOrDefault(registrationPackageDB(withPackageDBlbi))(regPackageDBregFlags)installDirs=absoluteInstallDirspkglbiNoCopyDestsetupMessageverbosity"Unregistering"pkgidcasecompilerFlavor(compilerlbi)ofGHC->letJustghcPkg=lookupProgramghcPkgProgram(withProgramslbi)invocation=HcPkg.unregisterInvocationghcPkgVerbosity.normalpackageDbpkgidinifgenScriptthenwriteFileAtomicunregScriptFileName(invocationAsSystemScriptbuildOSinvocation)elserunProgramInvocationverbosityinvocationHugs->do_<-tryIO$removeDirectoryRecursive(libdirinstallDirs)return()NHC->do_<-tryIO$removeDirectoryRecursive(libdirinstallDirs)return()_->die("only unregistering with GHC and Hugs is implemented")unregScriptFileName::FilePathunregScriptFileName=casebuildOSofWindows->"unregister.bat"_->"unregister.sh"