2022-08-06 21:13:06 +03:00
module Commands.Doctor where
2023-09-05 18:11:17 +03:00
import Commands.Base hiding ( info )
2022-09-14 17:16:15 +03:00
import Commands.Doctor.Options
2023-06-01 13:18:31 +03:00
import Commands.Extra.Compile
2022-08-06 21:13:06 +03:00
import Data.Aeson
import Data.Aeson.TH
import Juvix.Extra.Version qualified as V
import Network.HTTP.Simple
import Safe ( headMay )
import System.Environment qualified as E
import System.Process qualified as P
import Text.Read ( readMaybe )
newtype GithubRelease = GithubRelease { _githubReleaseTagName :: Maybe Text }
deriving stock ( Eq , Show , Generic )
$ ( deriveFromJSON
defaultOptions
{ fieldLabelModifier = camelTo2 '_' . dropPrefix " _githubRelease "
}
''GithubRelease
)
data DocumentedWarning
= NoClang
| OldClang
| NoWasmLd
| NoWasm32Target
| NoWasm32WasiTarget
| NoSysroot
| NoWasmer
data DocumentedMessage = DocumentedMessage
{ _documentedMessageUrl :: Text ,
_documentedMessageMessage :: Text
}
makeLenses ''GithubRelease
makeLenses ''DoctorOptions
makeLenses ''DocumentedMessage
minimumClangVersion :: Integer
minimumClangVersion = 13
documentedMessage :: DocumentedWarning -> DocumentedMessage
documentedMessage w = uncurry DocumentedMessage ( first ( baseUrl <> ) warningInfo )
where
warningInfo :: ( Text , Text )
warningInfo = case w of
NoClang -> ( " could-not-find-the-clang-command " , " Could not find the clang command " )
OldClang -> ( " newer-clang-version-required " , " Clang version " <> show minimumClangVersion <> " or newer required " )
NoWasmLd -> ( " could-not-find-the-wasm-ld-command " , " Could not find the wasm-ld command " )
NoWasm32Target -> ( " clang-does-not-support-the-wasm32-target " , " Clang does not support the wasm32 target " )
NoWasm32WasiTarget -> ( " clang-does-not-support-the-wasm32-wasi-target " , " Clang does not support the wasm32-wasi target " )
NoSysroot -> ( " environment-variable-wasi_sysroot_path-is-not-set " , " Environment variable WASI_SYSROOT_PATH is missing " )
NoWasmer -> ( " could-not-find-the-wasmer-command " , " Could not find the wasmer command " )
baseUrl :: Text
2023-10-26 13:51:48 +03:00
baseUrl = " https://docs.juvix.org/ " <> V . versionDoc <> " /reference/tooling/doctor/# "
2022-08-06 21:13:06 +03:00
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
heading :: ( Member Log r ) => Text -> Sem r ()
2022-08-06 21:13:06 +03:00
heading = log . ( " > " <> )
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
warning :: ( Member Log r ) => Text -> Sem r ()
2022-08-06 21:13:06 +03:00
warning = log . ( " ! " <> )
2023-06-01 13:18:31 +03:00
info :: ( Member Log r ) => Text -> Sem r ()
info = log . ( " | " <> )
2023-09-05 18:11:17 +03:00
type DoctorEff = '[Log, Embed IO, App]
2022-08-06 21:13:06 +03:00
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
checkCmdOnPath :: ( Members DoctorEff r ) => String -> [ Text ] -> Sem r ()
2022-08-06 21:13:06 +03:00
checkCmdOnPath cmd errMsg =
2022-12-20 15:05:40 +03:00
whenM ( isNothing <$> findExecutable ( relFile cmd ) ) ( mapM_ warning errMsg )
2022-08-06 21:13:06 +03:00
2023-06-01 13:18:31 +03:00
-- | Check that wasm-ld exists in the same LLVM distribution as the clang command
checkWasmLd :: ( Members DoctorEff r ) => Path Abs File -> [ Text ] -> Sem r ()
checkWasmLd clangPath errMsg =
unlessM ( isExecutable ( parent clangPath <//> $ ( mkRelFile " wasm-ld " ) ) ) ( mapM_ warning errMsg )
checkClangTargetSupported :: ( Members DoctorEff r ) => Path Abs File -> String -> [ Text ] -> Sem r ()
checkClangTargetSupported clangPath target errMsg = do
2022-08-06 21:13:06 +03:00
( code , _ , _ ) <-
embed
( P . readProcessWithExitCode
2023-06-01 13:18:31 +03:00
( toFilePath clangPath )
2022-08-06 21:13:06 +03:00
[ " -target " , target , " --print-supported-cpus " ]
" "
)
unless ( code == ExitSuccess ) ( mapM_ warning errMsg )
2023-06-01 13:18:31 +03:00
checkClangVersion :: ( Members DoctorEff r ) => Path Abs File -> Integer -> [ Text ] -> Sem r ()
checkClangVersion clangPath expectedVersion errMsg = do
versionString <- embed ( P . readProcess ( toFilePath clangPath ) [ " -dumpversion " ] " " )
2022-08-06 21:13:06 +03:00
case headMay ( splitOn " . " versionString ) >>= readMaybe of
Just majorVersion -> unless ( majorVersion >= expectedVersion ) ( mapM_ warning errMsg )
Nothing -> warning " Could not determine clang version "
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
checkEnvVarSet :: ( Members DoctorEff r ) => String -> [ Text ] -> Sem r ()
2022-08-06 21:13:06 +03:00
checkEnvVarSet var errMsg = do
whenM ( isNothing <$> embed ( E . lookupEnv var ) ) ( mapM_ warning errMsg )
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
getLatestRelease :: ( Members '[Embed IO, Fail] r ) => Sem r GithubRelease
2022-08-06 21:13:06 +03:00
getLatestRelease = do
request' <- failFromException ( parseRequest " https://api.github.com/repos/anoma/juvix/releases/latest " )
let request = setRequestHeaders [ ( " user-agent " , " curl/7.79.1 " ) , ( " Accept " , " application/vnd.github+json " ) ] request'
response <- failFromException ( httpJSON request )
return ( getResponseBody response )
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
checkVersion :: ( Members DoctorEff r ) => Sem r ()
2022-08-06 21:13:06 +03:00
checkVersion = do
heading " Checking latest Juvix release on Github... "
let tagName = " v " <> V . versionDoc
response <- runFail getLatestRelease
case response of
Just release -> case release ^. githubReleaseTagName of
Just latestTagName -> unless ( tagName == latestTagName ) ( warning ( " Newer Juvix version is available from https://github.com/anoma/juvix/releases/tag/ " <> latestTagName ) )
Nothing -> warning " Tag name is not present in release JSON from Github API "
Nothing -> warning " Network error when fetching data from Github API "
2023-06-01 13:18:31 +03:00
renderDocumentedWarning :: DocumentedWarning -> [ Text ]
renderDocumentedWarning w = [ dmsg ^. documentedMessageMessage , dmsg ^. documentedMessageUrl ]
2022-08-06 21:13:06 +03:00
where
dmsg :: DocumentedMessage
dmsg = documentedMessage w
2023-06-01 13:18:31 +03:00
documentedCheck ::
( [ Text ] -> Sem r () ) -> DocumentedWarning -> Sem r ()
documentedCheck check w = check ( renderDocumentedWarning w )
2023-08-25 19:37:23 +03:00
findClangPath :: ( Members DoctorEff r ) => Sem r ( Maybe ClangPath )
2023-06-01 13:18:31 +03:00
findClangPath = findClang
2023-08-25 19:37:23 +03:00
checkClang :: forall r . ( Members DoctorEff r ) => Bool -> Sem r ()
2023-06-01 13:18:31 +03:00
checkClang printVerbose = do
2022-08-06 21:13:06 +03:00
heading " Checking for clang... "
2023-06-01 13:18:31 +03:00
clangPath <- findClangPath
case clangPath of
Just cp -> when printVerbose ( printVerbosePath cp )
Nothing -> mapM_ warning ( renderDocumentedWarning NoClang )
mapM_ checkClangProperties ( extractClangPath <$> clangPath )
2022-08-06 21:13:06 +03:00
heading " Checking that WASI_SYSROOT_PATH is set... "
documentedCheck ( checkEnvVarSet " WASI_SYSROOT_PATH " ) NoSysroot
2023-06-01 13:18:31 +03:00
where
checkClangProperties :: Path Abs File -> Sem r ()
checkClangProperties p = do
heading " Checking clang version... "
documentedCheck ( checkClangVersion p minimumClangVersion ) OldClang
heading " Checking for wasm-ld... "
documentedCheck ( checkWasmLd p ) NoWasmLd
heading " Checking that clang supports wasm32... "
documentedCheck ( checkClangTargetSupported p " wasm32 " ) NoWasm32Target
heading " Checking that clang supports wasm32-wasi... "
documentedCheck ( checkClangTargetSupported p " wasm32-wasi " ) NoWasm32WasiTarget
baseClangMsg :: Path Abs File -> Text
baseClangMsg p = " Found clang at " <> show p
printVerbosePath :: ClangPath -> Sem r ()
printVerbosePath = \ case
ClangEnvVarPath p -> info ( baseClangMsg p <> ( " using " <> pack llvmDistEnvironmentVar <> " environment variable " ) )
ClangSystemPath p -> info ( baseClangMsg p <> ( " using system PATH " ) )
2022-08-06 21:13:06 +03:00
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
checkWasmer :: ( Members DoctorEff r ) => Sem r ()
2022-08-06 21:13:06 +03:00
checkWasmer = do
heading " Checking for wasmer... "
documentedCheck ( checkCmdOnPath " wasmer " ) NoWasmer
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
runCommand :: ( Members DoctorEff r ) => DoctorOptions -> Sem r ()
2022-09-14 17:16:15 +03:00
runCommand opts = do
2023-06-01 13:18:31 +03:00
checkClang ( opts ^. doctorVerbose )
2022-08-06 21:13:06 +03:00
checkWasmer
2023-09-05 18:11:17 +03:00
offlineMode <- ( ^. globalOffline ) <$> askGlobalOptions
unless offlineMode checkVersion