merge platform_helper into configure script
authorEvan Martin <martine@danga.com>
Tue, 18 Nov 2014 18:09:07 +0000 (10:09 -0800)
committerEvan Martin <martine@danga.com>
Tue, 18 Nov 2014 19:37:12 +0000 (11:37 -0800)
With this code all in one place, it's easier to spot unused code and
simplification opportunities.

configure.py
platform_helper.py [deleted file]

index b818bfc..524ffca 100755 (executable)
@@ -27,12 +27,75 @@ import pipes
 import string
 import subprocess
 import sys
-import platform_helper
-sys.path.insert(0, 'misc')
 
+sys.path.insert(0, 'misc')
 import ninja_syntax
 
 
+class Platform(object):
+    """Represents a host/target platform and its specific build attributes."""
+    def __init__(self, platform):
+        self._platform = platform
+        if self._platform is not None:
+            return
+        self._platform = sys.platform
+        if self._platform.startswith('linux'):
+            self._platform = 'linux'
+        elif self._platform.startswith('freebsd'):
+            self._platform = 'freebsd'
+        elif self._platform.startswith('gnukfreebsd'):
+            self._platform = 'freebsd'
+        elif self._platform.startswith('openbsd'):
+            self._platform = 'openbsd'
+        elif self._platform.startswith('solaris') or self._platform == 'sunos5':
+            self._platform = 'solaris'
+        elif self._platform.startswith('mingw'):
+            self._platform = 'mingw'
+        elif self._platform.startswith('win'):
+            self._platform = 'msvc'
+        elif self._platform.startswith('bitrig'):
+            self._platform = 'bitrig'
+        elif self._platform.startswith('netbsd'):
+            self._platform = 'netbsd'
+
+    @staticmethod
+    def known_platforms():
+      return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
+              'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd']
+
+    def platform(self):
+        return self._platform
+
+    def is_linux(self):
+        return self._platform == 'linux'
+
+    def is_mingw(self):
+        return self._platform == 'mingw'
+
+    def is_msvc(self):
+        return self._platform == 'msvc'
+
+    def msvc_needs_fs(self):
+        import subprocess
+        popen = subprocess.Popen(['cl', '/nologo', '/?'],
+                                 stdout=subprocess.PIPE,
+                                 stderr=subprocess.PIPE)
+        out, err = popen.communicate()
+        return '/FS ' in str(out)
+
+    def is_windows(self):
+        return self.is_mingw() or self.is_msvc()
+
+    def is_solaris(self):
+        return self._platform == 'solaris'
+
+    def uses_usr_local(self):
+        return self._platform in ('freebsd', 'openbsd', 'bitrig')
+
+    def supports_ppoll(self):
+        return self._platform in ('linux', 'openbsd', 'bitrig')
+
+
 class Bootstrap:
     """API shim for ninja_syntax.Writer that instead runs the commands.
 
@@ -110,12 +173,12 @@ parser.add_option('--bootstrap', action='store_true',
                   help='bootstrap a ninja binary from nothing')
 parser.add_option('--platform',
                   help='target platform (' +
-                       '/'.join(platform_helper.platforms()) + ')',
-                  choices=platform_helper.platforms())
+                       '/'.join(Platform.known_platforms()) + ')',
+                  choices=Platform.known_platforms())
 parser.add_option('--host',
                   help='host platform (' +
-                       '/'.join(platform_helper.platforms()) + ')',
-                  choices=platform_helper.platforms())
+                       '/'.join(Platform.known_platforms()) + ')',
+                  choices=Platform.known_platforms())
 parser.add_option('--debug', action='store_true',
                   help='enable debugging extras',)
 parser.add_option('--profile', metavar='TYPE',
@@ -133,9 +196,9 @@ if args:
     print('ERROR: extra unparsed command-line arguments:', args)
     sys.exit(1)
 
-platform = platform_helper.Platform(options.platform)
+platform = Platform(options.platform)
 if options.host:
-    host = platform_helper.Platform(options.host)
+    host = Platform(options.host)
 else:
     host = platform
 
@@ -250,6 +313,10 @@ else:
     if platform.is_mingw():
         cflags += ['-D_WIN32_WINNT=0x0501']
     ldflags = ['-L$builddir']
+    if platform.uses_usr_local():
+        cflags.append('-I/usr/local/include')
+        ldflags.append('-L/usr/local/lib')
+
 libs = []
 
 if platform.is_mingw():
@@ -267,8 +334,7 @@ else:
         cflags.append('-fno-omit-frame-pointer')
         libs.extend(['-Wl,--no-as-needed', '-lprofiler'])
 
-if (platform.is_linux() or platform.is_openbsd() or platform.is_bitrig()) and \
-        not options.force_pselect:
+if platform.supports_ppoll() and not options.force_pselect:
     cflags.append('-DUSE_PPOLL')
 
 have_browse = not platform.is_windows() and not platform.is_solaris()
diff --git a/platform_helper.py b/platform_helper.py
deleted file mode 100644 (file)
index 035a671..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2011 Google Inc.
-# Copyright 2013 Patrick von Reth <vonreth@kde.org>
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sys
-
-def platforms():
-    return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
-            'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd']
-
-class Platform(object):
-    def __init__(self, platform):
-        self._platform = platform
-        if not self._platform is None:
-            return
-        self._platform = sys.platform
-        if self._platform.startswith('linux'):
-            self._platform = 'linux'
-        elif self._platform.startswith('freebsd'):
-            self._platform = 'freebsd'
-        elif self._platform.startswith('gnukfreebsd'):
-            self._platform = 'freebsd'
-        elif self._platform.startswith('openbsd'):
-            self._platform = 'openbsd'
-        elif self._platform.startswith('solaris') or self._platform == 'sunos5':
-            self._platform = 'solaris'
-        elif self._platform.startswith('mingw'):
-            self._platform = 'mingw'
-        elif self._platform.startswith('win'):
-            self._platform = 'msvc'
-        elif self._platform.startswith('bitrig'):
-            self._platform = 'bitrig'
-        elif self._platform.startswith('netbsd'):
-            self._platform = 'netbsd'
-
-    def platform(self):
-        return self._platform
-
-    def is_linux(self):
-        return self._platform == 'linux'
-
-    def is_mingw(self):
-        return self._platform == 'mingw'
-
-    def is_msvc(self):
-        return self._platform == 'msvc'
-
-    def msvc_needs_fs(self):
-        import subprocess
-        popen = subprocess.Popen(['cl', '/nologo', '/?'],
-                                 stdout=subprocess.PIPE,
-                                 stderr=subprocess.PIPE)
-        out, err = popen.communicate()
-        return '/FS ' in str(out)
-
-    def is_windows(self):
-        return self.is_mingw() or self.is_msvc()
-
-    def is_solaris(self):
-        return self._platform == 'solaris'
-
-    def is_freebsd(self):
-        return self._platform == 'freebsd'
-
-    def is_openbsd(self):
-        return self._platform == 'openbsd'
-
-    def is_bitrig(self):
-        return self._platform == 'bitrig'
-
-    def is_netbsd(self):
-        return self._platform == 'netbsd'