[Git][NTPsec/ntpsec][ntpc] 4 commits: ntp.ntpc: Split _importado() and revise libpaths.
James Browning
gitlab at mg.gitlab.com
Sun Sep 13 01:26:38 UTC 2020
James Browning pushed to branch ntpc at NTPsec / ntpsec
Commits:
0b7485d1 by James Browning at 2020-09-11T07:49:29-07:00
ntp.ntpc: Split _importado() and revise libpaths.
- - - - -
3567b1aa by James Browning at 2020-09-11T08:24:08-07:00
wscript: refactor builds badly
- - - - -
108f3347 by James Browning at 2020-09-12T18:17:51-07:00
wscript: expose --enable-pylib option
- - - - -
47dcbd01 by James Browning at 2020-09-12T18:21:25-07:00
wscript: add/(ab)use --clients-only option 1/x
- - - - -
7 changed files:
- libntp/wscript
- pylib/ntpc.py
- pylib/wscript
- tests/wscript
- wafhelpers/bin_test.py
- wafhelpers/options.py
- wscript
Changes:
=====================================
libntp/wscript
=====================================
@@ -40,14 +40,15 @@ def build(ctx):
if not ctx.env.HAVE_STRLCAT or not ctx.env.HAVE_STRLCPY:
libntp_source_sharable += ["strl_obsd.c"]
- # C library
- ctx(
- features="c cstlib",
- includes=[ctx.bldnode.parent.abspath(), "../include"],
- source=libntp_source + libntp_source_sharable,
- target="ntp",
- use="CRYPTO SSL",
- )
+ if not ctx.env['client-only']:
+ # C library
+ ctx(
+ features="c cstlib",
+ includes=[ctx.bldnode.parent.abspath(), "../include"],
+ source=libntp_source + libntp_source_sharable,
+ target="ntp",
+ use="CRYPTO SSL",
+ )
if ctx.env['ntpc'] == 'ffi':
# Loadable FFI stub
@@ -60,15 +61,13 @@ def build(ctx):
use="M RT CRYPTO",
vnum=ctx.env['ntpcver'],
)
- return
- elif ctx.env['ntpc'] != 'ext':
- return
- # Loadable Python extension
- ctx(
- features="c cshlib pyext",
- install_path='${PYTHONARCHDIR}/ntp',
- includes=[ctx.bldnode.parent.abspath(), "../include"],
- source=["pymodule.c", "pymodule-mac.c"] + libntp_source_sharable,
- target="../pylib/ntpc", # Put the output in the pylib directory
- use="M RT CRYPTO",
- )
+ elif ctx.env['ntpc'] == 'ext':
+ # Loadable Python extension
+ ctx(
+ features="c cshlib pyext",
+ install_path='${PYTHONARCHDIR}/ntp',
+ includes=[ctx.bldnode.parent.abspath(), "../include"],
+ source=["pymodule.c", "pymodule-mac.c"] + libntp_source_sharable,
+ target="../pylib/ntpc", # Put the output in the pylib directory
+ use="M RT CRYPTO",
+ )
=====================================
pylib/ntpc.py
=====================================
@@ -7,40 +7,49 @@ import ctypes.util
import errno
import os
import os.path
+import sys
import ntp.poly
LIB = 'ntpc'
-def importado():
- """Load the ntpc library or throw an OSError trying.
- Use find_library() which looks in: LD_LIBRARY_PATH,
- DYLD_LIBRARY_PATH, $home/lib, /.usr/local/lib,
- /usr/lib, /lib Returns the library handle.
- """
+def _fmt():
+ """Produce library naming scheme."""
+ if sys.platform.startswith('darwin'):
+ return 'lib%s.dylib'
+ if sys.platform.startswith('win32'):
+ return '%s.dll'
+ if sys.platform.startswith('cygwin'):
+ return 'lib%s.dll'
+ return 'lib%s.so'
+
+
+def _importado():
+ """Load the ntpc library or throw an OSError trying."""
ntpc_paths = [] # places to look
j = __file__.split(os.sep)[:-1]
- for i in ['lib%s.so', 'lib%s.dylib', '%s.dll']:
- _ = os.sep.join(j + [i % LIB])
- # print(_)
- ntpc_paths.append(_)
+ ntpc_paths.append(os.sep.join(j + [_fmt() % LIB]))
ntpc_path = ctypes.util.find_library(LIB)
if ntpc_path:
ntpc_paths.append(ntpc_path)
- for ntpc_path in ntpc_paths:
+ return _dlo(ntpc_paths)
+
+
+def _dlo(paths):
+ """Try opening library from a list."""
+ for ntpc_path in paths:
try:
lib = ctypes.CDLL(ntpc_path, use_errno=True)
return lib
except OSError:
pass
-
raise OSError("Can't find %s library" % LIB)
-_ntpc = importado()
+_ntpc = _importado()
progname = ctypes.c_char_p.in_dll(_ntpc, 'progname')
# log_sys = ctypes.c_bool.in_dll(_ntpc, 'syslogit')
# log_term = ctypes.c_bool.in_dll(_ntpc, 'termlogit')
@@ -107,10 +116,7 @@ def lfptofloat(in_string):
def msyslog(level, in_string):
- """Log send a message to terminal or output.
- Can actually log to syslog, a file or stdout/arderr.
- Minimum of of features supported.
- """
+ """Log send a message to terminal or output."""
mid_bytes = ntp.poly.polybytes(in_string)
_msyslog(level, mid_bytes)
=====================================
pylib/wscript
=====================================
@@ -35,15 +35,6 @@ def build(ctx):
bldnode = ctx.bldnode.make_node('pylib')
target1 = bldnode.make_node('control.py')
target2 = bldnode.make_node('magic.py')
-
- bldnode.mkdir()
-
- if ctx.cmd not in ('install'):
- ctx.add_group()
- target3 = bldnode.ant_glob('*ntpc*')
- for _ in target3:
- ctx.exec_command("rm -f %s" % _.abspath())
- ctx.add_group()
sources = []
if ctx.env['ntpc'] == 'ext':
=====================================
tests/wscript
=====================================
@@ -55,15 +55,16 @@ def build(ctx):
"libntp/ymd2yd.c"
] + common_source
- ctx.ntp_test(
- features="c cprogram test",
- target="test_libntp",
- install_path=None,
- defines=unity_config + ["TEST_LIBNTP=1"],
- includes=[ctx.bldnode.parent.abspath(), "../include", "unity", "common"],
- use="unity ntp parse M PTHREAD CRYPTO RT SOCKET NSL",
- source=libntp_source,
- )
+ if not ctx.env['client-only']:
+ ctx.ntp_test(
+ features="c cprogram test",
+ target="test_libntp",
+ install_path=None,
+ defines=unity_config + ["TEST_LIBNTP=1"],
+ includes=[ctx.bldnode.parent.abspath(), "../include", "unity", "common"],
+ use="unity ntp parse M PTHREAD CRYPTO RT SOCKET NSL",
+ source=libntp_source,
+ )
if ctx.env.REFCLOCK_GENERIC or ctx.env.REFCLOCK_TRIMBLE:
# libparse available/required with generic and Trimble refclocks
@@ -103,16 +104,17 @@ def build(ctx):
"ntpd/nts_extens.c",
]
- ctx.ntp_test(
- defines=unity_config + ["TEST_NTPD=1"],
- features="c cprogram test",
- includes=[ctx.bldnode.parent.abspath(), "../include", "unity", "../ntpd", "common", "../libaes_siv"],
- install_path=None,
- source=ntpd_source,
- target="test_ntpd",
- use="ntpd_lib libntpd_obj unity ntp aes_siv "
- "M PTHREAD CRYPTO RT SOCKET NSL",
- )
+ if not ctx.env['client-only']:
+ ctx.ntp_test(
+ defines=unity_config + ["TEST_NTPD=1"],
+ features="c cprogram test",
+ includes=[ctx.bldnode.parent.abspath(), "../include", "unity", "../ntpd", "common", "../libaes_siv"],
+ install_path=None,
+ source=ntpd_source,
+ target="test_ntpd",
+ use="ntpd_lib libntpd_obj unity ntp aes_siv "
+ "M PTHREAD CRYPTO RT SOCKET NSL",
+ )
testpylib.get_bld().mkdir()
=====================================
wafhelpers/bin_test.py
=====================================
@@ -14,9 +14,6 @@ verStr = ntp.util.stdversion()
cmd_map = {
("main/ntpclients/ntpleapfetch", "--version"): "ntpleapfetch %s\n"
% verStr,
- ("main/ntpd/ntpd", "--version"): "ntpd %s\n" % verStr,
- ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n" % verStr,
- ("main/ntptime/ntptime", "-V"): "ntptime %s\n" % verStr
}
cmd_map_python = {
("main/ntpclients/ntpdig", "--version"): "ntpdig %s\n" % verStr,
@@ -87,8 +84,16 @@ def run(cmd, reg, pythonic):
def cmd_bin_test(ctx, config):
"""Run a suite of binary tests."""
+ global cmd_map
fails = 0
+ if not ctx.env['client-only']:
+ cmd_map.update({
+ ("main/ntpd/ntpd", "--version"): "ntpd %s\n" % verStr,
+ ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n" % verStr,
+ ("main/ntptime/ntptime", "-V"): "ntptime %s\n" % verStr
+ })
+
if ctx.env['PYTHON_ARGPARSE']:
cmd_map_python.update(cmd_map_python_argparse)
=====================================
wafhelpers/options.py
=====================================
@@ -31,6 +31,14 @@ def options_cmd(ctx, config):
grp.add_option('--enable-debug-timing', action='store_true',
default=False,
help="Collect timing statistics for debugging.")
+ grp.add_option('--enable-pylib', action='store',
+ default='ffi', choices=['ext', 'ffi', 'none'],
+ help="""Choose which Python library to build.\n
+ext, ffi, or none. defaults to ffi.""", nargs=1)
+ grp.add_option('--clients-only', action='store',
+ default='no', choices=['no', 'yes'], nargs=1,
+ help="""Whether to only build/install clients/pylib.\n
+no or yes. default to no.""")
grp = ctx.add_option_group("NTP cross compile options")
grp.add_option('--cross-compiler', type='string',
=====================================
wscript
=====================================
@@ -119,7 +119,8 @@ def configure(ctx):
opt = flag.replace("--", "").upper()
opt_map[opt] = ctx.env.OPT_STORE[flag]
- ctx.env['ntpc'] = 'ffi'
+ ctx.env['ntpc'] = ctx.options.enable_pylib
+ ctx.env['client-only'] = ctx.options.clients_only == 'yes'
ctx.env['ntpcver'] = '1.1.0'
msg("--- Configuring host ---")
@@ -1002,27 +1003,40 @@ def build(ctx):
ctx.load('asciidoc', tooldir='wafhelpers/')
ctx.load('rtems_trace', tooldir='wafhelpers/')
+ if ctx.variant == "host":
+ # if ctx.variant == "host" and not ctx.env['client-only']:
+ ctx.recurse("ntpd")
+ return
+
if ctx.cmd == "build":
# It's a waf gotcha that if there are object files (including
# .pyc and .pyo files) in a source directory, compilation to
# the build directory never happens. This is how we foil that.
ctx.add_pre_fun(lambda ctx: ctx.exec_command("rm -f pylib/*.py[co]"))
-
- if ctx.variant == "host":
+ # Start purging ntp.ntpc files from build dir
+ # so old extension won't clobber FFI or reverse
+ bldnode = ctx.bldnode.make_node('pylib')
+ bldnode.mkdir()
+ target3 = bldnode.ant_glob('*ntpc*')
+ for _ in target3:
+ ctx.exec_command("rm -f %s" % _.abspath())
+ # Finish purging ntp.ntpc
+ ctx.add_group()
+
+ if not ctx.env['client-only']:
+ if ctx.env.REFCLOCK_GENERIC or ctx.env.REFCLOCK_TRIMBLE:
+ # required by the generic and Trimble refclocks
+ ctx.recurse("libparse")
+ ctx.recurse("libntp")
+ if not ctx.env['client-only']:
+ ctx.recurse("libaes_siv")
ctx.recurse("ntpd")
- return
-
+ ctx.recurse("ntpfrob")
+ ctx.recurse("ntptime")
ctx.recurse("pylib")
- if ctx.env.REFCLOCK_GENERIC or ctx.env.REFCLOCK_TRIMBLE:
- # required by the generic and Trimble refclocks
- ctx.recurse("libparse")
- ctx.recurse("libntp")
- ctx.recurse("libaes_siv")
- ctx.recurse("ntpd")
- ctx.recurse("ntpfrob")
- ctx.recurse("ntptime")
- ctx.recurse("attic")
- ctx.recurse("etc")
+ if not ctx.env['client-only']:
+ ctx.recurse("attic")
+ ctx.recurse("etc")
ctx.recurse("tests")
if ctx.env['PYTHON_ARGPARSE']:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/d1c9cbda4c637e0adbcbc4dc171503ff3fa63f96...47dcbd010cdeadeac4cd6cb741545a4925d10177
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/d1c9cbda4c637e0adbcbc4dc171503ff3fa63f96...47dcbd010cdeadeac4cd6cb741545a4925d10177
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20200913/634d3815/attachment-0001.htm>
More information about the vc
mailing list