diff options
author | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 00:56:56 +0000 |
---|---|---|
committer | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 00:56:56 +0000 |
commit | 0e36041499e26100bdcf3bc93c7f41364591f74e (patch) | |
tree | 6766e1b09740c5a61651f7c4715ed5f3e14555e9 /webkit | |
parent | 89988c3da97b719bcb566b7e4f808ba1a87b8644 (diff) | |
download | chromium_src-0e36041499e26100bdcf3bc93c7f41364591f74e.zip chromium_src-0e36041499e26100bdcf3bc93c7f41364591f74e.tar.gz chromium_src-0e36041499e26100bdcf3bc93c7f41364591f74e.tar.bz2 |
fix third_party_headers to work properly on Windows w/ ninja.
The setup_third_party.py script was hand-rolling an implementation of
os.path.relpath in order to be 2.5 compatible, and that was getting
confused when we had to generate forwarding headers from ninja's
intermediate directory.
This patch reworks the python code to use relpath (since we require 2.6 now)
and work the same way regardless of platform or headers being generated, so
that we can have a single code path.
Full details in the bug.
R=tony@chromium.org
BUG=175273
Review URL: https://codereview.chromium.org/12224087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/support/setup_third_party.gyp | 14 | ||||
-rwxr-xr-x | webkit/support/setup_third_party.py | 101 |
2 files changed, 56 insertions, 59 deletions
diff --git a/webkit/support/setup_third_party.gyp b/webkit/support/setup_third_party.gyp index 7fc15ac..bda14c2 100644 --- a/webkit/support/setup_third_party.gyp +++ b/webkit/support/setup_third_party.gyp @@ -11,11 +11,23 @@ }, 'targets': [ { + # This target is only invoked when we are building chromium inside + # of a WebKit checkout. In this case, we will have chromium files + # that include WebKit headers via third_party/WebKit/Source/... ; + # that directory doesn't exist in a chromium-inside-webkit + # checkout, and so we need to create sets of forwarding headers. + # + # In addition, we can hit limits on the include paths on windows + # with a regular forwarding header due to the deep directory + # hierarchies, and so rather than using #includes that are relative + # to the directory containing the generated header, the generated files + # use #includes that are relative to <(DEPTH). 'target_name': 'third_party_headers', 'type': 'none', 'direct_dependent_settings': { 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)/webkit', + '<(DEPTH)', ], }, 'actions': [ @@ -33,6 +45,7 @@ 'setup_headers', '<(DEPTH)/public', '<(webkit_client_api_dest)', + '<(DEPTH)', ], 'message': 'Generating forwarding headers for third_party/WebKit/Source/WebKit/chromium/public', }, @@ -72,6 +85,7 @@ 'setup_headers', '<(DEPTH)/../mac/WebCoreSupport', '<(mac_webcoresupport_dest)', + '<(DEPTH)', ], 'message': 'Generating forwarding headers for third_party/WebKit/Source/WebKit/mac/WebCoreSupport', }, diff --git a/webkit/support/setup_third_party.py b/webkit/support/setup_third_party.py index 50c7cc2..0f4099d 100755 --- a/webkit/support/setup_third_party.py +++ b/webkit/support/setup_third_party.py @@ -11,16 +11,29 @@ import sys def GetHeaderFilesInDir(dir_path): - """Return a list of all header files in dir_path.""" + """Return a list of all header files under dir_path + (as absolute native paths).""" all_files = [] for root, dirs, files in os.walk(dir_path): - # Backslashes get shell escaped by gyp, so force forward slash for - # path separators. - all_files.extend([os.path.join(root, f).replace(os.sep, '/') - for f in files if f.endswith('.h')]) + all_files.extend([os.path.join(root, f) for f in files if f.endswith('.h')]) return all_files +def PathForInclude(path): + # We should always use unix-style forward slashes in #includes. + return path.replace(os.sep, '/') + + +def NativePath(path): + return path.replace('/', os.sep) + + +def PathForGyp(path): + # GYP will try to shell-escape backslashes, so we should always + # return unix-style paths with forward slashes as the directory separators. + return path.replace(os.sep, '/') + + def Inputs(args): """List the files in the provided input dir. @@ -31,7 +44,7 @@ def Inputs(args): return -1 for filename in GetHeaderFilesInDir(args[0]): - print filename + print PathForGyp(filename) return 0 @@ -45,37 +58,34 @@ def Outputs(args): print "'outputs' expects an input directory and an output directory." return -1 - base_input_dir = args[0] - output_dir = args[1] + base_input_dir = NativePath(args[0]) + output_dir = NativePath(args[1]) input_files = GetHeaderFilesInDir(base_input_dir) for filename in input_files: - rel_path = filename[len(base_input_dir) + 1:] - # Backslashes get shell escaped by gyp, so force forward slash for - # path separators. - print os.path.join(output_dir, rel_path).replace(os.sep, '/') + rel_path = os.path.relpath(filename, base_input_dir) + print PathForGyp(os.path.join(output_dir, rel_path)) def SetupHeaders(args): """Takes an input dir and an output dir and sets up forwarding headers from output dir to files in input dir. - args: A list with 2 values, the input dir and the output dir. + args: A list with 3 values, the input dir, the output dir, and the dir + that #include paths will be relative to.. Returns: 0 on success, other value on error.""" - if len(args) != 2 and len(args) != 3: + if len(args) != 3: print ("'setup_headers' expects an input directory, an output directory, ." - "and an optional directory to make includes relative to.") + "and a directory to make includes relative to.") return -1 - base_input_dir = args[0] - output_dir = args[1] - relative_to_dir = None - if len(args) == 3: - relative_to_dir = args[2] + base_input_dir = NativePath(args[0]) + output_dir = NativePath(args[1]) + relative_to_dir = NativePath(args[2]) input_files = GetHeaderFilesInDir(base_input_dir) for input_filename in input_files: - rel_path = input_filename[len(base_input_dir) + 1:] + rel_path = os.path.relpath(input_filename, base_input_dir) out_filename = os.path.join(output_dir, rel_path) TryToMakeDir(os.path.split(out_filename)[0]) - WriteSetupFilename(input_filename, out_filename, relative_to_dir) + WriteForwardingHeader(input_filename, out_filename, relative_to_dir) def TryToMakeDir(dir_name): @@ -87,47 +97,20 @@ def TryToMakeDir(dir_name): raise e -def NormalizePath(path): - """Normalize path for use with os.path.commonprefix. - On windows, this makes sure that the drive letters are always in the - same case.""" - abs_path = os.path.abspath(path) - drive, rest = os.path.splitdrive(abs_path) - return os.path.join(drive.lower(), rest) - - -def WriteSetupFilename(input_filename, out_filename, relative_to_dir): +def WriteForwardingHeader(input_filename, out_filename, relative_to_dir): """Create a forwarding header from out_filename to input_filename.""" - # Figure out the relative path from out_filename to input_filename. - # We can't use os.path.relpath since that's a python2.6 feature and we - # support python 2.5. - input_filename = NormalizePath(input_filename) - out_filename = NormalizePath(out_filename) - ancestor = os.path.commonprefix([input_filename, out_filename]) - - assert os.path.isdir(ancestor) - num_parent_dirs = 0 - out_dir = os.path.split(out_filename)[0] - while os.path.normpath(ancestor) != os.path.normpath(out_dir): - num_parent_dirs += 1 - out_dir = os.path.split(out_dir)[0] - - if sys.platform == 'win32': - # Windows has a file path limit of 260 characters that we can hit when - # generating these forwarding headers. Instead of writing the full - # relative path, just write the path relative to the WebKit/chromium dir, - # which is in the include path. - rel_path = input_filename[len(ancestor):] - if relative_to_dir: - rel_path = os.path.join(relative_to_dir, rel_path) - else: - rel_path = os.path.join('/'.join(['..'] * num_parent_dirs), - input_filename[len(ancestor):]) - + # Windows has a file path limit of 260 characters, which can be hit when + # generating these forwarding headers. Instead of using an include + # that specifies the path relative to out_filename's dir, we compute a path + # relative to relative_to_dir, which must be included in gyp's include_dirs + # settings for this to work. Even those this is really only needed on + # Windows, we do this on all platforms to be consistent. + rel_path = os.path.relpath(input_filename, relative_to_dir) out_file = open(out_filename, 'w') out_file.write("""// This file is generated. Do not edit. +// The include is relative to "%s". #include "%s" -""" % rel_path) +""" % (os.path.abspath(relative_to_dir), PathForInclude(rel_path))) out_file.close() |