Bug 603370 part 1 - Add an option to expandlibs-exec to allow to reorder the objects list. r=ted
This commit is contained in:
@@ -48,6 +48,10 @@ of a command line. The kind of list file format used depends on the
|
||||
EXPAND_LIBS_LIST_STYLE variable: 'list' for MSVC style lists (@file.list)
|
||||
or 'linkerscript' for GNU ld linker scripts.
|
||||
See https://bugzilla.mozilla.org/show_bug.cgi?id=584474#c59 for more details.
|
||||
|
||||
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
|
||||
@@ -125,6 +129,22 @@ 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)]
|
||||
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)]
|
||||
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
parser.add_option("--extract", action="store_true", dest="extract",
|
||||
@@ -133,12 +153,17 @@ def main():
|
||||
help="use a list file for objects when executing a command")
|
||||
parser.add_option("--verbose", action="store_true", dest="verbose",
|
||||
help="display executed command and temporary files content")
|
||||
parser.add_option("--reorder", dest="reorder",
|
||||
help="reorder the objects according to the given list", metavar="FILE")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
with ExpandArgsMore(args) as args:
|
||||
if options.extract:
|
||||
if options.extract or options.reorder:
|
||||
args.extract()
|
||||
if options.reorder:
|
||||
with open(options.reorder) as file:
|
||||
args.reorder([l.strip() for l in file.readlines()])
|
||||
if options.uselist:
|
||||
args.makelist()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user