Skip to content

Commit 43b99e2

Browse files
Copilotrolfbjarne
andcommitted
Use bash array for SED_INPLACE_FLAGS to properly handle empty string on macOS
Co-authored-by: rolfbjarne <249268+rolfbjarne@users.noreply.github.com>
1 parent 9c6901f commit 43b99e2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

builds/create-csproj-for-all-packagereferences.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ CLEAR=$(tput sgr0 || true)
66

77
# Detect the OS to use the right sed syntax
88
if [[ "$(uname -s)" == "Darwin" ]]; then
9-
SED_INPLACE_FLAGS="-i ''"
9+
SED_INPLACE_FLAGS=(-i '')
1010
else
11-
SED_INPLACE_FLAGS="-i"
11+
SED_INPLACE_FLAGS=(-i)
1212
fi
1313

1414
OUTPUTPATH=
@@ -51,16 +51,16 @@ cd "$(git rev-parse --show-toplevel)"
5151
git grep -e '<PackageReference.*Include="[a-zA-Z0-9._-]*".*Version="[a-zA-Z0-9._-]*".*>' -h > "$TMPPATH"
5252

5353
# Replace double double quotes with a single double quote. This happens in source code that generates project files (for tests).
54-
sed $SED_INPLACE_FLAGS 's/""/"/g' "$TMPPATH"
54+
sed "${SED_INPLACE_FLAGS[@]}" 's/""/"/g' "$TMPPATH"
5555

5656
# Remove packages that we build locally
57-
sed $SED_INPLACE_FLAGS '/Xamarin.Tests.FrameworksInRuntimesNativeDirectory/d' "$TMPPATH"
58-
sed $SED_INPLACE_FLAGS '/Xamarin.Tests.DynamicLibrariesInRuntimesNativeDirectory/d' "$TMPPATH"
59-
sed $SED_INPLACE_FLAGS '/Xamarin.Tests.XCFrameworkWithStaticLibraryInRuntimesNativeDirectory/d' "$TMPPATH"
60-
sed $SED_INPLACE_FLAGS '/Xamarin.Tests.XCFrameworkWithSymlinks/d' "$TMPPATH"
57+
sed "${SED_INPLACE_FLAGS[@]}" '/Xamarin.Tests.FrameworksInRuntimesNativeDirectory/d' "$TMPPATH"
58+
sed "${SED_INPLACE_FLAGS[@]}" '/Xamarin.Tests.DynamicLibrariesInRuntimesNativeDirectory/d' "$TMPPATH"
59+
sed "${SED_INPLACE_FLAGS[@]}" '/Xamarin.Tests.XCFrameworkWithStaticLibraryInRuntimesNativeDirectory/d' "$TMPPATH"
60+
sed "${SED_INPLACE_FLAGS[@]}" '/Xamarin.Tests.XCFrameworkWithSymlinks/d' "$TMPPATH"
6161

6262
# Get only the name and version of each package, and write that back in a PackageDownload item
63-
sed $SED_INPLACE_FLAGS 's@.*<PackageReference.*Include="\([a-zA-Z0-9._-]*\)".*Version="\([a-zA-Z0-9._-]*\)".*>.*@\t\t<PackageDownload Include="\1" Version="[\2]" />@g' "$TMPPATH"
63+
sed "${SED_INPLACE_FLAGS[@]}" 's@.*<PackageReference.*Include="\([a-zA-Z0-9._-]*\)".*Version="\([a-zA-Z0-9._-]*\)".*>.*@\t\t<PackageDownload Include="\1" Version="[\2]" />@g' "$TMPPATH"
6464

6565
# Sort the references and only list each once.
6666
sort -u -o "$TMPPATH" "$TMPPATH"

tools/common/create-makefile-fragment.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ cd "$(dirname "$0")"
1717

1818
# Detect OS for sed syntax
1919
if [[ "$OSTYPE" == "darwin"* ]]; then
20-
SED_INPLACE_FLAGS="-i ''"
20+
SED_INPLACE_FLAGS=(-i '')
2121
else
22-
SED_INPLACE_FLAGS="-i"
22+
SED_INPLACE_FLAGS=(-i)
2323
fi
2424

2525
if test -z "$1"; then
@@ -111,12 +111,12 @@ for proj in $(sort "$REFERENCES_PATH" | uniq); do
111111

112112
# The output contains relative paths, relative to the csproj directory
113113
# Change those to full paths by prepending the csproj directory.
114-
sed $SED_INPLACE_FLAGS "s@^@$proj_dir/@" "$inputs_path"
114+
sed "${SED_INPLACE_FLAGS[@]}" "s@^@$proj_dir/@" "$inputs_path"
115115

116116
# Change to Make syntax. This is horrifically difficult in MSBuild,
117117
# because MSBuild blindly replaces backslashes with forward slashes (i.e.
118118
# windows paths to unix paths...)
119-
sed $SED_INPLACE_FLAGS "s_^\\(.*\\)\$_ \\1 \\\\_" "$inputs_path"
119+
sed "${SED_INPLACE_FLAGS[@]}" "s_^\\(.*\\)\$_ \\1 \\\\_" "$inputs_path"
120120

121121
# Clean up
122122
rm -f "$TMPPROJ"
@@ -132,7 +132,7 @@ sort "${INPUT_PATHS[@]}" | uniq >> "$FRAGMENT_PATH"
132132

133133
# Simplify paths somewhat by removing the current directory
134134
if test -z "$ABSOLUTE_PATHS"; then
135-
sed $SED_INPLACE_FLAGS "s@$PROJECT_DIR/@@" "$FRAGMENT_PATH"
135+
sed "${SED_INPLACE_FLAGS[@]}" "s@$PROJECT_DIR/@@" "$FRAGMENT_PATH"
136136
fi
137137

138138
# Cleanup

0 commit comments

Comments
 (0)