Skip to content

Commit

Permalink
Fixes "argument list too long" problem on Linux by using the "find" c…
Browse files Browse the repository at this point in the history
…ommand 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
  • Loading branch information
henrike@webrtc.org committed Jul 25, 2014
1 parent 1ebd2e9 commit c7b8f39
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions webrtc/build/merge_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import subprocess
import sys

IGNORE_PATTERNS = ['do_not_use', 'protoc']

def FindFiles(path, pattern):
"""Finds files matching |pattern| under |path|.
Expand All @@ -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

Expand All @@ -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))

0 comments on commit c7b8f39

Please sign in to comment.