Extend Package to include id
This commit 1. rename Package with PackageBaseName 2. Pacakge = (PackageBaseName, Maybe String) to save its id 3. Expose packages with id if available
This commit is contained in:
parent
7c6fbb2af1
commit
a0db24b0a5
@ -44,26 +44,34 @@ getCompilerOptions ghcopts cradle pkgDesc = do
|
|||||||
wdir = cradleCurrentDir cradle
|
wdir = cradleCurrentDir cradle
|
||||||
Just cdir = cradleCabalDir cradle
|
Just cdir = cradleCabalDir cradle
|
||||||
Just cfile = cradleCabalFile cradle
|
Just cfile = cradleCabalFile cradle
|
||||||
|
pkgs = cradlePackages cradle
|
||||||
buildInfos = cabalAllBuildInfo pkgDesc
|
buildInfos = cabalAllBuildInfo pkgDesc
|
||||||
idirs = includeDirectories cdir wdir $ cabalSourceDirs buildInfos
|
idirs = includeDirectories cdir wdir $ cabalSourceDirs buildInfos
|
||||||
depPkgs = removeThem problematicPackages $ removeMe cfile $ cabalDependPackages buildInfos
|
depPkgs = attachPackageIds pkgs $ removeThem problematicPackages $ removeMe cfile $ cabalDependPackages buildInfos
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
-- Dependent packages
|
-- Dependent packages
|
||||||
|
|
||||||
removeMe :: FilePath -> [Package] -> [Package]
|
removeMe :: FilePath -> [PackageBaseName] -> [PackageBaseName]
|
||||||
removeMe cabalfile = filter (/= me)
|
removeMe cabalfile = filter (/= me)
|
||||||
where
|
where
|
||||||
me = dropExtension $ takeFileName cabalfile
|
me = dropExtension $ takeFileName cabalfile
|
||||||
|
|
||||||
removeThem :: [Package] -> [Package] -> [Package]
|
removeThem :: [PackageBaseName] -> [PackageBaseName] -> [PackageBaseName]
|
||||||
removeThem badpkgs = filter (`notElem` badpkgs)
|
removeThem badpkgs = filter (`notElem` badpkgs)
|
||||||
|
|
||||||
problematicPackages :: [Package]
|
problematicPackages :: [PackageBaseName]
|
||||||
problematicPackages = [
|
problematicPackages = [
|
||||||
"base-compat" -- providing "Prelude"
|
"base-compat" -- providing "Prelude"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
attachPackageIds :: [Package] -> [PackageBaseName] -> [Package]
|
||||||
|
attachPackageIds pkgs = map attachId
|
||||||
|
where
|
||||||
|
attachId x = case lookup x pkgs of
|
||||||
|
Nothing -> (x, Nothing)
|
||||||
|
Just p -> (x, p)
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
-- Include directories for modules
|
-- Include directories for modules
|
||||||
|
|
||||||
@ -138,7 +146,7 @@ cabalAllBuildInfo pd = libBI ++ execBI ++ testBI ++ benchBI
|
|||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
-- | Extracting package names of dependency.
|
-- | Extracting package names of dependency.
|
||||||
cabalDependPackages :: [BuildInfo] -> [Package]
|
cabalDependPackages :: [BuildInfo] -> [PackageBaseName]
|
||||||
cabalDependPackages bis = uniqueAndSort $ pkgs
|
cabalDependPackages bis = uniqueAndSort $ pkgs
|
||||||
where
|
where
|
||||||
pkgs = map getDependencyPackageName $ concatMap targetBuildDepends bis
|
pkgs = map getDependencyPackageName $ concatMap targetBuildDepends bis
|
||||||
|
@ -32,6 +32,7 @@ findCradle = do
|
|||||||
, cradleCabalDir = Nothing
|
, cradleCabalDir = Nothing
|
||||||
, cradleCabalFile = Nothing
|
, cradleCabalFile = Nothing
|
||||||
, cradlePackageDbOpts = []
|
, cradlePackageDbOpts = []
|
||||||
|
, cradlePackages = []
|
||||||
}
|
}
|
||||||
|
|
||||||
findCradle' :: FilePath -> IO Cradle
|
findCradle' :: FilePath -> IO Cradle
|
||||||
@ -43,13 +44,14 @@ findCradle' wdir = do
|
|||||||
, cradleCabalDir = Just cdir
|
, cradleCabalDir = Just cdir
|
||||||
, cradleCabalFile = Just cfile
|
, cradleCabalFile = Just cfile
|
||||||
, cradlePackageDbOpts = pkgDbOpts
|
, cradlePackageDbOpts = pkgDbOpts
|
||||||
|
, cradlePackages = []
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Just for testing
|
-- Just for testing
|
||||||
findCradleWithoutSandbox :: IO Cradle
|
findCradleWithoutSandbox :: IO Cradle
|
||||||
findCradleWithoutSandbox = do
|
findCradleWithoutSandbox = do
|
||||||
cradle <- findCradle
|
cradle <- findCradle
|
||||||
return cradle { cradlePackageDbOpts = [] }
|
return cradle { cradlePackageDbOpts = [], cradlePackages = [] }
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ debug opt cradle fileName = do
|
|||||||
, "Cabal file: " ++ cabalFile
|
, "Cabal file: " ++ cabalFile
|
||||||
, "GHC options: " ++ unwords gopts
|
, "GHC options: " ++ unwords gopts
|
||||||
, "Include directories: " ++ unwords incDir
|
, "Include directories: " ++ unwords incDir
|
||||||
, "Dependent packages: " ++ intercalate ", " pkgs
|
, "Dependent packages: " ++ (intercalate ", " $ map fst pkgs)
|
||||||
, "Fast check: " ++ if fast then "Yes" else "No"
|
, "Fast check: " ++ if fast then "Yes" else "No"
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
@ -234,8 +234,10 @@ addDevPkgs df pkgs = df''
|
|||||||
df' = dopt_set df Opt_HideAllPackages
|
df' = dopt_set df Opt_HideAllPackages
|
||||||
#endif
|
#endif
|
||||||
df'' = df' {
|
df'' = df' {
|
||||||
packageFlags = map ExposePackage pkgs ++ packageFlags df
|
packageFlags = map expose pkgs ++ packageFlags df
|
||||||
}
|
}
|
||||||
|
expose (pkg, Nothing) = ExposePackage pkg
|
||||||
|
expose (_, Just pid) = ExposePackageId pid
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
@ -90,6 +90,7 @@ data Cradle = Cradle {
|
|||||||
, cradleCabalFile :: Maybe FilePath
|
, cradleCabalFile :: Maybe FilePath
|
||||||
-- | The package db options. ([\"-no-user-package-db\",\"-package-db\",\"\/foo\/bar\/i386-osx-ghc-7.6.3-packages.conf.d\"])
|
-- | The package db options. ([\"-no-user-package-db\",\"-package-db\",\"\/foo\/bar\/i386-osx-ghc-7.6.3-packages.conf.d\"])
|
||||||
, cradlePackageDbOpts :: [GHCOption]
|
, cradlePackageDbOpts :: [GHCOption]
|
||||||
|
, cradlePackages :: [Package]
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
@ -101,7 +102,10 @@ type GHCOption = String
|
|||||||
type IncludeDir = FilePath
|
type IncludeDir = FilePath
|
||||||
|
|
||||||
-- | A package name.
|
-- | A package name.
|
||||||
type Package = String
|
type PackageBaseName = String
|
||||||
|
|
||||||
|
-- | A package name and its ID.
|
||||||
|
type Package = (PackageBaseName, Maybe String)
|
||||||
|
|
||||||
-- | Haskell expression.
|
-- | Haskell expression.
|
||||||
type Expression = String
|
type Expression = String
|
||||||
|
@ -28,7 +28,7 @@ spec = do
|
|||||||
ghcOptions = ghcOptions res
|
ghcOptions = ghcOptions res
|
||||||
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
||||||
}
|
}
|
||||||
res' `shouldBe` CompilerOptions {ghcOptions = ["-no-user-package-db","-package-db","/home/me/work/ghc-mod/test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"], includeDirs = ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"], depPackages = ["Cabal","base","template-haskell"]}
|
res' `shouldBe` CompilerOptions {ghcOptions = ["-no-user-package-db","-package-db","/home/me/work/ghc-mod/test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"], includeDirs = ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"], depPackages = [("Cabal", Nothing), ("base", Nothing) , ("template-haskell", Nothing)]}
|
||||||
|
|
||||||
describe "cabalDependPackages" $ do
|
describe "cabalDependPackages" $ do
|
||||||
it "extracts dependent packages" $ do
|
it "extracts dependent packages" $ do
|
||||||
|
@ -22,6 +22,7 @@ spec = do
|
|||||||
, cradleCabalDir = Nothing
|
, cradleCabalDir = Nothing
|
||||||
, cradleCabalFile = Nothing
|
, cradleCabalFile = Nothing
|
||||||
, cradlePackageDbOpts = []
|
, cradlePackageDbOpts = []
|
||||||
|
, cradlePackages = []
|
||||||
}
|
}
|
||||||
it "finds a cabal file and a sandbox" $ do
|
it "finds a cabal file and a sandbox" $ do
|
||||||
withDirectory "test/data/subdir1/subdir2" $ \dir -> do
|
withDirectory "test/data/subdir1/subdir2" $ \dir -> do
|
||||||
@ -31,6 +32,7 @@ spec = do
|
|||||||
, cradleCabalDir = Just ("test" </> "data")
|
, cradleCabalDir = Just ("test" </> "data")
|
||||||
, cradleCabalFile = Just ("test" </> "data" </> "cabalapi.cabal")
|
, cradleCabalFile = Just ("test" </> "data" </> "cabalapi.cabal")
|
||||||
, cradlePackageDbOpts = ["-no-user-package-db", "-package-db", "test" </> "data" </> ".cabal-sandbox" </> "/home/me/work/ghc-mod/test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"]
|
, cradlePackageDbOpts = ["-no-user-package-db", "-package-db", "test" </> "data" </> ".cabal-sandbox" </> "/home/me/work/ghc-mod/test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"]
|
||||||
|
, cradlePackages = []
|
||||||
}
|
}
|
||||||
it "works even if a sandbox config file is broken" $ do
|
it "works even if a sandbox config file is broken" $ do
|
||||||
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
||||||
@ -40,6 +42,7 @@ spec = do
|
|||||||
, cradleCabalDir = Just ("test" </> "data" </> "broken-sandbox")
|
, cradleCabalDir = Just ("test" </> "data" </> "broken-sandbox")
|
||||||
, cradleCabalFile = Just ("test" </> "data" </> "broken-sandbox" </> "dummy.cabal")
|
, cradleCabalFile = Just ("test" </> "data" </> "broken-sandbox" </> "dummy.cabal")
|
||||||
, cradlePackageDbOpts = []
|
, cradlePackageDbOpts = []
|
||||||
|
, cradlePackages = []
|
||||||
}
|
}
|
||||||
|
|
||||||
describe "getPackageDbDir" $ do
|
describe "getPackageDbDir" $ do
|
||||||
@ -51,11 +54,10 @@ spec = do
|
|||||||
getPackageDbDir "test/data/bad.config" `shouldThrow` anyException
|
getPackageDbDir "test/data/bad.config" `shouldThrow` anyException
|
||||||
|
|
||||||
relativeCradle :: FilePath -> Cradle -> Cradle
|
relativeCradle :: FilePath -> Cradle -> Cradle
|
||||||
relativeCradle dir cradle = Cradle {
|
relativeCradle dir cradle = cradle {
|
||||||
cradleCurrentDir = toRelativeDir dir $ cradleCurrentDir cradle
|
cradleCurrentDir = toRelativeDir dir $ cradleCurrentDir cradle
|
||||||
, cradleCabalDir = toRelativeDir dir <$> cradleCabalDir cradle
|
, cradleCabalDir = toRelativeDir dir <$> cradleCabalDir cradle
|
||||||
, cradleCabalFile = toRelativeDir dir <$> cradleCabalFile cradle
|
, cradleCabalFile = toRelativeDir dir <$> cradleCabalFile cradle
|
||||||
, cradlePackageDbOpts = cradlePackageDbOpts cradle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Work around GHC 7.2.2 where `canonicalizePath "/"` returns "/.".
|
-- Work around GHC 7.2.2 where `canonicalizePath "/"` returns "/.".
|
||||||
|
@ -7,7 +7,7 @@ import Dir
|
|||||||
|
|
||||||
checkFast :: String -> String -> IO ()
|
checkFast :: String -> String -> IO ()
|
||||||
checkFast file ans = withDirectory_ "test/data" $ do
|
checkFast file ans = withDirectory_ "test/data" $ do
|
||||||
let cradle = Cradle "." Nothing Nothing []
|
let cradle = Cradle "." Nothing Nothing [] []
|
||||||
res <- debugInfo defaultOptions cradle file
|
res <- debugInfo defaultOptions cradle file
|
||||||
lines res `shouldContain` [ans]
|
lines res `shouldContain` [ans]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user