[Git][ghc/ghc][wip/romes/hardwire-ghc-unit-id] If filepaths have hashes then cabal can't parse them
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Mon Mar 20 15:54:37 UTC 2023
Rodrigo Mesquita pushed to branch wip/romes/hardwire-ghc-unit-id at Glasgow Haskell Compiler / GHC
Commits:
66c4b329 by romes at 2023-03-20T15:54:06+00:00
If filepaths have hashes then cabal can't parse them
- - - - -
12 changed files:
- hadrian/src/Context.hs
- hadrian/src/Hadrian/Haskell/Cabal.hs
- hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
- hadrian/src/Hadrian/Haskell/Hash.hs
- hadrian/src/Hadrian/Haskell/Hash.hs-boot
- hadrian/src/Rules/BinaryDist.hs
- hadrian/src/Rules/CabalReinstall.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Register.hs
- hadrian/src/Settings/Builders/Cabal.hs
- hadrian/src/Settings/Builders/Ghc.hs
- hadrian/src/Settings/Builders/Haddock.hs
Changes:
=====================================
hadrian/src/Context.hs
=====================================
@@ -70,15 +70,15 @@ distDir st = do
hostArch <- cabalArchString <$> setting arch
return $ hostArch ++ "-" ++ hostOs ++ "-ghc-" ++ version
-pkgFileName :: Package -> String -> String -> Action FilePath
-pkgFileName package prefix suffix = do
- pid <- pkgSimpleIdentifier package
+pkgFileName :: Context -> Package -> String -> String -> Action FilePath
+pkgFileName context package prefix suffix = do
+ pid <- pkgUnitId context package
return $ prefix ++ pid ++ suffix
pkgFile :: Context -> String -> String -> Action FilePath
pkgFile context at Context {..} prefix suffix = do
path <- buildPath context
- fileName <- pkgFileName package prefix suffix
+ fileName <- pkgFileName context package prefix suffix
return $ path -/- fileName
-- | Path to inplace package configuration file of a given 'Context'.
@@ -95,9 +95,9 @@ pkgSetupConfigFile context = pkgSetupConfigDir context <&> (-/- "setup-config")
-- | Path to the haddock file of a given 'Context', e.g.:
-- @_build/stage1/libraries/array/doc/html/array/array.haddock at .
pkgHaddockFile :: Context -> Action FilePath
-pkgHaddockFile Context {..} = do
+pkgHaddockFile context at Context {..} = do
root <- buildRoot
- version <- pkgSimpleIdentifier package
+ version <- pkgUnitId context package
return $ root -/- "doc/html/libraries" -/- version -/- pkgName package <.> "haddock"
-- | Path to the registered ghc-pkg library file of a given 'Context', e.g.:
@@ -106,7 +106,7 @@ pkgHaddockFile Context {..} = do
pkgRegisteredLibraryFile :: Context -> Action FilePath
pkgRegisteredLibraryFile context at Context {..} = do
libDir <- libPath context
- pkgId <- pkgSimpleIdentifier package
+ pkgId <- pkgUnitId context package
fileName <- pkgRegisteredLibraryFileName context
distDir <- distDir stage
return $ if Dynamic `wayUnit` way
@@ -115,9 +115,9 @@ pkgRegisteredLibraryFile context at Context {..} = do
-- | Just the final filename portion of pkgRegisteredLibraryFile
pkgRegisteredLibraryFileName :: Context -> Action FilePath
-pkgRegisteredLibraryFileName Context{..} = do
+pkgRegisteredLibraryFileName context at Context{..} = do
extension <- libsuf stage way
- pkgFileName package "libHS" extension
+ pkgFileName context package "libHS" extension
-- | Path to the library file of a given 'Context', e.g.:
@@ -137,7 +137,7 @@ pkgGhciLibraryFile context at Context {..} = do
-- | Path to the configuration file of a given 'Context'.
pkgConfFile :: Context -> Action FilePath
pkgConfFile context at Context {..} = do
- pid <- pkgSimpleIdentifier package
+ pid <- pkgUnitId context package
dbPath <- packageDbPath (PackageDbLoc stage iplace)
return $ dbPath -/- pid <.> "conf"
=====================================
hadrian/src/Hadrian/Haskell/Cabal.hs
=====================================
@@ -10,7 +10,7 @@
-- Cabal files.
-----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal (
- pkgVersion, pkgSimpleIdentifier, pkgUnitId, pkgSynopsis, pkgDescription,
+ pkgVersion, pkgUnitId, pkgSynopsis, pkgDescription,
pkgDependencies, pkgGenericDescription, cabalArchString, cabalOsString
) where
@@ -27,18 +27,6 @@ import {-# SOURCE #-} Hadrian.Haskell.Hash (pkgUnitId)
pkgVersion :: Package -> Action String
pkgVersion = fmap version . readPackageData
-
--- | Read a Cabal file and return the package identifier without a hash, e.g. @base-4.10.0.0 at .
--- The Cabal file is tracked.
---
--- For an identifier complete with the hash use 'pkgUnitId'
-pkgSimpleIdentifier :: Package -> Action String
-pkgSimpleIdentifier package = do
- cabal <- readPackageData package
- return $ if null (version cabal)
- then name cabal
- else name cabal ++ "-" ++ version cabal
-
-- | Read a Cabal file and return the package synopsis. The Cabal file is tracked.
pkgSynopsis :: Package -> Action String
pkgSynopsis = fmap synopsis . readPackageData
=====================================
hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
=====================================
@@ -345,7 +345,7 @@ registerPackage rs context = do
pd <- packageDescription <$> readContextData context
db_path <- packageDbPath (PackageDbLoc (stage context) (iplace context))
dist_dir <- Context.buildPath context
- pid <- pkgUnitId context
+ pid <- pkgUnitId context (package context)
-- Note: the @cPath@ is ignored. The path that's used is the 'buildDir' path
-- from the local build info @lbi at .
lbi <- liftIO $ C.getPersistBuildConfig cPath
=====================================
hadrian/src/Hadrian/Haskell/Hash.hs
=====================================
@@ -6,7 +6,7 @@ module Hadrian.Haskell.Hash (pkgUnitId, pkgHashOracle) where
import Development.Shake
-import Hadrian.Haskell.Cabal.Type
+import Hadrian.Haskell.Cabal.Type as C
import Hadrian.Haskell.Cabal
import Hadrian.Oracles.Cabal
import Hadrian.Package
@@ -35,8 +35,9 @@ import Control.Monad
-- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0-abcd at .
-- This needs to be an oracle so it's cached
-pkgUnitId :: Context -> Action String
-pkgUnitId ctx = do
+pkgUnitId :: Context -> Package -> Action String
+pkgUnitId ctx' pkg = do
+ let ctx = ctx'{package = pkg}
pid <- pkgSimpleIdentifier (package ctx)
phash <- pkgHash ctx
-- Other boot packages still hardcode their unit-id to just <name>, but we
@@ -50,6 +51,16 @@ pkgUnitId ctx = do
truncateHash :: Int -> String -> String
truncateHash = take
+-- | Read a Cabal file and return the package identifier without a hash, e.g. @base-4.10.0.0 at .
+-- The Cabal file is tracked.
+--
+-- For an identifier complete with the hash use 'pkgUnitId'
+pkgSimpleIdentifier :: Package -> Action String
+pkgSimpleIdentifier package = do
+ cabal <- readPackageData package
+ return $ if null (version cabal)
+ then C.name cabal
+ else C.name cabal ++ "-" ++ version cabal
data PackageHashInputs = PackageHashInputs {
pkgHashPkgId :: String, -- ^ name-version
@@ -106,7 +117,7 @@ pkgHash = askOracle . PkgHashKey
-- TODO: Needs to be oracle to be cached? Called lots of times
pkgHashOracle :: Rules ()
pkgHashOracle = void $ addOracleCache $ \(PkgHashKey ctx) -> do
- ctx_data <- readContextData ctx
+ -- RECURSIVE ORACLE: ctx_data <- readContextData ctx
pkg_data <- readPackageData (package ctx)
name <- pkgSimpleIdentifier (package ctx)
let stag = stage ctx
@@ -141,8 +152,10 @@ pkgHashOracle = void $ addOracleCache $ \(PkgHashKey ctx) -> do
pkgHashStripLibs = False
pkgHashDebugInfo = undefined
- ghcArgs <- interpret (target ctx (Cabal Setup stag) [] []) flavourArgs
- let pkgHashProgramArgs = Map.singleton "ghc" ghcArgs
+ liftIO $ print "HI"
+ -- ghcArgs <- interpret (target ctx (Cabal Setup stag) [] []) flavourArgs
+ liftIO $ print "HI"
+ let pkgHashProgramArgs = mempty -- Map.singleton "ghc" ghcArgs
pkgHashExtraLibDirs = []
pkgHashExtraLibDirsStatic = []
pkgHashExtraFrameworkDirs = []
=====================================
hadrian/src/Hadrian/Haskell/Hash.hs-boot
=====================================
@@ -1,7 +1,8 @@
module Hadrian.Haskell.Hash where
import Context.Type
+import Hadrian.Package
import Development.Shake
-pkgUnitId :: Context -> Action String
+pkgUnitId :: Context -> Package -> Action String
=====================================
hadrian/src/Rules/BinaryDist.hs
=====================================
@@ -132,7 +132,8 @@ bindistRules = do
version <- setting ProjectVersion
targetPlatform <- setting TargetPlatformFull
distDir <- Context.distDir Stage1
- rtsDir <- pkgSimpleIdentifier rts
+ -- rtsDir <- pkgUnitId (vanillaContext Stage1 rts) rts
+ let rtsDir = "rts"
let ghcBuildDir = root -/- stageString Stage1
bindistFilesDir = root -/- "bindist" -/- ghcVersionPretty
=====================================
hadrian/src/Rules/CabalReinstall.hs
=====================================
@@ -10,7 +10,7 @@ import Utilities
import qualified System.Directory.Extra as IO
import Data.Either
import Rules.BinaryDist
-import Hadrian.Haskell.Cabal (pkgSimpleIdentifier)
+import Hadrian.Haskell.Cabal (pkgUnitId)
import Oracles.Setting
{-
@@ -54,7 +54,8 @@ cabalBuildRules = do
need (lib_targets ++ (map (\(_, p) -> p) (bin_targets ++ iserv_targets)))
distDir <- Context.distDir Stage1
- rtsDir <- pkgSimpleIdentifier rts
+ -- rtsDir <- pkgUnitId (vanillaContext Stage1 rts) rts
+ let rtsDir = "rts"
let ghcBuildDir = root -/- stageString Stage1
rtsIncludeDir = ghcBuildDir -/- "lib" -/- distDir -/- rtsDir
=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -15,7 +15,6 @@ import Oracles.ModuleFiles
import Oracles.Setting
import Hadrian.Haskell.Cabal.Type (PackageData(version))
import Hadrian.Haskell.Cabal
-import Hadrian.Haskell.Hash
import Hadrian.Oracles.Cabal (readPackageData)
import Packages
import Rules.Libffi
@@ -495,7 +494,7 @@ generateConfigHs = do
-- part of the WiringMap, so we don't to go back and forth between the
-- unit-id and the unit-key -- we take care that they are the same by using
-- 'pkgUnitId' to create the unit-id in both situations.
- cProjectUnitId <- expr . pkgUnitId =<< getContext
+ cProjectUnitId <- expr . (`pkgUnitId` ghc) =<< getContext
return $ unlines
[ "module GHC.Settings.Config"
, " ( module GHC.Version"
=====================================
hadrian/src/Rules/Register.hs
=====================================
@@ -183,7 +183,7 @@ buildConfFinal rs context at Context {..} _conf = do
-- so that if any change ends up modifying a library (but not its .conf
-- file), we still rebuild things that depend on it.
dir <- (-/-) <$> libPath context <*> distDir stage
- pkgid <- pkgSimpleIdentifier context
+ pkgid <- pkgUnitId context package
files <- liftIO $
(++) <$> getDirectoryFilesIO "." [dir -/- "*libHS"++pkgid++"*"]
<*> getDirectoryFilesIO "." [dir -/- pkgid -/- "**"]
=====================================
hadrian/src/Settings/Builders/Cabal.hs
=====================================
@@ -86,7 +86,7 @@ commonCabalArgs stage = do
verbosity <- expr getVerbosity
ctx <- getContext
pkg <- getPackage
- package_id <- expr $ pkgSimpleIdentifier pkg
+ package_id <- expr $ pkgUnitId ctx pkg
let prefix = "${pkgroot}" ++ (if windowsHost then "" else "/..")
mconcat [ -- Don't strip libraries when cross compiling.
-- TODO: We need to set @--with-strip=(stripCmdPath :: Action FilePath)@,
=====================================
hadrian/src/Settings/Builders/Ghc.hs
=====================================
@@ -3,7 +3,6 @@
module Settings.Builders.Ghc (ghcBuilderArgs, haddockGhcArgs) where
import Hadrian.Haskell.Cabal
-import Hadrian.Haskell.Hash
import Hadrian.Haskell.Cabal.Type
import Flavour
@@ -15,7 +14,6 @@ import Rules.Libffi (libffiName)
import qualified Data.Set as Set
import System.Directory
import Data.Version.Extra
-import Hadrian.Haskell.Hash
ghcBuilderArgs :: Args
ghcBuilderArgs = mconcat
@@ -262,7 +260,7 @@ packageGhcArgs = do
-- building stage0 because we have a flag in compiler/ghc.cabal.in that is
-- sets `-this-unit-id ghc` when hadrian is building stage0, which will
-- overwrite this one.
- pkgId <- expr $ pkgUnitId ctx
+ pkgId <- expr $ pkgUnitId ctx package
mconcat [ arg "-hide-all-packages"
, arg "-no-user-package-db"
, arg "-package-env -"
=====================================
hadrian/src/Settings/Builders/Haddock.hs
=====================================
@@ -42,7 +42,7 @@ haddockBuilderArgs = mconcat
version <- expr $ pkgVersion pkg
synopsis <- expr $ pkgSynopsis pkg
haddocks <- expr $ haddockDependencies context
- haddocks_with_versions <- expr $ sequence $ [(,h) <$> pkgSimpleIdentifier p | (p, h) <- haddocks]
+ haddocks_with_versions <- expr $ sequence $ [(,h) <$> pkgUnitId context p | (p, h) <- haddocks]
hVersion <- expr $ pkgVersion haddock
statsDir <- expr $ haddockStatsFilesDir
baseUrlTemplate <- expr (docsBaseUrl <$> userSetting defaultDocArgs)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66c4b329fa9c2767779d8b8f392cca5c44b1ff88
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/66c4b329fa9c2767779d8b8f392cca5c44b1ff88
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230320/dda4de32/attachment-0001.html>
More information about the ghc-commits
mailing list