Add jbbFlags to customize xxxJBB

This commit is contained in:
Ganesh Viswanathan 2020-07-11 17:29:21 -05:00
commit 37cdc5b94e
3 changed files with 66 additions and 28 deletions

View file

@ -15,7 +15,7 @@ Refer to the documentation for `getHeader()` for details on how to use this new
See the full list of changes here:
https://github.com/nimterop/nimterop/compare/v0.5.9...v0.6.1
https://github.com/nimterop/nimterop/compare/v0.5.9...v0.6.3
### Breaking changes
@ -39,6 +39,8 @@ https://github.com/nimterop/nimterop/compare/v0.5.9...v0.6.1
- Nimterop now supports anonymous nested structs/unions but it only works correctly for unions when `noHeader` is turned off (the default). This is because Nim does not support nested structs/unions and is unaware of the underlying memory structure. [#237][i237] (since v0.6.1)
- `xxxJBB` now allows for customizing the base location to search packages with the `jbbFlags` param to `getHeader()`. Specifying `giturl=xxx` where `xxx` could be a full Git URL or just the username for Github.com allows changing the default Git repo. In addition, `url=xxx` is also supported to download project info and binaries compiled with BinaryBuilder.org but hosted at another non-Git location. (since v0.6.3)
### Other improvements
- Generated wrappers no longer depend on nimterop being present - no more `import nimterop/types`. Supporting code is directly included in the wrapper output and only when required. E.g. enum macro is only included if wrapper contains enums. [#125][i125] (since v0.6.1)

View file

@ -141,18 +141,14 @@ proc getConanLDeps(outdir: string): seq[string] =
result = pkg.getConanLDeps(outdir)
proc getJBBPath(header, uri, outdir, version: string): string =
proc getJBBPath(header, uri, flags, outdir, version: string): string =
let
spl = uri.split('/', 1)
name = spl[0]
hasVersion = version.len != 0
var
ver =
if spl.len == 2:
spl[1]
else:
""
ver = if spl.len == 2: spl[1] else: ""
if ver.len != 0:
if "$#" in ver or "$1" in ver:
@ -166,6 +162,20 @@ proc getJBBPath(header, uri, outdir, version: string): string =
let
pkg = newJBBPackage(name, ver)
# Handle `jbbFlags`
if flags.nBl:
if flags.startsWith("giturl="):
let
val = flags["giturl=".len .. ^1]
if val.contains("://"):
pkg.baseUrl = val
else:
pkg.baseUrl = "https://github.com/" & val
elif flags.startsWith("url="):
pkg.baseUrl = flags["url=".len .. ^1]
pkg.isGit = false
downloadJBB(pkg, outdir)
result = findFile(header, outdir)
@ -217,7 +227,8 @@ macro getHeader*(
conanuri: static[string] = "", jbburi: static[string] = "",
outdir: static[string] = "", libdir: static[string] = "",
conFlags: static[string] = "", cmakeFlags: static[string] = "", makeFlags: static[string] = "",
altNames: static[string] = "", buildTypes: static[openArray[BuildType]] = [btCmake, btAutoconf]): untyped =
jbbFlags: static[string] = "", altNames: static[string] = "",
buildTypes: static[openArray[BuildType]] = [btCmake, btAutoconf]): untyped =
## Get the path to a header file for wrapping with
## `cImport() <cimport.html#cImport.m%2C%2Cstring%2Cstring%2Cstring>`_ or
## `c2nImport() <cimport.html#c2nImport.m%2C%2Cstring%2Cstring%2Cstring>`_.
@ -289,6 +300,13 @@ macro getHeader*(
## `cmake` and `make` in case additional configuration is required as part of the build
## process.
##
## `jbbFlags` allows changing the BinaryBuilder.org defaults:
## - `giturl=customUrl` changes the default `https://github.com/JuliaBinaryWrappers` to
## another Git URL. If no hostname is specified, `https://github.com` is assumed.
## - `url=customUrl` uses regular HTTP instead of Git and looks for `Artifacts.toml` and
## `Project.toml` files at that location. `$1` or `$#` are replaced with the version
## if specified.
##
## `altNames` is a list of alternate names for the library - e.g. zlib uses `zlib.h` for
## the header but the typical lib name is `libz.so` and not `libzlib.so`. However, it is
## libzlib.dll on Windows if built with cmake. In this case, `altNames = "z,zlib"`. Comma
@ -384,7 +402,7 @@ macro getHeader*(
`nameStatic`* = when defined(`nameStatic`): true else: `staticVal` == 1
# Search for header in outdir (after retrieving code) depending on -d:xxx mode
proc getPath(header, giturl, dlurl, conanuri, jbburi, outdir, version: string, shared: bool): string =
proc getPath(header, giturl, dlurl, conanuri, jbburi, jbbFlags, outdir, version: string, shared: bool): string =
when `nameGit`:
getGitPath(header, giturl, outdir, version)
elif `nameDL`:
@ -392,7 +410,7 @@ macro getHeader*(
elif `nameConan`:
getConanPath(header, conanuri, outdir, version, shared)
elif `nameJBB`:
getJBBPath(header, jbburi, outdir, version)
getJBBPath(header, jbburi, jbbFlags, outdir, version)
else:
getLocalPath(header, outdir)
@ -423,7 +441,8 @@ macro getHeader*(
when useStd:
stdPath
else:
getPath(`header`, `giturl`, `dlurl`, `conanuri`, `jbburi`, `outdir`, `version`, not `nameStatic`)
getPath(`header`, `giturl`, `dlurl`, `conanuri`, `jbburi`, `jbbFlags`,
`outdir`, `version`, not `nameStatic`)
# Run preBuild hook before building library if not Std, Conan or JBB
when not (useStd or `nameConan` or `nameJBB`) and declared(`preBuild`):
@ -458,7 +477,8 @@ macro getHeader*(
if prePath.len != 0:
prePath
else:
getPath(`header`, `giturl`, `dlurl`, `conanuri`, `jbburi`, `outdir`, `version`, not `nameStatic`)
getPath(`header`, `giturl`, `dlurl`, `conanuri`, `jbburi`, `jbbFlags`,
`outdir`, `version`, not `nameStatic`)
static:
doAssert `path`.len != 0, "\nHeader " & `header` & " not found - " &

View file

@ -12,7 +12,10 @@ type
name*: string
version*: string
url*: string
baseUrl*: string # Location to find package
isGit*: bool # Git or HTTP
url*: string # Download URL
sharedLibs*: seq[string]
staticLibs*: seq[string]
@ -20,7 +23,7 @@ type
const
# JBB URLs
jbbBaseUrl = "https://github.com/JuliaBinaryWrappers/$1_jll.jl"
jbbBaseUrl = "https://github.com/JuliaBinaryWrappers"
jbbInfo = "jbbinfo.json"
jbbProject = "Project.toml"
@ -45,6 +48,8 @@ proc newJBBPackage*(name, version: string): JBBPackage =
result = new(JBBPackage)
result.name = name
result.version = version
result.baseUrl = jbbBaseUrl
result.isGit = true
proc parseJBBProject(pkg: JBBPackage, outdir: string) =
# Get all dependencies from Project.toml
@ -127,21 +132,32 @@ proc getJBBRepo*(pkg: JBBPackage, outdir: string) =
let
path = outdir / "repos" / pkg.name
gitPull(
jbbBaseUrl % pkg.name,
outdir = path,
plist = "*.toml",
"master",
quiet = true
)
if pkg.isGit:
# Get package info using Git
gitPull(
pkg.baseUrl & ("/$1_jll.jl" % pkg.name),
outdir = path,
plist = "*.toml",
"master",
quiet = true
)
if pkg.version.len != 0:
# Checkout correct tag
let
tags = gitTags(path)
for i in tags.len - 1 .. 0:
if pkg.version in tags[i] and i != tags.len - 1:
gitCheckout(path, tags[i-1])
if pkg.version.len != 0:
# Checkout correct tag
let
tags = gitTags(path)
for i in tags.len - 1 .. 0:
if pkg.version in tags[i] and i != tags.len - 1:
gitCheckout(path, tags[i-1])
else:
# Download package info from HTTP
var
url = pkg.baseUrl
if "$#" in url or "$1" in url:
doAssert pkg.version.len != 0, "Need version for custom BinaryBuilder.org url: " & url
url = url % pkg.version
downloadUrl(url & "Artifacts.toml", path, quiet = true)
downloadUrl(url & "Project.toml", path, quiet = true)
pkg.parseJBBProject(path)
pkg.parseJBBArtifacts(path)