implemented --dynlibOverride option for static linking of 'dynlib'

This commit is contained in:
Araq
2013-04-08 16:38:49 +02:00
parent c4edcf3ea2
commit 5893a9195c
6 changed files with 34 additions and 3 deletions

View File

@@ -594,6 +594,7 @@ type
TLib* = object of lists.TListEntry # also misused for headers!
kind*: TLibKind
generated*: bool # needed for the backends:
isOverriden*: bool
name*: PRope
path*: PNode # can be a string literal!

View File

@@ -212,6 +212,11 @@ proc track(arg: string, info: TLineInfo) =
LocalError(info, errInvalidNumber, a[2])
msgs.addCheckpoint(newLineInfo(a[0], line, column))
proc dynlibOverride(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
if pass in {passCmd2, passPP}:
expectArg(switch, arg, pass, info)
options.inclDynlibOverride(arg)
proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
var
theOS: TSystemOS
@@ -480,6 +485,8 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
of "listfullpaths":
expectNoArg(switch, arg, pass, info)
gListFullPaths = true
of "dynliboverride":
dynlibOverride(switch, arg, pass, info)
else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
else: InvalidCmdLineOption(pass, switch, info)

View File

@@ -124,6 +124,7 @@ const
# additional configuration variables:
var
gConfigVars* = newStringTable(modeStyleInsensitive)
gDllOverrides = newStringtable(modeCaseInsensitive)
libpath* = ""
gProjectName* = "" # holds a name like 'nimrod'
gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
@@ -256,6 +257,20 @@ proc libCandidates*(s: string, dest: var seq[string]) =
else:
add(dest, s)
proc canonDynlibName(s: string): string =
let start = if s.startsWith("lib"): 3 else: 0
let ende = strutils.find(s, {'(', ')', '.'})
if ende >= 0:
result = s.substr(start, ende-1)
else:
result = s.substr(start)
proc inclDynlibOverride*(lib: string) =
gDllOverrides[lib.canonDynlibName] = "true"
proc isDynlibOverride*(lib: string): bool =
result = gDllOverrides.hasKey(lib.canonDynlibName)
proc binaryStrSearch*(x: openarray[string], y: string): int =
var a = 0
var b = len(x) - 1

View File

@@ -202,6 +202,8 @@ proc getLib(c: PContext, kind: TLibKind, path: PNode): PLib =
result = newLib(kind)
result.path = path
Append(c.libs, result)
if path.kind in {nkStrLit..nkTripleStrLit}:
result.isOverriden = options.isDynLibOverride(path.strVal)
proc expectDynlibNode(c: PContext, n: PNode): PNode =
if n.kind != nkExprColonExpr:
@@ -225,8 +227,9 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
else:
if n.kind == nkExprColonExpr:
var lib = getLib(c, libDynamic, expectDynlibNode(c, n))
addToLib(lib, sym)
incl(sym.loc.flags, lfDynamicLib)
if not lib.isOverriden:
addToLib(lib, sym)
incl(sym.loc.flags, lfDynamicLib)
else:
incl(sym.loc.flags, lfExportLib)
# since we'll be loading the dynlib symbols dynamically, we must use

View File

@@ -70,6 +70,11 @@ Advanced options:
--putenv:key=value set an environment variable
--babelPath:PATH add a path for Babel support
--excludePath:PATH exclude a path from the list of search paths
--dynlibOverride:SYMBOL marks SYMBOL so that dynlib:SYMBOL
has no effect and can be statically linked instead;
symbol matching is fuzzy so
that --dynlibOverride:lua matches
dynlib: "liblua.so.3"
--listCmd list the commands used to execute external programs
--parallelBuild=0|1|... perform a parallel build
value = number of processors (0 for auto-detect)

View File

@@ -1,7 +1,6 @@
version 0.9.2
=============
- a project wide override option for 'dynlib'
- FFI:
* test libffi on windows
* test: times.format with the FFI
@@ -29,6 +28,7 @@ Bugs
version 0.9.4
=============
- ``try`` as an expression
- provide tool/API to track leaks/object counts
- hybrid GC
- use big blocks in the allocator