OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 # This script helps workaround IncrediBuild problem on Windows. | |
7 # See http://crbug.com/17706. | |
8 | |
9 import os | |
10 import sys | |
11 | |
12 _SRC_PATH = os.path.join(os.path.dirname(__file__), '..', '..') | |
13 | |
14 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'grit')) | |
15 import grit.exception | |
16 import grit.grd_reader | |
17 | |
18 # We need to apply the workaround only on Windows. | |
19 if os.name != 'nt': | |
20 sys.exit(0) | |
21 | |
22 def total_split(path): | |
23 components = [] | |
24 while path: | |
25 head, tail = os.path.split(path) | |
26 if not tail: | |
27 break | |
28 components.append(tail) | |
29 path = head | |
30 return list(reversed(components)) | |
31 | |
32 for path in sys.argv[1:]: | |
33 path_components = total_split(path) | |
34 try: | |
35 root = grit.grd_reader.Parse(path) | |
36 except grit.exception.Base, exc: | |
37 # This hook exploded badly a few times on the buildbot with exception | |
38 # at this point. Do not exit with an error, just print more information | |
39 # for debugging. | |
40 # TODO(phajdan.jr): Make exception fatal when the root cause is fixed. | |
41 print 'Unexpected GRIT exception while processing ' + path | |
42 print exc | |
43 continue | |
44 output_files = [node.GetOutputFilename() for node in root.GetOutputFiles()] | |
45 output_headers = [file for file in output_files if file.endswith('.h')] | |
46 # Build output can be in any subdirectory of src. | |
47 paths = [d for d in os.listdir(_SRC_PATH) if | |
48 os.path.isdir(os.path.join(_SRC_PATH, d))] | |
49 for out_dir in paths: | |
50 for build_type in ('Debug', 'Release'): | |
51 build_path = os.path.join(_SRC_PATH, out_dir, build_type) | |
52 | |
53 # We guess target file output based on path of the grd file (the first | |
54 # path component after 'src'). | |
55 intermediate_path = os.path.join(build_path, 'obj', | |
56 'global_intermediate', path_components[1]) | |
57 | |
58 for header in output_headers: | |
59 full_path = os.path.normpath(os.path.join(intermediate_path, header)) | |
60 if os.path.exists(full_path): | |
61 try: | |
62 os.remove(full_path) | |
63 except OSError, e: | |
64 fmt = 'Could not remove %s: %s. Continuing.\n' | |
65 sys.stderr.write(fmt % (full_path, e)) | |
66 else: | |
67 print 'Clobbered ' + full_path | |
OLD | NEW |