[coverage] Perform glob expansion so that the coverage script works on
fuzz targets.
The `coverage.py` file has instructions for how to generate coverage for
fuzz targets.
However, the command as-written fails because StandaloneFuzzTarget
expects to receive a list of inputs; it exits with an error if it's
given a pointer to a directory.
It's simple enough to simply append `/*` to the directory, but Python's
subprocess doesn't support glob expansion.
So, this commit (1) changes the instructions to the new command, and (2)
enables glob expansion on that command.
Bug: 1356583
Change-Id: I90345b05d5baf4d016551f5d2f39ec18a8535277
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4121294
Reviewed-by: Zhaoyang Li <[email protected]>
Commit-Queue: Julia Hansbrough <[email protected]>
Reviewed-by: Erik Staab <[email protected]>
Reviewed-by: Jeff Yoon <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1093525}
diff --git a/tools/code_coverage/coverage.py b/tools/code_coverage/coverage.py
index 826496a..b1894a0 100755
--- a/tools/code_coverage/coverage.py
+++ b/tools/code_coverage/coverage.py
@@ -70,6 +70,7 @@
import sys
import argparse
+import glob
import json
import logging
import multiprocessing
@@ -460,7 +461,17 @@
"""Split a command string into parts in a platform-specific way."""
if coverage_utils.GetHostPlatform() == 'win':
return command.split()
- return shlex.split(command)
+ split_command = shlex.split(command)
+ # Python's subprocess does not do glob expansion, so we expand it out here.
+ new_command = []
+ for item in split_command:
+ if '*' in item:
+ files = glob.glob(item)
+ for file in files:
+ new_command.append(file)
+ else:
+ new_command.append(item)
+ return new_command
def _ExecuteCommand(target, command, output_file_path):