Commits

Gary Oberbrunner committed fb3fa7f

rpm tool: get default rpm arch more robustly, from rpm itself.

Comments (9)

Files changed (2)

 
 RELEASE 2.3.2.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE
 
+  From Gary Oberbrunner:
+    - get default RPM architecture more robustly when building RPMs
+
   From Shane Gannon:
     - Support for Visual Studio 2013 (12.0)
 

src/engine/SCons/Tool/rpmutils.py

 They were directly derived from the file "rpmrc.in" of the version
 rpm-4.9.1.3. For updating to a more recent version of RPM, this Python
 script can be used standalone. The usage() function below shows the
-exact syntax. 
+exact syntax.
 
 """
 
 
 
 import platform
+import subprocess
 
 # Start of rpmrc dictionaries (Marker, don't change or remove!)
 os_canon = {
 
 # End of rpmrc dictionaries (Marker, don't change or remove!)
 
-def defaultMachine():
+def defaultMachine(use_rpm_default=True):
     """ Return the canonicalized machine name. """
-    rmachine = platform.machine()
-    
-    # Try to lookup the string in the canon table
-    if rmachine in arch_canon:
-        rmachine = arch_canon[rmachine][0]
-    
+
+    if use_rpm_default:
+        try:
+            # This should be the most reliable way to get the default arch
+            rmachine = subprocess.check_output(['rpm', '--eval=%_target_cpu'], shell=False).rstrip()
+        except Exception as e:
+            # Something went wrong, try again by looking up platform.machine()
+            return defaultMachine(False)
+    else:
+        rmachine = platform.machine()
+
+        # Try to lookup the string in the canon table
+        if rmachine in arch_canon:
+            rmachine = arch_canon[rmachine][0]
+
     return rmachine
 
 def defaultSystem():
     """ Return the canonicalized system name. """
     rsystem = platform.system()
-    
+
     # Try to lookup the string in the canon tables
     if rsystem in os_canon:
         rsystem = os_canon[rsystem][0]
 
 def main():
     import sys
-    
+
     if len(sys.argv) < 3:
         usage()
         sys.exit(0)