[autoformat] Fix running sed on Linux. (#18254)

The autoformat action doesn't necessarily run on macOS, and sed's syntax is
different between macOS and Linux - so make sure to cope with these
differences.

Also execute the nullability fixes in a separate subshell to not interfere
with the rest of the script.

This fixes an issue where autoformat would fail with:

    + sed -i '' -e 's/!= null/is not null/g' -e 's/== null/is null/g' builds/fix-maccatalyst-assembly/Program.cs
    sed: can't read : No such file or directory
This commit is contained in:
Rolf Bjarne Kvinge 2023-05-11 07:27:47 +02:00 коммит произвёл GitHub
Родитель 34b2b9466f
Коммит 792a223c37
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -449,7 +449,7 @@ namespace Xamarin.iOS.Tasks {
public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
{
if (NativeReferences == null)
if (NativeReferences is null)
yield break;
foreach (var nativeRef in NativeReferences) {

Просмотреть файл

@ -10,12 +10,28 @@ SRC_DIR=$(pwd)
# except in a few tests files, where we have tests for (in)equality operators, and in that case the '== null' and '!= null' code is correct.
#
IFS=$'\n'
for file in $(git ls-files -- '*.cs' ':(exclude)tests/monotouch-test/Foundation/UrlTest.cs' ':(exclude)tests/monotouch-test/AVFoundation/AVAudioFormatTest.cs'); do
if [[ -L "$file" ]]; then
continue
(
set +x
export LANG=en
IFS=$'\n'
cd "$SRC_DIR"
if [[ "$OSTYPE" == "darwin"* ]]; then
SED=(sed -i "")
else
SED=(sed -i)
fi
LANG=en sed -i '' -e 's/!= null/is not null/g' -e 's/== null/is null/g' "$file"
done
for file in $(git ls-files -- '*.cs' ':(exclude)tests/monotouch-test/Foundation/UrlTest.cs' ':(exclude)tests/monotouch-test/AVFoundation/AVAudioFormatTest.cs'); do
if [[ -L "$file" ]]; then
echo "Skipping $file because it's a symlink"
continue
fi
"${SED[@]}" -e 's/!= null/is not null/g' -e 's/== null/is null/g' "$file"
done
)
# Go one directory up, to avoid any global.json in xamarin-macios
cd ..