tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

host_paths.py (3057B)


      1 # Copyright 2016 The Chromium Authors
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 import contextlib
      7 import os
      8 import sys
      9 
     10 from pylib import constants
     11 
     12 DIR_SOURCE_ROOT = os.environ.get(
     13    'CHECKOUT_SOURCE_ROOT',
     14    os.path.abspath(os.path.join(os.path.dirname(__file__),
     15                                 os.pardir, os.pardir, os.pardir, os.pardir)))
     16 
     17 # third-party libraries
     18 ANDROID_PLATFORM_DEVELOPMENT_SCRIPTS_PATH = os.path.join(
     19    DIR_SOURCE_ROOT, 'third_party', 'android_platform', 'development',
     20    'scripts')
     21 BUILD_PATH = os.path.join(DIR_SOURCE_ROOT, 'build')
     22 BUILD_UTIL_PATH = os.path.join(DIR_SOURCE_ROOT, 'build', 'util')
     23 
     24 DEVIL_PATH = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'catapult', 'devil')
     25 JAVA_PATH = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'jdk', 'current',
     26                         'bin')
     27 TRACING_PATH = os.path.join(
     28    DIR_SOURCE_ROOT, 'third_party', 'catapult', 'tracing')
     29 
     30 @contextlib.contextmanager
     31 def SysPath(path, position=None):
     32  if position is None:
     33    sys.path.append(path)
     34  else:
     35    sys.path.insert(position, path)
     36  try:
     37    yield
     38  finally:
     39    if sys.path[-1] == path:
     40      sys.path.pop()
     41    else:
     42      sys.path.remove(path)
     43 
     44 
     45 # Map of CPU architecture name to (toolchain_name, binprefix) pairs.
     46 # TODO(digit): Use the build_vars.json file generated by gn.
     47 _TOOL_ARCH_MAP = {
     48  'arm': ('arm-linux-androideabi-4.9', 'arm-linux-androideabi'),
     49  'arm64': ('aarch64-linux-android-4.9', 'aarch64-linux-android'),
     50  'x86': ('x86-4.9', 'i686-linux-android'),
     51  'x86_64': ('x86_64-4.9', 'x86_64-linux-android'),
     52  'x64': ('x86_64-4.9', 'x86_64-linux-android'),
     53  'mips': ('mipsel-linux-android-4.9', 'mipsel-linux-android'),
     54 }
     55 
     56 # Cache used to speed up the results of ToolPath()
     57 # Maps (arch, tool_name) pairs to fully qualified program paths.
     58 # Useful because ToolPath() is called repeatedly for demangling C++ symbols.
     59 _cached_tool_paths = {}
     60 
     61 
     62 def ToolPath(tool, cpu_arch):
     63  """Return a fully qualifed path to an arch-specific toolchain program.
     64 
     65  Args:
     66    tool: Unprefixed toolchain program name (e.g. 'objdump')
     67    cpu_arch: Target CPU architecture (e.g. 'arm64')
     68  Returns:
     69    Fully qualified path (e.g. ..../aarch64-linux-android-objdump')
     70  Raises:
     71    Exception if the toolchain could not be found.
     72  """
     73  tool_path = _cached_tool_paths.get((tool, cpu_arch))
     74  if tool_path:
     75    return tool_path
     76 
     77  toolchain_source, toolchain_prefix = _TOOL_ARCH_MAP.get(
     78      cpu_arch, (None, None))
     79  if not toolchain_source:
     80    raise Exception('Could not find tool chain for ' + cpu_arch)
     81 
     82  toolchain_subdir = (
     83      'toolchains/%s/prebuilt/linux-x86_64/bin' % toolchain_source)
     84 
     85  tool_path = os.path.join(constants.ANDROID_NDK_ROOT,
     86                           toolchain_subdir,
     87                           toolchain_prefix + '-' + tool)
     88 
     89  _cached_tool_paths[(tool, cpu_arch)] = tool_path
     90  return tool_path
     91 
     92 
     93 def GetAaptPath():
     94  """Returns the path to the 'aapt' executable."""
     95  return os.path.join(constants.ANDROID_SDK_TOOLS, 'aapt')