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 abstract string GetPawnCompilerName();
21 public bool CompilePlugin(Package pkg, Plugin pl)
23 string local_dir = Config.PathFormat("{0}/{1}/addons/sourcemod/scripting", cfg.OutputBase, pkg.GetBaseFolder());
25 string filepath = null;
26 if (pl.Folder != null)
28 filepath = Config.PathFormat("{0}/{1}", pl.Folder, pl.Source);
35 ProcessStartInfo info = new ProcessStartInfo();
36 info.WorkingDirectory = local_dir;
37 info.FileName = Config.PathFormat("{0}/{1}", local_dir, GetPawnCompilerName());
38 info.Arguments = filepath + ".sp";
39 info.UseShellExecute = false;
40 info.RedirectStandardOutput = true;
41 info.RedirectStandardError = true;
43 Process p = Process.Start(info);
44 string output = p.StandardOutput.ReadToEnd() + "\n";
45 output += p.StandardError.ReadToEnd();
49 Console.WriteLine(output);
51 string binary = Config.PathFormat("{0}/{1}/addons/sourcemod/scripting/{2}.smx", cfg.OutputBase, pkg.GetBaseFolder(), pl.Source);
52 if (!File.Exists(binary))
56 string new_loc = Config.PathFormat("{0}/{1}/addons/sourcemod/plugins/{2}.smx", cfg.OutputBase, pkg.GetBaseFolder(), pl.Source);
60 if (File.Exists(new_loc))
64 File.Move(binary, new_loc);
66 catch (System.Exception e)
68 Console.WriteLine(e.Message);
75 public string GetRevsionOfPath(string path)
77 ProcessStartInfo info = new ProcessStartInfo();
79 info.WorkingDirectory = path;
80 info.FileName = cfg.SVNVersion;
81 info.Arguments = "--committed \"" + path + "\"";
82 info.UseShellExecute = false;
83 info.RedirectStandardOutput = true;
85 Process p = Process.Start(info);
86 string output = p.StandardOutput.ReadToEnd();
90 string [] revs = output.Split(":".ToCharArray(), 2);
107 rev = rev.Replace("M", "");
108 rev = rev.Replace("S", "");
113 public bool CopyFile(Package pkg, string source, string dest)
115 string from = Config.PathFormat("{0}/{1}",
118 string to = Config.PathFormat("{0}/{1}/{2}",
123 File.Copy(from, to, true);
128 /** dest can be null to mean root base folder */
129 public void CopyFolder(Package pkg, string source, string dest, string [] omits)
131 string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
132 string to_base = null;
136 to_base = Config.PathFormat("{0}/{1}",
138 pkg.GetBaseFolder());
142 to_base = Config.PathFormat("{0}/{1}/{2}",
148 string [] files = Directory.GetFiles(from_base);
151 for (int i=0; i<files.Length; i++)
153 file = Path.GetFileName(files[i]);
158 for (int j=0; j<omits.Length; j++)
160 if (file.CompareTo(omits[j]) == 0)
171 dest = Config.PathFormat("{0}/{1}", to_base, file);
172 File.Copy(files[i], dest, true);
176 public string PackageBuildName(Package pkg)
178 return pkg.GetPackageName()
180 + GetRevsionOfPath(cfg.SourceBase)
183 + DateTime.Now.Month.ToString("00")
184 + DateTime.Now.Day.ToString("00");
187 public void BuildPackage(Package pkg)
189 string path = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg.GetBaseFolder());
191 if (!Directory.Exists(path))
193 Directory.CreateDirectory(path);
196 /* Create all dirs */
197 string [] paths = pkg.GetFolders();
198 for (int i=0; i<paths.GetLength(0); i++)
200 path = Config.PathFormat("{0}/{1}/{2}", cfg.OutputBase, pkg.GetBaseFolder(), paths[i]);
201 if (!Directory.Exists(path))
203 Directory.CreateDirectory(path);
207 /* Do primitive copies */
208 pkg.OnCopyFolders(this);
209 pkg.OnCopyFiles(this);
212 Library [] libs = pkg.GetLibraries();
213 string bin = null, binpath = null;
214 for (int i=0; i<libs.Length; i++)
216 if (BuildLibrary(pkg, libs[i], ref bin, ref binpath))
218 path = Config.PathFormat("{0}/{1}/{2}/{3}",
223 File.Copy(binpath, path, true);
227 throw new System.Exception("Failed to compile library: " + libs[i].Name);
232 Plugin [] plugins = pkg.GetPlugins();
235 for (int i=0; i<plugins.Length; i++)
237 if (!CompilePlugin(pkg, plugins[i]))
239 throw new System.Exception("Failed to compile plugin: " + plugins[i].Source);
244 string pkg_file = null;
245 if (cfg.Compressor != null)
247 if ((pkg_file=CompressPackage(pkg)) == null)
249 throw new System.Exception("Failed to compress package: " + pkg.GetPackageName());
252 string lpath = null, ltarget = null;
253 pkg.GetCompressBases(ref lpath, ref ltarget);
254 lpath = Config.PathFormat("{0}/{1}/{2}",
258 ltarget = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg_file);
260 if (File.Exists(ltarget))
262 File.Delete(ltarget);
265 File.Move(lpath, ltarget);