diff options
-rw-r--r-- | cabal-helper.cabal | 74 | ||||
-rw-r--r-- | src/CabalHelper/Runtime/Main.hs | 66 | ||||
-rw-r--r-- | tests/CompileTest.hs | 1 | ||||
-rw-r--r-- | tests/GhcSession.hs | 16 | ||||
-rw-r--r-- | tests/exeintlib/exeintlib.cabal (renamed from tests/exeintlib/exelib.cabal) | 0 |
5 files changed, 108 insertions, 49 deletions
diff --git a/cabal-helper.cabal b/cabal-helper.cabal index 80002b3..468d10b 100644 --- a/cabal-helper.cabal +++ b/cabal-helper.cabal @@ -125,44 +125,44 @@ executable cabal-helper-wrapper , utf8-string < 1.1 && >= 1.0.1.1 , ghc-prim -test-suite compile-test - default-language: Haskell2010 - default-extensions: NondecreasingIndentation - type: exitcode-stdio-1.0 - main-is: CompileTest.hs - hs-source-dirs: tests, src - other-modules: - CabalHelper.Compiletime.Compat.Environment - CabalHelper.Compiletime.Compat.Version - CabalHelper.Compiletime.Compile - CabalHelper.Compiletime.Data - CabalHelper.Compiletime.Log - CabalHelper.Compiletime.Types - CabalHelper.Shared.Common - CabalHelper.Shared.Sandbox - Paths_cabal_helper - ghc-options: -Wall - build-tools: cabal +-- test-suite compile-test +-- default-language: Haskell2010 +-- default-extensions: NondecreasingIndentation +-- type: exitcode-stdio-1.0 +-- main-is: CompileTest.hs +-- hs-source-dirs: tests, src +-- other-modules: +-- CabalHelper.Compiletime.Compat.Environment +-- CabalHelper.Compiletime.Compat.Version +-- CabalHelper.Compiletime.Compile +-- CabalHelper.Compiletime.Data +-- CabalHelper.Compiletime.Log +-- CabalHelper.Compiletime.Types +-- CabalHelper.Shared.Common +-- CabalHelper.Shared.Sandbox +-- Paths_cabal_helper +-- ghc-options: -Wall +-- build-tools: cabal - -- Same as cabal-helper-wrapper - build-depends: base < 5 && >= 4.5 - if os(windows) - build-depends: base >= 4.7 - build-depends: Cabal < 2.1 && >= 2.0 || < 1.26 && >= 1.14 - , bytestring < 0.11 && >= 0.9.2.1 - , directory < 1.4 && >= 1.1.0.2 - , exceptions < 0.9 && >= 0.8.3 - , filepath < 1.5 && >= 1.3.0.0 - , mtl < 2.3 && >= 2.0 - , process < 1.7 && >= 1.1.0.1 - , template-haskell < 2.13 && >= 2.7.0.0 - , temporary < 1.3 && >= 1.2.0.4 - , transformers < 0.6 && >= 0.3.0.0 - if !os(windows) - build-depends: unix < 2.8 && >= 2.5.1.1 - build-depends: unix-compat < 0.5 && >= 0.4.3.1 - , utf8-string < 1.1 && >= 1.0.1.1 - , ghc-prim +-- -- Same as cabal-helper-wrapper +-- build-depends: base < 5 && >= 4.5 +-- if os(windows) +-- build-depends: base >= 4.7 +-- build-depends: Cabal < 2.1 && >= 2.0 || < 1.26 && >= 1.14 +-- , bytestring < 0.11 && >= 0.9.2.1 +-- , directory < 1.4 && >= 1.1.0.2 +-- , exceptions < 0.9 && >= 0.8.3 +-- , filepath < 1.5 && >= 1.3.0.0 +-- , mtl < 2.3 && >= 2.0 +-- , process < 1.7 && >= 1.1.0.1 +-- , template-haskell < 2.13 && >= 2.7.0.0 +-- , temporary < 1.3 && >= 1.2.0.4 +-- , transformers < 0.6 && >= 0.3.0.0 +-- if !os(windows) +-- build-depends: unix < 2.8 && >= 2.5.1.1 +-- build-depends: unix-compat < 0.5 && >= 0.4.3.1 +-- , utf8-string < 1.1 && >= 1.0.1.1 +-- , ghc-prim test-suite ghc-session default-language: Haskell2010 diff --git a/src/CabalHelper/Runtime/Main.hs b/src/CabalHelper/Runtime/Main.hs index 2030023..ac357e2 100644 --- a/src/CabalHelper/Runtime/Main.hs +++ b/src/CabalHelper/Runtime/Main.hs @@ -19,7 +19,7 @@ #undef CH_MIN_VERSION_Cabal #define CH_MIN_VERSION_Cabal MIN_VERSION_Cabal #endif - +import Distribution.Backpack (OpenUnitId(..)) import Distribution.Simple.Utils (cabalVersion) import Distribution.Simple.Configure import Distribution.Package @@ -69,6 +69,7 @@ import Distribution.Simple.LocalBuildInfo , externalPackageDeps , withComponentsLBI , withLibLBI + , withExeLBI ) import Distribution.Simple.GHC ( componentGhcOptions @@ -105,6 +106,12 @@ import qualified Distribution.ModuleName as C import Distribution.Text ( display ) +import Distribution.Types.ModuleRenaming + ( ModuleRenaming(..) + ) +import Distribution.Types.UnitId + ( DefUnitId + ) import Distribution.Verbosity ( Verbosity , silent @@ -154,6 +161,7 @@ import Distribution.Version ) import Distribution.Types.UnitId ( UnitId + , unDefUnitId ) import Distribution.Types.MungedPackageId ( MungedPackageId @@ -405,6 +413,15 @@ getLibraryClbi pd lbi = unsafePerformIO $ do readIORef lr +getExeClbi pd lbi = unsafePerformIO $ do + lr <- newIORef Nothing + + withExeLBI pd lbi $ \ exe clbi -> + writeIORef lr $ Just (exe,clbi) + + readIORef lr + + componentsMap :: LocalBuildInfo -> Verbosity -> FilePath @@ -430,6 +447,12 @@ componentsMap lbi _v _distdir f = do reverse <$> readIORef lr +-- componentOptions' :: (LocalBuildInfo, Verbosity, FilePath) +-- -> Bool +-- -> [String] +-- -> (LocalBuildInfo -> Verbosity -> GhcOptions -> IO a) +-- -> (GhcOptions -> GhcOptions) +-- -> IO [(ChComponentName, a)] componentOptions' (lbi, v, distdir) inplaceFlag flags rf f = do let pd = localPkgDescr lbi componentsMap lbi v distdir $ \c clbi bi -> let @@ -442,7 +465,15 @@ componentOptions' (lbi, v, distdir) inplaceFlag flags rf f = do opts' = f opts in rf lbi v $ nubPackageFlags $ opts' `mappend` adopts - + -- in rf lbi v $ nubPackageFlags $ adopts + -- in rf lbi v $ nubPackageFlags $ opts' + -- in rf lbi v $ nubPackageFlags $ mempty + +componentOptions :: (LocalBuildInfo, Verbosity, FilePath) + -> Bool + -> [String] + -> (GhcOptions -> GhcOptions) + -> IO [(ChComponentName, [String])] componentOptions (lbi, v, distdir) inplaceFlag flags f = componentOptions' (lbi, v, distdir) inplaceFlag flags renderGhcOptions' f @@ -463,11 +494,12 @@ removeInplaceDeps :: Verbosity -> ComponentLocalBuildInfo -> (ComponentLocalBuildInfo, GhcOptions) removeInplaceDeps _v lbi pd clbi = let - (ideps, deps) = partition (isInplaceDep lbi) (componentPackageDeps clbi) + (ideps, deps) = partition (isInplaceDep lbi clbi) (componentPackageDeps clbi) + (_, incs) = partition (isInplaceCompInc clbi) (componentIncludes clbi) hasIdeps = not $ null ideps libopts = - case getLibraryClbi pd lbi of - Just (lib, libclbi) | hasIdeps -> + case (getLibraryClbi pd lbi,getExeClbi pd lbi) of + (Just (lib, libclbi),_) | hasIdeps -> let libbi = libBuildInfo lib liboutdir = componentOutDir lbi (CLib lib) @@ -475,10 +507,20 @@ removeInplaceDeps _v lbi pd clbi = let (componentGhcOptions normal lbi libbi libclbi liboutdir) { ghcOptPackageDBs = [] } + (_,Just (exe,execlbi)) | hasIdeps -> + let + exebi = buildInfo exe + exeoutdir = componentOutDir lbi (CExe exe) + in + (componentGhcOptions normal lbi exebi execlbi exeoutdir) { + ghcOptPackageDBs = [] + } _ -> mempty - clbi' = clbi { componentPackageDeps = deps } + clbi' = clbi { componentPackageDeps = deps + , componentIncludes = incs } in (clbi', libopts) - + -- in error $ "removeInplaceDeps:(clbi')=" ++ show (clbi' ) + initialBuildStepsForAllComponents distdir pd lbi v = initialBuildSteps distdir pd lbi v @@ -560,10 +602,16 @@ componentEntrypoints (CBench Benchmark { benchmarkInterface = BenchmarkExeV10 _ componentEntrypoints (CBench Benchmark {}) = ChLibEntrypoint [] [] +#if CH_MIN_VERSION_Cabal(2,0,0) +isInplaceCompInc :: ComponentLocalBuildInfo -> (OpenUnitId, ModuleRenaming) -> Bool +isInplaceCompInc clbi (DefiniteUnitId uid, _mr) = unDefUnitId uid `elem` componentInternalDeps clbi +isInplaceCompInc clbi (IndefFullUnitId _ _, _mmr) = False -- TODO: keep this for now, what in future? +#endif #if CH_MIN_VERSION_Cabal(2,0,0) -isInplaceDep :: LocalBuildInfo -> (UnitId, MungedPackageId) -> Bool -isInplaceDep lbi (mpid, pid) = localUnitId lbi == mpid +isInplaceDep :: LocalBuildInfo -> ComponentLocalBuildInfo -> (UnitId, MungedPackageId) -> Bool +isInplaceDep lbi clbi (uid, _mpid) = uid `elem` componentInternalDeps clbi +-- isInplaceDep lbi clbi (uid, _mpid) = True #else isInplaceDep :: LocalBuildInfo -> (InstalledPackageId, PackageId) -> Bool # if CH_MIN_VERSION_Cabal(1,23,0) diff --git a/tests/CompileTest.hs b/tests/CompileTest.hs index de9b6ab..cc9c85a 100644 --- a/tests/CompileTest.hs +++ b/tests/CompileTest.hs @@ -97,6 +97,7 @@ main = do , ("8.0.1", ">= 1.24 ") , ("8.0.2", ">= 1.24.2 ") , ("8.2.1", ">= 2.0.0.2 ") + , ("8.2.2", ">= 2.0.0.2 ") ] relevant_cabal_versions = diff --git a/tests/GhcSession.hs b/tests/GhcSession.hs index 42193b9..f627cae 100644 --- a/tests/GhcSession.hs +++ b/tests/GhcSession.hs @@ -27,8 +27,9 @@ main = do args <- getArgs topdir <- getCurrentDirectory res <- mapM (setup topdir test) $ case args of - [] -> [ ("tests/exelib" , parseVer "1.10") - , ("tests/exeintlib", parseVer "2.0") + [] -> [ + -- ("tests/exelib" , parseVer "1.10") + ("tests/exeintlib", parseVer "2.0") ] xs -> map (,parseVer "0") xs @@ -49,6 +50,7 @@ setup :: FilePath -> (FilePath -> IO [Bool]) -> (FilePath, Version) -> IO [Bool] setup topdir act (srcdir, min_cabal_ver) = do ci_ver <- cabalInstallVersion c_ver <- cabalInstallBuiltinCabalVersion + putStrLn $ "(ci_ver,c_ver)=" ++ show (ci_ver,c_ver) -- AZ-DEBUG let mreason | (ci_ver < parseVer "1.24") = Just $ "cabal-install-" ++ showVersion ci_ver ++ " is too old" @@ -63,7 +65,9 @@ setup topdir act (srcdir, min_cabal_ver) = do putStrLn $ "Skipping test '" ++ srcdir ++ "' because " ++ reason ++ "." return [] Nothing -> do - withSystemTempDirectory "cabal-helper.ghc-session.test" $ \dir -> do + -- withSystemTempDirectory "cabal-helper.ghc-session.test" $ \dir -> do + let dir = "/tmp/xxx" + do setCurrentDirectory $ topdir </> srcdir run "cabal" [ "sdist", "--output-dir", dir ] @@ -76,7 +80,9 @@ setup topdir act (srcdir, min_cabal_ver) = do run x xs = do print $ x:xs o <- readProcess x xs "" + putStrLn "=======================output============" -- AZ-DEBUG putStrLn o + putStrLn "=======================output-done=======" -- AZ-DEBUG return () test :: FilePath -> IO [Bool] @@ -85,7 +91,9 @@ test dir = do cs <- runQuery qe $ components $ (,,) <$> entrypoints <.> ghcOptions forM cs $ \(ep, opts, cn) -> do let sopts = intercalate " " $ map formatArg $ "ghc" : opts + putStrLn "======================= cn ============" -- AZ-DEBUG putStrLn $ "\n" ++ show cn ++ ": " ++ sopts + putStrLn "======================= cn done =======" -- AZ-DEBUG compileModule ep opts where formatArg x @@ -95,6 +103,8 @@ test dir = do compileModule :: ChEntrypoint -> [String] -> IO Bool compileModule ep opts = do + putStrLn $ "compileModule:ep=" ++ show ep + E.handle (\(ec :: ExitCode) -> print ec >> return False) $ do defaultErrorHandler defaultFatalMessager defaultFlushOut $ do diff --git a/tests/exeintlib/exelib.cabal b/tests/exeintlib/exeintlib.cabal index 807aac5..807aac5 100644 --- a/tests/exeintlib/exelib.cabal +++ b/tests/exeintlib/exeintlib.cabal |