From 14f08472630ccd8e391d7184651dcdd5a96366d4 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 12 Oct 2025 21:56:59 +0800 Subject: [PATCH] Add an option to allow running Agda setup in v2.8.0 --- app/Main.hs | 23 +++++++++++++++++------ src/Options.hs | 10 +++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index dd22719..55ef5e2 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} module Main where import Control.Monad (when) @@ -11,6 +12,10 @@ import System.FilePath (()) import System.IO import Text.Read (readMaybe) +#if MIN_VERSION_Agda(2,8,0) +import Agda.Setup (setup) +#endif + main :: IO () main = do -- set locale to UTF-8 @@ -19,6 +24,8 @@ main = do hSetEncoding stdin utf8 hSetEncoding stderr utf8 +-- getExecutablePath returns argv[0] in WASM, which is useless +#ifndef wasm32_HOST_ARCH -- The GitHub CI-built executable lacks the correct data directory path. -- If there's directory named "data" in the executable's directory, -- then we assume that the executable is built by GitHub CI @@ -28,14 +35,18 @@ main = do isBuiltByCI <- doesDirectoryExist dataDir when isBuiltByCI $ do setEnv "Agda_datadir" dataDir +#endif options <- getOptionsFromArgv - if optHelp options - then putStrLn usageMessage - else - if optVersion options - then putStrLn versionString - else do + case () of + _ | optHelp options -> putStrLn usageMessage + | optVersion options -> putStrLn versionString +#if MIN_VERSION_Agda(2,8,0) + | optSetup options -> do + setup True + return () +#endif + | otherwise -> do _ <- run options -- _ <- run return () diff --git a/src/Options.hs b/src/Options.hs index 585a0d7..ef8af48 100644 --- a/src/Options.hs +++ b/src/Options.hs @@ -39,13 +39,14 @@ usageMessage = usageInfo usage options ++ usageAboutAgdaOptions data Options = Options { optViaTCP :: Maybe Int, optRawAgdaOptions :: [String], + optSetup :: Bool, optHelp :: Bool, optVersion :: Bool } defaultOptions :: Options defaultOptions = - Options {optViaTCP = Nothing, optRawAgdaOptions = [], optHelp = False, optVersion = False} + Options {optViaTCP = Nothing, optRawAgdaOptions = [], optSetup = False, optHelp = False, optVersion = False} options :: [OptDescr (Options -> Options)] options = @@ -65,6 +66,13 @@ options = "PORT" ) "talk with the editor via TCP port (4096 as default)", +#if MIN_VERSION_Agda(2,8,0) + Option + [] + ["setup"] + (NoArg (\opts -> opts {optSetup = True})) + "run Agda setup and exit", +#endif Option ['V'] ["version"]