Exemple #1
0
def _UnzipUsingZipFile(file_path, output_dir, verbose=True):
    """Extracts a zip file using the Python zipfile module."""
    assert bisect_utils.IsWindowsHost() or bisect_utils.IsMacHost()
    zf = zipfile.ZipFile(file_path)
    for name in zf.namelist():
        if verbose:
            print 'Extracting %s' % name
        zf.extract(name, output_dir)
        if bisect_utils.IsMacHost():
            # Restore file permission bits.
            mode = zf.getinfo(name).external_attr >> 16
            os.chmod(os.path.join(output_dir, name), mode)
Exemple #2
0
 def __init__(self, target_arch='ia32', target_platform='chromium'):
     if bisect_utils.IsLinuxHost() and target_platform == 'android':
         self._platform = 'android'
     elif bisect_utils.IsLinuxHost():
         self._platform = 'linux'
     elif bisect_utils.IsMacHost():
         self._platform = 'mac'
     elif bisect_utils.Is64BitWindows() and target_arch == 'x64':
         self._platform = 'win64'
     elif bisect_utils.IsWindowsHost():
         self._platform = 'win'
     else:
         raise NotImplementedError('Unknown platform "%s".' % sys.platform)
Exemple #3
0
def Unzip(file_path, output_dir, verbose=True):
    """Extracts a zip archive's contents into the given output directory.

  This was based on ExtractZip from build/scripts/common/chromium_utils.py.

  Args:
    file_path: Path of the zip file to extract.
    output_dir: Path to the destination directory.
    verbose: Whether to print out what is being extracted.

  Raises:
    IOError: The unzip command had a non-zero exit code.
    RuntimeError: Failed to create the output directory.
  """
    _MakeDirectory(output_dir)

    # On Linux and Mac, we use the unzip command because it handles links and
    # file permissions bits, so achieving this behavior is easier than with
    # ZipInfo options.
    #
    # The Mac Version of unzip unfortunately does not support Zip64, whereas
    # the python module does, so we have to fall back to the python zip module
    # on Mac if the file size is greater than 4GB.
    mac_zip_size_limit = 2**32  # 4GB
    if (bisect_utils.IsLinuxHost()
            or (bisect_utils.IsMacHost()
                and os.path.getsize(file_path) < mac_zip_size_limit)):
        unzip_command = ['unzip', '-o']
        _UnzipUsingCommand(unzip_command, file_path, output_dir)
        return

    # On Windows, try to use 7z if it is installed, otherwise fall back to the
    # Python zipfile module. If 7z is not installed, then this may fail if the
    # zip file is larger than 512MB.
    sevenzip_path = r'C:\Program Files\7-Zip\7z.exe'
    if bisect_utils.IsWindowsHost() and os.path.exists(sevenzip_path):
        unzip_command = [sevenzip_path, 'x', '-y']
        _UnzipUsingCommand(unzip_command, file_path, output_dir)
        return

    _UnzipUsingZipFile(file_path, output_dir, verbose)
Exemple #4
0
def GetBuildOutputDirectory(opts, src_dir=None):
    """Returns the path to the build directory, relative to the checkout root.

  Assumes that the current working directory is the checkout root.

  Args:
    opts: Command-line options.
    src_dir: Path to chromium/src directory.

  Returns:
    A path to the directory to use as build output directory.

  Raises:
    NotImplementedError: The platform according to sys.platform is unexpected.
  """
    src_dir = src_dir or 'src'
    if opts.build_preference == 'ninja' or bisect_utils.IsLinuxHost():
        return os.path.join(src_dir, 'out')
    if bisect_utils.IsMacHost():
        return os.path.join(src_dir, 'xcodebuild')
    if bisect_utils.IsWindowsHost():
        return os.path.join(src_dir, 'build')
    raise NotImplementedError('Unexpected platform %s' % sys.platform)