Skip to content

Commit 037865f

Browse files
authored
Use numeric version and commit to compute build dir (#3424)
- Closes #3416 # New command `juvix version` ``` juvix version --help Usage: juvix version [COMMAND] Print the Juvix version in different formats Available options: -h,--help Show this help text Available commands: human [Default] Print a human-readable version with detailed information numeric Print the version in the form x.y.z numeric-commit Print the version in the form x.y.z-commit ``` 1. `juvix version` is the same as `juvix --version`. 1. `juvix version human` is the same as `juvix --version`. 2. `juvix version numeric` is the same as `juvix --numeric-version`. 3. `juvix-version numeric-commit` is new. In my opinion, we should deprecate `juvix --numeric-version` in favour of `juvix version numeric`. I would still keep `juvix --version` because it follows a widespread convention. # New command `juvix dev build-dir` ``` juvix dev build-dir --help Usage: juvix dev build-dir [--relative] Print the absolute path of the build directory for the current project Available options: --relative Print the relative path wrt the project root -h,--help Show this help text ``` # Changes in internal directories ## Global ``` $HOME/.config/juvix/0.6.10 ``` becomes ``` $HOME/.config/juvix/0.6.10-ce9240d409ae32f313bc7a16f696669a8df3158a ``` ## Local ``` my-project/.juvix-build/0.6.10 ``` becomes ``` my-project/.juvix-build/0.6.10-ce9240d409ae32f313bc7a16f696669a8df3158a ``` # Other changes To avoid potential confusion. We now always use the full lenght commit rather than sometimes using the short form.
1 parent ce9240d commit 037865f

File tree

19 files changed

+184
-79
lines changed

19 files changed

+184
-79
lines changed

app/Commands/Clean/Options.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ parseCleanOptions = do
1717
switch
1818
( long "global"
1919
<> short 'g'
20-
<> help ("Remove also $XDG_CONFIG_HOME/juvix/" <> unpack versionDoc)
20+
<> help ("Remove also $XDG_CONFIG_HOME/juvix/" <> unpack fullVersionDoc)
2121
)
2222
_cleanOptionsOnlyGlobal <-
2323
switch
2424
( long "global-only"
25-
<> help ("Remove only $XDG_CONFIG_HOME/juvix/" <> unpack versionDoc)
25+
<> help ("Remove only $XDG_CONFIG_HOME/juvix/" <> unpack fullVersionDoc)
2626
)
2727
pure CleanOptions {..}

app/Commands/Dev.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Commands.Dev.Asm qualified as Asm
1010
import Commands.Dev.Casm qualified as Casm
1111
import Commands.Dev.Core qualified as Core
1212
import Commands.Dev.DevCompile qualified as DevCompile
13+
import Commands.Dev.DisplayBuildDir qualified as DisplayBuildDir
1314
import Commands.Dev.DisplayRoot qualified as DisplayRoot
1415
import Commands.Dev.Highlight qualified as Highlight
1516
import Commands.Dev.ImportTree qualified as ImportTree
@@ -43,6 +44,7 @@ runCommand = \case
4344
Casm opts -> Casm.runCommand opts
4445
Runtime opts -> Runtime.runCommand opts
4546
DisplayRoot opts -> DisplayRoot.runCommand opts
47+
DisplayBuildDir opts -> DisplayBuildDir.runCommand opts
4648
JuvixDevRepl opts -> Repl.runCommand opts
4749
MigrateJuvixYaml opts -> runFilesIO $ MigrateJuvixYaml.runCommand opts
4850
Nockma opts -> Nockma.runCommand opts
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Commands.Dev.DisplayBuildDir where
2+
3+
import Commands.Base
4+
import Commands.Dev.DisplayBuildDir.Options
5+
import Juvix.Extra.Paths.Base qualified as Paths
6+
7+
runCommand :: forall r. (Members AppEffects r) => BuildDirOptions -> Sem r ()
8+
runCommand opts = do
9+
fp :: String <-
10+
if
11+
| opts ^. buildDirRelative -> return (toFilePath Paths.relBuildDir)
12+
| otherwise -> do
13+
root <- askPkgDir
14+
return (toFilePath (Paths.rootBuildDir root))
15+
renderStdOutLn fp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Commands.Dev.DisplayBuildDir.Options where
2+
3+
import CommonOptions
4+
5+
data BuildDirOptions = BuildDirOptions
6+
{ _buildDirRelative :: Bool
7+
}
8+
deriving stock (Data)
9+
10+
makeLenses ''BuildDirOptions
11+
12+
parseBuildDir :: Parser BuildDirOptions
13+
parseBuildDir = do
14+
_buildDirRelative <-
15+
switch
16+
( long "relative"
17+
<> help "Print the relative path wrt the project root"
18+
)
19+
20+
pure BuildDirOptions {..}

app/Commands/Dev/Options.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Commands.Dev.Asm.Options hiding (Compile)
1717
import Commands.Dev.Casm.Options
1818
import Commands.Dev.Core.Options
1919
import Commands.Dev.DevCompile.Options (DevCompileCommand, parseDevCompileCommand)
20+
import Commands.Dev.DisplayBuildDir.Options
2021
import Commands.Dev.DisplayRoot.Options
2122
import Commands.Dev.Highlight.Options
2223
import Commands.Dev.ImportTree.Options
@@ -36,6 +37,7 @@ import CommonOptions
3637

3738
data DevCommand
3839
= DisplayRoot RootOptions
40+
| DisplayBuildDir BuildDirOptions
3941
| ImportTree ImportTreeCommand
4042
| Latex LatexCommand
4143
| Highlight HighlightOptions
@@ -73,6 +75,7 @@ parseDevCommand =
7375
commandParse,
7476
commandScope,
7577
commandShowRoot,
78+
commandDisplayBuildDir,
7679
commandTermination,
7780
commandJuvixDevRepl,
7881
commandMigrateJuvixYaml,
@@ -173,6 +176,13 @@ commandScope =
173176
(Scope <$> parseScope)
174177
(progDesc "Parse and scope a Juvix file")
175178

179+
commandDisplayBuildDir :: Mod CommandFields DevCommand
180+
commandDisplayBuildDir =
181+
command "build-dir" $
182+
info
183+
(DisplayBuildDir <$> parseBuildDir)
184+
(progDesc "Print the absolute path of the build directory for the current project")
185+
176186
commandShowRoot :: Mod CommandFields DevCommand
177187
commandShowRoot =
178188
command "root" $

app/Commands/Doctor.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ documentedMessage w = uncurry DocumentedMessage (first (baseUrl <>) warningInfo)
5656
NoWasmer -> ("could-not-find-the-wasmer-command", "Could not find the wasmer command")
5757

5858
baseUrl :: Text
59-
baseUrl = "https://docs.juvix.org/" <> V.versionDoc <> "/reference/tooling/doctor/#"
59+
baseUrl = "https://docs.juvix.org/" <> V.numericVersionDoc <> "/reference/tooling/doctor/#"
6060

6161
logDoctor :: (Member Logger r) => Text -> Sem r ()
6262
logDoctor = logInfo . mkAnsiText
@@ -113,7 +113,7 @@ getLatestRelease = do
113113
checkVersion :: (Members DoctorEff r) => Sem r ()
114114
checkVersion = do
115115
heading "Checking latest Juvix release on Github..."
116-
let tagName = "v" <> V.versionDoc
116+
let tagName = "v" <> V.numericVersionDoc
117117
response <- runFail getLatestRelease
118118
case response of
119119
Just release' -> case release' ^. githubReleaseTagName of

app/Commands/Repl.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ noFileLoadedErr :: Repl a
9898
noFileLoadedErr = replError (mkAnsiText @Text "No file loaded. Load a file using the `:load FILE` command.")
9999

100100
welcomeMsg :: (MonadIO m) => m ()
101-
welcomeMsg = liftIO (putStrLn [i|Juvix REPL version #{versionTag}: https://juvix.org. Run :help for help|])
101+
welcomeMsg = liftIO (putStrLn [i|Juvix REPL version #{fullVersionDoc}: https://juvix.org. Run :help for help|])
102102

103103
multilineCmd :: String
104104
multilineCmd = "multiline"
@@ -154,7 +154,7 @@ getReplEntryPointFromPath :: Path Abs File -> Repl EntryPoint
154154
getReplEntryPointFromPath = getReplEntryPoint (\r a -> runM . runTaggedLockPermissive . entryPointFromGlobalOptions r (Just a))
155155

156156
displayVersion :: String -> Repl ()
157-
displayVersion _ = liftIO (putStrLn versionTag)
157+
displayVersion _ = liftIO (putStrLn fullVersionDoc)
158158

159159
replCommand :: ReplOptions -> String -> Repl ()
160160
replCommand opts input_ = catchAll $ do

app/Commands/Version.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Commands.Version where
2+
3+
import Commands.Base
4+
import Commands.Version.Options
5+
import Juvix.Extra.Version
6+
7+
runCommand :: (Members AppEffects r) => VersionCommand -> Sem r ()
8+
runCommand = \case
9+
VersionHuman -> runDisplayVersion
10+
VersionNumeric -> runDisplayNumericVersion
11+
VersionCommit -> runDisplayFullVersion

app/Commands/Version/Options.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Commands.Version.Options where
2+
3+
import CommonOptions
4+
5+
data VersionCommand
6+
= VersionHuman
7+
| VersionNumeric
8+
| VersionCommit
9+
deriving stock (Data)
10+
11+
parseVersionCommand :: Parser VersionCommand
12+
parseVersionCommand =
13+
fromMaybe VersionHuman <$> optional parseVersionCommand'
14+
15+
parseVersionCommand' :: Parser VersionCommand
16+
parseVersionCommand' =
17+
hsubparser $
18+
mconcat
19+
( [ command
20+
"human"
21+
(info (pure VersionHuman) (progDesc "[Default] Print a human-readable version with detailed information")),
22+
command
23+
"numeric"
24+
(info (pure VersionNumeric) (progDesc "Print the version in the form x.y.z")),
25+
command
26+
"numeric-commit"
27+
(info (pure VersionCommit) (progDesc "Print the version in the form x.y.z-commit"))
28+
]
29+
)

app/TopCommand.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Commands.Isabelle qualified as Isabelle
1414
import Commands.Markdown qualified as Markdown
1515
import Commands.Repl qualified as Repl
1616
import Commands.Typecheck qualified as Typecheck
17+
import Commands.Version qualified as Version
1718
import Juvix.Extra.Version
1819
import System.Environment qualified as E
1920
import TopCommand.Options
@@ -34,6 +35,7 @@ runTopCommand ::
3435
runTopCommand = \case
3536
DisplayVersion -> runDisplayVersion
3637
DisplayNumericVersion -> runDisplayNumericVersion
38+
JuvixVersion opts -> Version.runCommand opts
3739
DisplayHelp -> showHelpText
3840
Doctor opts -> Doctor.runCommand opts
3941
Isabelle opts -> Isabelle.runCommand opts

0 commit comments

Comments
 (0)