diff options
author | Paul Elder <paul.elder@ideasonboard.com> | 2020-09-08 20:47:19 +0900 |
---|---|---|
committer | Paul Elder <paul.elder@ideasonboard.com> | 2020-11-11 19:22:37 +0900 |
commit | 82ba73535c0966e8ae8fb50db1ea23534d827717 (patch) | |
tree | f75b0d7f3933369872157105f1e467b71430e8cf /utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py | |
parent | 3d624b745b31383dbcd94d96246fab865820085f (diff) |
utils: ipc: import mojo
Import mojo from the Chromium repository, so that we can use it for
generating code for the IPC mechanism. The commit from which this was
taken is:
a079161ec8c6907b883f9cb84fc8c4e7896cb1d0 "Add PPAPI constructs for
sending focus object to PdfAccessibilityTree"
This tree has been pruned to remove directories that didn't have any
necessary code:
- mojo/* except for mojo/public
- mojo core, docs, and misc files
- mojo/public/* except for mojo/public/{tools,LICENSE}
- language bindings for IPC, tests, and some mojo internals
- mojo/public/tools/{fuzzers,chrome_ipc}
- mojo/public/tools/bindings/generators
- code generation for other languages
No files were modified.
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py')
-rw-r--r-- | utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py b/utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py new file mode 100644 index 00000000..bf626f54 --- /dev/null +++ b/utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py @@ -0,0 +1,45 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import errno +import imp +import os.path +import sys + + +def _GetDirAbove(dirname): + """Returns the directory "above" this file containing |dirname| (which must + also be "above" this file).""" + path = os.path.abspath(__file__) + while True: + path, tail = os.path.split(path) + if not tail: + return None + if tail == dirname: + return path + + +def EnsureDirectoryExists(path, always_try_to_create=False): + """A wrapper for os.makedirs that does not error if the directory already + exists. A different process could be racing to create this directory.""" + + if not os.path.exists(path) or always_try_to_create: + try: + os.makedirs(path) + except OSError as e: + # There may have been a race to create this directory. + if e.errno != errno.EEXIST: + raise + + +def AddLocalRepoThirdPartyDirToModulePath(): + """Helper function to find the top-level directory of this script's repository + assuming the script falls somewhere within a 'mojo' directory, and insert the + top-level 'third_party' directory early in the module search path. Used to + ensure that third-party dependencies provided within the repository itself + (e.g. Chromium sources include snapshots of jinja2 and ply) are preferred over + locally installed system library packages.""" + toplevel_dir = _GetDirAbove('mojo') + if toplevel_dir: + sys.path.insert(1, os.path.join(toplevel_dir, 'third_party')) |