Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Last active February 23, 2024 07:29
Show Gist options
  • Save rolfbjarne/f68883309d2cc7fd7d82fa769502656e to your computer and use it in GitHub Desktop.
Save rolfbjarne/f68883309d2cc7fd7d82fa769502656e to your computer and use it in GitHub Desktop.
#!/bin/bash -ex
cd ~/work/maccore/net9.0/xamarin-macios/src
# Last year's:
# https://gist.github.com/rolfbjarne/420aad0666d0b651804b64a6147412d6
## macOS
function macOS ()
{
sed -i '' -E \
`# remove entire lines with only "[Mac (10|11,[0-9]|1[0-5])]"` \
-e '/^[[:space:]]*[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[Mac (10|11,[0-9]|1[0-5])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[Mac (10|11,[0-9]|1[0-5])]"` \
-e 's/[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][]][[:space:]]*//' \
`# remove "[Mac (10|11,[0-9]|1[0-5]),"` \
-e 's/[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", Mac (10|11,[0-9]|1[0-5])]"` \
-e 's/[[:space:]]*,[[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][[:space:]]*[]]/]/' \
`# remove ", Mac (10|11,[0-9]|1[0-5]), "` \
-e 's/[[:space:]]*,[[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[\)][[:space:]]*,[[:space:]]*/, /' \
\
`# remove entire lines with only "[Mac (10|11,[0-9]|1[0-5],[0-9])]"` \
-e '/^[[:space:]]*[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[Mac (10|11,[0-9]|1[0-5],[0-9])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[Mac (10|11,[0-9]|1[0-5],[0-9])]"` \
-e 's/[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][]][[:space:]]*//' \
`# remove "[Mac (10|11,[0-9]|1[0-5],[0-9]),"` \
-e 's/[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", Mac (10|11,[0-9]|1[0-5],[0-9])]"` \
-e 's/[[:space:]]*,[[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][[:space:]]*[]]/]/' \
`# remove ", Mac (10|11,[0-9]|1[0-5],[0-9]), "` \
-e 's/[[:space:]]*,[[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*[\)][[:space:]]*,[[:space:]]*/, /' \
\
`# remove entire lines with only "[Mac (10|11,[0-9]|1[0-5],[0-9], PlatformArchitecture.Arch64)]"` \
-e '/^[[:space:]]*[[][[:space:]]*Mac(Attribute)?[[:space:]]*[\(](10|11)[,][[:space:]]*([0-9]|10|11|12|13|14|15)[[:space:]]*,[[:space:]]*[0-9][[:space:]]*,[[:space:]]*PlatformArchitecture.Arch64[[:space:]]*[\)][]][[:space:]]*$/d' \
\
`# remove entire lines with only "[Mac (12,0)]"` \
-e '/^[[:space:]]*[[][[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[Mac (12,0)]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[Mac (12,0)]"` \
-e 's/[[][[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][]][[:space:]]*//' \
`# remove "[Mac (12,0),"` \
-e 's/[[][[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", Mac (12,0)]"` \
-e 's/[[:space:]]*,[[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][[:space:]]*[]]/]/' \
`# remove ", Mac (12,0), "` \
-e 's/[[:space:]]*,[[:space:]]*Mac[[:space:]]*[\(]12[,][[:space:]]*[0][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# SupportedOSPlatform ("macos[10|11].[0-9]*") -> SupportedOSPlatform ("macos")` \
-e 's/SupportedOSPlatform [\(]"macos(10|11)[.][0-9]*"[\)]/SupportedOSPlatform ("macos")/' \
`# SupportedOSPlatform ("macos12.0") -> SupportedOSPlatform ("macos")` \
-e 's/SupportedOSPlatform [\(]"macos12[.]0"[\)]/SupportedOSPlatform ("macos")/' \
\
`# [Introduced (PlatformName.MacOSX, 10|11, [09]*)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*(10|11)[[:space:]]*,[[:space:]]*[0-9]*[[:space:]]*[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 10|11, [09]*, [09]*)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*(10|11)[[:space:]]*,[[:space:]]*[0-9]*[[:space:]]*[,][[:space:]]*[0-9]*[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 10|11, [09]*, PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*(10|11)[[:space:]]*,[[:space:]]*[0-9]*[[:space:]]*[,][[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 10|11, [09]*, [09]*, PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*(10|11)[[:space:]]*,[[:space:]]*[0-9]*[[:space:]]*[,][[:space:]]*[0-9]*[[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 12, 0)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*12[[:space:]]*,[[:space:]]*0[[:space:]]*[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 12, 0, 0)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*12[[:space:]]*,[[:space:]]*0[[:space:]]*[,][[:space:]]*[0-9]*[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 12, 0, PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*12[[:space:]]*,[[:space:]]*0[[:space:]]*[,][[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.MacOSX, 12, 0, 0, PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]MacOSX[[:space:]]*,[[:space:]]*12[[:space:]]*,[[:space:]]*0[[:space:]]*[,][[:space:]]*[0-9]*[[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
./*.cs ./*/*.cs
}
## MacCatalyst
function MacCatalyst () {
# MacCatalyst is weird, because if there's an iOS attribute, and no Mac Catalyst attribute, then the Mac Catalyst attribute is implied from the iOS attribute.
# This becomes important when there's a Mac Catalyst attribute + NoiOS, because removing the Mac Catalyst attribute means completely removing the API from Mac Catalyst, which is wrong.
# This is too much of an analysis to get right from a shell script, so just don't remove any old Mac Catalyst attributes. Eventually we'll probably want to
# stop implying Mac Catalyst attributes from iOS attributes.
sed -i '' -E \
`## remove entire lines with only "[MacCatalyst (13|14,[0-9])]"` \
`# -e '/^[[:space:]]*[[][[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][]][[:space:]]*$/d'` \
`## remove entire lines with only "[MacCatalyst (13|14,[0-9])]" and then a comment` \
`# -e '/^[[:space:]]*[[][[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][]][[:space:]]*\/\/.*$/d'` \
`## remove "[MacCatalyst (13|14,[0-9])]"` \
`# -e 's/[[][[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][]][[:space:]]*//'` \
`## remove "[MacCatalyst (13|14,[0-9]),"` \
`# -e 's/[[][[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/[/'` \
`## remove ", MacCatalyst (13|14,[0-9])]"` \
`# -e 's/[[:space:]]*,[[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][[:space:]]*[]]/]/'` \
`## remove ", MacCatalyst (13|14,[0-9]), "` \
`# -e 's/[[:space:]]*,[[:space:]]*MacCatalyst[[:space:]]*[\(](13|14)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/, /'` \
\
`## remove entire lines with only "[MacCatalyst (15,0)]"` \
`# -e '/^[[:space:]]*[[][[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][]][[:space:]]*$/d'` \
`## remove entire lines with only "[MacCatalyst (15,0)]" and then a comment` \
`# -e '/^[[:space:]]*[[][[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][]][[:space:]]*\/\/.*$/d'` \
`## remove "[MacCatalyst (15,0)]"` \
`# -e 's/[[][[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][]][[:space:]]*//'` \
`## remove "[MacCatalyst (15,0),"` \
`# -e 's/[[][[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][[:space:]]*,[[:space:]]*/[/'` \
`## remove ", MacCatalyst (15,0)]"` \
`# -e 's/[[:space:]]*,[[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][[:space:]]*[]]/]/'` \
`## remove ", MacCatalyst (15,0), "` \
`# -e 's/[[:space:]]*,[[:space:]]*MacCatalyst[[:space:]]*[\(]15[,][[:space:]]*[0][\)][[:space:]]*,[[:space:]]*/, /'` \
\
`## replace "[MacCatalyst (13,0)]" with "[MacCatalyst (13,1)]"` \
`# -e 's/[[][[:space:]]*MacCatalyst[[:space:]]*[\(](13)[,][[:space:]]*0[\)][]]/[MacCatalyst (13, 1)]/'` \
\
`# SupportedOSPlatform ("maccatalyst[13|14].[0-9]") -> SupportedOSPlatform ("maccatalyst")` \
-e 's/SupportedOSPlatform [\(]"maccatalyst(13|14)[.][0-9]"[\)]/SupportedOSPlatform ("maccatalyst")/' \
`# SupportedOSPlatform ("maccatalyst15.0") -> SupportedOSPlatform ("maccatalyst")` \
-e 's/SupportedOSPlatform [\(]"maccatalyst15[.]0"[\)]/SupportedOSPlatform ("maccatalyst")/' \
\
./*.cs ./*/*.cs
}
## iOS
function iOS () {
sed -i '' -E \
`# remove entire lines with only "[iOS ([2-9]|10|11|,[0-9])]"` \
-e '/^[[:space:]]*[[][[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[iOS ([2-9]|10|11|,[0-9])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[iOS ([2-9]|10|11|,[0-9])]"` \
-e 's/[[][[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*//' \
`# remove "[iOS ([2-9]|10|11|,[0-9]),"` \
-e 's/[[][[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", iOS ([2-9]|10|11|,[0-9])]"` \
-e 's/[[:space:]]*,[[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*[]]/]/' \
`# remove ", iOS ([2-9]|10|11|,[0-9]), "` \
-e 's/[[:space:]]*,[[:space:]]*iOS[[:space:]]*[\(]([2-9]|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# remove entire lines with only "[iOS (12,[0-2])]"` \
-e '/^[[:space:]]*[[][[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[iOS (12,1,1])]"` \
-e '/^[[:space:]]*[[][[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[1][,][[:space:]]*[1][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[iOS (12,[0-2])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[iOS (12,[0-2])]"` \
-e 's/[[][[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*//' \
`# remove "[iOS (12,[0-2]),"` \
-e 's/[[][[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", iOS (12,[0-2])]"` \
-e 's/[[:space:]]*,[[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*[]]/]/' \
`# remove ", iOS (12,[0-2]), "` \
-e 's/[[:space:]]*,[[:space:]]*iOS[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# SupportedOSPlatform ("ios[7-10|11].[0-9]") -> SupportedOSPlatform ("ios")` \
-e 's/SupportedOSPlatform [\(]"ios(7|8|9|10|11)[.][0-9]"[\)]/SupportedOSPlatform ("ios")/' \
`# SupportedOSPlatform ("ios12.1.1") -> SupportedOSPlatform ("ios")` \
-e 's/SupportedOSPlatform [\(]"ios12[.]1[.]1"[\)]/SupportedOSPlatform ("ios")/' \
`# SupportedOSPlatform ("ios12.[0-2]") -> SupportedOSPlatform ("ios")` \
-e 's/SupportedOSPlatform [\(]"ios12[.][012]"[\)]/SupportedOSPlatform ("ios")/' \
\
`# [Introduced (PlatformName.iOS, [7-10|11], [0-9], PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]iOS[[:space:]]*,[[:space:]]*(7|8|9|10|11)[[:space:]]*[,][[:space:]]*[0-9][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]iOS[[:space:]]*,[[:space:]]*(7|8|9|10|11)[[:space:]]*[,][[:space:]]*[0-9][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*,[[:space:]]*null[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.iOS, 12, [0-2], PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]iOS[[:space:]]*,[[:space:]]*12[[:space:]]*[,][[:space:]]*[012][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]iOS[[:space:]]*,[[:space:]]*12[[:space:]]*[,][[:space:]]*[012][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*,[[:space:]]*null[[:space:]]*[\)][]][[:space:]]*$/d' \
\
./*.cs ./*/*.cs
}
## tvOS
function tvOS () {
sed -i '' -E \
`# remove entire lines with only "[TV (7-9|10|11|,[0-9])]"` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[TV (7-9|10|11|,[0-9],[0-9])]"` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][,][[:space:]]*[0-9][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[TV (7-9|10|11|,[0-9])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[TV (7-9|10|11|,[0-9])]"` \
-e 's/[[][[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][]][[:space:]]*//' \
`# remove "[TV (7-9|10|11|,[0-9]),"` \
-e 's/[[][[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", TV (7-9|10|11|,[0-9])]"` \
-e 's/[[:space:]]*,[[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*[]]/]/' \
`# remove ", TV (7-9|10|11|,[0-9]), "` \
-e 's/[[:space:]]*,[[:space:]]*TV[[:space:]]*[\(](7|8|9|10|11)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# remove entire lines with only "[TV (12,[0-2])]"` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[TV (12,1,1])]"` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[1][,][[:space:]]*[1][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[TV (12,[0-2])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[TV (12,[0-2])]"` \
-e 's/[[][[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][]][[:space:]]*//' \
`# remove "[TV (12,[0-2]),"` \
-e 's/[[][[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", TV (12,[0-2])]"` \
-e 's/[[:space:]]*,[[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*[]]/]/' \
`# remove ", TV (12,[0-2]), "` \
-e 's/[[:space:]]*,[[:space:]]*TV[[:space:]]*[\(]12[,][[:space:]]*[012][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# SupportedOSPlatform ("tvos[7-10|11].[0-9]") -> SupportedOSPlatform ("tvos")` \
-e 's/SupportedOSPlatform [\(]"tvos(7|8|9|10|11)[.][0-9]"[\)]/SupportedOSPlatform ("tvos")/' \
`# SupportedOSPlatform ("tvos12.1.1") -> SupportedOSPlatform ("ios")` \
-e 's/SupportedOSPlatform [\(]"tvos12[.]1[.]1"[\)]/SupportedOSPlatform ("tvos")/' \
`# SupportedOSPlatform ("tvos12.[0-2]") -> SupportedOSPlatform ("tvos")` \
-e 's/SupportedOSPlatform [\(]"tvos12[.][012]"[\)]/SupportedOSPlatform ("tvos")/' \
\
`# [Introduced (PlatformName.TvOS, [7-10|11], [0-9], PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]TvOS[[:space:]]*,[[:space:]]*(7|8|9|10|11)[[:space:]]*[,][[:space:]]*[0-9][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.TvOS, 12, [0-2], PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]TvOS[[:space:]]*,[[:space:]]*12[[:space:]]*[,][[:space:]]*[012][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
./*.cs ./*/*.cs
}
## watchOS
function watchOS () {
sed -i '' -E \
`# remove entire lines with only "[Watch ([2-3],[0-9])]"` \
-e '/^[[:space:]]*[[][[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[Watch ([2-3],[0-9])]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[Watch ([2-3],[0-9])"` \
-e 's/[[][[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][]][[:space:]]*//' \
`# remove "[Watch ([2-3],[0-9])"` \
-e 's/[[][[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", Watch ([2-3],[0-9])"` \
-e 's/[[:space:]]*,[[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][[:space:]]*[]]/]/' \
`# remove ", Watch ([2-3],[0-9]) "` \
-e 's/[[:space:]]*,[[:space:]]*Watch[[:space:]]*[\(](2|3)[,][[:space:]]*[0-9][\)][[:space:]]*,[[:space:]]*/, /' \
\
`# remove entire lines with only "[Watch (4,0)]"` \
-e '/^[[:space:]]*[[][[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][]][[:space:]]*$/d' \
`# remove entire lines with only "[Watch (4,0)]" and then a comment` \
-e '/^[[:space:]]*[[][[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][]][[:space:]]*\/\/.*$/d' \
`# remove "[Watch (4,0)"` \
-e 's/[[][[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][]][[:space:]]*//' \
`# remove "[Watch (4,0)"` \
-e 's/[[][[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][[:space:]]*,[[:space:]]*/[/' \
`# remove ", Watch (4,0)"` \
-e 's/[[:space:]]*,[[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][[:space:]]*[]]/]/' \
`# remove ", Watch (4,0) "` \
-e 's/[[:space:]]*,[[:space:]]*Watch[[:space:]]*[\(]4[,][[:space:]]*0[\)][[:space:]]*,[[:space:]]*/, /' \
\
`# [Introduced (PlatformName.WatchOS, [2-3], [0-9], PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]WatchOS[[:space:]]*,[[:space:]]*(2|3)[[:space:]]*[,][[:space:]]*[0-9][[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
`# [Introduced (PlatformName.WatchOS, 4, 0, PlatformArchitecture.All)] => delete` \
-e '/^[[:space:]]*[[][[:space:]]*Introduced[[:space:]]*[\(][[:space:]]*PlatformName[.]WatchOS[[:space:]]*,[[:space:]]*4[[:space:]]*[,][[:space:]]*0[[:space:]]*,[[:space:]]*PlatformArchitecture[.]All[[:space:]]*[\)][]][[:space:]]*$/d' \
\
./*.cs ./*/*.cs
}
#iOS
#tvOS
macOS
MacCatalyst
# other stuff
perl -p0 -i \
`# find and delete empty '#else ... #endif' blocks` \
-e 's/#else\n#endif/#endif/g;' \
\
`# find and delete empty '#if ... #endif' blocks` \
-e 's/\n\h*#if .*\n\h*#endif\h*\n/\n/g;' \
./*.cs ./*/*.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment