2022-05-18 18:10:10 +03:00
|
|
|
module App where
|
|
|
|
|
2022-09-14 17:16:15 +03:00
|
|
|
import CommonOptions
|
2022-08-12 10:48:06 +03:00
|
|
|
import Data.ByteString qualified as ByteString
|
2022-05-18 18:10:10 +03:00
|
|
|
import GlobalOptions
|
2022-11-07 16:47:56 +03:00
|
|
|
import Juvix.Compiler.Builtins.Effect
|
2022-08-03 14:20:40 +03:00
|
|
|
import Juvix.Compiler.Pipeline
|
|
|
|
import Juvix.Data.Error qualified as Error
|
2022-07-08 14:59:45 +03:00
|
|
|
import Juvix.Prelude.Pretty hiding (Doc)
|
2022-05-18 18:10:10 +03:00
|
|
|
import System.Console.ANSI qualified as Ansi
|
2023-03-29 16:51:04 +03:00
|
|
|
import System.Directory qualified as D
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
data App m a where
|
2022-09-06 16:26:48 +03:00
|
|
|
ExitMsg :: ExitCode -> Text -> App m a
|
2022-07-08 14:59:45 +03:00
|
|
|
ExitJuvixError :: JuvixError -> App m a
|
2022-08-30 12:24:15 +03:00
|
|
|
PrintJuvixError :: JuvixError -> App m ()
|
2022-12-20 15:05:40 +03:00
|
|
|
AskInvokeDir :: App m (Path Abs Dir)
|
|
|
|
AskPkgDir :: App m (Path Abs Dir)
|
2023-01-06 19:54:13 +03:00
|
|
|
AskBuildDir :: App m (Path Abs Dir)
|
2022-09-14 17:16:15 +03:00
|
|
|
AskPackage :: App m Package
|
|
|
|
AskGlobalOptions :: App m GlobalOptions
|
2022-05-18 18:10:10 +03:00
|
|
|
RenderStdOut :: (HasAnsiBackend a, HasTextBackend a) => a -> App m ()
|
2022-12-20 15:05:40 +03:00
|
|
|
RunPipelineEither :: AppPath File -> Sem PipelineEff a -> App m (Either JuvixError (Artifacts, a))
|
2022-06-09 17:36:07 +03:00
|
|
|
Say :: Text -> App m ()
|
2022-12-20 15:05:40 +03:00
|
|
|
SayRaw :: ByteString -> App m ()
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
makeSem ''App
|
|
|
|
|
2023-01-06 19:54:13 +03:00
|
|
|
data RunAppIOArgs = RunAppIOArgs
|
|
|
|
{ _runAppIOArgsGlobalOptions :: GlobalOptions,
|
|
|
|
_runAppIOArgsInvokeDir :: Path Abs Dir,
|
|
|
|
_runAppIOArgsBuildDir :: Path Abs Dir,
|
|
|
|
_runAppIOArgsPkgDir :: Path Abs Dir,
|
|
|
|
_runAppIOArgsPkg :: Package
|
|
|
|
}
|
|
|
|
|
|
|
|
runAppIO ::
|
|
|
|
forall r a.
|
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
|
|
|
(Member (Embed IO) r) =>
|
2023-01-06 19:54:13 +03:00
|
|
|
RunAppIOArgs ->
|
|
|
|
Sem (App ': r) a ->
|
|
|
|
Sem r a
|
|
|
|
runAppIO args@RunAppIOArgs {..} =
|
|
|
|
interpret $ \case
|
|
|
|
RenderStdOut t
|
|
|
|
| _runAppIOArgsGlobalOptions ^. globalOnlyErrors -> return ()
|
|
|
|
| otherwise -> embed $ do
|
|
|
|
sup <- Ansi.hSupportsANSIColor stdout
|
|
|
|
renderIO (not (_runAppIOArgsGlobalOptions ^. globalNoColors) && sup) t
|
|
|
|
AskGlobalOptions -> return _runAppIOArgsGlobalOptions
|
|
|
|
AskPackage -> return _runAppIOArgsPkg
|
|
|
|
AskInvokeDir -> return _runAppIOArgsInvokeDir
|
|
|
|
AskPkgDir -> return _runAppIOArgsPkgDir
|
|
|
|
AskBuildDir -> return _runAppIOArgsBuildDir
|
|
|
|
RunPipelineEither input p -> do
|
|
|
|
entry <- embed (getEntryPoint' args input)
|
|
|
|
embed (runIOEither iniState entry p)
|
|
|
|
Say t
|
|
|
|
| g ^. globalOnlyErrors -> return ()
|
|
|
|
| otherwise -> embed (putStrLn t)
|
|
|
|
PrintJuvixError e -> do
|
|
|
|
printErr e
|
|
|
|
ExitJuvixError e -> do
|
|
|
|
printErr e
|
|
|
|
embed exitFailure
|
2023-03-29 16:51:04 +03:00
|
|
|
ExitMsg exitCode t -> embed (putStrLn t >> hFlush stdout >> exitWith exitCode)
|
2023-01-06 19:54:13 +03:00
|
|
|
SayRaw b -> embed (ByteString.putStr b)
|
2022-08-30 12:24:15 +03:00
|
|
|
where
|
2023-01-06 19:54:13 +03:00
|
|
|
g :: GlobalOptions
|
|
|
|
g = _runAppIOArgsGlobalOptions
|
2022-08-30 12:24:15 +03:00
|
|
|
printErr e =
|
2023-01-06 19:54:13 +03:00
|
|
|
embed $ hPutStrLn stderr $ run $ runReader (project' @GenericOptions g) $ Error.render (not (_runAppIOArgsGlobalOptions ^. globalNoColors)) (g ^. globalOnlyErrors) e
|
2022-05-18 18:10:10 +03:00
|
|
|
|
2023-01-06 19:54:13 +03:00
|
|
|
getEntryPoint' :: RunAppIOArgs -> AppPath File -> IO EntryPoint
|
|
|
|
getEntryPoint' RunAppIOArgs {..} inputFile = do
|
|
|
|
let opts = _runAppIOArgsGlobalOptions
|
|
|
|
root = _runAppIOArgsPkgDir
|
2022-09-14 17:16:15 +03:00
|
|
|
estdin <-
|
|
|
|
if
|
|
|
|
| opts ^. globalStdin -> Just <$> getContents
|
|
|
|
| otherwise -> return Nothing
|
2023-03-28 12:41:05 +03:00
|
|
|
return $
|
|
|
|
(entryPointFromGlobalOptions root (someBaseToAbs _runAppIOArgsInvokeDir (inputFile ^. pathPath)) opts)
|
|
|
|
{ _entryPointBuildDir = _runAppIOArgsBuildDir,
|
2023-01-06 19:54:13 +03:00
|
|
|
_entryPointPackage = _runAppIOArgsPkg,
|
2023-03-28 12:41:05 +03:00
|
|
|
_entryPointStdin = estdin
|
2022-09-14 17:16:15 +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
|
|
|
someBaseToAbs' :: (Members '[App] r) => SomeBase a -> Sem r (Path Abs a)
|
2022-12-20 15:05:40 +03:00
|
|
|
someBaseToAbs' f = do
|
|
|
|
r <- askInvokeDir
|
|
|
|
return (someBaseToAbs r f)
|
|
|
|
|
2023-03-29 16:51:04 +03:00
|
|
|
filePathToAbs :: Members '[Embed IO, App] r => FilePath -> Sem r (Either (Path Abs File) (Path Abs Dir))
|
|
|
|
filePathToAbs fp = do
|
|
|
|
invokeDir <- askInvokeDir
|
|
|
|
absPath <- embed (D.canonicalizePath (toFilePath invokeDir </> fp))
|
|
|
|
isDirectory <- embed (D.doesDirectoryExist absPath)
|
|
|
|
if
|
|
|
|
| isDirectory -> Right <$> embed @IO (parseAbsDir absPath)
|
|
|
|
| otherwise -> Left <$> embed @IO (parseAbsFile absPath)
|
|
|
|
|
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
|
|
|
askGenericOptions :: (Members '[App] r) => Sem r GenericOptions
|
2022-09-14 17:16:15 +03:00
|
|
|
askGenericOptions = project <$> askGlobalOptions
|
|
|
|
|
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
|
|
|
getEntryPoint :: (Members '[Embed IO, App] r) => AppPath File -> Sem r EntryPoint
|
2022-09-14 17:16:15 +03:00
|
|
|
getEntryPoint inputFile = do
|
2023-01-06 19:54:13 +03:00
|
|
|
_runAppIOArgsGlobalOptions <- askGlobalOptions
|
|
|
|
_runAppIOArgsPkgDir <- askPkgDir
|
|
|
|
_runAppIOArgsPkg <- askPackage
|
|
|
|
_runAppIOArgsBuildDir <- askBuildDir
|
|
|
|
_runAppIOArgsInvokeDir <- askInvokeDir
|
|
|
|
embed (getEntryPoint' (RunAppIOArgs {..}) inputFile)
|
2022-09-14 17:16:15 +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
|
|
|
runPipeline :: (Member App r) => AppPath File -> Sem PipelineEff a -> Sem r a
|
2022-09-14 17:16:15 +03:00
|
|
|
runPipeline input p = do
|
|
|
|
r <- runPipelineEither input p
|
2022-05-18 18:10:10 +03:00
|
|
|
case r of
|
2022-07-08 14:59:45 +03:00
|
|
|
Left err -> exitJuvixError err
|
2022-11-07 16:47:56 +03:00
|
|
|
Right res -> return (snd res)
|
2022-05-18 18:10:10 +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
|
|
|
newline :: (Member App r) => Sem r ()
|
2022-05-18 18:10:10 +03:00
|
|
|
newline = say ""
|
2022-06-09 17:36:07 +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
|
|
|
printSuccessExit :: (Member App r) => Text -> Sem r a
|
2022-06-09 17:36:07 +03:00
|
|
|
printSuccessExit = exitMsg ExitSuccess
|
|
|
|
|
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
|
|
|
printFailureExit :: (Member App r) => Text -> Sem r a
|
2022-06-09 17:36:07 +03:00
|
|
|
printFailureExit = exitMsg (ExitFailure 1)
|
2022-09-06 16:26:48 +03:00
|
|
|
|
|
|
|
getRight :: (Members '[App] r, AppError e) => Either e a -> Sem r a
|
|
|
|
getRight = either appError return
|
|
|
|
|
|
|
|
instance AppError Text where
|
|
|
|
appError = printFailureExit
|
|
|
|
|
|
|
|
instance AppError JuvixError where
|
|
|
|
appError = exitJuvixError
|
|
|
|
|
|
|
|
class AppError e where
|
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
|
|
|
appError :: (Members '[App] r) => e -> Sem r a
|