Skip to content

Commit d98b3e4

Browse files
committed
clean up bash command to extract version from filename
1 parent 1c5d7b7 commit d98b3e4

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

nimjl/config.nim

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import std/os
2-
import std/strutils
1+
import std/[os, strutils, strformat]
32

43
when defined(windows):
54
{.error: "Compilation on windows is not supported.".}
@@ -32,23 +31,34 @@ when defined(nimjl_cross_compile):
3231
JuliaLibPattern = JuliaLibPath / libPrefix & "julia*" & libSuffix
3332
prefixLen = len(libPrefix)+len("julia")+1 # length of the string 'libjulia.'
3433
suffixLen = len(libSuffix)
35-
JlVersionCmd = fmt"cd {JuliaLibPath} && name=$(echo libjulia.*.*.*.dylib); vers=$\{name:{prefixLen}:-{suffixLen}\}; echo $vers"
36-
else:
37-
const JlVersionCmd = JuliaPath / "bin" / "julia" & " -E VERSION"
3834

39-
const (cmdOutput, exitCode) = gorgeEx(JlVersionCmd)
40-
static:
41-
echo "Nimjl> ", JuliaPath
42-
when exitCode != 0:
43-
{.error: "Nimjl> Fatal error ! Julia could not be found on your system.".}
35+
const JlVersionCmd = &"fullname=$(echo {JuliaLibPath}/libjulia.*.*.*.dylib); name=$(basename ${{fullname}}); vers=${{name:{prefixLen}:{suffixLen} }}; echo $vers"
36+
const (cmdOutput, exitCode) = gorgeEx(JlVersionCmd)
37+
when exitCode != 0:
38+
{.error: "Nimjl> Fatal error ! Julia could not be found on your system.".}
39+
# The bash line is just paramters expansion + string substitution to extract the version from the name
40+
# This assumes the files is always called : libjulia.so OR libjulia.dylib for osx
41+
const JuliaArrayVersion* = cmdOutput.split(".")
42+
const JuliaMajorVersion* = JuliaArrayVersion[0].parseInt()
43+
const JuliaMinorVersion* = JuliaArrayVersion[1].parseInt()
44+
const JuliaPatchVersion* = JuliaArrayVersion[2].parseInt()
4445

45-
const JuliaArrayVersion* = cmdOutput.split("\"")[1].split(".")
4646

47+
else:
48+
const JlVersionCmd = JuliaPath / "bin" / "julia" & " -E VERSION"
49+
const (cmdOutput, exitCode) = gorgeEx(JlVersionCmd)
50+
when exitCode != 0:
51+
{.error: "Nimjl> Fatal error ! Julia could not be found on your system.".}
52+
const JuliaArrayVersion* = cmdOutput.split("\"")[1].split(".")
4753
# For release : result has the form ["v", "1.6.0", ""] -> splitting [1] yields ["1", "6, "0"]
4854
# For dev: result has the form ["v", "1.7.0-DEV", "667"] -> splitting [1] yields ["1", "7, "0-DEV", "667"]
49-
const JuliaMajorVersion* = JuliaArrayVersion[0].parseInt()
50-
const JuliaMinorVersion* = JuliaArrayVersion[1].parseInt()
51-
const JuliaPatchVersion* = JuliaArrayVersion[2].parseInt()
55+
const JuliaMajorVersion* = JuliaArrayVersion[0].parseInt()
56+
const JuliaMinorVersion* = JuliaArrayVersion[1].parseInt()
57+
const JuliaPatchVersion* = JuliaArrayVersion[2].parseInt()
58+
59+
static:
60+
echo "Nimjl> ", JuliaPath, ", version:", JuliaMajorVersion, ".", JuliaMinorVersion, ".", JuliaPatchVersion
61+
5262

5363
# TODO: handle more platform
5464
{.passC: " -DJulia_ENABLE_THREADING=1".}

0 commit comments

Comments
 (0)