• Home
  • Raw
  • Download

Lines Matching full:path

6 """Handle path inference and translation."""
33 """Perform path resolution to/from the chroot.
38 path's repo parent during inbound translation; overrides |source_path|.
41 # TODO(garnold) We currently infer the source root based on the path's own
49 # either passing a source_root value, or requesting to infer it from the path
84 return os.path.realpath(GetCacheDir())
87 """Returns path to the chroot directory of a given source root."""
90 return os.path.join(source_path, constants.DEFAULT_CHROOT_DIR)
92 def _ReadChrootLink(self, path): argument
93 """Convert a chroot symlink to its absolute path.
99 path (str|None): The path to resolve.
102 str|None: The resolved path if the provided path is a symlink, None
107 if not path:
110 abs_path = os.path.abspath(path)
113 # ResolveSymlink returns the passed path when the path isn't a symlink. We
121 def _TranslatePath(self, path, src_root, dst_root_input): argument
122 """If |path| starts with |src_root|, replace it using |dst_root_input|.
125 path: An absolute path we want to convert to a destination equivalent.
126 src_root: The root that path needs to be contained in.
127 dst_root_input: The root we want to relocate the relative path into, or a
131 A translated path, or None if |src_root| is not a prefix of |path|.
137 if not path.startswith(os.path.join(src_root, '')) and path != src_root:
141 raise ValueError('No target root to translate path to')
142 return os.path.join(dst_root, path[len(src_root):].lstrip(os.path.sep))
144 def _GetChrootPath(self, path): argument
145 """Translates a fully-expanded host |path| into a chroot equivalent.
147 This checks path prefixes in order from the most to least "contained": the
152 path: A host path to translate.
155 An equivalent chroot path.
158 ValueError: If |path| is not reachable from the chroot.
164 # from the path itself.
170 path_repo_dir = git.FindRepoDir(path)
172 source_path = os.path.abspath(os.path.join(path_repo_dir, '..'))
176 # First, check if the path happens to be in the chroot already.
178 new_path = self._TranslatePath(path, chroot_path, '/')
181 new_path = self._TranslatePath(path, chroot_link, '/')
185 new_path = self._TranslatePath(path, self._GetCachePath(),
190 new_path = self._TranslatePath(path, source_path,
194 raise ValueError('Path is not reachable from the chroot')
198 def _GetHostPath(self, path): argument
199 """Translates a fully-expanded chroot |path| into a host equivalent.
203 case we trim the chroot path prefix and recurse. If neither was successful,
204 just prepend the chroot path.
207 path: A chroot path to translate.
210 An equivalent host path.
213 ValueError: If |path| could not be mapped to a proper host destination.
219 new_path = self._TranslatePath(path, src_root, dst_root)
224 # If no known root was identified, just prepend the chroot path.
225 new_path = self._TranslatePath(path, '', self._chroot_path)
227 # Check whether the resolved path happens to point back at the chroot, in
228 # which case trim the chroot path or link prefix and continue recursively.
229 path = self._TranslatePath(new_path, self._chroot_path, '/')
230 if path is None and self._chroot_link:
231 path = self._TranslatePath(new_path, self._chroot_link, '/')
233 if path is not None:
234 new_path = self._GetHostPath(path)
238 def _ConvertPath(self, path, get_converted_path): argument
239 """Expands |path|; if outside the chroot, applies |get_converted_path|.
242 path: A path to be converted.
246 An expanded and (if needed) converted path.
249 ValueError: If path conversion failed.
252 # prevents them from working. Therefore, if the path points to a file we
254 # path resolution might return unusable results for file symlinks that
257 expanded_path = os.path.expanduser(path)
258 if os.path.isfile(expanded_path):
259 expanded_path = os.path.join(
260 os.path.realpath(os.path.dirname(expanded_path)),
261 os.path.basename(expanded_path))
263 expanded_path = os.path.realpath(expanded_path)
271 raise ValueError('%s: %s' % (e, path))
273 def ToChroot(self, path): argument
274 """Resolves current environment |path| for use in the chroot."""
275 return self._ConvertPath(path, self._GetChrootPath)
277 def FromChroot(self, path): argument
278 """Resolves chroot |path| for use in the current environment."""
279 return self._ConvertPath(path, self._GetHostPath)
293 chrome_src_dir: If the checkout is a Chrome checkout, the path to the
297 root, path = None, None
300 for path in osutils.IteratePathParents(cwd):
301 gclient_file = os.path.join(path, '.gclient')
302 if os.path.exists(gclient_file):
305 repo_dir = os.path.join(path, '.repo')
306 if os.path.isdir(repo_dir):
311 root = path
316 chrome_src_dir = os.path.join(root, 'src')
325 return os.path.join(checkout.root, GENERAL_CACHE_DIR)
327 return os.path.join(checkout.chrome_src_dir, 'build', CHROME_CACHE_DIR)
329 return os.path.join(tempfile.gettempdir(), 'chromeos-cache')
339 def ToChrootPath(path, source_path=None): argument
340 """Resolves current environment |path| for use in the chroot.
343 path: string path to translate into chroot namespace.
344 source_path: string path to root of source checkout with chroot in it.
347 The same path converted to "inside chroot" namespace.
350 ValueError: If the path references a location not available in the chroot.
352 return ChrootPathResolver(source_path=source_path).ToChroot(path)
355 def FromChrootPath(path, source_path=None): argument
356 """Resolves chroot |path| for use in the current environment.
359 path: string path to translate out of chroot namespace.
360 source_path: string path to root of source checkout with chroot in it.
363 The same path converted to "outside chroot" namespace.
365 return ChrootPathResolver(source_path=source_path).FromChroot(path)