Bug 719742 - Make expandlibs properly handle the case where OBJ_SUFFIX is .i_o on Linux PGO first pass. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 25 Jan 2012 10:34:14 +0100
changeset 85328 747d47aadb5997892fb3be8c462e361c48f89e5d
parent 85327 27583d9d31b4a1341207a44b24254cf69369b98b
child 85329 4034e454bfbbc10a85ea08ce3b16ff655d8030ed
push id21915
push userbmo@edmorley.co.uk
push dateWed, 25 Jan 2012 14:16:23 +0000
treeherdermozilla-central@0d5ad6a6f814 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs719742
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 719742 - Make expandlibs properly handle the case where OBJ_SUFFIX is .i_o on Linux PGO first pass. r=ted
config/expandlibs.py
config/expandlibs_exec.py
config/expandlibs_gen.py
js/src/config/expandlibs.py
js/src/config/expandlibs_exec.py
js/src/config/expandlibs_gen.py
--- a/config/expandlibs.py
+++ b/config/expandlibs.py
@@ -81,16 +81,21 @@ def relativize(path):
         del abspath[0]
     if not curdir and not abspath:
         return '.'
     relpath = os.path.join(*[os.pardir for i in curdir] + abspath)
     if len(path) > len(relpath):
         return relpath
     return path
 
+def isObject(path):
+    '''Returns whether the given path points to an object file, that is,
+    ends with OBJ_SUFFIX or .i_o'''
+    return os.path.splitext(path)[1] in [conf.OBJ_SUFFIX, '.i_o']
+
 class LibDescriptor(dict):
     KEYS = ['OBJS', 'LIBS']
 
     def __init__(self, content=None):
         '''Creates an instance of a lib descriptor, initialized with contents
         from a list of strings when given. This is intended for use with
         file.readlines()'''
         if isinstance(content, list) and all([isinstance(item, str) for item in content]):
--- a/config/expandlibs_exec.py
+++ b/config/expandlibs_exec.py
@@ -51,17 +51,17 @@ See https://bugzilla.mozilla.org/show_bu
 
 With the --reorder argument, followed by a file name, it will reorder the
 object files from the command line according to the order given in the file.
 Implies --extract.
 '''
 from __future__ import with_statement
 import sys
 import os
-from expandlibs import ExpandArgs, relativize
+from expandlibs import ExpandArgs, relativize, isObject
 import expandlibs_config as conf
 from optparse import OptionParser
 import subprocess
 import tempfile
 import shutil
 
 class ExpandArgsMore(ExpandArgs):
     ''' Meant to be used as 'with ExpandArgsMore(args) as ...: '''
@@ -92,29 +92,29 @@ class ExpandArgsMore(ExpandArgs):
                 if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                     newlist += self._extract(self._expand_desc(arg))
                 elif os.path.exists(arg) and len(ar_extract):
                     tmp = tempfile.mkdtemp(dir=os.curdir)
                     self.tmp.append(tmp)
                     subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
                     objs = []
                     for root, dirs, files in os.walk(tmp):
-                        objs += [relativize(os.path.join(root, f)) for f in files if os.path.splitext(f)[1] in [conf.OBJ_SUFFIX, '.i_o']]
+                        objs += [relativize(os.path.join(root, f)) for f in files if isObject(f)]
                     newlist += objs
                 else:
                     newlist += [arg]
             else:
                 newlist += [arg]
         return newlist
 
     def makelist(self):
         '''Replaces object file names with a temporary list file, using a
         list format depending on the EXPAND_LIBS_LIST_STYLE variable
         '''
-        objs = [o for o in self if os.path.splitext(o)[1] == conf.OBJ_SUFFIX]
+        objs = [o for o in self if isObject(o)]
         if not len(objs): return
         fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
         if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
             content = ["INPUT(%s)\n" % obj for obj in objs]
             ref = tmp
         elif conf.EXPAND_LIBS_LIST_STYLE == "list":
             content = ["%s\n" % obj for obj in objs]
             ref = "@" + tmp
@@ -129,25 +129,25 @@ class ExpandArgsMore(ExpandArgs):
         newlist = self[0:idx] + [ref] + [item for item in self[idx:] if item not in objs]
         self[0:] = newlist
 
     def reorder(self, order_list):
         '''Given a list of file names without OBJ_SUFFIX, rearrange self
         so that the object file names it contains are ordered according to
         that list.
         '''
-        objs = [o for o in self if o.endswith(conf.OBJ_SUFFIX)]
+        objs = [o for o in self if isObject(o)]
         if not objs: return
         idx = self.index(objs[0])
         # Keep everything before the first object, then the ordered objects,
         # then any other objects, then any non-objects after the first object
         objnames = dict([(os.path.splitext(os.path.basename(o))[0], o) for o in objs])
         self[0:] = self[0:idx] + [objnames[o] for o in order_list if o in objnames] + \
                    [o for o in objs if os.path.splitext(os.path.basename(o))[0] not in order_list] + \
-                   [x for x in self[idx:] if not x.endswith(conf.OBJ_SUFFIX)]
+                   [x for x in self[idx:] if not isObject(x)]
 
 
 def main():
     parser = OptionParser()
     parser.add_option("--extract", action="store_true", dest="extract",
         help="when a library has no descriptor file, extract it first, when possible")
     parser.add_option("--uselist", action="store_true", dest="uselist",
         help="use a list file for objects when executing a command")
--- a/config/expandlibs_gen.py
+++ b/config/expandlibs_gen.py
@@ -36,22 +36,22 @@
 # ***** END LICENSE BLOCK *****
 
 '''Given a list of object files and library names, prints a library
 descriptor to standard output'''
 
 import sys
 import os
 import expandlibs_config as conf
-from expandlibs import LibDescriptor
+from expandlibs import LibDescriptor, isObject
 
 def generate(args):
     desc = LibDescriptor()
     for arg in args:
-        if os.path.splitext(arg)[1] in [conf.OBJ_SUFFIX, '.i_o']:
+        if isObject(arg):
             desc['OBJS'].append(os.path.abspath(arg))
         elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX and \
              (os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX)):
             desc['LIBS'].append(os.path.abspath(arg))
     return desc
 
 if __name__ == '__main__':
     print generate(sys.argv[1:])
--- a/js/src/config/expandlibs.py
+++ b/js/src/config/expandlibs.py
@@ -81,16 +81,21 @@ def relativize(path):
         del abspath[0]
     if not curdir and not abspath:
         return '.'
     relpath = os.path.join(*[os.pardir for i in curdir] + abspath)
     if len(path) > len(relpath):
         return relpath
     return path
 
+def isObject(path):
+    '''Returns whether the given path points to an object file, that is,
+    ends with OBJ_SUFFIX or .i_o'''
+    return os.path.splitext(path)[1] in [conf.OBJ_SUFFIX, '.i_o']
+
 class LibDescriptor(dict):
     KEYS = ['OBJS', 'LIBS']
 
     def __init__(self, content=None):
         '''Creates an instance of a lib descriptor, initialized with contents
         from a list of strings when given. This is intended for use with
         file.readlines()'''
         if isinstance(content, list) and all([isinstance(item, str) for item in content]):
--- a/js/src/config/expandlibs_exec.py
+++ b/js/src/config/expandlibs_exec.py
@@ -51,17 +51,17 @@ See https://bugzilla.mozilla.org/show_bu
 
 With the --reorder argument, followed by a file name, it will reorder the
 object files from the command line according to the order given in the file.
 Implies --extract.
 '''
 from __future__ import with_statement
 import sys
 import os
-from expandlibs import ExpandArgs, relativize
+from expandlibs import ExpandArgs, relativize, isObject
 import expandlibs_config as conf
 from optparse import OptionParser
 import subprocess
 import tempfile
 import shutil
 
 class ExpandArgsMore(ExpandArgs):
     ''' Meant to be used as 'with ExpandArgsMore(args) as ...: '''
@@ -92,29 +92,29 @@ class ExpandArgsMore(ExpandArgs):
                 if os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
                     newlist += self._extract(self._expand_desc(arg))
                 elif os.path.exists(arg) and len(ar_extract):
                     tmp = tempfile.mkdtemp(dir=os.curdir)
                     self.tmp.append(tmp)
                     subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
                     objs = []
                     for root, dirs, files in os.walk(tmp):
-                        objs += [relativize(os.path.join(root, f)) for f in files if os.path.splitext(f)[1] in [conf.OBJ_SUFFIX, '.i_o']]
+                        objs += [relativize(os.path.join(root, f)) for f in files if isObject(f)]
                     newlist += objs
                 else:
                     newlist += [arg]
             else:
                 newlist += [arg]
         return newlist
 
     def makelist(self):
         '''Replaces object file names with a temporary list file, using a
         list format depending on the EXPAND_LIBS_LIST_STYLE variable
         '''
-        objs = [o for o in self if os.path.splitext(o)[1] == conf.OBJ_SUFFIX]
+        objs = [o for o in self if isObject(o)]
         if not len(objs): return
         fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
         if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
             content = ["INPUT(%s)\n" % obj for obj in objs]
             ref = tmp
         elif conf.EXPAND_LIBS_LIST_STYLE == "list":
             content = ["%s\n" % obj for obj in objs]
             ref = "@" + tmp
@@ -129,25 +129,25 @@ class ExpandArgsMore(ExpandArgs):
         newlist = self[0:idx] + [ref] + [item for item in self[idx:] if item not in objs]
         self[0:] = newlist
 
     def reorder(self, order_list):
         '''Given a list of file names without OBJ_SUFFIX, rearrange self
         so that the object file names it contains are ordered according to
         that list.
         '''
-        objs = [o for o in self if o.endswith(conf.OBJ_SUFFIX)]
+        objs = [o for o in self if isObject(o)]
         if not objs: return
         idx = self.index(objs[0])
         # Keep everything before the first object, then the ordered objects,
         # then any other objects, then any non-objects after the first object
         objnames = dict([(os.path.splitext(os.path.basename(o))[0], o) for o in objs])
         self[0:] = self[0:idx] + [objnames[o] for o in order_list if o in objnames] + \
                    [o for o in objs if os.path.splitext(os.path.basename(o))[0] not in order_list] + \
-                   [x for x in self[idx:] if not x.endswith(conf.OBJ_SUFFIX)]
+                   [x for x in self[idx:] if not isObject(x)]
 
 
 def main():
     parser = OptionParser()
     parser.add_option("--extract", action="store_true", dest="extract",
         help="when a library has no descriptor file, extract it first, when possible")
     parser.add_option("--uselist", action="store_true", dest="uselist",
         help="use a list file for objects when executing a command")
--- a/js/src/config/expandlibs_gen.py
+++ b/js/src/config/expandlibs_gen.py
@@ -36,22 +36,22 @@
 # ***** END LICENSE BLOCK *****
 
 '''Given a list of object files and library names, prints a library
 descriptor to standard output'''
 
 import sys
 import os
 import expandlibs_config as conf
-from expandlibs import LibDescriptor
+from expandlibs import LibDescriptor, isObject
 
 def generate(args):
     desc = LibDescriptor()
     for arg in args:
-        if os.path.splitext(arg)[1] in [conf.OBJ_SUFFIX, '.i_o']:
+        if isObject(arg):
             desc['OBJS'].append(os.path.abspath(arg))
         elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX and \
              (os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX)):
             desc['LIBS'].append(os.path.abspath(arg))
     return desc
 
 if __name__ == '__main__':
     print generate(sys.argv[1:])