public void LogMessage(string message) { if (!LogMessages) { return; } LogMessage(MessageContainer.CreateInfoMessage(message)); }
/// <summary> /// Represents a known error that occurred during link time which is solvable by the user. /// </summary> /// <param name="message">Error message with a description of what went wrong</param> /// <param name="innerException"></param> public LinkerFatalErrorException(MessageContainer message, Exception innerException) : base(message.ToString(), innerException) { if (message.Category != MessageCategory.Error) { throw new ArgumentException($"'{nameof (LinkerFatalErrorException)}' ought to be used for errors only"); } MessageContainer = message; }
/// <summary> /// Display an error message to the end user. /// </summary> /// <param name="text">Humanly readable message describing the error</param> /// <param name="code">Unique error ID. Please see https://github.com/mono/linker/blob/master/doc/error-codes.md for the list of errors and possibly add a new one</param> /// <param name="subcategory">Optionally, further categorize this error</param> /// <param name="origin">Filename, line, and column where the error was found</param> /// <returns>New MessageContainer of 'Error' category</returns> public void LogError(string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin?origin = null, bool isWarnAsError = false, WarnVersion?version = null) { if (!LogMessages) { return; } var error = MessageContainer.CreateErrorMessage(text, code, subcategory, origin, isWarnAsError, version); LogMessage(error); }
/// <summary> /// Display an error message to the end user. /// </summary> /// <param name="text">Humanly readable message describing the error</param> /// <param name="code">Unique error ID. Please see https://github.com/mono/linker/blob/master/doc/error-codes.md for the list of errors and possibly add a new one</param> /// <param name="subcategory">Optionally, further categorize this error</param> /// <param name="origin">Filename, line, and column where the error was found</param> /// <returns>New MessageContainer of 'Error' category</returns> public void LogError(string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin?origin = null) { if (!LogMessages) { return; } var error = MessageContainer.CreateErrorMessage(text, code, subcategory, origin); LogMessage(error); }
/// <summary> /// Display a warning message to the end user. /// </summary> /// <param name="text">Humanly readable message describing the warning</param> /// <param name="code">Unique warning ID. Please see https://github.com/mono/linker/blob/master/doc/error-codes.md for the list of warnings and possibly add a new one</param> /// <param name="origin">Filename or member where the warning is coming from</param> /// <param name="subcategory">Optionally, further categorize this warning</param> public void LogWarning(string text, int code, MessageOrigin origin, string subcategory = MessageSubCategory.None) { if (!LogMessages) { return; } var warning = MessageContainer.CreateWarningMessage(this, text, code, origin, subcategory); LogMessage(warning); }
/// <param name="message">Error message with a description of what went wrong</param> /// <param name="innerException"></param> public LinkerFatalErrorException(MessageContainer message, Exception innerException) : base(message.ToString(), innerException) { if (message.Category != MessageCategory.Error) { throw new ArgumentException($"'{nameof (LinkerFatalErrorException)}' ought to be used for errors only"); } if (message.Code == null || message.Code.Value == 0) { throw new ArgumentException($"'{nameof (LinkerFatalErrorException)}' must have a code that indicates failure"); } MessageContainer = message; }
public void ParseXml(string document) { _xmlDocumentLocation = document; _document = new XPathDocument(_xmlDocumentLocation); XPathNavigator nav = _document.CreateNavigator(); if (!nav.MoveToChild("linker", string.Empty)) { return; } try { ProcessAssemblies(_context, nav.SelectChildren("assembly", string.Empty)); } catch (Exception ex) when(!(ex is LinkerFatalErrorException)) { throw new LinkerFatalErrorException(MessageContainer.CreateErrorMessage($"Error processing '{_xmlDocumentLocation}'", 1013), ex); } }
/// <summary> /// Display a warning message to the end user. /// This API is used for warnings defined in the linker, not by custom steps. Warning /// versions are inferred from the code, and every warning that we define is versioned. /// </summary> /// <param name="text">Humanly readable message describing the warning</param> /// <param name="code">Unique warning ID. Please see https://github.com/mono/linker/blob/master/doc/error-codes.md for the list of warnings and possibly add a new one</param> /// <param name="origin">Filename or member where the warning is coming from</param> /// <param name="subcategory">Optionally, further categorize this warning</param> /// <returns>New MessageContainer of 'Warning' category</returns> public void LogWarning(string text, int code, MessageOrigin origin, string subcategory = MessageSubCategory.None) { if (!LogMessages) { return; } var version = GetWarningVersion(code); if ((GeneralWarnAsError && (!WarnAsError.TryGetValue((uint)code, out var warnAsError) || warnAsError)) || (!GeneralWarnAsError && (WarnAsError.TryGetValue((uint)code, out warnAsError) && warnAsError))) { LogError(text, code, subcategory, origin, isWarnAsError: true, version: version); return; } var warning = MessageContainer.CreateWarningMessage(this, text, code, origin, subcategory, version); LogMessage(warning); }
public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { // Validate arguments, similarly to how the base class does it. if (name == null) { throw new ArgumentNullException("name"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (!_assemblies.TryGetValue(name.Name, out AssemblyDefinition asm) && (_unresolvedAssemblies == null || !_unresolvedAssemblies.Contains(name.Name))) { try { // Any full path explicit reference takes precedence over other look up logic asm = ResolveFromReferences(name, _references, parameters); // Fall back to the base class resolution logic if (asm == null) { asm = base.Resolve(name, parameters); } _assemblies[name.Name] = asm; } catch (AssemblyResolutionException) { if (!_ignoreUnresolved) { throw; } _context.LogMessage(MessageContainer.CreateInfoMessage($"Ignoring unresolved assembly '{name.Name}'.")); if (_unresolvedAssemblies == null) { _unresolvedAssemblies = new HashSet <string> (); } _unresolvedAssemblies.Add(name.Name); } } return(asm); }
public void LogMessage(MessageContainer message) { if (message == MessageContainer.Empty) { return; } if ((message.Category == MessageCategory.Diagnostic || message.Category == MessageCategory.Info) && !LogMessages) { return; } if (OutputWarningSuppressions && (message.Category == MessageCategory.Warning || message.Category == MessageCategory.WarningAsError) && message.Origin?.MemberDefinition != null) { WarningSuppressionWriter.AddWarning(message.Code.Value, message.Origin?.MemberDefinition); } Logger?.LogMessage(message); }
public void AddLocalSuppression(CustomAttribute ca, ICustomAttributeProvider provider) { SuppressMessageInfo info; if (!TryDecodeSuppressMessageAttributeData(ca, out info)) { return; } if (!_localSuppressions.TryGetValue(provider, out var suppressions)) { suppressions = new Dictionary <int, SuppressMessageInfo> (); _localSuppressions.Add(provider, suppressions); } if (suppressions.ContainsKey(info.Id)) { _context.LogMessage(MessageContainer.CreateInfoMessage( $"Element {provider} has more than one unconditional suppression. Note that only the last one is used.")); } suppressions[info.Id] = info; }
public virtual ICollection <AssemblyDefinition> ResolveReferences(AssemblyDefinition assembly) { List <AssemblyDefinition> references = new List <AssemblyDefinition> (); if (assembly == null) { return(references); } foreach (AssemblyNameReference reference in assembly.MainModule.AssemblyReferences) { try { AssemblyDefinition definition = Resolve(reference); if (definition != null) { references.Add(definition); } } catch (Exception e) { throw new LinkerFatalErrorException(MessageContainer.CreateErrorMessage($"Assembly '{assembly.FullName}' reference '{reference.FullName}' could not be resolved", 1009), e); } } return(references); }
public bool Run(ILogger customLogger = null) { int setupStatus = SetupContext(customLogger); if (setupStatus > 0) { return(true); } if (setupStatus < 0) { return(false); } Pipeline p = context.Pipeline; PreProcessPipeline(p); try { p.Process(context); } catch (Exception ex) { if (ex is LinkerFatalErrorException lex) { context.LogMessage(lex.MessageContainer); Console.Error.WriteLine(ex.ToString()); } else { context.LogMessage(MessageContainer.CreateErrorMessage($"IL Linker has encountered an unexpected error. Please report the issue at https://github.com/mono/linker/issues \n{ex}", 1012)); } return(false); } finally { context.Tracer.Finish(); } return(true); }
public bool Equals(MessageContainer other) => (Category, Text, Code, SubCategory, Origin) == (other.Category, other.Text, other.Code, other.SubCategory, other.Origin);
public void LogMessage(MessageContainer message) { Console.WriteLine(message.ToString()); }
public void LogMessage(MessageContainer message) { throw null; }
public void UnrecognizedReflectionAccessPattern(MethodDefinition sourceMethod, Instruction reflectionMethodCall, IMetadataTokenProvider accessedItem, string message) { _context.LogMessage(MessageContainer.CreateWarningMessage(message, 2006, "Unrecognized reflection pattern", reflectionMethodCall != null ? MessageOrigin.TryGetOrigin(sourceMethod, reflectionMethodCall.Offset) : null)); }