diff --git a/cabal-install/src/Distribution/Client/ScriptUtils.hs b/cabal-install/src/Distribution/Client/ScriptUtils.hs index 6c253b1febe..7215ac3d330 100644 --- a/cabal-install/src/Distribution/Client/ScriptUtils.hs +++ b/cabal-install/src/Distribution/Client/ScriptUtils.hs @@ -83,10 +83,11 @@ import Control.Exception ( bracket ) import qualified Data.ByteString.Char8 as BS import Data.ByteString.Lazy () +import qualified Data.Set as S import System.Directory ( canonicalizePath, doesFileExist, getTemporaryDirectory, removeDirectoryRecursive ) import System.FilePath - ( () ) + ( (), takeFileName ) import qualified Text.Parsec as P -- A note on multi-module script support #6787: @@ -255,9 +256,15 @@ updateContextAndWriteProjectFile ctx scriptPath scriptExecutable = do absScript <- canonicalizePath scriptPath let + -- Replace characters which aren't allowed in the executable component name with '_' + -- Prefix with "cabal-script-" to make it clear to end users that the name may be mangled + scriptExeName = "cabal-script-" ++ map censor (takeFileName scriptPath) + censor c | c `S.member` ccNamecore = c + | otherwise = '_' + sourcePackage = fakeProjectSourcePackage projectRoot & lSrcpkgDescription . L.condExecutables - .~ [("script", CondNode executable (targetBuildDepends $ buildInfo executable) [])] + .~ [(fromString scriptExeName, CondNode executable (targetBuildDepends $ buildInfo executable) [])] executable = scriptExecutable & L.modulePath .~ absScript @@ -354,3 +361,13 @@ lSrcpkgDescription f s = fmap (\x -> s { srcpkgDescription = x }) (f (srcpkgDesc lLocalPackages :: Lens' ProjectBaseContext [PackageSpecifier UnresolvedSourcePackage] lLocalPackages f s = fmap (\x -> s { localPackages = x }) (f (localPackages s)) {-# inline lLocalPackages #-} + +-- Character classes +-- Transcribed from "templates/Lexer.x" +ccSpace, ccCtrlchar, ccPrintable, ccSymbol', ccParen, ccNamecore :: Set Char +ccSpace = S.fromList " " +ccCtrlchar = S.fromList $ [chr 0x0 .. chr 0x1f] ++ [chr 0x7f] +ccPrintable = S.fromList [chr 0x0 .. chr 0xff] S.\\ ccCtrlchar +ccSymbol' = S.fromList ",=<>+*&|!$%^@#?/\\~" +ccParen = S.fromList "()[]" +ccNamecore = ccPrintable S.\\ S.unions [ccSpace, S.fromList ":\"{}", ccParen, ccSymbol'] diff --git a/cabal-testsuite/PackageTests/ListBin/Script/cabal.out b/cabal-testsuite/PackageTests/ListBin/Script/cabal.out index da8977f93ba..2a3f0446696 100644 --- a/cabal-testsuite/PackageTests/ListBin/Script/cabal.out +++ b/cabal-testsuite/PackageTests/ListBin/Script/cabal.out @@ -2,4 +2,4 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) + - fake-package-0 (exe:cabal-script-script.hs) (first run) diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/Script/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/Script/cabal.out index e36af55eb80..0c647f80d90 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/Script/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/Script/cabal.out @@ -2,6 +2,6 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRepl/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRepl/cabal.out index 236acd3eb59..71653f09844 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRepl/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRepl/cabal.out @@ -2,10 +2,10 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-repl Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (ephemeral targets) + - fake-package-0 (exe:cabal-script-script.hs) (ephemeral targets) diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out index c834bfbbc12..5641c7a2ed8 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptBuildRun/cabal.out @@ -2,8 +2,8 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-run Up to date diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptRerun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptRerun/cabal.out index 8959c065706..ff6bbcc5c6e 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptRerun/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBuild/ScriptRerun/cabal.out @@ -2,8 +2,8 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-build Up to date diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Keep/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Keep/cabal.out index 3ef003f5fca..634c825fcf9 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Keep/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Keep/cabal.out @@ -2,14 +2,14 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-build Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (configuration changed) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script2.hs) (first run) +Configuring executable 'cabal-script-script2.hs' for fake-package-0.. +Building executable 'cabal-script-script2.hs' for fake-package-0.. # cabal v2-clean diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Orphan/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Orphan/cabal.out index 3ef003f5fca..634c825fcf9 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Orphan/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Orphan/cabal.out @@ -2,14 +2,14 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-build Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (configuration changed) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script2.hs) (first run) +Configuring executable 'cabal-script-script2.hs' for fake-package-0.. +Building executable 'cabal-script-script2.hs' for fake-package-0.. # cabal v2-clean diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Script/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Script/cabal.out index 8950f7c21f7..9075c0f276a 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdClean/Script/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/Script/cabal.out @@ -2,7 +2,7 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-clean diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRepl/Script/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRepl/Script/cabal.out index cfca4898f50..cba93d1cfd8 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRepl/Script/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRepl/Script/cabal.out @@ -2,5 +2,5 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRepl/ScriptRerun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRepl/ScriptRerun/cabal.out index 13b77ec4a65..135f9694e0e 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRepl/ScriptRerun/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRepl/ScriptRerun/cabal.out @@ -2,9 +2,9 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-repl Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) + - fake-package-0 (exe:cabal-script-script.hs) (first run) diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.out index ff4a38632f5..0cc95e6299f 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.out @@ -2,6 +2,6 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.out index ff4a38632f5..7520d95a5a0 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.out @@ -2,6 +2,6 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.lhs) (first run) +Configuring executable 'cabal-script-script.lhs' for fake-package-0.. +Building executable 'cabal-script-script.lhs' for fake-package-0.. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.out index ff4a38632f5..e0e127886ed 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.out @@ -2,6 +2,6 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-with_sp) (first run) +Configuring executable 'cabal-script-with_sp' for fake-package-0.. +Building executable 'cabal-script-with_sp' for fake-package-0.. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.test.hs b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.test.hs index d648c46f77b..b78a6941a79 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.test.hs +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/cabal.test.hs @@ -1,4 +1,4 @@ import Test.Cabal.Prelude main = cabalTest . void $ do - cabal' "v2-run" ["script with spaces"] >>= assertOutputContains "Hello World" + cabal' "v2-run" ["with sp"] >>= assertOutputContains "Hello World" diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/script with spaces b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/with sp similarity index 100% rename from cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/script with spaces rename to cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptNoExtention/with sp diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out index 1db558594b2..f7a7ca06306 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out +++ b/cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptRerun/cabal.out @@ -2,8 +2,8 @@ Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: - - fake-package-0 (exe:script) (first run) -Configuring executable 'script' for fake-package-0.. -Building executable 'script' for fake-package-0.. + - fake-package-0 (exe:cabal-script-script.hs) (first run) +Configuring executable 'cabal-script-script.hs' for fake-package-0.. +Building executable 'cabal-script-script.hs' for fake-package-0.. # cabal v2-run Up to date diff --git a/changelog.d/pr-7851 b/changelog.d/pr-7851 index 079bb4d4fc2..30b9656dfa4 100644 --- a/changelog.d/pr-7851 +++ b/changelog.d/pr-7851 @@ -1,6 +1,6 @@ synopsis: Better support for scripts packages: cabal-install -prs: #7851 #7925 +prs: #7851 #7925 #7938 issues: #7842 #7073 #6354 #6149 description: { @@ -12,5 +12,7 @@ description: { - `cabal clean script` added. It will clean the cache for script. - `cabal clean` will now remove script caches for which there is no marching script. - `cabal list-bin` now works with scripts +- The name of the generated script executable has been changed from "script" to + "cabal-script-" for easier process management. }