From b408d16b025402cc7c0bf1a298e4808189ebfb96 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 26 Jun 2019 10:10:54 +0100 Subject: [PATCH] Make `debug-info` >= 1 imply library/executable-stripping: False Fixes #2702 If you enable `debug-info` then you also have to stop the libraries and executables being stripped as otherwise the debug symbols are removed. --- Cabal/ChangeLog.md | 2 ++ Cabal/Distribution/Simple/Configure.hs | 25 +++++++++++++++++++++++-- Cabal/Distribution/Simple/Setup.hs | 4 ++-- Cabal/doc/nix-local-build.rst | 6 +++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Cabal/ChangeLog.md b/Cabal/ChangeLog.md index 575cafa95c2..fedb2d5ce8b 100644 --- a/Cabal/ChangeLog.md +++ b/Cabal/ChangeLog.md @@ -32,6 +32,8 @@ add default implementation in terms of `coerce` / `unsafeCoerce`. * Implement support for response file arguments to defaultMain* and cabal-install. * Uniformly provide 'Semigroup' instances for `base < 4.9` via `semigroups` package + * Setting `debug-info` now implies `library-stripping: False` and + `executable-stripping: False) ([#2702](https://github.com/haskell/cabal/issues/2702)) ---- diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index e0fee661d2d..4039a078ff5 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -706,6 +706,27 @@ configure (pkg_descr0, pbi) cfg = do setCoverageLBI <- configureCoverage verbosity cfg comp + + + -- Turn off library and executable stripping when `debug-info` is set + -- to anything other than zero. + let + strip_libexe s f = + let defaultStrip = fromFlagOrDefault True (f cfg) + in case fromFlag (configDebugInfo cfg) of + NoDebugInfo -> return defaultStrip + _ -> case f cfg of + Flag True -> do + warn verbosity $ "Setting debug-info implies " + ++ s ++ "-stripping: False" + return False + + _ -> return False + + strip_lib <- strip_libexe "library" configStripLibs + strip_exe <- strip_libexe "executable" configStripExes + + let reloc = fromFlagOrDefault False $ configRelocatable cfg let buildComponentsMap = @@ -747,8 +768,8 @@ configure (pkg_descr0, pbi) cfg = do configGHCiLib cfg, splitSections = split_sections, splitObjs = split_objs, - stripExes = fromFlag $ configStripExes cfg, - stripLibs = fromFlag $ configStripLibs cfg, + stripExes = strip_exe, + stripLibs = strip_lib, exeCoverage = False, libCoverage = False, withPackageDB = packageDbs, diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 1dc0e10af28..3d1096b155f 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -381,8 +381,8 @@ defaultConfigFlags progDb = emptyConfigFlags { #endif configSplitSections = Flag False, configSplitObjs = Flag False, -- takes longer, so turn off by default - configStripExes = Flag True, - configStripLibs = Flag True, + configStripExes = NoFlag, + configStripLibs = NoFlag, configTests = Flag False, configBenchmarks = Flag False, configCoverage = Flag False, diff --git a/Cabal/doc/nix-local-build.rst b/Cabal/doc/nix-local-build.rst index bf8f9db5898..a4733b28830 100644 --- a/Cabal/doc/nix-local-build.rst +++ b/Cabal/doc/nix-local-build.rst @@ -1424,7 +1424,8 @@ Object code options Not all Haskell implementations generate native binaries. For such implementations this option has no effect. - (TODO: Check what happens if you combine this with ``debug-info``.) + If ``debug-info`` is set explicitly then ``executable-stripping`` is set + to ``False`` as otherwise all the debug symbols will be stripped. The command line variant of this flag is ``--enable-executable-stripping`` and @@ -1440,6 +1441,9 @@ Object code options binary, saving space on the file system. See also ``executable-stripping``. + If ``debug-info`` is set explicitly then ``library-stripping`` is set + to ``False`` as otherwise all the debug symbols will be stripped. + The command line variant of this flag is ``--enable-library-stripping`` and ``--disable-library-stripping``.