Skip to content

Commit

Permalink
Update documentation for better script support
Browse files Browse the repository at this point in the history
Ready for review: haskell#7851
May close: haskell#7842, haskell#6354, haskell#6149
  • Loading branch information
bacchanalia authored and mergify-bot committed Dec 31, 2021
1 parent 4e03925 commit 856134d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/ScriptUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import System.FilePath

-- | Get the directory where script builds are cached.
--
-- <cabalDir>/script-builds
-- CABAL_DIR\/script-builds\/
getScriptCacheDirectoryRoot :: IO FilePath
getScriptCacheDirectoryRoot = do
cabalDir <- getCabalDir
Expand All @@ -106,14 +106,14 @@ getScriptHash prefix script = showHashValue . hashValue . fromString . (prefix +
-- | Get the directory for caching a script build.
--
-- The only identity of a script is it's absolute path, so append the
-- hashed path to <cabalDir>/script-builds/ to get the cache directory.
-- hashed path to CABAL_DIR\/script-builds\/ to get the cache directory.
getScriptCacheDirectory :: String -> FilePath -> IO FilePath
getScriptCacheDirectory prefix script = (</>) <$> getScriptCacheDirectoryRoot <*> getScriptHash prefix script

-- | Get the directory for caching a script build and ensure it exists.
--
-- The only identity of a script is it's absolute path, so append the
-- hashed path to <cabalDir>/script-builds/ to get the cache directory.
-- hashed path to CABAL_DIR\/script-builds\/ to get the cache directory.
ensureScriptCacheDirectory :: Verbosity -> String -> FilePath -> IO FilePath
ensureScriptCacheDirectory verbosity prefix script = do
cacheDir <- getScriptCacheDirectory prefix script
Expand Down
25 changes: 25 additions & 0 deletions doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ A cabal command target can take any of the following forms:
- A filepath target: ``[package:][ctype:]filepath``, which specifies that the
component of which the given filepath is a part of will be built.

- A script target: ``path/to/script``, which specifies the path to a script
file. This is supported by ``build``, ``repl``, ``run``, and ``clean``.
Script targets are not part of a package.

cabal v2-build
---------------

Expand All @@ -262,6 +266,7 @@ Some example targets:
# "app/Main.hs"
$ cabal v2-build Lib # build the library component to
# which the module "Lib" belongs
$ cabal v2-build path/to/script # build the script as an executable

Beyond a list of targets, ``cabal v2-build`` accepts all the flags that
``cabal v2-configure`` takes. Most of these flags are only taken into
Expand All @@ -270,6 +275,9 @@ cause extra store packages to be built (for example,
``--enable-profiling`` will automatically make sure profiling libraries
for all transitive dependencies are built and installed.)

When building a script, the executable is cached under the cabal directory.
See ``cabal v2-run`` for more information on the format for scripts.

In addition ``cabal v2-build`` accepts these flags:

- ``--only-configure``: When given we will forego performing a full build and
Expand Down Expand Up @@ -323,6 +331,17 @@ cannot be excluded for technical reasons).

$ cabal v2-repl --build-depends vector --no-transitive-deps

Scripts can be passing the path to the script as the target.

::

$ cabal v2-repl script.hs

If the name of the script matches another target, the other target is preferred.
To load the script instead pass it as an explicit path: ./script.hs

See ``cabal v2-run`` for more information on the format for scripts.

cabal v2-run
-------------

Expand Down Expand Up @@ -543,6 +562,12 @@ and caches if the ``--save-config`` option is given, in which case it only remov
the build artefacts (``.hi``, ``.o`` along with any other temporary files generated
by the compiler, along with the build output).

``cabal v2-clean [FLAGS] path/to/script`` cleans up the temporary files and build
artifacts for the script, which are stored under the .cabal/script-builds directory.

In addition when clean is invoked it will remove all script build artifacts for
which the corresponding script no longer exists.

cabal v2-sdist
---------------

Expand Down

0 comments on commit 856134d

Please sign in to comment.