Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Changelog for Shake (* = breaking change)

#784, add --list-targets to list the available targets
#860, add specialise pragmas (maybe 10% faster)
Test with GHC 9.14, preserving exception call stacks on GHC 9.12 and later
0.19.9, released 2026-01-19
Expand Down
1 change: 1 addition & 0 deletions docs/CommandLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ There are a number of different modes in which Shake can run, which have an over

* `-h, --help` -- print the a message about supported command line flags and exit.
* `-v, --version, --numeric-version` -- print version information and exit. This will always be the Shake version number as available on Hackage.
* `--list-targets[=PATTERN]` -- print the available targets (those matching `PATTERN`, if given) along with any documentation from `withTargetDocs`, and exit.
* `--demo` -- run in demo mode, which creates a demo project and compiles it, producing [this output](Demo.md).
* `-f FILE, --file=FILE, --makefile=FILE` -- read in `FILE` as a Makefile or [Ninja project](Ninja.md). By default will look for `build.ninja` and use that if it exists.
* `-t TOOL, --tool=TOOL` -- Ninja-compatible tools such as `compdb`, only valid when operating on a Ninja project.
Expand Down
28 changes: 19 additions & 9 deletions src/Development/Shake/Internal/Args.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Development.Shake.Internal.CompactUI
import Development.Shake.Internal.Demo
import Development.Shake.Internal.Core.Action
import Development.Shake.FilePath
import Development.Shake.Internal.FilePattern
import Development.Shake.Internal.Rules.File
import Development.Shake.Internal.Progress
import Development.Shake.Database
Expand Down Expand Up @@ -148,6 +149,7 @@ shakeArgsOptionsWith baseOpts userOptions rules = do
changeDirectory = listToMaybe [x | ChangeDirectory x <- flagsExtra]
printDirectory = lastDef False [x | PrintDirectory x <- flagsExtra]
shareRemoves = [x | ShareRemove x <- flagsExtra]
listTargets = [x | ListTargets x <- flagsExtra]
oshakeOpts = foldl' (flip ($)) baseOpts flagsShake
lintInside <- mapM canonicalizePath $ shakeLintInside oshakeOpts
let shakeOpts = oshakeOpts {shakeLintInside = map (toStandard . addTrailingPathSeparator) lintInside
Expand All @@ -158,18 +160,21 @@ shakeArgsOptionsWith baseOpts userOptions rules = do
}
let putWhen v msg = when (shakeVerbosity oshakeOpts >= v) $ shakeOutput oshakeOpts v msg
let putWhenLn v msg = putWhen v $ msg ++ "\n"
-- run the rules as simply as we can, to find the targets and help suffix
let collectTargets = do
rs <- rules shakeOpts [] []
case rs of
Just (_, rs) -> do
xs <- getTargets shakeOpts rs
helpSuffix <- getHelpSuffix shakeOpts rs
evaluate $ force (xs, helpSuffix)
_ -> pure ([], [])
let showTarget (a, b) = a ++ maybe "" (" - " ++) b
let showHelp long = do
progName <- getProgName
(targets, helpSuffix) <- if not long then pure ([], []) else
handleSynchronous (\e -> do putWhenLn Info $ "Failure to collect targets: " ++ show e; pure ([], [])) $ do
-- run the rules as simply as we can
rs <- rules shakeOpts [] []
case rs of
Just (_, rs) -> do
xs <- getTargets shakeOpts rs
helpSuffix <- getHelpSuffix shakeOpts rs
evaluate $ force ([" - " ++ a ++ maybe "" (" - " ++) b | (a,b) <- xs], helpSuffix)
_ -> pure ([], [])
handleSynchronous (\e -> do putWhenLn Info $ "Failure to collect targets: " ++ show e; pure ([], [])) $
first (map ((" - " ++) . showTarget)) <$> collectTargets
changes<- pure $
let as = shakeOptionsFields baseOpts
bs = shakeOptionsFields oshakeOpts
Expand All @@ -190,6 +195,9 @@ shakeArgsOptionsWith baseOpts userOptions rules = do

if Help `elem` flagsExtra then
showHelp True
else if not $ null listTargets then do
targets <- filter ((?==*) listTargets . fst) . fst <$> collectTargets
unless (null targets) $ putWhen Error $ intercalate "\n" $ map showTarget targets
else if Version `elem` flagsExtra then
putWhenLn Info $ "Shake build system, version " ++ shakeVersionString
else if NumericVersion `elem` flagsExtra then
Expand Down Expand Up @@ -279,6 +287,7 @@ data Extra = ChangeDirectory FilePath
| NumericVersion
| PrintDirectory Bool
| Help
| ListTargets FilePattern
| Sleep
| NoTime
| Exception
Expand Down Expand Up @@ -336,6 +345,7 @@ shakeOptsEx =
,opts $ Option "" ["lint-fsatrace"] (optArg "DIR" $ \x s -> s{shakeLint=Just LintFSATrace, shakeLintInside=shakeLintInside s ++ [fromMaybe "." x]}) "Use fsatrace to do validation [in current dir]."
,opts $ Option "" ["lint-ignore"] (reqArg "PATTERN" $ \x s -> s{shakeLintIgnore=shakeLintIgnore s ++ [x]}) "Ignore any lint errors in these patterns."
,opts $ Option "" ["no-lint"] (noArg $ \s -> s{shakeLint=Nothing}) "Turn off --lint."
,extr $ Option "" ["list-targets"] (optArg "PATTERN" $ \x -> [ListTargets $ fromMaybe "//" x]) "List the available targets [matching PATTERN] and exit."
,opts $ Option "" ["live"] (optArg "FILE" $ \x s -> s{shakeLiveFiles=shakeLiveFiles s ++ [fromMaybe "live.txt" x]}) "List the files that are live [to live.txt]."
,opts $ Option "m" ["metadata"] (reqArg "PREFIX" $ \x s -> s{shakeFiles=x}) "Prefix for storing metadata files."
,extr $ Option "" ["numeric-version"] (noArg [NumericVersion]) "Print just the version number and exit."
Expand Down
2 changes: 1 addition & 1 deletion src/Development/Shake/Internal/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ instance (Semigroup a, Monoid a) => Monoid (Rules a) where
addUserRule :: Typeable a => a -> Rules ()
addUserRule r = newRules mempty{userRules = TMap.singleton $ UserRuleVersioned False $ UserRule r}

-- | Register a target, as available when passing @--help@ or through 'getTargets'.
-- | Register a target, as available when passing @--help@ or @--list-targets@, or through 'getTargets'.
-- Called automatically by rules such as 'Development.Shake.phony' and
-- 'Development.Shake.%>' - to avoid that use 'withoutTargets'.
-- To add documentation to a target use 'withTargetDocs'.
Expand Down
10 changes: 10 additions & 0 deletions src/Test/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Test.Targets(main) where
import Development.Shake
import Development.Shake.Internal.Core.Rules (getHelpSuffix)
import Test.Type
import System.Environment
import qualified System.IO.Extra as IO

main :: IO () -> IO ()
main _sleeper = do
Expand All @@ -11,6 +13,14 @@ main _sleeper = do
helpSuffix <- getHelpSuffix shakeOptions rules
helpSuffix === ["Don't Panic", "Know where your towel is"]

let listTargets args = lines . fst <$> IO.captureOutput (withArgs args $ shakeArgs shakeOptions rules)
xs <- listTargets ["--list-targets"]
xs === [a ++ maybe "" (" - " ++) b | (a,b) <- expected]
xs <- listTargets ["--list-targets=file1*", "--quiet"]
xs === ["file1", "file10", "file11 - a great file", "file12 - awesome files", "file13 - awesome files"]
xs <- listTargets ["--list-targets=phony*", "--list-targets=Foo"]
xs === ["phony1 - A phony target", "phony2 - Builds something really good", "Foo - bad docs"]

rules :: Rules ()
rules = do
withTargetDocs "A phony target" $ phony "phony1" $ pure ()
Expand Down