From 7ad4b9203a57e6470b123cf9c5c3c82cec7eec11 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 6 Sep 2024 12:26:39 -0400 Subject: [PATCH 1/2] Warn that scripts cannot be package executables --- doc/getting-started.rst | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/getting-started.rst b/doc/getting-started.rst index 056c4a85ebd..f420c2b6f6f 100644 --- a/doc/getting-started.rst +++ b/doc/getting-started.rst @@ -198,8 +198,8 @@ the following file named ``myscript``: main :: IO () main = haskellSay "Hello, Haskell!" -The necessary sections of a ``.cabal`` file are placed -directly into the script as a comment. +The necessary sections of a package description that would otherwise be in a +``.cabal`` file are placed directly into the script as a comment. Use the familiar ``cabal run`` command to execute this script: @@ -222,6 +222,36 @@ can be run directly after setting the execute permission (+x): See more in the documentation for :ref:`cabal run`. +.. warning:: + + Single-file scripts cannot also be part of a package, as an executable or + listed as a module. + + .. code-block:: console + + $ cat script-exclusivity.cabal + cabal-version: 3.0 + name: script-exclusitivity + version: 1 + + executable my-script-exe + build-depends: + base, + haskell-say + main-is: myscript.hs + + $ ./myscript.hs + Error: [Cabal-7070] + The run command can only run an executable as a whole, not files or modules + within them, but the target 'myscript.hs' refers to the file myscript.hs in the + executable my-script-exe. + + $ cabal run myscript.hs + Error: [Cabal-7070] + The run command can only run an executable as a whole, not files or modules + within them, but the target 'myscript.hs' refers to the file myscript.hs in the + executable my-script-exe. + What Next? ---------- From 9a29a83d34c405f42534be9eea5b57d00521e57d Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 9 Sep 2024 09:25:15 -0400 Subject: [PATCH 2/2] Link to error index --- doc/getting-started.rst | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/doc/getting-started.rst b/doc/getting-started.rst index f420c2b6f6f..921a5ada6ce 100644 --- a/doc/getting-started.rst +++ b/doc/getting-started.rst @@ -225,32 +225,8 @@ See more in the documentation for :ref:`cabal run`. .. warning:: Single-file scripts cannot also be part of a package, as an executable or - listed as a module. - - .. code-block:: console - - $ cat script-exclusivity.cabal - cabal-version: 3.0 - name: script-exclusitivity - version: 1 - - executable my-script-exe - build-depends: - base, - haskell-say - main-is: myscript.hs - - $ ./myscript.hs - Error: [Cabal-7070] - The run command can only run an executable as a whole, not files or modules - within them, but the target 'myscript.hs' refers to the file myscript.hs in the - executable my-script-exe. - - $ cabal run myscript.hs - Error: [Cabal-7070] - The run command can only run an executable as a whole, not files or modules - within them, but the target 'myscript.hs' refers to the file myscript.hs in the - executable my-script-exe. + listed as a module. Trying to run a module that is included in a package + will error with `Cabal-7070`_. What Next? ---------- @@ -259,3 +235,5 @@ Now that you know how to set up a simple Haskell package using Cabal, check out some of the resources on the Haskell website's `documentation page `__ or read more about packages and Cabal on the :doc:`What Cabal does ` page. + +.. _Cabal-7070: https://errors.haskell.org/messages/Cabal-7070/