Skip to content
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

[tools] Improve logging/reporting when running into problems with binding projects / assemblies. #18683

Merged
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
6 changes: 4 additions & 2 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
40 changes: 30 additions & 10 deletions tools/common/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tools/mtouch/Errors.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tools/mtouch/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,14 @@
<value>Could not decompress the file '{0}'. Please review the build log for more information from the native 'unzip' command.</value>
</data>

<data name="MX1307" xml:space="preserve">
<value>Could not extract the native framework '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'.</value>
</data>

<data name="MX1308" xml:space="preserve">
<value>Could not extract the native library '{0}' from the assembly '{1}', because it doesn't contain the resource '{2}'.</value>
</data>

<data name="MM1401" xml:space="preserve">
<value>The required 'Xamarin.Mac.dll' assembly is missing from the references
</value>
Expand Down