This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lcov.sh
executable file
·71 lines (63 loc) · 1.62 KB
/
lcov.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
# https://github.com/michaelhenry/swifty-code-coverage/blob/main/lcov.sh
OUTPUT_FILE="coverage/lcov.info"
IGNORE_FILENAME_REGEX=".build|Tests|Pods|Carthage|DerivedData"
IS_SPM=false
while :; do
case $1 in
--build-path) BUILD_PATH=$2
shift
;;
--target) TARGET=$2
shift
;;
--is-spm) IS_SPM=$2
shift
;;
--ignore-filename-regex) IGNORE_FILENAME_REGEX=$2
shift
;;
--output) OUTPUT_FILE=$2
shift
;;
*) break
esac
shift
done
if [ -z "$BUILD_PATH" ]; then
echo "Missing --build-path. Either DerivedData or .build (for spm)"
exit 1
fi
if [ -z "$TARGET" ]; then
echo "Missing --target. Either an .app or an .xctest (for spm)"
exit 1
fi
INSTR_PROFILE=$(find $BUILD_PATH -name "*.profdata")
if [ $IS_SPM = true ]; then
TARGET_PATH=$(find $BUILD_PATH -name "$TARGET" | tail -n1)
if [ -f $TARGET_PATH ]; then
OBJECT_FILE="$TARGET_PATH"
else
TARGET=$(echo $TARGET | sed 's/\.[^.]*$//')
OBJECT_FILE=$(find $BUILD_PATH -name "$TARGET" | tail -n1)
fi
else
TARGET=$(echo $TARGET | sed 's/\.[^.]*$//')
TARGET_PATH=$(find $BUILD_PATH -name "$TARGET.app")
OBJECT_FILE="$TARGET_PATH/$TARGET"
fi
mkdir -p $(dirname "$OUTPUT_FILE")
LLVM_COV_CMD="xcrun llvm-cov"
# print to stdout
$LLVM_COV_CMD report \
"$OBJECT_FILE" \
--instr-profile=$INSTR_PROFILE \
--ignore-filename-regex=$IGNORE_FILENAME_REGEX \
--use-color
# Export to code coverage file
$LLVM_COV_CMD export \
"$OBJECT_FILE" \
--instr-profile=$INSTR_PROFILE \
--ignore-filename-regex=$IGNORE_FILENAME_REGEX \
--format="lcov" > $OUTPUT_FILE
sed -i '' 's/18446744073709551615/1/' $OUTPUT_FILE