* Refractored a bit.
[ngenerator.git] / GccXmlHelper.cs
blob3c2b7e8fb5b1e4411372194fc865538a6a0abf1f
1 // /home/jeremie/TaoParser/NGenerator/GccXmlHelper.cs
2 // Writtent by jeremie at 20:02 30/05/2007
3 //
4 // This file is licensed under the LGPL licence as described in the COPYING file
6 using System;
7 using System.Diagnostics;
8 using System.IO;
10 namespace NGenerator
12 public static class GccXmlHelper
14 const string gccXmlProg = "gccxml";
15 const string xmlArg = "-fxml=";
17 static ProcessStartInfo stdInfo = new ProcessStartInfo();
18 //static ProcessStartInfo makeInfo = new ProcessStartInfo();
20 static Process commonProcess = new Process();
22 static GccXmlHelper()
24 stdInfo.WorkingDirectory = Environment.CurrentDirectory;
25 stdInfo.FileName = gccXmlProg;
26 //makeInfo.FileName = "make";
27 //stdInfo.Arguments
30 /// <summary>
31 /// This method is called when the user pass a directory to ngenerator like /home/libfoo/include/*
32 /// <argument name="dpath">The path to the directory (e.g. /home/libfoo/include/)</argument>
33 /// <return> A FileInfo reference to the generated gccxml's xml output</return>
34 public static FileInfo ParseDirectory(string dpath)
36 Logger.Debug("Parsing the directory : " + dpath);
37 EnsurePathExists(dpath);
38 FileInfo finalToParse = ResolveDirectory(dpath);
39 return Launch(finalToParse.FullName);
42 /// <summary>
43 /// This method is called when the user pass directly a master .h file
44 /// to ngenerator like /home/libfoo/include/All.h
45 /// <argument name="filename">The path to the file (e.g. /home/libfoo/include/All.h)</argument>
46 /// <return> A FileInfo reference to the generated gccxml's xml output</return>
47 public static FileInfo ParseFile(string filename)
49 EnsurePathExists(filename);
50 FileInfo finalToParse = ResolveFile(filename);
51 return Launch(finalToParse.FullName);
54 static FileInfo Launch(string filename)
56 string output = AddSourceAndParametrize(filename);
57 StartProcess(stdInfo);
58 return new FileInfo(output);
61 /// <summary>
62 /// This method takes the input file, strip unnecessary bits from it (like useless headers)
63 /// and return a FileInfo reference to the cleaned file
64 /// </summary>
65 static FileInfo ResolveFile(string filepath)
67 // The end-file should be created in the /tmp/ directory using
68 // Path.GetTempPath() or directly with Path.GetTempFile()
69 return null;
72 /// <summary>
73 /// This method takes the input directory, strip unnecessary bits from all .h files
74 /// contained in it (like useless headers), concatenate what is resting in one temp .h file
75 /// and finally returns a FileInfo reference to the cleaned file.
76 /// </summary>
77 static FileInfo ResolveDirectory (string directoryPath)
79 return null;
82 /*public static FileInfo UseMakeFile(string makeFileName)
84 EnsureFileExists(makeFileName);
85 string outputFileName = MakeOutputName();
86 // Set some environment variable to interact with the makefile
87 Environment.SetEnvironmentVariable("CC", gccXmlProg);
88 Environment.SetEnvironmentVariable("CFLAGS", xmlArg + outputFileName);
90 makeInfo.Arguments = "-f " + makeFileName.Trim();
92 StartProcess(makeInfo);
94 return new FileInfo(outputFileName);
95 }*/
97 static void StartProcess(ProcessStartInfo info)
99 commonProcess.StartInfo = info;
100 commonProcess.Start();
101 commonProcess.WaitForExit();
102 //System.Threading.Thread.Sleep(1000);
105 static void EnsurePathExists(string path)
107 // Need to test file too
108 if(!Directory.Exists(Path.GetFullPath(path)))
109 throw new DirectoryNotFoundException("The directory supplied doesn't exist : " + path);
112 static string AddSourceAndParametrize(string filename)
114 if (filename == null)
115 throw new ArgumentNullException("filename");
116 if (filename.Length == 0)
117 throw new ArgumentException("The input file is empty", "filename");
119 System.Text.StringBuilder sb = new System.Text.StringBuilder(filename.Length + 40);
120 string output = MakeOutputName();
121 sb.Append("-fno-builtin ");
122 sb.Append(filename);
123 sb.Append(' ');
124 sb.Append(xmlArg);
125 sb.Append(output);
127 stdInfo.Arguments = sb.ToString();
128 Logger.Debug("Parametrized Process with the following args : " + sb.ToString());
130 return output;
133 static string MakeOutputName()
135 /*string date = DateTime.Now.ToShortDateString();
136 date = date.Replace('/', '-');
137 return "output-" + date + ".xml";*/
138 return Path.GetTempFileName();