gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 3/5] Fixes gratuitous rebuild in non-git directories.


From: Fred Wright
Subject: [gpsd-dev] [PATCH 3/5] Fixes gratuitous rebuild in non-git directories.
Date: Sun, 23 Oct 2016 14:16:56 -0700

The code that generates the version string for development versions
tries to identify the specific code state in one of two ways.  When
the build is within a git repo, it uses "git describe" output.  When
the build is not within a git repo, it uses the date and time.

Before this change, the applicable date and time was the current date
and time, causing revision.h and everything that depends on it to be
rebuilt every time, even if no sources changed.  This change causes it
to use the latest mtime among the relevant sources instead, thus still
having the desired effect without unnecessary changes in the version
string.

Since git doesn't preserve mtimes, the resulting date/time may reflect
the last checkout of the relevant files rather than the last actual
change, but this is still a vast improvement.  And recent versions of
git avoid clobbering the mtimes of files that are not actually altered
by the checkout.

This change also alters the version format somewhat in this case, both
to incorporate the actual version number, and to eliminate some
truncation which was probably slightly incorrect, anyway.

A sample new format is:

        "3.17~dev-2016-09-24T19:06:46"

TESTED:
Tested both git and non-git cases.  Did not test the non-"dev" case,
but that code path is untouched.
---
 SConstruct | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/SConstruct b/SConstruct
index 8cd558a..c1495d1 100644
--- a/SConstruct
+++ b/SConstruct
@@ -63,7 +63,7 @@ tipwidget  = '<p><a href="https://www.patreon.com/esr";>Donate 
here to support co
 
 EnsureSConsVersion(2, 3, 0)
 
-import copy, os, sys, glob, re, platform, time, subprocess, ast
+import copy, os, sys, glob, re, platform, time, subprocess, ast, operator
 from distutils import sysconfig
 from distutils.util import get_platform
 import SCons
@@ -1442,21 +1442,49 @@ env.Command(target="ais_json.i", source="jsongen.py", 
action='''\
     $SC_PYTHON $SOURCE --ais --target=parser >$TARGET &&\
     chmod a-w $TARGET''')
 
+generated_sources = ['packet_names.h', 'timebase.h', 'gpsd.h', "ais_json.i",
+                     'gps_maskdump.c', 'revision.h', 'gpsd.php',
+                     'gpsd_config.h']
+
+# Helper functions for revision hackery
+
+def GetMtime(file):
+    """Get mtime of given file, or 0."""
+    try:
+        return os.stat(file).st_mtime
+    except OSError:
+        return 0
+
+def FileList(patterns, exclusions=[]):
+    """Get list of files based on patterns, minus excluded files."""
+    files = reduce(operator.add, map(glob.glob, patterns), [])
+    for file in exclusions:
+        try:
+            files.remove(file)
+        except ValueError:
+            pass
+    return files
+
 # generate revision.h
 if 'dev' in gpsd_version:
     (st, rev) = _getstatusoutput('git describe --tags')
     if st != 0:
-        from datetime import datetime
-        rev = datetime.now().isoformat()[:-4]
+        # Use timestamp from latest relevant file
+        files = FileList(['*.c', '*.cpp', '*.h', '*.in',
+                          'gpsd.h-*', 'SConstruct'],
+                         generated_sources)
+        timestamps = map(GetMtime, files)
+        if timestamps:
+            from datetime import datetime
+            latest = datetime.fromtimestamp(sorted(timestamps)[-1])
+            rev = '%s-%s' % (gpsd_version, latest.isoformat())
+        else:
+            rev = gpsd_version  # Paranoia
 else:
     rev = gpsd_version
 revision = '#define REVISION "%s"\n' % (rev.strip(),)
 env.Textfile(target="revision.h", source=[revision])
 
-generated_sources = ['packet_names.h', 'timebase.h', 'gpsd.h', "ais_json.i",
-                     'gps_maskdump.c', 'revision.h', 'gpsd.php',
-                     'gpsd_config.h']
-
 # leapseconds.cache is a local cache for information on leapseconds issued
 # by the U.S. Naval observatory. It gets kept in the repository so we can
 # build without Internet access.
-- 
2.10.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]