Skip to content

Commit d3ab381

Browse files
Merge pull request #6210 from practicalswift/find-overlay-cleanups
[gardening] Fix shellcheck warnings in recently introduced file find-overlay-deps-closure.sh
2 parents 8962c88 + 6f70287 commit d3ab381

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

utils/find-overlay-deps-closure.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
# Find the transitive closure of overlay dependencies for a single overlay.
24
# Runs the following command in a loop until the list stops growing:
35
# xcrun -sdk macosx clang -arch x86_64 -x objective-c - -M -fmodules < <(echo '@import SceneKit;@import AppKit;')
@@ -10,7 +12,6 @@
1012
# Overlays that have a different name in Swift than in the output: Dispatch, ObjectiveC, XPC
1113
# XCTest is hardcoded because this method doesn't work for it.
1214

13-
#!/bin/bash
1415
set -o pipefail
1516
set -e
1617

@@ -22,15 +23,16 @@ function find_deps() {
2223
local ARCH_ARG=$3
2324

2425
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
2628
regexp="ObjectiveC|objc|Dispatch|dispatch|XPC|xpc"
2729
if [[ ! $overlay =~ $regexp ]]; then
2830
PROGRAM+="@import $overlay;"
2931
fi
3032
done
3133

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)
3436
local ERROR_REGEX="(.*error:.*)"
3537
if [[ $DEPS =~ $ERROR_REGEX ]]; then
3638
echo "${BASH_REMATCH[1]}" >&2
@@ -39,9 +41,11 @@ function find_deps() {
3941

4042
local REGEX="./Frameworks/(${OVERLAY_NAME_ALTERNATION}).framework/.*|.*/usr/include/(xpc|dispatch|os|objc|simd)/.*\.h"
4143

44+
# shellcheck disable=SC1004
4245
IFS='\
4346
'
4447
local USED_OVERLAYS=""
48+
# shellcheck disable=SC2068
4549
for line in ${DEPS[@]}; do
4650
if [[ $line =~ $REGEX ]]; then
4751
if [[ ${BASH_REMATCH[1]} != "" ]]; then
@@ -59,11 +63,11 @@ function find_deps() {
5963
done
6064

6165
# Remove last ;
62-
if [[ ${#USED_OVERLAYS} > 0 ]]; then
66+
if [[ ${#USED_OVERLAYS} -gt 0 ]]; then
6367
USED_OVERLAYS=${USED_OVERLAYS%?}
6468
fi
6569

66-
TRIMMED=$(echo $USED_OVERLAYS | tr ";" "\n" | sort | uniq | tr "\n" ";")
70+
TRIMMED=$(tr ";" "\n" <<< "$USED_OVERLAYS" | sort | uniq | tr "\n" ";")
6771
echo "${TRIMMED%?}"
6872
}
6973

@@ -100,8 +104,8 @@ if [[ $OVERLAY_ARG == "XCTest" ]]; then
100104
esac
101105
else
102106
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
105109
break
106110
fi
107111
LAST_OUT=$OUT

0 commit comments

Comments
 (0)