public override void Clean(IProgressMonitor monitor, CombineEntry entry) { base.Clean(monitor, entry); CProject project = entry as CProject; if (project == null) { return; } StringBuilder cleanFiles = new StringBuilder(); foreach (ProjectFile file in project.ProjectFiles) { if (file.BuildAction == BuildAction.Compile) { cleanFiles.Append(Path.ChangeExtension(file.Name, ".o") + " "); cleanFiles.Append(Path.ChangeExtension(file.Name, ".d") + " "); } } ProcessWrapper p = Runtime.ProcessService.StartProcess("rm", cleanFiles.ToString(), null, null); p.WaitForExit(); p.Close(); }
protected static string GeneratePkgConfigArgs(ProjectPackageCollection packages, string pkgConfigArg) { if (packages == null || packages.Count < 1) { return(string.Empty); } string originalPkgConfigPath = Environment.GetEnvironmentVariable("PKG_CONFIG_PATH"); string pkgConfigPath = originalPkgConfigPath; StringBuilder libs = new StringBuilder(); foreach (Package p in packages) { if (Path.IsPathRooted(p.File)) { pkgConfigPath = string.Format("{0}{1}{2}", pkgConfigPath, Path.PathSeparator, Path.GetDirectoryName(p.File)); libs.Append(Path.GetFileNameWithoutExtension(p.File) + " "); } else { libs.Append(p.File + " "); } } string args = string.Format("{0} \"{1}\"", pkgConfigArg, libs.ToString().Trim()); StringWriter output = new StringWriter(); ProcessWrapper proc = new ProcessWrapper(); try { Environment.SetEnvironmentVariable("PKG_CONFIG_PATH", pkgConfigPath); proc = Runtime.ProcessService.StartProcess("pkg-config", args, null, null); proc.WaitForExit(); string line; while ((line = proc.StandardOutput.ReadLine()) != null) { output.WriteLine(line); } } catch (Exception ex) { MessageService.ShowException(ex, "You need to have pkg-config installed"); } finally { proc.Close(); Environment.SetEnvironmentVariable("PKG_CONFIG_PATH", originalPkgConfigPath); } return(output.ToString()); }
private void DoPrecompileHeader(ProjectFile file, string output, string args) { string completeArgs = String.Format("{0} {1} -o {2}", file.Name, args, output); ProcessWrapper p = Runtime.ProcessService.StartProcess(compilerCommand, completeArgs, null, null); p.WaitForExit(); p.Close(); }
internal string[] Headers(string filename, bool with_system) { string option = (with_system ? "-M" : "-MM"); ProcessWrapper p = Runtime.ProcessService.StartProcess("gcc", option + " -MG " + filename, null, null); p.WaitForExit(); StringBuilder output = new StringBuilder(); string line; while ((line = p.StandardOutput.ReadLine()) != null) { output.Append(line); } p.Close(); string[] lines = output.ToString().Split('\\'); List <string> headers = new List <string> (); for (int i = 0; i < lines.Length; i++) { string[] files = lines[i].Split(' '); // first line contains the rule (eg. file.o: dep1.c dep2.h ...) and we must skip it // and we skip the *.cpp or *.c etc. too for (int j = 0; j < files.Length; j++) { if (j == 0 || j == 1) { continue; } string depfile = files[j].Trim(); if (!string.IsNullOrEmpty(depfile)) { headers.Add(depfile); } } } return(headers.ToArray()); }
/// <summary> /// Compiles a single source file into object code /// and creates a file with it's dependencies. /// </summary> private bool DoCompilation(ProjectFile file, string args, ProjectPackageCollection packages, IProgressMonitor monitor, CompilerResults cr, bool use_ccache) { string outputName = Path.ChangeExtension(file.Name, ".o"); string pkgargs = GeneratePkgCompilerArgs(packages); string compiler_args = string.Format("{0} -MMD {1} {2} -c -o {3} {4}", (use_ccache ? compilerCommand : string.Empty), file.Name, args, outputName, pkgargs); monitor.Log.WriteLine("using: " + compilerCommand + " " + compiler_args); ProcessWrapper p = Runtime.ProcessService.StartProcess( (use_ccache ? "ccache" : compilerCommand), compiler_args, null, null); p.WaitForExit(); string line; StringWriter error = new StringWriter(); while ((line = p.StandardError.ReadLine()) != null) { error.WriteLine(line); } monitor.Log.WriteLine(error.ToString()); ParseCompilerOutput(error.ToString(), cr); error.Close(); bool result = p.ExitCode == 0; p.Close(); return(result); }
protected string GeneratePkgLinkerArgs(ProjectPackageCollection packages) { if (packages == null || packages.Count < 1) { return(string.Empty); } StringBuilder libs = new StringBuilder(); foreach (Package p in packages) { libs.Append(p.File + " "); } string args = string.Format("--libs {0}", libs.ToString().Trim()); StringWriter output = new StringWriter(); ProcessWrapper proc = new ProcessWrapper(); try { proc = Runtime.ProcessService.StartProcess("pkg-config", args, null, null); proc.WaitForExit(); string line; while ((line = proc.StandardOutput.ReadLine()) != null) { output.WriteLine(line); } } catch (Exception ex) { MessageService.ShowException(ex, "You need to have pkg-config installed"); } finally { proc.Close(); } return(output.ToString()); }
private void MakeSharedLibrary(ProjectFileCollection projectFiles, ProjectPackageCollection packages, CProjectConfiguration configuration, CompilerResults cr, IProgressMonitor monitor, string outputName) { if (!NeedsUpdate(projectFiles, outputName)) { return; } string objectFiles = StringArrayToSingleString(ObjectFiles(projectFiles)); string pkgargs = GeneratePkgLinkerArgs(packages); StringBuilder args = new StringBuilder(); CCompilationParameters cp = (CCompilationParameters)configuration.CompilationParameters; if (cp.ExtraLinkerArguments != null && cp.ExtraLinkerArguments.Length > 0) { string extraLinkerArgs = cp.ExtraLinkerArguments.Replace('\n', ' '); args.Append(extraLinkerArgs + " "); } if (configuration.LibPaths != null) { foreach (string libpath in configuration.LibPaths) { args.Append("-L" + libpath + " "); } } if (configuration.Libs != null) { foreach (string lib in configuration.Libs) { args.Append("-l" + lib + " "); } } monitor.Log.WriteLine("Generating shared object..."); string linker_args = string.Format("-shared -o {0} {1} {2} {3}", outputName, objectFiles, args.ToString(), pkgargs); monitor.Log.WriteLine("using: " + linkerCommand + " " + linker_args); ProcessWrapper p = Runtime.ProcessService.StartProcess(linkerCommand, linker_args, null, null); p.WaitForExit(); string line; StringWriter error = new StringWriter(); while ((line = p.StandardError.ReadLine()) != null) { error.WriteLine(line); } monitor.Log.WriteLine(error.ToString()); ParseCompilerOutput(error.ToString(), cr); error.Close(); p.Close(); ParseLinkerOutput(error.ToString(), cr); }