Skip to content

Commit

Permalink
Merge pull request #6109 from commercialhaskell/fix5584
Browse files Browse the repository at this point in the history
Fix #5584 Improve uninstallation of Stack-supplied tools
  • Loading branch information
mpilgrem authored Apr 23, 2023
2 parents 4ed76c3 + 91bb8b5 commit 9e34588
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 35 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Other enhancements:
`--work-dir` option is not a valid relative path.
* Stack will use the value of the `GH_TOKEN`, or `GITHUB_TOKEN`, environment
variable as credentials to authenticate its GitHub REST API requests.
* `stack uninstall` also shows how to uninstall Stack-supplied tools.

Bug fixes:

Expand Down
4 changes: 2 additions & 2 deletions doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
In connection with considering Stack's support of the
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
to take stock of the errors that Stack itself can raise, by reference to the
`master` branch of the Stack repository. Last updated: 2023-04-19.
`master` branch of the Stack repository. Last updated: 2023-04-22.

* `Main.main`: catches exceptions from action `commandLineHandler`.

Expand Down Expand Up @@ -272,7 +272,6 @@ to take stock of the errors that Stack itself can raise, by reference to the
[S-5308] | MSYS2NotFound Text
[S-5127] | UnwantedCompilerVersion
[S-1540] | UnwantedArchitecture
[S-9953] | SandboxedCompilerNotFound
[S-8668] | GHCInfoNotValidUTF8 UnicodeException
[S-4878] | GHCInfoNotListOfPairs
[S-2965] | GHCInfoMissingGlobalPackageDB
Expand Down Expand Up @@ -306,6 +305,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
[S-7441] = GHCInstallFailed SomeException StyleDoc String [String] (Path Abs Dir) (Path Abs Dir) (Path Abs Dir)
[S-2476] | InvalidGhcAt (Path Abs File) SomeException
[S-4764] | ExecutableNotFound [Path Abs File]
[S-9953] | SandboxedCompilerNotFound [String] [Path Abs Dir]
~~~

- `Stack.Storage.User.StorageUserException`
Expand Down
5 changes: 3 additions & 2 deletions doc/uninstall_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
stack uninstall
~~~

`stack uninstall` provides information about how to uninstall Stack. It does not
itself uninstall Stack.
`stack uninstall` provides information about how to uninstall Stack or a
Stack-supplied tool (such as GHC or, on Windows, MSYS2). It does not
itself uninstall Stack or a Stack-supplied tool.
45 changes: 31 additions & 14 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ data SetupException
| MSYS2NotFound Text
| UnwantedCompilerVersion
| UnwantedArchitecture
| SandboxedCompilerNotFound
| GHCInfoNotValidUTF8 UnicodeException
| GHCInfoNotListOfPairs
| GHCInfoMissingGlobalPackageDB
Expand Down Expand Up @@ -282,9 +281,6 @@ instance Exception SetupException where
displayException UnwantedArchitecture =
"Error: [S-1540]\n"
++ "Not the architecture we want."
displayException SandboxedCompilerNotFound =
"Error: [S-9953]\n"
++ "Could not find sandboxed compiler."
displayException (GHCInfoNotValidUTF8 e) = concat
[ "Error: [S-8668]\n"
, "GHC info is not valid UTF-8: "
Expand Down Expand Up @@ -403,15 +399,16 @@ instance Exception SetupException where
-- "Stack.Setup" module
data SetupPrettyException
= GHCInstallFailed
SomeException
String
String
[String]
(Path Abs Dir)
(Path Abs Dir)
(Path Abs Dir)
| InvalidGhcAt (Path Abs File) SomeException
| ExecutableNotFound [Path Abs File]
!SomeException
!String
!String
![String]
!(Path Abs Dir)
!(Path Abs Dir)
!(Path Abs Dir)
| InvalidGhcAt !(Path Abs File) !SomeException
| ExecutableNotFound ![Path Abs File]
| SandboxedCompilerNotFound ![String] ![Path Abs Dir]
deriving (Show, Typeable)

instance Pretty SetupPrettyException where
Expand Down Expand Up @@ -465,6 +462,26 @@ instance Pretty SetupPrettyException where
<> flow "Stack could not find any of the following executables:"
<> line
<> bulletedList (map pretty toTry)
pretty (SandboxedCompilerNotFound names fps) =
"[S-9953]"
<> line
<> fillSep
( ( flow "Stack could not find the sandboxed compiler. It looked for \
\one named one of:"
: mkNarrativeList Nothing False
( map fromString names :: [StyleDoc] )
)
<> ( flow "However, it could not find any on one of the paths:"
: mkNarrativeList Nothing False fps
)
)
<> blankLine
<> fillSep
[ flow "Perhaps a previously-installed compiler was not completely \
\uninstalled. For further information about uninstalling \
\tools, see the output of"
, style Shell (flow "stack uninstall") <> "."
]

instance Exception SetupPrettyException

Expand Down Expand Up @@ -1149,7 +1166,7 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
logError $
"Could not find it on the paths "
<> displayShow (edBins paths)
throwIO SandboxedCompilerNotFound
prettyThrowIO $ SandboxedCompilerNotFound names (edBins paths)
loop (x:xs) = do
res <- liftIO $
D.findExecutablesInDirectories (map toFilePath (edBins paths)) x
Expand Down
66 changes: 51 additions & 15 deletions src/Stack/Uninstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,57 @@ uninstallCmd () = withConfig NoReexec $ do
globalConfig' = toStyleDoc globalConfig
programsDir' = toStyleDoc programsDir
localBinDir' = toStyleDoc localBinDir
prettyInfo $ vsep
[ flow "To uninstall Stack, it should be sufficient to delete:"
, hang 4 $ fillSep [flow "(1) the directory containing Stack's tools",
"(" <> softbreak <> programsDir' <> softbreak <> ");"]
, hang 4 $ fillSep [flow "(2) the Stack root directory",
"(" <> softbreak <> stackRoot' <> softbreak <> ");"]
, hang 4 $ fillSep [flow "(3) if different, the directory containing ",
flow "Stack's global YAML configuration file",
"(" <> softbreak <> globalConfig' <> softbreak <> ");", "and"]
, hang 4 $ fillSep [flow "(4) the 'stack' executable file (see the output",
flow "of command", howToFindStack <> ",", flow "if Stack is on the PATH;",
flow "Stack is often installed in", localBinDir' <> softbreak <> ")."]
, fillSep [flow "You may also want to delete", style File ".stack-work",
flow "directories in any Haskell projects that you have built."]
]
prettyInfo $
vsep
[ flow "To uninstall Stack, it should be sufficient to delete:"
, hang 4 $ fillSep
[ flow "(1) the directory containing Stack's tools"
, "(" <> softbreak <> programsDir' <> softbreak <> ");"
]
, hang 4 $ fillSep
[ flow "(2) the Stack root directory"
, "(" <> softbreak <> stackRoot' <> softbreak <> ");"
]
, hang 4 $ fillSep
[ flow "(3) if different, the directory containing "
, flow "Stack's global YAML configuration file"
, parens globalConfig' <> ";"
, "and"
]
, hang 4 $ fillSep
[ flow "(4) the 'stack' executable file (see the output"
, flow "of command"
, howToFindStack <> ","
, flow "if Stack is on the PATH;"
, flow "Stack is often installed in"
, localBinDir' <> softbreak <> ")."
]
, fillSep
[flow "You may also want to delete"
, style File ".stack-work"
, flow "directories in any Haskell projects that you have built."
]
]
<> blankLine
<> vsep
[ fillSep
[ flow "To uninstall completely a Stack-supplied tool (such as \
\GHC or, on Windows, MSYS2), delete from Stack's tools \
\directory"
, parens programsDir' <> ":"
]
, hang 4 $ fillSep
[ flow "(1) the tool's subdirectory;"
]
, hang 4 $ fillSep
[ flow "(2) the tool's archive file"
, parens (style File "<tool>.tar.xz") <> "; and"
]
, hang 4 $ fillSep
[ flow "(3) the file marking that the tool is installed"
, parens (style File "<tool>.installed") <> "."
]
]
where
styleShell = style Shell
howToFindStack
Expand Down
4 changes: 2 additions & 2 deletions src/main/Stack/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ commandLineHandler currentDir progName isInterpreter =

uninstall = addCommand'
"uninstall"
"Show how to uninstall Stack. This command does not itself uninstall \
\Stack."
"Show how to uninstall Stack or a Stack-supplied tool. This command does \
\not itself uninstall Stack or a Stack-supplied tool."
uninstallCmd
(pure ())

Expand Down

0 comments on commit 9e34588

Please sign in to comment.