Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: build/scan_sources.py

Issue 11882002: Fix some scan_sources.py dependencies (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: merge with master Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 from optparse import OptionParser 6 from optparse import OptionParser
7 import os 7 import os
8 import re 8 import re
9 import sys 9 import sys
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 def open(self, pathname): 53 def open(self, pathname):
54 ospath = self.ToNativePath(pathname) 54 ospath = self.ToNativePath(pathname)
55 return open(ospath) 55 return open(ospath)
56 56
57 def realpath(self, pathname): 57 def realpath(self, pathname):
58 ospath = self.ToNativePath(pathname) 58 ospath = self.ToNativePath(pathname)
59 ospath = os.path.realpath(ospath) 59 ospath = os.path.realpath(ospath)
60 return self.ToPosixPath(ospath) 60 return self.ToPosixPath(ospath)
61 61
62 def dirname(self, pathname):
63 ospath = self.ToNativePath(pathname)
64 ospath = os.path.dirname(ospath)
65 return self.ToPosixPath(ospath)
66
62 67
63 class Resolver(object): 68 class Resolver(object):
64 """Resolver finds and generates relative paths for include files. 69 """Resolver finds and generates relative paths for include files.
65 70
66 The Resolver object provides a mechanism to to find and convert a source or 71 The Resolver object provides a mechanism to to find and convert a source or
67 include filename into a relative path based on provided search paths. All 72 include filename into a relative path based on provided search paths. All
68 paths use POSIX style separator. 73 paths use POSIX style separator.
69 """ 74 """
70 def __init__(self, pathobj=PathConverter()): 75 def __init__(self, pathobj=PathConverter()):
71 self.search_dirs = [] 76 self.search_dirs = []
72 self.pathobj = pathobj 77 self.pathobj = pathobj
73 self.cwd = self.pathobj.getcwd() 78 self.cwd = self.pathobj.getcwd()
74 self.offs = len(self.cwd) 79 self.offs = len(self.cwd)
75 80
76 def AddOneDirectory(self, pathname): 81 def AddOneDirectory(self, pathname):
77 """Add an include search path.""" 82 """Add an include search path."""
78 pathname = self.pathobj.realpath(pathname) 83 pathname = self.pathobj.realpath(pathname)
79 DebugPrint('Adding DIR: %s' % pathname) 84 DebugPrint('Adding DIR: %s' % pathname)
80 if pathname not in self.search_dirs: 85 if pathname not in self.search_dirs:
81 if self.pathobj.isdir(pathname): 86 if self.pathobj.isdir(pathname):
82 self.search_dirs.append(pathname) 87 self.search_dirs.append(pathname)
83 else: 88 else:
84 sys.stderr.write('Not a directory: %s\n' % pathname) 89 sys.stderr.write('Not a directory: %s\n' % pathname)
85 return False 90 return False
86 return True 91 return True
87 92
93 def RemoveOneDirectory(self, pathname):
94 """Remove an include search path."""
95 pathname = self.pathobj.realpath(pathname)
96 DebugPrint('Removing DIR: %s' % pathname)
97 if pathname in self.search_dirs:
98 self.search_dirs.remove(pathname)
99 return True
100
88 def AddDirectories(self, pathlist): 101 def AddDirectories(self, pathlist):
89 """Add list of space separated directories.""" 102 """Add list of space separated directories."""
90 failed = False 103 failed = False
91 dirlist = ' '.join(pathlist) 104 dirlist = ' '.join(pathlist)
92 for dirname in dirlist.split(' '): 105 for dirname in dirlist.split(' '):
93 if not self.AddOneDirectory(dirname): 106 if not self.AddOneDirectory(dirname):
94 failed = True 107 failed = True
95 return not failed 108 return not failed
96 109
97 def GetDirectories(self): 110 def GetDirectories(self):
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if not self.todo_list: 204 if not self.todo_list:
192 return None 205 return None
193 return self.todo_list.pop() 206 return self.todo_list.pop()
194 207
195 def Run(self): 208 def Run(self):
196 """Search through the available dependencies until the list becomes empty. 209 """Search through the available dependencies until the list becomes empty.
197 The list must be primed with one or more source files to search.""" 210 The list must be primed with one or more source files to search."""
198 scan_name = self.PopIfAvail() 211 scan_name = self.PopIfAvail()
199 while scan_name: 212 while scan_name:
200 includes = self.scanner.ScanFile(scan_name) 213 includes = self.scanner.ScanFile(scan_name)
214 # Add the directory of the current scanned file for resolving includes
215 # while processing includes for this file.
216 scan_dir = PathConverter().dirname(scan_name)
217 self.resolver.AddOneDirectory(scan_dir)
201 for include_file in includes: 218 for include_file in includes:
202 self.PushIfNew(include_file) 219 self.PushIfNew(include_file)
220 self.resolver.RemoveOneDirectory(scan_dir)
203 scan_name = self.PopIfAvail() 221 scan_name = self.PopIfAvail()
204 return sorted(self.added_set) 222 return sorted(self.added_set)
205 223
206 224
207 def DoMain(argv): 225 def DoMain(argv):
208 """Entry point used by gyp's pymod_do_main feature.""" 226 """Entry point used by gyp's pymod_do_main feature."""
209 global debug 227 global debug
210 parser = OptionParser() 228 parser = OptionParser()
211 parser.add_option('-I', dest='includes', action='append', 229 parser.add_option('-I', dest='includes', action='append',
212 help='Set include path.') 230 help='Set include path.')
(...skipping 21 matching lines...) Expand all
234 252
235 def Main(): 253 def Main():
236 retcode, result = DoMain(sys.argv[1:]) 254 retcode, result = DoMain(sys.argv[1:])
237 if retcode: 255 if retcode:
238 sys.exit(retcode) 256 sys.exit(retcode)
239 sys.stdout.write(result) 257 sys.stdout.write(result)
240 258
241 259
242 if __name__ == '__main__': 260 if __name__ == '__main__':
243 Main() 261 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698