From 4fc7f042f8e74ef8541b00b6d202603f8fdd4b66 Mon Sep 17 00:00:00 2001 From: Fendor Date: Thu, 8 Jul 2021 11:04:39 +0200 Subject: [PATCH] Re-design test-cases for show-build-info --- .../Configure/include/HsZlibConfig.h.in | 10 +- .../PackageTests/ShowBuildInfo/A/A.cabal | 23 +++ .../PackageTests/ShowBuildInfo/A/B/B.cabal | 10 ++ .../PackageTests/ShowBuildInfo/A/B/lib/B.hs | 4 + .../ShowBuildInfo/A/build-info-all.out | 21 +++ .../ShowBuildInfo/A/build-info-all.test.hs | 28 +++ .../ShowBuildInfo/A/build-info-exe.out | 8 + .../ShowBuildInfo/A/build-info-exe.test.hs | 14 ++ .../ShowBuildInfo/A/cabal.project | 1 + .../PackageTests/ShowBuildInfo/A/src/A.hs | 3 + .../PackageTests/ShowBuildInfo/A/src/Main.hs | 3 + .../PackageTests/ShowBuildInfo/A/src/Test.hs | 4 + .../ShowBuildInfo/Complex/Complex.cabal | 72 ++++++++ .../ShowBuildInfo/Complex/app/Main.lhs | 8 + .../ShowBuildInfo/Complex/app/Other.hs | 3 + .../ShowBuildInfo/Complex/benchmark/Main.hs | 3 + .../ShowBuildInfo/Complex/cabal.project | 4 + .../another-framework.cabal | 8 + .../repo/criterion-1.1.4.0/criterion.cabal | 8 + .../test-framework.cabal | 8 + .../ShowBuildInfo/Complex/single.out | 70 ++++++++ .../ShowBuildInfo/Complex/single.test.hs | 41 +++++ .../ShowBuildInfo/Complex/src/A.hs | 5 + .../ShowBuildInfo/Complex/src/B.hs | 3 + .../ShowBuildInfo/Complex/src/C.hs | 5 + .../ShowBuildInfo/Complex/src/D.hs | 5 + .../ShowBuildInfo/Complex/test/FuncMain.hs | 1 + .../ShowBuildInfo/Complex/test/UnitMain.hs | 1 + cabal-testsuite/cabal-testsuite.cabal | 1 + .../src/Test/Cabal/DecodeShowBuildInfo.hs | 160 ++++++++++++++++++ cabal-testsuite/src/Test/Cabal/Monad.hs | 13 +- .../src/Test/Cabal/OutputNormalizer.hs | 20 +++ cabal-testsuite/src/Test/Cabal/Plan.hs | 25 ++- 33 files changed, 587 insertions(+), 6 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/B/B.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/B/lib/B.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/src/A.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Main.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Main.lhs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Other.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/benchmark/Main.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/another-framework-0.8.1.1/another-framework.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/criterion-1.1.4.0/criterion.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/A.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/B.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/C.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/D.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/FuncMain.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/UnitMain.hs create mode 100644 cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs diff --git a/cabal-testsuite/PackageTests/Configure/include/HsZlibConfig.h.in b/cabal-testsuite/PackageTests/Configure/include/HsZlibConfig.h.in index aa500c7d2ce..b276a09c56f 100644 --- a/cabal-testsuite/PackageTests/Configure/include/HsZlibConfig.h.in +++ b/cabal-testsuite/PackageTests/Configure/include/HsZlibConfig.h.in @@ -3,12 +3,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H @@ -45,5 +45,7 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #undef STDC_HEADERS diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal new file mode 100644 index 00000000000..a1420d9676e --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal @@ -0,0 +1,23 @@ +cabal-version: 2.4 +name: A +version: 0.1.0.0 +license: BSD-3-Clause + +library + exposed-modules: A + build-depends: base >=4 + hs-source-dirs: src + default-language: Haskell2010 + +executable A + main-is: Main.hs + build-depends: base >=4 + hs-source-dirs: src + default-language: Haskell2010 + +test-suite A-tests + type: exitcode-stdio-1.0 + main-is: Test.hs + build-depends: base >=4, A + hs-source-dirs: src + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/B.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/B.cabal new file mode 100644 index 00000000000..e81b9eb3a1d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/B.cabal @@ -0,0 +1,10 @@ +cabal-version: 2.4 +name: B +version: 0.1.0.0 +license: BSD-3-Clause + +library + exposed-modules: B + build-depends: base >=4.0.0.0, A + hs-source-dirs: lib + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/lib/B.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/lib/B.hs new file mode 100644 index 00000000000..8b74dfe6b43 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/B/lib/B.hs @@ -0,0 +1,4 @@ +module B where + +foo :: Int -> Int +foo = id diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.out new file mode 100644 index 00000000000..b7dc59e7f5f --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.out @@ -0,0 +1,21 @@ +# cabal build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - A-0.1.0.0 (lib) (first run) + - A-0.1.0.0 (exe:A) (first run) + - B-0.1.0.0 (lib) (first run) + - A-0.1.0.0 (test:A-tests) (first run) +Configuring library for A-0.1.0.0.. +Preprocessing library for A-0.1.0.0.. +Building library for A-0.1.0.0.. +Configuring executable 'A' for A-0.1.0.0.. +Preprocessing executable 'A' for A-0.1.0.0.. +Building executable 'A' for A-0.1.0.0.. +Configuring library for B-0.1.0.0.. +Preprocessing library for B-0.1.0.0.. +Building library for B-0.1.0.0.. +Configuring test suite 'A-tests' for A-0.1.0.0.. +Warning: The package has an extraneous version range for a dependency on an internal library: A >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. +Preprocessing test suite 'A-tests' for A-0.1.0.0.. +Building test suite 'A-tests' for A-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.test.hs new file mode 100644 index 00000000000..8fdc04e7a2a --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-all.test.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} +import Test.Cabal.Prelude +import Test.Cabal.DecodeShowBuildInfo + +main = cabalTest $ do + runShowBuildInfo ["all", "--enable-tests"] + withPlan $ do + assertComponent "A" (exe "A") + defCompAssertion + { sourceFiles = ["Main.hs"] + , sourceDirs = ["src"] + } + assertComponent "A" mainLib + defCompAssertion + { modules = ["A"] + , sourceDirs = ["src"] + } + + assertComponent "B" mainLib + defCompAssertion + { modules = ["B"] + , sourceDirs = ["lib"] + } + assertComponent "A" (test "A-tests") + defCompAssertion + { sourceFiles = ["Test.hs"] + , sourceDirs = ["src"] + } diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out new file mode 100644 index 00000000000..9a6b8886d87 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out @@ -0,0 +1,8 @@ +# cabal build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - A-0.1.0.0 (exe:A) (first run) +Configuring executable 'A' for A-0.1.0.0.. +Preprocessing executable 'A' for A-0.1.0.0.. +Building executable 'A' for A-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs new file mode 100644 index 00000000000..a27bf2d8167 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE OverloadedStrings #-} +import Test.Cabal.Prelude +import Test.Cabal.DecodeShowBuildInfo + +main = cabalTest $ do + runShowBuildInfo ["exe:A"] + withPlan $ do + assertComponent "A" (exe "A") + defCompAssertion + { sourceFiles = ["Main.hs"] + , sourceDirs = ["src"] + -- does not list lib as a target + , compilerArgsPred = all (/= "A-0.1.0.0-inplace") + } diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project new file mode 100644 index 00000000000..9a091f69b3b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project @@ -0,0 +1 @@ +packages: . ./B/ diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/A.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/A.hs new file mode 100644 index 00000000000..2ec6a4f2188 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/A.hs @@ -0,0 +1,3 @@ +module A where + +foo = 2 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Main.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Main.hs new file mode 100644 index 00000000000..de106fe48f9 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Main.hs @@ -0,0 +1,3 @@ +module Main where + +main = return () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Test.hs new file mode 100644 index 00000000000..d82a4bd93b7 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Test.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = return () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal new file mode 100644 index 00000000000..d8ea0a46eca --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -0,0 +1,72 @@ +cabal-version: 2.4 +name: Complex +version: 0.1.0.0 +license: MIT + +library + build-depends: base + hs-source-dirs: src doesnt-exist + default-language: Haskell2010 + exposed-modules: + A + B + + autogen-modules: Paths_Complex + other-modules: + C + D + Paths_Complex + + ghc-options: -Wall + +executable Complex + main-is: Main.lhs + build-depends: + , base + , Complex + + hs-source-dirs: app + autogen-modules: Paths_Complex + other-modules: + Other + Paths_Complex + + ghc-options: + -threaded -rtsopts "-with-rtsopts=-N -T" -Wredundant-constraints + + default-language: Haskell2010 + +test-suite unit-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + build-depends: + , another-framework + , base + + main-is: UnitMain.hs + default-language: Haskell2010 + +test-suite func-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + build-depends: + , base + , Complex + , test-framework + + main-is: FuncMain.hs + default-language: Haskell2010 + +benchmark complex-benchmarks + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: Paths_Complex + autogen-modules: Paths_Complex + hs-source-dirs: benchmark + ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N + build-depends: + , base + , Complex + , criterion ^>=1.1.4 + + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Main.lhs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Main.lhs new file mode 100644 index 00000000000..6f482ce0695 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Main.lhs @@ -0,0 +1,8 @@ +> module Main where +> +> import A +> import Other +> +> main = do +> print foo +> print bar diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Other.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Other.hs new file mode 100644 index 00000000000..5d0685b1815 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/app/Other.hs @@ -0,0 +1,3 @@ +module Other where + +bar = () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/benchmark/Main.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/benchmark/Main.hs new file mode 100644 index 00000000000..7753bcff18c --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/benchmark/Main.hs @@ -0,0 +1,3 @@ +module Main where + +main = pure () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project new file mode 100644 index 00000000000..a40dbcbdd1e --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project @@ -0,0 +1,4 @@ +packages: . + +tests: True +benchmarks: True diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/another-framework-0.8.1.1/another-framework.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/another-framework-0.8.1.1/another-framework.cabal new file mode 100644 index 00000000000..173443e1906 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/another-framework-0.8.1.1/another-framework.cabal @@ -0,0 +1,8 @@ +name: another-framework +version: 0.8.1.1 +build-type: Simple +cabal-version: >= 1.10 + +library + build-depends: base + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/criterion-1.1.4.0/criterion.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/criterion-1.1.4.0/criterion.cabal new file mode 100644 index 00000000000..e7cdc916530 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/criterion-1.1.4.0/criterion.cabal @@ -0,0 +1,8 @@ +name: criterion +version: 1.1.4.0 +build-type: Simple +cabal-version: >= 1.10 + +library + build-depends: base, ghc-prim + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal new file mode 100644 index 00000000000..2235e2eeb39 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal @@ -0,0 +1,8 @@ +name: test-framework +version: 0.8.1.1 +build-type: Simple +cabal-version: >= 1.10 + +library + build-depends: base + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out new file mode 100644 index 00000000000..fb62cdec657 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out @@ -0,0 +1,70 @@ +# 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: 'hs-source-dirs: doesnt-exist' directory 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: The package has an extraneous version range for a dependency on an internal library: Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. +Warning: 'hs-source-dirs: doesnt-exist' directory 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-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","-stubdir","/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-i","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-iapp","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build","-optP-include","-optP/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/x/Complex/build/Complex/autogen/cabal_macros.h","-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-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","-stubdir","/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-i","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-isrc","-idoesnt-exist","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/build","-optP-include","-optP/single.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 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: The package has an extraneous version range for a dependency on an internal library: Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. +Warning: 'hs-source-dirs: doesnt-exist' directory 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-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","-stubdir","/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-i","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-ibenchmark","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build","-optP-include","-optP/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/b/complex-benchmarks/build/complex-benchmarks/autogen/cabal_macros.h","-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: + - 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: The package has an extraneous version range for a dependency on an internal library: Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0, Complex >=0 && ==0.1.0.0. This version range includes the current package but isn't needed as the current package's library will always be used. +Warning: 'hs-source-dirs: doesnt-exist' directory 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-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","-stubdir","/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-i","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-itest","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build","-optP-include","-optP/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/func-test/build/func-test/autogen/cabal_macros.h","-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: + - 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: 'hs-source-dirs: doesnt-exist' directory 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-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","-stubdir","/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-i","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-itest","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-i/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/global-autogen","-I/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build","-optP-include","-optP/single.dist/work/./dist/build//ghc-/Complex-0.1.0.0/t/unit-test/build/unit-test/autogen/cabal_macros.h","-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"}]} diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs new file mode 100644 index 00000000000..6e4067554ce --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE OverloadedStrings #-} +import Test.Cabal.Prelude +import Test.Cabal.DecodeShowBuildInfo + +main = cabalTest $ withRepo "repo" $ do + runShowBuildInfo ["exe:Complex"] >> withPlan (do + traceBuildInfo "Complex" (exe "Complex") + assertComponent "Complex" (exe "Complex") defCompAssertion + { modules = ["Other", "Paths_Complex"] + , sourceFiles = ["Main.lhs"] + , sourceDirs = ["app"] + }) + + runShowBuildInfo ["lib:Complex"] >> withPlan (do + traceBuildInfo "Complex" mainLib + assertComponent "Complex" mainLib defCompAssertion + { modules = ["A", "B", "C", "D", "Paths_Complex"] + , sourceDirs = ["src", "doesnt-exist"] + }) + + runShowBuildInfo ["benchmark:complex-benchmarks"] >> withPlan (do + traceBuildInfo "Complex" (bench "complex-benchmarks") + assertComponent "Complex" (bench "complex-benchmarks") defCompAssertion + { modules = ["Paths_Complex"] + , sourceFiles = ["Main.hs"] + , sourceDirs = ["benchmark"] + }) + + runShowBuildInfo ["test:func-test"] >> withPlan (do + traceBuildInfo "Complex" (test "func-test") + assertComponent "Complex" (test "func-test") defCompAssertion + { sourceFiles = ["FuncMain.hs"] + , sourceDirs = ["test"] + }) + + runShowBuildInfo ["test:unit-test"] >> withPlan (do + traceBuildInfo "Complex" (test "unit-test") + assertComponent "Complex" (test "unit-test") defCompAssertion + { sourceFiles = ["UnitMain.hs"] + , sourceDirs = ["test"] + }) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/A.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/A.hs new file mode 100644 index 00000000000..18032f68988 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/A.hs @@ -0,0 +1,5 @@ +module A where + +import D + +foo = d diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/B.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/B.hs new file mode 100644 index 00000000000..93b0222a65d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/B.hs @@ -0,0 +1,3 @@ +module B where + +b = 1 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/C.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/C.hs new file mode 100644 index 00000000000..419eb7eca64 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/C.hs @@ -0,0 +1,5 @@ +module C where + +import B + +c = b diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/D.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/D.hs new file mode 100644 index 00000000000..d9be40b5ba2 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/D.hs @@ -0,0 +1,5 @@ +module D where + +import C + +d = c diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/FuncMain.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/FuncMain.hs new file mode 100644 index 00000000000..b3549c2fe3d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/FuncMain.hs @@ -0,0 +1 @@ +main = return () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/UnitMain.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/UnitMain.hs new file mode 100644 index 00000000000..b3549c2fe3d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/UnitMain.hs @@ -0,0 +1 @@ +main = return () diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index 46f111e0c94..322175f9d75 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -39,6 +39,7 @@ library hs-source-dirs: src exposed-modules: Test.Cabal.CheckArMetadata + Test.Cabal.DecodeShowBuildInfo Test.Cabal.Monad Test.Cabal.OutputNormalizer Test.Cabal.Plan diff --git a/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs b/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs new file mode 100644 index 00000000000..0c0fab70175 --- /dev/null +++ b/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs @@ -0,0 +1,160 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE RecordWildCards #-} +module Test.Cabal.DecodeShowBuildInfo where + +import Test.Cabal.Prelude +import Test.Cabal.Plan +import Distribution.Text (display) +import Distribution.Types.ComponentName +import Distribution.Types.LibraryName +import Distribution.Types.UnqualComponentName +import Distribution.Package +import Distribution.Pretty (prettyShow) +import Control.Monad.Trans.Reader +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Stack.Types +import GHC.Generics +import System.Exit + +-- | Run 'show-build-info' silencing all output using '-v0'. +-- This is necessary to make sure no stray output from 'show-build-info' makes +-- parsing impossible. +runShowBuildInfo :: [String] -> TestM () +runShowBuildInfo args = cabal "build" ("--enable-dump-buildinfo":args) + +decodeShowBuildInfo :: String -> TestM BuildInfo +decodeShowBuildInfo s = case eitherDecodeStrict (T.encodeUtf8 $ T.pack s) of + Left err -> fail $ "Could not parse show-build-info command: " ++ err + Right buildInfos -> return buildInfos + +traceBuildInfo :: PackageName -> ComponentName -> TestM () +traceBuildInfo pkgName cname = do + Just plan <- testPlan <$> ask + let fp = buildInfoFile plan pkgName cname + recordMode RecordAll $ do + recordHeader ["show-build-info", prettyShow pkgName, prettyShow cname] + buildInfo <- liftIO $ readFile fp + recordLog $ Result ExitSuccess "build --enable-dump-buildinfo" buildInfo + +decodeBuildInfoFile :: FilePath -> TestM BuildInfo +decodeBuildInfoFile fp = do + shouldExist fp + res <- liftIO $ eitherDecodeFileStrict fp + case res of + Left err -> fail $ "Could not parse show-build-info file: " ++ err + Right buildInfos -> return buildInfos + +data BuildInfo = BuildInfo + { cabalVersion :: String + , compiler :: CompilerInfo + , components :: [ComponentInfo] + } deriving (Generic, Show) + +data CompilerInfo = CompilerInfo + { flavour :: String + , compilerId :: String + , path :: String + } deriving (Generic, Show) + +data ComponentInfo = ComponentInfo + { componentType :: String + , componentName :: String + , componentUnitId :: String + , componentCompilerArgs :: [String] + , componentModules :: [String] + , componentSrcFiles :: [FilePath] + , componentHsSrcDirs :: [FilePath] + , componentSrcDir :: FilePath + } deriving (Generic, Show) + +instance ToJSON BuildInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON BuildInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = camelTo2 '-' } + +instance ToJSON CompilerInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON CompilerInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = camelTo2 '-' } + +instance ToJSON ComponentInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON ComponentInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = drop 10 . camelTo2 '-' } + +-- ----------------------------------------------------------- +-- Assertion Helpers to define succinct test cases +-- ----------------------------------------------------------- + +data ComponentAssertion = ComponentAssertion + { unitIdPred :: (String -> Bool) + , compilerArgsPred :: ([String] -> Bool) + , modules :: [String] + , sourceFiles :: [FilePath] + , sourceDirs :: [FilePath] + } + +defCompAssertion :: ComponentAssertion +defCompAssertion = ComponentAssertion + { unitIdPred = not . null + , compilerArgsPred = not . null + , modules = [] + , sourceFiles = [] + , sourceDirs = [] + } + +assertCommonBuildInfo :: HasCallStack => BuildInfo -> TestM () +assertCommonBuildInfo buildInfo = do + assertEqual "Cabal Version" (display cabalVersionLibrary) (cabalVersion buildInfo) + assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) + assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) + assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) + +assertComponent :: HasCallStack => PackageName -> ComponentName -> ComponentAssertion -> TestM () +assertComponent pkgName cname ComponentAssertion {..} = do + Just plan <- testPlan <$> ask + let fp = buildInfoFile plan pkgName cname + buildInfo <- decodeBuildInfoFile fp + assertCommonBuildInfo buildInfo + + let component = findComponentInfo cname buildInfo + + assertEqual "Component type" (compTypeStr cname) (componentType component) + assertBool "Component Unit Id" (unitIdPred $ componentUnitId component) + assertBool "Component compiler args" (compilerArgsPred $ componentCompilerArgs component) + assertEqual "Component modules" modules (componentModules component) + assertEqual "Component source files" sourceFiles (componentSrcFiles component) + assertEqual "Component source directories" sourceDirs (componentHsSrcDirs component) + where + compTypeStr :: ComponentName -> String + compTypeStr (CLibName _) = "lib" + compTypeStr (CFLibName _) = "flib" + compTypeStr (CExeName _) = "exe" + compTypeStr (CTestName _) = "test" + compTypeStr (CBenchName _) = "bench" + +findComponentInfo :: ComponentName -> BuildInfo -> ComponentInfo +findComponentInfo cname buildInfo = + case filter (\c -> prettyShow cname == componentName c) (components buildInfo) of + [x] -> x + [] -> error $ "findComponentInfo: component " ++ prettyShow cname ++ " does not" + ++ " exist in build info-file" + _ -> error $ "findComponentInfo: found multiple copies of component " ++ prettyShow cname + ++ " in build info plan" + +exe :: String -> ComponentName +exe = CExeName . mkUnqualComponentName + +lib :: String -> ComponentName +lib = CLibName . LSubLibName . mkUnqualComponentName + +test :: String -> ComponentName +test = CTestName . mkUnqualComponentName + +bench :: String -> ComponentName +bench = CBenchName . mkUnqualComponentName + +mainLib :: ComponentName +mainLib = CLibName LMainLibName diff --git a/cabal-testsuite/src/Test/Cabal/Monad.hs b/cabal-testsuite/src/Test/Cabal/Monad.hs index c320282c301..4a216b4b602 100644 --- a/cabal-testsuite/src/Test/Cabal/Monad.hs +++ b/cabal-testsuite/src/Test/Cabal/Monad.hs @@ -47,6 +47,8 @@ module Test.Cabal.Monad ( CommonArgs(..), renderCommonArgs, commonArgParser, + -- * Version Constants + cabalVersionLibrary, ) where import Test.Cabal.Script @@ -62,9 +64,11 @@ import Distribution.Simple.Program.Db import Distribution.Simple.Program import Distribution.Simple.Configure ( configCompilerEx ) +import qualified Distribution.Simple.Utils as U (cabalVersion) import Distribution.Text import Distribution.Verbosity +import Distribution.Version import Data.Monoid ((<>), mempty) import qualified Control.Exception as E @@ -398,6 +402,7 @@ mkNormalizerEnv = do list_out <- liftIO $ readProcess (programPath ghc_pkg_program) ["list", "--global", "--simple-output"] "" tmpDir <- liftIO $ getTemporaryDirectory + return NormalizerEnv { normalizerRoot = addTrailingPathSeparator (testSourceDir env), @@ -410,8 +415,14 @@ mkNormalizerEnv = do normalizerKnownPackages = mapMaybe simpleParse (words list_out), normalizerPlatform - = testPlatform env + = testPlatform env, + normalizerCabalVersion + = cabalVersionLibrary } + where + +cabalVersionLibrary :: Version +cabalVersionLibrary = U.cabalVersion requireProgramM :: Program -> TestM ConfiguredProgram requireProgramM program = do diff --git a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs index 4e6aec19890..a1529cc47f9 100644 --- a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs +++ b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs @@ -49,6 +49,25 @@ normalizeOutput nenv = "/incoming/new-" -- Normalize architecture . resub (posixRegexEscape (display (normalizerPlatform nenv))) "" + -- Remove ghc path from show-build-info output + . resub ("\"path\":\"[^\"]*\"}") + "\"path\":\"\"}" + -- Remove cabal version output from show-build-info output + . resub ("{\"cabal-version\":\"" ++ posixRegexEscape (display (normalizerCabalVersion nenv)) ++ "\"") + "{\"cabal-version\":\"\"" + -- Remove the package id for stuff such as: + -- > "-package-id","base-4.14.0.0-" + -- and replace it with: + -- > "-package-id","" + -- + -- Otherwise, output can not be properly normalized as on MacOs we remove + -- vowels from packages to make the names shorter. + -- E.g. "another-framework-0.8.1.1" -> "nthr-frmwrk-0.8.1.1" + -- + -- This makes it impossible to have a stable package id, thus remove it completely. + -- Check manually in your test-cases if the package-id needs to be verified. + . resub ("\"-package-id\",\"([^\"]*)\"") + "\"-package-id\",\"\"" -- Some GHC versions are chattier than others . resub "^ignoring \\(possibly broken\\) abi-depends field for packages" "" -- Normalize the current GHC version. Apply this BEFORE packageIdRegex, @@ -74,6 +93,7 @@ data NormalizerEnv = NormalizerEnv , normalizerGhcVersion :: Version , normalizerKnownPackages :: [PackageId] , normalizerPlatform :: Platform + , normalizerCabalVersion :: Version } posixSpecialChars :: [Char] diff --git a/cabal-testsuite/src/Test/Cabal/Plan.hs b/cabal-testsuite/src/Test/Cabal/Plan.hs index 223832edc19..884c45902f0 100644 --- a/cabal-testsuite/src/Test/Cabal/Plan.hs +++ b/cabal-testsuite/src/Test/Cabal/Plan.hs @@ -5,6 +5,7 @@ module Test.Cabal.Plan ( Plan, DistDirOrBinFile(..), planDistDir, + buildInfoFile, ) where import Distribution.Parsec (simpleParsec) @@ -14,6 +15,7 @@ import Distribution.Package import qualified Data.Text as Text import Data.Aeson import Data.Aeson.Types +import Data.Maybe import Control.Monad -- TODO: index this @@ -27,6 +29,7 @@ data InstallItem -- local or inplace package data ConfiguredInplace = ConfiguredInplace { configuredInplaceDistDir :: FilePath + , configuredInplaceBuildInfo :: FilePath , configuredInplacePackageName :: PackageName , configuredInplaceComponentName :: Maybe ComponentName } @@ -57,9 +60,10 @@ instance FromJSON InstallItem where instance FromJSON ConfiguredInplace where parseJSON (Object v) = do dist_dir <- v .: "dist-dir" + build_info <- v .: "build-info" pkg_name <- v .: "pkg-name" component_name <- v .:? "component-name" - return (ConfiguredInplace dist_dir pkg_name component_name) + return (ConfiguredInplace dist_dir build_info pkg_name component_name) parseJSON invalid = typeMismatch "ConfiguredInplace" invalid instance FromJSON ConfiguredGlobal where @@ -109,3 +113,22 @@ planDistDir plan pkg_name cname = Nothing -> True Just cname' -> cname == cname' return $ DistDir $ configuredInplaceDistDir conf + +buildInfoFile :: Plan -> PackageName -> ComponentName -> FilePath +buildInfoFile plan pkg_name cname = + case concatMap p (planInstallPlan plan) of + [x] -> x + [] -> error $ "buildInfoFile: component " ++ prettyShow cname + ++ " of package " ++ prettyShow pkg_name ++ " either does not" + ++ " exist in the install plan or build info-file" + _ -> error $ "buildInfoFile: found multiple copies of component " ++ prettyShow cname + ++ " of package " ++ prettyShow pkg_name ++ " in install plan" + where + p APreExisting = [] + p (AConfiguredGlobal conf) = [] + p (AConfiguredInplace conf) = do + guard (configuredInplacePackageName conf == pkg_name) + guard $ case configuredInplaceComponentName conf of + Nothing -> True + Just cname' -> cname == cname' + return $ configuredInplaceBuildInfo conf