[cfe-commits] r62011 - in /cfe/trunk/tools/ccc/ccclib: Driver.py HostInfo.py Tools.py

Daniel Dunbar daniel at zuster.org
Fri Jan 9 14:21:24 PST 2009


Author: ddunbar
Date: Fri Jan  9 16:21:24 2009
New Revision: 62011

URL: http://llvm.org/viewvc/llvm-project?rev=62011&view=rev
Log:
ccc: Get host information via Driver methods.

Modified:
    cfe/trunk/tools/ccc/ccclib/Driver.py
    cfe/trunk/tools/ccc/ccclib/HostInfo.py
    cfe/trunk/tools/ccc/ccclib/Tools.py

Modified: cfe/trunk/tools/ccc/ccclib/Driver.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/Driver.py?rev=62011&r1=62010&r2=62011&view=diff

==============================================================================
--- cfe/trunk/tools/ccc/ccclib/Driver.py (original)
+++ cfe/trunk/tools/ccc/ccclib/Driver.py Fri Jan  9 16:21:24 2009
@@ -30,6 +30,36 @@
         self.hostInfo = None
         self.parser = Arguments.OptionParser()
 
+    # Host queries which can be forcibly over-riden by the user for
+    # testing purposes.
+    #
+    # FIXME: We should make sure these are drawn from a fixed set so
+    # that nothing downstream ever plays a guessing game.
+
+    def getHostBits(self):
+        if self.cccHostBits:
+            return self.cccHostBits
+        
+        return platform.architecture()[0].replace('bit','')
+
+    def getHostMachine(self):
+        if self.cccHostMachine:
+            return self.cccHostMachine
+
+        machine = platform.machine()
+        # Normalize names.
+        if machine == 'Power Macintosh':
+            return 'ppc'
+        return machine
+
+    def getHostSystemName(self):
+        if self.cccHostSystem:
+            return self.cccHostSystem
+        
+        return platform.system().lower()
+
+    ###
+
     def run(self, argv):
         # FIXME: Things to support from environment: GCC_EXEC_PREFIX,
         # COMPILER_PATH, LIBRARY_PATH, LPATH, CC_PRINT_OPTIONS,
@@ -41,7 +71,10 @@
         # only allowed at the beginning of the command line.
         cccPrintOptions = False
         cccPrintPhases = False
-        cccHostBits = cccHostMachine = cccHostSystem = None
+
+        # FIXME: How to handle override of host? ccc specific options?
+        # Abuse -b?
+        self.cccHostBits = self.cccHostMachine = self.cccHostSystem = None
         while argv and argv[0].startswith('-ccc-'):
             opt,argv = argv[0][5:],argv[1:]
 
@@ -50,21 +83,15 @@
             elif opt == 'print-phases':
                 cccPrintPhases = True
             elif opt == 'host-bits':
-                cccHostBits,argv = argv[0],argv[1:]
+                self.cccHostBits,argv = argv[0],argv[1:]
             elif opt == 'host-machine':
-                cccHostMachine,argv = argv[0],argv[1:]
+                self.cccHostMachine,argv = argv[0],argv[1:]
             elif opt == 'host-system':
-                cccHostSystem,argv = argv[0],argv[1:]
+                self.cccHostSystem,argv = argv[0],argv[1:]
             else:
                 raise ValueError,"Invalid ccc option: %r" % cccPrintOptions
 
-        # FIXME: How to handle override of host? ccc specific options?
-        # Abuse -b?
-        hostBits = cccHostBits or platform.architecture()[0].replace('bit','')
-        hostMachine = cccHostMachine or platform.machine()
-        hostSystem = cccHostSystem or platform.system().lower()
-        self.hostInfo = HostInfo.getHostInfo(self, 
-                                             hostSystem, hostMachine, hostBits)
+        self.hostInfo = HostInfo.getHostInfo(self)
         
         args = self.parser.parseArgs(argv)
 

Modified: cfe/trunk/tools/ccc/ccclib/HostInfo.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/HostInfo.py?rev=62011&r1=62010&r2=62011&view=diff

==============================================================================
--- cfe/trunk/tools/ccc/ccclib/HostInfo.py (original)
+++ cfe/trunk/tools/ccc/ccclib/HostInfo.py Fri Jan  9 16:21:24 2009
@@ -34,7 +34,9 @@
     def getArchName(self):
         return 'x86_64'
 
-def getDarwinHostInfo(machine, bits):
+def getDarwinHostInfo(driver):
+    machine = driver.getHostMachine()
+    bits = driver.getHostBits()
     if machine == 'i386':
         if bits == '32':
             return DarwinX86HostInfo()
@@ -46,7 +48,7 @@
         if bits == '64':
             return DarwinPPC_64HostInfo()
             
-    raise RuntimeError,'Unrecognized Darwin-i386 platform: %r:%r' % (machine, bits)
+    raise RuntimeError,'Unrecognized Darwin platform: %r:%r' % (machine, bits)
 
 # Unknown
 
@@ -57,7 +59,7 @@
     def useDriverDriver(self):
         return False
 
-def getUnknownHostInfo(machine, bits):
+def getUnknownHostInfo(driver):
     return UnknownHostInfo()
 
 ####
@@ -67,10 +69,11 @@
     'unknown' : getUnknownHostInfo,
     }
 
-def getHostInfo(driver, system, machine, bits):
+def getHostInfo(driver):
+    system = driver.getHostSystemName()
     handler = kSystems.get(system)
     if handler:
-        return handler(machine, bits)
+        return handler(driver)
 
     driver.warning('Unknown host %r, using generic host information.' % system)
     return UnknownHostInfo()

Modified: cfe/trunk/tools/ccc/ccclib/Tools.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/ccc/ccclib/Tools.py?rev=62011&r1=62010&r2=62011&view=diff

==============================================================================
--- cfe/trunk/tools/ccc/ccclib/Tools.py (original)
+++ cfe/trunk/tools/ccc/ccclib/Tools.py Fri Jan  9 16:21:24 2009
@@ -117,9 +117,8 @@
 
         cmd_args = []
         for arg in args:
-            if arg.opt:
-                if arg.opt.name in ('-framework',):
-                    cmd_args.extend(arglist.render(arg))
+            if arg.opt.name in ('-framework',):
+                cmd_args.extend(arglist.render(arg))
         for input in inputs:
             cmd_args.append(arglist.getValue(input.source))
         cmd_args.extend(arglist.render(output))





More information about the cfe-commits mailing list