Skip to content

Commit ef840b4

Browse files
authored
Adds a fallback to build_all when csources fails (#1245)
* Adds a fallback to `build_all` when `csources` fails * reverse test * fixes nimenv regression
1 parent 3b119f6 commit ef840b4

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/nimblepkg/nimenv.nim

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,35 @@ proc compileNim*(options: Options, nimDest: string, v: VersionRange) =
5151
else:
5252
"csources_v1"
5353
cd workspace:
54-
echo "Entering CSOURCES", csourcesVersion, " exists ", dirExists(csourcesVersion)
5554
if not dirExists(csourcesVersion):
5655
exec "git clone https://github.com/nim-lang/" & csourcesVersion
5756

57+
var csourcesSucceed = false
5858
cd workspace / csourcesVersion:
5959
when defined(windows):
60-
exec "build.bat"
60+
let cmd = "build.bat"
61+
csourcesSucceed = os.execShellCmd(cmd) == 0
6162
else:
6263
let makeExe = findExe("make")
6364
if makeExe.len == 0:
64-
exec "sh build.sh"
65+
let cmd = "sh build.sh"
66+
csourcesSucceed = os.execShellCmd(cmd) == 0
6567
else:
66-
exec "make"
67-
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt)
68+
let cmd = "make"
69+
csourcesSucceed = os.execShellCmd(cmd) == 0
70+
6871
cd nimDest:
72+
#Sometimes building from csources fails and we cant do much about it. So we fallback to the slow build_all method
73+
if not csourcesSucceed:
74+
display("Warning", "Building nim from csources failed. Using `build_all`", Warning, HighPriority)
75+
let cmd =
76+
when defined(windows): "build_all.bat"
77+
else: "sh build_all.sh"
78+
exec cmd
6979
let nimExe = "bin" / "nim".addFileExt(ExeExt)
70-
copyFileWithPermissions nimExe0, nimExe
80+
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt)
81+
if csourcesSucceed:
82+
copyFileWithPermissions nimExe0, nimExe
7183
exec nimExe & " c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch"
7284
let kochExe = when defined(windows): "koch.exe" else: "./koch"
7385
exec kochExe & " boot -d:release --skipUserCfg --skipParentCfg --hints:off"

tests/tniminstall.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ suite "Nim install":
2828
echo "Checking version ", nimVer
2929
let (_, exitCode) = execNimble("install", "-l")
3030
let pkgPath = getCurrentDir() / "nimbledeps" / "pkgs2"
31+
echo "Checking ", pkgPath
3132
check exitCode == QuitSuccess
3233
check walkDir(pkgPath).toSeq.anyIt(it[1].isNimPkgVer(nimVer))

0 commit comments

Comments
 (0)