Skip to content

Commit 3f5c2d2

Browse files
cfraz89fendor
authored andcommitted
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
1 parent 39ed3a3 commit 3f5c2d2

File tree

9 files changed

+694
-100
lines changed

9 files changed

+694
-100
lines changed

Cabal/Distribution/Simple.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ import Distribution.Simple.PreProcess
7373
import Distribution.Simple.Setup
7474
import Distribution.Simple.Command
7575

76-
import Distribution.Simple.Build ( build, showBuildInfo, repl )
77-
import Distribution.Simple.SrcDist ( sdist )
76+
import Distribution.Simple.Build
77+
import Distribution.Simple.SrcDist
7878
import Distribution.Simple.Register
7979

8080
import Distribution.Simple.Configure
@@ -179,6 +179,7 @@ defaultMainHelper hooks args = topHandler $
179179
\fs as -> configureAction hooks fs as >> return ()
180180
,buildCommand progs `commandAddAction` buildAction hooks
181181
,showBuildInfoCommand progs `commandAddAction` showBuildInfoAction hooks
182+
,writeAutogenFilesCommand progs `commandAddAction` writeAutogenFilesAction hooks
182183
,replCommand progs `commandAddAction` replAction hooks
183184
,installCommand `commandAddAction` installAction hooks
184185
,copyCommand `commandAddAction` copyAction hooks
@@ -285,6 +286,13 @@ showBuildInfoAction hooks flags args = do
285286

286287
postBuild hooks args flags' pkg_descr lbi'
287288

289+
writeAutogenFilesAction :: UserHooks -> WriteAutogenFilesFlags -> Args -> IO ()
290+
writeAutogenFilesAction hooks flags _ = do
291+
distPref <- findDistPrefOrDefault (wafDistPref flags)
292+
let verbosity = fromFlag $ wafVerbosity flags
293+
lbi <- getBuildConfig hooks verbosity distPref
294+
initialBuildSteps distPref (localPkgDescr lbi) lbi verbosity
295+
288296
replAction :: UserHooks -> ReplFlags -> Args -> IO ()
289297
replAction hooks flags args = do
290298
distPref <- findDistPrefOrDefault (replDistPref flags)

Cabal/Distribution/Simple/Build.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ import Distribution.Simple.Configure
7676
import Distribution.Simple.Register
7777
import Distribution.Simple.Test.LibV09
7878
import Distribution.Simple.Utils
79-
( createDirectoryIfMissingVerbose, rewriteFile, rewriteFileEx
80-
, die, die', info, debug, warn, setupMessage )
8179
import Distribution.Simple.Utils.Json
8280

8381
import Distribution.System

Cabal/Distribution/Simple/Setup.hs

Lines changed: 79 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ module Distribution.Simple.Setup (
4545
HaddockFlags(..), emptyHaddockFlags, defaultHaddockFlags, haddockCommand,
4646
HscolourFlags(..), emptyHscolourFlags, defaultHscolourFlags, hscolourCommand,
4747
BuildFlags(..), emptyBuildFlags, defaultBuildFlags, buildCommand,
48-
showBuildInfoCommand,
48+
49+
showBuildInfoCommand,
50+
writeAutogenFilesCommand,
51+
WriteAutogenFilesFlags(..),
4952
buildVerbose,
5053
ReplFlags(..), defaultReplFlags, replCommand,
5154
CleanFlags(..), emptyCleanFlags, defaultCleanFlags, cleanCommand,
@@ -1623,49 +1626,6 @@ instance Monoid CleanFlags where
16231626
instance Semigroup CleanFlags where
16241627
(<>) = gmappend
16251628

1626-
-- ------------------------------------------------------------
1627-
-- * show-build-info flags
1628-
-- ------------------------------------------------------------
1629-
1630-
showBuildInfoCommand :: ProgramConfiguration -> CommandUI BuildFlags
1631-
showBuildInfoCommand progConf = CommandUI
1632-
{ commandName = "show-build-info"
1633-
, commandSynopsis = "Emit details about how a package would be built."
1634-
, commandDescription = Just $ \_ -> wrapText $
1635-
"Components encompass executables, tests, and benchmarks.\n"
1636-
++ "\n"
1637-
++ "Affected by configuration options, see `configure`.\n"
1638-
, commandNotes = Just $ \pname ->
1639-
"Examples:\n"
1640-
++ " " ++ pname ++ " show-build-info "
1641-
++ " All the components in the package\n"
1642-
++ " " ++ pname ++ " show-build-info foo "
1643-
++ " A component (i.e. lib, exe, test suite)\n\n"
1644-
++ programFlagsDescription progConf
1645-
--TODO: re-enable once we have support for module/file targets
1646-
-- ++ " " ++ pname ++ " show-build-info Foo.Bar "
1647-
-- ++ " A module\n"
1648-
-- ++ " " ++ pname ++ " show-build-info Foo/Bar.hs"
1649-
-- ++ " A file\n\n"
1650-
-- ++ "If a target is ambiguous it can be qualified with the component "
1651-
-- ++ "name, e.g.\n"
1652-
-- ++ " " ++ pname ++ " show-build-info foo:Foo.Bar\n"
1653-
-- ++ " " ++ pname ++ " show-build-info testsuite1:Foo/Bar.hs\n"
1654-
, commandUsage = usageAlternatives "show-build-info" $
1655-
[ "[FLAGS]"
1656-
, "COMPONENTS [FLAGS]"
1657-
]
1658-
, commandDefaultFlags = defaultBuildFlags
1659-
, commandOptions = \showOrParseArgs ->
1660-
[ optionVerbosity
1661-
buildVerbosity (\v flags -> flags { buildVerbosity = v })
1662-
1663-
, optionDistPref
1664-
buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs
1665-
]
1666-
++ buildOptions progConf showOrParseArgs
1667-
}
1668-
16691629
-- ------------------------------------------------------------
16701630
-- * Build flags
16711631
-- ------------------------------------------------------------
@@ -2256,6 +2216,81 @@ optionNumJobs get set =
22562216
| otherwise -> Right (Just n)
22572217
_ -> Left "The jobs value should be a number or '$ncpus'"
22582218

2219+
2220+
-- ------------------------------------------------------------
2221+
-- * ghc-mod support flags
2222+
-- ------------------------------------------------------------
2223+
2224+
showBuildInfoCommand :: ProgramDb -> CommandUI BuildFlags
2225+
showBuildInfoCommand progDb = CommandUI
2226+
{ commandName = "show-build-info"
2227+
, commandSynopsis = "Emit details about how a package would be built."
2228+
, commandDescription = Just $ \_ -> wrapText $
2229+
"Components encompass executables, tests, and benchmarks.\n"
2230+
++ "\n"
2231+
++ "Affected by configuration options, see `configure`.\n"
2232+
, commandNotes = Just $ \pname ->
2233+
"Examples:\n"
2234+
++ " " ++ pname ++ " show-build-info "
2235+
++ " All the components in the package\n"
2236+
++ " " ++ pname ++ " show-build-info foo "
2237+
++ " A component (i.e. lib, exe, test suite)\n\n"
2238+
++ programFlagsDescription progDb
2239+
--TODO: re-enable once we have support for module/file targets
2240+
-- ++ " " ++ pname ++ " show-build-info Foo.Bar "
2241+
-- ++ " A module\n"
2242+
-- ++ " " ++ pname ++ " show-build-info Foo/Bar.hs"
2243+
-- ++ " A file\n\n"
2244+
-- ++ "If a target is ambiguous it can be qualified with the component "
2245+
-- ++ "name, e.g.\n"
2246+
-- ++ " " ++ pname ++ " show-build-info foo:Foo.Bar\n"
2247+
-- ++ " " ++ pname ++ " show-build-info testsuite1:Foo/Bar.hs\n"
2248+
, commandUsage = usageAlternatives "show-build-info" $
2249+
[ "[FLAGS]"
2250+
, "COMPONENTS [FLAGS]"
2251+
]
2252+
, commandDefaultFlags = defaultBuildFlags
2253+
, commandOptions = \showOrParseArgs ->
2254+
[ optionVerbosity
2255+
buildVerbosity (\v flags -> flags { buildVerbosity = v })
2256+
2257+
, optionDistPref
2258+
buildDistPref (\d flags -> flags { buildDistPref = d }) showOrParseArgs
2259+
]
2260+
++ buildOptions progDb showOrParseArgs
2261+
}
2262+
2263+
writeAutogenFilesCommand :: ProgramDb -> CommandUI WriteAutogenFilesFlags
2264+
writeAutogenFilesCommand progDb = CommandUI
2265+
{ commandName = "write-autogen-files"
2266+
, commandSynopsis = "Generate and write out the Paths_<pkg>.hs and cabal_macros.h files"
2267+
, commandDescription = Just $ \_ -> wrapText $
2268+
"Components encompass executables, tests, and benchmarks.\n"
2269+
++ "\n"
2270+
++ "Affected by configuration options, see `configure`.\n"
2271+
, commandNotes = Just $ \pname ->
2272+
"Examples:\n"
2273+
++ " " ++ pname ++ " write-autogen-files "
2274+
++ " All the components in the package\n"
2275+
++ " " ++ pname ++ " write-autogen-files foo "
2276+
++ " A component (i.e. lib, exe, test suite)\n\n"
2277+
++ programFlagsDescription progDb
2278+
, commandUsage = usageAlternatives "write-autogen-files" $
2279+
[ "[FLAGS]" ]
2280+
, commandDefaultFlags = WriteAutogenFilesFlags NoFlag (toFlag normal)
2281+
, commandOptions = \showOrParseArgs ->
2282+
[ optionVerbosity
2283+
wafVerbosity (\v flags -> flags { wafVerbosity = v })
2284+
2285+
, optionDistPref
2286+
wafDistPref (\d flags -> flags { wafDistPref = d }) showOrParseArgs
2287+
]
2288+
}
2289+
2290+
data WriteAutogenFilesFlags = WriteAutogenFilesFlags {
2291+
wafDistPref :: Flag FilePath,
2292+
wafVerbosity :: Flag Verbosity
2293+
} deriving Show
22592294
-- ------------------------------------------------------------
22602295
-- * Other Utils
22612296
-- ------------------------------------------------------------

Cabal/Distribution/Simple/UserHooks.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ data UserHooks = UserHooks {
7171

7272
-- |Hook to run before build command. Second arg indicates verbosity level.
7373
preBuild :: Args -> BuildFlags -> IO HookedBuildInfo,
74+
7475
-- |Over-ride this hook to get different behavior during build.
7576
buildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO (),
7677
-- |Hook to run after build command. Second arg indicates verbosity level.

0 commit comments

Comments
 (0)