Skip to content

Commit

Permalink
Merge pull request #6106 from commercialhaskell/unfix2868
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem authored Apr 21, 2023
2 parents f1f3855 + b86c287 commit b9c46ed
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 104 deletions.
5 changes: 0 additions & 5 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ Behavior changes:

Other enhancements:

* Add options of the form `--PROG-option=<option>` to `stack build`, where
`PROG` is a program recognised by the Cabal library and one of `alex`, `ar`,
`c2hs`, `cpphs`, `gcc`, `greencard`, `happy`, `hsc2hs`, `hscolour`, `ld`,
`pkg-config`, `strip` and `tar`. If Cabal uses the program during
`configuration` or `build`, the option is passed to it.
* Add flag `--[no-]use-root` to `stack script` (default disabled). Used with
`--compile` or `--optimize`, when enabled all compilation outputs (including
the executable) are written to a script-specific location in the `scripts`
Expand Down
31 changes: 8 additions & 23 deletions doc/build_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

~~~text
stack build [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--PROG-option OPTION] [--flag PACKAGE:[-]FLAG]
[--dependencies-only | --only-snapshot | --only-dependencies |
--only-locals] [--file-watch | --file-watch-poll] [--watch-all]
[--exec COMMAND [ARGUMENT(S)]] [--only-configure] [--trace]
[--profile] [--no-strip] [--[no-]library-profiling]
[--[no-]executable-profiling] [--[no-]library-stripping]
[--[no-]executable-stripping] [--[no-]haddock]
[--haddock-arguments HADDOCK_ARGS] [--[no-]open]
[--[no-]haddock-deps] [--[no-]haddock-internal]
[--flag PACKAGE:[-]FLAG] [--dependencies-only | --only-snapshot |
--only-dependencies | --only-locals] [--file-watch |
--file-watch-poll] [--watch-all] [--exec COMMAND [ARGUMENT(S)]]
[--only-configure] [--trace] [--profile] [--no-strip]
[--[no-]library-profiling] [--[no-]executable-profiling]
[--[no-]library-stripping] [--[no-]executable-stripping]
[--[no-]haddock] [--haddock-arguments HADDOCK_ARGS]
[--[no-]open] [--[no-]haddock-deps] [--[no-]haddock-internal]
[--[no-]haddock-hyperlink-source] [--[no-]copy-bins]
[--[no-]copy-compiler-tool] [--[no-]prefetch] [--[no-]keep-going]
[--[no-]keep-tmp-files] [--[no-]force-dirty] [--[no-]test]
Expand Down Expand Up @@ -407,20 +406,6 @@ symbols.
Pass the flag to enable profiling in libraries, executables, etc. for all
expressions, and generate a backtrace on exception.

## Flags affecting other tools' behaviour

### `--PROG-option` options

`PROG` is a program recognised by Cabal (the library) and one of `alex`, `ar`,
`c2hs`, `cpphs`, `gcc`, `greencard`, `happy`, `hsc2hs`, `hscolour`, `ld`,
`pkg-config`, `strip` and `tar`.

`stack build --PROG-option <PROG_option>` passes the specified command line
option to `PROG`, if it used by Cabal during `configuration` or `build`. This
option can be specified multiple times. For example, if the program `happy` is
used by Cabal, you could command `stack build --happy-option --ghc` to pass its
`--ghc` option to the program.

## Flags relating to build outputs

### `--[no]-cabal-verbose` flag
Expand Down
25 changes: 2 additions & 23 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,6 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
-- Stack.Types.Build.configureOpts
cabal KeepTHLoading $ "configure" : concat
[ concat exes
, progsOptionArgs eeBuildOptsCLI
, dirs
, nodirs
]
Expand Down Expand Up @@ -1209,25 +1208,6 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
<> blankLine
fixupOnWindows

-- | Generate a list of --PROG-option="<option>" arguments for PROGs.
progsOptionArgs :: BuildOptsCLI -> [String]
progsOptionArgs boptsCLI =
concatMap progOptionArgs (boptsCLIProgsOptions boptsCLI)
where
-- Generate a list of --PROG-option="<option>" arguments for a PROG.
progOptionArgs :: (Text, [Text]) -> [String]
progOptionArgs (prog, opts) = map progOptionArg opts
where
-- Generate a --PROG-option="<option>" argument for a PROG and option.
progOptionArg :: Text -> String
progOptionArg opt = concat
[ "--"
, T.unpack prog
, "-option=\""
, T.unpack opt
, "\""
]

-- | Make a padded prefix for log messages
packageNamePrefix :: ExecuteEnv -> PackageName -> String
packageNamePrefix ee name' =
Expand Down Expand Up @@ -2006,11 +1986,10 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
)
config <- view configL
extraOpts <- extraBuildOptions wc eeBuildOpts
let progOpts = progsOptionArgs eeBuildOptsCLI
stripTHLoading
let stripTHLoading
| configHideTHLoading config = ExcludeTHLoading
| otherwise = KeepTHLoading
cabal stripTHLoading (("build" :) $ (++ progOpts) $ (++ extraOpts) $
cabal stripTHLoading (("build" :) $ (++ extraOpts) $
case (taskType, taskAllInOne, isFinalBuild) of
(_, True, True) -> throwM AllInOneBuildBug
(TTLocalMutable lp, False, False) ->
Expand Down
52 changes: 1 addition & 51 deletions src/Stack/Options/BuildParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ module Stack.Options.BuildParser
, targetsParser
) where

import qualified Data.List as L
import qualified Data.Map as Map
import qualified Data.Text as T
import Options.Applicative
( Parser, completer, flag, flag', help, internal, long
, metavar, option, strOption, switch, value
, metavar, option, switch
)
import Options.Applicative.Args ( cmdOption )
import Options.Applicative.Builder.Extra ( textArgument, textOption )
Expand Down Expand Up @@ -54,7 +52,6 @@ buildOptsParser cmd = BuildOptsCLI
\multiple times)."
))
)
<*> progsOptionsParser
<*> flagsParser
<*> ( flag' BSOnlyDependencies
( long "dependencies-only"
Expand Down Expand Up @@ -130,50 +127,3 @@ flagsParser = Map.unionsWith Map.union
<> help "Override flags set in stack.yaml (applies to local packages \
\and extra-deps)."
))

progsOptionsParser :: Parser [(Text, [Text])]
progsOptionsParser =
dummyProgOptionsParser
*> (filter (not . L.null . snd) <$> progsOptionsParser')
where
-- The purpose of this parser is only to generate the desired help text. The
-- actual --PROG-options parsers are all internal.
dummyProgOptionsParser :: Parser String
dummyProgOptionsParser = strOption
( long "PROG-option"
<> help
( "Pass an option to PROG (can be specified multiple times). PROG \
\must be a program recognised by the Cabal library and one of "
<> T.unpack (T.intercalate " " progs) <> "."
)
<> metavar "OPTION"
<> value ""
)
progs :: [Text]
progs = L.sort
[
-- configuration
"pkg-config"
-- preprocessors
, "alex"
, "c2hs"
, "cpphs"
-- , "doctest -- Not present in Cabal-1.22.5.0.
, "greencard"
, "happy"
, "hsc2hs"
, "hscolour"
-- platform toolchain (GNU)
, "ar" -- create, modify, and extract from archives
, "gcc" -- C/C++ compiler
, "ld" -- linker
, "strip" -- discards symbols and other data from object files
, "tar"
]
progsOptionsParser' :: Parser [(Text, [Text])]
progsOptionsParser' = traverse mkProgOptionsParser progs
mkProgOptionsParser :: Text -> Parser (Text, [Text])
mkProgOptionsParser prog = fmap (prog,) $ many $ textOption
( long (T.unpack prog <> "-option")
<> internal
)
2 changes: 0 additions & 2 deletions src/Stack/Types/BuildOpts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ defaultBuildOptsCLI = BuildOptsCLI
, boptsCLIDryrun = False
, boptsCLIFlags = Map.empty
, boptsCLIGhcOptions = []
, boptsCLIProgsOptions = []
, boptsCLIBuildSubset = BSAll
, boptsCLIFileWatch = NoFileWatch
, boptsCLIWatchAll = False
Expand Down Expand Up @@ -174,7 +173,6 @@ data BuildOptsCLI = BuildOptsCLI
{ boptsCLITargets :: ![Text]
, boptsCLIDryrun :: !Bool
, boptsCLIGhcOptions :: ![Text]
, boptsCLIProgsOptions :: ![(Text, [Text])]
, boptsCLIFlags :: !(Map ApplyCLIFlag (Map FlagName Bool))
, boptsCLIBuildSubset :: !BuildSubset
, boptsCLIFileWatch :: !FileWatchOpts
Expand Down

0 comments on commit b9c46ed

Please sign in to comment.