1 // /home/jeremie/TaoParser/NGenerator/GccXmlHelper.cs
2 // Writtent by jeremie at 20:02 30/05/2007
4 // This file is licensed under the LGPL licence as described in the COPYING file
7 using System
.Diagnostics
;
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();
24 stdInfo
.WorkingDirectory
= Environment
.CurrentDirectory
;
25 stdInfo
.FileName
= gccXmlProg
;
26 //makeInfo.FileName = "make";
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
);
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
);
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
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()
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.
77 static FileInfo
ResolveDirectory (string directoryPath
)
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);
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 ");
127 stdInfo
.Arguments
= sb
.ToString();
128 Logger
.Debug("Parametrized Process with the following args : " + sb
.ToString());
133 static string MakeOutputName()
135 /*string date = DateTime.Now.ToShortDateString();
136 date = date.Replace('/', '-');
137 return "output-" + date + ".xml";*/
138 return Path
.GetTempFileName();