[msbuild] Copy binding resource files back to Windows. Fixes #13393. (#14702)

Fixes https://github.com/xamarin/xamarin-macios/issues/13393.
This commit is contained in:
Rolf Bjarne Kvinge 2022-04-27 08:31:42 +02:00 коммит произвёл GitHub
Родитель 04ca9aa067
Коммит ece70a6c6e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 68 добавлений и 5 удалений

Просмотреть файл

@ -2683,12 +2683,21 @@ namespace Xamarin.Localization.MSBuild {
}
/// <summary>
/// Looks up a localized string similar to Code signing has been requested multiple times for &apos;{0}&apos;, with different metadata. The metadata &apos;{1}&apos; has been values for each item (once it&apos;s &apos;{2}&apos;, another time it&apos;s &apos;{3}&apos;)..
/// Looks up a localized string similar to Code signing has been requested multiple times for &apos;{0}&apos;, with different metadata. The metadata &apos;{1}&apos; has different values for each item (once it&apos;s &apos;{2}&apos;, another time it&apos;s &apos;{3}&apos;)..
/// </summary>
public static string W7097 {
get {
return ResourceManager.GetString("W7097", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not find the binding resource package: {0}.
/// </summary>
public static string W7100 {
get {
return ResourceManager.GetString("W7100", resourceCulture);
}
}
}
}

Просмотреть файл

@ -1416,6 +1416,10 @@
<value>The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {0} (equivalent to macOS {1}).</value>
</data>
<data name="W7100" xml:space="preserve">
<value>Could not find the binding resource package: {0}</value>
</data>
<data name="E7101" xml:space="preserve">
<value>Unknown property '{0}' with value '{1}'.</value>
</data>

Просмотреть файл

@ -26,6 +26,10 @@ namespace Xamarin.MacDev.Tasks {
[Required]
public ITaskItem[] NativeReferences { get; set; }
// This is a list of files to copy back to Windows
[Output]
public ITaskItem[] PackagedFiles { get; set; }
public override bool Execute ()
{
// LinkWith must be migrated for NoBindingEmbedding styled binding projects
@ -51,6 +55,7 @@ namespace Xamarin.MacDev.Tasks {
var manifestDirectory = compress ? IntermediateOutputPath : BindingResourcePath;
var manifestPath = CreateManifest (manifestDirectory);
var packagedFiles = new List<string> ();
if (compress) {
var zipFile = Path.GetFullPath (BindingResourcePath + ".zip");
@ -73,15 +78,29 @@ namespace Xamarin.MacDev.Tasks {
var workingDirectory = Path.GetDirectoryName (fullPath);
zipArguments.Add (Path.GetFileName (fullPath));
ExecuteAsync ("zip", zipArguments, workingDirectory: workingDirectory).Wait ();
packagedFiles.Add (zipFile);
}
} else {
var bindingResourcePath = BindingResourcePath;
Log.LogMessage (MSBStrings.M0121, bindingResourcePath);
Directory.CreateDirectory (bindingResourcePath);
foreach (var nativeRef in NativeReferences)
foreach (var nativeRef in NativeReferences) {
Xamarin.Bundler.FileCopier.UpdateDirectory (nativeRef.ItemSpec, bindingResourcePath, FileCopierReportErrorCallback, FileCopierLogCallback);
var bindingOutputPath = Path.Combine (bindingResourcePath, Path.GetFileName (nativeRef.ItemSpec));
if (Directory.Exists (bindingOutputPath)) {
packagedFiles.AddRange (Directory.GetFiles (bindingOutputPath, "*", SearchOption.AllDirectories));
} else if (File.Exists (bindingOutputPath)) {
packagedFiles.Add (bindingOutputPath);
} else {
Log.LogWarning (MSBStrings.W7100, bindingOutputPath);
}
}
}
PackagedFiles = packagedFiles.Select (v => new TaskItem (v)).ToArray ();
return !Log.HasLoggedErrors;
}

Просмотреть файл

@ -13,10 +13,18 @@ namespace Xamarin.MacDev.Tasks
{
public override bool Execute ()
{
if (ShouldExecuteRemotely ())
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
if (!ShouldExecuteRemotely ())
return base.Execute ();
return base.Execute ();
var taskRunner = new TaskRunner (SessionId, BuildEngine4);
var success = taskRunner.RunAsync (this).Result;
if (success) {
TransferBindingResourcePackagesToWindowsAsync (taskRunner).Wait ();
}
return success;
}
public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
@ -48,5 +56,28 @@ namespace Xamarin.MacDev.Tasks
.Select (x => new TaskItem (x)))
yield return file;
}
async System.Threading.Tasks.Task TransferBindingResourcePackagesToWindowsAsync (TaskRunner taskRunner)
{
if (PackagedFiles is not null) {
foreach (var package in PackagedFiles) {
var localRelativePath = GetLocalRelativePath (package.ItemSpec);
await taskRunner.GetFileAsync (localRelativePath).ConfigureAwait (continueOnCapturedContext: false);
}
}
}
string GetLocalRelativePath (string path)
{
// convert mac full path in windows relative path
// must remove \users\{user}\Library\Caches\Xamarin\mtbs\builds\{appname}\{sessionid}\
if (path.Contains (SessionId)) {
var start = path.IndexOf (SessionId) + SessionId.Length + 1;
return path.Substring (start);
} else {
return path;
}
}
}
}