diff --git a/Cabal/src/Distribution/Simple/GHC/Internal.hs b/Cabal/src/Distribution/Simple/GHC/Internal.hs index f32b0e34eb3..fe66a74f98a 100644 --- a/Cabal/src/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/src/Distribution/Simple/GHC/Internal.hs @@ -81,10 +81,10 @@ import Distribution.Types.GivenComponent import Distribution.Types.LocalBuildInfo import Distribution.Types.TargetInfo import Distribution.Types.UnitId +import Distribution.Types.Version import Distribution.Utils.NubList (NubListR, toNubListR) import Distribution.Utils.Path import Distribution.Verbosity -import Distribution.Version (Version) import Language.Haskell.Extension import System.Directory (listDirectory) import System.Environment (getEnv) @@ -415,10 +415,19 @@ componentCxxGhcOptions verbosity lbi bi clbi odir filename = MaximalDebugInfo -> ["-g3"] ) ++ cxxOptions bi - , ghcOptCcProgram = - maybeToFlag $ - programPath - <$> lookupProgram gccProgram (withPrograms lbi) + , -- Similarly, you need to add a split for cxx-sources in the configure script. + -- The configure split can be found here: https://github.com/haskell/cabal/pull/10844 + ghcOptGppProgram = + ghcOptionsSince + (mkVersion [9, 4]) + (compiler lbi) + (maybeToFlag $ programPath <$> lookupProgram gppProgram (withPrograms lbi)) + , -- The assumption that the C++ compiler is part of the toolchain is only since ghc-9.4. + ghcOptCcProgram = + ghcOptionsBefore + (mkVersion [9, 4]) + (compiler lbi) + (maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi)) , ghcOptObjDir = toFlag odir , ghcOptExtra = hcOptions GHC bi } @@ -482,6 +491,25 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename = , ghcOptExtra = hcOptions GHC bi } +-- Applies options only if the GHC version is greater than or +-- equal to the given one. +ghcOptionsSince :: Monoid a => Version -> Compiler -> a -> a +ghcOptionsSince ver comp defOptions = + case compilerCompatVersion GHC comp of + Just v + | v >= ver -> defOptions + | otherwise -> mempty + Nothing -> mempty + +-- Applies options only if the GHC version is less than the given one. +ghcOptionsBefore :: Monoid a => Version -> Compiler -> a -> a +ghcOptionsBefore ver comp defOptions = + case compilerCompatVersion GHC comp of + Just v + | v < ver -> defOptions + | otherwise -> mempty + Nothing -> mempty + componentGhcOptions :: VerbosityLevel -> LocalBuildInfo @@ -555,6 +583,22 @@ componentGhcOptions verbosity lbi bi clbi odir = , -- Unsupported extensions have already been checked by configure ghcOptExtensions = toNubListR $ usedExtensions bi , ghcOptExtensionMap = Map.fromList . compilerExtensions $ (compiler lbi) + , -- Use -pgmc to ensure that Cabal always passes cc-options, ld-options to GHC (#4435, #9801) + -- We can only do this on GHC >= 9.4, as we need https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6949 + -- Without that GHC MR, this change would cause GHC to never pass -no-pie when linking, + -- which can cause breakage depending on the C toolchain use. We would have to appropriately + -- pass -pgmc-supports-no-pie as appropriate to avoid this regression. + ghcOptCcProgram = + ghcOptionsSince + (mkVersion [9, 4]) + (compiler lbi) + (maybeToFlag $ programPath <$> lookupProgram gccProgram (withPrograms lbi)) + , -- The assumption that the C++ compiler is part of the toolchain is only since ghc-9.4. + ghcOptGppProgram = + ghcOptionsSince + (mkVersion [9, 4]) + (compiler lbi) + (maybeToFlag $ programPath <$> lookupProgram gppProgram (withPrograms lbi)) } where exe_paths = diff --git a/Cabal/src/Distribution/Simple/Program/GHC.hs b/Cabal/src/Distribution/Simple/Program/GHC.hs index d68ae7af414..9841aa7f2c5 100644 --- a/Cabal/src/Distribution/Simple/Program/GHC.hs +++ b/Cabal/src/Distribution/Simple/Program/GHC.hs @@ -519,7 +519,10 @@ data GhcOptions = GhcOptions , ghcOptFfiIncludes :: NubListR FilePath -- ^ Extra header files to include for old-style FFI; the @ghc -#include@ flag. , ghcOptCcProgram :: Flag FilePath - -- ^ Program to use for the C and C++ compiler; the @ghc -pgmc@ flag. + -- ^ Program to use for the C compiler; the @ghc -pgmc@ flag and also + -- program to use for the C++ compiler before 9.4. + , ghcOptGppProgram :: Flag FilePath + -- ^ Program to use for the C++ compiler; the @ghc -pgmcxx@ flag. , ---------------------------- -- Language and extensions @@ -874,6 +877,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts in [cxxflag ++ opt | opt <- ghcOptCxxOptions opts] , ["-opta" ++ opt | opt <- ghcOptAsmOptions opts] , concat [["-pgmc", cc] | cc <- flag ghcOptCcProgram] + , concat [["-pgmcxx", cxx] | cxx <- flag ghcOptGppProgram] , ----------------- -- Linker stuff diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/Main.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/Main.hs new file mode 100644 index 00000000000..e3da361399f --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/Main.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Foreign.C (CInt (..)) + +foreign import ccall "pgmclib.h meaning_of_life_pgmc" + meaning_of_life_pgmc :: IO CInt + +main :: IO () +main = do + secret <- meaning_of_life_pgmc + -- The value 66 comes from __TESTOPT_PGMC__ - see cc-wrapper.sh. + if (secret == 66) + then putStrLn ("The secret is " ++ show secret) + else error ("Expected value 66, got " ++ show secret) diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/README.md b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/README.md new file mode 100644 index 00000000000..3f5209e81e6 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/README.md @@ -0,0 +1,7 @@ +# ForeignOptsPgmc + +This test case asserts that cabal passes the `-pgmc` GHC option to override the C compiler program. + +The cabal file sets `ghc-options: -pgmc scripts/cc-wrapper.sh`, pointing GHC at a shell script wrapper (`scripts/cc-wrapper.sh`) instead of the system C compiler. The wrapper adds `-D__TESTOPT_PGMC__=66` to every compilation and then delegates to the real `cc`. The C source requires `__TESTOPT_PGMC__` to be defined; if the wrapper is not used as the C compiler, the build fails with a `#error`. + +This test is skipped on Windows (no POSIX shell). diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.out b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.project b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs new file mode 100644 index 00000000000..8c1395ad636 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs @@ -0,0 +1,13 @@ +import Test.Cabal.Prelude + +main = do + skipIfWindows "requires a POSIX shell script as the C compiler wrapper" + -- Use -pgmc to ensure that Cabal always passes cc-options, ld-options to GHC (#4435, #9801) + -- We can only do this on GHC >= 9.4, as we need https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6949 + -- Without that GHC MR, this change would cause GHC to never pass -no-pie when linking, + -- which can cause breakage depending on the C toolchain use. We would have to appropriately + -- pass -pgmc-supports-no-pie as appropriate to avoid this regression. + cabalTest $ recordMode DoNotRecord $ do + skipUnlessGhcVersion ">= 9.4" + cabal "v2-build" ["foreign-opts-pgmc-exe"] + withPlan $ runPlanExe "foreign-opts-pgmc" "foreign-opts-pgmc-exe" [] diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.c b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.c new file mode 100644 index 00000000000..a93cf4961e4 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.c @@ -0,0 +1,9 @@ +#include "pgmclib.h" + +#ifndef __TESTOPT_PGMC__ +#error "Did not get required __TESTOPT_PGMC__ from the -pgmc wrapper" +#endif + +int meaning_of_life_pgmc() { + return __TESTOPT_PGMC__; +} diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.h b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.h new file mode 100644 index 00000000000..1e525fd32bf --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.h @@ -0,0 +1,6 @@ +#ifndef PGMCLIB_H +#define PGMCLIB_H + +int meaning_of_life_pgmc(); + +#endif diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/foreign-opts-pgmc.cabal b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/foreign-opts-pgmc.cabal new file mode 100644 index 00000000000..e8a119c3d36 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/foreign-opts-pgmc.cabal @@ -0,0 +1,12 @@ +cabal-version: 2.2 +name: foreign-opts-pgmc +version: 0.1 +build-type: Simple + +executable foreign-opts-pgmc-exe + main-is: Main.hs + build-depends: base + default-language: Haskell2010 + include-dirs: cbits + c-sources: cbits/pgmclib.c + ghc-options: -pgmc scripts/cc-wrapper.sh diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/scripts/cc-wrapper.sh b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/scripts/cc-wrapper.sh new file mode 100755 index 00000000000..8ef2af63ec1 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/scripts/cc-wrapper.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Wrapper around cc that adds -D__TESTOPT_PGMC__=66 to every compilation. +# Used by the ForeignOptsPgmc test to verify that -pgmc selects this wrapper. +exec cc -D__TESTOPT_PGMC__=66 "$@" diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/Main.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/Main.hs new file mode 100644 index 00000000000..bb7096d2d28 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/Main.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +module Main where + +import Foreign.C (CInt (..)) + +foreign import ccall "pgmcxxlib.h meaning_of_life_pgmcxx" + meaning_of_life_pgmcxx :: IO CInt + +main :: IO () +main = do + secret <- meaning_of_life_pgmcxx + -- The value 67 comes from __TESTOPT_PGMCXX__ - see cxx-wrapper.sh. + if (secret == 67) + then putStrLn ("The secret is " ++ show secret) + else error ("Expected value 67, got " ++ show secret) diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/README.md b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/README.md new file mode 100644 index 00000000000..80b2da68f1a --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/README.md @@ -0,0 +1,7 @@ +# ForeignOptsPgmcxx + +This test case asserts that cabal passes the `-pgmcxx` GHC option to override the C++ compiler program. + +The cabal file sets `ghc-options: -pgmcxx scripts/cxx-wrapper.sh`, pointing GHC at a shell script wrapper (`scripts/cxx-wrapper.sh`) instead of the system C++ compiler. The wrapper adds `-D__TESTOPT_PGMCXX__=67` to every compilation and then delegates to the real `g++`. The C++ source requires `__TESTOPT_PGMCXX__` to be defined; if the wrapper is not used as the C++ compiler, the build fails with a `#error`. + +This test is skipped on Windows (no POSIX shell). diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.out b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.project b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.test.hs b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.test.hs new file mode 100644 index 00000000000..920cb26c90e --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cabal.test.hs @@ -0,0 +1,9 @@ +import Test.Cabal.Prelude + +main = do + skipIfWindows "requires a POSIX shell script as the C++ compiler wrapper" + -- The assumption that the C++ compiler is part of the toolchain is only since ghc-9.4. + cabalTest $ recordMode DoNotRecord $ do + skipUnlessGhcVersion ">= 9.4" + cabal "v2-build" ["foreign-opts-pgmcxx-exe"] + withPlan $ runPlanExe "foreign-opts-pgmcxx" "foreign-opts-pgmcxx-exe" [] diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.cpp b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.cpp new file mode 100644 index 00000000000..f8f50dab32b --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.cpp @@ -0,0 +1,9 @@ +#include "pgmcxxlib.h" + +#ifndef __TESTOPT_PGMCXX__ +#error "Did not get required __TESTOPT_PGMCXX__ from the -pgmcxx wrapper" +#endif + +int meaning_of_life_pgmcxx() { + return __TESTOPT_PGMCXX__; +} diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.h b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.h new file mode 100644 index 00000000000..fea26a8dbbf --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/cxxbits/pgmcxxlib.h @@ -0,0 +1,8 @@ +#ifndef PGMCXXLIB_H +#define PGMCXXLIB_H +extern "C" { + +int meaning_of_life_pgmcxx(); + +} +#endif diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/foreign-opts-pgmcxx.cabal b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/foreign-opts-pgmcxx.cabal new file mode 100644 index 00000000000..4805b91e6f5 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/foreign-opts-pgmcxx.cabal @@ -0,0 +1,15 @@ +cabal-version: 2.2 +name: foreign-opts-pgmcxx +version: 0.1 +build-type: Simple + +executable foreign-opts-pgmcxx-exe + main-is: Main.hs + build-depends: base + default-language: Haskell2010 + include-dirs: cxxbits + -- The following options can be ignore with -pgmcxx by default. + -- Only gcc need stdc++ for C++ code, g++ doesn't need it. + -- extra-libraries: stdc++ + cxx-sources: cxxbits/pgmcxxlib.cpp + ghc-options: -pgmcxx scripts/cxx-wrapper.sh diff --git a/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/scripts/cxx-wrapper.sh b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/scripts/cxx-wrapper.sh new file mode 100755 index 00000000000..a68b2621205 --- /dev/null +++ b/cabal-testsuite/PackageTests/FFI/ForeignOptsPgmcxx/scripts/cxx-wrapper.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Wrapper around g++ that adds -D__TESTOPT_PGMCXX__=67 to every compilation. +# Used by the ForeignOptsPgmcxx test to verify that -pgmcxx selects this wrapper. +exec g++ -D__TESTOPT_PGMCXX__=67 "$@" diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.out new file mode 100644 index 00000000000..4360812ba2e --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.out @@ -0,0 +1,67 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# cabal build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - Complex-0.1.0.0 (lib) (first run) + - Complex-0.1.0.0 (exe:Complex) (first run) +Configuring library for Complex-0.1.0.0... +Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a directory which does not exist. +Preprocessing library for Complex-0.1.0.0... +Building library for Complex-0.1.0.0... +Configuring executable 'Complex' for Complex-0.1.0.0... +Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a directory which does not exist. +Preprocessing executable 'Complex' for Complex-0.1.0.0... +Building executable 'Complex' for Complex-0.1.0.0... +# show-build-info Complex exe:Complex +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-odir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hidir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hiedir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single-2.dist/home/.cabal/store/ghc-/package.db","-package-db","/single-2.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +# cabal build +Up to date +# show-build-info Complex lib +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"lib","name":"lib","unit-id":"Complex-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-odir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hidir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hiedir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/extra-compilation-artifacts/hie","-stubdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-isrc","-idoesnt-exist","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optPsingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single-2.dist/home/.cabal/store/ghc-/package.db","-package-db","/single-2.dist/work/dist/packagedb/ghc-","-package-id","","-XHaskell2010","-Wall"],"modules":["A","B","C","D","Paths_Complex"],"src-files":[],"hs-src-dirs":["src","doesnt-exist"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +# cabal build +Build profile: -w ghc- -O1 +In order, the following will be built: + - criterion-1.1.4.0 (lib) (requires build) + - Complex-0.1.0.0 (bench:complex-benchmarks) (first run) +Configuring library for criterion-1.1.4.0... +Preprocessing library for criterion-1.1.4.0... +Building library for criterion-1.1.4.0... +Installing library in +Configuring benchmark 'complex-benchmarks' for Complex-0.1.0.0... +Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a directory which does not exist. +Preprocessing benchmark 'complex-benchmarks' for Complex-0.1.0.0... +Building benchmark 'complex-benchmarks' for Complex-0.1.0.0... +# show-build-info Complex bench:complex-benchmarks +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"bench","name":"bench:complex-benchmarks","unit-id":"Complex-0.1.0.0-inplace-complex-benchmarks","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-odir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hidir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hiedir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/extra-compilation-artifacts/hie","-stubdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-ibenchmark","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optPsingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-complex-benchmarks","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single-2.dist/home/.cabal/store/ghc-/package.db","-package-db","/single-2.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010","-Wall","-rtsopts","-threaded","-with-rtsopts=-N"],"modules":["Paths_Complex"],"src-files":["Main.hs"],"hs-src-dirs":["benchmark"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +# cabal build +Build profile: -w ghc- -O1 +In order, the following will be built: + - test-framework-0.8.1.1 (lib) (requires build) + - Complex-0.1.0.0 (test:func-test) (first run) +Configuring library for test-framework-0.8.1.1... +Preprocessing library for test-framework-0.8.1.1... +Building library for test-framework-0.8.1.1... +Installing library in +Configuring test suite 'func-test' for Complex-0.1.0.0... +Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a directory which does not exist. +Preprocessing test suite 'func-test' for Complex-0.1.0.0... +Building test suite 'func-test' for Complex-0.1.0.0... +# show-build-info Complex test:func-test +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:func-test","unit-id":"Complex-0.1.0.0-inplace-func-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-odir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hidir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hiedir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/extra-compilation-artifacts/hie","-stubdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-itest","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optPsingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-func-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single-2.dist/home/.cabal/store/ghc-/package.db","-package-db","/single-2.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["FuncMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +# cabal build +Build profile: -w ghc- -O1 +In order, the following will be built: + - another-framework-0.8.1.1 (lib) (requires build) + - Complex-0.1.0.0 (test:unit-test) (first run) +Configuring library for another-framework-0.8.1.1... +Preprocessing library for another-framework-0.8.1.1... +Building library for another-framework-0.8.1.1... +Installing library in +Configuring test suite 'unit-test' for Complex-0.1.0.0... +Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a directory which does not exist. +Preprocessing test suite 'unit-test' for Complex-0.1.0.0... +Building test suite 'unit-test' for Complex-0.1.0.0... +# show-build-info Complex test:unit-test +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:unit-test","unit-id":"Complex-0.1.0.0-inplace-unit-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-odir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hidir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hiedir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/extra-compilation-artifacts/hie","-stubdir","single-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-i","-itest","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-optP-include","-optPsingle-2.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-unit-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single-2.dist/home/.cabal/store/ghc-/package.db","-package-db","/single-2.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["UnitMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.test.hs new file mode 100644 index 00000000000..aee4385bb54 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.test.hs @@ -0,0 +1,75 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Test.Cabal.DecodeShowBuildInfo +import Test.Cabal.Prelude + +main = cabalTest $ do + -- the With GHC-9.2+ output contains -this-unit-id + skipUnlessGhcVersion "^>= 9.2" + withRepo "repo" $ do + runShowBuildInfo ["exe:Complex"] + >> withPlan + ( do + recordBuildInfo "Complex" (exe "Complex") + assertComponent + "Complex" + (exe "Complex") + defCompAssertion + { modules = ["Other", "Paths_Complex"] + , sourceFiles = ["Main.lhs"] + , sourceDirs = ["app"] + } + ) + + runShowBuildInfo ["lib:Complex"] + >> withPlan + ( do + recordBuildInfo "Complex" mainLib + assertComponent + "Complex" + mainLib + defCompAssertion + { modules = ["A", "B", "C", "D", "Paths_Complex"] + , sourceDirs = ["src", "doesnt-exist"] + } + ) + + runShowBuildInfo ["benchmark:complex-benchmarks"] + >> withPlan + ( do + recordBuildInfo "Complex" (bench "complex-benchmarks") + assertComponent + "Complex" + (bench "complex-benchmarks") + defCompAssertion + { modules = ["Paths_Complex"] + , sourceFiles = ["Main.hs"] + , sourceDirs = ["benchmark"] + } + ) + + runShowBuildInfo ["test:func-test"] + >> withPlan + ( do + recordBuildInfo "Complex" (test "func-test") + assertComponent + "Complex" + (test "func-test") + defCompAssertion + { sourceFiles = ["FuncMain.hs"] + , sourceDirs = ["test"] + } + ) + + runShowBuildInfo ["test:unit-test"] + >> withPlan + ( do + recordBuildInfo "Complex" (test "unit-test") + assertComponent + "Complex" + (test "unit-test") + defCompAssertion + { sourceFiles = ["UnitMain.hs"] + , sourceDirs = ["test"] + } + ) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out index 3825d1f6cf8..f95744c876b 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out @@ -15,11 +15,11 @@ Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a director Preprocessing executable 'Complex' for Complex-0.1.0.0... Building executable 'Complex' for Complex-0.1.0.0... # show-build-info Complex exe:Complex -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"exe","name":"exe:Complex","unit-id":"Complex-0.1.0.0-inplace-Complex","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-iapp","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-Complex","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010","-threaded","-rtsopts","-with-rtsopts=-N -T","-Wredundant-constraints"],"modules":["Other","Paths_Complex"],"src-files":["Main.lhs"],"hs-src-dirs":["app"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Up to date # show-build-info Complex lib -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"lib","name":"lib","unit-id":"Complex-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-isrc","-idoesnt-exist","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-XHaskell2010","-Wall"],"modules":["A","B","C","D","Paths_Complex"],"src-files":[],"hs-src-dirs":["src","doesnt-exist"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"lib","name":"lib","unit-id":"Complex-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-isrc","-idoesnt-exist","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-XHaskell2010","-Wall"],"modules":["A","B","C","D","Paths_Complex"],"src-files":[],"hs-src-dirs":["src","doesnt-exist"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: @@ -34,7 +34,7 @@ Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a director Preprocessing benchmark 'complex-benchmarks' for Complex-0.1.0.0... Building benchmark 'complex-benchmarks' for Complex-0.1.0.0... # show-build-info Complex bench:complex-benchmarks -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"bench","name":"bench:complex-benchmarks","unit-id":"Complex-0.1.0.0-inplace-complex-benchmarks","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-ibenchmark","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-complex-benchmarks","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010","-Wall","-rtsopts","-threaded","-with-rtsopts=-N"],"modules":["Paths_Complex"],"src-files":["Main.hs"],"hs-src-dirs":["benchmark"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"bench","name":"bench:complex-benchmarks","unit-id":"Complex-0.1.0.0-inplace-complex-benchmarks","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-ibenchmark","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-complex-benchmarks","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010","-Wall","-rtsopts","-threaded","-with-rtsopts=-N"],"modules":["Paths_Complex"],"src-files":["Main.hs"],"hs-src-dirs":["benchmark"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: @@ -49,7 +49,7 @@ Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a director Preprocessing test suite 'func-test' for Complex-0.1.0.0... Building test suite 'func-test' for Complex-0.1.0.0... # show-build-info Complex test:func-test -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:func-test","unit-id":"Complex-0.1.0.0-inplace-func-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-func-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["FuncMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:func-test","unit-id":"Complex-0.1.0.0-inplace-func-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-func-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["FuncMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} # cabal build Build profile: -w ghc- -O1 In order, the following will be built: @@ -64,4 +64,4 @@ Warning: [unknown-directory] 'hs-source-dirs: doesnt-exist' specifies a director Preprocessing test suite 'unit-test' for Complex-0.1.0.0... Building test suite 'unit-test' for Complex-0.1.0.0... # show-build-info Complex test:unit-test -{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:unit-test","unit-id":"Complex-0.1.0.0-inplace-unit-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen/cabal_macros.h","-this-unit-id","Complex-0.1.0.0-inplace-unit-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["UnitMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} +{"cabal-lib-version":"","compiler":{"flavour":"ghc","compiler-id":"ghc-","path":""},"components":[{"type":"test","name":"test:unit-test","unit-id":"Complex-0.1.0.0-inplace-unit-test","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-odir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hidir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-hiedir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/extra-compilation-artifacts/hie","-stubdir","single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-i","-itest","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-Isingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-optP-include","-optPsingle.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen/cabal_macros.h","-pgmc","","-pgmcxx","","-this-unit-id","Complex-0.1.0.0-inplace-unit-test","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/single.dist/home/.cabal/store/ghc-/package.db","-package-db","/single.dist/work/dist/packagedb/ghc-","-package-id","","-package-id","","-XHaskell2010"],"modules":[],"src-files":["UnitMain.hs"],"hs-src-dirs":["test"],"src-dir":"/","cabal-file":"Complex.cabal"}]} \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs index b4bdc16f0cd..8869461c2e7 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs @@ -1,44 +1,76 @@ {-# LANGUAGE OverloadedStrings #-} -import Test.Cabal.Prelude -import Test.Cabal.DecodeShowBuildInfo + +import Test.Cabal.DecodeShowBuildInfo +import Test.Cabal.Prelude main = cabalTest $ do -- the With GHC-9.2+ output contains -this-unit-id - skipUnlessGhcVersion ">= 9.2" + -- the With GHC-9.4+ output contains -pgmc by default + skipUnlessGhcVersion ">= 9.4" withRepo "repo" $ do - runShowBuildInfo ["exe:Complex"] >> withPlan (do - recordBuildInfo "Complex" (exe "Complex") - assertComponent "Complex" (exe "Complex") defCompAssertion - { modules = ["Other", "Paths_Complex"] - , sourceFiles = ["Main.lhs"] - , sourceDirs = ["app"] - }) + runShowBuildInfo ["exe:Complex"] + >> withPlan + ( do + recordBuildInfo "Complex" (exe "Complex") + assertComponent + "Complex" + (exe "Complex") + defCompAssertion + { modules = ["Other", "Paths_Complex"] + , sourceFiles = ["Main.lhs"] + , sourceDirs = ["app"] + } + ) - runShowBuildInfo ["lib:Complex"] >> withPlan (do - recordBuildInfo "Complex" mainLib - assertComponent "Complex" mainLib defCompAssertion - { modules = ["A", "B", "C", "D", "Paths_Complex"] - , sourceDirs = ["src", "doesnt-exist"] - }) + runShowBuildInfo ["lib:Complex"] + >> withPlan + ( do + recordBuildInfo "Complex" mainLib + assertComponent + "Complex" + mainLib + defCompAssertion + { modules = ["A", "B", "C", "D", "Paths_Complex"] + , sourceDirs = ["src", "doesnt-exist"] + } + ) - runShowBuildInfo ["benchmark:complex-benchmarks"] >> withPlan (do - recordBuildInfo "Complex" (bench "complex-benchmarks") - assertComponent "Complex" (bench "complex-benchmarks") defCompAssertion - { modules = ["Paths_Complex"] - , sourceFiles = ["Main.hs"] - , sourceDirs = ["benchmark"] - }) + runShowBuildInfo ["benchmark:complex-benchmarks"] + >> withPlan + ( do + recordBuildInfo "Complex" (bench "complex-benchmarks") + assertComponent + "Complex" + (bench "complex-benchmarks") + defCompAssertion + { modules = ["Paths_Complex"] + , sourceFiles = ["Main.hs"] + , sourceDirs = ["benchmark"] + } + ) - runShowBuildInfo ["test:func-test"] >> withPlan (do - recordBuildInfo "Complex" (test "func-test") - assertComponent "Complex" (test "func-test") defCompAssertion - { sourceFiles = ["FuncMain.hs"] - , sourceDirs = ["test"] - }) + runShowBuildInfo ["test:func-test"] + >> withPlan + ( do + recordBuildInfo "Complex" (test "func-test") + assertComponent + "Complex" + (test "func-test") + defCompAssertion + { sourceFiles = ["FuncMain.hs"] + , sourceDirs = ["test"] + } + ) - runShowBuildInfo ["test:unit-test"] >> withPlan (do - recordBuildInfo "Complex" (test "unit-test") - assertComponent "Complex" (test "unit-test") defCompAssertion - { sourceFiles = ["UnitMain.hs"] - , sourceDirs = ["test"] - }) + runShowBuildInfo ["test:unit-test"] + >> withPlan + ( do + recordBuildInfo "Complex" (test "unit-test") + assertComponent + "Complex" + (test "unit-test") + defCompAssertion + { sourceFiles = ["UnitMain.hs"] + , sourceDirs = ["test"] + } + ) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Custom/custom.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Custom/custom.test.hs index f8c413c7c5b..182a0338347 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Custom/custom.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Custom/custom.test.hs @@ -1,7 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} -import Test.Cabal.Prelude -import Test.Cabal.DecodeShowBuildInfo -import Control.Monad.Trans.Reader + +import Control.Monad.Trans.Reader +import Test.Cabal.DecodeShowBuildInfo +import Test.Cabal.Prelude main = setupTest $ do -- No cabal test because per-component is broken with it @@ -14,15 +15,18 @@ main = setupTest $ do assertCommonBuildInfo buildInfo let [libBI, exeBI] = components buildInfo - assertComponentPure libBI defCompAssertion - { modules = ["MyLib"] - , compType = "lib" - , sourceDirs = ["src"] - } - - assertComponentPure exeBI defCompAssertion - { sourceFiles = ["Main.hs"] - , compType = "exe" - , sourceDirs = ["app"] - } + assertComponentPure + libBI + defCompAssertion + { modules = ["MyLib"] + , compType = "lib" + , sourceDirs = ["src"] + } + assertComponentPure + exeBI + defCompAssertion + { sourceFiles = ["Main.hs"] + , compType = "exe" + , sourceDirs = ["app"] + } diff --git a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs index c4b45c6f161..da9d19a61b3 100644 --- a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs +++ b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs @@ -125,6 +125,14 @@ normalizeOutput nenv = resub ("\"path\":\"" <> posixRegexEscape (normalizerGhcPath nenv) <> "\"") "\"path\":\"\"" + -- Normalize the C compiler path embedded in -pgmc. + . resub + ("\"-pgmc\",\"[^\"]+\"") + "\"-pgmc\",\"\"" + -- Normalize the C++ compiler path embedded in -pgmcxx. + . resub + ("\"-pgmcxx\",\"[^\"]+\"") + "\"-pgmcxx\",\"\"" -- Remove cabal version output from show-build-info output . resub ("{\"cabal-lib-version\":\"" ++ posixRegexEscape (display (normalizerCabalVersion nenv)) ++ "\"") diff --git a/changelog.d/11713.md b/changelog.d/11713.md new file mode 100644 index 00000000000..04669a05c75 --- /dev/null +++ b/changelog.d/11713.md @@ -0,0 +1,9 @@ +--- +synopsis: Adding an explicit pgmc flag for interaction with GHC +packages: [Cabal] +prs: 11713 +--- + +Added an explicit `pgmc` flag to Cabal's GHC invocation logic. This allows for +reliable and consistent passing of `cc-options`, `ld-options`, and `cpp-options` +to GHC by removing conditional filtering of these arguments. diff --git a/changelog.d/11763.md b/changelog.d/11763.md new file mode 100644 index 00000000000..d0025dcf0cb --- /dev/null +++ b/changelog.d/11763.md @@ -0,0 +1,12 @@ +--- +synopsis: Add explicit `pgmcxx` flag for GHC invocation +packages: [Cabal] +prs: 11763 +--- +Add an explicit `pgmcxx` flag to Cabal's GHC invocation logic. This aligns +with the existing `pgmc` behavior and accounts for the GHC 9.4+ toolchain +requirements, resolving inconsistencies in how C++ compiler options are handled. + +This change allows users to remove `extra-libraries: stdc++` from their +configuration files, as `g++` automatically handles C++ standard library +linking, unlike the legacy approach of invoking C++ via `gcc`.