Skip to content

Commit fe556df

Browse files
committed
Improve names of generated executables for scripts
1 parent a943141 commit fe556df

File tree

16 files changed

+59
-50
lines changed

16 files changed

+59
-50
lines changed

cabal-install/src/Distribution/Client/ScriptUtils.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import Distribution.Client.Types
4242
import Distribution.FieldGrammar
4343
( parseFieldGrammar, takeFields )
4444
import Distribution.Fields
45-
( ParseResult, parseFatalFailure, readFields )
45+
( ParseResult, Field(..), SectionArg(..), parseFatalFailure, readFields )
4646
import Distribution.PackageDescription.FieldGrammar
4747
( executableFieldGrammar )
4848
import Distribution.PackageDescription.PrettyPrint
@@ -86,7 +86,7 @@ import Data.ByteString.Lazy ()
8686
import System.Directory
8787
( canonicalizePath, doesFileExist, getTemporaryDirectory, removeDirectoryRecursive )
8888
import System.FilePath
89-
( (</>) )
89+
( (</>), takeFileName )
9090
import qualified Text.Parsec as P
9191

9292
-- A note on multi-module script support #6787:
@@ -255,9 +255,16 @@ updateContextAndWriteProjectFile ctx scriptPath scriptExecutable = do
255255

256256
absScript <- canonicalizePath scriptPath
257257
let
258+
-- Replace characters which aren't allowed in the executable component name with '_'
259+
-- Prefix with "cabal-script-" to make it clear to end users that the name may be mangled
260+
scriptExeName = "cabal-script-" ++ map censor (takeFileName scriptPath)
261+
censor c = case readFields (fromString $ "executable " ++ [c]) of
262+
Right [Section _ [SecArgName _ _] _] -> c
263+
_ -> '_'
264+
258265
sourcePackage = fakeProjectSourcePackage projectRoot
259266
& lSrcpkgDescription . L.condExecutables
260-
.~ [("script", CondNode executable (targetBuildDepends $ buildInfo executable) [])]
267+
.~ [(fromString scriptExeName, CondNode executable (targetBuildDepends $ buildInfo executable) [])]
261268
executable = scriptExecutable
262269
& L.modulePath .~ absScript
263270

cabal-testsuite/PackageTests/ListBin/Script/cabal.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)

cabal-testsuite/PackageTests/NewBuild/CmdBuild/Script/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..

cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRepl/cabal.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-repl
99
Build profile: -w ghc-<GHCVER> -O1
1010
In order, the following will be built:
11-
- fake-package-0 (exe:script) (ephemeral targets)
11+
- fake-package-0 (exe:cabal-script-script.hs) (ephemeral targets)

cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-run
99
Up to date

cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptRerun/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-build
99
Up to date

cabal-testsuite/PackageTests/NewBuild/CmdClean/Keep/cabal.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-build
99
Resolving dependencies...
1010
Build profile: -w ghc-<GHCVER> -O1
1111
In order, the following will be built:
12-
- fake-package-0 (exe:script) (configuration changed)
13-
Configuring executable 'script' for fake-package-0..
14-
Building executable 'script' for fake-package-0..
12+
- fake-package-0 (exe:cabal-script-script2.hs) (first run)
13+
Configuring executable 'cabal-script-script2.hs' for fake-package-0..
14+
Building executable 'cabal-script-script2.hs' for fake-package-0..
1515
# cabal v2-clean

cabal-testsuite/PackageTests/NewBuild/CmdClean/Orphan/cabal.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-build
99
Resolving dependencies...
1010
Build profile: -w ghc-<GHCVER> -O1
1111
In order, the following will be built:
12-
- fake-package-0 (exe:script) (configuration changed)
13-
Configuring executable 'script' for fake-package-0..
14-
Building executable 'script' for fake-package-0..
12+
- fake-package-0 (exe:cabal-script-script2.hs) (first run)
13+
Configuring executable 'cabal-script-script2.hs' for fake-package-0..
14+
Building executable 'cabal-script-script2.hs' for fake-package-0..
1515
# cabal v2-clean

cabal-testsuite/PackageTests/NewBuild/CmdClean/Script/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-clean

cabal-testsuite/PackageTests/NewBuild/CmdRepl/Script/cabal.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..

cabal-testsuite/PackageTests/NewBuild/CmdRepl/ScriptRerun/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
77
# cabal v2-repl
88
Build profile: -w ghc-<GHCVER> -O1
99
In order, the following will be built:
10-
- fake-package-0 (exe:script) (first run)
10+
- fake-package-0 (exe:cabal-script-script.hs) (first run)

cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..

cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.lhs) (first run)
6+
Configuring executable 'cabal-script-script.lhs' for fake-package-0..
7+
Building executable 'cabal-script-script.lhs' for fake-package-0..

cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script_with_spaces) (first run)
6+
Configuring executable 'cabal-script-script_with_spaces' for fake-package-0..
7+
Building executable 'cabal-script-script_with_spaces' for fake-package-0..

cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Resolving dependencies...
33
Build profile: -w ghc-<GHCVER> -O1
44
In order, the following will be built:
5-
- fake-package-0 (exe:script) (first run)
6-
Configuring executable 'script' for fake-package-0..
7-
Building executable 'script' for fake-package-0..
5+
- fake-package-0 (exe:cabal-script-script.hs) (first run)
6+
Configuring executable 'cabal-script-script.hs' for fake-package-0..
7+
Building executable 'cabal-script-script.hs' for fake-package-0..
88
# cabal v2-run
99
Up to date

changelog.d/pr-7851

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
synopsis: Better support for scripts
22
packages: cabal-install
3-
prs: #7851 #7925
3+
prs: #7851 #7925 #7938
44
issues: #7842 #7073 #6354 #6149
55

66
description: {
@@ -12,5 +12,7 @@ description: {
1212
- `cabal clean script` added. It will clean the cache for script.
1313
- `cabal clean` will now remove script caches for which there is no marching script.
1414
- `cabal list-bin` now works with scripts
15+
- The name of the generated script executable has been changed from "script" to
16+
"cabal-script-<your-sanitized-script-name>" for easier process management.
1517

1618
}

0 commit comments

Comments
 (0)