3 using System.Diagnostics;
7 public abstract class ABuilder
15 public abstract string CompressPackage(Package pkg);
17 public abstract bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath);
19 public string GetRevsionOfPath(string path)
21 ProcessStartInfo info = new ProcessStartInfo();
23 info.WorkingDirectory = path;
24 info.FileName = cfg.SVNVersion;
25 info.Arguments = "--committed \"" + path + "\"";
26 info.UseShellExecute = false;
27 info.RedirectStandardOutput = true;
29 Process p = Process.Start(info);
30 string output = p.StandardOutput.ReadToEnd();
34 string [] revs = output.Split(":".ToCharArray(), 2);
51 rev = rev.Replace("M", "");
52 rev = rev.Replace("S", "");
57 public void UpdateRevisionInfo(Package pkg, Library lib)
59 string path = Config.PathFormat("{0}/{1}", cfg.SourceBase, lib.LocalPath);
60 string file = Config.PathFormat("{0}/svn_version.h", path);
62 if (File.Exists(file))
64 UpdateRevisionInfo(path, file);
68 public void UpdateRevisionInfo(string path, string file)
70 string vers = cfg.ProductVersion.Replace(".", ",");
71 string rev = GetRevsionOfPath(path);
74 StreamWriter sw = File.CreateText(file);
76 sw.WriteLine("/** This file is autogenerated by build scripts */");
78 sw.WriteLine("#ifndef _INCLUDE_SVN_VERSION_H_");
79 sw.WriteLine("#define _INCLUDE_SVN_VERSION_H_");
81 sw.WriteLine("#define SVN_REVISION {0}", rev);
82 sw.WriteLine("#define SVN_REVISION_STRING \"{0}\"", rev);
83 sw.WriteLine("#define SVN_FILE_VERSION {0},{1}", vers, rev);
85 sw.WriteLine("#endif //_INCLUDE_SVN_VERSION_H_");
91 public bool CopyFile(Package pkg, string source, string dest)
93 string from = Config.PathFormat("{0}/{1}",
96 string to = Config.PathFormat("{0}/{1}/{2}",
101 File.Copy(from, to, true);
106 /** dest can be null to mean root base folder */
107 public void CopyFolder(Package pkg, string source, string dest, string [] omits)
109 string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
110 string to_base = null;
114 to_base = Config.PathFormat("{0}/{1}",
116 pkg.GetBaseFolder());
120 to_base = Config.PathFormat("{0}/{1}/{2}",
126 string [] files = Directory.GetFiles(from_base);
129 for (int i=0; i<files.Length; i++)
131 file = Path.GetFileName(files[i]);
136 for (int j=0; j<omits.Length; j++)
138 if (file.CompareTo(omits[j]) == 0)
149 dest = Config.PathFormat("{0}/{1}", to_base, file);
150 File.Copy(files[i], dest, true);
154 public string PackageBuildName(Package pkg)
156 return pkg.GetPackageName()
158 + DateTime.Now.Day.ToString("00")
159 + DateTime.Now.Month.ToString("00")
162 + GetRevsionOfPath(cfg.SourceBase);
165 public void BuildPackage(Package pkg)
167 string path = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg.GetBaseFolder());
169 if (!Directory.Exists(path))
171 Directory.CreateDirectory(path);
174 /* Create all dirs */
175 string [] paths = pkg.GetFolders();
176 for (int i=0; i<paths.GetLength(0); i++)
178 path = Config.PathFormat("{0}/{1}/{2}", cfg.OutputBase, pkg.GetBaseFolder(), paths[i]);
179 if (!Directory.Exists(path))
181 Directory.CreateDirectory(path);
185 /* Do primitive copies */
186 pkg.OnCopyFolders(this);
187 pkg.OnCopyFiles(this);
190 Library [] libs = pkg.GetLibraries();
191 string bin = null, binpath = null;
192 for (int i=0; i<libs.Length; i++)
194 UpdateRevisionInfo(pkg, libs[i]);
195 if (BuildLibrary(pkg, libs[i], ref bin, ref binpath))
197 path = Config.PathFormat("{0}/{1}/{2}/{3}",
202 File.Copy(binpath, path, true);
206 throw new System.Exception("Failed to compile library: " + libs[i].Name);
210 string pkg_file = null;
211 if ((pkg_file=CompressPackage(pkg)) == null)
213 throw new System.Exception("Failed to compress package: " + pkg.GetPackageName());
216 string lpath = null, ltarget = null;
217 pkg.GetCompressBases(ref lpath, ref ltarget);
218 lpath = Config.PathFormat("{0}/{1}/{2}",
222 ltarget = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg_file);
224 if (File.Exists(ltarget))
226 File.Delete(ltarget);
229 File.Move(lpath, ltarget);