Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # This script will add include paths to many include directives in
- # webkit so that include paths can be removed from the compiler
- # command. Note, it will not generate a working build. A lot of
- # handfixing is necessary to fix it.
- # TODO:
- # Make it work.
- # Fix .. and maybe ../.. so they're relative the right directory for each file.
- # Fix platform dependant includes.
- # And more
- import os.path
- import re
- from glob import glob
- '''A map of file names pointing to the array of directories in which they were found'''
- files_map = {
- }
- INCLUDE_RE = re.compile(r'#include\s+["<"]([^">]+)[">]')
- SOURCE_EXTENSION_RE = re.compile(r'\.(cpp|h)')
- # Include paths ripped out from third_party/WebKit/Source/WebCore/WebCore.gyp/WebCore.gyp
- INCLUDE_PATHS = [
- '../',
- '../..',
- '../Modules/battery',
- '../Modules/filesystem',
- '../Modules/filesystem/chromium',
- '../Modules/gamepad',
- '../Modules/geolocation',
- '../Modules/intents',
- '../Modules/indexeddb',
- '../Modules/indexeddb/chromium',
- '../Modules/mediasource',
- '../Modules/mediastream',
- '../Modules/navigatorcontentutils',
- '../Modules/notifications',
- '../Modules/proximity',
- '../Modules/quota',
- '../Modules/speech',
- '../Modules/webaudio',
- '../Modules/webdatabase',
- '../Modules/webdatabase/chromium',
- '../Modules/websockets',
- '../accessibility',
- '../accessibility/chromium',
- '../bindings',
- '../bindings/generic',
- '../bindings/v8',
- '../bindings/v8/custom',
- '../bridge',
- '../bridge/jni',
- '../bridge/jni/v8',
- '../css',
- '../dom',
- '../dom/default',
- '../editing',
- '../fileapi',
- '../history',
- '../html',
- '../html/canvas',
- '../html/parser',
- '../html/shadow',
- '../html/track',
- '../inspector',
- '../loader',
- '../loader/appcache',
- '../loader/archive',
- '../loader/archive/cf',
- '../loader/archive/mhtml',
- '../loader/cache',
- '../loader/icon',
- '../mathml',
- '../page',
- '../page/animation',
- '../page/chromium',
- '../page/scrolling',
- '../page/scrolling/chromium',
- '../platform',
- '../platform/animation',
- '../platform/audio',
- '../platform/audio/chromium',
- '../platform/chromium',
- '../platform/chromium/support',
- '../platform/graphics',
- '../platform/graphics/chromium',
- '../platform/graphics/chromium/cc',
- '../platform/graphics/cpu/arm',
- '../platform/graphics/cpu/arm/filters',
- '../platform/graphics/filters',
- '../platform/graphics/filters/skia',
- '../platform/graphics/gpu',
- '../platform/graphics/opentype',
- '../platform/graphics/skia',
- '../platform/graphics/transforms',
- '../platform/image-decoders',
- '../platform/image-decoders/bmp',
- '../platform/image-decoders/gif',
- '../platform/image-decoders/ico',
- '../platform/image-decoders/jpeg',
- '../platform/image-decoders/png',
- '../platform/image-decoders/skia',
- '../platform/image-decoders/webp',
- '../platform/image-encoders/skia',
- '../platform/leveldb',
- '../platform/mediastream',
- '../platform/mediastream/chromium',
- '../platform/mock',
- '../platform/network',
- '../platform/network/chromium',
- '../platform/sql',
- '../platform/text',
- '../platform/text/transcoder',
- '../plugins',
- '../plugins/chromium',
- '../rendering',
- '../rendering/mathml',
- '../rendering/style',
- '../rendering/svg',
- '../storage',
- '../svg',
- '../svg/animation',
- '../svg/graphics',
- '../svg/graphics/filters',
- '../svg/properties',
- '../../ThirdParty/glu',
- '../workers',
- '../workers/chromium',
- '../xml',
- '../xml/parser',
- # os==mac
- '../platform/audio/mac',
- '../platform/cocoa',
- '../platform/graphics/cg',
- '../platform/graphics/cocoa',
- '../platform/graphics/mac',
- '../platform/mac',
- '../platform/text/mac',
- '../platform/graphics/harfbuzz',
- '../platform/graphics/harfbuzz/ng',
- # os==win
- '../page/win',
- '../platform/audio/win',
- '../platform/graphics/win',
- '../platform/text/win',
- '../platform/win',
- # os==x11 or android or linux_embedded
- '../platform/graphics/harfbuzz',
- '../platform/graphics/harfbuzz/ng',
- ]
- def generate_filename_to_dirpath_map():
- for inc_path in INCLUDE_PATHS:
- headers = glob(inc_path + '/*.h')
- for header in headers:
- filename = os.path.basename(header)
- dirpath = os.path.dirname(os.path.relpath(header, '../..')).replace('\\', '/')
- if filename in files_map:
- files_map[filename].append(dirpath)
- else:
- files_map[filename] = [dirpath]
- def lookup_filename_in_map(filename, dirpath):
- if filename in files_map:
- # If the included file is in the same directory then don't change include
- # path. Mostly done due to copying of some files from
- # third_party/WebKit/Source/WebCore/platform/graphics/ into
- # global_intermediate directory where that would cause problems.
- if dirpath in files_map[filename]:
- return filename
- else:
- return files_map[filename][0] + '/' + filename
- else:
- return filename
- def replace_includes(dirpath, contents):
- '''Normalizes include paths in contents'''
- results = []
- for m in INCLUDE_RE.finditer(contents):
- results.append([m.group(1), m.start(1)])
- if not len(results):
- return None
- string_list = []
- current_offset = 0
- for (name, offset) in results:
- string_list.append(contents[current_offset:offset])
- string_list.append(lookup_filename_in_map(name, dirpath))
- current_offset = offset + len(name)
- if current_offset < len(contents):
- string_list.append(contents[current_offset:])
- return ''.join(string_list)
- if __name__ == '__main__':
- generate_filename_to_dirpath_map()
- # A path to the directory in which source files will be modified recursively.
- scanned_dir = '../..'
- # A path to the directory which will be used as a root
- # for modified #include paths. Relative to this script.
- include_root = '../..'
- for dirpath, dirnames, filenames in os.walk(scanned_dir):
- for fname in filenames:
- if SOURCE_EXTENSION_RE.search(fname):
- with open(os.path.join(dirpath, fname), 'r+U') as f:
- contents = replace_includes(os.path.relpath(dirpath, include_root), f.read())
- if contents is not None:
- f.truncate(0)
- f.seek(0)
- f.write(contents)
- print "Modified %s" % fname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement