Skip to content

Commit

Permalink
[tests] Ignore trailing slashes in NativeReference items. Fixes #15430.…
Browse files Browse the repository at this point in the history
… (#20567)

A `*.framework/` native reference and a `*.framework` reference are the same
thing, so treat them the same. We accomplish this by removing any trailing
path separators (both windows style and non-windows-style for consistency)
before doing any processing.

Fixes #15430.
  • Loading branch information
rolfbjarne committed May 20, 2024
1 parent 7e8e887 commit d6ddfce
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void ProcessSidecar (ITaskItem r, string resources, List<ITaskItem> native_frame
document.LoadXmlWithoutNetworkAccess (manifestContents);
foreach (XmlNode referenceNode in document.GetElementsByTagName ("NativeReference")) {
ITaskItem t = new TaskItem (r);
var name = referenceNode.Attributes ["Name"].Value;
var name = referenceNode.Attributes ["Name"].Value.Trim ('\\', '/');
switch (Path.GetExtension (name)) {
case ".xcframework": {
if (!TryResolveXCFramework (Log, TargetFrameworkMoniker, SdkIsSimulator, Architectures, resources, name, GetIntermediateDecompressionDir (resources), createdFiles, out var nativeLibraryPath))
Expand Down
2 changes: 1 addition & 1 deletion msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Copyright (C) 2020 Microsoft. All rights reserved.
</ItemGroup>
</Target>

<Target Name="_PrepareNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'">
<Target Name="_PrepareNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_SanitizeNativeReferences">
<PrepareNativeReferences
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Expand Down
16 changes: 15 additions & 1 deletion msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,25 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</PropertyGroup>
</Target>

<Target Name="_SanitizeNativeReferences">
<!-- Remove trailing slashes from native references, so that we treat '.framework' the same as '.framework/'.
Ref: https://github.com/xamarin/xamarin-macios/issues/15430
-->
<ItemGroup>
<NativeReference>
<IdentityWithoutPathSeparatorSuffix>$([System.String]::Copy('%(Identity)').TrimEnd('/').TrimEnd('\'))</IdentityWithoutPathSeparatorSuffix>
</NativeReference>
<NativeReferenceWithoutPathSeparatorSuffix Include="@(NativeReference->'%(IdentityWithoutPathSeparatorSuffix)')" />
<NativeReference Remove="@(NativeReference)" />
<NativeReference Include="@(NativeReferenceWithoutPathSeparatorSuffix)" />
</ItemGroup>
</Target>

<!--
@(NativeReference) are not safe to use as an Input to a task, as frameworks are a directory and will appears unbuilt every time.
So we split it into two camps as a prebuild step
-->
<Target Name="_ExpandNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName">
<Target Name="_ExpandNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName;_SanitizeNativeReferences">
<ItemGroup>
<_XCFrameworkNativeReference Include="@(NativeReference -> '%(Identity)/.')" Condition="'%(Extension)' == '.xcframework'" />
<_FrameworkNativeReference Include="@(NativeReference -> '%(Identity)/%(Filename)')" Condition="'%(Extension)' == '.framework'" />
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings-framework-test/dotnet/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<NoDSymUtil>true</NoDSymUtil>
<NoSymbolStrip>true</NoSymbolStrip>
</NativeReference>
<NativeReference Include="$(TestLibrariesDirectory)\.libs\$(NativeLibName)\XStaticObjectTest.framework">
<NativeReference Include="$(TestLibrariesDirectory)\.libs\$(NativeLibName)\XStaticObjectTest.framework\">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
<Frameworks>CoreLocation ModelIO</Frameworks>
Expand Down
2 changes: 1 addition & 1 deletion tests/bindings-xcframework-test/dotnet/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<TestLibrariesInput Include="$(TestLibrariesDirectory)\libframework.m" />
<TestLibrariesOutput Include="$(TestLibrariesDirectory)\.libs\XTest.xcframework" />

<NativeReference Include="$(TestLibrariesDirectory)\.libs\XTest.xcframework">
<NativeReference Include="$(TestLibrariesDirectory)\.libs\XTest.xcframework/">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
<Frameworks>CoreLocation ModelIO</Frameworks>
Expand Down

3 comments on commit d6ddfce

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.