1
+ #! /bin/bash
2
+
1
3
# Find the transitive closure of overlay dependencies for a single overlay.
2
4
# Runs the following command in a loop until the list stops growing:
3
5
# xcrun -sdk macosx clang -arch x86_64 -x objective-c - -M -fmodules < <(echo '@import SceneKit;@import AppKit;')
10
12
# Overlays that have a different name in Swift than in the output: Dispatch, ObjectiveC, XPC
11
13
# XCTest is hardcoded because this method doesn't work for it.
12
14
13
- #! /bin/bash
14
15
set -o pipefail
15
16
set -e
16
17
@@ -22,15 +23,16 @@ function find_deps() {
22
23
local ARCH_ARG=$3
23
24
24
25
local PROGRAM=" "
25
- for overlay in $( echo $OVERLAY_ARG | sed " s/;/ /g" ) ; do
26
+ # shellcheck disable=SC2013
27
+ for overlay in $( sed " s/;/ /g" <<< " $OVERLAY_ARG" ) ; do
26
28
regexp=" ObjectiveC|objc|Dispatch|dispatch|XPC|xpc"
27
29
if [[ ! $overlay =~ $regexp ]]; then
28
30
PROGRAM+=" @import $overlay ;"
29
31
fi
30
32
done
31
33
32
- local DEPS= $( xcrun -sdk $SDK_ARG clang -arch $ARCH_ARG -x objective-c - -M -fmodules < <( echo $PROGRAM ) 2>&1 )
33
-
34
+ local DEPS
35
+ DEPS= $( xcrun -sdk " $SDK_ARG " clang -arch " $ARCH_ARG " -x objective-c - -M -fmodules <<< " $PROGRAM " 2>&1 )
34
36
local ERROR_REGEX=" (.*error:.*)"
35
37
if [[ $DEPS =~ $ERROR_REGEX ]]; then
36
38
echo " ${BASH_REMATCH[1]} " >&2
@@ -39,9 +41,11 @@ function find_deps() {
39
41
40
42
local REGEX=" ./Frameworks/(${OVERLAY_NAME_ALTERNATION} ).framework/.*|.*/usr/include/(xpc|dispatch|os|objc|simd)/.*\.h"
41
43
44
+ # shellcheck disable=SC1004
42
45
IFS=' \
43
46
'
44
47
local USED_OVERLAYS=" "
48
+ # shellcheck disable=SC2068
45
49
for line in ${DEPS[@]} ; do
46
50
if [[ $line =~ $REGEX ]]; then
47
51
if [[ ${BASH_REMATCH[1]} != " " ]]; then
@@ -59,11 +63,11 @@ function find_deps() {
59
63
done
60
64
61
65
# Remove last ;
62
- if [[ ${# USED_OVERLAYS} > 0 ]]; then
66
+ if [[ ${# USED_OVERLAYS} -gt 0 ]]; then
63
67
USED_OVERLAYS=${USED_OVERLAYS% ?}
64
68
fi
65
69
66
- TRIMMED=$( echo $USED_OVERLAYS | tr " ;" " \n" | sort | uniq | tr " \n" " ;" )
70
+ TRIMMED=$( tr " ;" " \n" <<< " $USED_OVERLAYS " | sort | uniq | tr " \n" " ;" )
67
71
echo " ${TRIMMED% ?} "
68
72
}
69
73
@@ -100,8 +104,8 @@ if [[ $OVERLAY_ARG == "XCTest" ]]; then
100
104
esac
101
105
else
102
106
while true ; do
103
- OUT=$( find_deps $LAST_OUT $SDK_ARG $ARCH_ARG )
104
- if [[ $LAST_OUT == $OUT ]]; then
107
+ OUT=$( find_deps " $LAST_OUT " " $SDK_ARG " " $ARCH_ARG " )
108
+ if [[ " $LAST_OUT " == " $OUT " ]]; then
105
109
break
106
110
fi
107
111
LAST_OUT=$OUT
0 commit comments