Skip to content

Update Xamarin.Messaging and renamed Xamarin paths #22803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,16 @@
</ItemGroup>
</Target>

<Target Name="_ComputeDotNetRoot">
<PropertyGroup>
<_DotNetRoot Condition="'$(IsMacEnabled)' == 'true'">$(_DotNetRootRemoteDirectory)</_DotNetRoot>
</PropertyGroup>
</Target>

<PropertyGroup>
<_AOTCompileDependsOn>
$(_AOTCompileDependsOn);
_ComputeDotNetRoot;
_ComputeVariables;
_FindAotCompiler;
_DetectAppManifest;
Expand Down Expand Up @@ -1288,6 +1295,7 @@
SdkIsSimulator="$(_SdkIsSimulator)"
SdkRoot="$(_SdkRoot)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
DotNetRoot="$(_DotNetRoot)"
>
</CompileNativeCode>

Expand Down Expand Up @@ -1429,6 +1437,7 @@
<PropertyGroup>
<_CompileNativeExecutableDependsOn>
$(_CompileNativeExecutableDependsOn);
_ComputeDotNetRoot;
_DetectSdkLocations;
_ComputeTargetArchitectures;
_GenerateBundleName;
Expand Down Expand Up @@ -1462,6 +1471,7 @@
SdkIsSimulator="$(_SdkIsSimulator)"
SdkRoot="$(_SdkRoot)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
DotNetRoot="$(_DotNetRoot)"
>
</CompileNativeCode>

Expand Down
2 changes: 1 addition & 1 deletion msbuild/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
https://dev.azure.com/azure-public/vside/_artifacts/feed/xamarin-impl/NuGet/Xamarin.Messaging.Client/

-->
<MessagingVersion Condition="'$(MessagingVersion)' == ''">[3.0.13]</MessagingVersion>
<MessagingVersion Condition="'$(MessagingVersion)' == ''">[18.0.108-gaffa6c07e5]</MessagingVersion>
<HotRestartVersion>[17.14.133-g001ce2ac7a]</HotRestartVersion>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)../Directory.Build.props" />
Expand Down
1 change: 1 addition & 0 deletions msbuild/ILMerge.targets
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'ILStrip'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'Newtonsoft.Json'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'Renci.SshNet'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'BouncyCastle.Cryptography'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'Merq'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'Merq.Core'" />
<MergedAssemblies Include="@(ReferencePath)" Condition="'%(FileName)' == 'SshNet.Security.Cryptography'" />
Expand Down
3 changes: 2 additions & 1 deletion msbuild/Messaging/Xamarin.Messaging.Build/BuildAgent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Messaging.Build.Contracts;
using Xamarin.Messaging.Client;
Expand Down Expand Up @@ -39,7 +40,7 @@ protected override Task InitializeAsync ()
return Task.FromResult (true);
}

protected override async Task RegisterCustomHandlersAsync (MessageHandlerManager manager)
protected override async Task RegisterCustomHandlersAsync (MessageHandlerManager manager, CancellationToken cancellationToken)
{
await TryRegisterHandlerAsync (new ExecuteTaskMessageHandler ())
.ConfigureAwait (continueOnCapturedContext: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CompareFilesMessageHandler : RequestHandler<CompareItemsMessage, Co
protected override async Task<CompareItemsResult> ExecuteAsync (CompareItemsMessage message)
{
return await Task.Run (() => {
var buildPath = Path.Combine (MessagingContext.GetBuildPath (), message.AppName, message.SessionId);
var buildPath = Path.Combine (MessagingContext.BuildsPath, message.AppName, message.SessionId);
var files = new List<string> ();

using (var hashAlgorithm = Hash.GetAlgorithm ()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected override async Task ExecuteAsync (CopyItemMessage message)
{
await Task.Run (async () => {
var targetPath = Path.GetFullPath (Path.Combine (
MessagingContext.GetBuildPath (),
MessagingContext.BuildsPath,
message.AppName,
message.SessionId,
PlatformPath.GetPathForCurrentPlatform (message.ItemSpec)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override async Task<ExecuteTaskResult> ExecuteAsync (ExecuteTaskMessag
var currentDirectory = Directory.GetCurrentDirectory ();

try {
var buildDirectory = Path.Combine (MessagingContext.GetBuildPath (), message.AppName, message.SessionId);
var buildDirectory = Path.Combine (MessagingContext.BuildsPath, message.AppName, message.SessionId);

Directory.CreateDirectory (buildDirectory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected override async Task<GetItemResult> ExecuteAsync (GetItemMessage messag
{
return await Task.Run<GetItemResult> (() => {
var targetPath = Path.GetFullPath (Path.Combine (
MessagingContext.GetBuildPath (),
MessagingContext.BuildsPath,
message.AppName,
message.SessionId,
PlatformPath.GetPathForCurrentPlatform (message.ItemSpec)));
Expand Down
14 changes: 13 additions & 1 deletion msbuild/Messaging/Xamarin.Messaging.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Messaging.Client;
using System.IO;

namespace Xamarin.Messaging.Build {
class Program {
Expand All @@ -10,7 +13,16 @@ static async Task Main (string [] args)
var agent = new BuildAgent (topicGenerator, arguments.Version, arguments.VersionInfo);
var runner = new AgentConsoleRunner<BuildAgent> (agent, arguments);

await runner.RunAsync ().ConfigureAwait (continueOnCapturedContext: false);
//Hack to support legacy paths from Windows (likely Dev17 versions)
var index = MessagingContext.BasePath.IndexOf ("Xamarin", StringComparison.Ordinal);

if (index >= 0) {
var xamarinPath = MessagingContext.BasePath.Substring (0, index + "Xamarin".Length);

MessagingContext.BuildsPath = Path.Combine (xamarinPath, "mtbs", "builds");
}

await runner.RunAsync (CancellationToken.None).ConfigureAwait (continueOnCapturedContext: false);
}
}
}
2 changes: 1 addition & 1 deletion msbuild/Messaging/Xamarin.Messaging.Build/TaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ExecuteTaskResult Execute (string taskName, string inputs)

void SetDotNetVariables ()
{
var xmaSdkRootPath = Path.Combine (MessagingContext.GetXmaPath (), "SDKs");
var xmaSdkRootPath = MessagingContext.SdksPath;
var xmaDotNetRootPath = Path.Combine (xmaSdkRootPath, "dotnet");
var xmaDotNetPath = default (string);

Expand Down
5 changes: 5 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@
</value>
</data>

<data name="M0169" xml:space="preserve">
<value>Adjusted path from '{0}' to '{1}'
</value>
</data>

<data name="E0169" xml:space="preserve">
<value>Unknown target framework identifier: {0}.
</value>
Expand Down
34 changes: 32 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileNativeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class CompileNativeCode : XamarinTask, ICancelableTask, ITaskCallback {

[Required]
public bool SdkIsSimulator { get; set; }

public string DotNetRoot { get; set; }
#endregion

public override bool Execute ()
Expand Down Expand Up @@ -108,8 +110,11 @@ public override bool Execute ()
arguments.Add (SdkRoot);

if (IncludeDirectories is not null) {
foreach (var inc in IncludeDirectories)
arguments.Add ("-I" + Path.GetFullPath (inc.ItemSpec));
foreach (var inc in IncludeDirectories) {
var incPath = GetIncludeDirectory (inc);

arguments.Add ("-I" + incPath);
}
}

var args = info.GetMetadata ("Arguments");
Expand Down Expand Up @@ -158,5 +163,30 @@ public void Cancel ()
if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (BuildEngine4).Wait ();
}

string GetIncludeDirectory (ITaskItem item)
{
var path = Path.GetFullPath (item.ItemSpec);

if (string.IsNullOrEmpty (DotNetRoot)) {
return path;
}

var packsIdentifier = "packs";
var dotnetPacksIdentifier = Path.Combine ("dotnet", packsIdentifier);

//If the directory points to a dotnet pack, we want to ensure the full path
//is actually pointing to a sub-folder in the dotnet SDK
if (path.Contains (dotnetPacksIdentifier) && !path.StartsWith (DotNetRoot)) {
var relativePath = path.Substring (path.IndexOf (packsIdentifier));
Comment on lines +180 to +181
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (path.Contains (dotnetPacksIdentifier) && !path.StartsWith (DotNetRoot)) {
var relativePath = path.Substring (path.IndexOf (packsIdentifier));
var identifierIdx = path.IndexOf (packsIdentifier, StringComparison.OrdinalIgnoreCase);
if (identifierIdx >= 0 && !path.StartsWith (DotNetRoot, StringComparison.OrdinalIgnoreCase)) {
var relativePath = path.Substring (identifierIdx);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in the path.Contains (dotnetPacksIdentifier) I'm looking for "dotnet/packs", whereas in the path.Substring (path.IndexOf (packsIdentifier)) I'm using just "packs". That's why I have two variables, dotnetPacksIdentifier and packsIdentifier.

I did this to be more sure that a given pack is indeed a dotnet pack. It felt safer to look for "dotnet/packs" in the path instead for just "packs".

Do you think that just looking for "packs" is safer enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, my issue was mostly that culture-aware comparisons aren't necessary, so this instead then:

Suggested change
if (path.Contains (dotnetPacksIdentifier) && !path.StartsWith (DotNetRoot)) {
var relativePath = path.Substring (path.IndexOf (packsIdentifier));
if (path.Contains (dotnetPacksIdentifier, StringComparison.Ordinal) && !path.StartsWith (DotNetRoot, StringComparison.Ordinal)) {
var relativePath = path.Substring (path.IndexOf (packsIdentifier, StringComparison.Ordinal));

//We combine the relative pack dir (starting from "packs") with the dotnet root to get the full path
var newPath = Path.Combine (DotNetRoot, relativePath);

Log.LogMessage (MessageImportance.Low, MSBStrings.M0169, path, newPath);
path = newPath;
}

return path;
}
}
}
3 changes: 1 addition & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CopyArchiveFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ async System.Threading.Tasks.Task<IBuildClient> GetBuildClientAsync ()

async System.Threading.Tasks.Task CopyArchiveAsync (ISshCommands sshCommands)
{
var serverHomeDirectory = await sshCommands.GetHomeDirectoryAsync ().ConfigureAwait (continueOnCapturedContext: false);
var buildPath = PlatformPath.GetServerBuildPath (serverHomeDirectory, AppName, SessionId, TargetPath);
var buildPath = PlatformPath.GetServerBuildPath (AppName, SessionId, TargetPath);

if (!Directory.Exists (buildPath)) {
await sshCommands.CreateDirectoryAsync (buildPath).ConfigureAwait (continueOnCapturedContext: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved.
DependsOnTargets="_SayHello"
BeforeTargets="_CleanDebugSymbols;_CleanAppBundle;_DetectAppManifest;_DetectSdkLocations;_GenerateBundleName" />

<!-- Default context path values for remote builds -->
<!-- When building from VS, these values will be passed directly from the IDE -->
<Target Name="EnsureMessagingContext" BeforeTargets="_SayHello">
<PropertyGroup>
<BasePath Condition="'$(BasePath)' == ''">~/Library/Caches/maui/PairToMac</BasePath>
<LogsPath Condition="'$(LogsPath)' == ''">~/Library/Logs</LogsPath>
<LocalBasePath Condition="'$(LocalBasePath)' == ''">%LOCALAPPDATA%\maui\iOS\PairToMac</LocalBasePath>
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these values read/used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Messaging libraries, but we don't want to hardcode values in Messaging, so we set them from either those targets or from VS.
They are mostly used in the SayHello task and SSH connection related logic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that code handle expanding ~ to $HOME?

</PropertyGroup>
</Target>

<PropertyGroup>
<CreateAppBundleDependsOn>
GetBundleResourceWithLogicalNameItems;
Expand Down
10 changes: 5 additions & 5 deletions tests/dotnet/Windows/collect-binlogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ fi
rm -f ~/remote_build_testing/windows-remote-logs.zip
zip -9r ~/remote_build_testing/windows-remote-logs.zip ~/remote_build_testing/binlogs

if test -d ~/Library/Caches/Xamarin/XMA/Agents/Build; then
find ~/Library/Caches/Xamarin/XMA/Agents/Build -type f -print0 | xargs -0 shasum -a 256 > ~/remote_build_testing/Agents_Build_Checksums.txt
if test -d ~/Library/Caches/maui/PairToMac/Agents/Build; then
find ~/Library/Caches/maui/PairToMac/Agents/Build -type f -print0 | xargs -0 shasum -a 256 > ~/remote_build_testing/Agents_Build_Checksums.txt
zip -9r ~/remote_build_testing/windows-remote-logs.zip ~/remote_build_testing/Agents_Build_Checksums.txt
fi

Expand All @@ -49,6 +49,6 @@ ps auxww > ~/remote_build_testing/processes.txt || true
# Collect any crash reports.
zip -9r ~/remote_build_testing/windows-remote-logs.zip ~/Library/Logs/DiagnosticReports || true

ls -la ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/ >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
cat ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/NuGet.config >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
cat ~/Library/Caches/Xamarin/XMA/SDKs/.home/.nuget/NuGet/NuGet.Config >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
ls -la ~/Library/Caches/maui/PairToMac/Sdks/dotnet/ >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
cat ~/Library/Caches/maui/PairToMac/Sdks/dotnet/NuGet.config >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
cat ~/Library/Caches/maui/PairToMac/Sdks/.home/.nuget/NuGet/NuGet.Config >> ~/remote_build_testing/dotnet-debug.txt 2>&1 || true
5 changes: 5 additions & 0 deletions tools/devops/automation/scripts/clean-for-remote-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ if du -hs ~/Library/Caches/Xamarin; then
rm -rf ~/Library/Caches/Xamarin
fi

# Make sure we don't have any old stuff installed
if du -hs ~/Library/Caches/maui; then
rm -rf ~/Library/Caches/maui
fi

# Clean up temporary logs
rm -rf /tmp/com.xamarin.*

Expand Down
14 changes: 7 additions & 7 deletions tools/devops/automation/scripts/prepare-for-remote-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ cd "$(dirname "${BASH_SOURCE[0]}")/../../../.."

# Install the local .NET we're using into XMA's directory
# (we can't point XMA to our local directory)
mkdir -p ~/Library/Caches/Xamarin/XMA/SDKs
cp -cRH ./builds/downloads/dotnet ~/Library/Caches/Xamarin/XMA/SDKs
sed '/local-tests-feed/d' ./NuGet.config > ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/NuGet.config
mkdir -p ~/Library/Caches/maui/PairToMac/Sdks
cp -cRH ./builds/downloads/dotnet ~/Library/Caches/maui/PairToMac/Sdks
sed '/local-tests-feed/d' ./NuGet.config > ~/Library/Caches/maui/PairToMac/Sdks/dotnet/NuGet.config

mkdir -p ~/Library/Caches/Xamarin/XMA/SDKs/.home/.nuget/NuGet/
cp ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/NuGet.config ~/Library/Caches/Xamarin/XMA/SDKs/.home/.nuget/NuGet/NuGet.Config
mkdir -p ~/Library/Caches/maui/PairToMac/Sdks/.home/.nuget/NuGet/
cp ~/Library/Caches/maui/PairToMac/Sdks/dotnet/NuGet.config ~/Library/Caches/maui/PairToMac/Sdks/.home/.nuget/NuGet/NuGet.Config

# some diagnostics
cat ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/NuGet.config
cd ~/Library/Caches/Xamarin/XMA/SDKs/dotnet/
cat ~/Library/Caches/maui/PairToMac/Sdks/dotnet/NuGet.config
cd ~/Library/Caches/maui/PairToMac/Sdks/dotnet/
./dotnet --info || true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ("$Env:DOTNET" -eq "") {
$Env:ServerAddress = $Env:MAC_AGENT_IP
$Env:ServerUser = $Env:MAC_AGENT_USER
$Env:ServerPassword = $Env:XMA_PASSWORD
$Env:_DotNetRootRemoteDirectory = "/Users/$Env:MAC_AGENT_USER/Library/Caches/Xamarin/XMA/SDKs/dotnet/"
$Env:_DotNetRootRemoteDirectory = "/Users/$Env:MAC_AGENT_USER/Library/Caches/maui/PairToMac/Sdks/dotnet/"

& $Env:DOTNET `
test `
Expand Down
Loading