Commit 86ed4e32 authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

Fix detection of libraries

Previously a very fragile heuristic was used. Now we explicitly declare
this.

Perhaps a better option in the future would be to instead emit this
information from `ghc-cabal` and pick it up from `package-data.mk`.

Fixes #9.
parent 9d2868b1
......@@ -51,7 +51,7 @@ dllSplit = utility "dll-split"
filepath = library "filepath"
genapply = utility "genapply"
genprimopcode = utility "genprimopcode"
ghc = topLevel "ghc-bin" `setPath` "ghc"
ghc = topLevel "ghc-bin" `setPath` "ghc" `setPkgType` Program
ghcBoot = library "ghc-boot"
ghcCabal = utility "ghc-cabal"
ghci = library "ghci"
......
{-# LANGUAGE DeriveGeneric #-}
module Package (
Package (..), PackageName, pkgCabalFile, setPath, topLevel, library, utility,
matchPackageNames
Package (..), PackageName, PackageType (..),
-- * Queries
pkgCabalFile,
matchPackageNames,
-- * Helpers for constructing 'Package's
setPath, topLevel, library, utility, setPkgType
) where
import Base
import GHC.Generics (Generic)
-- It is helpful to distinguish package names from strings.
-- | It is helpful to distinguish package names from strings.
type PackageName = String
-- type PackageType = Program | Library
-- | We regard packages as either being libraries or programs. This is
-- bit of a convenient lie as Cabal packages can be both, but it works
-- for now.
data PackageType = Program | Library
deriving Generic
-- pkgPath is the path to the source code relative to the root
data Package = Package
{
pkgName :: PackageName, -- Examples: "ghc", "Cabal"
pkgPath :: FilePath -- "compiler", "libraries/Cabal/Cabal"
-- pkgType :: PackageType -- TopLevel, Library
pkgName :: PackageName, -- ^ Examples: "ghc", "Cabal"
pkgPath :: FilePath, -- ^ pkgPath is the path to the source code relative to the root.
-- e.g. "compiler", "libraries/Cabal/Cabal"
pkgType :: PackageType
}
deriving Generic
......@@ -26,17 +34,20 @@ pkgCabalFile :: Package -> FilePath
pkgCabalFile pkg = pkgPath pkg -/- pkgName pkg <.> "cabal"
topLevel :: PackageName -> Package
topLevel name = Package name name
topLevel name = Package name name Library
library :: PackageName -> Package
library name = Package name ("libraries" -/- name)
library name = Package name ("libraries" -/- name) Library
utility :: PackageName -> Package
utility name = Package name ("utils" -/- name)
utility name = Package name ("utils" -/- name) Program
setPath :: Package -> FilePath -> Package
setPath pkg path = pkg { pkgPath = path }
setPkgType :: Package -> PackageType -> Package
setPkgType pkg ty = pkg { pkgType = ty }
instance Show Package where
show = pkgName
......@@ -56,3 +67,7 @@ instance Binary Package
instance Hashable Package where
hashWithSalt salt = hashWithSalt salt . show
instance NFData Package
instance Binary PackageType
instance Hashable PackageType
instance NFData PackageType
......@@ -38,7 +38,8 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
buildWithResources [(ghcCabal rs, 1)] $
fullTarget target GhcCabal [cabalFile] outs
-- TODO: find out of ghc-cabal can be concurrent with ghc-pkg
-- ghc-pkg produces inplace-pkg-config when run on packages with
-- library components only
when (isLibrary pkg) .
whenM (interpretPartial target registerPackage) .
buildWithResources [(ghcPkg rs, 1)] $
......
......@@ -33,7 +33,8 @@ programPath :: Stage -> Package -> Maybe FilePath
programPath = userProgramPath
isLibrary :: Package -> Bool
isLibrary pkg = programPath Stage0 pkg == Nothing
isLibrary (Package {pkgType=Library}) = True
isLibrary _ = False
-- Find all Haskell source files for the current target. TODO: simplify.
getPackageSources :: Expr [FilePath]
......
......@@ -22,7 +22,7 @@ pkgDataFile stage pkg = targetPath stage pkg -/- "package-data.mk"
-- Relative path to a package haddock file, e.g.:
-- "libraries/array/dist-install/doc/html/array/array.haddock"
pkgHaddockFile :: Package -> FilePath
pkgHaddockFile pkg @ (Package name _) =
pkgHaddockFile pkg @ (Package name _ _) =
targetPath Stage1 pkg -/- "doc/html" -/- name -/- name <.> "haddock"
-- Relative path to a package library file, e.g.:
......
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