diff --git a/tools/common/Application.cs b/tools/common/Application.cs index dfdff4cd3cf6..cb327056ab26 100644 --- a/tools/common/Application.cs +++ b/tools/common/Application.cs @@ -709,7 +709,7 @@ public static void SaveAssembly (AssemblyDefinition assembly, string destination } } - public static void ExtractResource (ModuleDefinition module, string name, string path, bool remove) + public static bool ExtractResource (ModuleDefinition module, string name, string path, bool remove) { for (int i = 0; i < module.Resources.Count; i++) { EmbeddedResource embedded = module.Resources [i] as EmbeddedResource; @@ -728,8 +728,10 @@ public static void ExtractResource (ModuleDefinition module, string name, string if (remove) module.Resources.RemoveAt (i); - break; + return true; } + + return false; } // Returns true if the source file was copied to the target or false if it was already up to date. diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index 594ee9f8d8f4..b8aa9b4ae782 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -280,18 +280,24 @@ void ProcessLinkWithAttributes (AssemblyDefinition assembly) if (!string.IsNullOrEmpty (linkWith.LibraryName)) { switch (Path.GetExtension (linkWith.LibraryName).ToLowerInvariant ()) { - case ".framework": + case ".framework": { AssertiOSVersionSupportsUserFrameworks (linkWith.LibraryName); - Frameworks.Add (ExtractFramework (assembly, metadata)); + // TryExtractFramework prints a error/warning if something goes wrong, so no need for us to have an error handling path. + if (TryExtractFramework (assembly, metadata, out var framework)) + Frameworks.Add (framework); break; + } case ".xcframework": // this is resolved, at msbuild time, into a framework // but we must ignore it here (can't be the `default` case) break; - default: - LinkWith.Add (ExtractNativeLibrary (assembly, metadata)); + default: { + // TryExtractFramework prints a error/warning if something goes wrong, so no need for us to have an error handling path. + if (TryExtractNativeLibrary (assembly, metadata, out var framework)) + LinkWith.Add (framework); break; } + } } } } @@ -352,12 +358,17 @@ void ProcessNativeReferenceOptions (NativeReferenceMetadata metadata) #endif } - string ExtractNativeLibrary (AssemblyDefinition assembly, NativeReferenceMetadata metadata) + bool TryExtractNativeLibrary (AssemblyDefinition assembly, NativeReferenceMetadata metadata, out string library) { string path = Path.Combine (App.Cache.Location, metadata.LibraryName); + library = null; + if (!Application.IsUptodate (FullPath, path)) { - Application.ExtractResource (assembly.MainModule, metadata.LibraryName, path, false); + if (!Application.ExtractResource (assembly.MainModule, metadata.LibraryName, path, false)) { + ErrorHelper.Warning (1308, Errors.MX1308 /* Could not extract the native library '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'. */, metadata.LibraryName, FullPath, metadata.LibraryName); + return false; + } Driver.Log (3, "Extracted third-party binding '{0}' from '{1}' to '{2}'", metadata.LibraryName, FullPath, path); LogNativeReference (metadata); } else { @@ -367,16 +378,24 @@ string ExtractNativeLibrary (AssemblyDefinition assembly, NativeReferenceMetadat if (!File.Exists (path)) ErrorHelper.Warning (1302, Errors.MT1302, metadata.LibraryName, path); - return path; + library = path; + return true; } - string ExtractFramework (AssemblyDefinition assembly, NativeReferenceMetadata metadata) + bool TryExtractFramework (AssemblyDefinition assembly, NativeReferenceMetadata metadata, out string framework) { string path = Path.Combine (App.Cache.Location, metadata.LibraryName); var zipPath = path + ".zip"; + + framework = null; + if (!Application.IsUptodate (FullPath, zipPath)) { - Application.ExtractResource (assembly.MainModule, metadata.LibraryName, zipPath, false); + if (!Application.ExtractResource (assembly.MainModule, metadata.LibraryName, zipPath, false)) { + ErrorHelper.Warning (1307, Errors.MX1307 /* Could not extract the native framework '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'. */, metadata.LibraryName, FullPath, metadata.LibraryName); + return false; + } + Driver.Log (3, "Extracted third-party framework '{0}' from '{1}' to '{2}'", metadata.LibraryName, FullPath, zipPath); LogNativeReference (metadata); } else { @@ -401,7 +420,8 @@ string ExtractFramework (AssemblyDefinition assembly, NativeReferenceMetadata me throw ErrorHelper.CreateError (1303, Errors.MT1303, metadata.LibraryName, zipPath); } - return path; + framework = path; + return true; } static void LogNativeReference (NativeReferenceMetadata metadata) diff --git a/tools/mtouch/Errors.designer.cs b/tools/mtouch/Errors.designer.cs index d770fa6bddc0..f30a55cbb4ac 100644 --- a/tools/mtouch/Errors.designer.cs +++ b/tools/mtouch/Errors.designer.cs @@ -3811,6 +3811,24 @@ public static string MX1306 { } } + /// + /// Looks up a localized string similar to Could not extract the native framework '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'.. + /// + public static string MX1307 { + get { + return ResourceManager.GetString("MX1307", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Could not extract the native library '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'.. + /// + public static string MX1308 { + get { + return ResourceManager.GetString("MX1308", resourceCulture); + } + } + /// /// Looks up a localized string similar to One or more reference(s) to type '{0}' already exists inside '{1}' before linking /// . diff --git a/tools/mtouch/Errors.resx b/tools/mtouch/Errors.resx index 8ebe9f75b579..b55d3e80fc12 100644 --- a/tools/mtouch/Errors.resx +++ b/tools/mtouch/Errors.resx @@ -1023,6 +1023,14 @@ Could not decompress the file '{0}'. Please review the build log for more information from the native 'unzip' command. + + Could not extract the native framework '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'. + + + + Could not extract the native library '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'. + + The required 'Xamarin.Mac.dll' assembly is missing from the references