tools/android/elf_compression/compress_section.py
def _CopyRangeIntoCompressedSection(data, l, r):
  """Adds a new section containing compressed version of provided range."""
  compressed_range = compression.CompressData(data[l:r])

  with tempfile.TemporaryDirectory() as tmpdir:
    # The easiest way to add a new section is to use objcopy, but it requires
    # for all of the data to be stored in files.
    objcopy_input_file = os.path.join(tmpdir, 'input')
    objcopy_data_file = os.path.join(tmpdir, 'data')
    objcopy_output_file = os.path.join(tmpdir, 'output')

    with open(objcopy_input_file, 'wb') as f:
      f.write(data)
    with open(objcopy_data_file, 'wb') as f:
      f.write(compressed_range)

    objcopy_args = [
        OBJCOPY_PATH, objcopy_input_file, objcopy_output_file, '--add-section',
        '{}={}'.format(COMPRESSED_SECTION_NAME, objcopy_data_file)
    ]
    run_result = subprocess.run(
        objcopy_args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
    if run_result.returncode != 0:
      raise RuntimeError('objcopy failed with status code {}: {}'.format(
          run_result.returncode, run_result.stderr))

    with open(objcopy_output_file, 'rb') as f:
      data[:] = bytearray(f.read())
Adds a new section containing compressed version of provided range.
Adds a new section containing compressed version of provided range.
Adds a new section containing compressed version of provided range .
def _CopyRangeIntoCompressedSection(data, l, r):
  compressed_range = compression.CompressData(data[l:r])
  with tempfile.TemporaryDirectory() as tmpdir:
    objcopy_input_file = os.path.join(tmpdir, 'input')
    objcopy_data_file = os.path.join(tmpdir, 'data')
    objcopy_output_file = os.path.join(tmpdir, 'output')
    with open(objcopy_input_file, 'wb') as f:
      f.write(data)
    with open(objcopy_data_file, 'wb') as f:
      f.write(compressed_range)
    objcopy_args = [
        OBJCOPY_PATH, objcopy_input_file, objcopy_output_file, '--add-section',
        '{}={}'.format(COMPRESSED_SECTION_NAME, objcopy_data_file)
    ]
    run_result = subprocess.run(
        objcopy_args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
    if run_result.returncode != 0:
      raise RuntimeError('objcopy failed with status code {}: {}'.format(
          run_result.returncode, run_result.stderr))
    with open(objcopy_output_file, 'rb') as f:
      data[:] = bytearray(f.read())
def _CopyRangeIntoCompressedSection ( data , l , r ) : compressed_range = compression . CompressData ( data [ l : r ] ) with tempfile . TemporaryDirectory ( ) as tmpdir : objcopy_input_file = os . path . join ( tmpdir , 'input' ) objcopy_data_file = os . path . join ( tmpdir , 'data' ) objcopy_output_file = os . path . join ( tmpdir , 'output' ) with open ( objcopy_input_file , 'wb' ) as f : f . write ( data ) with open ( objcopy_data_file , 'wb' ) as f : f . write ( compressed_range ) objcopy_args = [ OBJCOPY_PATH , objcopy_input_file , objcopy_output_file , '--add-section' , '{}={}' . format ( COMPRESSED_SECTION_NAME , objcopy_data_file ) ] run_result = subprocess . run ( objcopy_args , stdout = subprocess . DEVNULL , stderr = subprocess . PIPE ) if run_result . returncode != 0 : raise RuntimeError ( 'objcopy failed with status code {}: {}' . format ( run_result . returncode , run_result . stderr ) ) with open ( objcopy_output_file , 'rb' ) as f : data [ : ] = bytearray ( f . read ( ) )
Adds a new section containing compressed version of provided range.
Adds a new section containing compressed version of provided range .
"""Adds a new section containing compressed version of provided range.""" # The easiest way to add a new section is to use objcopy, but it requires # for all of the data to be stored in files.
data
l
r