Loading config/expandlibs_exec.py +11 −7 Original line number Diff line number Diff line Loading @@ -70,17 +70,21 @@ class ExpandArgsMore(ExpandArgs): 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) 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 += sorted(objs) continue newlist += [arg] return newlist Loading config/tests/unit-expandlibs.py +49 −17 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ import mozunit from UserString import UserString # Create a controlled configuration for use by expandlibs config_win = { 'AR': 'lib', 'AR_EXTRACT': '', 'DLL_PREFIX': '', 'LIB_PREFIX': '', Loading @@ -21,6 +22,7 @@ config_win = { 'EXPAND_LIBS_LIST_STYLE': 'list', } config_unix = { 'AR': 'ar', 'AR_EXTRACT': 'ar -x', 'DLL_PREFIX': 'lib', 'LIB_PREFIX': 'lib', Loading Loading @@ -250,17 +252,46 @@ class TestExpandArgsMore(TestExpandInit): subprocess_call = subprocess.call extracted = {} def call(args, **kargs): 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.assertRelEqual(args[:len(ar_extract)], ar_extract) 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: Loading @@ -271,15 +302,16 @@ class TestExpandArgsMore(TestExpandInit): 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 # 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]) 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 Loading js/src/config/expandlibs_exec.py +11 −7 Original line number Diff line number Diff line Loading @@ -70,17 +70,21 @@ class ExpandArgsMore(ExpandArgs): 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) 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 += sorted(objs) continue newlist += [arg] return newlist Loading Loading
config/expandlibs_exec.py +11 −7 Original line number Diff line number Diff line Loading @@ -70,17 +70,21 @@ class ExpandArgsMore(ExpandArgs): 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) 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 += sorted(objs) continue newlist += [arg] return newlist Loading
config/tests/unit-expandlibs.py +49 −17 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ import mozunit from UserString import UserString # Create a controlled configuration for use by expandlibs config_win = { 'AR': 'lib', 'AR_EXTRACT': '', 'DLL_PREFIX': '', 'LIB_PREFIX': '', Loading @@ -21,6 +22,7 @@ config_win = { 'EXPAND_LIBS_LIST_STYLE': 'list', } config_unix = { 'AR': 'ar', 'AR_EXTRACT': 'ar -x', 'DLL_PREFIX': 'lib', 'LIB_PREFIX': 'lib', Loading Loading @@ -250,17 +252,46 @@ class TestExpandArgsMore(TestExpandInit): subprocess_call = subprocess.call extracted = {} def call(args, **kargs): 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.assertRelEqual(args[:len(ar_extract)], ar_extract) 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: Loading @@ -271,15 +302,16 @@ class TestExpandArgsMore(TestExpandInit): 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 # 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]) 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 Loading
js/src/config/expandlibs_exec.py +11 −7 Original line number Diff line number Diff line Loading @@ -70,17 +70,21 @@ class ExpandArgsMore(ExpandArgs): 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) 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 += sorted(objs) continue newlist += [arg] return newlist Loading