Use marshal pre 1.2.0

This commit is contained in:
Ganesh Viswanathan 2020-06-18 14:52:27 -05:00
commit 9b2aa7d4b1
2 changed files with 31 additions and 11 deletions

View file

@ -1,4 +1,9 @@
import json, os, strformat, strutils, tables
import os, strformat, strutils, tables
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
import marshal
else:
import json
type
ConanPackage* = ref object
@ -272,10 +277,13 @@ proc loadConanInfo*(outdir: string): ConanPackage =
file = outdir / conanInfo
if fileExists(file):
try:
result = to(readFile(file).parseJson(), ConanPackage)
except:
discard
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
result = to[ConanPackage](readFile(file))
else:
try:
result = to(readFile(file).parseJson(), ConanPackage)
except:
discard
proc saveConanInfo*(pkg: ConanPackage, outdir: string) =
## Save downloaded package info to `outdir/conaninfo.json`
@ -283,7 +291,10 @@ proc saveConanInfo*(pkg: ConanPackage, outdir: string) =
let
file = outdir / conanInfo
writeFile(file, $(%pkg))
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
writeFile(file, $$pkg)
else:
writeFile(file, $(%pkg))
proc parseConanManifest(pkg: ConanPackage, outdir: string) =
# Get all library info from downloaded conan package

View file

@ -1,5 +1,8 @@
import json, os, strutils
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
import marshal
type
JBBPackage* = ref object
## JBBPackage type that stores package information
@ -143,10 +146,13 @@ proc loadJBBInfo*(outdir: string): JBBPackage =
file = outdir / jbbInfo
if fileExists(file):
try:
result = to(readFile(file).parseJson(), JBBPackage)
except:
discard
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
result = to[JBBPackage](readFile(file))
else:
try:
result = to(readFile(file).parseJson(), JBBPackage)
except:
discard
proc saveJBBInfo*(pkg: JBBPackage, outdir: string) =
## Save downloaded package info to `outdir/jbbinfo.json`
@ -154,7 +160,10 @@ proc saveJBBInfo*(pkg: JBBPackage, outdir: string) =
let
file = outdir / jbbInfo
writeFile(file, $(%pkg))
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
writeFile(file, $$pkg)
else:
writeFile(file, $(%pkg))
proc dlJBBRequires*(pkg: JBBPackage, outdir: string)
proc downloadJBB*(pkg: JBBPackage, outdir: string, main = true) =