public void LogWarning(string message, ElementInformation info) { #if !NET_3_5 _buildEngine.LogWarningEvent(new BuildWarningEventArgs("Semiodesk.Trinity", "", info.Source, info.LineNumber, 0, info.LineNumber, 0, message, "Semiodesk", "OntologyGenerator", DateTime.Now)); #else _buildEngine.LogWarningEvent(new BuildWarningEventArgs("Semiodesk.Trinity", "", info.Source, info.LineNumber, 0, info.LineNumber, 0, message, "Semiodesk", "OntologyGenerator")); #endif }
/// <returns>Null if it could not retrieve an input hash</returns> public String TryGetSavedInputHash(String outputFile, out Sha1 savedInputHash) { if (!File.Exists(outputFile)) { savedInputHash = default(Sha1); return(null); } String firstLine; using (StreamReader reader = new StreamReader(new FileStream(outputFile, FileMode.Open, FileAccess.Read, FileShare.Read), true)) { firstLine = reader.ReadLine(); } // Output file is empty if (firstLine == null) { savedInputHash = default(Sha1); return(null); } Int32 inputShaIndex = firstLine.IndexOf(PdlFile.InputShaPrefix); if (inputShaIndex < 0) { // First line does not contain hash buildEngine.LogWarningEvent(new BuildWarningEventArgs(null, null, outputFile, 1, inputShaIndex, 1, firstLine.Length, String.Format("Expected first line to contain InputSha but it was '{0}'", firstLine), null, null)); savedInputHash = default(Sha1); return(null); } inputShaIndex += PdlFile.InputShaPrefix.Length; String savedInputHashString = firstLine.Substring(inputShaIndex); if (savedInputHashString.Length != PdlFile.ShaHexStringLength) { buildEngine.LogWarningEvent(new BuildWarningEventArgs(null, null, outputFile, 1, inputShaIndex, 1, firstLine.Length, String.Format("Expected the InputSha of the output file to be 40 characters but it was {0}", savedInputHashString.Length), null, null)); savedInputHash = default(Sha1); return(null); } try { savedInputHash = Sha1.ParseHex(savedInputHashString, 0); return(savedInputHashString); } catch (Exception e) { buildEngine.LogWarningEvent(new BuildWarningEventArgs(null, null, outputFile, 1, inputShaIndex, 1, firstLine.Length, String.Format("Exception occured while parsing InputSha of the output file '{0}': {1}", savedInputHashString, e.Message), null, null)); savedInputHash = default(Sha1); return(null); } }
public void LogWarning(string message, params object[] messageArgs) { // FIXME: what about all the parameters? BuildWarningEventArgs bwea = new BuildWarningEventArgs( null, null, buildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, FormatString(message, messageArgs), helpKeywordPrefix, null); buildEngine.LogWarningEvent(bwea); }
/// <summary> /// Replays the provided binlog file in the current build engine /// </summary> public static void Replay(IBuildEngine engine, string filePath) { if (File.Exists(filePath)) { var replaySource = new Microsoft.Build.Logging.BinaryLogReplayEventSource(); replaySource.MessageRaised += (s, e) => engine.LogMessageEvent(e); replaySource.WarningRaised += (s, e) => engine.LogWarningEvent(e); replaySource.ErrorRaised += (s, e) => engine.LogErrorEvent(e); replaySource.Replay(filePath); } }
private void LogWarning(string value) { BuildWarningEventArgs warning = new BuildWarningEventArgs( subcategory: null, code: null, file: _buildEngine.ProjectFileOfTaskNode, lineNumber: _buildEngine.LineNumberOfTaskNode, columnNumber: _buildEngine.ColumnNumberOfTaskNode, endLineNumber: 0, endColumnNumber: 0, message: value, helpKeyword: null, senderName: _taskName, eventTimestamp: DateTime.UtcNow); _buildEngine.LogWarningEvent(warning); }
public static (bool success, bool writtentofile) Compile(IBuildEngine engine, string input, string[] references, string projectDirectory, string output, string strongNameKey) { var typeSystem = new CecilTypeSystem(references .Where(r => !r.ToLowerInvariant().EndsWith("robust.build.tasks.dll")) .Concat(new[] { input }), input); var asm = typeSystem.TargetAssemblyDefinition; if (asm.MainModule.GetType("CompiledRobustXaml", "XamlIlContext") != null) { // If this type exists, the assembly has already been processed by us. // Do not run again, it would corrupt the file. // This *shouldn't* be possible due to Inputs/Outputs dependencies in the build system, // but better safe than sorry eh? engine.LogWarningEvent(new BuildWarningEventArgs("XAMLIL", "", "", 0, 0, 0, 0, "Ran twice on same assembly file; ignoring.", "", "")); return(true, false); } var compileRes = CompileCore(engine, typeSystem); if (compileRes == null) { return(true, false); } if (compileRes == false) { return(false, false); } var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols }; if (!string.IsNullOrWhiteSpace(strongNameKey)) { writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey); } asm.Write(output, writerParameters); return(true, true); }
public void log_a_warning_event_containing(string message, params object[] args) { //build_engine.LogMessageEvent(new BuildMessageEventArgs( // string.Format(message, args), // string.Empty, // calling_task.GetType().Name, // MessageImportance.High)); if (build_engine == null) { return; } build_engine.LogWarningEvent(new BuildWarningEventArgs( string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, string.Format(message, args), string.Empty, calling_task.GetType().Name)); }
/// <summary> /// The send report message. /// </summary> /// <param name="eventArgs"> /// The event args. /// </param> /// <param name="buildEngine"> /// The build engine. /// </param> /// <param name="senderName"> /// The sender name. /// </param> public static void SendDeploymentMangerMessage( DeploymentMangerMessageEventArgs eventArgs, IBuildEngine buildEngine, string senderName) { switch (eventArgs.ReportMessageType) { case DeploymentMangerMessageType.Information: buildEngine.LogMessageEvent( new BuildMessageEventArgs(eventArgs.Message, String.Empty, senderName, MessageImportance.Normal)); break; case DeploymentMangerMessageType.Warning: buildEngine.LogWarningEvent( new BuildWarningEventArgs( "Reporting", eventArgs.Method, buildEngine.ProjectFileOfTaskNode, buildEngine.LineNumberOfTaskNode, buildEngine.ColumnNumberOfTaskNode, 0, 0, eventArgs.Message, String.Empty, senderName)); break; case DeploymentMangerMessageType.Error: buildEngine.LogErrorEvent( new BuildErrorEventArgs( "Reporting", eventArgs.Method, buildEngine.ProjectFileOfTaskNode, buildEngine.LineNumberOfTaskNode, buildEngine.ColumnNumberOfTaskNode, 0, 0, eventArgs.Message, String.Empty, senderName)); break; } }
/// <summary> /// Replays the provided binlog file in the current build engine /// </summary> public static void Replay(IBuildEngine engine, string filePath, TaskLoggingHelper log) { if (File.Exists(filePath)) { try { var replaySource = new Microsoft.Build.Logging.BinaryLogReplayEventSource(); replaySource.MessageRaised += (s, e) => engine.LogMessageEvent(e); replaySource.WarningRaised += (s, e) => engine.LogWarningEvent(e); replaySource.ErrorRaised += (s, e) => engine.LogErrorEvent(e); replaySource.Replay(filePath); } catch (Exception e) { var fileSize = File.Exists(filePath) ? new FileInfo(filePath).Length : -1; log.LogWarning($"Failed to replay source generation controller build messages (path:{filePath}, size:{fileSize}) : {e}"); } } }
private void LogBuildEvent(IssueKind issueKind, string message, MessageImportance messageImportance, string code = null, string path = null, int startLine = 0, int startColumn = 0, int endLine = 0, int endColumn = 0) { switch (issueKind) { case IssueKind.Error: _buildEngine.LogErrorEvent(new BuildErrorEventArgs( null, code, path, startLine, startColumn, endLine, endColumn, message, code, ProductConstants.ToolName)); break; case IssueKind.Warning: _buildEngine.LogWarningEvent(new BuildWarningEventArgs( null, code, path, startLine, startColumn, endLine, endColumn, message, code, ProductConstants.ToolName)); break; default: var formattedMessage = $"[{ProductConstants.ToolName}] {message}"; _buildEngine.LogMessageEvent(new BuildMessageEventArgs( null, code, path, startLine, startColumn, endLine, endColumn, formattedMessage, code, ProductConstants.ToolName, messageImportance)); break; } }
public virtual void LogWarning(string message, string?file, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, string?code) { BuildEngine.LogWarningEvent(new BuildWarningEventArgs("", code ?? "", file, lineNumber, columnNumber, endLineNumber, endColumnNumber, PrependMessage(message), "", "Fody")); }
public static void LogWarning(this IBuildEngine engine, BuildEngineErrorCode code, string file, string message) { engine.LogWarningEvent(new BuildWarningEventArgs("Avalonia", FormatErrorCode(code), file ?? "", 0, 0, 0, 0, message, "", "Avalonia")); }
public static void Warn(this IBuildEngine engine, string message, string sender = default) { engine.LogWarningEvent(new BuildWarningEventArgs(message, null, null, 0, 0, 0, 0, message, null, sender)); }
// FIXME: my guess is the tasks does not have to be loaded entirely but only requested tasks must be loaded at invocation time. void LoadUsingTasks(ProjectInstance projectInstance, IEnumerable <ProjectUsingTaskElement> usingTasks) { Func <string, bool> cond = s => projectInstance != null?projectInstance.EvaluateCondition(s) : Convert.ToBoolean(s); foreach (var ut in usingTasks) { var ta = assemblies.FirstOrDefault(a => a.AssemblyFile.Equals(ut.AssemblyFile, StringComparison.OrdinalIgnoreCase) || a.AssemblyName.Equals(ut.AssemblyName, StringComparison.OrdinalIgnoreCase)); if (ta == null) { var path = Path.GetDirectoryName(string.IsNullOrEmpty(ut.Location.File) ? projectInstance.FullPath : ut.Location.File); ta = new TaskAssembly() { AssemblyName = ut.AssemblyName, AssemblyFile = ut.AssemblyFile }; try { ta.LoadedAssembly = !string.IsNullOrEmpty(ta.AssemblyName) ? Assembly.Load(ta.AssemblyName) : Assembly.LoadFile(Path.Combine(path, ta.AssemblyFile)); } catch { var errorNotLoaded = string.Format("For task '{0}' Specified assembly '{1}' was not found", ut.TaskName, string.IsNullOrEmpty(ta.AssemblyName) ? ta.AssemblyFile : ta.AssemblyName); engine.LogWarningEvent(new BuildWarningEventArgs(null, null, projectInstance.FullPath, ut.Location.Line, ut.Location.Column, 0, 0, errorNotLoaded, null, null)); continue; } assemblies.Add(ta); } var pg = ut.ParameterGroup == null ? null : ut.ParameterGroup.Parameters.Select(p => new TaskPropertyInfo(p.Name, Type.GetType(p.ParameterType), cond(p.Output), cond(p.Required))) .ToDictionary(p => p.Name); Type type = null; string error = null; TaskDescription task = new TaskDescription() { TaskAssembly = ta, Name = ut.TaskName, TaskFactoryParameters = pg, TaskBody = ut.TaskBody != null && cond(ut.TaskBody.Condition) ? ut.TaskBody.Evaluate : null, }; if (string.IsNullOrEmpty(ut.TaskFactory)) { type = LoadTypeFrom(ta.LoadedAssembly, ut.TaskName, ut.TaskName); if (type == null) { error = string.Format("For task '{0}' Specified type '{1}' was not found in assembly '{2}'", ut.TaskName, ut.TaskName, ta.LoadedAssembly.FullName); } else { task.TaskType = type; } } else { type = LoadTypeFrom(ta.LoadedAssembly, ut.TaskName, ut.TaskFactory); if (type == null) { error = string.Format("For task '{0}' Specified factory type '{1}' was not found in assembly '{2}'", ut.TaskName, ut.TaskFactory, ta.LoadedAssembly.FullName); } else { task.TaskFactoryType = type; } } if (error != null) { engine.LogWarningEvent(new BuildWarningEventArgs(null, null, projectInstance.FullPath, ut.Location.Line, ut.Location.Column, 0, 0, error, null, null)); } else { task_descs.Add(task); } } }
public void Warning(string message, params object[] args) { _buildEngine.LogWarningEvent(new BuildWarningEventArgs("", "", "", 0, 0, 0, 0, Format(message, args), "", _sender)); }
/// <inheritdoc cref="ISlnGenLogger.LogWarning" /> public void LogWarning(string message, string code = null) => _buildEngine.LogWarningEvent(new BuildWarningEventArgs(null, code, null, 0, 0, 0, 0, message, null, null));
static bool?CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem) { var asm = typeSystem.TargetAssemblyDefinition; var embrsc = new EmbeddedResources(asm); if (embrsc.Resources.Count(CheckXamlName) == 0) { // Nothing to do return(null); } var xamlLanguage = new XamlLanguageTypeMappings(typeSystem) { XmlnsAttributes = { typeSystem.GetType("Avalonia.Metadata.XmlnsDefinitionAttribute"), }, ContentAttributes = { typeSystem.GetType("Robust.Client.UserInterface.XAML.ContentAttribute") }, UsableDuringInitializationAttributes = { typeSystem.GetType("Robust.Client.UserInterface.XAML.UsableDuringInitializationAttribute") }, DeferredContentPropertyAttributes = { typeSystem.GetType("Robust.Client.UserInterface.XAML.DeferredContentAttribute") }, RootObjectProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestRootObjectProvider"), UriContextProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestUriContext"), ProvideValueTarget = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestProvideValueTarget"), }; var emitConfig = new XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> { ContextTypeBuilderCallback = (b, c) => EmitNameScopeField(xamlLanguage, typeSystem, b, c) }; var transformerconfig = new TransformerConfiguration( typeSystem, typeSystem.TargetAssembly, xamlLanguage, XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), CustomValueConverter); var contextDef = new TypeDefinition("CompiledRobustXaml", "XamlIlContext", TypeAttributes.Class, asm.MainModule.TypeSystem.Object); asm.MainModule.Types.Add(contextDef); var contextClass = XamlILContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem, xamlLanguage, emitConfig); var compiler = new RobustXamlILCompiler(transformerconfig, emitConfig, true); var loaderDispatcherDef = new TypeDefinition("CompiledRobustXaml", "!XamlLoader", TypeAttributes.Class, asm.MainModule.TypeSystem.Object); var loaderDispatcherMethod = new MethodDefinition("TryLoad", MethodAttributes.Static | MethodAttributes.Public, asm.MainModule.TypeSystem.Object) { Parameters = { new ParameterDefinition(asm.MainModule.TypeSystem.String) } }; loaderDispatcherDef.Methods.Add(loaderDispatcherMethod); asm.MainModule.Types.Add(loaderDispatcherDef); var stringEquals = asm.MainModule.ImportReference(asm.MainModule.TypeSystem.String.Resolve().Methods.First( m => m.IsStatic && m.Name == "Equals" && m.Parameters.Count == 2 && m.ReturnType.FullName == "System.Boolean" && m.Parameters[0].ParameterType.FullName == "System.String" && m.Parameters[1].ParameterType.FullName == "System.String")); bool CompileGroup(IResourceGroup group) { var typeDef = new TypeDefinition("CompiledRobustXaml", "!" + group.Name, TypeAttributes.Class, asm.MainModule.TypeSystem.Object); //typeDef.CustomAttributes.Add(new CustomAttribute(ed)); asm.MainModule.Types.Add(typeDef); var builder = typeSystem.CreateTypeBuilder(typeDef); foreach (var res in group.Resources.Where(CheckXamlName)) { try { engine.LogMessage($"XAMLIL: {res.Name} -> {res.Uri}", MessageImportance.Low); var xaml = new StreamReader(new MemoryStream(res.FileContents)).ReadToEnd(); var parsed = XDocumentXamlParser.Parse(xaml); var initialRoot = (XamlAstObjectNode)parsed.Root; var classDirective = initialRoot.Children.OfType <XamlAstXmlDirective>() .FirstOrDefault(d => d.Namespace == XamlNamespaces.Xaml2006 && d.Name == "Class"); string classname; if (classDirective != null && classDirective.Values[0] is XamlAstTextNode tn) { classname = tn.Text; } else { classname = res.Name.Replace(".xaml", ""); } var classType = typeSystem.TargetAssembly.FindType(classname); if (classType == null) { throw new Exception($"Unable to find type '{classname}'"); } compiler.Transform(parsed); var populateName = $"Populate:{res.Name}"; var buildName = $"Build:{res.Name}"; var classTypeDefinition = typeSystem.GetTypeReference(classType).Resolve(); var populateBuilder = typeSystem.CreateTypeBuilder(classTypeDefinition); compiler.Compile(parsed, contextClass, compiler.DefinePopulateMethod(populateBuilder, parsed, populateName, classTypeDefinition == null), compiler.DefineBuildMethod(builder, parsed, buildName, true), null, (closureName, closureBaseType) => populateBuilder.DefineSubType(closureBaseType, closureName, false), res.Uri, res ); //add compiled populate method var compiledPopulateMethod = typeSystem.GetTypeReference(populateBuilder).Resolve().Methods .First(m => m.Name == populateName); const string TrampolineName = "!XamlIlPopulateTrampoline"; var trampoline = new MethodDefinition(TrampolineName, MethodAttributes.Static | MethodAttributes.Private, asm.MainModule.TypeSystem.Void); trampoline.Parameters.Add(new ParameterDefinition(classTypeDefinition)); classTypeDefinition.Methods.Add(trampoline); trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull)); trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Call, compiledPopulateMethod)); trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); var foundXamlLoader = false; // Find RobustXamlLoader.Load(this) and replace it with !XamlIlPopulateTrampoline(this) foreach (var method in classTypeDefinition.Methods .Where(m => !m.Attributes.HasFlag(MethodAttributes.Static))) { var i = method.Body.Instructions; for (var c = 1; c < i.Count; c++) { if (i[c].OpCode == OpCodes.Call) { var op = i[c].Operand as MethodReference; if (op != null && op.Name == TrampolineName) { foundXamlLoader = true; break; } if (op != null && op.Name == "Load" && op.Parameters.Count == 1 && op.Parameters[0].ParameterType.FullName == "System.Object" && op.DeclaringType.FullName == "Robust.Client.UserInterface.XAML.RobustXamlLoader") { if (MatchThisCall(i, c - 1)) { i[c].Operand = trampoline; foundXamlLoader = true; } } } } } if (!foundXamlLoader) { var ctors = classTypeDefinition.GetConstructors() .Where(c => !c.IsStatic).ToList(); // We can inject xaml loader into default constructor if (ctors.Count == 1 && ctors[0].Body.Instructions.Count(o => o.OpCode != OpCodes.Nop) == 3) { var i = ctors[0].Body.Instructions; var retIdx = i.IndexOf(i.Last(x => x.OpCode == OpCodes.Ret)); i.Insert(retIdx, Instruction.Create(OpCodes.Call, trampoline)); i.Insert(retIdx, Instruction.Create(OpCodes.Ldarg_0)); } else { throw new InvalidProgramException( $"No call to RobustXamlLoader.Load(this) call found anywhere in the type {classType.FullName} and type seems to have custom constructors."); } } //add compiled build method var compiledBuildMethod = typeSystem.GetTypeReference(builder).Resolve().Methods .First(m => m.Name == buildName); var parameterlessCtor = classTypeDefinition.GetConstructors() .FirstOrDefault(c => c.IsPublic && !c.IsStatic && !c.HasParameters); if (compiledBuildMethod != null && parameterlessCtor != null) { var i = loaderDispatcherMethod.Body.Instructions; var nop = Instruction.Create(OpCodes.Nop); i.Add(Instruction.Create(OpCodes.Ldarg_0)); i.Add(Instruction.Create(OpCodes.Ldstr, res.Uri)); i.Add(Instruction.Create(OpCodes.Call, stringEquals)); i.Add(Instruction.Create(OpCodes.Brfalse, nop)); if (parameterlessCtor != null) { i.Add(Instruction.Create(OpCodes.Newobj, parameterlessCtor)); } else { i.Add(Instruction.Create(OpCodes.Call, compiledBuildMethod)); } i.Add(Instruction.Create(OpCodes.Ret)); i.Add(nop); } } catch (Exception e) { engine.LogWarningEvent(new BuildWarningEventArgs("XAMLIL", "", res.Uri, 0, 0, 0, 0, e.ToString(), "", "CompileRobustXaml")); } } return(true); } if (embrsc.Resources.Count(CheckXamlName) != 0) { if (!CompileGroup(embrsc)) { return(false); } } loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull)); loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); return(true); }
public void LogWarningEvent(BuildWarningEventArgs e) { _buildEngine.LogWarningEvent(e); }