David Eichmann pushed to branch wip/davide/hadrian_avoid_response_files at Glasgow Haskell Compiler / GHC
Commits:
-
52935fea
by David Eichmann at 2026-05-29T17:19:55+01:00
2 changed files:
Changes:
| ... | ... | @@ -346,7 +346,16 @@ instance H.Builder Builder where |
| 346 | 346 | |
| 347 | 347 | Haddock BuildPackage -> runHaddock path buildArgs buildInputs
|
| 348 | 348 | |
| 349 | - Ghc _ _ -> runGhcWithResponse path buildArgs buildInputs buildOptions
|
|
| 349 | + Ghc _ _ ->
|
|
| 350 | + -- Use a response file for ghc invocations to avoid issues with command line
|
|
| 351 | + -- size limit on Windows (#26637).
|
|
| 352 | + -- Note we can't put the buildArgs in a response file, because some flags require
|
|
| 353 | + -- empty arguments (such as the -dep-suffix flag), but that isn't supported
|
|
| 354 | + -- yet due to #26560.
|
|
| 355 | + withResponseFileOnWindows
|
|
| 356 | + buildInputs
|
|
| 357 | + (escapeArgs buildInputs)
|
|
| 358 | + (\buildInputs' -> cmd [path] buildArgs buildInputs' buildOptions)
|
|
| 350 | 359 | |
| 351 | 360 | HsCpp -> captureStdout
|
| 352 | 361 | |
| ... | ... | @@ -386,23 +395,10 @@ runHaddock :: FilePath -- ^ path to @haddock@ |
| 386 | 395 | -> [String]
|
| 387 | 396 | -> [FilePath] -- ^ input file paths
|
| 388 | 397 | -> Action ()
|
| 389 | -runHaddock haddockPath flagArgs fileInputs = withResponseFile $ \tmp -> do
|
|
| 390 | - writeFile' tmp $ escapeArgs fileInputs
|
|
| 391 | - cmd [haddockPath] flagArgs ('@' : tmp)
|
|
| 392 | - |
|
| 393 | --- | Use a response file for ghc invocations to avoid issues with command line
|
|
| 394 | --- size limit on Windows (#26637).
|
|
| 395 | -runGhcWithResponse :: FilePath -- ^ Path to ghc
|
|
| 396 | - -> [String] -- ^ Arguments passed on the command line
|
|
| 397 | - -> [FilePath] -- ^ Input file paths (passed via response file)
|
|
| 398 | - -> [CmdOption]
|
|
| 399 | - -> Action ()
|
|
| 400 | -runGhcWithResponse ghcPath buildArgs buildInputs buildOptions = withResponseFile $ \tmp -> do
|
|
| 401 | - -- We can't put the buildArgs in a response file, because some flags require
|
|
| 402 | - -- empty arguments (such as the -dep-suffix flag), but that isn't supported
|
|
| 403 | - -- yet due to #26560.
|
|
| 404 | - writeFile' tmp (escapeArgs buildInputs)
|
|
| 405 | - cmd [ghcPath] buildArgs ('@' : tmp) buildOptions
|
|
| 398 | +runHaddock haddockPath flagArgs fileInputs = withResponseFileOnWindows
|
|
| 399 | + fileInputs
|
|
| 400 | + (escapeArgs fileInputs)
|
|
| 401 | + (\fileInputs' -> cmd [haddockPath] flagArgs fileInputs')
|
|
| 406 | 402 | |
| 407 | 403 | -- TODO: Some builders are required only on certain platforms. For example,
|
| 408 | 404 | -- 'Objdump' is only required on OpenBSD and AIX. Add support for platform
|
| ... | ... | @@ -14,7 +14,7 @@ module Hadrian.Utilities ( |
| 14 | 14 | |
| 15 | 15 | -- * Paths
|
| 16 | 16 | BuildRoot (..), buildRoot, buildRootRules, isGeneratedSource,
|
| 17 | - KeepResponseFiles (..), keepResponseFiles, withResponseFile,
|
|
| 17 | + KeepResponseFiles (..), keepResponseFiles, withResponseFile, withResponseFileOnWindows,
|
|
| 18 | 18 | |
| 19 | 19 | -- * File system operations
|
| 20 | 20 | copyFile, copyFileUntracked, createFileLink, fixFile,
|
| ... | ... | @@ -49,7 +49,9 @@ import Development.Shake hiding (Normal) |
| 49 | 49 | import Development.Shake.Classes
|
| 50 | 50 | import Development.Shake.FilePath
|
| 51 | 51 | import System.Environment (lookupEnv)
|
| 52 | +import System.Info.Extra (isWindows)
|
|
| 52 | 53 | import System.IO (hClose, openTempFile)
|
| 54 | +import System.IO.Error (isPermissionError)
|
|
| 53 | 55 | |
| 54 | 56 | import qualified Data.ByteString as BS
|
| 55 | 57 | import qualified Control.Exception.Base as IO
|
| ... | ... | @@ -57,8 +59,7 @@ import qualified Data.HashMap.Strict as Map |
| 57 | 59 | import qualified System.Directory.Extra as IO
|
| 58 | 60 | import qualified System.Info.Extra as IO
|
| 59 | 61 | import qualified System.IO as IO
|
| 60 | -import System.IO.Error (isPermissionError)
|
|
| 61 | -import qualified System.FilePath.Posix as Posix
|
|
| 62 | +import qualified System.FilePath.Posix as Posix
|
|
| 62 | 63 | |
| 63 | 64 | -- | Extract a value from a singleton list, or terminate with an error message
|
| 64 | 65 | -- if the list does not contain exactly one value.
|
| ... | ... | @@ -328,6 +329,23 @@ keepResponseFiles = do |
| 328 | 329 | KeepResponseFiles keep <- userSetting (KeepResponseFiles False)
|
| 329 | 330 | return keep
|
| 330 | 331 | |
| 332 | +-- | Run an action either with command arguments direcly or by, on windows,
|
|
| 333 | +-- placing those arguments into a response file (initialized to some string).
|
|
| 334 | +--
|
|
| 335 | +-- With @--keep-response-files@, the file is left on disk (if used)
|
|
| 336 | +withResponseFileOnWindows ::
|
|
| 337 | + [String] -- ^ Command arguments
|
|
| 338 | + -> String -- ^ Response file content (the command arguments converted to the response file format).
|
|
| 339 | + -> ([String] -> Action a) -- ^ Perform an action with the given command arguments or, on windows, the with the
|
|
| 340 | + -- response file initialized and the passed argument is in the form ["@reponseFilePath"]
|
|
| 341 | + -> Action a
|
|
| 342 | +withResponseFileOnWindows commandArgs responseFileContent action = do
|
|
| 343 | + if isWindows
|
|
| 344 | + then withResponseFile $ \tmp -> do
|
|
| 345 | + writeFile' tmp responseFileContent
|
|
| 346 | + action ['@' : tmp]
|
|
| 347 | + else action commandArgs
|
|
| 348 | + |
|
| 331 | 349 | -- | Run an action with a response file path.
|
| 332 | 350 | --
|
| 333 | 351 | -- With @--keep-response-files@, the file is left on disk.
|