From 1e9de7fa9fb9cec5dd15fd792109dd65e96eb625 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sun, 16 Aug 2015 19:50:39 +0200 Subject: [PATCH 01/43] Add show-build-info command This allows users to get a JSON representation of various information about how Cabal would go about building a package. The output of this command is intended for external tools and therefore the format should remain stable. --- Cabal/Cabal.cabal | 2 + Cabal/Distribution/Simple.hs | 26 +++- Cabal/Distribution/Simple/Build.hs | 19 ++- Cabal/Distribution/Simple/Setup.hs | 44 +++++++ Cabal/Distribution/Simple/ShowBuildInfo.hs | 142 +++++++++++++++++++++ Cabal/Distribution/Simple/UserHooks.hs | 1 - Cabal/Distribution/Simple/Utils/Json.hs | 34 +++++ cabal-install/Distribution/Client/Setup.hs | 23 +++- 8 files changed, 286 insertions(+), 5 deletions(-) create mode 100644 Cabal/Distribution/Simple/ShowBuildInfo.hs create mode 100644 Cabal/Distribution/Simple/Utils/Json.hs diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 6175385cd65..9c66a4a9ce8 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -375,6 +375,7 @@ library Distribution.Simple.Program.Types Distribution.Simple.Register Distribution.Simple.Setup + Distribution.Simple.ShowBuildInfo Distribution.Simple.SrcDist Distribution.Simple.Test Distribution.Simple.Test.ExeV10 @@ -534,6 +535,7 @@ library Distribution.Simple.GHC.EnvironmentParser Distribution.Simple.GHC.Internal Distribution.Simple.GHC.ImplInfo + Distribution.Simple.Utils.Json Paths_Cabal if flag(bundled-binary-generic) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index 16a5adff1a6..ae9b36a7843 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -72,8 +72,8 @@ import Distribution.Simple.PreProcess import Distribution.Simple.Setup import Distribution.Simple.Command -import Distribution.Simple.Build -import Distribution.Simple.SrcDist +import Distribution.Simple.Build ( build, showBuildInfo, repl ) +import Distribution.Simple.SrcDist ( sdist ) import Distribution.Simple.Register import Distribution.Simple.Configure @@ -179,6 +179,7 @@ defaultMainHelper hooks args = topHandler $ do [configureCommand progs `commandAddAction` \fs as -> configureAction hooks fs as >> return () ,buildCommand progs `commandAddAction` buildAction hooks + ,showBuildInfoCommand progs `commandAddAction` showBuildInfoAction hooks ,replCommand progs `commandAddAction` replAction hooks ,installCommand `commandAddAction` installAction hooks ,copyCommand `commandAddAction` copyAction hooks @@ -264,6 +265,27 @@ buildAction hooks flags args = do (return lbi { withPrograms = progs }) hooks flags' { buildArgs = args } args +showBuildInfoAction :: UserHooks -> BuildFlags -> Args -> IO () +showBuildInfoAction hooks flags args = do + distPref <- findDistPrefOrDefault (buildDistPref flags) + let verbosity = fromFlag $ buildVerbosity flags + flags' = flags { buildDistPref = toFlag distPref } + + lbi <- getBuildConfig hooks verbosity distPref + progs <- reconfigurePrograms verbosity + (buildProgramPaths flags') + (buildProgramArgs flags') + (withPrograms lbi) + + pbi <- preBuild hooks args flags' + let lbi' = lbi { withPrograms = progs } + pkg_descr0 = localPkgDescr lbi' + pkg_descr = updatePackageDescription pbi pkg_descr0 + -- TODO: Somehow don't ignore build hook? + showBuildInfo pkg_descr lbi' flags + + postBuild hooks args flags' pkg_descr lbi' + replAction :: UserHooks -> ReplFlags -> Args -> IO () replAction hooks flags args = do distPref <- findDistPrefOrDefault (replDistPref flags) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 95c576a5781..3747d1f48fe 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -19,7 +19,7 @@ -- module Distribution.Simple.Build ( - build, repl, + build, showBuildInfo, repl, startInterpreter, initialBuildSteps, @@ -69,11 +69,16 @@ import Distribution.Simple.PreProcess import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Program.Types import Distribution.Simple.Program.Db +import qualified Distribution.Simple.Program.HcPkg as HcPkg +import Distribution.Simple.ShowBuildInfo import Distribution.Simple.BuildPaths import Distribution.Simple.Configure import Distribution.Simple.Register import Distribution.Simple.Test.LibV09 import Distribution.Simple.Utils + ( createDirectoryIfMissingVerbose, rewriteFile, rewriteFileEx + , die, die', info, debug, warn, setupMessage ) +import Distribution.Simple.Utils.Json import Distribution.System import Distribution.Pretty @@ -128,6 +133,18 @@ build pkg_descr lbi flags suffixes = do verbosity = fromFlag (buildVerbosity flags) +showBuildInfo :: PackageDescription -- ^ Mostly information from the .cabal file + -> LocalBuildInfo -- ^ Configuration information + -> BuildFlags -- ^ Flags that the user passed to build + -> IO () +showBuildInfo pkg_descr lbi flags = do + let verbosity = fromFlag (buildVerbosity flags) + targets <- readTargetInfos verbosity pkg_descr lbi (buildArgs flags) + let targetsToBuild = neededTargetsInBuildOrder' pkg_descr lbi (map nodeKey targets) + doc = mkBuildInfo pkg_descr lbi flags targetsToBuild + putStrLn $ renderJson doc "" + + repl :: PackageDescription -- ^ Mostly information from the .cabal file -> LocalBuildInfo -- ^ Configuration information -> ReplFlags -- ^ Flags that the user passed to build diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index c778d407a61..cb3082801c3 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -45,6 +45,7 @@ module Distribution.Simple.Setup ( HaddockFlags(..), emptyHaddockFlags, defaultHaddockFlags, haddockCommand, HscolourFlags(..), emptyHscolourFlags, defaultHscolourFlags, hscolourCommand, BuildFlags(..), emptyBuildFlags, defaultBuildFlags, buildCommand, + showBuildInfoCommand, ReplFlags(..), defaultReplFlags, replCommand, CleanFlags(..), emptyCleanFlags, defaultCleanFlags, cleanCommand, RegisterFlags(..), emptyRegisterFlags, defaultRegisterFlags, registerCommand, @@ -1621,6 +1622,49 @@ instance Monoid CleanFlags where instance Semigroup CleanFlags where (<>) = gmappend +-- ------------------------------------------------------------ +-- * show-build-info flags +-- ------------------------------------------------------------ + +showBuildInfoCommand :: ProgramConfiguration -> CommandUI BuildFlags +showBuildInfoCommand progConf = CommandUI + { commandName = "show-build-info" + , commandSynopsis = "Emit details about how a package would be built." + , commandDescription = Just $ \_ -> wrapText $ + "Components encompass executables, tests, and benchmarks.\n" + ++ "\n" + ++ "Affected by configuration options, see `configure`.\n" + , commandNotes = Just $ \pname -> + "Examples:\n" + ++ " " ++ pname ++ " show-build-info " + ++ " All the components in the package\n" + ++ " " ++ pname ++ " show-build-info foo " + ++ " A component (i.e. lib, exe, test suite)\n\n" + ++ programFlagsDescription progConf +--TODO: re-enable once we have support for module/file targets +-- ++ " " ++ pname ++ " show-build-info Foo.Bar " +-- ++ " A module\n" +-- ++ " " ++ pname ++ " show-build-info Foo/Bar.hs" +-- ++ " A file\n\n" +-- ++ "If a target is ambiguous it can be qualified with the component " +-- ++ "name, e.g.\n" +-- ++ " " ++ pname ++ " show-build-info foo:Foo.Bar\n" +-- ++ " " ++ pname ++ " show-build-info testsuite1:Foo/Bar.hs\n" + , commandUsage = usageAlternatives "show-build-info" $ + [ "[FLAGS]" + , "COMPONENTS [FLAGS]" + ] + , commandDefaultFlags = defaultBuildFlags + , commandOptions = \showOrParseArgs -> + [ optionVerbosity + buildVerbosity (\v flags -> flags { buildVerbosity = v }) + + , optionDistPref + buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs + ] + ++ buildOptions progConf showOrParseArgs + } + -- ------------------------------------------------------------ -- * Build flags -- ------------------------------------------------------------ diff --git a/Cabal/Distribution/Simple/ShowBuildInfo.hs b/Cabal/Distribution/Simple/ShowBuildInfo.hs new file mode 100644 index 00000000000..21bbb44c876 --- /dev/null +++ b/Cabal/Distribution/Simple/ShowBuildInfo.hs @@ -0,0 +1,142 @@ +-- | +-- This module defines a simple JSON-based format for exporting basic +-- information about a Cabal package and the compiler configuration Cabal +-- would use to build it. This can be produced with the @cabal show-build-info@ +-- command. +-- +-- This format is intended for consumption by external tooling and should +-- therefore be rather stable. Moreover, this allows tooling users to avoid +-- linking against Cabal. This is an important advantage as direct API usage +-- tends to be rather fragile in the presence of user-initiated upgrades of +-- Cabal. +-- +-- Below is an example of the output this module produces, +-- +-- @ +-- { "cabal_version": "1.23.0.0", +-- "compiler": { +-- "flavor": "GHC", +-- "compiler_id": "ghc-7.10.2", +-- "path": "/usr/bin/ghc", +-- }, +-- "components": [ +-- { "type": "library", +-- "name": "CLibName", +-- "compiler_args": +-- ["-O", "-XHaskell98", "-Wall", +-- "-package-id", "parallel-3.2.0.6-b79c38c5c25fff77f3ea7271851879eb"] +-- "modules": ["Project.ModA", "Project.ModB", "Paths_project"], +-- "source_files": [], +-- "source_dirs": ["src"] +-- } +-- ] +-- } +-- @ +-- +-- The @cabal_version@ property provides the version of the Cabal library +-- which generated the output. The @compiler@ property gives some basic +-- information about the compiler Cabal would use to compile the package. +-- +-- The @components@ property gives a list of the Cabal 'Component's defined by +-- the package. Each has, +-- +-- * @type@: the type of the component (one of @library@, @executable@, +-- @test-suite@, or @benchmark@) +-- * @name@: a string serving to uniquely identify the component within the +-- package. +-- * @compiler_args@: the command-line arguments Cabal would pass to the +-- compiler to compile the component +-- * @modules@: the modules belonging to the component +-- * @source_dirs@: a list of directories where the modules might be found +-- * @source_files@: any other Haskell sources needed by the component +-- +-- Note: At the moment this is only supported when using the GHC compiler. +-- + +module Distribution.Simple.ShowBuildInfo (mkBuildInfo) where + +import qualified Distribution.Simple.GHC as GHC +import qualified Distribution.Simple.Program.GHC as GHC + +import Distribution.PackageDescription +import Distribution.Compiler +import Distribution.Verbosity +import Distribution.Simple.Compiler +import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.Program +import Distribution.Simple.Setup +import Distribution.Simple.Utils (cabalVersion) +import Distribution.Simple.Utils.Json +import Distribution.Types.TargetInfo +import Distribution.Text + +-- | Construct a JSON document describing the build information for a package +mkBuildInfo :: PackageDescription -- ^ Mostly information from the .cabal file + -> LocalBuildInfo -- ^ Configuration information + -> BuildFlags -- ^ Flags that the user passed to build + -> [TargetInfo] + -> Json +mkBuildInfo pkg_descr lbi _flags targetsToBuild = info + where + componentsToBuild = map (\target -> (componentLocalName $ targetCLBI target,targetCLBI target)) targetsToBuild + (.=) :: String -> Json -> (String, Json) + k .= v = (k, v) + + info = JsonObject + [ "cabal_version" .= JsonString (display cabalVersion) + , "compiler" .= mkCompilerInfo + , "components" .= JsonArray (map mkComponentInfo componentsToBuild) + ] + + mkCompilerInfo = JsonObject + [ "flavour" .= JsonString (show $ compilerFlavor $ compiler lbi) + , "compiler_id" .= JsonString (showCompilerId $ compiler lbi) + , "path" .= path + ] + where + path = maybe JsonNull (JsonString . programPath) + $ lookupProgram ghcProgram (withPrograms lbi) + + mkComponentInfo (name, clbi) = JsonObject + [ "type" .= JsonString compType + , "name" .= JsonString (show name) + , "compiler_args" .= JsonArray (map JsonString $ getCompilerArgs bi lbi clbi) + , "modules" .= JsonArray (map (JsonString . display) modules) + , "source_files" .= JsonArray (map JsonString source_files) + , "source_dirs" .= JsonArray (map JsonString $ hsSourceDirs bi) + ] + where + bi = componentBuildInfo comp + Just comp = lookupComponent pkg_descr name + compType = case comp of + CLib _ -> "library" + CExe _ -> "executable" + CTest _ -> "test-suite" + CBench _ -> "benchmark" + CFLib _ -> "foreign-library" + modules = case comp of + CLib lib -> explicitLibModules lib + CExe exe -> exeModules exe + _ -> [] + source_files = case comp of + CLib _ -> [] + CExe exe -> [modulePath exe] + _ -> [] + +-- | Get the command-line arguments that would be passed +-- to the compiler to build the given component. +getCompilerArgs :: BuildInfo + -> LocalBuildInfo + -> ComponentLocalBuildInfo + -> [String] +getCompilerArgs bi lbi clbi = + case compilerFlavor $ compiler lbi of + GHC -> ghc + GHCJS -> ghc + c -> error $ "ShowBuildInfo.getCompilerArgs: Don't know how to get "++ + "build arguments for compiler "++show c + where + -- This is absolutely awful + ghc = GHC.renderGhcOptions (compiler lbi) (hostPlatform lbi) baseOpts + where + baseOpts = GHC.componentGhcOptions normal lbi bi clbi (buildDir lbi) diff --git a/Cabal/Distribution/Simple/UserHooks.hs b/Cabal/Distribution/Simple/UserHooks.hs index 306092186d1..97f22933c56 100644 --- a/Cabal/Distribution/Simple/UserHooks.hs +++ b/Cabal/Distribution/Simple/UserHooks.hs @@ -69,7 +69,6 @@ data UserHooks = UserHooks { -- |Hook to run before build command. Second arg indicates verbosity level. preBuild :: Args -> BuildFlags -> IO HookedBuildInfo, - -- |Over-ride this hook to get different behavior during build. buildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO (), -- |Hook to run after build command. Second arg indicates verbosity level. diff --git a/Cabal/Distribution/Simple/Utils/Json.hs b/Cabal/Distribution/Simple/Utils/Json.hs new file mode 100644 index 00000000000..b8447fc5075 --- /dev/null +++ b/Cabal/Distribution/Simple/Utils/Json.hs @@ -0,0 +1,34 @@ +module Distribution.Simple.Utils.Json + ( Json(..) + , renderJson + ) where + +data Json = JsonArray [Json] + | JsonBool !Bool + | JsonNull + | JsonNumber !Int + | JsonObject [(String, Json)] + | JsonString !String + +renderJson :: Json -> ShowS +renderJson (JsonArray objs) = + surround "[" "]" $ intercalate "," $ map renderJson objs +renderJson (JsonBool True) = showString "true" +renderJson (JsonBool False) = showString "false" +renderJson JsonNull = showString "null" +renderJson (JsonNumber n) = shows n +renderJson (JsonObject attrs) = + surround "{" "}" $ intercalate "," $ map render attrs + where + render (k,v) = (surround "\"" "\"" $ showString k) . showString ":" . renderJson v +renderJson (JsonString s) = surround "\"" "\"" $ showString s + +surround :: String -> String -> ShowS -> ShowS +surround begin end middle = showString begin . middle . showString end + +intercalate :: String -> [ShowS] -> ShowS +intercalate sep = go + where + go [] = id + go [x] = x + go (x:xs) = x . showString sep . go xs diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index eb5330d3d16..473a91de4ce 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -23,7 +23,7 @@ module Distribution.Client.Setup , configureExCommand, ConfigExFlags(..), defaultConfigExFlags , buildCommand, BuildFlags(..), BuildExFlags(..), SkipAddSourceDepsCheck(..) , filterTestFlags - , replCommand, testCommand, benchmarkCommand, testOptions + , replCommand, testCommand, showBuildInfoCommand, benchmarkCommand, testOptions , configureExOptions, reconfigureCommand , installCommand, InstallFlags(..), installOptions, defaultInstallFlags , filterHaddockArgs, filterHaddockFlags, haddockOptions @@ -197,6 +197,7 @@ globalCommand commands = CommandUI { , "outdated" , "haddock" , "hscolour" + , "show-build-info" , "exec" , "new-build" , "new-configure" @@ -283,6 +284,7 @@ globalCommand commands = CommandUI { , addCmd "upload" , addCmd "report" , par + , addCmd "show-build-info" , addCmd "freeze" , addCmd "gen-bounds" , addCmd "outdated" @@ -861,6 +863,25 @@ filterTestFlags flags cabalLibVersion Cabal.testWrapper = NoFlag } +-- ------------------------------------------------------------ +-- * show-build-info command +-- ------------------------------------------------------------ + +showBuildInfoCommand :: CommandUI (BuildFlags, BuildExFlags) +showBuildInfoCommand = parent { + commandDefaultFlags = (commandDefaultFlags parent, mempty), + commandOptions = + \showOrParseArgs -> liftOptions fst setFst + (commandOptions parent showOrParseArgs) + ++ + liftOptions snd setSnd (buildExOptions showOrParseArgs) + } + where + setFst a (_,b) = (a,b) + setSnd b (a,_) = (a,b) + + parent = Cabal.showBuildInfoCommand defaultProgramDb + -- ------------------------------------------------------------ -- * Repl command -- ------------------------------------------------------------ From 0418c08fe7c45beea07f394b02fb0bc27e692123 Mon Sep 17 00:00:00 2001 From: Chris Fraser Date: Mon, 28 May 2018 22:18:03 +1000 Subject: [PATCH 02/43] Rebase work of cfraz89 and bgamari Add (currently nonfunctional) new-show-build-info Fix compile error Make new-show-build-info functional Use silent verbosity by default on showBuildInfo commands to keep output json clean Make show-build-info commands hidden Implement write-autogen-files Make new-write-autogen-files work Make new-write-autogen-files configure if necessary Use target selectors for new-show-build-info Don't prune plan for new-show-build-info Only configure in new-show-build-info and new-write-autogen-files if no persist build info file is found Wrap multiple target output of new-show-build-info in json list --- Cabal/Distribution/Simple.hs | 12 +- Cabal/Distribution/Simple/Build.hs | 2 - Cabal/Distribution/Simple/Setup.hs | 122 ++++++--- Cabal/Distribution/Simple/UserHooks.hs | 1 + .../Distribution/Client/CmdShowBuildInfo.hs | 254 ++++++++++++++++++ .../Client/CmdWriteAutogenFiles.hs | 220 +++++++++++++++ cabal-install/Distribution/Client/Setup.hs | 29 ++ cabal-install/cabal-install.cabal | 2 + cabal-install/main/Main.hs | 128 ++++++--- 9 files changed, 691 insertions(+), 79 deletions(-) create mode 100644 cabal-install/Distribution/Client/CmdShowBuildInfo.hs create mode 100644 cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index ae9b36a7843..85165459016 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -72,8 +72,8 @@ import Distribution.Simple.PreProcess import Distribution.Simple.Setup import Distribution.Simple.Command -import Distribution.Simple.Build ( build, showBuildInfo, repl ) -import Distribution.Simple.SrcDist ( sdist ) +import Distribution.Simple.Build +import Distribution.Simple.SrcDist import Distribution.Simple.Register import Distribution.Simple.Configure @@ -180,6 +180,7 @@ defaultMainHelper hooks args = topHandler $ do \fs as -> configureAction hooks fs as >> return () ,buildCommand progs `commandAddAction` buildAction hooks ,showBuildInfoCommand progs `commandAddAction` showBuildInfoAction hooks + ,writeAutogenFilesCommand progs `commandAddAction` writeAutogenFilesAction hooks ,replCommand progs `commandAddAction` replAction hooks ,installCommand `commandAddAction` installAction hooks ,copyCommand `commandAddAction` copyAction hooks @@ -286,6 +287,13 @@ showBuildInfoAction hooks flags args = do postBuild hooks args flags' pkg_descr lbi' +writeAutogenFilesAction :: UserHooks -> WriteAutogenFilesFlags -> Args -> IO () +writeAutogenFilesAction hooks flags _ = do + distPref <- findDistPrefOrDefault (wafDistPref flags) + let verbosity = fromFlag $ wafVerbosity flags + lbi <- getBuildConfig hooks verbosity distPref + initialBuildSteps distPref (localPkgDescr lbi) lbi verbosity + replAction :: UserHooks -> ReplFlags -> Args -> IO () replAction hooks flags args = do distPref <- findDistPrefOrDefault (replDistPref flags) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 3747d1f48fe..4105957511f 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -76,8 +76,6 @@ import Distribution.Simple.Configure import Distribution.Simple.Register import Distribution.Simple.Test.LibV09 import Distribution.Simple.Utils - ( createDirectoryIfMissingVerbose, rewriteFile, rewriteFileEx - , die, die', info, debug, warn, setupMessage ) import Distribution.Simple.Utils.Json import Distribution.System diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index cb3082801c3..16841db934c 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -45,7 +45,9 @@ module Distribution.Simple.Setup ( HaddockFlags(..), emptyHaddockFlags, defaultHaddockFlags, haddockCommand, HscolourFlags(..), emptyHscolourFlags, defaultHscolourFlags, hscolourCommand, BuildFlags(..), emptyBuildFlags, defaultBuildFlags, buildCommand, - showBuildInfoCommand, + showBuildInfoCommand, + writeAutogenFilesCommand, + WriteAutogenFilesFlags(..), ReplFlags(..), defaultReplFlags, replCommand, CleanFlags(..), emptyCleanFlags, defaultCleanFlags, cleanCommand, RegisterFlags(..), emptyRegisterFlags, defaultRegisterFlags, registerCommand, @@ -1622,49 +1624,6 @@ instance Monoid CleanFlags where instance Semigroup CleanFlags where (<>) = gmappend --- ------------------------------------------------------------ --- * show-build-info flags --- ------------------------------------------------------------ - -showBuildInfoCommand :: ProgramConfiguration -> CommandUI BuildFlags -showBuildInfoCommand progConf = CommandUI - { commandName = "show-build-info" - , commandSynopsis = "Emit details about how a package would be built." - , commandDescription = Just $ \_ -> wrapText $ - "Components encompass executables, tests, and benchmarks.\n" - ++ "\n" - ++ "Affected by configuration options, see `configure`.\n" - , commandNotes = Just $ \pname -> - "Examples:\n" - ++ " " ++ pname ++ " show-build-info " - ++ " All the components in the package\n" - ++ " " ++ pname ++ " show-build-info foo " - ++ " A component (i.e. lib, exe, test suite)\n\n" - ++ programFlagsDescription progConf ---TODO: re-enable once we have support for module/file targets --- ++ " " ++ pname ++ " show-build-info Foo.Bar " --- ++ " A module\n" --- ++ " " ++ pname ++ " show-build-info Foo/Bar.hs" --- ++ " A file\n\n" --- ++ "If a target is ambiguous it can be qualified with the component " --- ++ "name, e.g.\n" --- ++ " " ++ pname ++ " show-build-info foo:Foo.Bar\n" --- ++ " " ++ pname ++ " show-build-info testsuite1:Foo/Bar.hs\n" - , commandUsage = usageAlternatives "show-build-info" $ - [ "[FLAGS]" - , "COMPONENTS [FLAGS]" - ] - , commandDefaultFlags = defaultBuildFlags - , commandOptions = \showOrParseArgs -> - [ optionVerbosity - buildVerbosity (\v flags -> flags { buildVerbosity = v }) - - , optionDistPref - buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs - ] - ++ buildOptions progConf showOrParseArgs - } - -- ------------------------------------------------------------ -- * Build flags -- ------------------------------------------------------------ @@ -2249,6 +2208,81 @@ optionNumJobs get set = | otherwise -> Right (Just n) _ -> Left "The jobs value should be a number or '$ncpus'" + +-- ------------------------------------------------------------ +-- * ghc-mod support flags +-- ------------------------------------------------------------ + +showBuildInfoCommand :: ProgramDb -> CommandUI BuildFlags +showBuildInfoCommand progDb = CommandUI + { commandName = "show-build-info" + , commandSynopsis = "Emit details about how a package would be built." + , commandDescription = Just $ \_ -> wrapText $ + "Components encompass executables, tests, and benchmarks.\n" + ++ "\n" + ++ "Affected by configuration options, see `configure`.\n" + , commandNotes = Just $ \pname -> + "Examples:\n" + ++ " " ++ pname ++ " show-build-info " + ++ " All the components in the package\n" + ++ " " ++ pname ++ " show-build-info foo " + ++ " A component (i.e. lib, exe, test suite)\n\n" + ++ programFlagsDescription progDb +--TODO: re-enable once we have support for module/file targets +-- ++ " " ++ pname ++ " show-build-info Foo.Bar " +-- ++ " A module\n" +-- ++ " " ++ pname ++ " show-build-info Foo/Bar.hs" +-- ++ " A file\n\n" +-- ++ "If a target is ambiguous it can be qualified with the component " +-- ++ "name, e.g.\n" +-- ++ " " ++ pname ++ " show-build-info foo:Foo.Bar\n" +-- ++ " " ++ pname ++ " show-build-info testsuite1:Foo/Bar.hs\n" + , commandUsage = usageAlternatives "show-build-info" $ + [ "[FLAGS]" + , "COMPONENTS [FLAGS]" + ] + , commandDefaultFlags = defaultBuildFlags + , commandOptions = \showOrParseArgs -> + [ optionVerbosity + buildVerbosity (\v flags -> flags { buildVerbosity = v }) + + , optionDistPref + buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs + ] + ++ buildOptions progDb showOrParseArgs + } + +writeAutogenFilesCommand :: ProgramDb -> CommandUI WriteAutogenFilesFlags +writeAutogenFilesCommand progDb = CommandUI + { commandName = "write-autogen-files" + , commandSynopsis = "Generate and write out the Paths_.hs and cabal_macros.h files" + , commandDescription = Just $ \_ -> wrapText $ + "Components encompass executables, tests, and benchmarks.\n" + ++ "\n" + ++ "Affected by configuration options, see `configure`.\n" + , commandNotes = Just $ \pname -> + "Examples:\n" + ++ " " ++ pname ++ " write-autogen-files " + ++ " All the components in the package\n" + ++ " " ++ pname ++ " write-autogen-files foo " + ++ " A component (i.e. lib, exe, test suite)\n\n" + ++ programFlagsDescription progDb + , commandUsage = usageAlternatives "write-autogen-files" $ + [ "[FLAGS]" ] + , commandDefaultFlags = WriteAutogenFilesFlags NoFlag (toFlag normal) + , commandOptions = \showOrParseArgs -> + [ optionVerbosity + wafVerbosity (\v flags -> flags { wafVerbosity = v }) + + , optionDistPref + wafDistPref (\d flags -> flags { wafDistPref = d }) showOrParseArgs + ] + } + +data WriteAutogenFilesFlags = WriteAutogenFilesFlags { + wafDistPref :: Flag FilePath, + wafVerbosity :: Flag Verbosity +} deriving Show -- ------------------------------------------------------------ -- * Other Utils -- ------------------------------------------------------------ diff --git a/Cabal/Distribution/Simple/UserHooks.hs b/Cabal/Distribution/Simple/UserHooks.hs index 97f22933c56..306092186d1 100644 --- a/Cabal/Distribution/Simple/UserHooks.hs +++ b/Cabal/Distribution/Simple/UserHooks.hs @@ -69,6 +69,7 @@ data UserHooks = UserHooks { -- |Hook to run before build command. Second arg indicates verbosity level. preBuild :: Args -> BuildFlags -> IO HookedBuildInfo, + -- |Over-ride this hook to get different behavior during build. buildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO (), -- |Hook to run after build command. Second arg indicates verbosity level. diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs new file mode 100644 index 00000000000..cc5a41bb6cc --- /dev/null +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -0,0 +1,254 @@ +-- | cabal-install CLI command: build +-- +module Distribution.Client.CmdShowBuildInfo ( + -- * The @build@ CLI and action + showBuildInfoCommand, + showBuildInfoAction + ) where + +import Distribution.Client.ProjectOrchestration +import Distribution.Client.CmdErrorMessages +import Distribution.Client.CmdInstall.ClientInstallFlags + +import Distribution.Client.Setup + ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags ) +import qualified Distribution.Client.Setup as Client +import Distribution.Simple.Setup + ( HaddockFlags, fromFlagOrDefault, TestFlags ) +import Distribution.Simple.Command + ( CommandUI(..), usageAlternatives ) +import Distribution.Verbosity + ( Verbosity, silent ) +import Distribution.Simple.Utils + ( wrapText, die') +import Distribution.Types.UnitId (UnitId) + +import qualified Data.Map as Map +import qualified Distribution.Simple.Setup as Cabal +import Distribution.Client.SetupWrapper +import Distribution.Simple.Program ( defaultProgramDb ) +import qualified Distribution.Client.InstallPlan as InstallPlan +import Distribution.Client.ProjectPlanning.Types +import Distribution.Client.ProjectPlanning ( + setupHsConfigureFlags, setupHsConfigureArgs, + setupHsBuildFlags, setupHsBuildArgs, + setupHsScriptOptions + ) +import Distribution.Client.DistDirLayout (distBuildDirectory) +import Distribution.Client.Types ( PackageLocation(..), GenericReadyPackage(..) ) +import Distribution.Client.JobControl (newLock, Lock) +import Distribution.Simple.Configure (tryGetPersistBuildConfig) +import Data.List (find) + +showBuildInfoCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) +showBuildInfoCommand = Client.installCommand { + commandName = "new-show-build-info", + commandSynopsis = "Show project build information", + commandUsage = usageAlternatives "new-show-build-info" [ "[TARGETS] [FLAGS]" ], + commandDescription = Just $ \_ -> wrapText $ + "Build one or more targets from within the project. The available " + ++ "targets are the packages in the project as well as individual " + ++ "components within those packages, including libraries, executables, " + ++ "test-suites or benchmarks. Targets can be specified by name or " + ++ "location. If no target is specified then the default is to build " + ++ "the package in the current directory.\n\n" + + ++ "Dependencies are built or rebuilt as necessary. Additional " + ++ "configuration flags can be specified on the command line and these " + ++ "extend the project configuration from the 'cabal.project', " + ++ "'cabal.project.local' and other files.", + commandNotes = Just $ \pname -> + "Examples:\n" + ++ " " ++ pname ++ " new-build\n" + ++ " Build the package in the current directory or all packages in the project\n" + ++ " " ++ pname ++ " new-build pkgname\n" + ++ " Build the package named pkgname in the project\n" + ++ " " ++ pname ++ " new-build ./pkgfoo\n" + ++ " Build the package in the ./pkgfoo directory\n" + ++ " " ++ pname ++ " new-build cname\n" + ++ " Build the component named cname module Distribution.Client.InstallPlanin the project\n" + ++ " " ++ pname ++ " new-build cname --module Distribution.Client.InstallPlanenable-profiling\n" + ++ " Build the component in profilingmodule Distribution.Client.InstallPlan mode (including dependencies as needed)\n\n" + + ++ cmdCommonHelpTextNewBuildBeta + } + + +-- | The @build@ command does a lot. It brings the install plan up to date, +-- selects that part of the plan needed by the given or implicit targets and +-- then executes the plan. +-- +-- For more details on how this works, see the module +-- "Distribution.Client.ProjectOrchestration" +-- +showBuildInfoAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) + -> [String] -> GlobalFlags -> IO () +showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags) + targetStrings globalFlags = do + + baseCtx <- establishProjectBaseContext verbosity cliConfig + let baseCtx' = baseCtx { + buildSettings = (buildSettings baseCtx) { + buildSettingDryRun = True + } + } + + targetSelectors <- either (reportTargetSelectorProblems verbosity) return + =<< readTargetSelectors (localPackages baseCtx') Nothing targetStrings + + buildCtx <- + runProjectPreBuildPhase verbosity baseCtx' $ \elaboratedPlan -> do + -- Interpret the targets on the command line as build targets + -- (as opposed to say repl or haddock targets). + targets <- either (reportTargetProblems verbosity) return + $ resolveTargets + selectPackageTargets + selectComponentTarget + TargetProblemCommon + elaboratedPlan + Nothing + targetSelectors + + -- Don't prune the plan though, as we want a list of all configured packages + return (elaboratedPlan, targets) + + scriptLock <- newLock + showTargets verbosity baseCtx' buildCtx scriptLock + + where + -- Default to silent verbosity otherwise it will pollute our json output + verbosity = fromFlagOrDefault silent (configVerbosity configFlags) + cliConfig = commandLineFlagsToProjectConfig + globalFlags configFlags configExFlags + installFlags defaultClientInstallFlags + haddockFlags + testFlags + +-- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks +showTargets :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () +showTargets verbosity baseCtx buildCtx lock = do + putStr "[" + mapM_ showSeparated (zip [0..] targets) + putStrLn "]" + where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] + targets = fst <$> (Map.toList . targetsMap $ buildCtx) + doShowInfo unitId = showInfo verbosity baseCtx buildCtx lock configured unitId + showSeparated (idx, unitId) + | idx == length targets - 1 = doShowInfo unitId + | otherwise = doShowInfo unitId >> putStrLn "," + +showInfo :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () +showInfo verbosity baseCtx buildCtx lock pkgs targetUnitId + | Nothing <- mbPkg = die' verbosity $ "No unit " ++ show targetUnitId + | Just pkg <- mbPkg = do + let shared = elaboratedShared buildCtx + install = elaboratedPlanOriginal buildCtx + dirLayout = distDirLayout baseCtx + buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) + flags = setupHsBuildFlags pkg shared verbosity buildDir + args = setupHsBuildArgs pkg + srcDir = case (elabPkgSourceLocation pkg) of + LocalUnpackedPackage fp -> fp + _ -> "" + scriptOptions = setupHsScriptOptions + (ReadyPackage pkg) + install + shared + dirLayout + srcDir + buildDir + False + lock + configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir + configureArgs = setupHsConfigureArgs pkg + --Configure the package if there's no existing config + lbi <- tryGetPersistBuildConfig buildDir + case lbi of + Left _ -> setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.configureCommand defaultProgramDb) + (const $ configureFlags) + (const configureArgs) + Right _ -> pure () + setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.showBuildInfoCommand defaultProgramDb) + (const flags) + (const args) + where mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs + +-- | This defines what a 'TargetSelector' means for the @write-autogen-files@ command. +-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, +-- or otherwise classifies the problem. +-- +-- For the @write-autogen-files@ command select all components except non-buildable and disabled +-- tests\/benchmarks, fail if there are no such components +-- +selectPackageTargets :: TargetSelector + -> [AvailableTarget k] -> Either TargetProblem [k] +selectPackageTargets targetSelector targets + + -- If there are any buildable targets then we select those + | not (null targetsBuildable) + = Right targetsBuildable + + -- If there are targets but none are buildable then we report those + | not (null targets) + = Left (TargetProblemNoneEnabled targetSelector targets') + + -- If there are no targets at all then we report that + | otherwise + = Left (TargetProblemNoTargets targetSelector) + where + targets' = forgetTargetsDetail targets + targetsBuildable = selectBuildableTargetsWith + (buildable targetSelector) + targets + + -- When there's a target filter like "pkg:tests" then we do select tests, + -- but if it's just a target like "pkg" then we don't build tests unless + -- they are requested by default (i.e. by using --enable-tests) + buildable (TargetPackage _ _ Nothing) TargetNotRequestedByDefault = False + buildable (TargetAllPackages Nothing) TargetNotRequestedByDefault = False + buildable _ _ = True + +-- | For a 'TargetComponent' 'TargetSelector', check if the component can be +-- selected. +-- +-- For the @build@ command we just need the basic checks on being buildable etc. +-- +selectComponentTarget :: SubComponentTarget + -> AvailableTarget k -> Either TargetProblem k +selectComponentTarget subtarget = + either (Left . TargetProblemCommon) Right + . selectComponentTargetBasic subtarget + + +-- | The various error conditions that can occur when matching a +-- 'TargetSelector' against 'AvailableTarget's for the @build@ command. +-- +data TargetProblem = + TargetProblemCommon TargetProblemCommon + + -- | The 'TargetSelector' matches targets but none are buildable + | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] + + -- | There are no targets at all + | TargetProblemNoTargets TargetSelector + deriving (Eq, Show) + +reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a +reportTargetProblems verbosity = + die' verbosity . unlines . map renderTargetProblem + +renderTargetProblem :: TargetProblem -> String +renderTargetProblem (TargetProblemCommon problem) = + renderTargetProblemCommon "build" problem +renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = + renderTargetProblemNoneEnabled "build" targetSelector targets +renderTargetProblem(TargetProblemNoTargets targetSelector) = + renderTargetProblemNoTargets "build" targetSelector \ No newline at end of file diff --git a/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs b/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs new file mode 100644 index 00000000000..86a80b6fa53 --- /dev/null +++ b/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs @@ -0,0 +1,220 @@ +-- | cabal-install CLI command: build +-- +module Distribution.Client.CmdWriteAutogenFiles ( + -- * The @build@ CLI and action + writeAutogenFilesCommand, + writeAutogenFilesAction + ) where + +import Distribution.Client.ProjectOrchestration +import Distribution.Client.CmdErrorMessages +import Distribution.Client.CmdInstall.ClientInstallFlags + +import Distribution.Client.Setup + ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags, WriteAutogenFilesFlags(..) ) +import qualified Distribution.Client.Setup as Client +import Distribution.Simple.Setup + ( HaddockFlags, fromFlagOrDefault, Flag(..), TestFlags ) +import Distribution.Simple.Command + ( CommandUI(..), usageAlternatives ) +import Distribution.Verbosity + ( Verbosity, normal ) +import Distribution.Simple.Utils + ( wrapText, die' ) +import Distribution.Simple.Configure (tryGetPersistBuildConfig) + +import qualified Data.Map as Map +import qualified Distribution.Simple.Setup as Cabal +import Distribution.Client.SetupWrapper +import Distribution.Simple.Program ( defaultProgramDb ) +import qualified Distribution.Client.InstallPlan as InstallPlan +import Distribution.Client.ProjectPlanning.Types +import Distribution.Client.ProjectPlanning ( + setupHsScriptOptions, setupHsConfigureFlags, setupHsConfigureArgs + ) +import Distribution.Client.DistDirLayout (distBuildDirectory) +import Distribution.Client.Types ( PackageLocation(..), GenericReadyPackage(..) ) +import Distribution.Client.JobControl (newLock, Lock) + +writeAutogenFilesCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) +writeAutogenFilesCommand = Client.installCommand { + commandName = "new-write-autogen-files", + commandSynopsis = "", + commandUsage = usageAlternatives "new-write-autogen-files" [ "[FLAGS]" ], + commandDescription = Just $ \_ -> wrapText $ + "Generate and write out the Paths_.hs and cabal_macros.h files\n" + ++ "for all components in the project", + commandNotes = Just $ \pname -> + "Examples:\n" + ++ " " ++ pname ++ " new-write-autogen-files\n" + ++ " Write for all packages in the project\n" + } + +writeAutogenFilesAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) + -> [String] -> GlobalFlags -> IO () +writeAutogenFilesAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags) + targetStrings globalFlags = do + baseCtx <- establishProjectBaseContext verbosity cliConfig + let baseCtx' = baseCtx { + buildSettings = (buildSettings baseCtx) { + buildSettingDryRun = True + } + } + targetSelectors <- either (reportTargetSelectorProblems verbosity) return + =<< readTargetSelectors (localPackages baseCtx') Nothing targetStrings + + buildCtx <- + runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do + -- Interpret the targets on the command line as build targets + -- (as opposed to say repl or haddock targets). + targets <- either (reportTargetProblems verbosity) return + $ resolveTargets + selectPackageTargets + selectComponentTarget + TargetProblemCommon + elaboratedPlan + Nothing + targetSelectors + + let elaboratedPlan' = pruneInstallPlanToTargets + TargetActionBuild + targets + elaboratedPlan + elaboratedPlan'' <- + if buildSettingOnlyDeps (buildSettings baseCtx') + then either (reportCannotPruneDependencies verbosity) return $ + pruneInstallPlanToDependencies (Map.keysSet targets) + elaboratedPlan' + else return elaboratedPlan' + + return (elaboratedPlan'', targets) + + scriptLock <- newLock + writeAutogenFiles verbosity baseCtx' buildCtx scriptLock (configured buildCtx) + + where + verbosity = fromFlagOrDefault normal (configVerbosity configFlags) + cliConfig = commandLineFlagsToProjectConfig + globalFlags configFlags configExFlags + installFlags defaultClientInstallFlags + haddockFlags + testFlags + configured ctx = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanToExecute ctx)] + + +writeAutogenFiles :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> IO () +writeAutogenFiles verbosity baseCtx buildCtx lock pkgs = mapM_ runWrapper pkgs + where runWrapper pkg = do + let shared = elaboratedShared buildCtx + install = elaboratedPlanOriginal buildCtx + dirLayout = distDirLayout baseCtx + buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) + srcDir = case (elabPkgSourceLocation pkg) of + LocalUnpackedPackage fp -> fp + _ -> "" + scriptOptions = setupHsScriptOptions + (ReadyPackage pkg) + install + shared + dirLayout + srcDir + buildDir + False + lock + configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir + configureArgs = setupHsConfigureArgs pkg + --Configure the package if there's no existing config, + lbi <- tryGetPersistBuildConfig buildDir + case lbi of + Left _ -> setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.configureCommand defaultProgramDb) + (const $ configureFlags) + (const configureArgs) + Right _ -> pure () + setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.writeAutogenFilesCommand defaultProgramDb) + (const $ WriteAutogenFilesFlags (Flag buildDir) (Flag verbosity)) + (const []) + +-- | This defines what a 'TargetSelector' means for the @write-autogen-files@ command. +-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, +-- or otherwise classifies the problem. +-- +-- For the @write-autogen-files@ command select all components except non-buildable and disabled +-- tests\/benchmarks, fail if there are no such components +-- +selectPackageTargets :: TargetSelector + -> [AvailableTarget k] -> Either TargetProblem [k] +selectPackageTargets targetSelector targets + + -- If there are any buildable targets then we select those + | not (null targetsBuildable) + = Right targetsBuildable + + -- If there are targets but none are buildable then we report those + | not (null targets) + = Left (TargetProblemNoneEnabled targetSelector targets') + + -- If there are no targets at all then we report that + | otherwise + = Left (TargetProblemNoTargets targetSelector) + where + targets' = forgetTargetsDetail targets + targetsBuildable = selectBuildableTargetsWith + (buildable targetSelector) + targets + + -- When there's a target filter like "pkg:tests" then we do select tests, + -- but if it's just a target like "pkg" then we don't build tests unless + -- they are requested by default (i.e. by using --enable-tests) + buildable (TargetPackage _ _ Nothing) TargetNotRequestedByDefault = False + buildable (TargetAllPackages Nothing) TargetNotRequestedByDefault = False + buildable _ _ = True + +-- | For a 'TargetComponent' 'TargetSelector', check if the component can be +-- selected. +-- +-- For the @build@ command we just need the basic checks on being buildable etc. +-- +selectComponentTarget :: SubComponentTarget + -> AvailableTarget k -> Either TargetProblem k +selectComponentTarget subtarget = + either (Left . TargetProblemCommon) Right + . selectComponentTargetBasic subtarget + + +-- | The various error conditions that can occur when matching a +-- 'TargetSelector' against 'AvailableTarget's for the @build@ command. +-- +data TargetProblem = + TargetProblemCommon TargetProblemCommon + + -- | The 'TargetSelector' matches targets but none are buildable + | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] + + -- | There are no targets at all + | TargetProblemNoTargets TargetSelector + deriving (Eq, Show) + +reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a +reportTargetProblems verbosity = + die' verbosity . unlines . map renderTargetProblem + +renderTargetProblem :: TargetProblem -> String +renderTargetProblem (TargetProblemCommon problem) = + renderTargetProblemCommon "build" problem +renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = + renderTargetProblemNoneEnabled "build" targetSelector targets +renderTargetProblem(TargetProblemNoTargets targetSelector) = + renderTargetProblemNoTargets "build" targetSelector + +reportCannotPruneDependencies :: Verbosity -> CannotPruneDependencies -> IO a +reportCannotPruneDependencies verbosity = + die' verbosity . renderCannotPruneDependencies + diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 473a91de4ce..b5c4f385efb 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -57,6 +57,9 @@ module Distribution.Client.Setup , copyCommand , registerCommand + --ghc-mod support commands + , showBuildInfoCommand + , writeAutogenFilesCommand, WriteAutogenFilesFlags(..) , parsePackageArgs , liftOptions , yesNoOpt @@ -105,6 +108,7 @@ import Distribution.Simple.Setup , SDistFlags(..), HaddockFlags(..) , CleanFlags(..), DoctestFlags(..) , CopyFlags(..), RegisterFlags(..) + , WriteAutogenFilesFlags(..) , readPackageDbList, showPackageDbList , Flag(..), toFlag, flagToMaybe, flagToList, maybeToFlag , BooleanFlag(..), optionVerbosity @@ -198,6 +202,7 @@ globalCommand commands = CommandUI { , "haddock" , "hscolour" , "show-build-info" + , "write-autogen-files" , "exec" , "new-build" , "new-configure" @@ -285,6 +290,7 @@ globalCommand commands = CommandUI { , addCmd "report" , par , addCmd "show-build-info" + , addCmd "write-autogen-files" , addCmd "freeze" , addCmd "gen-bounds" , addCmd "outdated" @@ -3003,3 +3009,26 @@ relevantConfigValuesText :: [String] -> String relevantConfigValuesText vs = "Relevant global configuration keys:\n" ++ concat [" " ++ v ++ "\n" |v <- vs] + + +-- ------------------------------------------------------------ +-- * Commands to support ghc-mod +-- ------------------------------------------------------------ + +showBuildInfoCommand :: CommandUI (BuildFlags, BuildExFlags) +showBuildInfoCommand = parent { + commandDefaultFlags = (commandDefaultFlags parent, mempty), + commandOptions = + \showOrParseArgs -> liftOptions fst setFst + (commandOptions parent showOrParseArgs) + ++ + liftOptions snd setSnd (buildExOptions showOrParseArgs) + } + where + setFst a (_,b) = (a,b) + setSnd b (a,_) = (a,b) + + parent = Cabal.showBuildInfoCommand defaultProgramDb + +writeAutogenFilesCommand :: CommandUI WriteAutogenFilesFlags +writeAutogenFilesCommand = Cabal.writeAutogenFilesCommand defaultProgramDb \ No newline at end of file diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 2310258bfb7..989456e90b7 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -161,6 +161,8 @@ executable cabal Distribution.Client.CmdBench Distribution.Client.CmdBuild Distribution.Client.CmdClean + Distribution.Client.CmdShowBuildInfo + Distribution.Client.CmdWriteAutogenFiles Distribution.Client.CmdConfigure Distribution.Client.CmdUpdate Distribution.Client.CmdErrorMessages diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 9c0cb8e3084..a55fe9fc979 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -52,6 +52,7 @@ import Distribution.Client.Setup , doctestCommand , copyCommand , registerCommand + , WriteAutogenFilesFlags(..) ) import Distribution.Simple.Setup ( HaddockTarget(..) @@ -83,6 +84,8 @@ import qualified Distribution.Client.List as List import qualified Distribution.Client.CmdConfigure as CmdConfigure import qualified Distribution.Client.CmdUpdate as CmdUpdate import qualified Distribution.Client.CmdBuild as CmdBuild +import qualified Distribution.Client.CmdShowBuildInfo as CmdShowBuildInfo +import qualified Distribution.Client.CmdWriteAutogenFiles as CmdWriteAutogenFiles import qualified Distribution.Client.CmdRepl as CmdRepl import qualified Distribution.Client.CmdFreeze as CmdFreeze import qualified Distribution.Client.CmdHaddock as CmdHaddock @@ -155,7 +158,7 @@ import qualified Distribution.Simple as Simple import qualified Distribution.Make as Make import qualified Distribution.Types.UnqualComponentName as Make import Distribution.Simple.Build - ( startInterpreter ) + ( startInterpreter, initialBuildSteps ) import Distribution.Simple.Command ( CommandParse(..), CommandUI(..), Command, CommandSpec(..) , CommandType(..), commandsRun, commandAddAction, hiddenCommand @@ -178,7 +181,7 @@ import Distribution.Simple.Utils import Distribution.Text ( display ) import Distribution.Verbosity as Verbosity - ( Verbosity, normal ) + ( Verbosity, normal, silent ) import Distribution.Version ( Version, mkVersion, orLaterVersion ) import qualified Paths_cabal_install (version) @@ -304,7 +307,11 @@ mainWorker args = do , hiddenCmd win32SelfUpgradeCommand win32SelfUpgradeAction , hiddenCmd actAsSetupCommand actAsSetupAction , hiddenCmd manpageCommand (manpageAction commandSpecs) - + -- ghc-mod supporting commands + , hiddenCmd CmdShowBuildInfo.showBuildInfoCommand + CmdShowBuildInfo.showBuildInfoAction + , hiddenCmd CmdWriteAutogenFiles.writeAutogenFilesCommand + CmdWriteAutogenFiles.writeAutogenFilesAction ] ++ concat [ newCmd CmdConfigure.configureCommand CmdConfigure.configureAction , newCmd CmdUpdate.updateCommand CmdUpdate.updateAction @@ -319,7 +326,6 @@ mainWorker args = do , newCmd CmdExec.execCommand CmdExec.execAction , newCmd CmdClean.cleanCommand CmdClean.cleanAction , newCmd CmdSdist.sdistCommand CmdSdist.sdistAction - , legacyCmd configureExCommand configureAction , legacyCmd updateCommand updateAction , legacyCmd buildCommand buildAction @@ -447,40 +453,80 @@ reconfigureAction flags@(configFlags, _) _ globalFlags = do checkFlags [] globalFlags config pure () -buildAction :: (BuildFlags, BuildExFlags) -> [String] -> Action -buildAction (buildFlags, buildExFlags) extraArgs globalFlags = do - let verbosity = fromFlagOrDefault normal (buildVerbosity buildFlags) - noAddSource = fromFlagOrDefault DontSkipAddSourceDepsCheck - (buildOnly buildExFlags) - (useSandbox, config) <- loadConfigOrSandboxConfig verbosity globalFlags - distPref <- findSavedDistPref config (buildDistPref buildFlags) - -- Calls 'configureAction' to do the real work, so nothing special has to be - -- done to support sandboxes. - config' <- - reconfigure configureAction - verbosity distPref useSandbox noAddSource (buildNumJobs buildFlags) - mempty [] globalFlags config - nixShell verbosity distPref globalFlags config $ do - maybeWithSandboxDirOnSearchPath useSandbox $ - build verbosity config' distPref buildFlags extraArgs +buildAction :: (BuildFlags, BuildExFlags) -> [String] -> Action +buildAction flags@(buildFlags, _) = buildActionForCommand + (Cabal.buildCommand defaultProgramDb) + verbosity + flags + where verbosity = fromFlagOrDefault normal (buildVerbosity buildFlags) + +showBuildInfoAction :: (BuildFlags, BuildExFlags) -> [String] -> Action +showBuildInfoAction flags@(buildFlags, _) = buildActionForCommand + (Cabal.showBuildInfoCommand defaultProgramDb) + verbosity + flags + -- Default silent verbosity so as not to pollute json output + where verbosity = fromFlagOrDefault silent (buildVerbosity buildFlags) + +buildActionForCommand :: CommandUI BuildFlags + -> Verbosity + -> (BuildFlags, BuildExFlags) + -> [String] + -> Action +buildActionForCommand commandUI verbosity (buildFlags, buildExFlags) extraArgs globalFlags + = do + let noAddSource = + fromFlagOrDefault DontSkipAddSourceDepsCheck (buildOnly buildExFlags) + (useSandbox, config) <- loadConfigOrSandboxConfig verbosity globalFlags + distPref <- findSavedDistPref config (buildDistPref buildFlags) + -- Calls 'configureAction' to do the real work, so nothing special has to be + -- done to support sandboxes. + config' <- reconfigure configureAction + verbosity + distPref + useSandbox + noAddSource + (buildNumJobs buildFlags) + mempty + [] + globalFlags + config + nixShell verbosity distPref globalFlags config $ do + maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand commandUI + verbosity + config' + distPref + buildFlags + extraArgs -- | Actually do the work of building the package. This is separate from -- 'buildAction' so that 'testAction' and 'benchmarkAction' do not invoke -- 'reconfigure' twice. build :: Verbosity -> SavedConfig -> FilePath -> BuildFlags -> [String] -> IO () -build verbosity config distPref buildFlags extraArgs = - setupWrapper verbosity setupOptions Nothing - (Cabal.buildCommand progDb) mkBuildFlags (const extraArgs) - where - progDb = defaultProgramDb - setupOptions = defaultSetupScriptOptions { useDistPref = distPref } +build = buildForCommand (Cabal.buildCommand defaultProgramDb) + +buildForCommand :: CommandUI BuildFlags + -> Verbosity + -> SavedConfig + -> FilePath + -> BuildFlags + -> [String] + -> IO () +buildForCommand command verbosity config distPref buildFlags extraArgs = + setupWrapper verbosity + setupOptions + Nothing + command + mkBuildFlags + (const extraArgs) + where + setupOptions = defaultSetupScriptOptions { useDistPref = distPref } - mkBuildFlags version = filterBuildFlags version config buildFlags' - buildFlags' = buildFlags - { buildVerbosity = toFlag verbosity - , buildDistPref = toFlag distPref - } + mkBuildFlags version = filterBuildFlags version config buildFlags' + buildFlags' = buildFlags { buildVerbosity = toFlag verbosity + , buildDistPref = toFlag distPref + } -- | Make sure that we don't pass new flags to setup scripts compiled against -- old versions of Cabal. @@ -1248,3 +1294,23 @@ manpageAction commands flagVerbosity extraArgs _ = do then dropExtension pname else pname putStrLn $ manpage cabalCmd commands + +--Further commands to support ghc-mod usage +writeAutogenFilesAction :: WriteAutogenFilesFlags -> [String] -> Action +writeAutogenFilesAction flags _ globalFlags = do + let verbosity = fromFlag (wafVerbosity flags) + load <- try (loadConfigOrSandboxConfig verbosity globalFlags) + let config = either (\(SomeException _) -> mempty) snd load + distPref <- findSavedDistPref config (wafDistPref flags) + pkg <- fmap LBI.localPkgDescr (getPersistBuildConfig distPref) + eLBI <- tryGetPersistBuildConfig distPref + case eLBI of + Left err -> case err of + -- Note: the build config could have been generated by a custom setup + -- script built against a different Cabal version, so it's crucial that + -- we ignore the bad version error here. + ConfigStateFileBadVersion _ _ _ -> pure () + _ -> die' verbosity (show err) + Right lbi -> do + initialBuildSteps distPref pkg lbi verbosity + pure () \ No newline at end of file From 533d6bffd1a19b0173406a9342d218c35ce01b7a Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 20 Mar 2019 20:06:08 +0100 Subject: [PATCH 03/43] Remove unused import --- Cabal/Distribution/Simple/Build.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 4105957511f..a6f93b97a21 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -69,7 +69,6 @@ import Distribution.Simple.PreProcess import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Program.Types import Distribution.Simple.Program.Db -import qualified Distribution.Simple.Program.HcPkg as HcPkg import Distribution.Simple.ShowBuildInfo import Distribution.Simple.BuildPaths import Distribution.Simple.Configure From 0469b47c0fa6d09294bd71d8750be35c1503af64 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 25 Mar 2019 15:42:53 +0100 Subject: [PATCH 04/43] Adopt coding style and edit comments --- Cabal/Distribution/Simple/Setup.hs | 2 +- .../Distribution/Client/CmdShowBuildInfo.hs | 8 +++--- cabal-install/Distribution/Client/Setup.hs | 4 +-- cabal-install/main/Main.hs | 26 ++++++------------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 16841db934c..b7636c03511 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -2210,7 +2210,7 @@ optionNumJobs get set = -- ------------------------------------------------------------ --- * ghc-mod support flags +-- * show-build-info command flags -- ------------------------------------------------------------ showBuildInfoCommand :: ProgramDb -> CommandUI BuildFlags diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index cc5a41bb6cc..7dda82df59a 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -1,7 +1,7 @@ -- | cabal-install CLI command: build -- module Distribution.Client.CmdShowBuildInfo ( - -- * The @build@ CLI and action + -- * The @show-build-info@ CLI and action showBuildInfoCommand, showBuildInfoAction ) where @@ -74,7 +74,7 @@ showBuildInfoCommand = Client.installCommand { } --- | The @build@ command does a lot. It brings the install plan up to date, +-- | The @show-build-info@ command does a lot. It brings the install plan up to date, -- selects that part of the plan needed by the given or implicit targets and -- then executes the plan. -- @@ -219,7 +219,7 @@ selectPackageTargets targetSelector targets -- | For a 'TargetComponent' 'TargetSelector', check if the component can be -- selected. -- --- For the @build@ command we just need the basic checks on being buildable etc. +-- For the @show-build-info@ command we just need the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget -> AvailableTarget k -> Either TargetProblem k @@ -229,7 +229,7 @@ selectComponentTarget subtarget = -- | The various error conditions that can occur when matching a --- 'TargetSelector' against 'AvailableTarget's for the @build@ command. +-- 'TargetSelector' against 'AvailableTarget's for the @show-build-info@ command. -- data TargetProblem = TargetProblemCommon TargetProblemCommon diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index b5c4f385efb..c55154bc16d 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -56,8 +56,6 @@ module Distribution.Client.Setup , doctestCommand , copyCommand , registerCommand - - --ghc-mod support commands , showBuildInfoCommand , writeAutogenFilesCommand, WriteAutogenFilesFlags(..) , parsePackageArgs @@ -3012,7 +3010,7 @@ relevantConfigValuesText vs = -- ------------------------------------------------------------ --- * Commands to support ghc-mod +-- * Commands to support show-build-info -- ------------------------------------------------------------ showBuildInfoCommand :: CommandUI (BuildFlags, BuildExFlags) diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index a55fe9fc979..c86c7c02cef 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -307,7 +307,6 @@ mainWorker args = do , hiddenCmd win32SelfUpgradeCommand win32SelfUpgradeAction , hiddenCmd actAsSetupCommand actAsSetupAction , hiddenCmd manpageCommand (manpageAction commandSpecs) - -- ghc-mod supporting commands , hiddenCmd CmdShowBuildInfo.showBuildInfoCommand CmdShowBuildInfo.showBuildInfoAction , hiddenCmd CmdWriteAutogenFiles.writeAutogenFilesCommand @@ -482,23 +481,13 @@ buildActionForCommand commandUI verbosity (buildFlags, buildExFlags) extraArgs g distPref <- findSavedDistPref config (buildDistPref buildFlags) -- Calls 'configureAction' to do the real work, so nothing special has to be -- done to support sandboxes. - config' <- reconfigure configureAction - verbosity - distPref - useSandbox - noAddSource - (buildNumJobs buildFlags) - mempty - [] - globalFlags - config + config' <- reconfigure + configureAction verbosity distPref useSandbox noAddSource + (buildNumJobs buildFlags) mempty [] globalFlags config + nixShell verbosity distPref globalFlags config $ do - maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand commandUI - verbosity - config' - distPref - buildFlags - extraArgs + maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand + commandUI verbosity config' distPref buildFlags extraArgs -- | Actually do the work of building the package. This is separate from -- 'buildAction' so that 'testAction' and 'benchmarkAction' do not invoke @@ -506,6 +495,7 @@ buildActionForCommand commandUI verbosity (buildFlags, buildExFlags) extraArgs g build :: Verbosity -> SavedConfig -> FilePath -> BuildFlags -> [String] -> IO () build = buildForCommand (Cabal.buildCommand defaultProgramDb) +-- | Helper function buildForCommand :: CommandUI BuildFlags -> Verbosity -> SavedConfig @@ -1295,7 +1285,7 @@ manpageAction commands flagVerbosity extraArgs _ = do else pname putStrLn $ manpage cabalCmd commands ---Further commands to support ghc-mod usage +--Further commands to support show-build-info usage writeAutogenFilesAction :: WriteAutogenFilesFlags -> [String] -> Action writeAutogenFilesAction flags _ globalFlags = do let verbosity = fromFlag (wafVerbosity flags) From c917a06efdffdf1d31b3ac941db60ef4a59a31e6 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 25 Mar 2019 16:07:17 +0100 Subject: [PATCH 05/43] Adopt coding style --- .../Distribution/Client/CmdShowBuildInfo.hs | 2 +- cabal-install/main/Main.hs | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 7dda82df59a..1f8f79e833f 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -1,4 +1,4 @@ --- | cabal-install CLI command: build +-- | cabal-install CLI command: new-show-build-info -- module Distribution.Client.CmdShowBuildInfo ( -- * The @show-build-info@ CLI and action diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index c86c7c02cef..2af2ffa8be2 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -485,7 +485,7 @@ buildActionForCommand commandUI verbosity (buildFlags, buildExFlags) extraArgs g configureAction verbosity distPref useSandbox noAddSource (buildNumJobs buildFlags) mempty [] globalFlags config - nixShell verbosity distPref globalFlags config $ do + nixShell verbosity distPref globalFlags config $ maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand commandUI verbosity config' distPref buildFlags extraArgs @@ -504,12 +504,7 @@ buildForCommand :: CommandUI BuildFlags -> [String] -> IO () buildForCommand command verbosity config distPref buildFlags extraArgs = - setupWrapper verbosity - setupOptions - Nothing - command - mkBuildFlags - (const extraArgs) + setupWrapper verbosity setupOptions Nothing command mkBuildFlags (const extraArgs) where setupOptions = defaultSetupScriptOptions { useDistPref = distPref } @@ -558,8 +553,8 @@ replAction (replFlags, buildExFlags) extraArgs globalFlags = do -- be done to support sandboxes. _ <- reconfigure configureAction - verbosity distPref useSandbox noAddSource NoFlag - mempty [] globalFlags config + verbosity distPref useSandbox noAddSource NoFlag + mempty [] globalFlags config let progDb = defaultProgramDb setupOptions = defaultSetupScriptOptions { useCabalVersion = orLaterVersion $ mkVersion [1,18,0] From dae46d9ba2d9b27c260793db3e8be5c8da62442b Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 25 Mar 2019 18:34:56 +0100 Subject: [PATCH 06/43] Use prett show to show component name --- Cabal/Distribution/Simple/ShowBuildInfo.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cabal/Distribution/Simple/ShowBuildInfo.hs b/Cabal/Distribution/Simple/ShowBuildInfo.hs index 21bbb44c876..fb08ca0e2bf 100644 --- a/Cabal/Distribution/Simple/ShowBuildInfo.hs +++ b/Cabal/Distribution/Simple/ShowBuildInfo.hs @@ -69,6 +69,7 @@ import Distribution.Simple.Utils (cabalVersion) import Distribution.Simple.Utils.Json import Distribution.Types.TargetInfo import Distribution.Text +import Distribution.Pretty -- | Construct a JSON document describing the build information for a package mkBuildInfo :: PackageDescription -- ^ Mostly information from the .cabal file @@ -89,7 +90,7 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info ] mkCompilerInfo = JsonObject - [ "flavour" .= JsonString (show $ compilerFlavor $ compiler lbi) + [ "flavour" .= JsonString (prettyShow $ compilerFlavor $ compiler lbi) , "compiler_id" .= JsonString (showCompilerId $ compiler lbi) , "path" .= path ] @@ -99,7 +100,7 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info mkComponentInfo (name, clbi) = JsonObject [ "type" .= JsonString compType - , "name" .= JsonString (show name) + , "name" .= JsonString (prettyShow name) , "compiler_args" .= JsonArray (map JsonString $ getCompilerArgs bi lbi clbi) , "modules" .= JsonArray (map (JsonString . display) modules) , "source_files" .= JsonArray (map JsonString source_files) From b0ecf2d8cabb2a9325646964c4c3219b205fea78 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 27 Mar 2019 19:07:54 +0100 Subject: [PATCH 07/43] Add help message for show-build-info cmd --- .../Distribution/Client/CmdShowBuildInfo.hs | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 1f8f79e833f..074eb6e265b 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -46,30 +46,16 @@ showBuildInfoCommand = Client.installCommand { commandSynopsis = "Show project build information", commandUsage = usageAlternatives "new-show-build-info" [ "[TARGETS] [FLAGS]" ], commandDescription = Just $ \_ -> wrapText $ - "Build one or more targets from within the project. The available " - ++ "targets are the packages in the project as well as individual " - ++ "components within those packages, including libraries, executables, " - ++ "test-suites or benchmarks. Targets can be specified by name or " - ++ "location. If no target is specified then the default is to build " - ++ "the package in the current directory.\n\n" - - ++ "Dependencies are built or rebuilt as necessary. Additional " - ++ "configuration flags can be specified on the command line and these " - ++ "extend the project configuration from the 'cabal.project', " - ++ "'cabal.project.local' and other files.", + "Provides detailed json output for the given package.\n" + ++ "Contains information about the different build components and compiler flags.\n", commandNotes = Just $ \pname -> "Examples:\n" - ++ " " ++ pname ++ " new-build\n" - ++ " Build the package in the current directory or all packages in the project\n" - ++ " " ++ pname ++ " new-build pkgname\n" - ++ " Build the package named pkgname in the project\n" - ++ " " ++ pname ++ " new-build ./pkgfoo\n" - ++ " Build the package in the ./pkgfoo directory\n" - ++ " " ++ pname ++ " new-build cname\n" - ++ " Build the component named cname module Distribution.Client.InstallPlanin the project\n" - ++ " " ++ pname ++ " new-build cname --module Distribution.Client.InstallPlanenable-profiling\n" - ++ " Build the component in profilingmodule Distribution.Client.InstallPlan mode (including dependencies as needed)\n\n" - + ++ " " ++ pname ++ " new-show-build-info\n" + ++ " Shows build information about the current package\n" + ++ " " ++ pname ++ " new-show-build-info .\n" + ++ " Shows build information about the current package\n" + ++ " " ++ pname ++ " new-show-build-info ./pkgname \n" + ++ " Shows build information about the package located in './pkgname'\n" ++ cmdCommonHelpTextNewBuildBeta } From 3ff927649935464833c2f63889915b0309fe41c3 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 2 Apr 2019 21:40:29 +0200 Subject: [PATCH 08/43] Use mempty as the clientInstallFlags --- cabal-install/Distribution/Client/CmdShowBuildInfo.hs | 2 +- cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 074eb6e265b..1a013d64b3f 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -106,7 +106,7 @@ showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, tes verbosity = fromFlagOrDefault silent (configVerbosity configFlags) cliConfig = commandLineFlagsToProjectConfig globalFlags configFlags configExFlags - installFlags defaultClientInstallFlags + installFlags mempty -- Not needed here haddockFlags testFlags diff --git a/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs b/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs index 86a80b6fa53..b6b4608d4d4 100644 --- a/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs +++ b/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs @@ -96,7 +96,7 @@ writeAutogenFilesAction (configFlags, configExFlags, installFlags, haddockFlags, verbosity = fromFlagOrDefault normal (configVerbosity configFlags) cliConfig = commandLineFlagsToProjectConfig globalFlags configFlags configExFlags - installFlags defaultClientInstallFlags + installFlags mempty -- Not needed here haddockFlags testFlags configured ctx = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanToExecute ctx)] From 73c438d533058fb4855a8c3ae48f2ff79e522f87 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 3 Apr 2019 16:43:22 +0200 Subject: [PATCH 09/43] Remove Command WriteAutogenFiles --- Cabal/Distribution/Simple.hs | 8 - Cabal/Distribution/Simple/Build.hs | 1 - Cabal/Distribution/Simple/Setup.hs | 31 --- .../Client/CmdWriteAutogenFiles.hs | 220 ------------------ cabal-install/Distribution/Client/Setup.hs | 7 - cabal-install/cabal-install.cabal | 1 - cabal-install/main/Main.hs | 26 +-- 7 files changed, 1 insertion(+), 293 deletions(-) delete mode 100644 cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index 85165459016..ef4680a508d 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -180,7 +180,6 @@ defaultMainHelper hooks args = topHandler $ do \fs as -> configureAction hooks fs as >> return () ,buildCommand progs `commandAddAction` buildAction hooks ,showBuildInfoCommand progs `commandAddAction` showBuildInfoAction hooks - ,writeAutogenFilesCommand progs `commandAddAction` writeAutogenFilesAction hooks ,replCommand progs `commandAddAction` replAction hooks ,installCommand `commandAddAction` installAction hooks ,copyCommand `commandAddAction` copyAction hooks @@ -287,13 +286,6 @@ showBuildInfoAction hooks flags args = do postBuild hooks args flags' pkg_descr lbi' -writeAutogenFilesAction :: UserHooks -> WriteAutogenFilesFlags -> Args -> IO () -writeAutogenFilesAction hooks flags _ = do - distPref <- findDistPrefOrDefault (wafDistPref flags) - let verbosity = fromFlag $ wafVerbosity flags - lbi <- getBuildConfig hooks verbosity distPref - initialBuildSteps distPref (localPkgDescr lbi) lbi verbosity - replAction :: UserHooks -> ReplFlags -> Args -> IO () replAction hooks flags args = do distPref <- findDistPrefOrDefault (replDistPref flags) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index a6f93b97a21..e10cdaf8a73 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -25,7 +25,6 @@ module Distribution.Simple.Build ( initialBuildSteps, createInternalPackageDB, componentInitialBuildSteps, - writeAutogenFiles, ) where import Prelude () diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index b7636c03511..20068c85fa1 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -2252,37 +2252,6 @@ showBuildInfoCommand progDb = CommandUI ++ buildOptions progDb showOrParseArgs } -writeAutogenFilesCommand :: ProgramDb -> CommandUI WriteAutogenFilesFlags -writeAutogenFilesCommand progDb = CommandUI - { commandName = "write-autogen-files" - , commandSynopsis = "Generate and write out the Paths_.hs and cabal_macros.h files" - , commandDescription = Just $ \_ -> wrapText $ - "Components encompass executables, tests, and benchmarks.\n" - ++ "\n" - ++ "Affected by configuration options, see `configure`.\n" - , commandNotes = Just $ \pname -> - "Examples:\n" - ++ " " ++ pname ++ " write-autogen-files " - ++ " All the components in the package\n" - ++ " " ++ pname ++ " write-autogen-files foo " - ++ " A component (i.e. lib, exe, test suite)\n\n" - ++ programFlagsDescription progDb - , commandUsage = usageAlternatives "write-autogen-files" $ - [ "[FLAGS]" ] - , commandDefaultFlags = WriteAutogenFilesFlags NoFlag (toFlag normal) - , commandOptions = \showOrParseArgs -> - [ optionVerbosity - wafVerbosity (\v flags -> flags { wafVerbosity = v }) - - , optionDistPref - wafDistPref (\d flags -> flags { wafDistPref = d }) showOrParseArgs - ] - } - -data WriteAutogenFilesFlags = WriteAutogenFilesFlags { - wafDistPref :: Flag FilePath, - wafVerbosity :: Flag Verbosity -} deriving Show -- ------------------------------------------------------------ -- * Other Utils -- ------------------------------------------------------------ diff --git a/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs b/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs deleted file mode 100644 index b6b4608d4d4..00000000000 --- a/cabal-install/Distribution/Client/CmdWriteAutogenFiles.hs +++ /dev/null @@ -1,220 +0,0 @@ --- | cabal-install CLI command: build --- -module Distribution.Client.CmdWriteAutogenFiles ( - -- * The @build@ CLI and action - writeAutogenFilesCommand, - writeAutogenFilesAction - ) where - -import Distribution.Client.ProjectOrchestration -import Distribution.Client.CmdErrorMessages -import Distribution.Client.CmdInstall.ClientInstallFlags - -import Distribution.Client.Setup - ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags, WriteAutogenFilesFlags(..) ) -import qualified Distribution.Client.Setup as Client -import Distribution.Simple.Setup - ( HaddockFlags, fromFlagOrDefault, Flag(..), TestFlags ) -import Distribution.Simple.Command - ( CommandUI(..), usageAlternatives ) -import Distribution.Verbosity - ( Verbosity, normal ) -import Distribution.Simple.Utils - ( wrapText, die' ) -import Distribution.Simple.Configure (tryGetPersistBuildConfig) - -import qualified Data.Map as Map -import qualified Distribution.Simple.Setup as Cabal -import Distribution.Client.SetupWrapper -import Distribution.Simple.Program ( defaultProgramDb ) -import qualified Distribution.Client.InstallPlan as InstallPlan -import Distribution.Client.ProjectPlanning.Types -import Distribution.Client.ProjectPlanning ( - setupHsScriptOptions, setupHsConfigureFlags, setupHsConfigureArgs - ) -import Distribution.Client.DistDirLayout (distBuildDirectory) -import Distribution.Client.Types ( PackageLocation(..), GenericReadyPackage(..) ) -import Distribution.Client.JobControl (newLock, Lock) - -writeAutogenFilesCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) -writeAutogenFilesCommand = Client.installCommand { - commandName = "new-write-autogen-files", - commandSynopsis = "", - commandUsage = usageAlternatives "new-write-autogen-files" [ "[FLAGS]" ], - commandDescription = Just $ \_ -> wrapText $ - "Generate and write out the Paths_.hs and cabal_macros.h files\n" - ++ "for all components in the project", - commandNotes = Just $ \pname -> - "Examples:\n" - ++ " " ++ pname ++ " new-write-autogen-files\n" - ++ " Write for all packages in the project\n" - } - -writeAutogenFilesAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) - -> [String] -> GlobalFlags -> IO () -writeAutogenFilesAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags) - targetStrings globalFlags = do - baseCtx <- establishProjectBaseContext verbosity cliConfig - let baseCtx' = baseCtx { - buildSettings = (buildSettings baseCtx) { - buildSettingDryRun = True - } - } - targetSelectors <- either (reportTargetSelectorProblems verbosity) return - =<< readTargetSelectors (localPackages baseCtx') Nothing targetStrings - - buildCtx <- - runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do - -- Interpret the targets on the command line as build targets - -- (as opposed to say repl or haddock targets). - targets <- either (reportTargetProblems verbosity) return - $ resolveTargets - selectPackageTargets - selectComponentTarget - TargetProblemCommon - elaboratedPlan - Nothing - targetSelectors - - let elaboratedPlan' = pruneInstallPlanToTargets - TargetActionBuild - targets - elaboratedPlan - elaboratedPlan'' <- - if buildSettingOnlyDeps (buildSettings baseCtx') - then either (reportCannotPruneDependencies verbosity) return $ - pruneInstallPlanToDependencies (Map.keysSet targets) - elaboratedPlan' - else return elaboratedPlan' - - return (elaboratedPlan'', targets) - - scriptLock <- newLock - writeAutogenFiles verbosity baseCtx' buildCtx scriptLock (configured buildCtx) - - where - verbosity = fromFlagOrDefault normal (configVerbosity configFlags) - cliConfig = commandLineFlagsToProjectConfig - globalFlags configFlags configExFlags - installFlags mempty -- Not needed here - haddockFlags - testFlags - configured ctx = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanToExecute ctx)] - - -writeAutogenFiles :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> IO () -writeAutogenFiles verbosity baseCtx buildCtx lock pkgs = mapM_ runWrapper pkgs - where runWrapper pkg = do - let shared = elaboratedShared buildCtx - install = elaboratedPlanOriginal buildCtx - dirLayout = distDirLayout baseCtx - buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) - srcDir = case (elabPkgSourceLocation pkg) of - LocalUnpackedPackage fp -> fp - _ -> "" - scriptOptions = setupHsScriptOptions - (ReadyPackage pkg) - install - shared - dirLayout - srcDir - buildDir - False - lock - configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir - configureArgs = setupHsConfigureArgs pkg - --Configure the package if there's no existing config, - lbi <- tryGetPersistBuildConfig buildDir - case lbi of - Left _ -> setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.configureCommand defaultProgramDb) - (const $ configureFlags) - (const configureArgs) - Right _ -> pure () - setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.writeAutogenFilesCommand defaultProgramDb) - (const $ WriteAutogenFilesFlags (Flag buildDir) (Flag verbosity)) - (const []) - --- | This defines what a 'TargetSelector' means for the @write-autogen-files@ command. --- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, --- or otherwise classifies the problem. --- --- For the @write-autogen-files@ command select all components except non-buildable and disabled --- tests\/benchmarks, fail if there are no such components --- -selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] -selectPackageTargets targetSelector targets - - -- If there are any buildable targets then we select those - | not (null targetsBuildable) - = Right targetsBuildable - - -- If there are targets but none are buildable then we report those - | not (null targets) - = Left (TargetProblemNoneEnabled targetSelector targets') - - -- If there are no targets at all then we report that - | otherwise - = Left (TargetProblemNoTargets targetSelector) - where - targets' = forgetTargetsDetail targets - targetsBuildable = selectBuildableTargetsWith - (buildable targetSelector) - targets - - -- When there's a target filter like "pkg:tests" then we do select tests, - -- but if it's just a target like "pkg" then we don't build tests unless - -- they are requested by default (i.e. by using --enable-tests) - buildable (TargetPackage _ _ Nothing) TargetNotRequestedByDefault = False - buildable (TargetAllPackages Nothing) TargetNotRequestedByDefault = False - buildable _ _ = True - --- | For a 'TargetComponent' 'TargetSelector', check if the component can be --- selected. --- --- For the @build@ command we just need the basic checks on being buildable etc. --- -selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k -selectComponentTarget subtarget = - either (Left . TargetProblemCommon) Right - . selectComponentTargetBasic subtarget - - --- | The various error conditions that can occur when matching a --- 'TargetSelector' against 'AvailableTarget's for the @build@ command. --- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - deriving (Eq, Show) - -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a -reportTargetProblems verbosity = - die' verbosity . unlines . map renderTargetProblem - -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = - renderTargetProblemCommon "build" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = - renderTargetProblemNoneEnabled "build" targetSelector targets -renderTargetProblem(TargetProblemNoTargets targetSelector) = - renderTargetProblemNoTargets "build" targetSelector - -reportCannotPruneDependencies :: Verbosity -> CannotPruneDependencies -> IO a -reportCannotPruneDependencies verbosity = - die' verbosity . renderCannotPruneDependencies - diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index c55154bc16d..68d5ab0ff57 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -57,7 +57,6 @@ module Distribution.Client.Setup , copyCommand , registerCommand , showBuildInfoCommand - , writeAutogenFilesCommand, WriteAutogenFilesFlags(..) , parsePackageArgs , liftOptions , yesNoOpt @@ -106,7 +105,6 @@ import Distribution.Simple.Setup , SDistFlags(..), HaddockFlags(..) , CleanFlags(..), DoctestFlags(..) , CopyFlags(..), RegisterFlags(..) - , WriteAutogenFilesFlags(..) , readPackageDbList, showPackageDbList , Flag(..), toFlag, flagToMaybe, flagToList, maybeToFlag , BooleanFlag(..), optionVerbosity @@ -200,7 +198,6 @@ globalCommand commands = CommandUI { , "haddock" , "hscolour" , "show-build-info" - , "write-autogen-files" , "exec" , "new-build" , "new-configure" @@ -288,7 +285,6 @@ globalCommand commands = CommandUI { , addCmd "report" , par , addCmd "show-build-info" - , addCmd "write-autogen-files" , addCmd "freeze" , addCmd "gen-bounds" , addCmd "outdated" @@ -3027,6 +3023,3 @@ showBuildInfoCommand = parent { setSnd b (a,_) = (a,b) parent = Cabal.showBuildInfoCommand defaultProgramDb - -writeAutogenFilesCommand :: CommandUI WriteAutogenFilesFlags -writeAutogenFilesCommand = Cabal.writeAutogenFilesCommand defaultProgramDb \ No newline at end of file diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 989456e90b7..ea4539af8cb 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -162,7 +162,6 @@ executable cabal Distribution.Client.CmdBuild Distribution.Client.CmdClean Distribution.Client.CmdShowBuildInfo - Distribution.Client.CmdWriteAutogenFiles Distribution.Client.CmdConfigure Distribution.Client.CmdUpdate Distribution.Client.CmdErrorMessages diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 2af2ffa8be2..8df2d6f6043 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -52,7 +52,6 @@ import Distribution.Client.Setup , doctestCommand , copyCommand , registerCommand - , WriteAutogenFilesFlags(..) ) import Distribution.Simple.Setup ( HaddockTarget(..) @@ -85,7 +84,6 @@ import qualified Distribution.Client.CmdConfigure as CmdConfigure import qualified Distribution.Client.CmdUpdate as CmdUpdate import qualified Distribution.Client.CmdBuild as CmdBuild import qualified Distribution.Client.CmdShowBuildInfo as CmdShowBuildInfo -import qualified Distribution.Client.CmdWriteAutogenFiles as CmdWriteAutogenFiles import qualified Distribution.Client.CmdRepl as CmdRepl import qualified Distribution.Client.CmdFreeze as CmdFreeze import qualified Distribution.Client.CmdHaddock as CmdHaddock @@ -158,7 +156,7 @@ import qualified Distribution.Simple as Simple import qualified Distribution.Make as Make import qualified Distribution.Types.UnqualComponentName as Make import Distribution.Simple.Build - ( startInterpreter, initialBuildSteps ) + ( startInterpreter ) import Distribution.Simple.Command ( CommandParse(..), CommandUI(..), Command, CommandSpec(..) , CommandType(..), commandsRun, commandAddAction, hiddenCommand @@ -309,8 +307,6 @@ mainWorker args = do , hiddenCmd manpageCommand (manpageAction commandSpecs) , hiddenCmd CmdShowBuildInfo.showBuildInfoCommand CmdShowBuildInfo.showBuildInfoAction - , hiddenCmd CmdWriteAutogenFiles.writeAutogenFilesCommand - CmdWriteAutogenFiles.writeAutogenFilesAction ] ++ concat [ newCmd CmdConfigure.configureCommand CmdConfigure.configureAction , newCmd CmdUpdate.updateCommand CmdUpdate.updateAction @@ -1279,23 +1275,3 @@ manpageAction commands flagVerbosity extraArgs _ = do then dropExtension pname else pname putStrLn $ manpage cabalCmd commands - ---Further commands to support show-build-info usage -writeAutogenFilesAction :: WriteAutogenFilesFlags -> [String] -> Action -writeAutogenFilesAction flags _ globalFlags = do - let verbosity = fromFlag (wafVerbosity flags) - load <- try (loadConfigOrSandboxConfig verbosity globalFlags) - let config = either (\(SomeException _) -> mempty) snd load - distPref <- findSavedDistPref config (wafDistPref flags) - pkg <- fmap LBI.localPkgDescr (getPersistBuildConfig distPref) - eLBI <- tryGetPersistBuildConfig distPref - case eLBI of - Left err -> case err of - -- Note: the build config could have been generated by a custom setup - -- script built against a different Cabal version, so it's crucial that - -- we ignore the bad version error here. - ConfigStateFileBadVersion _ _ _ -> pure () - _ -> die' verbosity (show err) - Right lbi -> do - initialBuildSteps distPref pkg lbi verbosity - pure () \ No newline at end of file From dc93de6119440bb5d545ebce50ff9c808bcf33e0 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 3 Apr 2019 20:57:32 +0200 Subject: [PATCH 10/43] Adapt naming to fit to plan.json --- Cabal/Distribution/Simple/ShowBuildInfo.hs | 53 +++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Cabal/Distribution/Simple/ShowBuildInfo.hs b/Cabal/Distribution/Simple/ShowBuildInfo.hs index fb08ca0e2bf..27eeb1ace21 100644 --- a/Cabal/Distribution/Simple/ShowBuildInfo.hs +++ b/Cabal/Distribution/Simple/ShowBuildInfo.hs @@ -1,8 +1,9 @@ -- | -- This module defines a simple JSON-based format for exporting basic -- information about a Cabal package and the compiler configuration Cabal --- would use to build it. This can be produced with the @cabal show-build-info@ --- command. +-- would use to build it. This can be produced with the +-- @cabal new-show-build-info@ command. +-- -- -- This format is intended for consumption by external tooling and should -- therefore be rather stable. Moreover, this allows tooling users to avoid @@ -13,42 +14,42 @@ -- Below is an example of the output this module produces, -- -- @ --- { "cabal_version": "1.23.0.0", +-- { "cabal-version": "1.23.0.0", -- "compiler": { -- "flavor": "GHC", --- "compiler_id": "ghc-7.10.2", +-- "compiler-id": "ghc-7.10.2", -- "path": "/usr/bin/ghc", -- }, -- "components": [ --- { "type": "library", --- "name": "CLibName", --- "compiler_args": +-- { "type": "lib", +-- "name": "lib:Cabal", +-- "compiler-args": -- ["-O", "-XHaskell98", "-Wall", -- "-package-id", "parallel-3.2.0.6-b79c38c5c25fff77f3ea7271851879eb"] -- "modules": ["Project.ModA", "Project.ModB", "Paths_project"], --- "source_files": [], --- "source_dirs": ["src"] +-- "src-files": [], +-- "src-dirs": ["src"] -- } -- ] -- } -- @ -- --- The @cabal_version@ property provides the version of the Cabal library +-- The @cabal-version@ property provides the version of the Cabal library -- which generated the output. The @compiler@ property gives some basic -- information about the compiler Cabal would use to compile the package. -- -- The @components@ property gives a list of the Cabal 'Component's defined by -- the package. Each has, -- --- * @type@: the type of the component (one of @library@, @executable@, --- @test-suite@, or @benchmark@) +-- * @type@: the type of the component (one of @lib@, @exe@, +-- @test@, @bench@, or @flib@) -- * @name@: a string serving to uniquely identify the component within the -- package. --- * @compiler_args@: the command-line arguments Cabal would pass to the +-- * @compiler-args@: the command-line arguments Cabal would pass to the -- compiler to compile the component -- * @modules@: the modules belonging to the component --- * @source_dirs@: a list of directories where the modules might be found --- * @source_files@: any other Haskell sources needed by the component +-- * @src-dirs@: a list of directories where the modules might be found +-- * @src-files@: any other Haskell sources needed by the component -- -- Note: At the moment this is only supported when using the GHC compiler. -- @@ -84,14 +85,14 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info k .= v = (k, v) info = JsonObject - [ "cabal_version" .= JsonString (display cabalVersion) + [ "cabal-version" .= JsonString (display cabalVersion) , "compiler" .= mkCompilerInfo , "components" .= JsonArray (map mkComponentInfo componentsToBuild) ] mkCompilerInfo = JsonObject [ "flavour" .= JsonString (prettyShow $ compilerFlavor $ compiler lbi) - , "compiler_id" .= JsonString (showCompilerId $ compiler lbi) + , "compiler-id" .= JsonString (showCompilerId $ compiler lbi) , "path" .= path ] where @@ -101,25 +102,25 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info mkComponentInfo (name, clbi) = JsonObject [ "type" .= JsonString compType , "name" .= JsonString (prettyShow name) - , "compiler_args" .= JsonArray (map JsonString $ getCompilerArgs bi lbi clbi) + , "compiler-args" .= JsonArray (map JsonString $ getCompilerArgs bi lbi clbi) , "modules" .= JsonArray (map (JsonString . display) modules) - , "source_files" .= JsonArray (map JsonString source_files) - , "source_dirs" .= JsonArray (map JsonString $ hsSourceDirs bi) + , "src-files" .= JsonArray (map JsonString sourceFiles) + , "src-dirs" .= JsonArray (map JsonString $ hsSourceDirs bi) ] where bi = componentBuildInfo comp Just comp = lookupComponent pkg_descr name compType = case comp of - CLib _ -> "library" - CExe _ -> "executable" - CTest _ -> "test-suite" - CBench _ -> "benchmark" - CFLib _ -> "foreign-library" + CLib _ -> "lib" + CExe _ -> "exe" + CTest _ -> "test" + CBench _ -> "bench" + CFLib _ -> "flib" modules = case comp of CLib lib -> explicitLibModules lib CExe exe -> exeModules exe _ -> [] - source_files = case comp of + sourceFiles = case comp of CLib _ -> [] CExe exe -> [modulePath exe] _ -> [] From 8c61157b5cd80aff47ea42558960618bac9d046f Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 11 Apr 2019 14:34:21 +0200 Subject: [PATCH 11/43] Integrate PR change requests --- Cabal/Distribution/Simple/Build.hs | 1 + Cabal/Distribution/Simple/Utils/Json.hs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index e10cdaf8a73..a69a6e57cc4 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -25,6 +25,7 @@ module Distribution.Simple.Build ( initialBuildSteps, createInternalPackageDB, componentInitialBuildSteps, + writeAutogenFiles ) where import Prelude () diff --git a/Cabal/Distribution/Simple/Utils/Json.hs b/Cabal/Distribution/Simple/Utils/Json.hs index b8447fc5075..f748a340b08 100644 --- a/Cabal/Distribution/Simple/Utils/Json.hs +++ b/Cabal/Distribution/Simple/Utils/Json.hs @@ -1,3 +1,5 @@ +-- | Utility json lib for Cabal +-- TODO: Remove it again. module Distribution.Simple.Utils.Json ( Json(..) , renderJson From c677b5b9f58c1d65f387fc5947461ee273681498 Mon Sep 17 00:00:00 2001 From: fendor Date: Fri, 12 Apr 2019 17:39:40 +0200 Subject: [PATCH 12/43] Add flags for new-show-build-info Add functioning flag `--buildinfo-json-output=FILE` Add custom flags to parse more flags. Dont write always to stdout but to a file if specified. --- Cabal/Distribution/Simple.hs | 19 ++-- Cabal/Distribution/Simple/Build.hs | 6 +- Cabal/Distribution/Simple/Setup.hs | 50 +++++++++-- cabal-install/Distribution/Client/CmdBuild.hs | 3 +- .../Distribution/Client/CmdShowBuildInfo.hs | 90 ++++++++++++++----- cabal-install/Distribution/Client/Setup.hs | 4 +- cabal-install/main/Main.hs | 15 ++-- 7 files changed, 136 insertions(+), 51 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index ef4680a508d..94a35f2b911 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -265,13 +265,16 @@ buildAction hooks flags args = do (return lbi { withPrograms = progs }) hooks flags' { buildArgs = args } args -showBuildInfoAction :: UserHooks -> BuildFlags -> Args -> IO () -showBuildInfoAction hooks flags args = do +showBuildInfoAction :: UserHooks -> ShowBuildInfoFlags -> Args -> IO () +showBuildInfoAction hooks a@(ShowBuildInfoFlags flags fileOutput _) args = do + print a distPref <- findDistPrefOrDefault (buildDistPref flags) let verbosity = fromFlag $ buildVerbosity flags - flags' = flags { buildDistPref = toFlag distPref } - lbi <- getBuildConfig hooks verbosity distPref + let flags' = flags { buildDistPref = toFlag distPref + , buildCabalFilePath = maybeToFlag (cabalFilePath lbi) + } + progs <- reconfigurePrograms verbosity (buildProgramPaths flags') (buildProgramArgs flags') @@ -281,9 +284,11 @@ showBuildInfoAction hooks flags args = do let lbi' = lbi { withPrograms = progs } pkg_descr0 = localPkgDescr lbi' pkg_descr = updatePackageDescription pbi pkg_descr0 - -- TODO: Somehow don't ignore build hook? - showBuildInfo pkg_descr lbi' flags - + -- TODO: Somehow don't ignore build hook? + buildInfoString <- showBuildInfo pkg_descr lbi' flags + + maybe (putStrLn buildInfoString) (\fp -> appendFile fp buildInfoString) (fileOutput) + postBuild hooks args flags' pkg_descr lbi' replAction :: UserHooks -> ReplFlags -> Args -> IO () diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index a69a6e57cc4..331c367d8de 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -25,7 +25,7 @@ module Distribution.Simple.Build ( initialBuildSteps, createInternalPackageDB, componentInitialBuildSteps, - writeAutogenFiles + writeAutogenFiles, ) where import Prelude () @@ -133,13 +133,13 @@ build pkg_descr lbi flags suffixes = do showBuildInfo :: PackageDescription -- ^ Mostly information from the .cabal file -> LocalBuildInfo -- ^ Configuration information -> BuildFlags -- ^ Flags that the user passed to build - -> IO () + -> IO String showBuildInfo pkg_descr lbi flags = do let verbosity = fromFlag (buildVerbosity flags) targets <- readTargetInfos verbosity pkg_descr lbi (buildArgs flags) let targetsToBuild = neededTargetsInBuildOrder' pkg_descr lbi (map nodeKey targets) doc = mkBuildInfo pkg_descr lbi flags targetsToBuild - putStrLn $ renderJson doc "" + return $ renderJson doc "" repl :: PackageDescription -- ^ Mostly information from the .cabal file diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 20068c85fa1..b3aee06fab3 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -45,9 +45,7 @@ module Distribution.Simple.Setup ( HaddockFlags(..), emptyHaddockFlags, defaultHaddockFlags, haddockCommand, HscolourFlags(..), emptyHscolourFlags, defaultHscolourFlags, hscolourCommand, BuildFlags(..), emptyBuildFlags, defaultBuildFlags, buildCommand, - showBuildInfoCommand, - writeAutogenFilesCommand, - WriteAutogenFilesFlags(..), + ShowBuildInfoFlags(..), defaultShowBuildFlags, showBuildInfoCommand, ReplFlags(..), defaultReplFlags, replCommand, CleanFlags(..), emptyCleanFlags, defaultCleanFlags, cleanCommand, RegisterFlags(..), emptyRegisterFlags, defaultRegisterFlags, registerCommand, @@ -2213,7 +2211,21 @@ optionNumJobs get set = -- * show-build-info command flags -- ------------------------------------------------------------ -showBuildInfoCommand :: ProgramDb -> CommandUI BuildFlags +data ShowBuildInfoFlags = ShowBuildInfoFlags + { buildInfoBuildFlags :: BuildFlags + , buildInfoOutputFile :: Maybe FilePath + , buildInfoUnitIds :: Maybe [String] + } deriving Show + +defaultShowBuildFlags :: ShowBuildInfoFlags +defaultShowBuildFlags = + ShowBuildInfoFlags + { buildInfoBuildFlags = defaultBuildFlags + , buildInfoOutputFile = Nothing + , buildInfoUnitIds = Nothing + } + +showBuildInfoCommand :: ProgramDb -> CommandUI ShowBuildInfoFlags showBuildInfoCommand progDb = CommandUI { commandName = "show-build-info" , commandSynopsis = "Emit details about how a package would be built." @@ -2241,16 +2253,40 @@ showBuildInfoCommand progDb = CommandUI [ "[FLAGS]" , "COMPONENTS [FLAGS]" ] - , commandDefaultFlags = defaultBuildFlags + , commandDefaultFlags = defaultShowBuildFlags , commandOptions = \showOrParseArgs -> + parseBuildFlagsForShowBuildInfoFlags showOrParseArgs progDb + ++ + [ option [] ["buildinfo-json-output"] + "Write the result to the given file instead of stdout" + buildInfoOutputFile (\pf flags -> flags { buildInfoOutputFile = pf }) + (reqArg' "FILE" Just (maybe [] pure)), + option [] ["unit-ids-json"] + "Show build-info only for selected unit-id's." + buildInfoUnitIds (\pf flags -> flags { buildInfoUnitIds = pf }) + (reqArg' "UNIT-ID" (Just . words) (fromMaybe [] )) + ] + + } + +parseBuildFlagsForShowBuildInfoFlags :: ShowOrParseArgs -> ProgramDb -> [OptionField ShowBuildInfoFlags] +parseBuildFlagsForShowBuildInfoFlags showOrParseArgs progDb = + map + (liftOption + buildInfoBuildFlags + (\bf flags -> flags { buildInfoBuildFlags = bf } ) + ) + buildFlags + where + buildFlags = buildOptions progDb showOrParseArgs + ++ [ optionVerbosity buildVerbosity (\v flags -> flags { buildVerbosity = v }) , optionDistPref buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs ] - ++ buildOptions progDb showOrParseArgs - } + -- -- ------------------------------------------------------------ -- * Other Utils diff --git a/cabal-install/Distribution/Client/CmdBuild.hs b/cabal-install/Distribution/Client/CmdBuild.hs index cb1858837a4..5cb36f55529 100644 --- a/cabal-install/Distribution/Client/CmdBuild.hs +++ b/cabal-install/Distribution/Client/CmdBuild.hs @@ -8,7 +8,8 @@ module Distribution.Client.CmdBuild ( -- * Internals exposed for testing TargetProblem(..), selectPackageTargets, - selectComponentTarget + selectComponentTarget, + reportTargetProblems ) where import Distribution.Client.ProjectOrchestration diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 1a013d64b3f..5060ffb9ee5 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -11,12 +11,16 @@ import Distribution.Client.CmdErrorMessages import Distribution.Client.CmdInstall.ClientInstallFlags import Distribution.Client.Setup - ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags ) + ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags + ) import qualified Distribution.Client.Setup as Client import Distribution.Simple.Setup - ( HaddockFlags, fromFlagOrDefault, TestFlags ) + ( HaddockFlags, TestFlags + , fromFlagOrDefault + ) import Distribution.Simple.Command - ( CommandUI(..), usageAlternatives ) + ( CommandUI(..), option, reqArg', usageAlternatives + ) import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Simple.Utils @@ -38,10 +42,12 @@ import Distribution.Client.DistDirLayout (distBuildDirectory) import Distribution.Client.Types ( PackageLocation(..), GenericReadyPackage(..) ) import Distribution.Client.JobControl (newLock, Lock) import Distribution.Simple.Configure (tryGetPersistBuildConfig) +import qualified Distribution.Client.CmdInstall as CmdInstall import Data.List (find) +import Data.Maybe (fromMaybe) -showBuildInfoCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) -showBuildInfoCommand = Client.installCommand { +showBuildInfoCommand :: CommandUI ShowBuildInfoFlags +showBuildInfoCommand = CmdInstall.installCommand { commandName = "new-show-build-info", commandSynopsis = "Show project build information", commandUsage = usageAlternatives "new-show-build-info" [ "[TARGETS] [FLAGS]" ], @@ -56,9 +62,35 @@ showBuildInfoCommand = Client.installCommand { ++ " Shows build information about the current package\n" ++ " " ++ pname ++ " new-show-build-info ./pkgname \n" ++ " Shows build information about the package located in './pkgname'\n" - ++ cmdCommonHelpTextNewBuildBeta + ++ cmdCommonHelpTextNewBuildBeta, + commandOptions = \showOrParseArgs -> + Client.liftOptions buildInfoInstallCommandFlags (\pf flags -> flags { buildInfoInstallCommandFlags = pf }) (commandOptions CmdInstall.installCommand showOrParseArgs) + ++ + [ option [] ["buildinfo-json-output"] + "Write the result to the given file instead of stdout" + buildInfoOutputFile (\pf flags -> flags { buildInfoOutputFile = pf }) + (reqArg' "FILE" Just (maybe [] pure)), + option [] ["unit-ids-json"] + "Show build-info only for selected unit-id's." + buildInfoUnitIds (\pf flags -> flags { buildInfoUnitIds = pf }) + (reqArg' "UNIT-ID" (Just . words) (fromMaybe [])) + ], + commandDefaultFlags = defaultShowBuildInfoFlags + } +data ShowBuildInfoFlags = ShowBuildInfoFlags + { buildInfoInstallCommandFlags :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags, ClientInstallFlags) + , buildInfoOutputFile :: Maybe FilePath + , buildInfoUnitIds :: Maybe [String] + } + +defaultShowBuildInfoFlags :: ShowBuildInfoFlags +defaultShowBuildInfoFlags = ShowBuildInfoFlags + { buildInfoInstallCommandFlags = (mempty, mempty, mempty, mempty, mempty, mempty) + , buildInfoOutputFile = Nothing + , buildInfoUnitIds = Nothing + } -- | The @show-build-info@ command does a lot. It brings the install plan up to date, -- selects that part of the plan needed by the given or implicit targets and @@ -67,11 +99,10 @@ showBuildInfoCommand = Client.installCommand { -- For more details on how this works, see the module -- "Distribution.Client.ProjectOrchestration" -- -showBuildInfoAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags) +showBuildInfoAction :: ShowBuildInfoFlags -> [String] -> GlobalFlags -> IO () -showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags) +showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlags, haddockFlags, testFlags, clientInstallFlags) fileOutput unitIds) targetStrings globalFlags = do - baseCtx <- establishProjectBaseContext verbosity cliConfig let baseCtx' = baseCtx { buildSettings = (buildSettings baseCtx) { @@ -99,32 +130,36 @@ showBuildInfoAction (configFlags, configExFlags, installFlags, haddockFlags, tes return (elaboratedPlan, targets) scriptLock <- newLock - showTargets verbosity baseCtx' buildCtx scriptLock + showTargets fileOutput unitIds verbosity baseCtx' buildCtx scriptLock where -- Default to silent verbosity otherwise it will pollute our json output verbosity = fromFlagOrDefault silent (configVerbosity configFlags) cliConfig = commandLineFlagsToProjectConfig globalFlags configFlags configExFlags - installFlags mempty -- Not needed here + installFlags clientInstallFlags haddockFlags testFlags -- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks -showTargets :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () -showTargets verbosity baseCtx buildCtx lock = do - putStr "[" - mapM_ showSeparated (zip [0..] targets) - putStrLn "]" +showTargets :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () +showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do + case fileOutput of + Nothing -> do + putStr "[" + mapM_ doShowInfo targets + putStrLn "]" + Just fp -> do + writeFile fp "[" + mapM_ doShowInfo targets + appendFile fp "]" + where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] targets = fst <$> (Map.toList . targetsMap $ buildCtx) - doShowInfo unitId = showInfo verbosity baseCtx buildCtx lock configured unitId - showSeparated (idx, unitId) - | idx == length targets - 1 = doShowInfo unitId - | otherwise = doShowInfo unitId >> putStrLn "," + doShowInfo unitId = showInfo fileOutput unitIds verbosity baseCtx buildCtx lock configured unitId -showInfo :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () -showInfo verbosity baseCtx buildCtx lock pkgs targetUnitId +showInfo :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () +showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId | Nothing <- mbPkg = die' verbosity $ "No unit " ++ show targetUnitId | Just pkg <- mbPkg = do let shared = elaboratedShared buildCtx @@ -155,15 +190,22 @@ showInfo verbosity baseCtx buildCtx lock pkgs targetUnitId scriptOptions (Just $ elabPkgDescription pkg) (Cabal.configureCommand defaultProgramDb) - (const $ configureFlags) + (const configureFlags) (const configureArgs) Right _ -> pure () + setupWrapper verbosity scriptOptions (Just $ elabPkgDescription pkg) (Cabal.showBuildInfoCommand defaultProgramDb) - (const flags) + (const (Cabal.ShowBuildInfoFlags + { Cabal.buildInfoBuildFlags = flags + , Cabal.buildInfoOutputFile = fileOutput + , Cabal.buildInfoUnitIds = unitIds + } + ) + ) (const args) where mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 68d5ab0ff57..2c426d372d7 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -56,7 +56,7 @@ module Distribution.Client.Setup , doctestCommand , copyCommand , registerCommand - , showBuildInfoCommand + --, showBuildInfoCommand , parsePackageArgs , liftOptions , yesNoOpt @@ -3009,7 +3009,7 @@ relevantConfigValuesText vs = -- * Commands to support show-build-info -- ------------------------------------------------------------ -showBuildInfoCommand :: CommandUI (BuildFlags, BuildExFlags) +showBuildInfoCommand :: CommandUI (Cabal.ShowBuildInfoFlags, BuildExFlags) showBuildInfoCommand = parent { commandDefaultFlags = (commandDefaultFlags parent, mempty), commandOptions = diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 8df2d6f6043..7d173d49495 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -456,13 +456,14 @@ buildAction flags@(buildFlags, _) = buildActionForCommand flags where verbosity = fromFlagOrDefault normal (buildVerbosity buildFlags) -showBuildInfoAction :: (BuildFlags, BuildExFlags) -> [String] -> Action -showBuildInfoAction flags@(buildFlags, _) = buildActionForCommand - (Cabal.showBuildInfoCommand defaultProgramDb) - verbosity - flags - -- Default silent verbosity so as not to pollute json output - where verbosity = fromFlagOrDefault silent (buildVerbosity buildFlags) +-- showBuildInfoAction :: (Cabal.ShowBuildInfoFlags, BuildExFlags) -> [String] -> Action +-- showBuildInfoAction (showBuildInfoFlags, buildEx) = buildActionForCommand +-- (Cabal.showBuildInfoCommand defaultProgramDb) +-- showBuildInfoFlags +-- verbosity +-- (Cabal.buildInfoBuildFlags showBuildInfoFlags, buildEx) +-- -- Default silent verbosity so as not to pollute json output +-- where verbosity = fromFlagOrDefault silent (buildVerbosity (Cabal.buildInfoBuildFlags showBuildInfoFlags )) buildActionForCommand :: CommandUI BuildFlags -> Verbosity From 17cb80414a45932e0283e53b987ae84eac1afc24 Mon Sep 17 00:00:00 2001 From: fendor Date: Sat, 13 Apr 2019 19:34:43 +0200 Subject: [PATCH 13/43] Clean up code a bit --- Cabal/Distribution/Simple.hs | 11 ++- Cabal/Distribution/Simple/ShowBuildInfo.hs | 1 + .../Distribution/Client/CmdShowBuildInfo.hs | 72 +++++++++---------- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index 94a35f2b911..ca4bf80de96 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -266,13 +266,12 @@ buildAction hooks flags args = do hooks flags' { buildArgs = args } args showBuildInfoAction :: UserHooks -> ShowBuildInfoFlags -> Args -> IO () -showBuildInfoAction hooks a@(ShowBuildInfoFlags flags fileOutput _) args = do - print a +showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput unitIds) args = do distPref <- findDistPrefOrDefault (buildDistPref flags) let verbosity = fromFlag $ buildVerbosity flags lbi <- getBuildConfig hooks verbosity distPref let flags' = flags { buildDistPref = toFlag distPref - , buildCabalFilePath = maybeToFlag (cabalFilePath lbi) + , buildCabalFilePath = maybeToFlag (cabalFilePath lbi) } progs <- reconfigurePrograms verbosity @@ -286,9 +285,9 @@ showBuildInfoAction hooks a@(ShowBuildInfoFlags flags fileOutput _) args = do pkg_descr = updatePackageDescription pbi pkg_descr0 -- TODO: Somehow don't ignore build hook? buildInfoString <- showBuildInfo pkg_descr lbi' flags - - maybe (putStrLn buildInfoString) (\fp -> appendFile fp buildInfoString) (fileOutput) - + + maybe (putStrLn buildInfoString) (\fp -> appendFile fp buildInfoString) fileOutput + postBuild hooks args flags' pkg_descr lbi' replAction :: UserHooks -> ReplFlags -> Args -> IO () diff --git a/Cabal/Distribution/Simple/ShowBuildInfo.hs b/Cabal/Distribution/Simple/ShowBuildInfo.hs index 27eeb1ace21..b89cb462795 100644 --- a/Cabal/Distribution/Simple/ShowBuildInfo.hs +++ b/Cabal/Distribution/Simple/ShowBuildInfo.hs @@ -102,6 +102,7 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info mkComponentInfo (name, clbi) = JsonObject [ "type" .= JsonString compType , "name" .= JsonString (prettyShow name) + , "unit-id" .= JsonString (prettyShow $ componentUnitId clbi) , "compiler-args" .= JsonArray (map JsonString $ getCompilerArgs bi lbi clbi) , "modules" .= JsonArray (map (JsonString . display) modules) , "src-files" .= JsonArray (map JsonString sourceFiles) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 5060ffb9ee5..90f94de8054 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -15,7 +15,7 @@ import Distribution.Client.Setup ) import qualified Distribution.Client.Setup as Client import Distribution.Simple.Setup - ( HaddockFlags, TestFlags + ( HaddockFlags, TestFlags , fromFlagOrDefault ) import Distribution.Simple.Command @@ -35,7 +35,7 @@ import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.ProjectPlanning.Types import Distribution.Client.ProjectPlanning ( setupHsConfigureFlags, setupHsConfigureArgs, - setupHsBuildFlags, setupHsBuildArgs, + setupHsBuildFlags, setupHsBuildArgs, setupHsScriptOptions ) import Distribution.Client.DistDirLayout (distBuildDirectory) @@ -76,7 +76,7 @@ showBuildInfoCommand = CmdInstall.installCommand { (reqArg' "UNIT-ID" (Just . words) (fromMaybe [])) ], commandDefaultFlags = defaultShowBuildInfoFlags - + } data ShowBuildInfoFlags = ShowBuildInfoFlags @@ -99,16 +99,13 @@ defaultShowBuildInfoFlags = ShowBuildInfoFlags -- For more details on how this works, see the module -- "Distribution.Client.ProjectOrchestration" -- -showBuildInfoAction :: ShowBuildInfoFlags - -> [String] -> GlobalFlags -> IO () +showBuildInfoAction :: ShowBuildInfoFlags -> [String] -> GlobalFlags -> IO () showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlags, haddockFlags, testFlags, clientInstallFlags) fileOutput unitIds) - targetStrings globalFlags = do + targetStrings globalFlags = do baseCtx <- establishProjectBaseContext verbosity cliConfig - let baseCtx' = baseCtx { - buildSettings = (buildSettings baseCtx) { - buildSettingDryRun = True - } - } + let baseCtx' = baseCtx + { buildSettings = (buildSettings baseCtx) { buildSettingDryRun = True } + } targetSelectors <- either (reportTargetSelectorProblems verbosity) return =<< readTargetSelectors (localPackages baseCtx') Nothing targetStrings @@ -131,7 +128,6 @@ showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlag scriptLock <- newLock showTargets fileOutput unitIds verbosity baseCtx' buildCtx scriptLock - where -- Default to silent verbosity otherwise it will pollute our json output verbosity = fromFlagOrDefault silent (configVerbosity configFlags) @@ -144,12 +140,12 @@ showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlag -- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks showTargets :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do - case fileOutput of - Nothing -> do + case fileOutput of + Nothing -> do putStr "[" mapM_ doShowInfo targets putStrLn "]" - Just fp -> do + Just fp -> do writeFile fp "[" mapM_ doShowInfo targets appendFile fp "]" @@ -160,7 +156,7 @@ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do showInfo :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId - | Nothing <- mbPkg = die' verbosity $ "No unit " ++ show targetUnitId + | Nothing <- mbPkg = die' verbosity $ "No unit " ++ show targetUnitId | Just pkg <- mbPkg = do let shared = elaboratedShared buildCtx install = elaboratedPlanOriginal buildCtx @@ -171,41 +167,41 @@ showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId srcDir = case (elabPkgSourceLocation pkg) of LocalUnpackedPackage fp -> fp _ -> "" - scriptOptions = setupHsScriptOptions - (ReadyPackage pkg) - install - shared + scriptOptions = setupHsScriptOptions + (ReadyPackage pkg) + install + shared dirLayout - srcDir - buildDir - False + srcDir + buildDir + False lock configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir configureArgs = setupHsConfigureArgs pkg --Configure the package if there's no existing config lbi <- tryGetPersistBuildConfig buildDir case lbi of - Left _ -> setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.configureCommand defaultProgramDb) + Left _ -> setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.configureCommand defaultProgramDb) (const configureFlags) (const configureArgs) Right _ -> pure () - - setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.showBuildInfoCommand defaultProgramDb) - (const (Cabal.ShowBuildInfoFlags + + setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.showBuildInfoCommand defaultProgramDb) + (const (Cabal.ShowBuildInfoFlags { Cabal.buildInfoBuildFlags = flags , Cabal.buildInfoOutputFile = fileOutput - , Cabal.buildInfoUnitIds = unitIds - } + , Cabal.buildInfoUnitIds = unitIds + } ) - ) + ) (const args) where mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs From 316676b68717dd1d42327a7a122e37b6ddec1173 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 25 Apr 2019 15:50:36 +0200 Subject: [PATCH 14/43] Add first draft for tests --- .../PackageTests/ShowBuildInfo/A/A.cabal | 32 +++++++++++++++++++ .../PackageTests/ShowBuildInfo/A/CHANGELOG.md | 5 +++ .../PackageTests/ShowBuildInfo/A/LICENSE | 30 +++++++++++++++++ .../PackageTests/ShowBuildInfo/A/Setup.hs | 2 ++ .../PackageTests/ShowBuildInfo/A/src/A.hs | 4 +++ .../PackageTests/ShowBuildInfo/A/src/Main.hs | 4 +++ .../PackageTests/ShowBuildInfo/B/B.cabal | 24 ++++++++++++++ .../PackageTests/ShowBuildInfo/B/CHANGELOG.md | 5 +++ .../PackageTests/ShowBuildInfo/B/LICENSE | 30 +++++++++++++++++ .../PackageTests/ShowBuildInfo/B/Setup.hs | 2 ++ .../PackageTests/ShowBuildInfo/B/src/A.hs | 4 +++ .../PackageTests/ShowBuildInfo/cabal.test.hs | 7 ++++ 12 files changed, 149 insertions(+) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/LICENSE create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/Setup.hs 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/B/B.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/LICENSE create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/Setup.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/src/A.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal new file mode 100644 index 00000000000..b1e689f63e5 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal @@ -0,0 +1,32 @@ +cabal-version: 2.4 +-- Initial package description 'A.cabal' generated by 'cabal init'. For +-- further documentation, see http://haskell.org/cabal/users-guide/ + +name: A +version: 0.1.0.0 +-- synopsis: +-- description: +-- bug-reports: +license: BSD-3-Clause +license-file: LICENSE +author: Foo Bar +maintainer: cabal-dev@haskell.org +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +library + -- exposed-modules: + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.12.0.0 + hs-source-dirs: src + default-language: Haskell2010 + +executable A + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.12.0.0 + hs-source-dirs: src + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/CHANGELOG.md b/cabal-testsuite/PackageTests/ShowBuildInfo/A/CHANGELOG.md new file mode 100644 index 00000000000..cfa8b563c0e --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for A + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/LICENSE b/cabal-testsuite/PackageTests/ShowBuildInfo/A/LICENSE new file mode 100644 index 00000000000..671281e7a8b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2019, Foo Bar + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Foo Bar nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/Setup.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain 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..ad7a0c07729 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/A.hs @@ -0,0 +1,4 @@ +module A where + +foo :: Int -> Int +foo = id \ No newline at end of file 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..65ae4a05d5d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/src/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal new file mode 100644 index 00000000000..c98f468b6b8 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal @@ -0,0 +1,24 @@ +cabal-version: 2.4 +-- Initial package description 'B.cabal' generated by 'cabal init'. For +-- further documentation, see http://haskell.org/cabal/users-guide/ + +name: B +version: 0.1.0.0 +-- synopsis: +-- description: +-- bug-reports: +license: BSD-3-Clause +license-file: LICENSE +author: Foo Bar +maintainer: cabal-dev@haskell.org +-- copyright: +-- category: +extra-source-files: CHANGELOG.md + +library + -- exposed-modules: + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.12.0.0 + hs-source-dirs: src + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/CHANGELOG.md b/cabal-testsuite/PackageTests/ShowBuildInfo/B/CHANGELOG.md new file mode 100644 index 00000000000..5cf6ac2adb2 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for B + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/LICENSE b/cabal-testsuite/PackageTests/ShowBuildInfo/B/LICENSE new file mode 100644 index 00000000000..671281e7a8b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2019, Foo Bar + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Foo Bar nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/Setup.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/src/A.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/src/A.hs new file mode 100644 index 00000000000..ad7a0c07729 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/src/A.hs @@ -0,0 +1,4 @@ +module A where + +foo :: Int -> Int +foo = id \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs new file mode 100644 index 00000000000..3c4425c6cac --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +main = do + putStrLn "We ride!" + cabalTest $ + r <- cabal' "new-show-build-info" ["A"] + assertOutputContains "Hi" r From 167bc7233f49787f960319f2830ab3b9a709f37a Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 25 Apr 2019 17:04:15 +0200 Subject: [PATCH 15/43] Update the correct cabal-install.cabal --- cabal-install/cabal-install.cabal | 2 +- cabal-install/cabal-install.cabal.pp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index ea4539af8cb..35c6912488f 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -161,7 +161,6 @@ executable cabal Distribution.Client.CmdBench Distribution.Client.CmdBuild Distribution.Client.CmdClean - Distribution.Client.CmdShowBuildInfo Distribution.Client.CmdConfigure Distribution.Client.CmdUpdate Distribution.Client.CmdErrorMessages @@ -172,6 +171,7 @@ executable cabal Distribution.Client.CmdInstall.ClientInstallFlags Distribution.Client.CmdRepl Distribution.Client.CmdRun + Distribution.Client.CmdShowBuildInfo Distribution.Client.CmdTest Distribution.Client.CmdLegacy Distribution.Client.CmdSdist diff --git a/cabal-install/cabal-install.cabal.pp b/cabal-install/cabal-install.cabal.pp index 860714fb2a9..c2c0fd44039 100644 --- a/cabal-install/cabal-install.cabal.pp +++ b/cabal-install/cabal-install.cabal.pp @@ -99,6 +99,7 @@ Distribution.Client.CmdInstall.ClientInstallFlags Distribution.Client.CmdRepl Distribution.Client.CmdRun + Distribution.Client.CmdShowBuildInfo Distribution.Client.CmdTest Distribution.Client.CmdLegacy Distribution.Client.CmdSdist From 0b0bd5df1efbd4da6cedcb165d1df368f206fae6 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 25 Apr 2019 18:13:57 +0200 Subject: [PATCH 16/43] Implement basic test for new-show-build-info --- .../PackageTests/ShowBuildInfo/A/A.cabal | 6 +++--- .../ShowBuildInfo/A/build-info-exe.test.hs | 17 +++++++++++++++++ .../ShowBuildInfo/A/build-info-lib.test.hs | 16 ++++++++++++++++ .../PackageTests/ShowBuildInfo/A/cabal.project | 1 + .../PackageTests/ShowBuildInfo/B/B.cabal | 4 ++-- .../ShowBuildInfo/B/build-info-lib.test.hs | 16 ++++++++++++++++ .../PackageTests/ShowBuildInfo/B/cabal.project | 1 + .../PackageTests/ShowBuildInfo/cabal.test.hs | 7 ------- 8 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/cabal.project delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal index b1e689f63e5..2873a450394 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal @@ -16,10 +16,10 @@ maintainer: cabal-dev@haskell.org extra-source-files: CHANGELOG.md library - -- exposed-modules: + exposed-modules: A -- other-modules: -- other-extensions: - build-depends: base ^>=4.12.0.0 + build-depends: base >=4.0.0 hs-source-dirs: src default-language: Haskell2010 @@ -27,6 +27,6 @@ executable A main-is: Main.hs -- other-modules: -- other-extensions: - build-depends: base ^>=4.12.0.0 + build-depends: base >=4.0.0.0 hs-source-dirs: src default-language: Haskell2010 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..ed5d0c57e1f --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs @@ -0,0 +1,17 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["exe:A"] + assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r + assertOutputContains "\"compiler\":{" r + assertOutputContains "\"flavour\":\"ghc\"" r + assertOutputContains "\"compiler-id\":" r + assertOutputContains "\"path\":" r + assertOutputContains "\"type\":\"exe\"" r + assertOutputContains "\"name\":\"exe:A\"" r + assertOutputContains "\"unit-id\":\"A-0.1.0.0-inplace-A\"" r + assertOutputContains "\"compiler-args\":[" r + assertOutputContains "\"modules\":[]" r + assertOutputContains "\"src-files\":[\"Main.hs\"]" r + assertOutputContains "\"src-dirs\":[\"src\"]" r + diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs new file mode 100644 index 00000000000..e14f0d87808 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs @@ -0,0 +1,16 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["lib:A"] + assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r + assertOutputContains "\"compiler\":{" r + assertOutputContains "\"flavour\":\"ghc\"" r + assertOutputContains "\"compiler-id\":" r + assertOutputContains "\"path\":" r + assertOutputContains "\"type\":\"lib\"" r + assertOutputContains "\"name\":\"lib\"" r + assertOutputContains "\"unit-id\":\"A-0.1.0.0-inplace\"" r + assertOutputContains "\"compiler-args\":[" r + assertOutputContains "\"modules\":[\"A\"]" r + assertOutputContains "\"src-files\":[]" r + assertOutputContains "\"src-dirs\":[\"src\"]" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project new file mode 100644 index 00000000000..5356e76f67c --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project @@ -0,0 +1 @@ +packages: . \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal index c98f468b6b8..d8ed91d655b 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/B.cabal @@ -16,9 +16,9 @@ maintainer: cabal-dev@haskell.org extra-source-files: CHANGELOG.md library - -- exposed-modules: + exposed-modules: A -- other-modules: -- other-extensions: - build-depends: base ^>=4.12.0.0 + build-depends: base >=4.0.0.0 hs-source-dirs: src default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs new file mode 100644 index 00000000000..1de89cb1cb6 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs @@ -0,0 +1,16 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["lib:B"] + assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r + assertOutputContains "\"compiler\":{" r + assertOutputContains "\"flavour\":\"ghc\"" r + assertOutputContains "\"compiler-id\":" r + assertOutputContains "\"path\":" r + assertOutputContains "\"type\":\"lib\"" r + assertOutputContains "\"name\":\"lib\"" r + assertOutputContains "\"unit-id\":\"B-0.1.0.0-inplace\"" r + assertOutputContains "\"compiler-args\":[" r + assertOutputContains "\"modules\":[\"A\"]" r + assertOutputContains "\"src-files\":[]" r + assertOutputContains "\"src-dirs\":[\"src\"]" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/B/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs deleted file mode 100644 index 3c4425c6cac..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/cabal.test.hs +++ /dev/null @@ -1,7 +0,0 @@ -import Test.Cabal.Prelude - -main = do - putStrLn "We ride!" - cabalTest $ - r <- cabal' "new-show-build-info" ["A"] - assertOutputContains "Hi" r From 59d1f06feb1ccdd8c1118af4cbf12a42f30252dc Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 6 May 2019 18:18:54 +0200 Subject: [PATCH 17/43] Improve format and clean up code --- Cabal/Distribution/Simple.hs | 3 +- Cabal/Distribution/Simple/Setup.hs | 1 - .../Distribution/Client/CmdShowBuildInfo.hs | 33 ++++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index ca4bf80de96..ee1854853ff 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -286,7 +286,8 @@ showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput unitIds) args = d -- TODO: Somehow don't ignore build hook? buildInfoString <- showBuildInfo pkg_descr lbi' flags - maybe (putStrLn buildInfoString) (\fp -> appendFile fp buildInfoString) fileOutput + -- TODO: writeFileAtomic? + maybe (putStr buildInfoString) (\fp -> appendFile fp buildInfoString) fileOutput postBuild hooks args flags' pkg_descr lbi' diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index b3aee06fab3..351bb5de4fc 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -2286,7 +2286,6 @@ parseBuildFlagsForShowBuildInfoFlags showOrParseArgs progDb = , optionDistPref buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs ] - -- -- ------------------------------------------------------------ -- * Other Utils diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 90f94de8054..c65296f7ed4 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -1,10 +1,12 @@ -- | cabal-install CLI command: new-show-build-info -- -module Distribution.Client.CmdShowBuildInfo ( - -- * The @show-build-info@ CLI and action - showBuildInfoCommand, - showBuildInfoAction - ) where +module Distribution.Client.CmdShowBuildInfo where +-- ( +-- -- * The @show-build-info@ CLI and action +-- showBuildInfoCommand, +-- showBuildInfoAction +-- ) + import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages @@ -25,7 +27,8 @@ import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Simple.Utils ( wrapText, die') -import Distribution.Types.UnitId (UnitId) +import Distribution.Types.UnitId (UnitId, mkUnitId) +import Distribution.Deprecated.Text (display) import qualified Data.Map as Map import qualified Distribution.Simple.Setup as Cabal @@ -141,9 +144,10 @@ showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlag showTargets :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do case fileOutput of + -- TODO: replace with writeFileAtomic Nothing -> do putStr "[" - mapM_ doShowInfo targets + unroll targets putStrLn "]" Just fp -> do writeFile fp "[" @@ -151,12 +155,17 @@ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do appendFile fp "]" where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] - targets = fst <$> (Map.toList . targetsMap $ buildCtx) + targets = maybe (fst <$> (Map.toList . targetsMap $ buildCtx)) (map mkUnitId) unitIds doShowInfo unitId = showInfo fileOutput unitIds verbosity baseCtx buildCtx lock configured unitId + unroll :: [UnitId] -> IO () + unroll [x] = doShowInfo x + unroll (x:xs) = doShowInfo x >> putStr "," >> unroll xs + unroll [] = return () + showInfo :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId - | Nothing <- mbPkg = die' verbosity $ "No unit " ++ show targetUnitId + | Nothing <- mbPkg = die' verbosity $ "No unit " ++ display targetUnitId | Just pkg <- mbPkg = do let shared = elaboratedShared buildCtx install = elaboratedPlanOriginal buildCtx @@ -198,18 +207,18 @@ showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId (const (Cabal.ShowBuildInfoFlags { Cabal.buildInfoBuildFlags = flags , Cabal.buildInfoOutputFile = fileOutput - , Cabal.buildInfoUnitIds = unitIds + , Cabal.buildInfoUnitIds = unitIds } ) ) (const args) where mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs --- | This defines what a 'TargetSelector' means for the @write-autogen-files@ command. +-- | This defines what a 'TargetSelector' means for the @new-show-build-info@ command. -- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, -- or otherwise classifies the problem. -- --- For the @write-autogen-files@ command select all components except non-buildable and disabled +-- For the @new-show-build-info@ command select all components except non-buildable and disabled -- tests\/benchmarks, fail if there are no such components -- selectPackageTargets :: TargetSelector From 669c18bd07fa65d35ff7679e7694b4c8170352d3 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 6 May 2019 18:18:54 +0200 Subject: [PATCH 18/43] Improve format and clean up code --- cabal-install/Distribution/Client/Setup.hs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 2c426d372d7..b47f22cf05d 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -863,25 +863,6 @@ filterTestFlags flags cabalLibVersion Cabal.testWrapper = NoFlag } --- ------------------------------------------------------------ --- * show-build-info command --- ------------------------------------------------------------ - -showBuildInfoCommand :: CommandUI (BuildFlags, BuildExFlags) -showBuildInfoCommand = parent { - commandDefaultFlags = (commandDefaultFlags parent, mempty), - commandOptions = - \showOrParseArgs -> liftOptions fst setFst - (commandOptions parent showOrParseArgs) - ++ - liftOptions snd setSnd (buildExOptions showOrParseArgs) - } - where - setFst a (_,b) = (a,b) - setSnd b (a,_) = (a,b) - - parent = Cabal.showBuildInfoCommand defaultProgramDb - -- ------------------------------------------------------------ -- * Repl command -- ------------------------------------------------------------ From c9679313d299002df315b0f09bb861e6b55f7e7c Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 4 Jun 2019 16:02:24 +0200 Subject: [PATCH 19/43] Silence warnings --- Cabal/Distribution/Simple.hs | 2 +- .../Distribution/Client/CmdShowBuildInfo.hs | 14 +++++++------- cabal-install/main/Main.hs | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index ee1854853ff..dbb488d8f17 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -266,7 +266,7 @@ buildAction hooks flags args = do hooks flags' { buildArgs = args } args showBuildInfoAction :: UserHooks -> ShowBuildInfoFlags -> Args -> IO () -showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput unitIds) args = do +showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput _) args = do distPref <- findDistPrefOrDefault (buildDistPref flags) let verbosity = fromFlag $ buildVerbosity flags lbi <- getBuildConfig hooks verbosity distPref diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index c65296f7ed4..c4864ca56a1 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -142,26 +142,26 @@ showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlag -- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks showTargets :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () -showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do +showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = case fileOutput of -- TODO: replace with writeFileAtomic Nothing -> do putStr "[" - unroll targets + unroll putStr targets putStrLn "]" Just fp -> do writeFile fp "[" - mapM_ doShowInfo targets + unroll (appendFile fp) targets appendFile fp "]" where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] targets = maybe (fst <$> (Map.toList . targetsMap $ buildCtx)) (map mkUnitId) unitIds doShowInfo unitId = showInfo fileOutput unitIds verbosity baseCtx buildCtx lock configured unitId - unroll :: [UnitId] -> IO () - unroll [x] = doShowInfo x - unroll (x:xs) = doShowInfo x >> putStr "," >> unroll xs - unroll [] = return () + unroll :: (String -> IO ()) -> [UnitId] -> IO () + unroll _ [x] = doShowInfo x + unroll printer (x:xs) = doShowInfo x >> printer "," >> unroll printer xs + unroll _ [] = return () showInfo :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId diff --git a/cabal-install/main/Main.hs b/cabal-install/main/Main.hs index 7d173d49495..ef8f9dbf72a 100644 --- a/cabal-install/main/Main.hs +++ b/cabal-install/main/Main.hs @@ -179,7 +179,7 @@ import Distribution.Simple.Utils import Distribution.Text ( display ) import Distribution.Verbosity as Verbosity - ( Verbosity, normal, silent ) + ( Verbosity, normal ) import Distribution.Version ( Version, mkVersion, orLaterVersion ) import qualified Paths_cabal_install (version) @@ -478,12 +478,12 @@ buildActionForCommand commandUI verbosity (buildFlags, buildExFlags) extraArgs g distPref <- findSavedDistPref config (buildDistPref buildFlags) -- Calls 'configureAction' to do the real work, so nothing special has to be -- done to support sandboxes. - config' <- reconfigure - configureAction verbosity distPref useSandbox noAddSource + config' <- reconfigure + configureAction verbosity distPref useSandbox noAddSource (buildNumJobs buildFlags) mempty [] globalFlags config - + nixShell verbosity distPref globalFlags config $ - maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand + maybeWithSandboxDirOnSearchPath useSandbox $ buildForCommand commandUI verbosity config' distPref buildFlags extraArgs -- | Actually do the work of building the package. This is separate from From d89ca8d138df3b1a8b02c50b44e8890d16ef2b4b Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 4 Jun 2019 16:38:45 +0200 Subject: [PATCH 20/43] Remove unused flag to Cabal --- Cabal/Distribution/Simple.hs | 2 +- Cabal/Distribution/Simple/Setup.hs | 8 +------- cabal-install/Distribution/Client/CmdShowBuildInfo.hs | 7 +++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index dbb488d8f17..005e6418b12 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -266,7 +266,7 @@ buildAction hooks flags args = do hooks flags' { buildArgs = args } args showBuildInfoAction :: UserHooks -> ShowBuildInfoFlags -> Args -> IO () -showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput _) args = do +showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput) args = do distPref <- findDistPrefOrDefault (buildDistPref flags) let verbosity = fromFlag $ buildVerbosity flags lbi <- getBuildConfig hooks verbosity distPref diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 351bb5de4fc..4630f20e064 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -2214,7 +2214,6 @@ optionNumJobs get set = data ShowBuildInfoFlags = ShowBuildInfoFlags { buildInfoBuildFlags :: BuildFlags , buildInfoOutputFile :: Maybe FilePath - , buildInfoUnitIds :: Maybe [String] } deriving Show defaultShowBuildFlags :: ShowBuildInfoFlags @@ -2222,7 +2221,6 @@ defaultShowBuildFlags = ShowBuildInfoFlags { buildInfoBuildFlags = defaultBuildFlags , buildInfoOutputFile = Nothing - , buildInfoUnitIds = Nothing } showBuildInfoCommand :: ProgramDb -> CommandUI ShowBuildInfoFlags @@ -2260,11 +2258,7 @@ showBuildInfoCommand progDb = CommandUI [ option [] ["buildinfo-json-output"] "Write the result to the given file instead of stdout" buildInfoOutputFile (\pf flags -> flags { buildInfoOutputFile = pf }) - (reqArg' "FILE" Just (maybe [] pure)), - option [] ["unit-ids-json"] - "Show build-info only for selected unit-id's." - buildInfoUnitIds (\pf flags -> flags { buildInfoUnitIds = pf }) - (reqArg' "UNIT-ID" (Just . words) (fromMaybe [] )) + (reqArg' "FILE" Just (maybe [] pure)) ] } diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index c4864ca56a1..6b58605eb04 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -156,15 +156,15 @@ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] targets = maybe (fst <$> (Map.toList . targetsMap $ buildCtx)) (map mkUnitId) unitIds - doShowInfo unitId = showInfo fileOutput unitIds verbosity baseCtx buildCtx lock configured unitId + doShowInfo unitId = showInfo fileOutput verbosity baseCtx buildCtx lock configured unitId unroll :: (String -> IO ()) -> [UnitId] -> IO () unroll _ [x] = doShowInfo x unroll printer (x:xs) = doShowInfo x >> printer "," >> unroll printer xs unroll _ [] = return () -showInfo :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () -showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId +showInfo :: Maybe FilePath -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () +showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId | Nothing <- mbPkg = die' verbosity $ "No unit " ++ display targetUnitId | Just pkg <- mbPkg = do let shared = elaboratedShared buildCtx @@ -207,7 +207,6 @@ showInfo fileOutput unitIds verbosity baseCtx buildCtx lock pkgs targetUnitId (const (Cabal.ShowBuildInfoFlags { Cabal.buildInfoBuildFlags = flags , Cabal.buildInfoOutputFile = fileOutput - , Cabal.buildInfoUnitIds = unitIds } ) ) From 6f0cb5b83fe0d5ea5ef047e6293a313d95d29bd2 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 4 Jun 2019 17:27:06 +0200 Subject: [PATCH 21/43] In the tests, do not record --- .../PackageTests/ShowBuildInfo/A/build-info-exe.test.hs | 3 ++- .../PackageTests/ShowBuildInfo/A/build-info-lib.test.hs | 3 ++- .../PackageTests/ShowBuildInfo/B/build-info-lib.test.hs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs index ed5d0c57e1f..e9db1423912 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs @@ -1,6 +1,7 @@ import Test.Cabal.Prelude -main = cabalTest $ do +main = cabalTest $ + recordMode DoNotRecord $ do r <- cabal' "new-show-build-info" ["exe:A"] assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r assertOutputContains "\"compiler\":{" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs index e14f0d87808..a894fe5d8ef 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs @@ -1,6 +1,7 @@ import Test.Cabal.Prelude -main = cabalTest $ do +main = cabalTest $ + recordMode DoNotRecord $ do r <- cabal' "new-show-build-info" ["lib:A"] assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r assertOutputContains "\"compiler\":{" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs index 1de89cb1cb6..cf984db11b2 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs @@ -1,6 +1,7 @@ import Test.Cabal.Prelude -main = cabalTest $ do +main = cabalTest $ + recordMode DoNotRecord $ do r <- cabal' "new-show-build-info" ["lib:B"] assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r assertOutputContains "\"compiler\":{" r From feefced244a7a6e0e3ebefd3f460bf3947648024 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 13:56:19 +0200 Subject: [PATCH 22/43] Communicate with Cabal over temp files --- Cabal/Distribution/Simple.hs | 5 +- .../Distribution/Client/CmdShowBuildInfo.hs | 62 +++++++++++++------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Cabal/Distribution/Simple.hs b/Cabal/Distribution/Simple.hs index 005e6418b12..e632acc88e8 100644 --- a/Cabal/Distribution/Simple.hs +++ b/Cabal/Distribution/Simple.hs @@ -286,8 +286,9 @@ showBuildInfoAction hooks (ShowBuildInfoFlags flags fileOutput) args = do -- TODO: Somehow don't ignore build hook? buildInfoString <- showBuildInfo pkg_descr lbi' flags - -- TODO: writeFileAtomic? - maybe (putStr buildInfoString) (\fp -> appendFile fp buildInfoString) fileOutput + case fileOutput of + Nothing -> putStr buildInfoString + Just fp -> writeFile fp buildInfoString postBuild hooks args flags' pkg_descr lbi' diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 6b58605eb04..d694de9e7ea 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -26,7 +26,7 @@ import Distribution.Simple.Command import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Simple.Utils - ( wrapText, die') + ( wrapText, die', withTempDirectory ) import Distribution.Types.UnitId (UnitId, mkUnitId) import Distribution.Deprecated.Text (display) @@ -46,8 +46,12 @@ import Distribution.Client.Types ( PackageLocation(..), GenericReadyPackage(..) import Distribution.Client.JobControl (newLock, Lock) import Distribution.Simple.Configure (tryGetPersistBuildConfig) import qualified Distribution.Client.CmdInstall as CmdInstall + +import Control.Monad (mapM_) import Data.List (find) import Data.Maybe (fromMaybe) +import System.Directory (getTemporaryDirectory) +import System.FilePath (()) showBuildInfoCommand :: CommandUI ShowBuildInfoFlags showBuildInfoCommand = CmdInstall.installCommand { @@ -142,28 +146,48 @@ showBuildInfoAction (ShowBuildInfoFlags (configFlags, configExFlags, installFlag -- Pretty nasty piecemeal out of json, but I can't see a way to retrieve output of the setupWrapper'd tasks showTargets :: Maybe FilePath -> Maybe [String] -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> IO () -showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = - case fileOutput of - -- TODO: replace with writeFileAtomic - Nothing -> do - putStr "[" - unroll putStr targets - putStrLn "]" - Just fp -> do - writeFile fp "[" - unroll (appendFile fp) targets - appendFile fp "]" +showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do + tempDir <- getTemporaryDirectory + withTempDirectory verbosity tempDir "show-build-info" $ \dir -> do + mapM_ (doShowInfo dir) targets + case fileOutput of + Nothing -> outputResult dir putStr targets + Just fp -> do + writeFile fp "" + outputResult dir (appendFile fp) targets where configured = [p | InstallPlan.Configured p <- InstallPlan.toList (elaboratedPlanOriginal buildCtx)] targets = maybe (fst <$> (Map.toList . targetsMap $ buildCtx)) (map mkUnitId) unitIds - doShowInfo unitId = showInfo fileOutput verbosity baseCtx buildCtx lock configured unitId + doShowInfo :: FilePath -> UnitId -> IO () + doShowInfo dir unitId = + showInfo + (dir unitIdToFilePath unitId) + verbosity + baseCtx + buildCtx + lock + configured + unitId + + outputResult :: FilePath -> (String -> IO ()) -> [UnitId] -> IO () + outputResult dir printer units = do + let unroll [] = return () + unroll [x] = do + content <- readFile (dir unitIdToFilePath x) + printer content + unroll (x:xs) = do + content <- readFile (dir unitIdToFilePath x) + printer content + printer "," + unroll xs + printer "[" + unroll units + printer "]" - unroll :: (String -> IO ()) -> [UnitId] -> IO () - unroll _ [x] = doShowInfo x - unroll printer (x:xs) = doShowInfo x >> printer "," >> unroll printer xs - unroll _ [] = return () + unitIdToFilePath :: UnitId -> FilePath + unitIdToFilePath unitId = "build-info-" ++ display unitId -showInfo :: Maybe FilePath -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () +showInfo :: FilePath -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId | Nothing <- mbPkg = die' verbosity $ "No unit " ++ display targetUnitId | Just pkg <- mbPkg = do @@ -206,7 +230,7 @@ showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId (Cabal.showBuildInfoCommand defaultProgramDb) (const (Cabal.ShowBuildInfoFlags { Cabal.buildInfoBuildFlags = flags - , Cabal.buildInfoOutputFile = fileOutput + , Cabal.buildInfoOutputFile = Just fileOutput } ) ) From b62af6c2db2a8572854ddb83af534d2cc8408ca4 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 17:26:58 +0200 Subject: [PATCH 23/43] Add tests for new-show-build-info --- .../ShowBuildInfo/A/build-info-exe-exact.out | 1 + .../A/build-info-exe-exact.test.hs | 67 ++++++++++ .../ShowBuildInfo/A/build-info-exe.out | 3 + .../ShowBuildInfo/A/build-info-exe.test.hs | 3 +- .../ShowBuildInfo/A/build-info-lib.out | 3 + .../ShowBuildInfo/A/build-info-lib.test.hs | 3 +- ...build-info-multiple-exact-unit-id-file.out | 1 + ...d-info-multiple-exact-unit-id-file.test.hs | 88 +++++++++++++ .../A/build-info-multiple-exact-unit-id.out | 1 + .../build-info-multiple-exact-unit-id.test.hs | 87 +++++++++++++ .../A/build-info-multiple-exact.out | 1 + .../A/build-info-multiple-exact.test.hs | 87 +++++++++++++ .../ShowBuildInfo/A/build-info-unknown.out | 12 ++ .../A/build-info-unknown.test.hs | 14 ++ .../PackageTests/ShowBuildInfo/A/unit.json | 1 + .../ShowBuildInfo/Complex/CHANGELOG.md | 5 + .../ShowBuildInfo/Complex/Complex.cabal | 50 +++++++ .../ShowBuildInfo/Complex/LICENSE | 20 +++ .../ShowBuildInfo/Complex/Setup.hs | 2 + .../ShowBuildInfo/Complex/cabal.project | 1 + .../ShowBuildInfo/Complex/exe.out | 1 + .../ShowBuildInfo/Complex/exe.test.hs | 67 ++++++++++ .../ShowBuildInfo/Complex/src/Lib.hs | 4 + .../ShowBuildInfo/Complex/src/Main.lhs | 9 ++ .../ShowBuildInfo/Complex/test/Main.hs | 1 + .../ShowBuildInfo/Complex/unit.json | 122 ++++++++++++++++++ 26 files changed, 650 insertions(+), 4 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/LICENSE create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Setup.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Lib.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Main.lhs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/Main.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs new file mode 100644 index 00000000000..6449e181d28 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs @@ -0,0 +1,67 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["exe:A", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:A" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file 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..64b379f5fdc --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out @@ -0,0 +1,3 @@ +# cabal new-show-build-info +Resolving dependencies... +Configuring 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 index e9db1423912..ed5d0c57e1f 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs @@ -1,7 +1,6 @@ import Test.Cabal.Prelude -main = cabalTest $ - recordMode DoNotRecord $ do +main = cabalTest $ do r <- cabal' "new-show-build-info" ["exe:A"] assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r assertOutputContains "\"compiler\":{" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out new file mode 100644 index 00000000000..3162a2cdecd --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out @@ -0,0 +1,3 @@ +# cabal new-show-build-info +Resolving dependencies... +Configuring library for A-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs index a894fe5d8ef..e14f0d87808 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs @@ -1,7 +1,6 @@ import Test.Cabal.Prelude -main = cabalTest $ - recordMode DoNotRecord $ do +main = cabalTest $ do r <- cabal' "new-show-build-info" ["lib:A"] assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r assertOutputContains "\"compiler\":{" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs new file mode 100644 index 00000000000..5e0a17cd44e --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs @@ -0,0 +1,88 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["--buildinfo-json-output=unit.json", "--unit-ids-json=A-0.1.0.0-inplace A-0.1.0.0-inplace-A", "-v0"] + shouldExist "unit.json" + buildInfoEither <- liftIO $ eitherDecodeFileStrict "unit.json" + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly two " 2 (length buildInfos) + let [libBuildInfo, exeBuildInfo] = buildInfos + assertExe exeBuildInfo + assertLib libBuildInfo + return () + where + assertExe :: BuildInfo -> TestM () + assertExe buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:A" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + + assertLib :: BuildInfo -> TestM () + assertLib buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "lib" (componentType component) + assertEqual "Component name" "lib" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs new file mode 100644 index 00000000000..3fee513f545 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs @@ -0,0 +1,87 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace A-0.1.0.0-inplace-A", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly two " 2 (length buildInfos) + let [libBuildInfo, exeBuildInfo] = buildInfos + assertExe exeBuildInfo + assertLib libBuildInfo + return () + where + assertExe :: BuildInfo -> TestM () + assertExe buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:A" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + + assertLib :: BuildInfo -> TestM () + assertLib buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "lib" (componentType component) + assertEqual "Component name" "lib" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs new file mode 100644 index 00000000000..899a4720526 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs @@ -0,0 +1,87 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["exe:A", "lib:A", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly two " 2 (length buildInfos) + let [libBuildInfo, exeBuildInfo] = buildInfos + assertExe exeBuildInfo + assertLib libBuildInfo + return () + where + assertExe :: BuildInfo -> TestM () + assertExe buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:A" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + + assertLib :: BuildInfo -> TestM () + assertLib buildInfo = do + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "lib" (componentType component) + assertEqual "Component name" "lib" (componentName component) + assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.out new file mode 100644 index 00000000000..ff049ec672f --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.out @@ -0,0 +1,12 @@ +# cabal new-show-build-info +cabal: Internal error in target matching. It should always be possible to find a syntax that's sufficiently qualified to give an unambiguous match. However when matching 'exe:B' we found exe:B (unknown-component) which does not have an unambiguous syntax. The possible syntax and the targets they match are as follows: +'exe:B' which matches exe:B (unknown-component), :pkg:exe:lib:exe:module:B (unknown-module), :pkg:exe:lib:exe:file:B (unknown-file) +# cabal new-show-build-info +Resolving dependencies... +cabal: No unit B-inplace-0.1.0.0 +# cabal new-show-build-info +Configuring library for A-0.1.0.0.. +cabal: No unit B-inplace-0.1.0.0 +# cabal new-show-build-info +cabal: Internal error in target matching. It should always be possible to find a syntax that's sufficiently qualified to give an unambiguous match. However when matching 'exe:B' we found exe:B (unknown-component) which does not have an unambiguous syntax. The possible syntax and the targets they match are as follows: +'exe:B' which matches exe:B (unknown-component), :pkg:exe:lib:exe:module:B (unknown-module), :pkg:exe:lib:exe:file:B (unknown-file) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs new file mode 100644 index 00000000000..35968002aae --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs @@ -0,0 +1,14 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + r <- fails $ cabal' "new-show-build-info" ["exe:B"] + assertOutputContains "cabal: Internal error in target matching." r + + r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=B-inplace-0.1.0.0"] + assertOutputContains "cabal: No unit B-inplace-0.1.0.0" r + + r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace B-inplace-0.1.0.0"] + assertOutputContains "cabal: No unit B-inplace-0.1.0.0" r + + r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace", "exe:B"] + assertOutputContains "cabal: Internal error in target matching." r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json b/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json new file mode 100644 index 00000000000..00cea5f5f03 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json @@ -0,0 +1 @@ +[{"cabal-version":"3.0.0.0","compiler":{"flavour":"ghc","compiler-id":"ghc-8.6.4","path":"/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc-8.6.4"},"components":[{"type":"lib","name":"lib","unit-id":"A-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-odir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-hidir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-stubdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-i","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-isrc","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-optP-include","-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen/cabal_macros.h","-this-unit-id","A-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/home/.cabal/store/ghc-8.6.4/package.db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/packagedb/ghc-8.6.4","-package-id","base-4.12.0.0","-XHaskell2010"],"modules":["A"],"src-files":[],"src-dirs":["src"]}]},{"cabal-version":"3.0.0.0","compiler":{"flavour":"ghc","compiler-id":"ghc-8.6.4","path":"/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc-8.6.4"},"components":[{"type":"exe","name":"exe:A","unit-id":"A-0.1.0.0-inplace-A","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-odir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-hidir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-stubdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-i","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-isrc","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-optP-include","-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen/cabal_macros.h","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/home/.cabal/store/ghc-8.6.4/package.db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/packagedb/ghc-8.6.4","-package-id","base-4.12.0.0","-XHaskell2010"],"modules":[],"src-files":["Main.hs"],"src-dirs":["src"]}]}] \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/CHANGELOG.md b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/CHANGELOG.md new file mode 100644 index 00000000000..624468cdfdb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for Complex + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal new file mode 100644 index 00000000000..6eac38850ac --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -0,0 +1,50 @@ +cabal-version: 2.4 +name: Complex +version: 0.1.0.0 +license: MIT +license-file: LICENSE +author: Bla Bla +maintainer: "" +category: Testing +extra-source-files: CHANGELOG.md + + +library + build-depends: base >=4.0.0 + hs-source-dirs: src + default-language: Haskell2010 + + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall + +executable Complex + main-is: Main.lhs + build-depends: base >=4.0.0 + hs-source-dirs: src + default-language: Haskell2010 + other-modules: Paths_complex + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints + -with-rtsopts=-T + +test-suite unit-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + +test-suite func-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + +benchmark complex-benchmarks + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: + Paths_complex + hs-source-dirs: + benchmark + ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N + build-depends: + base + , criterion + , Complex + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/LICENSE b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/LICENSE new file mode 100644 index 00000000000..a234fc7e8dd --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2019 Bla Bla + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Setup.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project new file mode 100644 index 00000000000..5356e76f67c --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/cabal.project @@ -0,0 +1 @@ +packages: . \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs new file mode 100644 index 00000000000..672e9580f8d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs @@ -0,0 +1,67 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["exe:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:Complex" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Lib.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Lib.hs new file mode 100644 index 00000000000..5d35e3e9617 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +foo :: Int -> Int +foo = (+1) \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Main.lhs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Main.lhs new file mode 100644 index 00000000000..a1b75006b8d --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/src/Main.lhs @@ -0,0 +1,9 @@ +module Main where + +import Lib + +main :: IO () +main = do + let i = foo 5 + putStrLn "Hello, Haskell!" + print i diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/Main.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/Main.hs new file mode 100644 index 00000000000..3ef47688534 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/test/Main.hs @@ -0,0 +1 @@ +main = return () \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json new file mode 100644 index 00000000000..cbde796622b --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json @@ -0,0 +1,122 @@ +[ + { + "cabal-version": "3.0.0.0", + "compiler": { + "flavour": "ghc", + "compiler-id": "ghc-8.6.4", + "path": "/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc" + }, + "components": [ + { + "type": "lib", + "name": "lib", + "unit-id": "Complex-0.1.0.0-inplace", + "compiler-args": [ + "-fbuilding-cabal-package", + "-O", + "-outputdir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-odir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-hidir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-stubdir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-i", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-isrc", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/autogen", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", + "-optP-include", + "-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/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", + "/home/baldr/.cabal/store/ghc-8.6.4/package.db", + "-package-db", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/packagedb/ghc-8.6.4", + "-package-id", + "base-4.12.0.0", + "-XHaskell2010", + "-threaded", + "-rtsopts", + "-with-rtsopts=-N", + "-Wall" + ], + "modules": [], + "src-files": [], + "src-dirs": [ + "src" + ] + } + ] + }, + { + "cabal-version": "3.0.0.0", + "compiler": { + "flavour": "ghc", + "compiler-id": "ghc-8.6.4", + "path": "/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc" + }, + "components": [ + { + "type": "exe", + "name": "exe:Complex", + "unit-id": "Complex-0.1.0.0-inplace-Complex", + "compiler-args": [ + "-fbuilding-cabal-package", + "-O", + "-outputdir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-odir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-hidir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-stubdir", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-i", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-isrc", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/Complex/autogen", + "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/Complex/autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", + "-optP-include", + "-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/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", + "/home/baldr/.cabal/store/ghc-8.6.4/package.db", + "-package-db", + "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/packagedb/ghc-8.6.4", + "-package-id", + "base-4.12.0.0", + "-XHaskell2010", + "-threaded", + "-rtsopts", + "-with-rtsopts=-N", + "-Wall", + "-Wredundant-constraints", + "-with-rtsopts=-T" + ], + "modules": [ + "Paths_complex" + ], + "src-files": [ + "Main.lhs" + ], + "src-dirs": [ + "src" + ] + } + ] + } +] \ No newline at end of file From 3dcc14a823307e9e1690ae5b9896fd868feb2718 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:12:44 +0200 Subject: [PATCH 24/43] Remove unit.json that is a temporary file --- .../PackageTests/ShowBuildInfo/A/unit.json | 1 - unit.json | 282 ++++++++++++++++++ 2 files changed, 282 insertions(+), 1 deletion(-) delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json create mode 100644 unit.json diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json b/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json deleted file mode 100644 index 00cea5f5f03..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json +++ /dev/null @@ -1 +0,0 @@ -[{"cabal-version":"3.0.0.0","compiler":{"flavour":"ghc","compiler-id":"ghc-8.6.4","path":"/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc-8.6.4"},"components":[{"type":"lib","name":"lib","unit-id":"A-0.1.0.0-inplace","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-odir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-hidir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-stubdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-i","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-isrc","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build","-optP-include","-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/build/autogen/cabal_macros.h","-this-unit-id","A-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/home/.cabal/store/ghc-8.6.4/package.db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/packagedb/ghc-8.6.4","-package-id","base-4.12.0.0","-XHaskell2010"],"modules":["A"],"src-files":[],"src-dirs":["src"]}]},{"cabal-version":"3.0.0.0","compiler":{"flavour":"ghc","compiler-id":"ghc-8.6.4","path":"/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc-8.6.4"},"components":[{"type":"exe","name":"exe:A","unit-id":"A-0.1.0.0-inplace-A","compiler-args":["-fbuilding-cabal-package","-O","-outputdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-odir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-hidir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-stubdir","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-i","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-isrc","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen","-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/global-autogen","-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build","-optP-include","-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/build/x86_64-linux/ghc-8.6.4/A-0.1.0.0/x/A/build/A/autogen/cabal_macros.h","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/home/.cabal/store/ghc-8.6.4/package.db","-package-db","/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.dist/work/./dist/packagedb/ghc-8.6.4","-package-id","base-4.12.0.0","-XHaskell2010"],"modules":[],"src-files":["Main.hs"],"src-dirs":["src"]}]}] \ No newline at end of file diff --git a/unit.json b/unit.json new file mode 100644 index 00000000000..8d1e8d7e22b --- /dev/null +++ b/unit.json @@ -0,0 +1,282 @@ +[ + { + "cabal-version": "3.0.0.0", + "compiler": { + "flavour": "ghc", + "compiler-id": "ghc-8.6.4", + "path": "/nix/store/55csnj0rp4b88crsky9svglb90i9rsyx-ghc-8.6.4-with-packages/bin/ghc-8.6.4" + }, + "components": [ + { + "type": "exe", + "name": "exe:cabal", + "unit-id": "cabal-install-3.0.0.0-inplace-cabal", + "compiler-args": [ + "-fbuilding-cabal-package", + "-O", + "-outputdir", + "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-odir", + "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-hidir", + "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-stubdir", + "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-i", + "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-imain", + "-i.", + "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen", + "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen", + "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/global-autogen", + "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", + "-optP-include", + "-optP/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen/cabal_macros.h", + "-hide-all-packages", + "-Wmissing-home-modules", + "-no-user-package-db", + "-package-db", + "/home/baldr/.cabal/store/ghc-8.6.4/package.db", + "-package-db", + "/home/baldr/Documents/haskell/cabal/showinfo-dist/packagedb/ghc-8.6.4", + "-package-id", + "Cabal-3.0.0.0-inplace", + "-package-id", + "HTTP-4000.3.12-3RDNlv0dUf55uUEzxyCS7Y", + "-package-id", + "array-0.5.3.0", + "-package-id", + "async-2.2.1-6Mx2AftB9JuF2N8iGfZc3g", + "-package-id", + "base-4.12.0.0", + "-package-id", + "base16-bytestring-0.1.1.6-17atVnUhDnM13pAkKbwL6I", + "-package-id", + "binary-0.8.6.0", + "-package-id", + "bytestring-0.10.8.2", + "-package-id", + "containers-0.6.0.1", + "-package-id", + "cryptohash-sha256-0.11.101.0-4hEdGCusAXMBLiu8h413L1", + "-package-id", + "deepseq-1.4.4.0", + "-package-id", + "directory-1.3.3.0", + "-package-id", + "echo-0.1.3-ECiqPOMwsmlLdGbSgLjbPY", + "-package-id", + "edit-distance-0.2.2.1-B6mvKcqXpoPBl1SFk9eZwT", + "-package-id", + "filepath-1.4.2.1", + "-package-id", + "hackage-security-0.5.3.0-inplace", + "-package-id", + "hashable-1.2.7.0-3Td3QPpYpP355exFvEAGjQ", + "-package-id", + "mtl-2.2.2", + "-package-id", + "network-2.8.0.0-AkCJm1aNSYz7ekXKYyI0pF", + "-package-id", + "network-uri-2.6.1.0-1ERYjyKboJwKD55sQAb9dJ", + "-package-id", + "parsec-3.1.13.0", + "-package-id", + "pretty-1.1.3.6", + "-package-id", + "process-1.6.5.0", + "-package-id", + "random-1.1-3ypV4EIycgb35PKjTYYr5q", + "-package-id", + "resolv-0.1.1.2-FnHYhF4Lf0wK5YRpbsaqd7", + "-package-id", + "stm-2.5.0.0", + "-package-id", + "tar-0.5.1.0-HaIVxa1LuWJqqT6yxHWqZ", + "-package-id", + "text-1.2.3.1", + "-package-id", + "time-1.8.0.2", + "-package-id", + "unix-2.7.2.2", + "-package-id", + "zlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY", + "-XHaskell2010", + "-Wall", + "-fwarn-tabs", + "-rtsopts", + "-threaded", + "-Wcompat", + "-Wnoncanonical-monad-instances", + "-Wnoncanonical-monadfail-instances" + ], + "modules": [ + "Distribution.Deprecated.ParseUtils", + "Distribution.Deprecated.ReadP", + "Distribution.Deprecated.Text", + "Distribution.Deprecated.ViewAsFieldDescr", + "Distribution.Client.BuildReports.Anonymous", + "Distribution.Client.BuildReports.Storage", + "Distribution.Client.BuildReports.Types", + "Distribution.Client.BuildReports.Upload", + "Distribution.Client.Check", + "Distribution.Client.CmdBench", + "Distribution.Client.CmdBuild", + "Distribution.Client.CmdClean", + "Distribution.Client.CmdConfigure", + "Distribution.Client.CmdUpdate", + "Distribution.Client.CmdErrorMessages", + "Distribution.Client.CmdExec", + "Distribution.Client.CmdFreeze", + "Distribution.Client.CmdHaddock", + "Distribution.Client.CmdInstall", + "Distribution.Client.CmdInstall.ClientInstallFlags", + "Distribution.Client.CmdRepl", + "Distribution.Client.CmdRun", + "Distribution.Client.CmdShowBuildInfo", + "Distribution.Client.CmdTest", + "Distribution.Client.CmdLegacy", + "Distribution.Client.CmdSdist", + "Distribution.Client.Compat.Directory", + "Distribution.Client.Compat.ExecutablePath", + "Distribution.Client.Compat.FileLock", + "Distribution.Client.Compat.FilePerms", + "Distribution.Client.Compat.Prelude", + "Distribution.Client.Compat.Process", + "Distribution.Client.Compat.Semaphore", + "Distribution.Client.Config", + "Distribution.Client.Configure", + "Distribution.Client.Dependency", + "Distribution.Client.Dependency.Types", + "Distribution.Client.DistDirLayout", + "Distribution.Client.Exec", + "Distribution.Client.Fetch", + "Distribution.Client.FetchUtils", + "Distribution.Client.FileMonitor", + "Distribution.Client.Freeze", + "Distribution.Client.GZipUtils", + "Distribution.Client.GenBounds", + "Distribution.Client.Get", + "Distribution.Client.Glob", + "Distribution.Client.GlobalFlags", + "Distribution.Client.Haddock", + "Distribution.Client.HttpUtils", + "Distribution.Client.IndexUtils", + "Distribution.Client.IndexUtils.Timestamp", + "Distribution.Client.Init", + "Distribution.Client.Init.Heuristics", + "Distribution.Client.Init.Licenses", + "Distribution.Client.Init.Types", + "Distribution.Client.Install", + "Distribution.Client.InstallPlan", + "Distribution.Client.InstallSymlink", + "Distribution.Client.JobControl", + "Distribution.Client.List", + "Distribution.Client.Manpage", + "Distribution.Client.Nix", + "Distribution.Client.Outdated", + "Distribution.Client.PackageHash", + "Distribution.Client.PackageUtils", + "Distribution.Client.ParseUtils", + "Distribution.Client.ProjectBuilding", + "Distribution.Client.ProjectBuilding.Types", + "Distribution.Client.ProjectConfig", + "Distribution.Client.ProjectConfig.Legacy", + "Distribution.Client.ProjectConfig.Types", + "Distribution.Client.ProjectOrchestration", + "Distribution.Client.ProjectPlanOutput", + "Distribution.Client.ProjectPlanning", + "Distribution.Client.ProjectPlanning.Types", + "Distribution.Client.RebuildMonad", + "Distribution.Client.Reconfigure", + "Distribution.Client.Run", + "Distribution.Client.Sandbox", + "Distribution.Client.Sandbox.Index", + "Distribution.Client.Sandbox.PackageEnvironment", + "Distribution.Client.Sandbox.Timestamp", + "Distribution.Client.Sandbox.Types", + "Distribution.Client.SavedFlags", + "Distribution.Client.Security.DNS", + "Distribution.Client.Security.HTTP", + "Distribution.Client.Setup", + "Distribution.Client.SetupWrapper", + "Distribution.Client.SolverInstallPlan", + "Distribution.Client.SourceFiles", + "Distribution.Client.SourceRepoParse", + "Distribution.Client.SrcDist", + "Distribution.Client.Store", + "Distribution.Client.Tar", + "Distribution.Client.TargetSelector", + "Distribution.Client.Targets", + "Distribution.Client.Types", + "Distribution.Client.Update", + "Distribution.Client.Upload", + "Distribution.Client.Utils", + "Distribution.Client.Utils.Assertion", + "Distribution.Client.Utils.Json", + "Distribution.Client.Utils.Parsec", + "Distribution.Client.VCS", + "Distribution.Client.Win32SelfUpgrade", + "Distribution.Client.World", + "Distribution.Solver.Compat.Prelude", + "Distribution.Solver.Modular", + "Distribution.Solver.Modular.Assignment", + "Distribution.Solver.Modular.Builder", + "Distribution.Solver.Modular.Configured", + "Distribution.Solver.Modular.ConfiguredConversion", + "Distribution.Solver.Modular.ConflictSet", + "Distribution.Solver.Modular.Cycles", + "Distribution.Solver.Modular.Dependency", + "Distribution.Solver.Modular.Explore", + "Distribution.Solver.Modular.Flag", + "Distribution.Solver.Modular.Index", + "Distribution.Solver.Modular.IndexConversion", + "Distribution.Solver.Modular.LabeledGraph", + "Distribution.Solver.Modular.Linking", + "Distribution.Solver.Modular.Log", + "Distribution.Solver.Modular.Message", + "Distribution.Solver.Modular.PSQ", + "Distribution.Solver.Modular.Package", + "Distribution.Solver.Modular.Preference", + "Distribution.Solver.Modular.RetryLog", + "Distribution.Solver.Modular.Solver", + "Distribution.Solver.Modular.Tree", + "Distribution.Solver.Modular.Validate", + "Distribution.Solver.Modular.Var", + "Distribution.Solver.Modular.Version", + "Distribution.Solver.Modular.WeightedPSQ", + "Distribution.Solver.Types.ComponentDeps", + "Distribution.Solver.Types.ConstraintSource", + "Distribution.Solver.Types.DependencyResolver", + "Distribution.Solver.Types.Flag", + "Distribution.Solver.Types.InstSolverPackage", + "Distribution.Solver.Types.InstalledPreference", + "Distribution.Solver.Types.LabeledPackageConstraint", + "Distribution.Solver.Types.OptionalStanza", + "Distribution.Solver.Types.PackageConstraint", + "Distribution.Solver.Types.PackageFixedDeps", + "Distribution.Solver.Types.PackageIndex", + "Distribution.Solver.Types.PackagePath", + "Distribution.Solver.Types.PackagePreferences", + "Distribution.Solver.Types.PkgConfigDb", + "Distribution.Solver.Types.Progress", + "Distribution.Solver.Types.ResolverPackage", + "Distribution.Solver.Types.Settings", + "Distribution.Solver.Types.SolverId", + "Distribution.Solver.Types.SolverPackage", + "Distribution.Solver.Types.SourcePackage", + "Distribution.Solver.Types.Variable", + "Paths_cabal_install" + ], + "src-files": [ + "Main.hs" + ], + "src-dirs": [ + "main", + "." + ] + } + ] + } +] \ No newline at end of file From a1b4f6a9a75c9cdab73678ea3f2d1f2eee9faf02 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:24:49 +0200 Subject: [PATCH 25/43] Fix test for unit-file --- .../A/build-info-multiple-exact-unit-id-file.test.hs | 10 ++++++---- cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json | 0 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs index 5e0a17cd44e..039b5c7708b 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs @@ -6,10 +6,12 @@ import qualified Data.Text.Encoding as T import Data.Aeson import GHC.Generics -main = cabalTest $ do - r <- cabal' "new-show-build-info" ["--buildinfo-json-output=unit.json", "--unit-ids-json=A-0.1.0.0-inplace A-0.1.0.0-inplace-A", "-v0"] - shouldExist "unit.json" - buildInfoEither <- liftIO $ eitherDecodeFileStrict "unit.json" +main = cabalTest $ withSourceCopy $do + cwd <- fmap testCurrentDir getTestEnv + let fp = cwd "unit.json" + r <- cabal' "new-show-build-info" ["--buildinfo-json-output=" ++ fp, "--unit-ids-json=A-0.1.0.0-inplace A-0.1.0.0-inplace-A", "-v0"] + shouldExist fp + buildInfoEither <- liftIO $ eitherDecodeFileStrict fp case buildInfoEither of Left err -> fail $ "Could not parse build-info command" ++ err Right buildInfos -> do diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json b/cabal-testsuite/PackageTests/ShowBuildInfo/A/unit.json new file mode 100644 index 00000000000..e69de29bb2d From 114bb5a33c7af1e7ebb026f44b4520208bfc796f Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:27:25 +0200 Subject: [PATCH 26/43] Add fake repository for complex project --- .../Complex/repo/criterion-1.1.4.0/criterion.cabal | 8 ++++++++ .../repo/test-framework-0.8.1.1/test-framework.cabal | 8 ++++++++ 2 files changed, 16 insertions(+) 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 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 From b3b7ab1b9a6e2c430a47acc379d9cf68b05002da Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:33:58 +0200 Subject: [PATCH 27/43] Add exact test for library component --- .../ShowBuildInfo/B/build-info-lib-exact.out | 1 + .../B/build-info-lib-exact.test.hs | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.out b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs new file mode 100644 index 00000000000..13def3f091c --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs @@ -0,0 +1,67 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["lib:B", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "lib" (componentType component) + assertEqual "Component name" "lib" (componentName component) + assertEqual "Component unit-id" "B-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file From 70359c6feef65562169c7aadce7cbc4fc00bc99d Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:40:04 +0200 Subject: [PATCH 28/43] Add check for component modules --- .../PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs | 1 + .../A/build-info-multiple-exact-unit-id-file.test.hs | 2 ++ .../ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs | 2 ++ .../ShowBuildInfo/A/build-info-multiple-exact.test.hs | 2 ++ .../PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs | 1 + .../PackageTests/ShowBuildInfo/Complex/Complex.cabal | 2 ++ cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs | 1 + 7 files changed, 11 insertions(+) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs index 6449e181d28..240c39e7d40 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe-exact.test.hs @@ -24,6 +24,7 @@ main = cabalTest $ do assertEqual "Component name" "exe:A" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" [] (componentModules component) assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) return () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs index 039b5c7708b..7d1f87fa62e 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id-file.test.hs @@ -33,6 +33,7 @@ main = cabalTest $ withSourceCopy $do assertEqual "Component name" "exe:A" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" [] (componentModules component) assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) @@ -48,6 +49,7 @@ main = cabalTest $ withSourceCopy $do assertEqual "Component name" "lib" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["A"] (componentModules component) assertEqual "Component source files" [] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs index 3fee513f545..3b82c94c393 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact-unit-id.test.hs @@ -30,6 +30,7 @@ main = cabalTest $ do assertEqual "Component name" "exe:A" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" [] (componentModules component) assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) @@ -45,6 +46,7 @@ main = cabalTest $ do assertEqual "Component name" "lib" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["A"] (componentModules component) assertEqual "Component source files" [] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs index 899a4720526..c410954fa27 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-multiple-exact.test.hs @@ -30,6 +30,7 @@ main = cabalTest $ do assertEqual "Component name" "exe:A" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace-A" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" [] (componentModules component) assertEqual "Component source files" ["Main.hs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) @@ -45,6 +46,7 @@ main = cabalTest $ do assertEqual "Component name" "lib" (componentName component) assertEqual "Component unit-id" "A-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["A"] (componentModules component) assertEqual "Component source files" [] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs index 13def3f091c..31ef1fdc9f4 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib-exact.test.hs @@ -24,6 +24,7 @@ main = cabalTest $ do assertEqual "Component name" "lib" (componentName component) assertEqual "Component unit-id" "B-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["A"] (componentModules component) assertEqual "Component source files" [] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) return () diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index 6eac38850ac..1b3132698bf 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -28,11 +28,13 @@ executable Complex test-suite unit-test type: exitcode-stdio-1.0 hs-source-dirs: test + build-depends: test-framework main-is: Main.hs test-suite func-test type: exitcode-stdio-1.0 hs-source-dirs: test + build-depends: test-framework main-is: Main.hs benchmark complex-benchmarks diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs index 672e9580f8d..6acf264b038 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs @@ -24,6 +24,7 @@ main = cabalTest $ do assertEqual "Component name" "exe:Complex" (componentName component) assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Paths_complex"] (componentModules component) assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) return () From 7014bb7a188811a257bfa0805700e509b91a7403 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 9 Jun 2019 18:55:30 +0200 Subject: [PATCH 29/43] Prepare test component tests --- .../ShowBuildInfo/Complex/Complex.cabal | 2 + .../ShowBuildInfo/Complex/func-test.test.hs | 69 +++++++++++++++++++ .../ShowBuildInfo/Complex/lib.out | 1 + .../ShowBuildInfo/Complex/lib.test.hs | 68 ++++++++++++++++++ .../ShowBuildInfo/Complex/unit-test.test.hs | 68 ++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.out create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index 1b3132698bf..d62b4bf685e 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -13,6 +13,8 @@ library build-depends: base >=4.0.0 hs-source-dirs: src default-language: Haskell2010 + exposed-modules: Lib + other-modules: Paths_complex ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs new file mode 100644 index 00000000000..adbbabf1559 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs @@ -0,0 +1,69 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ withRepo "repo" $ do + r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "test" (componentType component) + assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.out b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.out new file mode 100644 index 00000000000..bc3b3f767eb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.out @@ -0,0 +1 @@ +# cabal new-show-build-info diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs new file mode 100644 index 00000000000..43b99247ac9 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs @@ -0,0 +1,68 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ do + r <- cabal' "new-show-build-info" ["lib:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "lib" (componentType component) + assertEqual "Component name" "lib" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs new file mode 100644 index 00000000000..e2280b47ab8 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs @@ -0,0 +1,68 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ withRepo "repo" $ do + r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "test" (componentType component) + assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file From 1bd70df90cfd4dd8726fa2937d5d4ad8ccbbbbf0 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 13 Jun 2019 19:09:48 +0200 Subject: [PATCH 30/43] Manually escape special json characters --- Cabal/Distribution/Simple/Utils/Json.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Cabal/Distribution/Simple/Utils/Json.hs b/Cabal/Distribution/Simple/Utils/Json.hs index f748a340b08..f90f2f38aa2 100644 --- a/Cabal/Distribution/Simple/Utils/Json.hs +++ b/Cabal/Distribution/Simple/Utils/Json.hs @@ -22,15 +22,25 @@ renderJson (JsonNumber n) = shows n renderJson (JsonObject attrs) = surround "{" "}" $ intercalate "," $ map render attrs where - render (k,v) = (surround "\"" "\"" $ showString k) . showString ":" . renderJson v -renderJson (JsonString s) = surround "\"" "\"" $ showString s + render (k,v) = (surround "\"" "\"" $ showString' k) . showString ":" . renderJson v +renderJson (JsonString s) = surround "\"" "\"" $ showString' s surround :: String -> String -> ShowS -> ShowS surround begin end middle = showString begin . middle . showString end +showString' :: String -> ShowS +showString' xs = showStringWorker xs + where + showStringWorker :: String -> ShowS + showStringWorker ('\"':as) = showString "\\\"" . showStringWorker as + showStringWorker ('\\':as) = showString "\\\\" . showStringWorker as + showStringWorker ('\'':as) = showString "\\\'" . showStringWorker as + showStringWorker (x:as) = showString [x] . showStringWorker as + showStringWorker [] = showString "" + intercalate :: String -> [ShowS] -> ShowS intercalate sep = go where go [] = id go [x] = x - go (x:xs) = x . showString sep . go xs + go (x:xs) = x . showString' sep . go xs From e2139255aff98216d317b966c1bd9facb3bcfa38 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 13 Jun 2019 21:26:35 +0200 Subject: [PATCH 31/43] Remove/adapt inaccurate test cases --- .../ShowBuildInfo/A/build-info-exe.out | 3 --- .../ShowBuildInfo/A/build-info-exe.test.hs | 17 ----------------- .../ShowBuildInfo/A/build-info-lib.out | 3 --- .../ShowBuildInfo/A/build-info-lib.test.hs | 16 ---------------- .../ShowBuildInfo/A/build-info-unknown.test.hs | 8 ++++---- .../ShowBuildInfo/B/build-info-lib.test.hs | 17 ----------------- 6 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out deleted file mode 100644 index 64b379f5fdc..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.out +++ /dev/null @@ -1,3 +0,0 @@ -# cabal new-show-build-info -Resolving dependencies... -Configuring 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 deleted file mode 100644 index ed5d0c57e1f..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-exe.test.hs +++ /dev/null @@ -1,17 +0,0 @@ -import Test.Cabal.Prelude - -main = cabalTest $ do - r <- cabal' "new-show-build-info" ["exe:A"] - assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r - assertOutputContains "\"compiler\":{" r - assertOutputContains "\"flavour\":\"ghc\"" r - assertOutputContains "\"compiler-id\":" r - assertOutputContains "\"path\":" r - assertOutputContains "\"type\":\"exe\"" r - assertOutputContains "\"name\":\"exe:A\"" r - assertOutputContains "\"unit-id\":\"A-0.1.0.0-inplace-A\"" r - assertOutputContains "\"compiler-args\":[" r - assertOutputContains "\"modules\":[]" r - assertOutputContains "\"src-files\":[\"Main.hs\"]" r - assertOutputContains "\"src-dirs\":[\"src\"]" r - diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out deleted file mode 100644 index 3162a2cdecd..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.out +++ /dev/null @@ -1,3 +0,0 @@ -# cabal new-show-build-info -Resolving dependencies... -Configuring library for A-0.1.0.0.. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs deleted file mode 100644 index e14f0d87808..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-lib.test.hs +++ /dev/null @@ -1,16 +0,0 @@ -import Test.Cabal.Prelude - -main = cabalTest $ do - r <- cabal' "new-show-build-info" ["lib:A"] - assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r - assertOutputContains "\"compiler\":{" r - assertOutputContains "\"flavour\":\"ghc\"" r - assertOutputContains "\"compiler-id\":" r - assertOutputContains "\"path\":" r - assertOutputContains "\"type\":\"lib\"" r - assertOutputContains "\"name\":\"lib\"" r - assertOutputContains "\"unit-id\":\"A-0.1.0.0-inplace\"" r - assertOutputContains "\"compiler-args\":[" r - assertOutputContains "\"modules\":[\"A\"]" r - assertOutputContains "\"src-files\":[]" r - assertOutputContains "\"src-dirs\":[\"src\"]" r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs index 35968002aae..44ca75277cf 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/build-info-unknown.test.hs @@ -2,13 +2,13 @@ import Test.Cabal.Prelude main = cabalTest $ do r <- fails $ cabal' "new-show-build-info" ["exe:B"] - assertOutputContains "cabal: Internal error in target matching." r + assertOutputContains "Internal error in target matching." r r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=B-inplace-0.1.0.0"] - assertOutputContains "cabal: No unit B-inplace-0.1.0.0" r + assertOutputContains "No unit B-inplace-0.1.0.0" r r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace B-inplace-0.1.0.0"] - assertOutputContains "cabal: No unit B-inplace-0.1.0.0" r + assertOutputContains "No unit B-inplace-0.1.0.0" r r <- fails $ cabal' "new-show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace", "exe:B"] - assertOutputContains "cabal: Internal error in target matching." r + assertOutputContains "Internal error in target matching." r diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs deleted file mode 100644 index cf984db11b2..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/B/build-info-lib.test.hs +++ /dev/null @@ -1,17 +0,0 @@ -import Test.Cabal.Prelude - -main = cabalTest $ - recordMode DoNotRecord $ do - r <- cabal' "new-show-build-info" ["lib:B"] - assertOutputContains "\"cabal-version\":\"3.0.0.0\"" r - assertOutputContains "\"compiler\":{" r - assertOutputContains "\"flavour\":\"ghc\"" r - assertOutputContains "\"compiler-id\":" r - assertOutputContains "\"path\":" r - assertOutputContains "\"type\":\"lib\"" r - assertOutputContains "\"name\":\"lib\"" r - assertOutputContains "\"unit-id\":\"B-0.1.0.0-inplace\"" r - assertOutputContains "\"compiler-args\":[" r - assertOutputContains "\"modules\":[\"A\"]" r - assertOutputContains "\"src-files\":[]" r - assertOutputContains "\"src-dirs\":[\"src\"]" r From e1b3875bb8b8521b856d11cab50ea800129196e5 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 13 Jun 2019 22:08:18 +0200 Subject: [PATCH 32/43] More explicit check for ghc flags --- .../ShowBuildInfo/Complex/Complex.cabal | 2 +- .../ShowBuildInfo/Complex/exe.test.hs | 16 ++++++++++++++++ .../ShowBuildInfo/Complex/lib.test.hs | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index d62b4bf685e..0f1d5ca0e81 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -24,7 +24,7 @@ executable Complex hs-source-dirs: src default-language: Haskell2010 other-modules: Paths_complex - ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wredundant-constraints -with-rtsopts=-T test-suite unit-test diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs index 6acf264b038..91c2cec1429 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs @@ -24,6 +24,22 @@ main = cabalTest $ do assertEqual "Component name" "exe:Complex" (componentName component) assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-with-rtsopts=-T" + , "-Wredundant-constraints" + ] + ) + assertBool "Component ghc-options does not contain -Wall" + (all + (`notElem` componentCompilerArgs component) + [ "-Wall" + ] + ) assertEqual "Component modules" ["Paths_complex"] (componentModules component) assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs index 43b99247ac9..932c12a5955 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/lib.test.hs @@ -24,6 +24,21 @@ main = cabalTest $ do assertEqual "Component name" "lib" (componentName component) assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-Wall" + ] + ) + assertBool "Component ghc-options does not contain -Wredundant-constraints" + (all + (`notElem` componentCompilerArgs component) + [ "-Wredundant-constraints" + ] + ) assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) assertEqual "Component source files" [] (componentSrcFiles component) assertEqual "Component source directories" ["src"] (componentSrcDirs component) From 4562c8db717adeb4db04fca8e9032d89432c1b17 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 13 Jun 2019 22:30:23 +0200 Subject: [PATCH 33/43] Remove accidentally commited build-info files --- .../ShowBuildInfo/Complex/unit.json | 122 -------- unit.json | 282 ------------------ 2 files changed, 404 deletions(-) delete mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json delete mode 100644 unit.json diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json deleted file mode 100644 index cbde796622b..00000000000 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit.json +++ /dev/null @@ -1,122 +0,0 @@ -[ - { - "cabal-version": "3.0.0.0", - "compiler": { - "flavour": "ghc", - "compiler-id": "ghc-8.6.4", - "path": "/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc" - }, - "components": [ - { - "type": "lib", - "name": "lib", - "unit-id": "Complex-0.1.0.0-inplace", - "compiler-args": [ - "-fbuilding-cabal-package", - "-O", - "-outputdir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-odir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-hidir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-stubdir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-i", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-isrc", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/autogen", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/build", - "-optP-include", - "-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/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", - "/home/baldr/.cabal/store/ghc-8.6.4/package.db", - "-package-db", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/packagedb/ghc-8.6.4", - "-package-id", - "base-4.12.0.0", - "-XHaskell2010", - "-threaded", - "-rtsopts", - "-with-rtsopts=-N", - "-Wall" - ], - "modules": [], - "src-files": [], - "src-dirs": [ - "src" - ] - } - ] - }, - { - "cabal-version": "3.0.0.0", - "compiler": { - "flavour": "ghc", - "compiler-id": "ghc-8.6.4", - "path": "/nix/store/szbf00bn66l9d45ivrhlsq0psf6f0div-ghc-8.6.4-with-packages/bin/ghc" - }, - "components": [ - { - "type": "exe", - "name": "exe:Complex", - "unit-id": "Complex-0.1.0.0-inplace-Complex", - "compiler-args": [ - "-fbuilding-cabal-package", - "-O", - "-outputdir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-odir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-hidir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-stubdir", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-i", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-isrc", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/Complex/autogen", - "-i/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/Complex/autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/Complex-0.1.0.0/x/Complex/build", - "-optP-include", - "-optP/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/build/x86_64-linux/ghc-8.6.4/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", - "/home/baldr/.cabal/store/ghc-8.6.4/package.db", - "-package-db", - "/home/baldr/Documents/haskell/cabal/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/dist-newstyle/packagedb/ghc-8.6.4", - "-package-id", - "base-4.12.0.0", - "-XHaskell2010", - "-threaded", - "-rtsopts", - "-with-rtsopts=-N", - "-Wall", - "-Wredundant-constraints", - "-with-rtsopts=-T" - ], - "modules": [ - "Paths_complex" - ], - "src-files": [ - "Main.lhs" - ], - "src-dirs": [ - "src" - ] - } - ] - } -] \ No newline at end of file diff --git a/unit.json b/unit.json deleted file mode 100644 index 8d1e8d7e22b..00000000000 --- a/unit.json +++ /dev/null @@ -1,282 +0,0 @@ -[ - { - "cabal-version": "3.0.0.0", - "compiler": { - "flavour": "ghc", - "compiler-id": "ghc-8.6.4", - "path": "/nix/store/55csnj0rp4b88crsky9svglb90i9rsyx-ghc-8.6.4-with-packages/bin/ghc-8.6.4" - }, - "components": [ - { - "type": "exe", - "name": "exe:cabal", - "unit-id": "cabal-install-3.0.0.0-inplace-cabal", - "compiler-args": [ - "-fbuilding-cabal-package", - "-O", - "-outputdir", - "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-odir", - "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-hidir", - "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-stubdir", - "/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-i", - "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-imain", - "-i.", - "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen", - "-i/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen", - "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/global-autogen", - "-I/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build", - "-optP-include", - "-optP/home/baldr/Documents/haskell/cabal/showinfo-dist/build/x86_64-linux/ghc-8.6.4/cabal-install-3.0.0.0/build/cabal/autogen/cabal_macros.h", - "-hide-all-packages", - "-Wmissing-home-modules", - "-no-user-package-db", - "-package-db", - "/home/baldr/.cabal/store/ghc-8.6.4/package.db", - "-package-db", - "/home/baldr/Documents/haskell/cabal/showinfo-dist/packagedb/ghc-8.6.4", - "-package-id", - "Cabal-3.0.0.0-inplace", - "-package-id", - "HTTP-4000.3.12-3RDNlv0dUf55uUEzxyCS7Y", - "-package-id", - "array-0.5.3.0", - "-package-id", - "async-2.2.1-6Mx2AftB9JuF2N8iGfZc3g", - "-package-id", - "base-4.12.0.0", - "-package-id", - "base16-bytestring-0.1.1.6-17atVnUhDnM13pAkKbwL6I", - "-package-id", - "binary-0.8.6.0", - "-package-id", - "bytestring-0.10.8.2", - "-package-id", - "containers-0.6.0.1", - "-package-id", - "cryptohash-sha256-0.11.101.0-4hEdGCusAXMBLiu8h413L1", - "-package-id", - "deepseq-1.4.4.0", - "-package-id", - "directory-1.3.3.0", - "-package-id", - "echo-0.1.3-ECiqPOMwsmlLdGbSgLjbPY", - "-package-id", - "edit-distance-0.2.2.1-B6mvKcqXpoPBl1SFk9eZwT", - "-package-id", - "filepath-1.4.2.1", - "-package-id", - "hackage-security-0.5.3.0-inplace", - "-package-id", - "hashable-1.2.7.0-3Td3QPpYpP355exFvEAGjQ", - "-package-id", - "mtl-2.2.2", - "-package-id", - "network-2.8.0.0-AkCJm1aNSYz7ekXKYyI0pF", - "-package-id", - "network-uri-2.6.1.0-1ERYjyKboJwKD55sQAb9dJ", - "-package-id", - "parsec-3.1.13.0", - "-package-id", - "pretty-1.1.3.6", - "-package-id", - "process-1.6.5.0", - "-package-id", - "random-1.1-3ypV4EIycgb35PKjTYYr5q", - "-package-id", - "resolv-0.1.1.2-FnHYhF4Lf0wK5YRpbsaqd7", - "-package-id", - "stm-2.5.0.0", - "-package-id", - "tar-0.5.1.0-HaIVxa1LuWJqqT6yxHWqZ", - "-package-id", - "text-1.2.3.1", - "-package-id", - "time-1.8.0.2", - "-package-id", - "unix-2.7.2.2", - "-package-id", - "zlib-0.6.2-BdOecmQ0rL1HOiGypdSgxY", - "-XHaskell2010", - "-Wall", - "-fwarn-tabs", - "-rtsopts", - "-threaded", - "-Wcompat", - "-Wnoncanonical-monad-instances", - "-Wnoncanonical-monadfail-instances" - ], - "modules": [ - "Distribution.Deprecated.ParseUtils", - "Distribution.Deprecated.ReadP", - "Distribution.Deprecated.Text", - "Distribution.Deprecated.ViewAsFieldDescr", - "Distribution.Client.BuildReports.Anonymous", - "Distribution.Client.BuildReports.Storage", - "Distribution.Client.BuildReports.Types", - "Distribution.Client.BuildReports.Upload", - "Distribution.Client.Check", - "Distribution.Client.CmdBench", - "Distribution.Client.CmdBuild", - "Distribution.Client.CmdClean", - "Distribution.Client.CmdConfigure", - "Distribution.Client.CmdUpdate", - "Distribution.Client.CmdErrorMessages", - "Distribution.Client.CmdExec", - "Distribution.Client.CmdFreeze", - "Distribution.Client.CmdHaddock", - "Distribution.Client.CmdInstall", - "Distribution.Client.CmdInstall.ClientInstallFlags", - "Distribution.Client.CmdRepl", - "Distribution.Client.CmdRun", - "Distribution.Client.CmdShowBuildInfo", - "Distribution.Client.CmdTest", - "Distribution.Client.CmdLegacy", - "Distribution.Client.CmdSdist", - "Distribution.Client.Compat.Directory", - "Distribution.Client.Compat.ExecutablePath", - "Distribution.Client.Compat.FileLock", - "Distribution.Client.Compat.FilePerms", - "Distribution.Client.Compat.Prelude", - "Distribution.Client.Compat.Process", - "Distribution.Client.Compat.Semaphore", - "Distribution.Client.Config", - "Distribution.Client.Configure", - "Distribution.Client.Dependency", - "Distribution.Client.Dependency.Types", - "Distribution.Client.DistDirLayout", - "Distribution.Client.Exec", - "Distribution.Client.Fetch", - "Distribution.Client.FetchUtils", - "Distribution.Client.FileMonitor", - "Distribution.Client.Freeze", - "Distribution.Client.GZipUtils", - "Distribution.Client.GenBounds", - "Distribution.Client.Get", - "Distribution.Client.Glob", - "Distribution.Client.GlobalFlags", - "Distribution.Client.Haddock", - "Distribution.Client.HttpUtils", - "Distribution.Client.IndexUtils", - "Distribution.Client.IndexUtils.Timestamp", - "Distribution.Client.Init", - "Distribution.Client.Init.Heuristics", - "Distribution.Client.Init.Licenses", - "Distribution.Client.Init.Types", - "Distribution.Client.Install", - "Distribution.Client.InstallPlan", - "Distribution.Client.InstallSymlink", - "Distribution.Client.JobControl", - "Distribution.Client.List", - "Distribution.Client.Manpage", - "Distribution.Client.Nix", - "Distribution.Client.Outdated", - "Distribution.Client.PackageHash", - "Distribution.Client.PackageUtils", - "Distribution.Client.ParseUtils", - "Distribution.Client.ProjectBuilding", - "Distribution.Client.ProjectBuilding.Types", - "Distribution.Client.ProjectConfig", - "Distribution.Client.ProjectConfig.Legacy", - "Distribution.Client.ProjectConfig.Types", - "Distribution.Client.ProjectOrchestration", - "Distribution.Client.ProjectPlanOutput", - "Distribution.Client.ProjectPlanning", - "Distribution.Client.ProjectPlanning.Types", - "Distribution.Client.RebuildMonad", - "Distribution.Client.Reconfigure", - "Distribution.Client.Run", - "Distribution.Client.Sandbox", - "Distribution.Client.Sandbox.Index", - "Distribution.Client.Sandbox.PackageEnvironment", - "Distribution.Client.Sandbox.Timestamp", - "Distribution.Client.Sandbox.Types", - "Distribution.Client.SavedFlags", - "Distribution.Client.Security.DNS", - "Distribution.Client.Security.HTTP", - "Distribution.Client.Setup", - "Distribution.Client.SetupWrapper", - "Distribution.Client.SolverInstallPlan", - "Distribution.Client.SourceFiles", - "Distribution.Client.SourceRepoParse", - "Distribution.Client.SrcDist", - "Distribution.Client.Store", - "Distribution.Client.Tar", - "Distribution.Client.TargetSelector", - "Distribution.Client.Targets", - "Distribution.Client.Types", - "Distribution.Client.Update", - "Distribution.Client.Upload", - "Distribution.Client.Utils", - "Distribution.Client.Utils.Assertion", - "Distribution.Client.Utils.Json", - "Distribution.Client.Utils.Parsec", - "Distribution.Client.VCS", - "Distribution.Client.Win32SelfUpgrade", - "Distribution.Client.World", - "Distribution.Solver.Compat.Prelude", - "Distribution.Solver.Modular", - "Distribution.Solver.Modular.Assignment", - "Distribution.Solver.Modular.Builder", - "Distribution.Solver.Modular.Configured", - "Distribution.Solver.Modular.ConfiguredConversion", - "Distribution.Solver.Modular.ConflictSet", - "Distribution.Solver.Modular.Cycles", - "Distribution.Solver.Modular.Dependency", - "Distribution.Solver.Modular.Explore", - "Distribution.Solver.Modular.Flag", - "Distribution.Solver.Modular.Index", - "Distribution.Solver.Modular.IndexConversion", - "Distribution.Solver.Modular.LabeledGraph", - "Distribution.Solver.Modular.Linking", - "Distribution.Solver.Modular.Log", - "Distribution.Solver.Modular.Message", - "Distribution.Solver.Modular.PSQ", - "Distribution.Solver.Modular.Package", - "Distribution.Solver.Modular.Preference", - "Distribution.Solver.Modular.RetryLog", - "Distribution.Solver.Modular.Solver", - "Distribution.Solver.Modular.Tree", - "Distribution.Solver.Modular.Validate", - "Distribution.Solver.Modular.Var", - "Distribution.Solver.Modular.Version", - "Distribution.Solver.Modular.WeightedPSQ", - "Distribution.Solver.Types.ComponentDeps", - "Distribution.Solver.Types.ConstraintSource", - "Distribution.Solver.Types.DependencyResolver", - "Distribution.Solver.Types.Flag", - "Distribution.Solver.Types.InstSolverPackage", - "Distribution.Solver.Types.InstalledPreference", - "Distribution.Solver.Types.LabeledPackageConstraint", - "Distribution.Solver.Types.OptionalStanza", - "Distribution.Solver.Types.PackageConstraint", - "Distribution.Solver.Types.PackageFixedDeps", - "Distribution.Solver.Types.PackageIndex", - "Distribution.Solver.Types.PackagePath", - "Distribution.Solver.Types.PackagePreferences", - "Distribution.Solver.Types.PkgConfigDb", - "Distribution.Solver.Types.Progress", - "Distribution.Solver.Types.ResolverPackage", - "Distribution.Solver.Types.Settings", - "Distribution.Solver.Types.SolverId", - "Distribution.Solver.Types.SolverPackage", - "Distribution.Solver.Types.SourcePackage", - "Distribution.Solver.Types.Variable", - "Paths_cabal_install" - ], - "src-files": [ - "Main.hs" - ], - "src-dirs": [ - "main", - "." - ] - } - ] - } -] \ No newline at end of file From 53aa595e9f65cc09579b1bd96fff0d2a4ea823a7 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 13 Jun 2019 23:52:48 +0200 Subject: [PATCH 34/43] Pattern match on compiler flavour --- Cabal/Distribution/Simple/ShowBuildInfo.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Cabal/Distribution/Simple/ShowBuildInfo.hs b/Cabal/Distribution/Simple/ShowBuildInfo.hs index b89cb462795..b13f95b78f0 100644 --- a/Cabal/Distribution/Simple/ShowBuildInfo.hs +++ b/Cabal/Distribution/Simple/ShowBuildInfo.hs @@ -1,9 +1,9 @@ -- | -- This module defines a simple JSON-based format for exporting basic -- information about a Cabal package and the compiler configuration Cabal --- would use to build it. This can be produced with the +-- would use to build it. This can be produced with the -- @cabal new-show-build-info@ command. --- +-- -- -- This format is intended for consumption by external tooling and should -- therefore be rather stable. Moreover, this allows tooling users to avoid @@ -97,7 +97,15 @@ mkBuildInfo pkg_descr lbi _flags targetsToBuild = info ] where path = maybe JsonNull (JsonString . programPath) - $ lookupProgram ghcProgram (withPrograms lbi) + $ (flavorToProgram . compilerFlavor $ compiler lbi) + >>= flip lookupProgram (withPrograms lbi) + + flavorToProgram :: CompilerFlavor -> Maybe Program + flavorToProgram GHC = Just ghcProgram + flavorToProgram GHCJS = Just ghcjsProgram + flavorToProgram UHC = Just uhcProgram + flavorToProgram JHC = Just jhcProgram + flavorToProgram _ = Nothing mkComponentInfo (name, clbi) = JsonObject [ "type" .= JsonString compType From 928e92f5e6fb2770c506099eb1776e64a3fc4f16 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 18 Jun 2019 17:19:48 +0200 Subject: [PATCH 35/43] Modify test files --- .../ShowBuildInfo/Complex/Complex.cabal | 6 +- .../ShowBuildInfo/Complex/bench.test.hs | 84 +++++++++++++++++++ .../ShowBuildInfo/Complex/exe.test.hs | 74 ++++++++-------- .../ShowBuildInfo/Complex/func-test.test.hs | 4 +- .../ShowBuildInfo/Complex/unit-test.test.hs | 42 +++++----- 5 files changed, 147 insertions(+), 63 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index 0f1d5ca0e81..93947142a95 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -30,13 +30,13 @@ executable Complex test-suite unit-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework + build-depends: test-framework == 0.8.1.1 main-is: Main.hs test-suite func-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework + build-depends: test-framework == 0.8.1.1 main-is: Main.hs benchmark complex-benchmarks @@ -49,6 +49,6 @@ benchmark complex-benchmarks ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N build-depends: base - , criterion + , criterion == 1.1.4.0 , Complex default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs new file mode 100644 index 00000000000..e8c59683dfb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs @@ -0,0 +1,84 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ withRepo "repo" $ do + r <- cabal' "new-show-build-info" ["--enable-benchmarks", "bench:complex-benchmarks", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "benchmark" (componentType component) + assertEqual "Component name" "bench:complex-brenchmarks" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-with-rtsopts=-T" + , "-Wredundant-constraints" + ] + ) + assertBool "Component ghc-options does not contain -Wall" + (all + (`notElem` componentCompilerArgs component) + [ "-Wall" + ] + ) + assertEqual "Component modules" ["Paths_complex"] (componentModules component) + assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +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 :: [String] + , componentSrcDirs :: [String] + } 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 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs index 91c2cec1429..43250743de8 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs @@ -7,43 +7,43 @@ import Data.Aeson import GHC.Generics main = cabalTest $ do - r <- cabal' "new-show-build-info" ["exe:Complex", "-v0"] - let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] - case buildInfoEither of - Left err -> fail $ "Could not parse build-info command" ++ err - Right buildInfos -> do - assertEqual "Build Infos, exactly one" 1 (length buildInfos) - let [buildInfo] = buildInfos - assertEqual "Cabal Version" "3.0.0.0" (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) - assertEqual "Components, exactly one" 1 (length $ components buildInfo) - let [component] = components buildInfo - assertEqual "Component type" "exe" (componentType component) - assertEqual "Component name" "exe:Complex" (componentName component) - assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) - assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) - assertBool "Component ghc-options contains all specified in .cabal" - (all - (`elem` componentCompilerArgs component) - [ "-threaded" - , "-rtsopts" - , "-with-rtsopts=-N" - , "-with-rtsopts=-T" - , "-Wredundant-constraints" - ] - ) - assertBool "Component ghc-options does not contain -Wall" - (all - (`notElem` componentCompilerArgs component) - [ "-Wall" - ] - ) - assertEqual "Component modules" ["Paths_complex"] (componentModules component) - assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) - assertEqual "Component source directories" ["src"] (componentSrcDirs component) - return () + r <- cabal' "new-show-build-info" ["exe:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:Complex" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-with-rtsopts=-T" + , "-Wredundant-constraints" + ] + ) + assertBool "Component ghc-options does not contain -Wall" + (all + (`notElem` componentCompilerArgs component) + [ "-Wall" + ] + ) + assertEqual "Component modules" ["Paths_complex"] (componentModules component) + assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () data BuildInfo = BuildInfo { cabalVersion :: String diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs index adbbabf1559..f12dd74c6c9 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs @@ -7,7 +7,7 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] + r <- cabal' "new-show-build-info" ["--enable-tests", ":func-test", "-v0"] let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] case buildInfoEither of Left err -> fail $ "Could not parse build-info command" ++ err @@ -21,7 +21,7 @@ main = cabalTest $ withRepo "repo" $ do assertEqual "Components, exactly one" 1 (length $ components buildInfo) let [component] = components buildInfo assertEqual "Component type" "test" (componentType component) - assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component name" "test:func" (componentName component) assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs index e2280b47ab8..4bbe2a81034 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs @@ -7,27 +7,27 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] - let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] - case buildInfoEither of - Left err -> fail $ "Could not parse build-info command" ++ err - Right buildInfos -> do - assertEqual "Build Infos, exactly one" 1 (length buildInfos) - let [buildInfo] = buildInfos - assertEqual "Cabal Version" "3.0.0.0" (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) - assertEqual "Components, exactly one" 1 (length $ components buildInfo) - let [component] = components buildInfo - assertEqual "Component type" "test" (componentType component) - assertEqual "Component name" "test:unit" (componentName component) - assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) - assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) - assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) - assertEqual "Component source files" [] (componentSrcFiles component) - assertEqual "Component source directories" ["src"] (componentSrcDirs component) - return () + r <- cabal' "new-show-build-info" ["--enable-tests", ":unit-test", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (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) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "test" (componentType component) + assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () data BuildInfo = BuildInfo { cabalVersion :: String From c0c1ac298a8f60ac325474292d0ff1a75d3bb080 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 18 Jun 2019 19:08:26 +0200 Subject: [PATCH 36/43] Add file ending for Cabal ShowBuildInfo --- cabal-install/Distribution/Client/CmdShowBuildInfo.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index d694de9e7ea..d78abd99645 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -185,7 +185,7 @@ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do printer "]" unitIdToFilePath :: UnitId -> FilePath - unitIdToFilePath unitId = "build-info-" ++ display unitId + unitIdToFilePath unitId = "build-info-" ++ display unitId ++ ".json" showInfo :: FilePath -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId From 0c1834306aa40c3c18a52e440881ac5f80776613 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 19 Jun 2019 18:28:36 +0200 Subject: [PATCH 37/43] Use hspec package instead of test-framework in test case --- .../PackageTests/ShowBuildInfo/Complex/Complex.cabal | 10 +++++----- .../test-framework.cabal => hspec-2.7.1/spec.cabal} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/{test-framework-0.8.1.1/test-framework.cabal => hspec-2.7.1/spec.cabal} (88%) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index 93947142a95..9047830cd4f 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -10,7 +10,7 @@ extra-source-files: CHANGELOG.md library - build-depends: base >=4.0.0 + build-depends: base hs-source-dirs: src default-language: Haskell2010 exposed-modules: Lib @@ -20,7 +20,7 @@ library executable Complex main-is: Main.lhs - build-depends: base >=4.0.0 + build-depends: base hs-source-dirs: src default-language: Haskell2010 other-modules: Paths_complex @@ -30,13 +30,13 @@ executable Complex test-suite unit-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework == 0.8.1.1 + build-depends: hspec main-is: Main.hs test-suite func-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework == 0.8.1.1 + build-depends: hspec main-is: Main.hs benchmark complex-benchmarks @@ -49,6 +49,6 @@ benchmark complex-benchmarks ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N build-depends: base - , criterion == 1.1.4.0 + , criterion , Complex 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/hspec-2.7.1/spec.cabal similarity index 88% rename from cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal rename to cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/spec.cabal index 2235e2eeb39..d203fd4cd0e 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/test-framework-0.8.1.1/test-framework.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/spec.cabal @@ -1,5 +1,5 @@ name: test-framework -version: 0.8.1.1 +version: 2.7.1 build-type: Simple cabal-version: >= 1.10 From 041e3705a3df7a316902ea7a47ac745d027cfa2c Mon Sep 17 00:00:00 2001 From: fendor Date: Fri, 21 Jun 2019 17:04:29 +0200 Subject: [PATCH 38/43] Fail if Cabal version is too old --- .../Distribution/Client/CmdShowBuildInfo.hs | 36 ++++++++++++++----- .../Distribution/Client/SetupWrapper.hs | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index d78abd99645..66fb76e3dd0 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -7,7 +7,8 @@ module Distribution.Client.CmdShowBuildInfo where -- showBuildInfoAction -- ) - +import Distribution.Client.Compat.Prelude + ( when, find, fromMaybe ) import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages import Distribution.Client.CmdInstall.ClientInstallFlags @@ -27,8 +28,14 @@ import Distribution.Verbosity ( Verbosity, silent ) import Distribution.Simple.Utils ( wrapText, die', withTempDirectory ) -import Distribution.Types.UnitId (UnitId, mkUnitId) -import Distribution.Deprecated.Text (display) +import Distribution.Types.UnitId + ( UnitId, mkUnitId ) +import Distribution.Types.Version + ( mkVersion ) +import Distribution.Types.PackageDescription + ( buildType ) +import Distribution.Deprecated.Text + ( display ) import qualified Data.Map as Map import qualified Distribution.Simple.Setup as Cabal @@ -47,9 +54,9 @@ import Distribution.Client.JobControl (newLock, Lock) import Distribution.Simple.Configure (tryGetPersistBuildConfig) import qualified Distribution.Client.CmdInstall as CmdInstall -import Control.Monad (mapM_) -import Data.List (find) -import Data.Maybe (fromMaybe) +import Control.Monad + ( mapM_ ) + import System.Directory (getTemporaryDirectory) import System.FilePath (()) @@ -195,6 +202,7 @@ showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId install = elaboratedPlanOriginal buildCtx dirLayout = distDirLayout baseCtx buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) + buildType' = buildType (elabPkgDescription pkg) flags = setupHsBuildFlags pkg shared verbosity buildDir args = setupHsBuildArgs pkg srcDir = case (elabPkgSourceLocation pkg) of @@ -211,6 +219,15 @@ showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId lock configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir configureArgs = setupHsConfigureArgs pkg + + -- check cabal version is corrct + (cabalVersion, _, _) <- getSetupMethod verbosity scriptOptions + (elabPkgDescription pkg) buildType' + when (cabalVersion < mkVersion [3, 0, 0,0]) + ( die' verbosity $ "Only a Cabal version >= 3.0.0.0 is supported for this command.\n" + <> "Found version: " <> display cabalVersion <> "\n" + <> "For component: " <> display targetUnitId + ) --Configure the package if there's no existing config lbi <- tryGetPersistBuildConfig buildDir case lbi of @@ -235,7 +252,10 @@ showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId ) ) (const args) - where mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs + where + mbPkg :: Maybe ElaboratedConfiguredPackage + mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs + -- | This defines what a 'TargetSelector' means for the @new-show-build-info@ command. -- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, @@ -307,4 +327,4 @@ renderTargetProblem (TargetProblemCommon problem) = renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = renderTargetProblemNoneEnabled "build" targetSelector targets renderTargetProblem(TargetProblemNoTargets targetSelector) = - renderTargetProblemNoTargets "build" targetSelector \ No newline at end of file + renderTargetProblemNoTargets "build" targetSelector diff --git a/cabal-install/Distribution/Client/SetupWrapper.hs b/cabal-install/Distribution/Client/SetupWrapper.hs index d422a2fddfb..955ac3b0c11 100644 --- a/cabal-install/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/Distribution/Client/SetupWrapper.hs @@ -17,7 +17,7 @@ -- runs it with the given arguments. module Distribution.Client.SetupWrapper ( - getSetup, runSetup, runSetupCommand, setupWrapper, + getSetup, runSetup, runSetupCommand, setupWrapper, getSetupMethod, SetupScriptOptions(..), defaultSetupScriptOptions, ) where From 83bf66255862483d2ae2ae1e3fda8b1dc41dfda3 Mon Sep 17 00:00:00 2001 From: fendor Date: Fri, 21 Jun 2019 17:05:29 +0200 Subject: [PATCH 39/43] Rename spec.cabal to hspec.cabal in test-suite --- .../Complex/repo/hspec-2.7.1/{spec.cabal => hspec.cabal} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/{spec.cabal => hspec.cabal} (100%) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/spec.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/hspec.cabal similarity index 100% rename from cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/spec.cabal rename to cabal-testsuite/PackageTests/ShowBuildInfo/Complex/repo/hspec-2.7.1/hspec.cabal From 141d7066cdc1b5e7289265abb53f1850014d8886 Mon Sep 17 00:00:00 2001 From: fendor Date: Fri, 21 Jun 2019 21:42:45 +0200 Subject: [PATCH 40/43] Prefer (++) over (<>) for string concatenation --- cabal-install/Distribution/Client/CmdShowBuildInfo.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 66fb76e3dd0..9d3edfa0a06 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -225,8 +225,8 @@ showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId (elabPkgDescription pkg) buildType' when (cabalVersion < mkVersion [3, 0, 0,0]) ( die' verbosity $ "Only a Cabal version >= 3.0.0.0 is supported for this command.\n" - <> "Found version: " <> display cabalVersion <> "\n" - <> "For component: " <> display targetUnitId + ++ "Found version: " ++ display cabalVersion ++ "\n" + ++ "For component: " ++ display targetUnitId ) --Configure the package if there's no existing config lbi <- tryGetPersistBuildConfig buildDir From decab601b7602a209de55ea0f67487535ccbb713 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 23 Jun 2019 11:22:58 +0200 Subject: [PATCH 41/43] Remove redundant import --- cabal-install/Distribution/Client/CmdShowBuildInfo.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 9d3edfa0a06..257a6793c61 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -54,9 +54,6 @@ import Distribution.Client.JobControl (newLock, Lock) import Distribution.Simple.Configure (tryGetPersistBuildConfig) import qualified Distribution.Client.CmdInstall as CmdInstall -import Control.Monad - ( mapM_ ) - import System.Directory (getTemporaryDirectory) import System.FilePath (()) From 0d0686729d3fdfb8743668cab45e3baa74a67809 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 23 Jun 2019 13:03:16 +0200 Subject: [PATCH 42/43] Use case of to be exhaustive in pattern matching --- .../Distribution/Client/CmdShowBuildInfo.hs | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs index 257a6793c61..9eb23aafb67 100644 --- a/cabal-install/Distribution/Client/CmdShowBuildInfo.hs +++ b/cabal-install/Distribution/Client/CmdShowBuildInfo.hs @@ -192,68 +192,68 @@ showTargets fileOutput unitIds verbosity baseCtx buildCtx lock = do unitIdToFilePath unitId = "build-info-" ++ display unitId ++ ".json" showInfo :: FilePath -> Verbosity -> ProjectBaseContext -> ProjectBuildContext -> Lock -> [ElaboratedConfiguredPackage] -> UnitId -> IO () -showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId - | Nothing <- mbPkg = die' verbosity $ "No unit " ++ display targetUnitId - | Just pkg <- mbPkg = do - let shared = elaboratedShared buildCtx - install = elaboratedPlanOriginal buildCtx - dirLayout = distDirLayout baseCtx - buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) - buildType' = buildType (elabPkgDescription pkg) - flags = setupHsBuildFlags pkg shared verbosity buildDir - args = setupHsBuildArgs pkg - srcDir = case (elabPkgSourceLocation pkg) of - LocalUnpackedPackage fp -> fp - _ -> "" - scriptOptions = setupHsScriptOptions - (ReadyPackage pkg) - install - shared - dirLayout - srcDir - buildDir - False - lock - configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir - configureArgs = setupHsConfigureArgs pkg - - -- check cabal version is corrct - (cabalVersion, _, _) <- getSetupMethod verbosity scriptOptions - (elabPkgDescription pkg) buildType' - when (cabalVersion < mkVersion [3, 0, 0,0]) - ( die' verbosity $ "Only a Cabal version >= 3.0.0.0 is supported for this command.\n" - ++ "Found version: " ++ display cabalVersion ++ "\n" - ++ "For component: " ++ display targetUnitId - ) - --Configure the package if there's no existing config - lbi <- tryGetPersistBuildConfig buildDir - case lbi of - Left _ -> setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.configureCommand defaultProgramDb) - (const configureFlags) - (const configureArgs) - Right _ -> pure () - - setupWrapper - verbosity - scriptOptions - (Just $ elabPkgDescription pkg) - (Cabal.showBuildInfoCommand defaultProgramDb) - (const (Cabal.ShowBuildInfoFlags - { Cabal.buildInfoBuildFlags = flags - , Cabal.buildInfoOutputFile = Just fileOutput - } +showInfo fileOutput verbosity baseCtx buildCtx lock pkgs targetUnitId = + case mbPkg of + Nothing -> die' verbosity $ "No unit " ++ display targetUnitId + Just pkg -> do + let shared = elaboratedShared buildCtx + install = elaboratedPlanOriginal buildCtx + dirLayout = distDirLayout baseCtx + buildDir = distBuildDirectory dirLayout (elabDistDirParams shared pkg) + buildType' = buildType (elabPkgDescription pkg) + flags = setupHsBuildFlags pkg shared verbosity buildDir + args = setupHsBuildArgs pkg + srcDir = case (elabPkgSourceLocation pkg) of + LocalUnpackedPackage fp -> fp + _ -> "" + scriptOptions = setupHsScriptOptions + (ReadyPackage pkg) + install + shared + dirLayout + srcDir + buildDir + False + lock + configureFlags = setupHsConfigureFlags (ReadyPackage pkg) shared verbosity buildDir + configureArgs = setupHsConfigureArgs pkg + + -- check cabal version is corrct + (cabalVersion, _, _) <- getSetupMethod verbosity scriptOptions + (elabPkgDescription pkg) buildType' + when (cabalVersion < mkVersion [3, 0, 0,0]) + ( die' verbosity $ "Only a Cabal version >= 3.0.0.0 is supported for this command.\n" + ++ "Found version: " ++ display cabalVersion ++ "\n" + ++ "For component: " ++ display targetUnitId + ) + --Configure the package if there's no existing config + lbi <- tryGetPersistBuildConfig buildDir + case lbi of + Left _ -> setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.configureCommand defaultProgramDb) + (const configureFlags) + (const configureArgs) + Right _ -> pure () + + setupWrapper + verbosity + scriptOptions + (Just $ elabPkgDescription pkg) + (Cabal.showBuildInfoCommand defaultProgramDb) + (const (Cabal.ShowBuildInfoFlags + { Cabal.buildInfoBuildFlags = flags + , Cabal.buildInfoOutputFile = Just fileOutput + } + ) ) - ) - (const args) + (const args) where mbPkg :: Maybe ElaboratedConfiguredPackage mbPkg = find ((targetUnitId ==) . elabUnitId) pkgs - -- | This defines what a 'TargetSelector' means for the @new-show-build-info@ command. -- It selects the 'AvailableTarget's that the 'TargetSelector' refers to, -- or otherwise classifies the problem. From 457d8a577d1585ee7f72ea088c549a28309e1de3 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 23 Jun 2019 13:04:13 +0200 Subject: [PATCH 43/43] Use qualified target names --- .../PackageTests/ShowBuildInfo/Complex/func-test.test.hs | 2 +- .../PackageTests/ShowBuildInfo/Complex/unit-test.test.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs index f12dd74c6c9..c0c4df28bd1 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs @@ -7,7 +7,7 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", ":func-test", "-v0"] + r <- cabal' "new-show-build-info" ["--enable-tests", "test:func-test", "-v0"] let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] case buildInfoEither of Left err -> fail $ "Could not parse build-info command" ++ err diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs index 4bbe2a81034..9eda7c27b8d 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs @@ -7,7 +7,7 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", ":unit-test", "-v0"] + r <- cabal' "new-show-build-info" ["--enable-tests", "test:unit-test", "-v0"] let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] case buildInfoEither of Left err -> fail $ "Could not parse build-info command" ++ err