[Git][NTPsec/ntpsec][master] Make PPS API checks more robust.

Amar Takhar gitlab at mg.gitlab.com
Mon Nov 30 16:41:09 UTC 2015


Amar Takhar pushed to branch master at NTPsec / ntpsec


Commits:
38e49ac7 by Amar Takhar at 2015-11-30T11:40:09Z
Make PPS API checks more robust.

  * Add a compile check to ensure the PPS capabilities exist.
  * Send a warning and automatically disable PPS clocks if they are requested by
    the user but the API is not available.

This fixes #17

- - - - -


3 changed files:

- + pylib/check_timepps.py
- pylib/configure.py
- pylib/refclock.py


Changes:

=====================================
pylib/check_timepps.py
=====================================
--- /dev/null
+++ b/pylib/check_timepps.py
@@ -0,0 +1,29 @@
+TIMEPPS_FRAG = """
+#include <sys/types.h>
+
+#ifdef HAVE_TIMEPPS_H
+# include <timepps.h>
+#else
+# ifdef HAVE_SYS_TIMEPPS_H
+#  include <sys/timepps.h>
+# endif
+#endif
+
+int main(void) {
+	pps_handle_t pps_h;
+	time_pps_destroya (pps_h);
+
+    return 0;
+}
+"""
+
+
+def check_timepps(ctx):
+	ctx.check_cc(
+		fragment	= TIMEPPS_FRAG,
+		define_name = "HAVE_PPSAPI",
+		features	= "c",
+		msg         = "Checking if PPS PAI works",
+		mandatory	= False
+	)
+


=====================================
pylib/configure.py
=====================================
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -303,7 +303,8 @@ def cmd_configure(ctx):
 			print "Compilation check failed but include exists %s" % hdr
 
 	if ctx.get_define("HAVE_TIMEPPS_H") or ctx.get_define("HAVE_SYS_TIMEPPS_H"):
-		ctx.define("HAVE_PPSAPI", 1)
+		from pylib.check_timepps import check_timepps
+		check_timepps(ctx)
 
 
 	ctx.check_cc(header_name="event2/event.h", includes=ctx.env.PLATFORM_INCLUDES)
@@ -485,5 +486,5 @@ def cmd_configure(ctx):
 	msg_setting("LDFLAGS", " ".join(ctx.env.LDFLAGS))
 	msg_setting("PREFIX", ctx.env.PREFIX)
 	msg_setting("Debug Support", yesno(ctx.options.enable_debug))
-	msg_setting("Refclocks", ctx.options.refclocks)
+	msg_setting("Refclocks", ", ".join(ctx.env.REFCLOCK_LIST))
 	msg_setting("Build Manpages", yesno(ctx.env.BIN_A2X and not ctx.env.DISABLE_MANPAGE))


=====================================
pylib/refclock.py
=====================================
--- a/pylib/refclock.py
+++ b/pylib/refclock.py
@@ -1,4 +1,5 @@
 from waflib.Configure import conf
+from waflib.Logs import pprint
 
 # Note: When you change this list. also check the following files:
 # doc/recflock.txt
@@ -110,6 +111,7 @@ refclock_map = {
 	30: {
 		"descr":	"Motorola UT Oncore GPS",
 		"define":	"CLOCK_ONCORE",
+		"require":	["ppsapi"],
 		"file":		"oncore"
 	},
 
@@ -225,12 +227,21 @@ def refclock_config(ctx):
 			for subtype in parse_clocks:
 				ctx.define(subtype, 1)
 
-		ctx.start_msg("Enabling Refclock %s:" % id)
+		ctx.start_msg("Enabling Refclock %s (%d):" % (rc["descr"], id))
+
+		if "require" in rc:
+			if "ppsapi" in rc["require"]:
+				if not ctx.get_define("HAVE_PPSAPI"):
+					ctx.end_msg("No")
+					pprint("RED", "Refclock \"%s\" disabled, PPS API has not been detected as working." % rc["descr"])
+					continue
+
 		ctx.env.REFCLOCK_SOURCE.append((rc["file"], rc["define"]))
-		ctx.end_msg(rc["descr"])
 		ctx.env["REFCLOCK_%s" % rc["file"].upper()] = True
-
 		ctx.define(rc["define"], 1)
+		ctx.env.REFCLOCK_LIST += [str(id)]
+
+		ctx.end_msg("Yes")
 
 		refclock = True
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/38e49ac7719213a43e6957adb6bdee31f86cffbd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151130/09b4e077/attachment.html>


More information about the vc mailing list