OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A helper script for setting up forwarding headers.""" | 6 """A helper script for setting up forwarding headers.""" |
7 | 7 |
8 import errno | 8 import errno |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 out_filename = NormalizePath(out_filename) | 96 out_filename = NormalizePath(out_filename) |
97 ancestor = os.path.commonprefix([input_filename, out_filename]) | 97 ancestor = os.path.commonprefix([input_filename, out_filename]) |
98 | 98 |
99 assert os.path.isdir(ancestor) | 99 assert os.path.isdir(ancestor) |
100 num_parent_dirs = 0 | 100 num_parent_dirs = 0 |
101 out_dir = os.path.split(out_filename)[0] | 101 out_dir = os.path.split(out_filename)[0] |
102 while os.path.normpath(ancestor) != os.path.normpath(out_dir): | 102 while os.path.normpath(ancestor) != os.path.normpath(out_dir): |
103 num_parent_dirs += 1 | 103 num_parent_dirs += 1 |
104 out_dir = os.path.split(out_dir)[0] | 104 out_dir = os.path.split(out_dir)[0] |
105 | 105 |
106 rel_path = os.path.join('/'.join(['..'] * num_parent_dirs), | 106 if sys.platform == 'win32': |
107 input_filename[len(ancestor):]) | 107 # Windows has a file path limit of 260 characters that we can hit when |
M-A Ruel
2011/12/15 01:19:37
Why not do the same on all platforms?
| |
108 # generating these forwarding headers. Instead of writing the full | |
109 # relative path, just write the path relative to the WebKit/chromium dir, | |
110 # which is in the include path. | |
111 rel_path = input_filename[len(ancestor):] | |
112 else: | |
113 rel_path = os.path.join('/'.join(['..'] * num_parent_dirs), | |
114 input_filename[len(ancestor):]) | |
108 | 115 |
109 out_file = open(out_filename, 'w') | 116 out_file = open(out_filename, 'w') |
110 out_file.write("""// This file is generated. Do not edit. | 117 out_file.write("""// This file is generated. Do not edit. |
111 #include "%s" | 118 #include "%s" |
112 """ % rel_path) | 119 """ % rel_path) |
113 out_file.close() | 120 out_file.close() |
114 | 121 |
115 | 122 |
116 def Main(argv): | 123 def Main(argv): |
117 commands = { | 124 commands = { |
118 'inputs': Inputs, | 125 'inputs': Inputs, |
119 'outputs': Outputs, | 126 'outputs': Outputs, |
120 'setup_headers': SetupHeaders, | 127 'setup_headers': SetupHeaders, |
121 } | 128 } |
122 command = argv[1] | 129 command = argv[1] |
123 args = argv[2:] | 130 args = argv[2:] |
124 return commands[command](args) | 131 return commands[command](args) |
125 | 132 |
126 | 133 |
127 if __name__ == '__main__': | 134 if __name__ == '__main__': |
128 sys.exit(Main(sys.argv)) | 135 sys.exit(Main(sys.argv)) |
OLD | NEW |