tools/builder/Win32Builder.cs
author Borja Ferrer <faluco@alliedmods.net>
Thu May 10 22:51:56 2007 +0000 (2007-05-10)
changeset 762 e82fc0f89dc1
parent 686 b3f80b9ced9e
child 852 9a7a93363979
permissions -rw-r--r--
added debug code for leak detection on plugins
     1 using System;
     2 using System.IO;
     3 using System.Diagnostics;
     4 
     5 namespace builder
     6 {
     7 	public class Win32Builder : ABuilder
     8 	{
     9 		public Win32Builder(Config _cfg)
    10 		{
    11 			cfg = _cfg;
    12 		}
    13 
    14 		public override string CompressPackage(Package pkg)
    15 		{
    16 			string lpath = null, ltarget = null;
    17 			
    18 			pkg.GetCompressBases(ref lpath, ref ltarget);
    19 
    20 			string local_dir = Config.PathFormat("{0}/{1}", 
    21 				cfg.OutputBase,
    22 				lpath);
    23 
    24 			string name = PackageBuildName(pkg) + ".zip";
    25 
    26 			ProcessStartInfo info = new ProcessStartInfo();
    27 			info.FileName = cfg.Compressor;
    28 			info.WorkingDirectory = local_dir;
    29 			info.Arguments = "-r \"" + name + "\" \"" + ltarget + "\"";
    30 			info.UseShellExecute = false;
    31 
    32 			Process p = Process.Start(info);
    33 			p.WaitForExit();
    34 
    35 			local_dir = Config.PathFormat("{0}/{1}", local_dir, name);
    36 
    37 			if (!File.Exists(local_dir))
    38 			{
    39 				return null;
    40 			}
    41 
    42 			return name;
    43 		}
    44 
    45 		public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
    46 		{
    47 			ProcessStartInfo info = new ProcessStartInfo();
    48 
    49 			string path = Config.PathFormat("{0}/{1}/msvc8", 
    50 				cfg.SourceBase,
    51 				lib.LocalPath);
    52 
    53 			/* PlatformExt ignored for us */
    54 			string binName = lib.Name + (lib.IsExecutable ? ".exe" : ".dll");
    55 
    56 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    57 				path,
    58 				lib.ReleaseBuild,
    59 				binName);
    60 			
    61 			if (File.Exists(binpath))
    62 			{
    63 				File.Delete(binpath);
    64 			}
    65 
    66 			string projectFile = null;
    67 			if (lib.ProjectFile != null)
    68 			{
    69 				projectFile = lib.ProjectFile + ".vcproj";
    70 			} 
    71 			else 
    72 			{
    73 				projectFile = lib.Name + ".vcproj";
    74 			}
    75 
    76 			info.WorkingDirectory = path;
    77 			info.FileName = cfg.BuilderPath;
    78 			info.UseShellExecute = false;
    79 			info.RedirectStandardOutput = true;
    80 			info.RedirectStandardError = true;
    81 
    82 			if (cfg.BuildOptions != null)
    83 			{
    84 				info.Arguments = cfg.BuildOptions + " ";
    85 			}
    86 
    87 			info.Arguments += "/rebuild " + lib.ReleaseBuild + " " + projectFile;
    88 
    89 			Process p = Process.Start(info);
    90 			Console.WriteLine(p.StandardOutput.ReadToEnd());
    91 			p.WaitForExit();
    92 			p.Close();
    93 
    94 			if (!File.Exists(binpath))
    95 			{
    96 				return false;
    97 			}
    98 
    99 			_binName = binName;
   100 			_binPath = binpath;
   101 
   102 			return true;
   103 		}
   104 	}
   105 }