def rewrite_record_file(workspace, src_record_file, mutated_file_tuples):
  """Given a RECORD file and list of mutated file tuples, update the RECORD file in place.

  The RECORD file should always be a member of the mutated files, due to both containing
  versions, and having a version in its filename.
  """
  mutated_files = set()
  dst_record_file = None
  for src, dst in mutated_file_tuples:
    if src == src_record_file:
      dst_record_file = dst
    else:
      mutated_files.add(dst)
  if not dst_record_file:
    raise Exception('Malformed whl or bad globs: `{}` was not rewritten.'.format(src_record_file))

  output_records = []
  file_name = os.path.join(workspace, dst_record_file)
  for line in read_file(file_name).splitlines():
    filename, fingerprint_str, size_str = line.rsplit(',', 3)
    if filename in mutated_files:
      fingerprint_str, size_str = fingerprint_file(workspace, filename)
      output_line = ','.join((filename, fingerprint_str, size_str))
    else:
      output_line = line
    output_records.append(output_line)

  safe_file_dump(file_name, '\r\n'.join(output_records) + '\r\n')
Given a RECORD file and list of mutated file tuples, update the RECORD file in place.

  The RECORD file should always be a member of the mutated files, due to both containing
  versions, and having a version in its filename.