From 19c23d12083011cd942ddf0acd0cd6b8e12ec501 Mon Sep 17 00:00:00 2001 From: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:33:37 +0200 Subject: [PATCH] Add mono to mac OS 13 image (#8342) --- images/macos/provision/core/mono.sh | 54 +++++++++++++++++++ .../SoftwareReport.Generator.ps1 | 6 ++- images/macos/templates/macOS-13.anka.pkr.hcl | 1 + .../templates/macOS-13.arm64.anka.pkr.hcl | 1 + images/macos/tests/Xamarin.Tests.ps1 | 32 ++++++----- images/macos/toolsets/toolset-13.json | 8 +++ 6 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 images/macos/provision/core/mono.sh diff --git a/images/macos/provision/core/mono.sh b/images/macos/provision/core/mono.sh new file mode 100644 index 000000000..f4052a252 --- /dev/null +++ b/images/macos/provision/core/mono.sh @@ -0,0 +1,54 @@ +#!/bin/bash -e -o pipefail + +################################################################################ +## File: mono.sh +## Desc: Installs Mono Framework +################################################################################ + +# Source utility functions +source ~/utils/utils.sh + +# Create a temporary directory to store downloaded files +TMP_DIR=$(mktemp -d /tmp/visualstudio.XXXX) + +# Install Mono Framework +MONO_VERSION_FULL=$(get_toolset_value '.mono.framework.version') +MONO_VERSION=$(echo "$MONO_VERSION_FULL" | cut -d. -f 1,2,3) +MONO_VERSION_SHORT=$(echo $MONO_VERSION_FULL | cut -d. -f 1,2) +MONO_PKG_URL="https://download.mono-project.com/archive/${MONO_VERSION}/macos-10-universal/MonoFramework-MDK-${MONO_VERSION_FULL}.macos10.xamarin.universal.pkg" +MONO_PKG_NAME=${MONO_PKG_URL##*/} +MONO_VERSIONS_PATH='/Library/Frameworks/Mono.framework/Versions' + +download_with_retries "$MONO_PKG_URL" "$TMP_DIR" +echo "Installing $MONO_PKG_NAME..." +sudo installer -pkg "$TMP_DIR/$MONO_PKG_NAME" -target / + +# Download and install NUnit console +NUNIT_VERSION=$(get_toolset_value '.mono.nunit.version') +NUNIT_ARCHIVE_URL="https://github.com/nunit/nunit-console/releases/download/${NUNIT_VERSION}/NUnit.Console-${NUNIT_VERSION}.zip" +NUNIT_ARCHIVE_NAME=${NUNIT_ARCHIVE_URL##*/} +NUNIT_PATH="/Library/Developer/nunit" +NUNIT_VERSION_PATH="$NUNIT_PATH/$NUNIT_VERSION" + +download_with_retries "$NUNIT_ARCHIVE_URL" "$TMP_DIR" +echo "Installing $NUNIT_ARCHIVE_NAME..." +sudo mkdir -p "$NUNIT_VERSION_PATH" +sudo unzip -q "$TMP_DIR/$NUNIT_ARCHIVE_NAME" -d "$NUNIT_VERSION_PATH" + +# Create a wrapper script for nunit3-console +echo "Creating nunit3-console wrapper..." +NUNIT3_CONSOLE_WRAPPER=nunit3-console +cat < "${TMP_DIR}/${NUNIT3_CONSOLE_WRAPPER}" +#!/bin/bash -e -o pipefail +exec ${MONO_VERSIONS_PATH}/${MONO_VERSION}/bin/mono --debug \$MONO_OPTIONS $NUNIT_VERSION_PATH/nunit3-console.exe "\$@" +EOF +cat "${TMP_DIR}/${NUNIT3_CONSOLE_WRAPPER}" +sudo chmod +x "${TMP_DIR}/${NUNIT3_CONSOLE_WRAPPER}" +sudo mv "${TMP_DIR}/${NUNIT3_CONSOLE_WRAPPER}" "${MONO_VERSIONS_PATH}/${MONO_VERSION}/Commands/${NUNIT3_CONSOLE_WRAPPER}" + +# Create a symlink for the short version of Mono (e.g., 6.12) +echo "Creating short symlink '${MONO_VERSION_SHORT}'..." +sudo ln -s "${MONO_VERSIONS_PATH}/${MONO_VERSION}" "${MONO_VERSIONS_PATH}/${MONO_VERSION_SHORT}" + +# Invoke tests for Xamarin and Mono +invoke_tests "Xamarin" "Mono" diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 5032c798f..f75ec124b 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -42,7 +42,9 @@ $languageAndRuntime.AddToolVersion("Julia", $(Get-JuliaVersion)) $languageAndRuntime.AddToolVersion("Kotlin", $(Get-KotlinVersion)) if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { $languageAndRuntime.AddToolVersion("Go", $(Get-GoVersion)) - $languageAndRuntime.AddToolVersion("Mono", $(Get-MonoVersion)) +} +$languageAndRuntime.AddToolVersion("Mono", $(Get-MonoVersion)) +if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { $languageAndRuntime.AddToolVersion("MSBuild", $(Get-MSBuildVersion)) $languageAndRuntime.AddToolVersion("Node.js", $(Get-NodeVersion)) $languageAndRuntime.AddToolVersion("NVM", $(Get-NVMVersion)) @@ -74,8 +76,8 @@ if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { $packageManagement.AddToolVersion("Miniconda", $(Get-CondaVersion)) } $packageManagement.AddToolVersion("NPM", $(Get-NPMVersion)) +$packageManagement.AddToolVersion("NuGet", $(Get-NuGetVersion)) if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { - $packageManagement.AddToolVersion("NuGet", $(Get-NuGetVersion)) $packageManagement.AddToolVersion("Pip", $(Get-PipVersion -Version 2)) } diff --git a/images/macos/templates/macOS-13.anka.pkr.hcl b/images/macos/templates/macOS-13.anka.pkr.hcl index f9628ce05..3b8f36495 100644 --- a/images/macos/templates/macOS-13.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.anka.pkr.hcl @@ -162,6 +162,7 @@ build { scripts = [ "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", + "./provision/core/mono.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", "./provision/core/azcopy.sh", diff --git a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl index 69986ec23..78d7450e2 100644 --- a/images/macos/templates/macOS-13.arm64.anka.pkr.hcl +++ b/images/macos/templates/macOS-13.arm64.anka.pkr.hcl @@ -163,6 +163,7 @@ build { pause_before = "30s" scripts = [ "./provision/core/powershell.sh", + "./provision/core/mono.sh", "./provision/core/dotnet.sh", "./provision/core/azcopy.sh", "./provision/core/openssl.sh", diff --git a/images/macos/tests/Xamarin.Tests.ps1 b/images/macos/tests/Xamarin.Tests.ps1 index e610dbba8..789aa656d 100644 --- a/images/macos/tests/Xamarin.Tests.ps1 +++ b/images/macos/tests/Xamarin.Tests.ps1 @@ -2,11 +2,17 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -DisableNameChecking $os = Get-OSVersion -if ((-not $os.IsVentura) -and (-not $os.IsVenturaArm64)) { +if ($os.IsVentura -or $os.IsVenturaArm64) { + $MONO_VERSIONS = @(Get-ToolsetValue "mono.framework.version") + $XAMARIN_IOS_VERSIONS = @() + $XAMARIN_MAC_VERSIONS = @() + $XAMARIN_ANDROID_VERSIONS = @() +} elseif ($os.IsBigSur -or $os.IsMonterey) { $MONO_VERSIONS = Get-ToolsetValue "xamarin.mono-versions" $XAMARIN_IOS_VERSIONS = Get-ToolsetValue "xamarin.ios-versions" $XAMARIN_MAC_VERSIONS = Get-ToolsetValue "xamarin.mac-versions" $XAMARIN_ANDROID_VERSIONS = Get-ToolsetValue "xamarin.android-versions" +} BeforeAll { function Get-ShortSymlink { @@ -19,7 +25,7 @@ BeforeAll { } } -Describe "Mono" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { +Describe "Mono" { $MONO_VERSIONS | ForEach-Object { Context "$_" { $MONO_VERSIONS_PATH = "/Library/Frameworks/Mono.framework/Versions" @@ -116,12 +122,12 @@ Describe "Xamarin.iOS" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { } } -Describe "Xamarin.Mac" -Skip:($os.IsVentura-or $os.IsVenturaArm64) { +Describe "Xamarin.Mac" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { $XAMARIN_MAC_VERSIONS | ForEach-Object { Context "$_" { $XAMARIN_MAC_VERSIONS_PATH = "/Library/Frameworks/Xamarin.Mac.framework/Versions" $versionFolderPath = Join-Path $XAMARIN_MAC_VERSIONS_PATH $_ - $testCase = @{ XamarinMacVersion = $_; VersionFolderPath = $versionFolderPath; MacVersionsPath = $XAMARIN_MAC_VERSIONS_PATH } + $testCase = @{ XamarinMacVersion = $_; VersionFolderPath = $versionFolderPath; MacVersionsPath = $XAMARIN_MAC_VERSIONS_PATH } It "is installed" -TestCases $testCase { param ( [string] $VersionFolderPath ) @@ -197,28 +203,30 @@ Describe "Xamarin Bundles" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { $XAMARIN_ANDROID_VERSIONS_PATH = "/Library/Frameworks/Xamarin.Android.framework/Versions" } + If ($XAMARIN_BUNDLES.Count -eq 0) { return } # Skip this test if there are no bundles + [array]$XAMARIN_BUNDLES = Get-ToolsetValue "xamarin.bundles" $XAMARIN_DEFAULT_BUNDLE = Get-ToolsetValue "xamarin.bundle-default" If ($XAMARIN_DEFAULT_BUNDLE -eq "latest") { $XAMARIN_DEFAULT_BUNDLE = $XAMARIN_BUNDLES[0].symlink } $currentBundle = [PSCustomObject] @{ symlink = "Current" - mono = $XAMARIN_DEFAULT_BUNDLE - ios = $XAMARIN_DEFAULT_BUNDLE - mac = $XAMARIN_DEFAULT_BUNDLE + mono = $XAMARIN_DEFAULT_BUNDLE + ios = $XAMARIN_DEFAULT_BUNDLE + mac = $XAMARIN_DEFAULT_BUNDLE android = $XAMARIN_DEFAULT_BUNDLE } $latestBundle = [PSCustomObject] @{ symlink = "Latest" - mono = $XAMARIN_BUNDLES[0].mono - ios = $XAMARIN_BUNDLES[0].ios - mac = $XAMARIN_BUNDLES[0].mac + mono = $XAMARIN_BUNDLES[0].mono + ios = $XAMARIN_BUNDLES[0].ios + mac = $XAMARIN_BUNDLES[0].mac android = $XAMARIN_BUNDLES[0].android } $bundles = $XAMARIN_BUNDLES + $currentBundle + $latestBundle - $allBundles = $bundles | ForEach-Object { @{BundleSymlink = $_.symlink; BundleMono = $_.mono; BundleIos = $_.ios; BundleMac = $_.mac; BundleAndroid = $_.android} } + $allBundles = $bundles | ForEach-Object { @{BundleSymlink = $_.symlink; BundleMono = $_.mono; BundleIos = $_.ios; BundleMac = $_.mac; BundleAndroid = $_.android } } It "Mono symlink exists" -TestCases $allBundles { param ( [string] $BundleSymlink ) @@ -299,5 +307,3 @@ Describe "Nuget" -Skip:($os.IsVentura -or $os.IsVenturaArm64) { Get-Content $env:HOME/.config/NuGet/NuGet.Config | Out-String | Should -Match "nuget.org" } } - -} \ No newline at end of file diff --git a/images/macos/toolsets/toolset-13.json b/images/macos/toolsets/toolset-13.json index 73650b768..cdc1b7570 100644 --- a/images/macos/toolsets/toolset-13.json +++ b/images/macos/toolsets/toolset-13.json @@ -204,5 +204,13 @@ }, "php": { "version": "8.2" + }, + "mono": { + "framework":{ + "version": "6.12.0.188" + }, + "nunit": { + "version": "3.15.4" + } } }