tools/clang/scripts/goma_link.py
def names_in_archive(path):
  """
  Yields the member names in the archive file at path.
  """
  # Note: This could alternatively be implemented by invoking some
  # external utility, e.g. llvm-ar, which would avoid having logic here
  # to parse thin archives. The current approach was chosen because it
  # avoids spawning additional processes and having an external dependency
  # (in particular, this works even if llvm-ar is not in $PATH).
  with open(path, 'rb') as f:
    long_names = None
    f.seek(8, io.SEEK_CUR)
    while True:
      file_id = f.read(16)
      if len(file_id) == 0:
        break
      f.seek(32, io.SEEK_CUR)
      m = re.match(b'/([0-9]+)', file_id)
      if long_names and m:
        name_pos = long(m.group(1))
        name_end = long_names.find(b'/\n', name_pos)
        name = long_names[name_pos:name_end]
      else:
        name = file_id
      try:
        size = long(f.read(10))
      except:
        sys.stderr.write('While parsing %r, pos %r\n' % (path, f.tell()))
        raise
      # Two entries are special: '/' and '//'. The former is
      # the symbol table, which we skip. The latter is the long
      # file name table, which we read.
      # Anything else is a filename entry which we yield.
      # Every file record ends with two terminating characters
      # which we skip.
      seek_distance = 2
      if file_id == b'/               ':
        # Skip symbol table.
        seek_distance += size + (size & 1)
      elif file_id == b'//              ':
        # Read long name table.
        f.seek(2, io.SEEK_CUR)
        long_names = f.read(size)
        seek_distance = size & 1
      else:
        # Using UTF-8 here gives us a fighting chance if someone decides to use
        # non-US-ASCII characters in a file name, and backslashreplace gives us
        # a human-readable representation of any undecodable bytes we might
        # encounter.
        yield name.decode('UTF-8', 'backslashreplace')
      f.seek(seek_distance, io.SEEK_CUR)

  Yields the member names in the archive file at path.
  
Yields the member names in the archive file at path.
Yields the member names in the archive file at path .
def names_in_archive(path):
  with open(path, 'rb') as f:
    long_names = None
    f.seek(8, io.SEEK_CUR)
    while True:
      file_id = f.read(16)
      if len(file_id) == 0:
        break
      f.seek(32, io.SEEK_CUR)
      m = re.match(b'/([0-9]+)', file_id)
      if long_names and m:
        name_pos = long(m.group(1))
        name_end = long_names.find(b'/\n', name_pos)
        name = long_names[name_pos:name_end]
      else:
        name = file_id
      try:
        size = long(f.read(10))
      except:
        sys.stderr.write('While parsing %r, pos %r\n' % (path, f.tell()))
        raise
      seek_distance = 2
      if file_id == b'/               ':
        seek_distance += size + (size & 1)
      elif file_id == b'//              ':
        f.seek(2, io.SEEK_CUR)
        long_names = f.read(size)
        seek_distance = size & 1
      else:
        yield name.decode('UTF-8', 'backslashreplace')
      f.seek(seek_distance, io.SEEK_CUR)
def names_in_archive ( path ) : with open ( path , 'rb' ) as f : long_names = None f . seek ( 8 , io . SEEK_CUR ) while True : file_id = f . read ( 16 ) if len ( file_id ) == 0 : break f . seek ( 32 , io . SEEK_CUR ) m = re . match ( b'/([0-9]+)' , file_id ) if long_names and m : name_pos = long ( m . group ( 1 ) ) name_end = long_names . find ( b'/\n' , name_pos ) name = long_names [ name_pos : name_end ] else : name = file_id try : size = long ( f . read ( 10 ) ) except : sys . stderr . write ( 'While parsing %r, pos %r\n' % ( path , f . tell ( ) ) ) raise seek_distance = 2 if file_id == b'/               ' : seek_distance += size + ( size & 1 ) elif file_id == b'//              ' : f . seek ( 2 , io . SEEK_CUR ) long_names = f . read ( size ) seek_distance = size & 1 else : yield name . decode ( 'UTF-8' , 'backslashreplace' ) f . seek ( seek_distance , io . SEEK_CUR )
Yields the member names in the archive file at path.
Yields the member names in the archive file at path .
"""
  Yields the member names in the archive file at path.
  """ # Note: This could alternatively be implemented by invoking some # external utility, e.g. llvm-ar, which would avoid having logic here # to parse thin archives. The current approach was chosen because it # avoids spawning additional processes and having an external dependency # (in particular, this works even if llvm-ar is not in $PATH). # Two entries are special: '/' and '//'. The former is # the symbol table, which we skip. The latter is the long # file name table, which we read. # Anything else is a filename entry which we yield. # Every file record ends with two terminating characters # which we skip. # Skip symbol table. # Read long name table. # Using UTF-8 here gives us a fighting chance if someone decides to use # non-US-ASCII characters in a file name, and backslashreplace gives us # a human-readable representation of any undecodable bytes we might # encounter.
path