protected TkFxcItem GetTkFxcItem(ITaskItem item) { var data = new TkFxcItem { FxName = item.ItemSpec, DynamicCompiling = item.GetMetadata("DynamicCompiling", DynamicCompiling), LinkName = item.GetMetadata("Link", item.ItemSpec), OutputNamespace = item.GetMetadata("OutputNamespace", RootNamespace), OutputFieldName = item.GetMetadata("OutputFieldName", "bytecode"), OutputCs = item.GetMetadata("OutputCs", false) }; data.OutputClassName = item.GetMetadata("OutputClassName", Path.GetFileNameWithoutExtension(data.LinkName)); data.OutputCsFile = item.GetMetadata("OutputCsFileName", Path.GetFileNameWithoutExtension(data.LinkName) + ".Generated.cs"); var outputCsFile = item.GetMetadata<string>("LastGenOutput", null); if (outputCsFile != null && outputCsFile.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase)) { data.OutputCsFile = outputCsFile; } // Fullpath to the generated Output FilePath either // For fxo: $(ProjectDir)/obj/Debug/XXX/YYY.fxo // For cs: $(ProjectDir)/XXX/YYY.cs if (data.OutputCs) { data.OutputFilePath = Path.Combine(IntermediateDirectory.ItemSpec, Path.Combine(Path.GetDirectoryName(data.FxName) ?? string.Empty, data.OutputCsFile)); } else { data.OutputLink = Path.ChangeExtension(data.LinkName, "fxo"); data.OutputFilePath = Path.Combine(IntermediateDirectory.ItemSpec, data.OutputLink); } // Prefix by ProjectDirectory data.OutputFilePath = Path.Combine(ProjectDirectory.ItemSpec, data.OutputFilePath); // Fullpath to the input file data.InputFilePath = Path.Combine(ProjectDirectory.ItemSpec, data.FxName); return data; }
protected override bool ProcessItem(TkFxcItem item) { bool hasErrors = false; var inputFilePath = item.InputFilePath; var outputFilePath = item.OutputFilePath; var dependencyFilePath = Path.Combine(Path.Combine(ProjectDirectory.ItemSpec, IntermediateDirectory.ItemSpec), compiler.GetDependencyFileNameFromEffectPath(item.LinkName)); // Creates the dependency directory if it does no exist yet. var dependencyDirectoryPath = Path.GetDirectoryName(dependencyFilePath); if (!Directory.Exists(dependencyDirectoryPath)) { Directory.CreateDirectory(dependencyDirectoryPath); } Log.LogMessage(MessageImportance.High, "Check Toolkit FX file to compile {0} with dependency file {1}", inputFilePath, dependencyFilePath); if (compiler.CheckForChanges(dependencyFilePath) || !File.Exists(outputFilePath)) { Log.LogMessage(MessageImportance.High, "Start to compile {0}", inputFilePath); var compilerResult = compiler.CompileFromFile(inputFilePath, Debug ? EffectCompilerFlags.Debug : EffectCompilerFlags.None, null, null, item.DynamicCompiling, dependencyFilePath); if (compilerResult.HasErrors) { hasErrors = true; } else { Log.LogMessage(MessageImportance.High, "Compiled successfull {0} to {1}", inputFilePath, outputFilePath); } foreach (var message in compilerResult.Logger.Messages) { var text = message.ToString(); string line = null; var textReader = new StringReader(text); while ((line = textReader.ReadLine()) != null) { var match = parseMessage.Match(line); if (match.Success) { var filePath = match.Groups[1].Value; var lineNumber = int.Parse(match.Groups[2].Value); var colNumberText = match.Groups[3].Value; int colStartNumber; int colEndNumber; var colMatch = matchNumberRange.Match(colNumberText); if (colMatch.Success) { int.TryParse(colMatch.Groups[1].Value, out colStartNumber); int.TryParse(colMatch.Groups[2].Value, out colEndNumber); } else { int.TryParse(colNumberText, out colStartNumber); colEndNumber = colStartNumber; } var msgType = match.Groups[4].Value; var msgCode = match.Groups[5].Value; var msgText = match.Groups[6].Value; if (string.Compare(msgType, "error", StringComparison.InvariantCultureIgnoreCase) == 0) { Log.LogError(string.Empty, msgCode, string.Empty, filePath, lineNumber, colStartNumber, lineNumber, colEndNumber, msgText); } else if (string.Compare(msgType, "warning", StringComparison.InvariantCultureIgnoreCase) == 0) { Log.LogWarning(string.Empty, msgCode, string.Empty, filePath, lineNumber, colStartNumber, lineNumber, colEndNumber, msgText); } else if (string.Compare(msgType, "info", StringComparison.InvariantCultureIgnoreCase) == 0) { Log.LogWarning(string.Empty, msgCode, string.Empty, filePath, lineNumber, colStartNumber, lineNumber, colEndNumber, msgText); } else { Log.LogWarning(line); } } else { Log.LogWarning(line); } } } if (!compilerResult.HasErrors && compilerResult.EffectData != null) { try { var directoryName = Path.GetDirectoryName(outputFilePath); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (item.OutputCs) { var codeWriter = new EffectDataCodeWriter { Namespace = item.OutputNamespace, ClassName = item.OutputClassName, FieldName = item.OutputFieldName, }; using (var stream = new NativeFileStream(outputFilePath, NativeFileMode.Create, NativeFileAccess.Write, NativeFileShare.Write)) { codeWriter.Write(compilerResult.EffectData, new StreamWriter(stream, Encoding.UTF8)); } } else { compilerResult.EffectData.Save(outputFilePath); } } catch (Exception ex) { Log.LogError("Cannot write compiled file to {0} : {1}", inputFilePath, ex.Message); hasErrors = true; } } } return !hasErrors; }
protected virtual bool ProcessItem(TkFxcItem item) { return true; }