Skip to content

Commit df311b2

Browse files
authored
[ git ] Merge pull request #39 from agda-web/wasm-agda-setup
Add an option to run Agda setup if compiled with Agda newer than v2.8.0
2 parents 898e58f + 14f0847 commit df311b2

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

app/Main.hs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
module Main where
23

34
import Control.Monad (when)
@@ -11,6 +12,10 @@ import System.FilePath ((</>))
1112
import System.IO
1213
import Text.Read (readMaybe)
1314

15+
#if MIN_VERSION_Agda(2,8,0)
16+
import Agda.Setup (setup)
17+
#endif
18+
1419
main :: IO ()
1520
main = do
1621
-- set locale to UTF-8
@@ -19,6 +24,8 @@ main = do
1924
hSetEncoding stdin utf8
2025
hSetEncoding stderr utf8
2126

27+
-- getExecutablePath returns argv[0] in WASM, which is useless
28+
#ifndef wasm32_HOST_ARCH
2229
-- The GitHub CI-built executable lacks the correct data directory path.
2330
-- If there's directory named "data" in the executable's directory,
2431
-- then we assume that the executable is built by GitHub CI
@@ -28,14 +35,18 @@ main = do
2835
isBuiltByCI <- doesDirectoryExist dataDir
2936
when isBuiltByCI $ do
3037
setEnv "Agda_datadir" dataDir
38+
#endif
3139

3240
options <- getOptionsFromArgv
33-
if optHelp options
34-
then putStrLn usageMessage
35-
else
36-
if optVersion options
37-
then putStrLn versionString
38-
else do
41+
case () of
42+
_ | optHelp options -> putStrLn usageMessage
43+
| optVersion options -> putStrLn versionString
44+
#if MIN_VERSION_Agda(2,8,0)
45+
| optSetup options -> do
46+
setup True
47+
return ()
48+
#endif
49+
| otherwise -> do
3950
_ <- run options
4051
-- _ <- run
4152
return ()

src/Options.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ usageMessage = usageInfo usage options ++ usageAboutAgdaOptions
3939
data Options = Options
4040
{ optViaTCP :: Maybe Int,
4141
optRawAgdaOptions :: [String],
42+
optSetup :: Bool,
4243
optHelp :: Bool,
4344
optVersion :: Bool
4445
}
4546

4647
defaultOptions :: Options
4748
defaultOptions =
48-
Options {optViaTCP = Nothing, optRawAgdaOptions = [], optHelp = False, optVersion = False}
49+
Options {optViaTCP = Nothing, optRawAgdaOptions = [], optSetup = False, optHelp = False, optVersion = False}
4950

5051
options :: [OptDescr (Options -> Options)]
5152
options =
@@ -65,6 +66,13 @@ options =
6566
"PORT"
6667
)
6768
"talk with the editor via TCP port (4096 as default)",
69+
#if MIN_VERSION_Agda(2,8,0)
70+
Option
71+
[]
72+
["setup"]
73+
(NoArg (\opts -> opts {optSetup = True}))
74+
"run Agda setup and exit",
75+
#endif
6876
Option
6977
['V']
7078
["version"]

0 commit comments

Comments
 (0)