def get_line_counts(data: GetLineCountsData) -> None: root: str files: List[str] # In gcov_prefix_dir, add symlinks to build_dir .gcno files. print("Adding symlinks.") # If the symlinks already exist, we will get an error. # os.symlink does not provide an option to overwrite. # We instead create the symlink with a randomized name and then rename it using os.replace, which atomically # overwrites any existing file. random_text = util.get_random_name()[:10] for root, _, files in os.walk(data.build_dir): gcno_files = [f for f in files if f.endswith(".gcno")] if gcno_files: root_rel = strip_root(root) os.makedirs(os.path.join(data.gcov_prefix_dir, root_rel), exist_ok=True) for file_name in gcno_files: source = os.path.join(root, file_name) dest = os.path.join(data.gcov_prefix_dir, root_rel, file_name) temp = dest + random_text os.symlink(source, temp) os.replace(temp, dest) print("Done.") print("Processing .gcno files.") gcovs_thread = threading.Thread(target=_thread_gcovs, args=(data,)) adder_thread = threading.Thread(target=_thread_adder, args=(data,)) gcovs_thread.start() adder_thread.start() for root, _, files in os.walk( os.path.join(data.gcov_prefix_dir, strip_root(data.build_dir)) ): gcno_files = [f for f in files if f.endswith(".gcno")] # TODO: Could split further if necessary. if gcno_files: data.gcno_files_queue.put((os.path.join(root), gcno_files)) # Send a "done" message for each thread. for _ in range(data.num_threads): data.gcno_files_queue.put(("", [])) # wait for threads. gcovs_thread.join() adder_thread.join() print("Done.")
def get_random_name() -> str: # TODO: could change to human-readable random name or the date. return util.get_random_name()