diff options
author | sbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-28 22:54:08 +0000 |
---|---|---|
committer | sbc@chromium.org <sbc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-28 22:54:08 +0000 |
commit | a1f2799a8a17c94b4cb06b2512dfcecf549be523 (patch) | |
tree | 2181d497af8c6a4c2a2d988896c0d7bab5a2bb5f /native_client_sdk/src/tools/fix_deps.py | |
parent | bba9e63bdb8de860a20f2979c49cb814552d3ee3 (diff) | |
download | chromium_src-a1f2799a8a17c94b4cb06b2512dfcecf549be523.zip chromium_src-a1f2799a8a17c94b4cb06b2512dfcecf549be523.tar.gz chromium_src-a1f2799a8a17c94b4cb06b2512dfcecf549be523.tar.bz2 |
[NaCl SDK] Fixup GCC-generated .d files (second attempt)
The change adds a script that will post-procress
gcc-generated .d files such that they do not have
file-not-found issue when headers are removed or
renamed.
Also, fix an issue in common.mk where it was checking
for IGNORE_DEPS incorrectly. This was causing dependencies
to always be built which was leading to duplicate builds
of the same project causing race conditions in the build
system.
R=binji@chromium.org
BUG=None
Review URL: https://codereview.chromium.org/17769006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/tools/fix_deps.py')
-rwxr-xr-x | native_client_sdk/src/tools/fix_deps.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/native_client_sdk/src/tools/fix_deps.py b/native_client_sdk/src/tools/fix_deps.py new file mode 100755 index 0000000..a10feac --- /dev/null +++ b/native_client_sdk/src/tools/fix_deps.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Fixup GCC-generated dependency files. + +Modify GCC generated dependency files in-place so they are more suitable +for including in a GNU Makefile. Without the fixups, deleting or renaming +headers can cause the build to be broken. See: +http://mad-scientist.net/make/autodep.html for more details of the problem. +""" + +import os +import optparse +import sys + +TAG_LINE = '# Updated by fix_deps.py\n' + + +class Error(Exception): + pass + + +def ParseLine(line, new_target): + """Parse one line of a GCC-generated deps file. + + Each line contains an optional target and then a list + of space seperated dependencies. Spaces within filenames + are escaped with a backslash. + """ + filenames = [] + + if new_target and ':' in line: + line = line.split(':', 1)[1] + + line = line.strip() + line = line.rstrip('\\') + + while True: + # Find the next non-escaped space + line = line.strip() + pos = line.find(' ') + while pos > 0 and line[pos-1] == '\\': + pos = line.find(' ', pos+1) + + if pos == -1: + filenames.append(line) + break + filenames.append(line[:pos]) + line = line[pos+1:] + + return filenames + + +def FixupDepFile(filename): + if not os.path.exists(filename): + raise Error('File not found: %s' % filename) + + outlines = [TAG_LINE] + deps = [] + new_target = True + with open(filename) as infile: + for line in infile: + if line == TAG_LINE: + raise Error('Already processed: %s' % filename) + outlines.append(line) + deps += ParseLine(line, new_target) + new_target = line.endswith('\\') + + # For every depenency found output a dummy target with no rules + for dep in deps: + outlines.append('%s:\n' % dep) + + with open(filename, 'w') as outfile: + for line in outlines: + outfile.write(line) + + +def main(argv): + usage = "usage: %prog [options] <dep_file ...>" + parser = optparse.OptionParser(usage=usage, description=__doc__) + args = parser.parse_args(argv)[1] + if not args: + raise parser.error('expected one or more files as arguments') + for arg in args: + FixupDepFile(arg) + + +if __name__ == '__main__': + try: + sys.exit(main(sys.argv[1:])) + except Error as e: + sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) + sys.exit(1) |