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

View file

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