Skip to content

Commit 9de5e57

Browse files
committed
Fix #6696 Add stack config build-files
Also makes minor correction to in-app documentation for other `stack config` commands.
1 parent 5850a9b commit 9de5e57

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Behavior changes:
1212

1313
Other enhancements:
1414

15+
* Add the `stack config build-files` command to generate (when applicable) a
16+
Cabal file from a package description in the Hpack format and/or a lock file
17+
for Stack's project-level configuration, without taking any other build steps.
18+
1519
Bug fixes:
1620

1721
## v3.5.0.1 (release candidate) - 2025-03-15

doc/commands/config_command.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,32 @@
66
stack config COMMAND
77
88
Available commands:
9-
env Print environment variables for use in a shell
10-
set Sets a key in configuration file to value
9+
build-files Generate (when applicable) a Cabal file from a
10+
package description in the Hpack format and/or a lock
11+
file for Stack's project-level configuration.
12+
env Print environment variables for use in a shell.
13+
set Set a key in a configuration file to value.
1114
~~~
1215

1316
The `stack config` commands provide assistance with accessing or modifying
1417
Stack's configuration. See `stack config` for the available commands.
1518

19+
## The `stack config build-files` command
20+
21+
~~~text
22+
stack config build-files
23+
~~~
24+
25+
`stack config build-files` generates (when applicable):
26+
27+
* a Cabal file from a package description in the Hpack format (`package.yaml`);
28+
and/or
29+
30+
* a [lock file](../topics/lock_files.md) for Stack's project-level
31+
configuration (by default, `stack.yaml`);
32+
33+
without taking any other build steps.
34+
1635
## The `stack config env` command
1736

1837
~~~text

doc/topics/lock_files.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ few problems with making this work:
1010
* Entering all of the information to fully provide reproducibility is tedious.
1111
This would include things like Hackage revisions, hashes of remote tarballs,
1212
etc. Users don't want to enter this information.
13+
1314
* Many operations in Stack rely upon a "snapshot hash," which transitively
1415
includes the completed information for all of these dependencies. If any of
1516
that information is missing when parsing the `stack.yaml` file or snapshot
@@ -184,3 +185,11 @@ Subject to Stack's
184185
[`--lock-file`](../configure/global_flags.md#-lock-file-option) option, that new
185186
lock file is compared against the one on disk and, if there are any differences,
186187
written out to the disk.
188+
189+
## `stack config build-files` command
190+
191+
The
192+
[`stack config build-files`](../commands/config_command.md#the-stack-config-build-files-command)
193+
loads a project-level configuration file (see above) without taking any other
194+
build steps (other than generating, when applicable, a Cabal file from a package
195+
description in the Hpack format).

src/Stack/CLI.hs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import RIO.Process ( withProcessContextNoLogging )
2626
import Stack.Build ( buildCmd )
2727
import Stack.BuildInfo ( hpackVersion, versionString' )
2828
import Stack.Clean ( CleanCommand (..), cleanCmd )
29-
import Stack.ConfigCmd as ConfigCmd
29+
import Stack.ConfigCmd
30+
( cfgCmdBuildFiles, cfgCmdBuildFilesName, cfgCmdEnv
31+
, cfgCmdEnvName, configCmdEnvParser, cfgCmdName, cfgCmdSet
32+
, cfgCmdSetName, configCmdSetParser
33+
)
3034
import Stack.Constants
3135
( globalFooter, osIsWindows, relFileStack, relFileStackDotExe
3236
, stackProgName
@@ -72,7 +76,9 @@ import qualified Stack.Path ( path )
7276
import Stack.Prelude
7377
import Stack.Query ( queryCmd )
7478
import Stack.Runners
75-
( ShouldReexec (..), withConfig, withDefaultEnvConfig )
79+
( ShouldReexec (..), withBuildConfig, withConfig
80+
, withDefaultEnvConfig
81+
)
7682
import Stack.SDist ( sdistCmd )
7783
import Stack.Script ( ScriptOpts (..), scriptCmd )
7884
import Stack.SetupCmd ( setupCmd )
@@ -224,19 +230,28 @@ commandLineHandler currentDir progName mExecutablePath isInterpreter =
224230
(cleanOptsParser Clean)
225231

226232
config = addSubCommands'
227-
ConfigCmd.cfgCmdName
233+
cfgCmdName
228234
"Subcommands for accessing and modifying configuration values."
229235
( do
230236
addCommand'
231-
ConfigCmd.cfgCmdSetName
232-
"Sets a key in configuration file to value."
237+
cfgCmdSetName
238+
"Set a key in a configuration file to value."
233239
(withConfig NoReexec . cfgCmdSet)
234240
configCmdSetParser
235241
addCommandWithLocalInstallRootFooter
236-
ConfigCmd.cfgCmdEnvName
242+
cfgCmdEnvName
237243
"Print environment variables for use in a shell."
238244
(withConfig YesReexec . withDefaultEnvConfig . cfgCmdEnv)
239245
configCmdEnvParser
246+
addCommand'
247+
cfgCmdBuildFilesName
248+
"Generate (when applicable) a Cabal file from a package \
249+
\ description in the Hpack format and/or a lock file for Stack's \
250+
\project-level configuration."
251+
-- It is withBuildConfig that yields the desired actions;
252+
-- cfgCmdBuildFiles itself yields nothing of interest.
253+
(withConfig YesReexec . withBuildConfig . cfgCmdBuildFiles)
254+
(pure ())
240255
)
241256

242257
docker = addSubCommands'

src/Stack/ConfigCmd.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module Stack.ConfigCmd
1313
, configCmdEnvParser
1414
, cfgCmdEnv
1515
, cfgCmdEnvName
16+
, cfgCmdBuildFiles
17+
, cfgCmdBuildFilesName
1618
, cfgCmdName
1719
) where
1820

@@ -40,6 +42,7 @@ import Stack.Config
4042
)
4143
import Stack.Constants ( stackDotYaml )
4244
import Stack.Prelude
45+
import Stack.Types.BuildConfig ( BuildConfig )
4346
import Stack.Types.Config ( Config (..), HasConfig (..) )
4447
import Stack.Types.ConfigMonoid
4548
( configMonoidInstallGHCName
@@ -307,6 +310,9 @@ cfgCmdSetName = "set"
307310
cfgCmdEnvName :: String
308311
cfgCmdEnvName = "env"
309312

313+
cfgCmdBuildFilesName :: String
314+
cfgCmdBuildFilesName = "build-files"
315+
310316
configCmdSetParser :: OA.Parser ConfigCmdSet
311317
configCmdSetParser =
312318
OA.hsubparser $
@@ -461,3 +467,8 @@ cfgCmdEnv es = do
461467
escape '\'' = "'\"'\"'"
462468
escape c = T.singleton c
463469
putBuilder $ Map.foldMapWithKey toLine actions
470+
471+
-- | This function takes no settings and yields no action of interest. It is
472+
-- 'withBuildConfig' that yields the desired actions.
473+
cfgCmdBuildFiles :: () -> RIO BuildConfig ()
474+
cfgCmdBuildFiles () = pure ()

0 commit comments

Comments
 (0)