private void Copy_Plugins(bool OvertakeOutString = false) { if (compiledFiles.Count > 0) { nonUploadedFiles.Clear(); var copyCount = 0; var c = Program.Configs[Program.SelectedConfig]; if (!string.IsNullOrWhiteSpace(c.CopyDirectory)) { var stringOutput = new StringBuilder(); foreach (var file in compiledFiles) { try { var destFile = new FileInfo(file); if (destFile.Exists) { var destinationFileName = destFile.Name; var copyFileDestination = Path.Combine(c.CopyDirectory, destinationFileName); File.Copy(file, copyFileDestination, true); nonUploadedFiles.Add(copyFileDestination); stringOutput.AppendLine($"{Program.Translations.GetLanguage("Copied")}: " + file); ++copyCount; if (c.DeleteAfterCopy) { File.Delete(file); stringOutput.AppendLine($"{Program.Translations.GetLanguage("Deleted")}: " + file); } } } catch (Exception) { stringOutput.AppendLine($"{Program.Translations.GetLanguage("FailCopy")}: " + file); } } if (copyCount == 0) { stringOutput.AppendLine(Program.Translations.GetLanguage("NoFilesCopy")); } if (OvertakeOutString) { CompileOutput.AppendText(stringOutput.ToString()); } else { CompileOutput.Text = stringOutput.ToString(); } if (CompileOutputRow.Height.Value < 11.0) { CompileOutputRow.Height = new GridLength(200.0); } } } }
public void Copy_Plugins(bool OvertakeOutString = false) { if (compiledFiles.Count > 0) { nonUploadedFiles.Clear(); int copyCount = 0; var c = Program.Configs[Program.SelectedConfig]; if (!string.IsNullOrWhiteSpace(c.CopyDirectory)) { StringBuilder stringOutput = new StringBuilder(); for (int i = 0; i < compiledFiles.Count; ++i) { try { FileInfo destFile = new FileInfo(compiledFiles[i]); if (destFile.Exists) { string destinationFileName = destFile.Name; string copyFileDestination = Path.Combine(c.CopyDirectory, destinationFileName); File.Copy(compiledFiles[i], copyFileDestination, true); nonUploadedFiles.Add(copyFileDestination); stringOutput.AppendLine($"{Program.Translations.Copied}: " + compiledFiles[i]); ++copyCount; if (c.DeleteAfterCopy) { File.Delete(compiledFiles[i]); stringOutput.AppendLine($"{Program.Translations.Deleted}: " + compiledFiles[i]); } } } catch (Exception) { stringOutput.AppendLine($"{Program.Translations.FailCopy}: " + compiledFiles[i]); } } if (copyCount == 0) { stringOutput.AppendLine(Program.Translations.NoFilesCopy); } if (OvertakeOutString) { CompileOutput.AppendText(stringOutput.ToString()); } else { CompileOutput.Text = stringOutput.ToString(); } if (CompileOutputRow.Height.Value < 11.0) { CompileOutputRow.Height = new GridLength(200.0); } } } }
/// <inheritdoc /> public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath) { var compileEnvironment = options.CompileEnv; var output = new CompileOutput(); // Setup arguments shared by all source files var commonArgs = new List <string>(); SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath); { commonArgs.Add("-c"); commonArgs.Add("-pipe"); commonArgs.Add("-x"); commonArgs.Add("c++"); commonArgs.Add("-std=c++14"); commonArgs.Add("-Wdelete-non-virtual-dtor"); commonArgs.Add("-fno-math-errno"); commonArgs.Add("-fdiagnostics-format=msvc"); if (Architecture == TargetArchitecture.ARM || Architecture == TargetArchitecture.ARM64) { commonArgs.Add("-fsigned-char"); } if (compileEnvironment.RuntimeTypeInfo) { commonArgs.Add("-frtti"); } else { commonArgs.Add("-fno-rtti"); } if (compileEnvironment.TreatWarningsAsErrors) { commonArgs.Add("-Wall -Werror"); } // TODO: compileEnvironment.IntrinsicFunctions // TODO: compileEnvironment.FunctionLevelLinking // TODO: compileEnvironment.FavorSizeOrSpeed // TODO: compileEnvironment.RuntimeChecks // TODO: compileEnvironment.StringPooling // TODO: compileEnvironment.BufferSecurityCheck if (compileEnvironment.DebugInformation) { commonArgs.Add("-glldb"); } commonArgs.Add("-pthread"); if (compileEnvironment.Optimization) { commonArgs.Add("-O2"); } else { commonArgs.Add("-O0"); } if (!compileEnvironment.Inlining) { commonArgs.Add("-fno-inline-functions"); commonArgs.Add("-fno-inline"); } if (compileEnvironment.EnableExceptions) { commonArgs.Add("-fexceptions"); } else { commonArgs.Add("-fno-exceptions"); } } // Add preprocessor definitions foreach (var definition in compileEnvironment.PreprocessorDefinitions) { commonArgs.Add(string.Format("-D \"{0}\"", definition)); } // Add include paths foreach (var includePath in compileEnvironment.IncludePaths) { commonArgs.Add(string.Format("-I\"{0}\"", includePath.Replace('\\', '/'))); } // Compile all C++ files var args = new List <string>(); foreach (var sourceFile in sourceFiles) { var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile); var task = graph.Add <CompileCppTask>(); // Use shared arguments args.Clear(); args.AddRange(commonArgs); // Object File Name var objFile = Path.Combine(outputPath, sourceFilename + ".o"); args.Add(string.Format("-o \"{0}\"", objFile.Replace('\\', '/'))); output.ObjectFiles.Add(objFile); task.ProducedFiles.Add(objFile); // Source File Name args.Add("\"" + sourceFile.Replace('\\', '/') + "\""); // Request included files to exist var includes = IncludesCache.FindAllIncludedFiles(sourceFile); task.PrerequisiteFiles.AddRange(includes); // Compile task.WorkingDirectory = options.WorkingDirectory; task.CommandPath = ClangPath; task.CommandArguments = string.Join(" ", args); task.PrerequisiteFiles.Add(sourceFile); task.InfoMessage = Path.GetFileName(sourceFile); task.Cost = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting } return(output); }
/// <inheritdoc /> public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath) { var compileEnvironment = options.CompileEnv; var output = new CompileOutput(); // Setup arguments shared by all source files var commonArgs = new List <string>(); SetupCompileCppFilesArgs(graph, options, commonArgs); { // Suppress Startup Banner commonArgs.Add("/nologo"); // Compile Without Linking commonArgs.Add("/c"); // Generate Intrinsic Functions if (compileEnvironment.IntrinsicFunctions) { commonArgs.Add("/Oi"); } // Enable Function-Level Linking if (compileEnvironment.FunctionLevelLinking) { commonArgs.Add("/Gy"); } else { commonArgs.Add("/Gy-"); } // List Include Files //commonArgs.Add("/showIncludes"); // Code Analysis commonArgs.Add("/analyze-"); // Remove unreferenced COMDAT commonArgs.Add("/Zc:inline"); // Favor Small Code, Favor Fast Code if (compileEnvironment.FavorSizeOrSpeed == FavorSizeOrSpeed.FastCode) { commonArgs.Add("/Ot"); } else if (compileEnvironment.FavorSizeOrSpeed == FavorSizeOrSpeed.SmallCode) { commonArgs.Add("/Os"); } // Run-Time Error Checks if (compileEnvironment.RuntimeChecks && !compileEnvironment.CompileAsWinRT) { commonArgs.Add("/RTC1"); } // Enable Additional Security Checks if (compileEnvironment.RuntimeChecks) { commonArgs.Add("/sdl"); } // Inline Function Expansion if (compileEnvironment.Inlining) { commonArgs.Add("/Ob2"); } if (compileEnvironment.DebugInformation) { // Debug Information Format commonArgs.Add("/Zi"); // Enhance Optimized Debugging commonArgs.Add("/Zo"); } if (compileEnvironment.Optimization) { // Enable Most Speed Optimizations commonArgs.Add("/Ox"); // Generate Intrinsic Functions commonArgs.Add("/Oi"); // Frame-Pointer Omission commonArgs.Add("/Oy"); if (compileEnvironment.WholeProgramOptimization) { // Whole Program Optimization commonArgs.Add("/GL"); } } else { // Disable compiler optimizations (Debug) commonArgs.Add("/Od"); // Frame-Pointer Omission commonArgs.Add("/Oy-"); } // Full Path of Source Code File in Diagnostics commonArgs.Add("/FC"); // Report Internal Compiler Errors commonArgs.Add("/errorReport:prompt"); // Exception Handling Model if (!compileEnvironment.CompileAsWinRT) { if (compileEnvironment.EnableExceptions) { commonArgs.Add("/EHsc"); } else { commonArgs.Add("/D_HAS_EXCEPTIONS=0"); } } // Eliminate Duplicate Strings if (compileEnvironment.StringPooling) { commonArgs.Add("/GF"); } else { commonArgs.Add("/GF-"); } // Use Run-Time Library if (compileEnvironment.UseDebugCRT) { commonArgs.Add("/MDd"); } else { commonArgs.Add("/MD"); } // Specify floating-point behavior commonArgs.Add("/fp:fast"); commonArgs.Add("/fp:except-"); // Buffer Security Check if (compileEnvironment.BufferSecurityCheck) { commonArgs.Add("/GS"); } else { commonArgs.Add("/GS-"); } // Enable Run-Time Type Information if (compileEnvironment.RuntimeTypeInfo) { commonArgs.Add("/GR"); } else { commonArgs.Add("/GR-"); } // Treats all compiler warnings as errors if (compileEnvironment.TreatWarningsAsErrors) { commonArgs.Add("/WX"); } else { commonArgs.Add("/WX-"); } // Show warnings // TODO: compile with W4 and fix all warnings commonArgs.Add("/W3"); // Silence macro redefinition warning commonArgs.Add("/wd\"4005\""); // wchar_t is Native Type commonArgs.Add("/Zc:wchar_t"); // Common Language Runtime Compilation if (compileEnvironment.CompileAsWinRT) { commonArgs.Add("/clr"); } // Windows Runtime Compilation if (compileEnvironment.WinRTComponentExtensions) { commonArgs.Add("/ZW"); //commonArgs.Add("/ZW:nostdlib"); var dir = GetCppCXMetadataDirectory(); if (dir != null) { commonArgs.Add(string.Format("/AI\"{0}\"", dir)); commonArgs.Add(string.Format("/FU\"{0}\\platform.winmd\"", dir)); } } } // Add preprocessor definitions foreach (var definition in compileEnvironment.PreprocessorDefinitions) { commonArgs.Add(string.Format("/D \"{0}\"", definition)); } // Add include paths foreach (var includePath in compileEnvironment.IncludePaths) { AddIncludePath(commonArgs, includePath); } // Compile all C++ files var args = new List <string>(); foreach (var sourceFile in sourceFiles) { var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile); var task = graph.Add <CompileCppTask>(); // Use shared arguments args.Clear(); args.AddRange(commonArgs); if (compileEnvironment.DebugInformation) { // Program Database File Name var pdbFile = Path.Combine(outputPath, sourceFilename + ".pdb"); args.Add(string.Format("/Fd\"{0}\"", pdbFile)); output.DebugDataFiles.Add(pdbFile); } if (compileEnvironment.GenerateDocumentation) { // Process Documentation Comments var docFile = Path.Combine(outputPath, sourceFilename + ".xdc"); args.Add(string.Format("/doc\"{0}\"", docFile)); output.DocumentationFiles.Add(docFile); } // Object File Name var objFile = Path.Combine(outputPath, sourceFilename + ".obj"); args.Add(string.Format("/Fo\"{0}\"", objFile)); output.ObjectFiles.Add(objFile); task.ProducedFiles.Add(objFile); // Source File Name args.Add("\"" + sourceFile + "\""); // Request included files to exist var includes = IncludesCache.FindAllIncludedFiles(sourceFile); task.PrerequisiteFiles.AddRange(includes); // Compile task.WorkingDirectory = options.WorkingDirectory; task.CommandPath = _compilerPath; task.CommandArguments = string.Join(" ", args); task.PrerequisiteFiles.Add(sourceFile); task.Cost = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting } return(output); }
/// <inheritdoc /> public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath) { var compileEnvironment = options.CompileEnv; var output = new CompileOutput(); // Setup arguments shared by all source files var commonArgs = new List <string>(); { commonArgs.Add("-c"); commonArgs.Add("-fmessage-length=0"); commonArgs.Add("-pipe"); commonArgs.Add("-x"); commonArgs.Add("objective-c++"); commonArgs.Add("-std=c++14"); commonArgs.Add("-stdlib=libc++"); AddArgsCommon(options, commonArgs); switch (Architecture) { case TargetArchitecture.x64: commonArgs.Add("-msse2"); break; } commonArgs.Add("-Wdelete-non-virtual-dtor"); commonArgs.Add("-fno-math-errno"); commonArgs.Add("-fasm-blocks"); commonArgs.Add("-fpascal-strings"); commonArgs.Add("-fdiagnostics-format=msvc"); commonArgs.Add("-Wno-absolute-value"); commonArgs.Add("-Wno-nullability-completeness"); commonArgs.Add("-Wno-undef-prefix"); commonArgs.Add("-Wno-expansion-to-defined"); commonArgs.Add("-Wno-non-virtual-dtor"); // Hide all symbols by default commonArgs.Add("-fvisibility-inlines-hidden"); commonArgs.Add("-fvisibility-ms-compat"); if (compileEnvironment.RuntimeTypeInfo) { commonArgs.Add("-frtti"); } else { commonArgs.Add("-fno-rtti"); } if (compileEnvironment.TreatWarningsAsErrors) { commonArgs.Add("-Wall -Werror"); } // TODO: compileEnvironment.IntrinsicFunctions // TODO: compileEnvironment.FunctionLevelLinking // TODO: compileEnvironment.FavorSizeOrSpeed // TODO: compileEnvironment.RuntimeChecks // TODO: compileEnvironment.StringPooling // TODO: compileEnvironment.BufferSecurityCheck if (compileEnvironment.DebugInformation) { commonArgs.Add("-gdwarf-2"); } commonArgs.Add("-pthread"); if (compileEnvironment.Optimization) { commonArgs.Add("-O3"); } else { commonArgs.Add("-O0"); } if (!compileEnvironment.Inlining) { commonArgs.Add("-fno-inline-functions"); commonArgs.Add("-fno-inline"); } if (compileEnvironment.EnableExceptions) { commonArgs.Add("-fexceptions"); } else { commonArgs.Add("-fno-exceptions"); } } // Add preprocessor definitions foreach (var definition in compileEnvironment.PreprocessorDefinitions) { commonArgs.Add(string.Format("-D \"{0}\"", definition)); } // Add include paths foreach (var includePath in compileEnvironment.IncludePaths) { commonArgs.Add(string.Format("-I\"{0}\"", includePath.Replace('\\', '/'))); } // Compile all C++ files var args = new List <string>(); foreach (var sourceFile in sourceFiles) { var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile); var task = graph.Add <CompileCppTask>(); // Use shared arguments args.Clear(); args.AddRange(commonArgs); // Object File Name var objFile = Path.Combine(outputPath, sourceFilename + ".o"); args.Add(string.Format("-o \"{0}\"", objFile.Replace('\\', '/'))); output.ObjectFiles.Add(objFile); task.ProducedFiles.Add(objFile); // Source File Name args.Add("\"" + sourceFile.Replace('\\', '/') + "\""); // Request included files to exist var includes = IncludesCache.FindAllIncludedFiles(sourceFile); task.PrerequisiteFiles.AddRange(includes); // Compile task.WorkingDirectory = options.WorkingDirectory; task.CommandPath = ClangPath; task.CommandArguments = string.Join(" ", args); task.PrerequisiteFiles.Add(sourceFile); task.InfoMessage = Path.GetFileName(sourceFile); task.Cost = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting } return(output); }
//todo async this private void Compile_SPScript() { if (InCompiling) { return; } Command_Save(); InCompiling = true; Config c = Program.ConfigList.Current; FileInfo spCompInfo = null; bool SpCompFound = false; foreach (string dir in c.SMDirectories) { //todo add setting spCompInfo = new FileInfo(Path.Combine(dir, "amxxpc.exe")); if (spCompInfo.Exists) { SpCompFound = true; break; } } if (!SpCompFound) { InCompiling = false; MessageBox.Show(Properties.Resources.Error, Properties.Resources.SPCompNotFound); return; } EditorElement ee = GetCurrentEditorElement(); if (ee == null || !ee.FullFilePath.EndsWith(".sma")) { InCompiling = false; return; } ErrorResultGrid.Items.Clear(); CompileOutput.Text = ""; StringBuilder stringOutput = new StringBuilder(); FileInfo fileInfo = new FileInfo(ee.FullFilePath); stringOutput.AppendLine(fileInfo.Name); ProcessUITasks(); if (fileInfo.Exists) { StatusLine_StatusText.Text = $"{Properties.Resources.Compiling} \"{fileInfo.Name} ...\""; CompOutTabControl.SelectedIndex = 0; using (Process process = new Process()) { string destinationFileName = Path.GetFileNameWithoutExtension(fileInfo.Name) + ".amxx"; string outFile = Path.Combine(fileInfo.DirectoryName, destinationFileName); if (File.Exists(outFile)) { File.Delete(outFile); } string compOutput = ""; StringBuilder includeDirectories = new StringBuilder(); foreach (string dir in c.SMDirectories) { includeDirectories.Append(" -i\"" + Path.Combine(dir, "include") + "\""); } process.StartInfo = new ProcessStartInfo { WorkingDirectory = fileInfo.DirectoryName, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, FileName = spCompInfo.FullName, Arguments = $"\"{fileInfo.FullName}\" -o\"{outFile}\" {includeDirectories}", // // todo add debug level RedirectStandardOutput = true }; #if DEBUG //CompileOutput.Text += $"\"{fileInfo.FullName}\" -o\"{outFile}\" {includeDirectories}\n"; #endif string execResult = ExecuteCommandLine(c.PreCmd, fileInfo.DirectoryName, c.CopyDirectory, fileInfo.FullName, fileInfo.Name, outFile, destinationFileName); if (!string.IsNullOrWhiteSpace(execResult)) { stringOutput.AppendLine(execResult.Trim('\n', '\r')); } ProcessUITasks(); try { process.Start(); compOutput = process.StandardOutput.ReadToEnd(); process.WaitForExit(); } catch (Exception) { MessageBox.Show(Properties.Resources.SPCompNotStarted, Properties.Resources.Error); InCompiling = false; StatusLine_StatusText.Text = ""; } compOutput = ReformatCompOutput(compOutput); stringOutput.Append(compOutput); MatchCollection mc = _errorFilterRegex.Matches(compOutput); foreach (Match match in mc) { string lineMatch = match.Groups["line"].Value.Trim(); string typeMatch = match.Groups["type"].Value.Trim(); ErrorResultGrid.Items.Add(new ErrorDataGridRow { file = match.Groups["file"].Value.Trim(), line = lineMatch, type = typeMatch, details = match.Groups["details"].Value.Trim() }); DocumentLine line = ee.editor.Document.Lines[int.Parse(lineMatch) - 1]; ITextMarker marker = ee.textMarkerService.Create(line.Offset, line.Length); marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline; marker.MarkerColor = typeMatch.Contains("error") ? Colors.Red : Colors.Green; } if (mc.Count > 0) { CompOutTabControl.SelectedIndex = 1; //todo get rid of this } if (process.ExitCode != 0) { StatusLine_StatusText.Text = "Error"; } else { StatusLine_StatusText.Text = "Success"; string execResult_Post = ExecuteCommandLine(c.PostCmd, fileInfo.DirectoryName, c.CopyDirectory, fileInfo.FullName, fileInfo.Name, outFile, destinationFileName); if (!string.IsNullOrWhiteSpace(execResult_Post)) { stringOutput.AppendLine(execResult_Post.Trim('\n', '\r')); } } //stringOutput.AppendLine(Properties.Resources.Done); ProcessUITasks(); } } CompileOutput.Text += stringOutput.ToString(); CompileOutput.ScrollToEnd(); if (CompileOutputRow.Height.Value < 11.0) { CompileOutputRow.Height = new GridLength(200.0); } InCompiling = false; }
private void HandleAddingPreCompiledPluginInDirectory(AggregateCatalog returnValue, string pluginDirectory) { List <Assembly> assemblies = new List <Assembly>(); var assembliesFiles = Directory.GetFiles(pluginDirectory, "*.dll"); foreach (string assemblyName in assembliesFiles) { try { if (IsAssemblyAlreadyReferenced(assemblyName)) { string message = $"Warning: {pluginDirectory} - Skipping over assembly {assemblyName} because it is already loaded by a different plugin"; CompileOutput.Add(message); } else { var asm = Assembly.LoadFrom(assemblyName); assemblies.Add(asm); } } catch (Exception ex) { CompileErrors.Add(string.Format("Failed to load {0}: {1}", assemblyName, ex.Message)); } } AggregateCatalog catalogToMakeSureStuffIsLinked = new AggregateCatalog(); foreach (var assembly in assemblies) { var catalog = new AssemblyCatalog(assembly); catalogToMakeSureStuffIsLinked.Catalogs.Add(catalog); } bool failed = false; try { var container = new CompositionContainer(catalogToMakeSureStuffIsLinked); container.GetExports <object>(); } catch (Exception e) { string message = ""; message += "Error trying to load plugins from directory: " + pluginDirectory; if (e is ReflectionTypeLoadException) { foreach (var innerException in (e as ReflectionTypeLoadException).LoaderExceptions) { message += "\r\n" + innerException.ToString(); } } else { message += "\r\n" + e.ToString(); } CompileErrors.Add(message); failed = true; } if (!failed) { foreach (var assemblyCatalog in catalogToMakeSureStuffIsLinked.Catalogs) { returnValue.Catalogs.Add(assemblyCatalog); } } }
protected override void ProcessRecord() { try { logFile = Path.Combine(logPath, "AxCompileAll.html"); StartTasks(); CompileOutput output = null; if (File.Exists(logFile)) { try { output = CompileOutput.CreateFromFile(logFile); } catch (FileNotFoundException) { throw new Exception("Compile log could not be found"); } catch (Exception ex) { throw new Exception(string.Format("Error parsing compile log: {0}", ex.Message)); } bool hasErrors = false; foreach (var item in output.Output) { string compileMessage = String.Format("{0}, line {1}, column {2} : {3}", item.TreeNodePath, item.LineNumber, item.ColumnNumber, item.Message); switch (item.Severity) { // Compile Errors case 0: WriteObject(compileMessage); hasErrors = true; break; // Compile Warnings case 1: case 2: case 3: WriteObject(compileMessage); break; // Best practices case 4: WriteObject(string.Format("BP: {0}", compileMessage)); break; // TODOs case 254: case 255: WriteObject(string.Format("TODO: {0}", compileMessage)); break; // "Other" default: WriteObject(compileMessage); break; } } if (hasErrors) { throw new Exception("Compile error(s) found"); } else { if (File.Exists(logFile)) { File.Delete(logFile); } } } } catch (Exception ex) { WriteError(new ErrorRecord(ex, "An exception occured", ErrorCategory.InvalidOperation, ConfigurationFile)); } }