Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass command line arguments to hsc2hs using response files #5553

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
* Foreign libraries are now linked against the threaded RTS when the
'ghc-options: -threaded' flag is used
([#5431](https://github.com/haskell/cabal/pull/5431)).
* Pass command line arguments to `hsc2hs` using response files when possible
([#3122](https://github.com/haskell/cabal/issues/3122)).

----

Expand Down
27 changes: 24 additions & 3 deletions Cabal/Distribution/Simple/PreProcess.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths
import Distribution.Simple.Utils
import Distribution.Simple.Program
import Distribution.Simple.Program.ResponseFile
import Distribution.Simple.Test.LibV09
import Distribution.System
import Distribution.Text
Expand Down Expand Up @@ -392,7 +393,28 @@ ppHsc2hs bi lbi clbi =
platformIndependent = False,
runPreProcessor = mkSimplePreProcessor $ \inFile outFile verbosity -> do
(gccProg, _) <- requireProgram verbosity gccProgram (withPrograms lbi)
runDbProgram verbosity hsc2hsProgram (withPrograms lbi) $
(hsc2hsProg, hsc2hsVersion, _) <- requireProgramVersion verbosity
hsc2hsProgram anyVersion (withPrograms lbi)
-- See Trac #13896 and https://github.com/haskell/cabal/issues/3122.
let hsc2hsSupportsResponseFiles = hsc2hsVersion >= mkVersion [0,68,4]
pureArgs = genPureArgs gccProg inFile outFile
if hsc2hsSupportsResponseFiles
then withResponseFile
verbosity
defaultTempFileOptions
(takeDirectory outFile)
"hsc2hs-response.txt"
Nothing
pureArgs
(\responseFileName ->
runProgram verbosity hsc2hsProg ["@"++ responseFileName])
else runProgram verbosity hsc2hsProg pureArgs
}
where
-- Returns a list of command line arguments that can either be passed
-- directly, or via a response file.
genPureArgs :: ConfiguredProgram -> String -> String -> [String]
genPureArgs gccProg inFile outFile =
[ "--cc=" ++ programPath gccProg
, "--ld=" ++ programPath gccProg ]

Expand Down Expand Up @@ -456,8 +478,7 @@ ppHsc2hs bi lbi clbi =
++ [ "-l" ++ opt | opt <- Installed.extraLibraries pkg ]
++ [ opt | opt <- Installed.ldOptions pkg ] ]
++ ["-o", outFile, inFile]
}
where

hacked_index = packageHacks (installedPkgs lbi)
-- Look only at the dependencies of the current component
-- being built! This relies on 'installedPkgs' maintaining
Expand Down