nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 835 lines 39 kB view raw
1This patch is based on https://github.com/sternenseemann/cabal/tree/sterni-cabal-3.16-for-aarch64-darwin and has been created using 2git diff 77afa40961a686d36717604864b4c48ed5233bea eeed4f92625bbe2dbfb57f51d953e3b9a495d884 --patch --src-prefix=a/libraries/Cabal/ --dst-prefix=b/libraries/Cabal/ 3 4Reasoning and explanation of the patch can be found in the comment in the diff for PathsModule.hs below. 5 6diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule.hs 7index 9392acf3c..3417e613a 100644 8--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule.hs 9+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule.hs 10@@ -52,6 +52,7 @@ generatePathsModule pkg_descr lbi clbi = 11 , Z.zIsI386 = buildArch == I386 12 , Z.zIsX8664 = buildArch == X86_64 13 , Z.zIsAArch64 = buildArch == AArch64 14+ , Z.zOr = (||) 15 , Z.zNot = not 16 , Z.zManglePkgName = showPkgName 17 , Z.zPrefix = show flat_prefix 18@@ -61,8 +62,110 @@ generatePathsModule pkg_descr lbi clbi = 19 , Z.zDatadir = zDatadir 20 , Z.zLibexecdir = zLibexecdir 21 , Z.zSysconfdir = zSysconfdir 22+ , -- Sadly we can't be cleverer about this – we can't have literals in the template 23+ Z.zShouldEmitDataDir = shouldEmit "DataDir" 24+ , Z.zShouldEmitLibDir = shouldEmit "LibDir" 25+ , Z.zShouldEmitDynLibDir = shouldEmit "DynLibDir" 26+ , Z.zShouldEmitLibexecDir = shouldEmit "LibexecDir" 27+ , Z.zShouldEmitSysconfDir = shouldEmit "SysconfDir" 28+ , Z.zWarning = zWarning 29+ , Z.zShouldEmitWarning = zShouldEmitWarning 30 } 31 where 32+ -- GHC's NCG backend for aarch64-darwin does not support link-time dead code 33+ -- elimination to the extent that NCG does for other targets. Consequently, 34+ -- we struggle with unnecessarily retained store path references due to the 35+ -- use of `Paths_*` modules – even if `getLibDir` is not used, it'll end up 36+ -- in the final library or executables we build. 37+ -- 38+ -- When using a different output for the executables and library, this 39+ -- becomes more sinister: The library will contain a reference to the bin 40+ -- output and itself due to `getLibDir` and `getBinDir`, but the executables 41+ -- will do so, too. Either due to linking dynamically or because the library 42+ -- is linked statically into the executable and retains those references. 43+ -- Since Nix disallows cyclical references between two outputs, it becomes 44+ -- impossible to use the `Paths_*` module and a separate `bin` output for 45+ -- aarch64-darwin. 46+ -- 47+ -- The solution we have resorted to for now, is to trim the `Paths_*` module 48+ -- dynamically depending on what references *could* be used without causing 49+ -- a cyclical reference. That has the effect that any code that would not 50+ -- cause a cyclical reference with dead code elimination will compile and 51+ -- work for aarch64-darwin. If the code would use a `get*Dir` function that 52+ -- has been omitted, this would indicate that the code would have caused a 53+ -- cyclical reference anyways. 54+ -- 55+ -- The logic for this makes some pretty big assumptions about installation 56+ -- prefixes that probably only hold fully in nixpkgs with 57+ -- `haskellPackages.mkDerivation`. Simple uses outside nixpkgs that have 58+ -- everything below the same prefix should continue to work as expected, 59+ -- though. 60+ -- 61+ -- We assume the following: 62+ -- 63+ -- - flat_prefix is `$out`. 64+ -- - flat_libdir etc. are always below `$out`. 65+ -- 66+ -- Since in the normal case due to static linking `$bin` and `$out` will 67+ -- have the same references in libraries/executables, we need to either 68+ -- prevent usage of `getBinDir` or `getLibDir` to break the cycle in case 69+ -- `flat_bindir` is not below `$out`. We have decided to always allow usage 70+ -- of `getBinDir`, so `getLibDir` gets dropped if a separate `bin` output is 71+ -- used. This has the simple reason that `$out` which contains `flat_libdir` 72+ -- tends to be quite big – we would like to have a `bin` output that doesn't 73+ -- require keeping that around. 74+ pathEmittable :: FilePath -> Bool 75+ pathEmittable p 76+ -- If the executable installation target is below `$out` the reference 77+ -- cycle is within a single output (since libs are installed to `$out`) 78+ -- and thus unproblematic. We can use any and all `get*Dir` functions. 79+ | flat_prefix `isPrefixOf` flat_bindir = True 80+ -- Otherwise, we need to disallow all `get*Dir` functions that would cause 81+ -- a reference to `$out` which contains the libraries that would in turn 82+ -- reference `$bin`. This always include `flat_libdir` and friends, but 83+ -- can also include `flat_datadir` if no separate output for data files is 84+ -- used. 85+ | otherwise = not (flat_prefix `isPrefixOf` p) 86+ 87+ -- This list maps the "name" of the directory to whether we want to include 88+ -- it in the `Paths_*` module or not. `shouldEmit` performs a lookup in this. 89+ dirs :: [(String, Bool)] 90+ dirs = 91+ map 92+ (\(name, path) -> (name, pathEmittable path)) 93+ [ ("LibDir", flat_libdir) 94+ , ("DynLibDir", flat_dynlibdir) 95+ , ("DataDir", flat_datadir) 96+ , ("LibexecDir", flat_libexecdir) 97+ , ("SysconfDir", flat_sysconfdir) 98+ ] 99+ 100+ shouldEmit :: String -> Bool 101+ shouldEmit name = 102+ case lookup name dirs of 103+ Just b -> b 104+ Nothing -> error "panic! BUG in Cabal Paths_ patch for aarch64-darwin, report this at https://github.com/nixos/nixpkgs/issues" 105+ 106+ -- This is a comma separated list of all functions that have been omitted. 107+ -- This is included in a GHC warning which will be attached to the `Paths_*` 108+ -- module in case we are dropping any `get*Dir` functions that would 109+ -- normally exist. 110+ -- 111+ -- TODO: getDataFileName is not accounted for at the moment. 112+ omittedFunctions :: String 113+ omittedFunctions = 114+ intercalate ", " $ 115+ map (("get" ++) . fst) $ 116+ filter (not . snd) dirs 117+ 118+ zWarning :: String 119+ zWarning = 120+ show $ 121+ "The following functions have been omitted by a nixpkgs-specific patch to Cabal: " 122+ ++ omittedFunctions 123+ zShouldEmitWarning :: Bool 124+ zShouldEmitWarning = any (not . snd) dirs 125+ 126 supports_cpp = supports_language_pragma 127 supports_rebindable_syntax = ghc_newer_than (mkVersion [7, 0, 1]) 128 supports_language_pragma = ghc_newer_than (mkVersion [6, 6, 1]) 129diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs 130index 8f33717bb..b89775893 100644 131--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs 132+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs 133@@ -20,6 +20,14 @@ data Z 134 zDatadir :: FilePath, 135 zLibexecdir :: FilePath, 136 zSysconfdir :: FilePath, 137+ zShouldEmitLibDir :: Bool, 138+ zShouldEmitDynLibDir :: Bool, 139+ zShouldEmitLibexecDir :: Bool, 140+ zShouldEmitDataDir :: Bool, 141+ zShouldEmitSysconfDir :: Bool, 142+ zShouldEmitWarning :: Bool, 143+ zWarning :: String, 144+ zOr :: (Bool -> Bool -> Bool), 145 zNot :: (Bool -> Bool), 146 zManglePkgName :: (PackageName -> String)} 147 deriving Generic 148@@ -74,10 +82,51 @@ render z_root = execWriter $ do 149 tell "\n" 150 tell "module Paths_" 151 tell (zManglePkgName z_root (zPackageName z_root)) 152- tell " (\n" 153+ tell "\n" 154+ tell " " 155+ if (zShouldEmitWarning z_root) 156+ then do 157+ tell "{-# WARNING " 158+ tell (zWarning z_root) 159+ tell " #-}" 160+ return () 161+ else do 162+ return () 163+ tell "\n" 164+ tell " (\n" 165 tell " version,\n" 166- tell " getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,\n" 167- tell " getDataFileName, getSysconfDir\n" 168+ tell " getBinDir,\n" 169+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitLibDir z_root)) 170+ then do 171+ tell " getLibDir,\n" 172+ return () 173+ else do 174+ return () 175+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitDynLibDir z_root)) 176+ then do 177+ tell " getDynLibDir,\n" 178+ return () 179+ else do 180+ return () 181+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitLibexecDir z_root)) 182+ then do 183+ tell " getLibexecDir,\n" 184+ return () 185+ else do 186+ return () 187+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitDataDir z_root)) 188+ then do 189+ tell " getDataFileName,\n" 190+ tell " getDataDir,\n" 191+ return () 192+ else do 193+ return () 194+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitSysconfDir z_root)) 195+ then do 196+ tell " getSysconfDir\n" 197+ return () 198+ else do 199+ return () 200 tell " ) where\n" 201 tell "\n" 202 if (zNot z_root (zAbsolute z_root)) 203@@ -126,57 +175,19 @@ render z_root = execWriter $ do 204 tell (zVersionDigits z_root) 205 tell " []\n" 206 tell "\n" 207- tell "-- |If the argument is a filename, the result is the name of a corresponding\n" 208- tell "-- file on the system on which the program is running, if the file were listed\n" 209- tell "-- in the @data-files@ field of the package's Cabal package description file.\n" 210- tell "-- No check is performed that the given filename is listed in that field.\n" 211- tell "getDataFileName :: FilePath -> IO FilePath\n" 212- tell "getDataFileName name = do\n" 213- tell " dir <- getDataDir\n" 214- tell " return (dir `joinFileName` name)\n" 215- tell "\n" 216- tell "-- |The location of the directory specified by Cabal's @--bindir@ option (where\n" 217- tell "-- executables that the user might invoke are installed). This can be overridden\n" 218- tell "-- at runtime using the environment variable " 219- tell (zManglePkgName z_root (zPackageName z_root)) 220- tell "_bindir.\n" 221- tell "getBinDir :: IO FilePath\n" 222- tell "\n" 223- tell "-- |The location of the directory specified by Cabal's @--libdir@ option (where\n" 224- tell "-- object libraries are installed). This can be overridden at runtime using the\n" 225- tell "-- environment variable " 226- tell (zManglePkgName z_root (zPackageName z_root)) 227- tell "_libdir.\n" 228- tell "getLibDir :: IO FilePath\n" 229- tell "\n" 230- tell "-- |The location of the directory specified by Cabal's @--dynlibdir@ option\n" 231- tell "-- (where dynamic libraries are installed). This can be overridden at runtime\n" 232- tell "-- using the environment variable " 233- tell (zManglePkgName z_root (zPackageName z_root)) 234- tell "_dynlibdir.\n" 235- tell "getDynLibDir :: IO FilePath\n" 236- tell "\n" 237- tell "-- |The location of the directory specified by Cabal's @--datadir@ option (where\n" 238- tell "-- architecture-independent data files are installed). This can be overridden at\n" 239- tell "-- runtime using the environment variable " 240- tell (zManglePkgName z_root (zPackageName z_root)) 241- tell "_datadir.\n" 242- tell "getDataDir :: IO FilePath\n" 243- tell "\n" 244- tell "-- |The location of the directory specified by Cabal's @--libexedir@ option\n" 245- tell "-- (where executables that are not expected to be invoked directly by the user\n" 246- tell "-- are installed). This can be overridden at runtime using the environment\n" 247- tell "-- variable " 248- tell (zManglePkgName z_root (zPackageName z_root)) 249- tell "_libexedir.\n" 250- tell "getLibexecDir :: IO FilePath\n" 251- tell "\n" 252- tell "-- |The location of the directory specified by Cabal's @--sysconfdir@ option\n" 253- tell "-- (where configuration files are installed). This can be overridden at runtime\n" 254- tell "-- using the environment variable " 255- tell (zManglePkgName z_root (zPackageName z_root)) 256- tell "_sysconfdir.\n" 257- tell "getSysconfDir :: IO FilePath\n" 258+ if (zOr z_root (zNot z_root (zAbsolute z_root)) (zShouldEmitDataDir z_root)) 259+ then do 260+ tell "-- |If the argument is a filename, the result is the name of a corresponding\n" 261+ tell "-- file on the system on which the program is running, if the file were listed\n" 262+ tell "-- in the @data-files@ field of the package's Cabal package description file.\n" 263+ tell "-- No check is performed that the given filename is listed in that field.\n" 264+ tell "getDataFileName :: FilePath -> IO FilePath\n" 265+ tell "getDataFileName name = do\n" 266+ tell " dir <- getDataDir\n" 267+ tell " return (dir `joinFileName` name)\n" 268+ return () 269+ else do 270+ return () 271 tell "\n" 272 let 273 z_var0_function_defs = do 274@@ -204,6 +215,7 @@ render z_root = execWriter $ do 275 tell "\n" 276 if (zRelocatable z_root) 277 then do 278+ tell "\n" 279 tell "\n" 280 tell "getPrefixDirReloc :: FilePath -> IO FilePath\n" 281 tell "getPrefixDirReloc dirRel = do\n" 282@@ -213,31 +225,68 @@ render z_root = execWriter $ do 283 tell (zBindir z_root) 284 tell ") `joinFileName` dirRel)\n" 285 tell "\n" 286+ tell "-- |The location of the directory specified by Cabal's @--bindir@ option (where\n" 287+ tell "-- executables that the user might invoke are installed). This can be overridden\n" 288+ tell "-- at runtime using the environment variable " 289+ tell (zManglePkgName z_root (zPackageName z_root)) 290+ tell "_bindir.\n" 291+ tell "getBinDir :: IO FilePath\n" 292 tell "getBinDir = catchIO (getEnv \"" 293 tell (zManglePkgName z_root (zPackageName z_root)) 294 tell "_bindir\") (\\_ -> getPrefixDirReloc $ " 295 tell (zBindir z_root) 296 tell ")\n" 297+ tell "-- |The location of the directory specified by Cabal's @--libdir@ option (where\n" 298+ tell "-- object libraries are installed). This can be overridden at runtime using the\n" 299+ tell "-- environment variable " 300+ tell (zManglePkgName z_root (zPackageName z_root)) 301+ tell "_libdir.\n" 302+ tell "getLibDir :: IO FilePath\n" 303 tell "getLibDir = catchIO (getEnv \"" 304 tell (zManglePkgName z_root (zPackageName z_root)) 305 tell "_libdir\") (\\_ -> getPrefixDirReloc $ " 306 tell (zLibdir z_root) 307 tell ")\n" 308+ tell "-- |The location of the directory specified by Cabal's @--dynlibdir@ option\n" 309+ tell "-- (where dynamic libraries are installed). This can be overridden at runtime\n" 310+ tell "-- using the environment variable " 311+ tell (zManglePkgName z_root (zPackageName z_root)) 312+ tell "_dynlibdir.\n" 313+ tell "getDynLibDir :: IO FilePath\n" 314 tell "getDynLibDir = catchIO (getEnv \"" 315 tell (zManglePkgName z_root (zPackageName z_root)) 316 tell "_dynlibdir\") (\\_ -> getPrefixDirReloc $ " 317 tell (zDynlibdir z_root) 318 tell ")\n" 319+ tell "-- |The location of the directory specified by Cabal's @--datadir@ option (where\n" 320+ tell "-- architecture-independent data files are installed). This can be overridden at\n" 321+ tell "-- runtime using the environment variable " 322+ tell (zManglePkgName z_root (zPackageName z_root)) 323+ tell "_datadir.\n" 324+ tell "getDataDir :: IO FilePath\n" 325 tell "getDataDir = catchIO (getEnv \"" 326 tell (zManglePkgName z_root (zPackageName z_root)) 327 tell "_datadir\") (\\_ -> getPrefixDirReloc $ " 328 tell (zDatadir z_root) 329 tell ")\n" 330+ tell "-- |The location of the directory specified by Cabal's @--libexedir@ option\n" 331+ tell "-- (where executables that are not expected to be invoked directly by the user\n" 332+ tell "-- are installed). This can be overridden at runtime using the environment\n" 333+ tell "-- variable " 334+ tell (zManglePkgName z_root (zPackageName z_root)) 335+ tell "_libexedir.\n" 336+ tell "getLibexecDir :: IO FilePath\n" 337 tell "getLibexecDir = catchIO (getEnv \"" 338 tell (zManglePkgName z_root (zPackageName z_root)) 339 tell "_libexecdir\") (\\_ -> getPrefixDirReloc $ " 340 tell (zLibexecdir z_root) 341 tell ")\n" 342+ tell "-- |The location of the directory specified by Cabal's @--sysconfdir@ option\n" 343+ tell "-- (where configuration files are installed). This can be overridden at runtime\n" 344+ tell "-- using the environment variable " 345+ tell (zManglePkgName z_root (zPackageName z_root)) 346+ tell "_sysconfdir.\n" 347+ tell "getSysconfDir :: IO FilePath\n" 348 tell "getSysconfDir = catchIO (getEnv \"" 349 tell (zManglePkgName z_root (zPackageName z_root)) 350 tell "_sysconfdir\") (\\_ -> getPrefixDirReloc $ " 351@@ -251,72 +300,186 @@ render z_root = execWriter $ do 352 if (zAbsolute z_root) 353 then do 354 tell "\n" 355- tell "bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath\n" 356+ tell "bindir :: FilePath\n" 357 tell "bindir = " 358 tell (zBindir z_root) 359 tell "\n" 360- tell "libdir = " 361- tell (zLibdir z_root) 362 tell "\n" 363- tell "dynlibdir = " 364- tell (zDynlibdir z_root) 365+ tell "-- |The location of the directory specified by Cabal's @--bindir@ option (where\n" 366+ tell "-- executables that the user might invoke are installed). This can be overridden\n" 367+ tell "-- at runtime using the environment variable " 368+ tell (zManglePkgName z_root (zPackageName z_root)) 369+ tell "_bindir.\n" 370+ tell "getBinDir :: IO FilePath\n" 371+ tell "getBinDir = catchIO (getEnv \"" 372+ tell (zManglePkgName z_root (zPackageName z_root)) 373+ tell "_bindir\") (\\_ -> return bindir)\n" 374 tell "\n" 375- tell "datadir = " 376- tell (zDatadir z_root) 377+ if (zShouldEmitLibDir z_root) 378+ then do 379+ tell "libdir :: FilePath\n" 380+ tell "libdir = " 381+ tell (zLibdir z_root) 382+ tell "\n" 383+ tell "\n" 384+ tell "-- |The location of the directory specified by Cabal's @--libdir@ option (where\n" 385+ tell "-- object libraries are installed). This can be overridden at runtime using the\n" 386+ tell "-- environment variable " 387+ tell (zManglePkgName z_root (zPackageName z_root)) 388+ tell "_libdir.\n" 389+ tell "getLibDir :: IO FilePath\n" 390+ tell "getLibDir = catchIO (getEnv \"" 391+ tell (zManglePkgName z_root (zPackageName z_root)) 392+ tell "_libdir\") (\\_ -> return libdir)\n" 393+ return () 394+ else do 395+ return () 396 tell "\n" 397- tell "libexecdir = " 398- tell (zLibexecdir z_root) 399+ if (zShouldEmitDynLibDir z_root) 400+ then do 401+ tell "dynlibdir :: FilePath\n" 402+ tell "dynlibdir = " 403+ tell (zDynlibdir z_root) 404+ tell "\n" 405+ tell "-- |The location of the directory specified by Cabal's @--dynlibdir@ option\n" 406+ tell "-- (where dynamic libraries are installed). This can be overridden at runtime\n" 407+ tell "-- using the environment variable " 408+ tell (zManglePkgName z_root (zPackageName z_root)) 409+ tell "_dynlibdir.\n" 410+ tell "getDynLibDir :: IO FilePath\n" 411+ tell "getDynLibDir = catchIO (getEnv \"" 412+ tell (zManglePkgName z_root (zPackageName z_root)) 413+ tell "_dynlibdir\") (\\_ -> return dynlibdir)\n" 414+ return () 415+ else do 416+ return () 417 tell "\n" 418- tell "sysconfdir = " 419- tell (zSysconfdir z_root) 420+ if (zShouldEmitDataDir z_root) 421+ then do 422+ tell "datadir :: FilePath\n" 423+ tell "datadir = " 424+ tell (zDatadir z_root) 425+ tell "\n" 426+ tell "\n" 427+ tell "-- |The location of the directory specified by Cabal's @--datadir@ option (where\n" 428+ tell "-- architecture-independent data files are installed). This can be overridden at\n" 429+ tell "-- runtime using the environment variable " 430+ tell (zManglePkgName z_root (zPackageName z_root)) 431+ tell "_datadir.\n" 432+ tell "getDataDir :: IO FilePath\n" 433+ tell "getDataDir = catchIO (getEnv \"" 434+ tell (zManglePkgName z_root (zPackageName z_root)) 435+ tell "_datadir\") (\\_ -> return datadir)\n" 436+ return () 437+ else do 438+ return () 439 tell "\n" 440+ if (zShouldEmitLibexecDir z_root) 441+ then do 442+ tell "libexecdir :: FilePath\n" 443+ tell "libexecdir = " 444+ tell (zLibexecdir z_root) 445+ tell "\n" 446+ tell "\n" 447+ tell "-- |The location of the directory specified by Cabal's @--libexedir@ option\n" 448+ tell "-- (where executables that are not expected to be invoked directly by the user\n" 449+ tell "-- are installed). This can be overridden at runtime using the environment\n" 450+ tell "-- variable " 451+ tell (zManglePkgName z_root (zPackageName z_root)) 452+ tell "_libexedir.\n" 453+ tell "getLibexecDir :: IO FilePath\n" 454+ tell "getLibexecDir = catchIO (getEnv \"" 455+ tell (zManglePkgName z_root (zPackageName z_root)) 456+ tell "_libexecdir\") (\\_ -> return libexecdir)\n" 457+ return () 458+ else do 459+ return () 460 tell "\n" 461- tell "getBinDir = catchIO (getEnv \"" 462- tell (zManglePkgName z_root (zPackageName z_root)) 463- tell "_bindir\") (\\_ -> return bindir)\n" 464- tell "getLibDir = catchIO (getEnv \"" 465- tell (zManglePkgName z_root (zPackageName z_root)) 466- tell "_libdir\") (\\_ -> return libdir)\n" 467- tell "getDynLibDir = catchIO (getEnv \"" 468- tell (zManglePkgName z_root (zPackageName z_root)) 469- tell "_dynlibdir\") (\\_ -> return dynlibdir)\n" 470- tell "getDataDir = catchIO (getEnv \"" 471- tell (zManglePkgName z_root (zPackageName z_root)) 472- tell "_datadir\") (\\_ -> return datadir)\n" 473- tell "getLibexecDir = catchIO (getEnv \"" 474- tell (zManglePkgName z_root (zPackageName z_root)) 475- tell "_libexecdir\") (\\_ -> return libexecdir)\n" 476- tell "getSysconfDir = catchIO (getEnv \"" 477- tell (zManglePkgName z_root (zPackageName z_root)) 478- tell "_sysconfdir\") (\\_ -> return sysconfdir)\n" 479+ if (zShouldEmitSysconfDir z_root) 480+ then do 481+ tell "sysconfdir :: FilePath\n" 482+ tell "sysconfdir = " 483+ tell (zSysconfdir z_root) 484+ tell "\n" 485+ tell "\n" 486+ tell "-- |The location of the directory specified by Cabal's @--sysconfdir@ option\n" 487+ tell "-- (where configuration files are installed). This can be overridden at runtime\n" 488+ tell "-- using the environment variable " 489+ tell (zManglePkgName z_root (zPackageName z_root)) 490+ tell "_sysconfdir.\n" 491+ tell "getSysconfDir :: IO FilePath\n" 492+ tell "getSysconfDir = catchIO (getEnv \"" 493+ tell (zManglePkgName z_root (zPackageName z_root)) 494+ tell "_sysconfdir\") (\\_ -> return sysconfdir)\n" 495+ return () 496+ else do 497+ return () 498 tell "\n" 499 return () 500 else do 501 if (zIsWindows z_root) 502 then do 503+ tell "\n" 504 tell "\n" 505 tell "prefix :: FilePath\n" 506 tell "prefix = " 507 tell (zPrefix z_root) 508 tell "\n" 509 tell "\n" 510+ tell "-- |The location of the directory specified by Cabal's @--bindir@ option (where\n" 511+ tell "-- executables that the user might invoke are installed). This can be overridden\n" 512+ tell "-- at runtime using the environment variable " 513+ tell (zManglePkgName z_root (zPackageName z_root)) 514+ tell "_bindir.\n" 515+ tell "getBinDir :: IO FilePath\n" 516 tell "getBinDir = getPrefixDirRel $ " 517 tell (zBindir z_root) 518 tell "\n" 519+ tell "-- |The location of the directory specified by Cabal's @--libdir@ option (where\n" 520+ tell "-- object libraries are installed). This can be overridden at runtime using the\n" 521+ tell "-- environment variable " 522+ tell (zManglePkgName z_root (zPackageName z_root)) 523+ tell "_libdir.\n" 524+ tell "getLibDir :: IO FilePath\n" 525 tell "getLibDir = " 526 tell (zLibdir z_root) 527 tell "\n" 528+ tell "-- |The location of the directory specified by Cabal's @--dynlibdir@ option\n" 529+ tell "-- (where dynamic libraries are installed). This can be overridden at runtime\n" 530+ tell "-- using the environment variable " 531+ tell (zManglePkgName z_root (zPackageName z_root)) 532+ tell "_dynlibdir.\n" 533+ tell "getDynLibDir :: IO FilePath\n" 534 tell "getDynLibDir = " 535 tell (zDynlibdir z_root) 536 tell "\n" 537+ tell "-- |The location of the directory specified by Cabal's @--datadir@ option (where\n" 538+ tell "-- architecture-independent data files are installed). This can be overridden at\n" 539+ tell "-- runtime using the environment variable " 540+ tell (zManglePkgName z_root (zPackageName z_root)) 541+ tell "_datadir.\n" 542+ tell "getDataDir :: IO FilePath\n" 543 tell "getDataDir = catchIO (getEnv \"" 544 tell (zManglePkgName z_root (zPackageName z_root)) 545 tell "_datadir\") (\\_ -> " 546 tell (zDatadir z_root) 547 tell ")\n" 548+ tell "-- |The location of the directory specified by Cabal's @--libexedir@ option\n" 549+ tell "-- (where executables that are not expected to be invoked directly by the user\n" 550+ tell "-- are installed). This can be overridden at runtime using the environment\n" 551+ tell "-- variable " 552+ tell (zManglePkgName z_root (zPackageName z_root)) 553+ tell "_libexedir.\n" 554+ tell "getLibexecDir :: IO FilePath\n" 555 tell "getLibexecDir = " 556 tell (zLibexecdir z_root) 557 tell "\n" 558+ tell "-- |The location of the directory specified by Cabal's @--sysconfdir@ option\n" 559+ tell "-- (where configuration files are installed). This can be overridden at runtime\n" 560+ tell "-- using the environment variable " 561+ tell (zManglePkgName z_root (zPackageName z_root)) 562+ tell "_sysconfdir.\n" 563+ tell "getSysconfDir :: IO FilePath\n" 564 tell "getSysconfDir = " 565 tell (zSysconfdir z_root) 566 tell "\n" 567diff --git a/libraries/Cabal/cabal-dev-scripts/src/GenPathsModule.hs b/libraries/Cabal/cabal-dev-scripts/src/GenPathsModule.hs 568index 7c5c947a5..3b7a67498 100644 569--- a/libraries/Cabal/cabal-dev-scripts/src/GenPathsModule.hs 570+++ b/libraries/Cabal/cabal-dev-scripts/src/GenPathsModule.hs 571@@ -42,6 +42,16 @@ $(capture "decls" [d| 572 , zLibexecdir :: FilePath 573 , zSysconfdir :: FilePath 574 575+ , zShouldEmitLibDir :: Bool 576+ , zShouldEmitDynLibDir :: Bool 577+ , zShouldEmitLibexecDir :: Bool 578+ , zShouldEmitDataDir :: Bool 579+ , zShouldEmitSysconfDir :: Bool 580+ 581+ , zShouldEmitWarning :: Bool 582+ , zWarning :: String 583+ 584+ , zOr :: Bool -> Bool -> Bool 585 , zNot :: Bool -> Bool 586 , zManglePkgName :: PackageName -> String 587 } 588diff --git a/libraries/Cabal/templates/Paths_pkg.template.hs b/libraries/Cabal/templates/Paths_pkg.template.hs 589index a9b02b0ef..d99252a29 100644 590--- a/libraries/Cabal/templates/Paths_pkg.template.hs 591+++ b/libraries/Cabal/templates/Paths_pkg.template.hs 592@@ -31,10 +31,31 @@ For further information about Cabal's options for its configuration step, and 593 their default values, see the Cabal User Guide. 594 -} 595 596-module Paths_{{ manglePkgName packageName }} ( 597+module Paths_{{ manglePkgName packageName }} 598+ {% if shouldEmitWarning %}{-# WARNING {{ warning }} #-}{% endif %} 599+ ( 600 version, 601- getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, 602- getDataFileName, getSysconfDir 603+ getBinDir, 604+{# We only care about the absolute case for our emit logic, since only in this 605+ case references are incurred. We are not going to hit isWindows and relocatable 606+ has no absolute references to begin with. 607+#} 608+{% if or (not absolute) shouldEmitLibDir %} 609+ getLibDir, 610+{% endif %} 611+{% if or (not absolute) shouldEmitDynLibDir %} 612+ getDynLibDir, 613+{% endif %} 614+{% if or (not absolute) shouldEmitLibexecDir %} 615+ getLibexecDir, 616+{% endif %} 617+{% if or (not absolute) shouldEmitDataDir %} 618+ getDataFileName, 619+ getDataDir, 620+{% endif %} 621+{% if or (not absolute) shouldEmitSysconfDir %} 622+ getSysconfDir 623+{% endif %} 624 ) where 625 626 {% if not absolute %} 627@@ -73,6 +94,7 @@ catchIO = Exception.catch 628 version :: Version 629 version = Version {{ versionDigits }} [] 630 631+{% if or (not absolute) shouldEmitDataDir %} 632 -- |If the argument is a filename, the result is the name of a corresponding 633 -- file on the system on which the program is running, if the file were listed 634 -- in the @data-files@ field of the package's Cabal package description file. 635@@ -81,37 +103,7 @@ getDataFileName :: FilePath -> IO FilePath 636 getDataFileName name = do 637 dir <- getDataDir 638 return (dir `joinFileName` name) 639- 640--- |The location of the directory specified by Cabal's @--bindir@ option (where 641--- executables that the user might invoke are installed). This can be overridden 642--- at runtime using the environment variable {{ manglePkgName packageName }}_bindir. 643-getBinDir :: IO FilePath 644- 645--- |The location of the directory specified by Cabal's @--libdir@ option (where 646--- object libraries are installed). This can be overridden at runtime using the 647--- environment variable {{ manglePkgName packageName }}_libdir. 648-getLibDir :: IO FilePath 649- 650--- |The location of the directory specified by Cabal's @--dynlibdir@ option 651--- (where dynamic libraries are installed). This can be overridden at runtime 652--- using the environment variable {{ manglePkgName packageName }}_dynlibdir. 653-getDynLibDir :: IO FilePath 654- 655--- |The location of the directory specified by Cabal's @--datadir@ option (where 656--- architecture-independent data files are installed). This can be overridden at 657--- runtime using the environment variable {{ manglePkgName packageName }}_datadir. 658-getDataDir :: IO FilePath 659- 660--- |The location of the directory specified by Cabal's @--libexedir@ option 661--- (where executables that are not expected to be invoked directly by the user 662--- are installed). This can be overridden at runtime using the environment 663--- variable {{ manglePkgName packageName }}_libexedir. 664-getLibexecDir :: IO FilePath 665- 666--- |The location of the directory specified by Cabal's @--sysconfdir@ option 667--- (where configuration files are installed). This can be overridden at runtime 668--- using the environment variable {{ manglePkgName packageName }}_sysconfdir. 669-getSysconfDir :: IO FilePath 670+{% endif %} 671 672 {% defblock function_defs %} 673 minusFileName :: FilePath -> String -> FilePath 674@@ -140,48 +132,155 @@ splitFileName p = (reverse (path2++drive), reverse fname) 675 676 {% if relocatable %} 677 678+{# Relocatable can not incur any absolute references, so we can ignore it. 679+ Additionally, --enable-relocatable is virtually useless in Nix builds 680+#} 681+ 682 getPrefixDirReloc :: FilePath -> IO FilePath 683 getPrefixDirReloc dirRel = do 684 exePath <- getExecutablePath 685 let (dir,_) = splitFileName exePath 686 return ((dir `minusFileName` {{ bindir }}) `joinFileName` dirRel) 687 688+-- |The location of the directory specified by Cabal's @--bindir@ option (where 689+-- executables that the user might invoke are installed). This can be overridden 690+-- at runtime using the environment variable {{ manglePkgName packageName }}_bindir. 691+getBinDir :: IO FilePath 692 getBinDir = catchIO (getEnv "{{ manglePkgName packageName }}_bindir") (\_ -> getPrefixDirReloc $ {{ bindir }}) 693+-- |The location of the directory specified by Cabal's @--libdir@ option (where 694+-- object libraries are installed). This can be overridden at runtime using the 695+-- environment variable {{ manglePkgName packageName }}_libdir. 696+getLibDir :: IO FilePath 697 getLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_libdir") (\_ -> getPrefixDirReloc $ {{ libdir }}) 698+-- |The location of the directory specified by Cabal's @--dynlibdir@ option 699+-- (where dynamic libraries are installed). This can be overridden at runtime 700+-- using the environment variable {{ manglePkgName packageName }}_dynlibdir. 701+getDynLibDir :: IO FilePath 702 getDynLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_dynlibdir") (\_ -> getPrefixDirReloc $ {{ dynlibdir }}) 703+-- |The location of the directory specified by Cabal's @--datadir@ option (where 704+-- architecture-independent data files are installed). This can be overridden at 705+-- runtime using the environment variable {{ manglePkgName packageName }}_datadir. 706+getDataDir :: IO FilePath 707 getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> getPrefixDirReloc $ {{ datadir }}) 708+-- |The location of the directory specified by Cabal's @--libexedir@ option 709+-- (where executables that are not expected to be invoked directly by the user 710+-- are installed). This can be overridden at runtime using the environment 711+-- variable {{ manglePkgName packageName }}_libexedir. 712+getLibexecDir :: IO FilePath 713 getLibexecDir = catchIO (getEnv "{{ manglePkgName packageName }}_libexecdir") (\_ -> getPrefixDirReloc $ {{ libexecdir }}) 714+-- |The location of the directory specified by Cabal's @--sysconfdir@ option 715+-- (where configuration files are installed). This can be overridden at runtime 716+-- using the environment variable {{ manglePkgName packageName }}_sysconfdir. 717+getSysconfDir :: IO FilePath 718 getSysconfDir = catchIO (getEnv "{{ manglePkgName packageName }}_sysconfdir") (\_ -> getPrefixDirReloc $ {{ sysconfdir }}) 719 720 {% useblock function_defs %} 721 722 {% elif absolute %} 723 724-bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath 725+bindir :: FilePath 726 bindir = {{ bindir }} 727-libdir = {{ libdir }} 728-dynlibdir = {{ dynlibdir }} 729-datadir = {{ datadir }} 730-libexecdir = {{ libexecdir }} 731-sysconfdir = {{ sysconfdir }} 732 733+-- |The location of the directory specified by Cabal's @--bindir@ option (where 734+-- executables that the user might invoke are installed). This can be overridden 735+-- at runtime using the environment variable {{ manglePkgName packageName }}_bindir. 736+getBinDir :: IO FilePath 737 getBinDir = catchIO (getEnv "{{ manglePkgName packageName }}_bindir") (\_ -> return bindir) 738+ 739+{% if shouldEmitLibDir %} 740+libdir :: FilePath 741+libdir = {{ libdir }} 742+ 743+-- |The location of the directory specified by Cabal's @--libdir@ option (where 744+-- object libraries are installed). This can be overridden at runtime using the 745+-- environment variable {{ manglePkgName packageName }}_libdir. 746+getLibDir :: IO FilePath 747 getLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_libdir") (\_ -> return libdir) 748+{% endif %} 749+ 750+{% if shouldEmitDynLibDir %} 751+dynlibdir :: FilePath 752+dynlibdir = {{ dynlibdir }} 753+-- |The location of the directory specified by Cabal's @--dynlibdir@ option 754+-- (where dynamic libraries are installed). This can be overridden at runtime 755+-- using the environment variable {{ manglePkgName packageName }}_dynlibdir. 756+getDynLibDir :: IO FilePath 757 getDynLibDir = catchIO (getEnv "{{ manglePkgName packageName }}_dynlibdir") (\_ -> return dynlibdir) 758+{% endif %} 759+ 760+{% if shouldEmitDataDir %} 761+datadir :: FilePath 762+datadir = {{ datadir }} 763+ 764+-- |The location of the directory specified by Cabal's @--datadir@ option (where 765+-- architecture-independent data files are installed). This can be overridden at 766+-- runtime using the environment variable {{ manglePkgName packageName }}_datadir. 767+getDataDir :: IO FilePath 768 getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> return datadir) 769+{% endif %} 770+ 771+{% if shouldEmitLibexecDir %} 772+libexecdir :: FilePath 773+libexecdir = {{ libexecdir }} 774+ 775+-- |The location of the directory specified by Cabal's @--libexedir@ option 776+-- (where executables that are not expected to be invoked directly by the user 777+-- are installed). This can be overridden at runtime using the environment 778+-- variable {{ manglePkgName packageName }}_libexedir. 779+getLibexecDir :: IO FilePath 780 getLibexecDir = catchIO (getEnv "{{ manglePkgName packageName }}_libexecdir") (\_ -> return libexecdir) 781+{% endif %} 782+ 783+{% if shouldEmitSysconfDir %} 784+sysconfdir :: FilePath 785+sysconfdir = {{ sysconfdir }} 786+ 787+-- |The location of the directory specified by Cabal's @--sysconfdir@ option 788+-- (where configuration files are installed). This can be overridden at runtime 789+-- using the environment variable {{ manglePkgName packageName }}_sysconfdir. 790+getSysconfDir :: IO FilePath 791 getSysconfDir = catchIO (getEnv "{{ manglePkgName packageName }}_sysconfdir") (\_ -> return sysconfdir) 792+{% endif %} 793 794 {% elif isWindows %} 795 796+{# We are only trying to fix the problem for aarch64-darwin with this patch, 797+ so let's ignore Windows which we can reach via pkgsCross, for example. 798+#} 799+ 800 prefix :: FilePath 801 prefix = {{ prefix }} 802 803+-- |The location of the directory specified by Cabal's @--bindir@ option (where 804+-- executables that the user might invoke are installed). This can be overridden 805+-- at runtime using the environment variable {{ manglePkgName packageName }}_bindir. 806+getBinDir :: IO FilePath 807 getBinDir = getPrefixDirRel $ {{ bindir }} 808+-- |The location of the directory specified by Cabal's @--libdir@ option (where 809+-- object libraries are installed). This can be overridden at runtime using the 810+-- environment variable {{ manglePkgName packageName }}_libdir. 811+getLibDir :: IO FilePath 812 getLibDir = {{ libdir }} 813+-- |The location of the directory specified by Cabal's @--dynlibdir@ option 814+-- (where dynamic libraries are installed). This can be overridden at runtime 815+-- using the environment variable {{ manglePkgName packageName }}_dynlibdir. 816+getDynLibDir :: IO FilePath 817 getDynLibDir = {{ dynlibdir }} 818+-- |The location of the directory specified by Cabal's @--datadir@ option (where 819+-- architecture-independent data files are installed). This can be overridden at 820+-- runtime using the environment variable {{ manglePkgName packageName }}_datadir. 821+getDataDir :: IO FilePath 822 getDataDir = catchIO (getEnv "{{ manglePkgName packageName }}_datadir") (\_ -> {{ datadir }}) 823+-- |The location of the directory specified by Cabal's @--libexedir@ option 824+-- (where executables that are not expected to be invoked directly by the user 825+-- are installed). This can be overridden at runtime using the environment 826+-- variable {{ manglePkgName packageName }}_libexedir. 827+getLibexecDir :: IO FilePath 828 getLibexecDir = {{ libexecdir }} 829+-- |The location of the directory specified by Cabal's @--sysconfdir@ option 830+-- (where configuration files are installed). This can be overridden at runtime 831+-- using the environment variable {{ manglePkgName packageName }}_sysconfdir. 832+getSysconfDir :: IO FilePath 833 getSysconfDir = {{ sysconfdir }} 834 835 getPrefixDirRel :: FilePath -> IO FilePath