New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional warnings for 'cabal run' #2510
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,10 @@ module Distribution.Client.Run ( run, splitRunArgs ) | |
import Distribution.Client.Utils (tryCanonicalizePath) | ||
|
||
import Distribution.PackageDescription (Executable (..), | ||
PackageDescription (..)) | ||
TestSuite(..), | ||
Benchmark(..), | ||
PackageDescription (..), | ||
BuildInfo(buildable)) | ||
import Distribution.Simple.Compiler (compilerFlavor, CompilerFlavor(..)) | ||
import Distribution.Simple.Build.PathsModule (pkgPathEnvVar) | ||
import Distribution.Simple.BuildPaths (exeExtension) | ||
|
@@ -25,7 +28,7 @@ import Distribution.Simple.LocalBuildInfo (ComponentName (..), | |
import Distribution.Simple.Utils (die, notice, rawSystemExitWithEnv, | ||
addLibraryPath) | ||
import Distribution.System (Platform (..)) | ||
import Distribution.Verbosity (Verbosity) | ||
import Distribution.Verbosity (Verbosity, normal) | ||
|
||
import qualified Distribution.Simple.GHCJS as GHCJS | ||
|
||
|
@@ -42,23 +45,60 @@ import System.FilePath ((<.>), (</>)) | |
-- forwarded to it. | ||
splitRunArgs :: LocalBuildInfo -> [String] -> IO (Executable, [String]) | ||
splitRunArgs lbi args = | ||
case exes of | ||
[] -> die "Couldn't find any executables." | ||
[exe] -> case args of | ||
[] -> return (exe, []) | ||
(x:xs) | x == exeName exe -> return (exe, xs) | ||
| otherwise -> return (exe, args) | ||
_ -> case args of | ||
[] -> die $ "This package contains multiple executables. " | ||
++ "You must pass the executable name as the first argument " | ||
++ "to 'cabal run'." | ||
(x:xs) -> case find (\exe -> exeName exe == x) exes of | ||
Nothing -> die $ "No executable named '" ++ x ++ "'." | ||
Just exe -> return (exe, xs) | ||
case whichExecutable of -- Either err (wasManuallyChosen, exe, restParams) | ||
Left err -> do printMaybeWarningWithAdditional "" | ||
die err | ||
Right (True, exe, xs) -> return (exe, xs) | ||
Right (False, exe, xs) -> do printMaybeWarningWithAdditional | ||
$ " Interpreting all parameters to `run`" | ||
++ " as a parameter to the" | ||
++ " default executable." | ||
return (exe, xs) | ||
where | ||
pkg_descr = localPkgDescr lbi | ||
exes = executables pkg_descr | ||
|
||
whichExecutable :: Either String -- error string | ||
( Bool -- if it was manually chosen | ||
, Executable -- the executable | ||
, [String] -- the remaining parameters | ||
) | ||
whichExecutable = case (enabledExes, args) of | ||
([] , _) -> Left "Couldn't find any enabled executables." | ||
([exe], []) -> return (False, exe, []) | ||
([exe], (x:xs)) | ||
| x == exeName exe -> return (True, exe, xs) | ||
| otherwise -> return (False, exe, args) | ||
(_ , []) -> Left | ||
$ "This package contains multiple executables. " | ||
++ "You must pass the executable name as the first argument " | ||
++ "to 'cabal run'." | ||
(_ , (x:xs)) -> | ||
case find (\exe -> exeName exe == x) enabledExes of | ||
Nothing -> Left $ "No executable named '" ++ x ++ "'." | ||
Just exe -> return (True, exe, xs) | ||
where | ||
enabledExes = filter (buildable . buildInfo) (executables pkg_descr) | ||
printMaybeWarningWithAdditional :: String -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's simpler to just make this |
||
printMaybeWarningWithAdditional add = case firstParamComponentWarning of | ||
Nothing -> return () | ||
Just warning -> notice normal $ warning ++ add | ||
where | ||
firstParamComponentWarning = case args of | ||
[] -> Nothing | ||
(x:_) -> lookup x components | ||
components :: [(String, String)] -- component name, label | ||
components = [ (name, "The executable '" ++ name ++ "' is disabled.") | ||
| e <- executables pkg_descr | ||
, let name = exeName e] | ||
++ [ (name, "There is a test-suite '" ++ name ++ "'," | ||
++ " but the `run` command is only for" | ||
++ " executables.") | ||
| t <- testSuites pkg_descr | ||
, let name = testName t] | ||
++ [ (name, "There is a benchmark '" ++ name ++ "'," | ||
++ " but the run command is only for" | ||
++ " executables.") | ||
| b <- benchmarks pkg_descr | ||
, let name = benchmarkName b] | ||
|
||
-- | Run a given executable. | ||
run :: Verbosity -> LocalBuildInfo -> Executable -> [String] -> IO () | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use a trailing whitespace in
printMaybeWarningWithAdditional
instead of a prefix whitespace here (since this can be only message that gets printed).