swc-installation-test-2.py: Add MakeDependency class
authorW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:32:46 +0000 (09:32 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:49:49 +0000 (09:49 -0500)
On the fairly ancient SunOS 5.10 (January 2005), `make` doesn't
support `--version`.  Looking into the POSIX.2 specs [1], it doesn't
have to.  On FreeBSD [2] and in GNU Make [3], there is a MAKE_VERSION
variable, and the Sun executable has something similar:

  $ strings make | grep MAKE_VERSION
  .MAKE_VERSION

but it just expands to an empty string.

Since reading a makefile from stdin *is* in POSIX [1], we can use that
to test `make` if `make --version` fails.  If we get something for
MAKE_VERSION, use that.  If we get something for MAKE (required by
POSIX [2]), then call that a valid, but unkown, version.

[1]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/make.html#tag_04_84_04
[2]: http://lists.freebsd.org/pipermail/freebsd-questions/2010-October/222214.html
[3]: http://www.gnu.org/software/make/manual/html_node/Features.html#index-MAKE_005fVERSION-1021
[4]: http://pubs.opengroup.org/onlinepubs/009695399/utilities/make.html#tag_04_84_13_08

swc-installation-test-2.py

index a2d7f0163b66c0ed72341c77e2a1b448408f54bd..3de2fdb9dfe8932861494c797db787d3993eaf9f 100755 (executable)
@@ -321,7 +321,6 @@ for command,long_name,minimum_version in [
         ('zsh', 'Z Shell', None),
         ('git', 'Git', (1, 7, 0)),
         ('hg', 'Mercurial', (2, 0, 0)),
-        ('make', None, None),
         ('sqlite3', 'SQLite 3', None),
         ('nosetests', 'Nose', (1, 0, 0)),
         ('emacs', 'Emacs', None),
@@ -342,6 +341,41 @@ for command,long_name,minimum_version in [
 del command, long_name, minimum_version  # cleanup namespace
 
 
+class MakeDependency (CommandDependency):
+    makefile = '\n'.join([
+            'all:',
+            '\t@echo "MAKE_VERSION=$(MAKE_VERSION)"',
+            '\t@echo "MAKE=$(MAKE)"',
+            '',
+            ])
+
+    def _get_version(self):
+        try:
+            return super(MakeDependency, self)._get_version()
+        except DependencyError as e:
+            version_options = self.version_options
+            self.version_options = ['-f', '-']
+            try:
+                stream = self._get_version_stream(stdin=self.makefile)
+                info = {}
+                for line in stream.splitlines():
+                    try:
+                        key,value = line.split('=', 1)
+                    except ValueError as ve:
+                        raise e# from NotImplementedError(stream)
+                    info[key] = value
+                if info.get('MAKE_VERSION', None):
+                    return info['MAKE_VERSION']
+                elif info.get('MAKE', None):
+                    return None
+                raise e
+            finally:
+                self.version_options = version_options
+
+
+CHECKER['make'] = MakeDependency(command='make', minimum_version=None)
+
+
 class EasyInstallDependency (CommandDependency):
     def _get_version(self):
         try: