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
|
2023-03-30 14:39:27 +03:00
|
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
|
2022-08-03 14:20:40 +03:00
|
|
|
import Juvix.Compiler.Pipeline
|
|
|
|
import Juvix.Data.Error qualified as Error
|
2023-04-27 18:33:08 +03:00
|
|
|
import Juvix.Prelude.Pretty hiding
|
|
|
|
( Doc,
|
|
|
|
)
|
2022-05-18 18:10:10 +03:00
|
|
|
import System.Console.ANSI qualified as Ansi
|
|
|
|
|
|
|
|
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 ()
|
2023-04-13 12:27:39 +03:00
|
|
|
AskRoots :: App m Roots
|
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
|
2023-04-13 12:27:39 +03:00
|
|
|
AskPackageGlobal :: App m Bool
|
2022-09-14 17:16:15 +03:00
|
|
|
AskGlobalOptions :: App m GlobalOptions
|
2023-04-19 17:56:48 +03:00
|
|
|
FromAppPathFile :: AppPath File -> App m (Path Abs File)
|
|
|
|
FromAppPathDir :: AppPath Dir -> App m (Path Abs Dir)
|
2022-05-18 18:10:10 +03:00
|
|
|
RenderStdOut :: (HasAnsiBackend a, HasTextBackend a) => a -> App m ()
|
2023-03-30 14:39:27 +03:00
|
|
|
RunPipelineEither :: AppPath File -> Sem PipelineEff a -> App m (Either JuvixError (ResolverState, a))
|
2023-04-27 18:33:08 +03:00
|
|
|
RunPipelineNoFileEither :: Sem PipelineEff a -> App m (Either JuvixError (ResolverState, a))
|
2023-03-30 14:39:27 +03:00
|
|
|
RunCorePipelineEither :: AppPath File -> App m (Either JuvixError Artifacts)
|
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,
|
2023-04-13 12:27:39 +03:00
|
|
|
_runAppIOArgsRoots :: Roots
|
2023-01-06 19:54:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-04-13 12:27:39 +03:00
|
|
|
AskPackageGlobal -> return (_runAppIOArgsRoots ^. rootsPackageGlobal)
|
2023-04-19 17:56:48 +03:00
|
|
|
FromAppPathFile p -> embed (prepathToAbsFile invDir (p ^. pathPath))
|
|
|
|
FromAppPathDir p -> embed (prepathToAbsDir invDir (p ^. pathPath))
|
2023-01-06 19:54:13 +03:00
|
|
|
RenderStdOut t
|
|
|
|
| _runAppIOArgsGlobalOptions ^. globalOnlyErrors -> return ()
|
|
|
|
| otherwise -> embed $ do
|
|
|
|
sup <- Ansi.hSupportsANSIColor stdout
|
|
|
|
renderIO (not (_runAppIOArgsGlobalOptions ^. globalNoColors) && sup) t
|
|
|
|
AskGlobalOptions -> return _runAppIOArgsGlobalOptions
|
2023-04-13 12:27:39 +03:00
|
|
|
AskPackage -> return (_runAppIOArgsRoots ^. rootsPackage)
|
|
|
|
AskRoots -> return _runAppIOArgsRoots
|
2023-04-19 17:56:48 +03:00
|
|
|
AskInvokeDir -> return invDir
|
2023-04-13 12:27:39 +03:00
|
|
|
AskPkgDir -> return (_runAppIOArgsRoots ^. rootsRootDir)
|
|
|
|
AskBuildDir -> return (_runAppIOArgsRoots ^. rootsBuildDir)
|
2023-03-30 14:39:27 +03:00
|
|
|
RunCorePipelineEither input -> do
|
|
|
|
entry <- embed (getEntryPoint' args input)
|
|
|
|
embed (corePipelineIOEither entry)
|
2023-01-06 19:54:13 +03:00
|
|
|
RunPipelineEither input p -> do
|
|
|
|
entry <- embed (getEntryPoint' args input)
|
2023-03-30 14:39:27 +03:00
|
|
|
embed (runIOEither entry p)
|
2023-04-27 18:33:08 +03:00
|
|
|
RunPipelineNoFileEither p -> do
|
|
|
|
entry <- embed (getEntryPointStdin' args)
|
|
|
|
embed (runIOEither entry p)
|
2023-01-06 19:54:13 +03:00
|
|
|
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-04-19 17:56:48 +03:00
|
|
|
invDir = _runAppIOArgsRoots ^. rootsInvokeDir
|
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
|
2023-04-19 17:56:48 +03:00
|
|
|
roots = _runAppIOArgsRoots
|
2022-09-14 17:16:15 +03:00
|
|
|
estdin <-
|
|
|
|
if
|
|
|
|
| opts ^. globalStdin -> Just <$> getContents
|
|
|
|
| otherwise -> return Nothing
|
2023-04-19 17:56:48 +03:00
|
|
|
set entryPointStdin estdin <$> entryPointFromGlobalOptionsPre roots (inputFile ^. pathPath) opts
|
2022-09-14 17:16:15 +03:00
|
|
|
|
2023-04-27 18:33:08 +03:00
|
|
|
getEntryPointStdin' :: RunAppIOArgs -> IO EntryPoint
|
|
|
|
getEntryPointStdin' RunAppIOArgs {..} = do
|
|
|
|
let opts = _runAppIOArgsGlobalOptions
|
|
|
|
roots = _runAppIOArgsRoots
|
|
|
|
estdin <-
|
|
|
|
if
|
|
|
|
| opts ^. globalStdin -> Just <$> getContents
|
|
|
|
| otherwise -> return Nothing
|
|
|
|
set entryPointStdin estdin <$> entryPointFromGlobalOptionsNoFile roots opts
|
|
|
|
|
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-04-19 17:56:48 +03:00
|
|
|
filePathToAbs :: Members '[Embed IO, App] r => Prepath FileOrDir -> Sem r (Either (Path Abs File) (Path Abs Dir))
|
2023-03-29 16:51:04 +03:00
|
|
|
filePathToAbs fp = do
|
|
|
|
invokeDir <- askInvokeDir
|
2023-04-19 17:56:48 +03:00
|
|
|
embed (fromPreFileOrDir invokeDir fp)
|
2023-03-29 16:51:04 +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
|
|
|
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
|
2023-04-13 12:27:39 +03:00
|
|
|
_runAppIOArgsRoots <- askRoots
|
2023-01-06 19:54:13 +03:00
|
|
|
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
|
|
|
|
2023-04-27 18:33:08 +03:00
|
|
|
runPipelineNoFile :: (Member App r) => Sem PipelineEff a -> Sem r a
|
|
|
|
runPipelineNoFile p = do
|
|
|
|
r <- runPipelineNoFileEither p
|
|
|
|
case r of
|
|
|
|
Left err -> exitJuvixError err
|
|
|
|
Right res -> return (snd res)
|
|
|
|
|
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
|