[Git][NTPsec/ntpsec][master] 9 commits: Disables useless pyembed check and setup.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Sep 26 09:14:58 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
fc512729 by Fred Wright at 2017-09-26T05:13:49-04:00
Disables useless pyembed check and setup.

Since nothing here contains an embedded python interpreter, there's no
reason to bother with the setup to build it.  That was only being done
because check_python_headers() does both pyembed and pyext by default.

TESTED:
Ran several Python client and test programs with all supported versions
of Python.  No issues related to the extension build.

- - - - -
4f281984 by Fred Wright at 2017-09-26T05:13:49-04:00
Fixes incorrect Python library install locations.

This makes three changes related to Python library install locations:

1) Adds a workaround for waf's broken code that sets up PYTHONDIR and
PYTHONARCHDIR.  The code is conceptually broken on all platforms, though
it may produce correct results by coincidence on some platforms.  See
the comments in wafhelpers/fix_python_config.py for more details.

2) Adds reporting of the PYTHONDIR and PYTHONARCHDIR values to the
configure output, so that misbehavior of this form is more obvious.

3) Adds a comment indicating why the Python extension install isn't
using PYTHONARCHDIR as it ordinarily should.

TESTED:
Did a simple "launch test" (using -V) with ntpdig, ntplogtemp, ntpmon,
ntpq, and ntpviz, with all supported Python versions (2.6, 2.7,
3.3-3.6) from MacPorts on OSX 10.9.  Also tested with Python 2.7 on
OSX 10.5-10.12, Ubuntu 14, CentOS 7, Fedora 25, FreeBSD 10.3, and
OpenBSD 5.6.  PYTHONPATH was unset in all cases (as it should be).

- - - - -
301851df by Fred Wright at 2017-09-26T05:13:49-04:00
Fixes Python in-tree build setup.

This reworks a few things to make in-tree testing of Python code
work properly.  Note that all tweaks for this are now applied to
the build tree rather than the source tree, so the build-tree
copies of the programs should be used.  Specifically:

1) Moves the generated Python sources to the build tree, where they're
findable by the Python programs in the build tree.

2) Builds the C extension into the pylib directory, where it's needed.
This avoids the need to symlink it into pylib, and to be aware of the
different naming conventions used by different Python versions.

3) It copies the non-generated Python sources to the build tree, where
they're sometimes needed even when the .pyc/.pyo files are present
(e.g., by Python 3).

4) The symlinks for the 'ntp' package are now placed in the build tree
rather than the source tree.

TESTED:
Ran three client programs (ntpdig, ntpq, and ntpviz) sufficient to
cover all imports, as well as the four test programs in tests/pylib.
No import-related issues, though some programs have other issues with
Python 3.

- - - - -
b3f4a825 by Fred Wright at 2017-09-26T05:13:49-04:00
Suppresses wafhelpers .pyc files.

Setting the option in Python to suppress writing .pyc files before
importing any wafhelpers modules avoids some source-tree pollution
with no appreciable effect on build time.

This also allows the added cleanup in afterparty to be further
reduced.

TESTED:
Ran configure+build with all supported Python versions, and observed
no .pyc files under wafhelpers/.
Also verified that clean still works.

- - - - -
a2788263 by Fred Wright at 2017-09-26T05:13:49-04:00
Adds cleanup for incorrect Python library installs.

Because install and uninstall only apply to the locations known to the
current version of the script, libraries installed to the location
determined by the old buggy code could linger.  This could be
especially troublesome if PYTHONPATH had (inappropriately) been set up
to point to the incorrect location.  This adds code to get around this
by removing any libraries installed to the old location (when it
differs).  Since one might do an install without an uninstall, this
cleanup is applied to both.

TESTED:
Ran both install and uninstall, each after previously installing with
the old code.  Verified that the old libraries were removed, and that
the warning to remove the old directory appeared.

- - - - -
947e05e5 by Fred Wright at 2017-09-26T05:13:49-04:00
Removes all PYTHONPATH references.

All references to PYTHONPATH existed solely in relation to the
incorrect library install locations that may have been used prior to
the recent fix.  Since setting PYTHONPATH is generally undesirable, it
has now been removed from the error messages and from the
documentation.

Note that there were two import errors in ntpmon unrelated to ntpsec
itself, but which suggested the use of PYTHONPATH.  If this is still
an issue, something else needs to be fixed.

TESTED:
Ran all relevant programs with the ntp libraries inaccessible, and
verified proper error messages.

- - - - -
32121f86 by Fred Wright at 2017-09-26T05:13:49-04:00
Adds build-time warning when PYTHONPATH is set.

Because previous versions of the script and documentation
inappropriately recommended setting PYTHONPATH, some developers (and
perhaps even some users) may have added it to startup scripts.  Since
this may mask problems or even cause problems in some cases, it's
important to undo any such changes.  The old build-time warning is
here resurrected in the inverted sense, warning if PYTHONPATH *is*
set.

This code can be removed once sufficient time has passed to eradicate
all inappropriate PYTHONPATH definitions.

TESTED:
Verified that the message appears iff PYTHONPATH is set.

- - - - -
e2150fe0 by Fred Wright at 2017-09-26T05:13:49-04:00
Fixes misleading ntploggps error when GPSD not installed.

TESTED:
Verified correct behavior in all three cases.

- - - - -
1e645117 by Fred Wright at 2017-09-26T05:13:49-04:00
Removes execute permissions from client and test sources.

Since in-tree testing is intended to use the build-tree copies of the
programs, removing execute permissions from the source-tree copies
avoids accidentally running the wrong copies.  This doesn't affect the
build-tree copies or the installed copies, since the permissions are
explicitly set as those are generated.  Not running the source copies
also avoids polluting the source directory with .pyc/.pyo files.

TESTED:
Verified correct permissions in all places.

- - - - -


23 changed files:

- .gitignore
- INSTALL
- contrib/ntpheat
- contrib/ntpheatusb
- devel/testing.txt
- libntp/wscript
- ntpclients/ntpdig
- ntpclients/ntpkeygen
- ntpclients/ntploggps
- ntpclients/ntplogtemp
- ntpclients/ntpmon
- ntpclients/ntpq
- ntpclients/ntpsweep
- ntpclients/ntptrace
- ntpclients/ntpviz
- ntpclients/ntpwait
- pylib/wscript
- tests/pylib/test_statfiles.py
- tests/pylib/test_util.py
- tests/time-startup.sh
- tests/wscript
- + wafhelpers/fix_python_config.py
- wscript


Changes:

=====================================
.gitignore
=====================================
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,6 @@
-pylib/version.py
-pylib/control.py
-pylib/magic.py
-*/ntp
-*/*/ntp
 wafhelpers/.autorevision-cache
 .lock-waf*
 .waf*
 *.pyc
 ntpd/version.h
 build
-


=====================================
INSTALL
=====================================
--- a/INSTALL
+++ b/INSTALL
@@ -51,13 +51,6 @@ Python 2.x, x >= 6, or Python 3.x, x >= 3::
    installation and Python dev tools, if your OS makes such a
    distinction.
 
-  Some OS distros won't find our installed python libraries.
-  Your shell may need something like this:
-    export PYTHONPATH=/usr/local/lib/python2.7/site-packages
-  CentOS 6 is using python 2.6
-    export PYTHONPATH=/usr/local/lib/python2.6/site-packages
-  (I put it in my .bashrc)
-
 argparse::
    Required for ntpviz when using Python version 2.6
    Install with pip: pip install argparse


=====================================
contrib/ntpheat
=====================================
--- a/contrib/ntpheat
+++ b/contrib/ntpheat
@@ -24,8 +24,7 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpheat: can't find Python NTP modules "
-                     "-- check PYTHONPATH.\n%s\n" % e)
+    sys.stderr.write("ntpheat: can't find Python NTP modules.\n%s\n" % e)
     sys.exit(1)
 
 # Work with argvars


=====================================
contrib/ntpheatusb
=====================================
--- a/contrib/ntpheatusb
+++ b/contrib/ntpheatusb
@@ -37,8 +37,7 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpheatusb: can't find Python NTP modules "
-                     "-- check PYTHONPATH.\n%s\n" % e)
+    sys.stderr.write("ntpheatusb: can't find Python NTP modules.\n%s\n" % e)
     sys.exit(1)
 
 


=====================================
devel/testing.txt
=====================================
--- a/devel/testing.txt
+++ b/devel/testing.txt
@@ -9,10 +9,11 @@ directory.
 == Path problems with the test tools ==
 
 The very first thing to do, even before you start up ntpd, is to change
-directory to ntpclients/ and run ./ntpq there. If you get a message that says
+directory to build/main/ntpclients/ and run ./ntpq there. If you get a message
+that says
 
 ---------------------------------------------------------------------
-ntpq: can't find Python NTP library -- check PYTHONPATH.
+ntpq: can't find Python NTP library.
 ---------------------------------------------------------------------
 
 you *may* have a problem.  A lot of what was C code in legacy versions
@@ -21,25 +22,20 @@ Python in order to improve maintainability and decrease attack
 surface.  Most of these tools share a Python library of critical
 functions.  If you can't load that library, you can't test effectively.
 
-The waf build is supposed to create a symbolic link from ntpclients/ntp to
-pylib in the build directory. This should enable ntpq to "import ntp"
-before you install to rootspace. If that link is not created or
-doesn't point to pylib/ under your build directory, report
+The waf build is supposed to create a symbolic link from
+build/main/ntpclients/ntp to pylib in the build directory. This should enable
+ntpq to "import ntp" before you install to rootspace. If that link is not
+created or doesn't point to pylib/ under your build directory, report
 this as a bug. If it is, but ./ntpq startup fails anyway, you may
 have a mis-configured Python and need to investigate that.
 
-Load paths are more likely to be an issue after rootspace
-installation.  On most systems, waf will by default install the Python
-library under /usr/local/lib/python${VERSION}/dist-packages (or
-possibly the peer directory site-packages) where ${VERSION} is what
-the command "python --version" gives back. This directory should be on
-your Python's sys.path, in which case all will proceed normally.
-
-If it's not, you will get the same ntpq failure to launch ./ntpq from
-anywhere *outside* the source tree.  You may be able to patch around
-this by setting the environment variable PYTHONPATH to include the
-rootspace directory where waf installed the library; use "waf -v
-install" to nail down this location.
+Load paths may be more likely to be an issue after rootspace installation.
+The script should install the Python library in the directory specified by
+Python itself, which is reported as PYTHONDIR near the end of the configure
+phase.  This directory should be on your Python's sys.path, in which case all
+will proceed normally.  If it's not, you will get the same ntpq failure to
+launch ./ntpq from anywhere *outside* the source tree.  If this is the case,
+report it as a bug.
 
 Be aware that if this sort of problem occurs in an NTPsec instance
 installed from a binary package, it is almost certainly not an NTPsec


=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -55,11 +55,15 @@ def build(ctx):
     )
 
     # Loadable Python extension
+    #
+    # In theory this should use PYTHONARCHDIR, but that doesn't work on
+    # CentOS (at least), for some as-yet-undetermined reason.  On most
+    # platforms, PYTHONARCHDIR == PYTHONDIR, anyway.
     ctx(
         features="c cshlib bld_include src_include pyext",
         install_path='${PYTHONDIR}/ntp',
         includes=includes,
         source=["pymodule.c"] + libntp_source_sharable,
-        target="ntpc",
+        target="../pylib/ntpc",  # Put the output in the pylib directory
         use="M RT CRYPTO",
     )


=====================================
ntpclients/ntpdig
=====================================
--- a/ntpclients/ntpdig
+++ b/ntpclients/ntpdig
@@ -52,7 +52,7 @@ try:
     import ntp.magic
 except ImportError as e:
     sys.stderr.write(
-        "ntpdig: can't find Python NTP library -- check PYTHONPATH.\n")
+        "ntpdig: can't find Python NTP library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpkeygen
=====================================


=====================================
ntpclients/ntploggps
=====================================
--- a/ntpclients/ntploggps
+++ b/ntpclients/ntploggps
@@ -28,11 +28,12 @@ import threading
 import time
 
 try:
+    package = 'GPSD'  # pylint: disable=invalid-name
     import gps
+    package = 'NTP'  # pylint: disable=invalid-name
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntploggps: can't find Python NTP modules "
-                     "-- check PYTHONPATH.\n")
+    sys.stderr.write("ntploggps: can't find Python %s modules.\n" % package)
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntplogtemp
=====================================
--- a/ntpclients/ntplogtemp
+++ b/ntpclients/ntplogtemp
@@ -34,8 +34,7 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntplogtemp: can't find Python NTP modules "
-                     "-- check PYTHONPATH.\n%s\n" % e)
+    sys.stderr.write("ntplogtemp: can't find Python NTP modules.\n%s\n" % e)
     sys.exit(1)
 
 


=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -40,7 +40,7 @@ try:
     import ntp.magic
 except ImportError as e:
     sys.stderr.write(
-        "ntpmon: can't find Python NTP library -- check PYTHONPATH.\n")
+        "ntpmon: can't find Python NTP library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 
@@ -49,7 +49,7 @@ try:
     import locale
 except ImportError as e:
     sys.stderr.write(
-        "ntpmon: can't find Python locale library -- check PYTHONPATH.\n")
+        "ntpmon: can't find Python locale library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 
@@ -57,7 +57,7 @@ try:
     import curses
 except ImportError as e:
     sys.stderr.write(
-        "ntpmon: can't find Python curses library -- check PYTHONPATH.\n")
+        "ntpmon: can't find Python curses library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -30,7 +30,7 @@ try:
     import ntp.version
 except ImportError as e:
     sys.stderr.write(
-        "ntpq: can't find Python NTP library -- check PYTHONPATH.\n")
+        "ntpq: can't find Python NTP library.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpsweep
=====================================


=====================================
ntpclients/ntptrace
=====================================


=====================================
ntpclients/ntpviz
=====================================
--- a/ntpclients/ntpviz
+++ b/ntpclients/ntpviz
@@ -101,8 +101,7 @@ try:
     import ntp.statfiles
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpviz: can't find Python NTP modules "
-                     "-- check PYTHONPATH.\n")
+    sys.stderr.write("ntpviz: can't find Python NTP modules.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpwait
=====================================


=====================================
pylib/wscript
=====================================
--- a/pylib/wscript
+++ b/pylib/wscript
@@ -1,20 +1,35 @@
+from waflib import Utils  # pylint: disable=import-error
+from wafhelpers.fix_python_config import FixConfig
+
+
 def options(opt):
     opt.load('python')
 
 
 def configure(conf):
-    conf.load('python')
-    conf.check_python_version((2, 6, 0))
-    conf.check_python_headers()
+    fixed = FixConfig(conf)
+    fixed.load('python')
+    fixed.check_python_version((2, 6, 0))
+    conf.check_python_headers(features='pyext')  # Extension-only, no embedded
 
 
 def build(ctx):
     srcnode = ctx.srcnode.make_node('pylib')
-    # bldnode = ctx.bldnode.make_node('pylib')
-    target1 = ctx.srcnode.make_node('pylib/control.py')
-    target2 = ctx.srcnode.make_node('pylib/magic.py')
-    target3 = ctx.srcnode.make_node('pylib/version.py')
+    bldnode = ctx.bldnode.make_node('pylib')
+    target1 = bldnode.make_node('control.py')
+    target2 = bldnode.make_node('magic.py')
+    target3 = bldnode.make_node('version.py')
     target4 = ctx.srcnode.make_node('wafhelpers/.autorevision-cache')
+    sources = srcnode.ant_glob('*.py')
+    builds = [x.get_bld() for x in sources]
+
+    # Make sure Python sees .py as well as .pyc/.pyo
+    ctx(
+        features="subst",
+        source=sources,
+        target=builds,
+        chmod=Utils.O755,
+    )
 
     ctx(
         before=['pyc', 'pyo'],
@@ -36,7 +51,7 @@ def build(ctx):
         before=['pyc', 'pyo'],
         cwd=srcnode,
         rule='VCS_EXTRA=`cat ${SRC[0]}` ../wafhelpers/autorevision.sh '
-             '-o ${TGT[1].abspath()} -e VERSION -t python >${TGT[0].name}',
+             '-o ${TGT[1].abspath()} -e VERSION -t python >${TGT[0].abspath()}',
         source=["../VERSION", '../wafhelpers/autorevision.sh'],
         target=[target3, target4],
     )
@@ -46,7 +61,7 @@ def build(ctx):
 
     ctx(
         features='py',
-        source=ctx.path.ant_glob('*.py')+ctx.path.ant_glob('*.py[oc]'),
-        install_from='.',
+        source=builds+[target1, target2, target3],
+        install_from=bldnode,
         install_path='${PYTHONDIR}/ntp'
     )


=====================================
tests/pylib/test_statfiles.py
=====================================


=====================================
tests/pylib/test_util.py
=====================================


=====================================
tests/time-startup.sh
=====================================
--- a/tests/time-startup.sh
+++ b/tests/time-startup.sh
@@ -1,9 +1,6 @@
 #!/bin/sh
 # Hack to measure startup timing
 
-# FIXME - needed on Fedora
-export PYTHONPATH=/usr/local/lib/python2.7/site-packages
-
 if test "$#" -ge 1
 then
   CONF=$1


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -1,5 +1,10 @@
+from waflib import Utils  # pylint: disable=import-error
+
 def build(ctx):
     srcnode = ctx.srcnode.abspath()
+    testsrc = ctx.srcnode.make_node('tests')
+    testpylib = testsrc.make_node('pylib')
+    testpysrc = testpylib.ant_glob('*.py')
 
     # Unity source
     unity_source = [
@@ -109,5 +114,14 @@ def build(ctx):
             "M PTHREAD CRYPTO RT SOCKET NSL",
     )
 
+    testpylib.get_bld().mkdir()
+
+    ctx(
+        features="subst",
+        source=testpysrc,
+        target=[x.get_bld() for x in testpysrc],
+        chmod=Utils.O755,
+    )
+
     # ctx.exec_command("%s/tests/pylib/test_statfiles.py" % srcnode)
     # ctx.exec_command("%s/tests/pylib/test_util.py" % srcnode)


=====================================
wafhelpers/fix_python_config.py
=====================================
--- /dev/null
+++ b/wafhelpers/fix_python_config.py
@@ -0,0 +1,100 @@
+"""Work around waf bugs related to Python config setup."""
+
+import os
+
+from waflib import Utils  # pylint: disable=import-error
+from waflib.Logs import pprint  # pylint: disable=import-error
+
+# NOTE:  Everything in this file relates to waf bugs.  It can go away once
+# the waf bugs are fixed.
+
+# The waf code for setting up PYTHONDIR and PYTHONARCHDIR is broken, because
+# get_python_lib() only returns the proper library locations when the 'prefix'
+# argument is absent or None, but waf insists on feeding it the PREFIX value.
+# To make matters worse, the design of waf's ConfigSet object makes it
+# impossible to get it to return a value of None for any item, so merely
+# temporarily patching PREFIX doesn't work.  Thus, the most straightforward
+# workaround is to duplicate the relevant code with the properly omitted
+# 'prefix'.
+#
+# In principle, there might be some value in allowing a prefix to be optionally
+# supplied (separately from PREFIX), but given that both values are already
+# overridable, there's little need for an additional option.
+#
+# Naturally, the fix doesn't override user-supplied values, but the fixup runs
+# after the version check, using the captured original settings to determine
+# whether to override.
+
+# An additional function is temporarily needed to clean up any libraries
+# that had been installed to the incorrect PYTHONDIR by former
+# versions of the script.
+#
+# Although this code is a NOP when the old and new install locations are
+# identical, for maximum safety the extra deletions are done preinstall
+# and postuninstall.  This might matter if the old and new locations were
+# symlinked together (a possible workaround for the old bug).
+#
+# Merely removing the libraries doesn't remove the containing directory(s)
+# which may have been newly created by the old script.  Removing any such
+# directories is desirable, but doing so automatically would be too
+# dangerous.  The compromise is to issue a warning message when an empty
+# containing directory is left.  This is always done at the end, to avoid
+# burying the warning in the install messages.
+
+
+class FixConfig(object):
+    """Methods and state for working around waf's python-config bugs."""
+    def __init__(self, conf):
+        """Initialize state from conf object."""
+        self.conf = conf
+        self.opts = None
+
+    def get_options(self):
+        """Capture values after option processing."""
+        self.opts = self.conf.env.derive().detach()
+
+    def fix_python_libs(self):
+        """Fix up library install paths."""
+        # Remember original setting for "compatibility cleanup".
+        self.conf.env.OLD_PYTHONDIR = self.conf.env.PYTHONDIR
+        if Utils.is_win32:
+            return  # No fixups supported on Windows
+        if not ('PYTHONDIR' in self.opts or 'PYTHONDIR' in self.conf.environ):
+            (pydir,) = self.conf.get_python_variables(
+                ["get_python_lib(plat_specific=0)"]
+                )
+            self.conf.env.PYTHONDIR = pydir
+        if not ('PYTHONARCHDIR' in self.opts
+                or 'PYTHONARCHDIR' in self.conf.environ):
+            (pyarchdir,) = self.conf.get_python_variables(
+                ["get_python_lib(plat_specific=1)"]
+                )
+            self.conf.env.PYTHONARCHDIR = pyarchdir or pydir
+
+    def load(self, *args, **kwargs):
+        """Do the load and capture the options."""
+        self.conf.load(*args, **kwargs)
+        self.get_options()
+
+    def check_python_version(self, *args, **kwargs):
+        """Check version and fix up install paths."""
+        self.conf.check_python_version(*args, **kwargs)
+        self.fix_python_libs()
+
+    @staticmethod
+    def cleanup_python_libs(ctx, cmd='preinstall'):
+        """Remove any Python libs that were installed to the wrong location."""
+        if not ctx.env.PYTHONDIR:
+            return  # Here on pre-setup call
+        if ctx.env.PYTHONDIR == ctx.env.OLD_PYTHONDIR:
+            return  # Here when old bug had no effect
+        if not os.path.isdir(ctx.env.OLD_PYTHONDIR):
+            return  # Here when old dir doesn't exist or isn't a dir
+        if cmd in ('preinstall', 'uninstall'):
+            ctx.exec_command('rm -rf %s/ntp' % ctx.env.OLD_PYTHONDIR)
+        if cmd == 'preinstall':
+            return  # Skip message where it's not likely to be seen
+        # See if we may have left an inappropriate empty directory
+        if not os.listdir(ctx.env.OLD_PYTHONDIR):
+            pprint('YELLOW',
+                   'May need to manually remove %s' % ctx.env.OLD_PYTHONDIR)


=====================================
wscript
=====================================
--- a/wscript
+++ b/wscript
@@ -17,10 +17,15 @@ from waflib.Errors import WafError
 from waflib.Logs import pprint
 from waflib.Tools import waf_unit_test
 
+# Avoid writing .pyc files in wafhelpers/
+sys.dont_write_bytecode = True
+
 from wafhelpers.options import options_cmd
 from wafhelpers.probes \
     import probe_header_with_prerequisites, probe_function_with_prerequisites
 from wafhelpers.test import test_write_log, test_print_log
+from wafhelpers.fix_python_config import FixConfig
+
 
 pprint.__doc__ = None
 
@@ -930,6 +935,8 @@ int main(int argc, char **argv) {
                 yesno(ctx.env.ENABLE_DOC and not ctx.env.DISABLE_MANPAGE))
 
     ctx.recurse("pylib")
+    msg_setting("PYTHONDIR", ctx.env.PYTHONDIR)
+    msg_setting("PYTHONARCHDIR", ctx.env.PYTHONARCHDIR)
 
 
 class check(BuildContext):
@@ -1005,24 +1012,23 @@ for command, func, descr in commands:
 def afterparty(ctx):
     # Make magic links to support in-tree testing.
     #
-    # The idea is that all directories where the Python tools
-    # listed above live should have an 'ntp' symlink so they
-    # can import compiled Python modules from the build directory.
-    # Also, they need to be able to see the Python extension
-    # module built in libntp.
+    # The idea is that all directories where the Python tools live should
+    # have an 'ntp' symlink so they can import Python modules from the pylib
+    # directory.
     #
-    # Note, this kluge falls apart under Python 3, because
-    # waf radically changes the shape of the build directory and
-    # the naming conventions for the product files.
+    # Note that this setup is applied to the build tree, not the
+    # source tree.  Only the build-tree copies of the programs are
+    # expected to work.
     if ctx.cmd == 'clean':
-        ctx.exec_command("rm -fr wafhelpers/*.pyc pylib/__pycache__/*.pyc "
-                         "wafhelpers/__pycache__/*.pyc ntpd/version.h "
-                         "ntpclients/ntp tests/pylib/ntp")
+        ctx.exec_command("rm -f ntpd/version.h ")
+    if ctx.cmd in ('uninstall', 'install'):
+        # Make sure libs are removed from the old location
+        FixConfig.cleanup_python_libs(ctx, ctx.cmd)
     for x in ("ntpclients", "tests/pylib"):
         # List used to be longer...
         path_build = ctx.bldnode.make_node("pylib")
-        path_source = ctx.srcnode.make_node(x + "/ntp")
-        relpath = ("../" * (x.count("/")+1)) + path_build.path_from(ctx.srcnode)
+        path_source = ctx.bldnode.make_node(x + "/ntp")
+        relpath = ("../" * (x.count("/")+1)) + path_build.path_from(ctx.bldnode)
         if ctx.cmd in ('install', 'build'):
             if ((not path_source.exists() or
                     os.readlink(path_source.abspath()) != relpath)):
@@ -1031,14 +1037,7 @@ def afterparty(ctx):
                 except OSError:
                     pass
                 os.symlink(relpath, path_source.abspath())
-        elif ctx.cmd == 'clean':
-            if path_source.exists():
-                # print "removing", path_source.abspath()
-                os.remove(path_source.abspath())
-    bldnode = ctx.bldnode.abspath()
-    if ctx.cmd in ('install', 'build'):
-        os.system("cd %s/pylib; ln -sf ../libntp/ntpc.so ntpc.so "
-                  % (bldnode,))
+
 
 python_scripts = [
     "ntpclients/ntploggps",
@@ -1065,6 +1064,10 @@ def build(ctx):
         # 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.cmd == "install":
+        # Make sure libs are removed from the old location
+        ctx.add_pre_fun(FixConfig.cleanup_python_libs)
+
     if ctx.env.ENABLE_DOC_USER:
         if ctx.variant != "main":
             ctx.recurse("docs")
@@ -1132,9 +1135,9 @@ def build(ctx):
         Options.options.no_tests = True
 
     if ctx.cmd == "build":
-        if "PYTHONPATH" not in os.environ:
-            print("--- PYTHONPATH is not set, "
-                  "loading the Python ntp library may be troublesome ---")
+        if "PYTHONPATH" in os.environ:
+            print("--- PYTHONPATH is set, "
+                  "this may mask or cause library-related problems ---")
 
 #
 # Boot script setup



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fde16e4cf0cb54b2d8128dd790d2842a9ceb48b1...1e6451178b71b153dd76254a09b3a75f2c05f17b

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fde16e4cf0cb54b2d8128dd790d2842a9ceb48b1...1e6451178b71b153dd76254a09b3a75f2c05f17b
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/20170926/07839005/attachment.html>


More information about the vc mailing list