Fixes "argument list too long" problem on Linux by using the "find" command instead of re-implementing one in python.

R=pbos@webrtc.org
TBR=andrew@webrtc.org
BUG=b/15773179

Review URL: https://webrtc-codereview.appspot.com/18929004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6782 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2014-07-25 18:36:55 +00:00
parent 1ebd2e96df
commit c7b8f39e2e

View File

@ -16,6 +16,7 @@ import os
import subprocess
import sys
IGNORE_PATTERNS = ['do_not_use', 'protoc']
def FindFiles(path, pattern):
"""Finds files matching |pattern| under |path|.
@ -35,9 +36,10 @@ def FindFiles(path, pattern):
files = []
for root, _, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, pattern):
if 'do_not_use' not in filename and 'protoc' not in filename:
# We use the relative path here to avoid "argument list too long"
# errors on Linux.
if filename not in IGNORE_PATTERNS:
# We use the relative path here to avoid "argument list too
# long" errors on Linux. Note: This doesn't always work, so
# we use the find command on Linux.
files.append(os.path.relpath(os.path.join(root, filename)))
return files
@ -58,23 +60,28 @@ def main(argv):
os.remove(output_lib)
if sys.platform.startswith('linux'):
objects = FindFiles(search_path, '*.o')
cmd = 'ar crs '
pattern = '*.o'
cmd = 'ar crs'
elif sys.platform == 'darwin':
objects = FindFiles(search_path, '*.a')
pattern = '*.a'
cmd = 'libtool -static -v -o '
elif sys.platform == 'win32':
objects = FindFiles(search_path, '*.lib')
pattern = '*.lib'
cmd = 'lib /OUT:'
else:
sys.stderr.write('Platform not supported: %r\n\n' % sys.platform)
return 1
cmd += output_lib + ' ' + ' '.join(objects)
if sys.platform.startswith('linux'):
cmd = ' '.join(['find', search_path, '-name "' + pattern + '"' +
' -and -not -name ' +
' -and -not -name '.join(IGNORE_PATTERNS) +
' -exec', cmd, output_lib, '{} +'])
else:
cmd = ' '.join([cmd, output_lib] + FindFiles(search_path, pattern))
print cmd
subprocess.check_call(cmd, shell=True)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))