Skip to content

Commit

Permalink
Bug 648407 - Support expandlibs_exec.py --extract on windows. r=ted
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Mar 17, 2013
1 parent 3a35c07 commit b8333c7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 31 deletions.
18 changes: 11 additions & 7 deletions config/expandlibs_exec.py
Expand Up @@ -70,18 +70,22 @@ def _extract(self, args):
if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
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):
continue
elif os.path.exists(arg) and (len(ar_extract) or conf.AR == 'lib'):
tmp = tempfile.mkdtemp(dir=os.curdir)
self.tmp.append(tmp)
subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
if conf.AR == 'lib':
out = subprocess.check_output([conf.AR, '-NOLOGO', '-LIST', arg])
for l in out.splitlines():
subprocess.call([conf.AR, '-NOLOGO', '-EXTRACT:%s' % l, os.path.abspath(arg)], cwd=tmp)
else:
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 isObject(f)]
newlist += objs
else:
newlist += [arg]
else:
newlist += [arg]
newlist += sorted(objs)
continue
newlist += [arg]
return newlist

def makelist(self):
Expand Down
66 changes: 49 additions & 17 deletions config/tests/unit-expandlibs.py
Expand Up @@ -10,6 +10,7 @@
from UserString import UserString
# Create a controlled configuration for use by expandlibs
config_win = {
'AR': 'lib',
'AR_EXTRACT': '',
'DLL_PREFIX': '',
'LIB_PREFIX': '',
Expand All @@ -21,6 +22,7 @@
'EXPAND_LIBS_LIST_STYLE': 'list',
}
config_unix = {
'AR': 'ar',
'AR_EXTRACT': 'ar -x',
'DLL_PREFIX': 'lib',
'LIB_PREFIX': 'lib',
Expand Down Expand Up @@ -250,17 +252,46 @@ def test_extract(self):
subprocess_call = subprocess.call
extracted = {}
def call(args, **kargs):
# The command called is always AR_EXTRACT
ar_extract = config.AR_EXTRACT.split()
self.assertRelEqual(args[:len(ar_extract)], ar_extract)
if config.AR == 'lib':
self.assertEqual(args[:2], [config.AR, '-NOLOGO'])
self.assertTrue(args[2].startswith('-EXTRACT:'))
extract = [args[2][len('-EXTRACT:'):]]
self.assertTrue(extract)
args = args[3:]
else:
# The command called is always AR_EXTRACT
ar_extract = config.AR_EXTRACT.split()
self.assertEqual(args[:len(ar_extract)], ar_extract)
args = args[len(ar_extract):]
# Remaining argument is always one library
self.assertRelEqual([os.path.splitext(arg)[1] for arg in args[len(ar_extract):]], [config.LIB_SUFFIX])
# Simulate AR_EXTRACT extracting one object file for the library
lib = os.path.splitext(os.path.basename(args[len(ar_extract)]))[0]
extracted[lib] = os.path.join(kargs['cwd'], "{0}".format(Obj(lib)))
self.touch([extracted[lib]])
self.assertEqual(len(args), 1)
arg = args[0]
self.assertEqual(os.path.splitext(arg)[1], config.LIB_SUFFIX)
# Simulate file extraction
lib = os.path.splitext(os.path.basename(arg))[0]
if config.AR != 'lib':
extract = [lib, lib + '2']
extract = [os.path.join(kargs['cwd'], f) for f in extract]
if config.AR != 'lib':
extract = [Obj(f) for f in extract]
if not lib in extracted:
extracted[lib] = []
extracted[lib].extend(extract)
self.touch(extract)
subprocess.call = call

def check_output(args, **kargs):
# The command called is always AR
ar = config.AR
self.assertEqual(args[0:3], [ar, '-NOLOGO', '-LIST'])
# Remaining argument is always one library
self.assertRelEqual([os.path.splitext(arg)[1] for arg in args[3:]],
[config.LIB_SUFFIX])
# Simulate LIB -NOLOGO -LIST
lib = os.path.splitext(os.path.basename(args[3]))[0]
return '%s\n%s\n' % (Obj(lib), Obj(lib + '2'))
subprocess.check_output = check_output

# ExpandArgsMore does the same as ExpandArgs
self.touch([self.tmpfile('liby', Lib('y'))])
with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
Expand All @@ -271,15 +302,16 @@ def call(args, **kargs):
args.extract()

files = self.files + self.liby_files + self.libx_files
if not len(config.AR_EXTRACT):
# If we don't have an AR_EXTRACT, extract() expands libraries with a
# descriptor when the corresponding library exists (which ExpandArgs
# alone doesn't)
self.assertRelEqual(args, ['foo', '-bar'] + files)
else:
# With AR_EXTRACT, it uses the descriptors when there are, and actually
# extracts the remaining libraries
self.assertRelEqual(args, ['foo', '-bar'] + [extracted[os.path.splitext(os.path.basename(f))[0]] if f.endswith(config.LIB_SUFFIX) else f for f in files])
# With AR_EXTRACT, it uses the descriptors when there are, and
# actually
# extracts the remaining libraries
extracted_args = []
for f in files:
if f.endswith(config.LIB_SUFFIX):
extracted_args.extend(sorted(extracted[os.path.splitext(os.path.basename(f))[0]]))
else:
extracted_args.append(f)
self.assertRelEqual(args, ['foo', '-bar'] + extracted_args)

tmp = args.tmp
# Check that all temporary files are properly removed
Expand Down
18 changes: 11 additions & 7 deletions js/src/config/expandlibs_exec.py
Expand Up @@ -70,18 +70,22 @@ def _extract(self, args):
if os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
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):
continue
elif os.path.exists(arg) and (len(ar_extract) or conf.AR == 'lib'):
tmp = tempfile.mkdtemp(dir=os.curdir)
self.tmp.append(tmp)
subprocess.call(ar_extract + [os.path.abspath(arg)], cwd=tmp)
if conf.AR == 'lib':
out = subprocess.check_output([conf.AR, '-NOLOGO', '-LIST', arg])
for l in out.splitlines():
subprocess.call([conf.AR, '-NOLOGO', '-EXTRACT:%s' % l, os.path.abspath(arg)], cwd=tmp)
else:
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 isObject(f)]
newlist += objs
else:
newlist += [arg]
else:
newlist += [arg]
newlist += sorted(objs)
continue
newlist += [arg]
return newlist

def makelist(self):
Expand Down

0 comments on commit b8333c7

Please sign in to comment.