Skip to content

Commit

Permalink
[net8.0] Merge main into net8.0. (xamarin#18465)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Jun 20, 2023
2 parents 89f069d + a192eed commit 6c32a1e
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 45 deletions.
44 changes: 29 additions & 15 deletions .github/workflows/backport-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@ on:
types: [created]

jobs:
launchBackportBuild:
setupBackport:
runs-on: ubuntu-latest
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/sudo backport')

if: github.event.issue.pull_request != '' && startswith(github.event.comment.body, '/sudo backport')
outputs:
target_branch: ${{ steps.parse_comment.outputs.target_branch }}
steps:
- uses: xamarin/[email protected]
with:
pull_request_url: ${{ github.event.issue.pull_request.url }}
comment_body: ${{ github.event.comment.body }}
comment_author: ${{ github.actor }}
github_repository: ${{ github.repository }}
ado_organization: ${{ secrets.ADO_PROJECTCOLLECTION }}
ado_project: ${{ secrets.ADO_PROJECT }}
backport_pipeline_id: ${{ secrets.BACKPORT_PIPELINEID }}
ado_build_pat: ${{ secrets.ADO_BUILDPAT }}
github_account_pat: ${{ secrets.SERVICEACCOUNT_PAT }}
use_fork: true
- name: Parse Comment
id: parse_comment
run: |
Write-Host "Parsing $env:COMMENT"
($botName, $backport, $backportTargetBranch) = [System.Text.RegularExpressions.Regex]::Split("$env:COMMENT", "\s+")
echo "::set-output name=target_branch::$backportTargetBranch"
shell: pwsh
env:
COMMENT: "${{ github.event.comment.body }}"

launchBackportBuild:
needs: setupBackport
uses: xamarin/backport-bot-action/.github/workflows/[email protected]
with:
pull_request_url: ${{ github.event.issue.pull_request.url }}
target_branch: ${{ needs.setupBackport.outputs.target_branch }}
comment_author: ${{ github.actor }}
github_repository: ${{ github.repository }}
use_fork: true
secrets:
ado_organization: ${{ secrets.ADO_PROJECTCOLLECTION }}
ado_project: ${{ secrets.ADO_PROJECT }}
backport_pipeline_id: ${{ secrets.BACKPORT_PIPELINEID }}
ado_build_pat: ${{ secrets.ADO_BUILDPAT }}
github_account_pat: ${{ secrets.SERVICEACCOUNT_PAT }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<_DotNetRootRemoteDirectory Condition="$(_DotNetRootRemoteDirectory) == ''">/usr/local/share/dotnet/</_DotNetRootRemoteDirectory>
<_XamarinSdkRootDirectoryOnMac Condition="'$(_XamarinSdkRootDirectory)' != ''">$(_XamarinSdkRootDirectory.Replace('$(NetCoreRoot)', '$(_DotNetRootRemoteDirectory)'))</_XamarinSdkRootDirectoryOnMac>
<_MlaunchPath Condition="'$(_MlaunchPath)' == ''">$(_XamarinSdkRootDirectoryOnMac)tools/bin/mlaunch</_MlaunchPath>
<MlaunchPath Condition="'$(MlaunchPath)' == ''">$(_XamarinSdkRootDirectoryOnMac)tools/bin/mlaunch</MlaunchPath>
<AfterMicrosoftNETSdkTargets>$(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)..\targets\Microsoft.iOS.Windows.Sdk.targets</AfterMicrosoftNETSdkTargets>

<_XamarinSdkRootOnMac Condition="'$(_XamarinSdkRoot)' != ''">$(_XamarinSdkRoot.Replace('$(NetCoreRoot)', '$(_DotNetRootRemoteDirectory)'))</_XamarinSdkRootOnMac>
Expand Down
56 changes: 44 additions & 12 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1751,34 +1751,51 @@
<!-- Install & Run -->

<PropertyGroup>
<_MlaunchPath Condition="'$(_MlaunchPath)' == ''">$(_XamarinSdkRootDirectory)tools\bin\mlaunch</_MlaunchPath>
<!-- We used to use '_MlaunchPath' as the property name, but we've made it public, so it's MlaunchPath now, but keep setting/supporting the underscored version for a while -->
<MlaunchPath Condition="'$(MlaunchPath)' == '' And '$(_MlaunchPath)' != ''">$(_MlaunchPath)</MlaunchPath>
<MlaunchPath Condition="'$(MlaunchPath)' == ''">$(_XamarinSdkRootDirectory)tools\bin\mlaunch</MlaunchPath>
<_MlaunchPath Condition="'$(_MlaunchPath)' == ''">$(MlaunchPath)</_MlaunchPath>
</PropertyGroup>

<Target Name="_InstallMobile" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName" Condition="'$(_SdkIsSimulator)' == 'false'">
<Target Name="ComputeMlaunchInstallArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest;_ComputeMlaunchInstallArguments" />
<Target Name="_ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false'">
<!-- Launching from the command line on windows hasn't been implemented: https://github.com/xamarin/xamarin-macios/issues/16609 -->
<Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." />
<Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." />

<GetMlaunchArguments
SessionId="$(BuildSessionId)"
AppBundlePath="$(_AppBundlePath)"
AppManifestPath="$(_AppBundleManifestPath)"
DeviceName="$(_DeviceName)"
InstallApp="$(_AppBundlePath)"
MlaunchPath="$(_MlaunchPath)"
MlaunchPath="$(MlaunchPath)"
SdkDevPath="$(_SdkDevPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkVersion="$(_SdkVersion)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
<Output TaskParameter="MlaunchArguments" PropertyName="_MlaunchInstallArguments" />
<Output TaskParameter="MlaunchArguments" PropertyName="MlaunchInstallArguments" />
</GetMlaunchArguments>

<Exec SessionId="$(BuildSessionId)" Command="$(_MlaunchPath) $(_MlaunchInstallArguments)" />
<WriteLinesToFile
File="$(MlaunchInstallScript)"
Lines="$(MlaunchPath) $(MlaunchInstallArguments)"
Overwrite="true"
WriteOnlyWhenDifferent="true"
Condition="'$(MlaunchInstallScript)' != ''"
/>
</Target>

<!-- This is only needed for mobile platforms, RunCommand and RunArguments are defined for macOS in Microsoft.macOS.Sdk.targets. -->
<Target Name="_PrepareRunMobile" DependsOnTargets="_InstallMobile" Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">
<Target Name="_InstallMobile" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;ComputeMlaunchInstallArguments" Condition="'$(_SdkIsSimulator)' == 'false'">
<Exec SessionId="$(BuildSessionId)" Command="$(MlaunchPath) $(MlaunchInstallArguments)" />
</Target>

<Target Name="ComputeMlaunchRunArguments" DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;_DetectAppManifest" Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">
<!-- Launching from the command line on windows hasn't been implemented: https://github.com/xamarin/xamarin-macios/issues/16609 -->
<Error Condition="$([MSBuild]::IsOSPlatform('windows'))" Text="It's currently not supported to launch an app from the command line on Windows." />
<Error Condition="!Exists('$(_AppBundleManifestPath)')" Text="The app must be built before the arguments to launch the app using mlaunch can be computed." />

<PropertyGroup>
<!-- capture output by default -->
<_MlaunchCaptureOutput Condition="'$(_MlaunchCaptureOutput)' == ''">true</_MlaunchCaptureOutput>
Expand All @@ -1803,7 +1820,7 @@
DeviceName="$(_DeviceName)"
EnvironmentVariables="@(MlaunchEnvironmentVariables)"
LaunchApp="$(_AppBundlePath)"
MlaunchPath="$(_MlaunchPath)"
MlaunchPath="$(MlaunchPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkDevPath="$(_SdkDevPath)"
SdkVersion="$(_SdkVersion)"
Expand All @@ -1812,12 +1829,23 @@
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
WaitForExit="$(_MlaunchWaitForExit)"
>
<Output TaskParameter="MlaunchArguments" PropertyName="_MlaunchRunArguments" />
<Output TaskParameter="MlaunchArguments" PropertyName="MlaunchRunArguments" />
</GetMlaunchArguments>

<WriteLinesToFile
File="$(MlaunchRunScript)"
Lines="$(MlaunchPath) $(MlaunchRunArguments)"
Overwrite="true"
WriteOnlyWhenDifferent="true"
Condition="'$(MlaunchRunScript)' != ''"
/>
</Target>

<!-- This is only needed for mobile platforms, RunCommand and RunArguments are defined for macOS in Microsoft.macOS.Sdk.targets. -->
<Target Name="_PrepareRunMobile" DependsOnTargets="_InstallMobile;ComputeMlaunchRunArguments" Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">
<PropertyGroup>
<RunCommand>$(_MlaunchPath)</RunCommand>
<RunArguments>$(_MlaunchRunArguments)</RunArguments>
<RunCommand>$(MlaunchPath)</RunCommand>
<RunArguments>$(MlaunchRunArguments)</RunArguments>
</PropertyGroup>
</Target>

Expand Down Expand Up @@ -1898,7 +1926,11 @@ global using nfloat = global::System.Runtime.InteropServices.NFloat%3B
</ItemGroup>
</Target>

<Target Name="_CopyLocalBindingResources" AfterTargets="ResolveAssemblyReferences" BeforeTargets="CopyFilesToOutputDirectory">
<Target Name="_CopyLocalBindingResources"
AfterTargets="ResolveAssemblyReferences"
BeforeTargets="CopyFilesToOutputDirectory"
Condition="'$(_DisableCopyLocalBindingResources)' != 'true'"
>
<!--
We need to copy binding resource packages (either zipped or as a
Expand Down
12 changes: 10 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ namespace Xamarin.MacDev.Tasks {
public class Zip : ZipTaskBase, ITaskCallback {
public override bool Execute ()
{
if (ShouldExecuteRemotely ())
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
if (ShouldExecuteRemotely ()) {
var taskRunner = new TaskRunner (SessionId, BuildEngine4);
var rv = taskRunner.RunAsync (this).Result;

// Copy the zipped file back to Windows.
if (rv)
taskRunner.GetFileAsync (this, OutputFile.ItemSpec).Wait ();

return rv;
}

return base.Execute ();
}
Expand Down
12 changes: 12 additions & 0 deletions src/avfoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ interface MTAudioProcessingTap {}
delegate void AVAssetImageGeneratorCompletionHandler (CMTime requestedTime, IntPtr imageRef, CMTime actualTime, AVAssetImageGeneratorResult result, NSError error);
delegate void AVAssetImageGeneratorCompletionHandler2 (CMTime requestedTime, CGImage imageRef, CMTime actualTime, AVAssetImageGeneratorResult result, NSError error);
#endif
delegate void AVAssetImageGenerateAsynchronouslyForTimeCompletionHandler (CGImage imageRef, CMTime actualTime, NSError error);
delegate void AVCompletion (bool finished);
delegate void AVRequestAccessStatus (bool accessGranted);
delegate AVAudioBuffer AVAudioConverterInputHandler (uint inNumberOfPackets, out AVAudioConverterInputStatus outStatus);
Expand Down Expand Up @@ -4034,6 +4035,10 @@ interface AVAssetImageGenerator {
[Export ("initWithAsset:")]
NativeHandle Constructor (AVAsset asset);

[Deprecated (PlatformName.MacOSX, 13, 0, message: "Use the 'GenerateCGImagesAsynchronously' method instead.")]
[Deprecated (PlatformName.TvOS, 16, 0, message: "Use the 'GenerateCGImagesAsynchronously' method instead.")]
[Deprecated (PlatformName.iOS, 16, 0, message: "Use the 'GenerateCGImagesAsynchronously' method instead.")]
[Deprecated (PlatformName.MacCatalyst, 16, 0, message: "Use the 'GenerateCGImagesAsynchronously' method instead.")]
[Export ("copyCGImageAtTime:actualTime:error:")]
[return: NullAllowed]
[return: Release ()]
Expand All @@ -4048,6 +4053,13 @@ interface AVAssetImageGenerator {
void GenerateCGImagesAsynchronously (NSValue [] cmTimesRequestedTimes, AVAssetImageGeneratorCompletionHandler2 handler);
#endif

[iOS (16, 0)]
[Mac (13, 0)]
[MacCatalyst (16, 0)]
[TV (16, 0)]
[Export ("generateCGImageAsynchronouslyForTime:completionHandler:")]
void GenerateCGImageAsynchronously (CMTime requestedTime, AVAssetImageGenerateAsynchronouslyForTimeCompletionHandler handler);

[Export ("cancelAllCGImageGeneration")]
void CancelAllCGImageGeneration ();

Expand Down
5 changes: 4 additions & 1 deletion src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,10 @@ public TrampolineInfo MakeTrampoline (Type t)

if (TypeManager.INativeObject.IsAssignableFrom (pi.ParameterType)) {
pars.Add (new TrampolineParameterInfo (NativeHandleType, safe_name));
invoke.AppendFormat ("new {0} ({1}, false)", pi.ParameterType, safe_name);
if (BindThirdPartyLibrary)
invoke.AppendFormat ("Runtime.GetINativeObject<{0}> ({1}, false)!", pi.ParameterType, safe_name);
else
invoke.AppendFormat ("{1} == IntPtr.Zero ? null! : new {0} ({1}, false)", pi.ParameterType, safe_name);
continue;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/common/BinLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ public static bool TryFindPropertyValue (string binlog, string property, [NotNul
var dict = pefea.Properties as IDictionary<string, string>;
if (dict is not null && dict.TryGetValue (property, out var pvalue))
value = pvalue;
} else if (args is BuildMessageEventArgs bmea) {
if (bmea.Message.StartsWith ("Output Property: ", StringComparison.Ordinal)) {
var kvp = bmea.Message.Substring ("Output Property: ".Length);
var eq = kvp.IndexOf ('=');
if (eq > 0) {
var propname = kvp.Substring (0, eq);
var propvalue = kvp.Substring (eq + 1);
if (propname == property)
value = propvalue;
}
}
}
}

Expand Down
97 changes: 97 additions & 0 deletions tests/dotnet/UnitTests/MlaunchTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text;

using Mono.Cecil;

using Xamarin.Tests;

#nullable enable

namespace Xamarin.Tests {
[TestFixture]
public class MlaunchTest : TestBaseClass {
[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64")]
public void GetMlaunchInstallArguments (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);

var outputPath = Path.Combine (Cache.CreateTemporaryDirectory (), "install.sh");
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["EnableCodeSigning"] = "false"; // Skip code signing, since that would require making sure we have code signing configured on bots.

// Create the app manifest first, since it's required to compute the mlaunch install arguments
DotNet.Execute ("build", project_path, properties, target: "_DetectSdkLocations;_DetectAppManifest;_CompileAppManifest;_WriteAppManifest");

properties ["MlaunchInstallScript"] = outputPath;
var rv = DotNet.Execute ("build", project_path, properties, target: "ComputeMlaunchInstallArguments");

if (!BinLog.TryFindPropertyValue (rv.BinLogPath, "MlaunchInstallArguments", out var mlaunchInstallArguments))
Assert.Fail ("Could not find the property 'MlaunchInstallArguments' in the binlog.");

if (!BinLog.TryFindPropertyValue (rv.BinLogPath, "MlaunchPath", out var mlaunchPath))
Assert.Fail ("Could not find the property 'MlaunchPath' in the binlog.");
Assert.That (mlaunchPath, Does.Exist, "mlaunch existence");

var expectedArguments = new StringBuilder ();
expectedArguments.Append ("--installdev ");
expectedArguments.Append (appPath.Substring (Path.GetDirectoryName (project_path)!.Length + 1)).Append ('/');
expectedArguments.Append ($" --wait-for-exit:false");
Assert.AreEqual (expectedArguments.ToString (), mlaunchInstallArguments);

var scriptContents = File.ReadAllText (outputPath).Trim ('\n');
var expectedScriptContents = mlaunchPath + " " + expectedArguments.ToString ();
Assert.AreEqual (expectedScriptContents, scriptContents, "Script contents");
}

[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-x64;iossimulator-arm64", ":v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-16-4,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro")]
[TestCase (ApplePlatform.iOS, "ios-arm64", "")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm64", ":v2:runtime=com.apple.CoreSimulator.SimRuntime.tvOS-16-4,devicetype=com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-1080p")]
public void GetMlaunchRunArguments (ApplePlatform platform, string runtimeIdentifiers, string device)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);

var outputPath = Path.Combine (Cache.CreateTemporaryDirectory (), "launch.sh");
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["EnableCodeSigning"] = "false"; // Skip code signing, since that would require making sure we have code signing configured on bots.

// Create the app manifest first, since it's required to compute the mlaunch run arguments
DotNet.Execute ("build", project_path, properties, target: "_DetectSdkLocations;_DetectAppManifest;_CompileAppManifest;_WriteAppManifest");

properties ["MlaunchRunScript"] = outputPath;
var rv = DotNet.Execute ("build", project_path, properties, target: "ComputeMlaunchRunArguments");

if (!BinLog.TryFindPropertyValue (rv.BinLogPath, "MlaunchRunArguments", out var mlaunchRunArguments))
Assert.Fail ("Could not find the property 'MlaunchRunArguments' in the binlog.");

if (!BinLog.TryFindPropertyValue (rv.BinLogPath, "MlaunchPath", out var mlaunchPath))
Assert.Fail ("Could not find the property 'MlaunchPath' in the binlog.");
Assert.That (mlaunchPath, Does.Exist, "mlaunch existence");

var expectedArguments = new StringBuilder ();
var isSim = runtimeIdentifiers.Contains ("simulator");
expectedArguments.Append (isSim ? "--launchsim " : "--launchdev ");
expectedArguments.Append (appPath.Substring (Path.GetDirectoryName (project_path)!.Length + 1)).Append ('/');
if (isSim) {
expectedArguments.Append (" --device \"");
expectedArguments.Append (device);
expectedArguments.Append ('"');
}
expectedArguments.Append ($" --wait-for-exit:true");
Assert.AreEqual (expectedArguments.ToString (), mlaunchRunArguments);

var scriptContents = File.ReadAllText (outputPath).Trim ('\n');
var expectedScriptContents = mlaunchPath + " " + expectedArguments.ToString ();
Assert.AreEqual (expectedScriptContents, scriptContents, "Script contents");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
!deprecated-attribute-missing! AVAsset::tracksWithMediaType: missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAsset::trackWithTrackID: missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAsset::unusedTrackID missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAssetImageGenerator::copyCGImageAtTime:actualTime:error: missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAssetTrack::associatedTracksOfType: missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAssetTrack::metadataForFormat: missing a [Deprecated] attribute
!deprecated-attribute-missing! AVAssetTrack::samplePresentationTimeForTrackTime: missing a [Deprecated] attribute
Expand Down Expand Up @@ -74,7 +73,6 @@
!missing-selector! +NSValue::valueWithCMVideoDimensions: not bound
!missing-selector! AVAssetExportSession::audioTrackGroupHandling not bound
!missing-selector! AVAssetExportSession::setAudioTrackGroupHandling: not bound
!missing-selector! AVAssetImageGenerator::generateCGImageAsynchronouslyForTime:completionHandler: not bound
!missing-selector! AVAssetPlaybackAssistant::loadPlaybackConfigurationOptionsWithCompletionHandler: not bound
!missing-selector! AVAssetResourceLoadingContentInformationRequest::isEntireLengthAvailableOnDemand not bound
!missing-selector! AVAssetResourceLoadingContentInformationRequest::setEntireLengthAvailableOnDemand: not bound
Expand Down
Loading

0 comments on commit 6c32a1e

Please sign in to comment.