tools/builder/Win32Builder.cs
author David Anderson <dvander@alliedmods.net>
Sun Dec 23 00:08:08 2007 +0000 (2007-12-23)
changeset 1816 269bbfbfbcac
parent 1558 95a3d8bf618d
child 2289 44045ead61cd
permissions -rw-r--r--
added pdb logging
     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 GetPawnCompilerName()
    15 		{
    16 			return "spcomp.exe";
    17 		}
    18 
    19 		public override bool BuildLibrary(Package pkg, Library lib)
    20 		{
    21 			ProcessStartInfo info = new ProcessStartInfo();
    22 
    23 			string path = Config.PathFormat("{0}/{1}/msvc8", 
    24 				cfg.source_path,
    25 				lib.source_path);
    26 
    27 			/* PlatformExt ignored for us */
    28 			string binName = lib.binary_name + (lib.is_executable ? ".exe" : ".dll");
    29 
    30 			string config_name = "Unknown";
    31 
    32 			if (lib.release_mode == ReleaseMode.ReleaseMode_Release)
    33 			{
    34 				config_name = "Release";
    35 			}
    36 			else if (lib.release_mode == ReleaseMode.ReleaseMode_Debug)
    37 			{
    38 				config_name = "Debug";
    39 			}
    40 
    41 			if (lib.build_mode == BuildMode.BuildMode_Episode1)
    42 			{
    43 				config_name = config_name + " - Episode 1";
    44 			}
    45 			else if (lib.build_mode == BuildMode.BuildMode_Episode2)
    46 			{
    47 				config_name = config_name + " - Orange Box";
    48 			}
    49 			else if (lib.build_mode == BuildMode.BuildMode_OldMetamod)
    50 			{
    51 				config_name = config_name + " - Old Metamod";
    52 			}
    53 
    54 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    55 				path,
    56 				config_name,
    57 				binName);
    58 			
    59 			if (File.Exists(binpath))
    60 			{
    61 				File.Delete(binpath);
    62 			}
    63 
    64 			string project_file = null;
    65 			if (lib.vcproj_name != null)
    66 			{
    67 				project_file = lib.vcproj_name + ".vcproj";
    68 			} 
    69 			else 
    70 			{
    71 				project_file = lib.binary_name + ".vcproj";
    72 			}
    73 
    74 			info.WorkingDirectory = path;
    75 			info.FileName = cfg.builder_path;
    76 			info.UseShellExecute = false;
    77 			info.RedirectStandardOutput = true;
    78 			info.RedirectStandardError = true;
    79 
    80 			if (cfg.build_options != null)
    81 			{
    82 				info.Arguments = cfg.build_options + " ";
    83 			}
    84 
    85 			info.Arguments += "/rebuild \"" + config_name + "\" " + project_file;
    86 
    87 			Process p = Process.Start(info);
    88 			Console.WriteLine(p.StandardOutput.ReadToEnd());
    89 			p.WaitForExit();
    90 			p.Close();
    91 
    92 			if (!File.Exists(binpath))
    93 			{
    94 				return false;
    95 			}
    96 
    97 			path = Config.PathFormat("{0}/{1}/{2}/{3}",
    98 				cfg.pkg_path,
    99 				pkg.GetBaseFolder(),
   100 				lib.package_path,
   101 				binName);
   102 			File.Copy(binpath, path, true);
   103 
   104 			/* On Windows we optionally log the PDB path */
   105 			if (!lib.is_executable && cfg.pdb_log_file != null)
   106 			{
   107 				FileStream fs = File.Open(cfg.pdb_log_file, FileMode.Append, FileAccess.Write);
   108 				StreamWriter sw = new StreamWriter(fs);
   109 				sw.WriteLine(binpath.Replace(".dll", ".pdb"));
   110 				sw.Close();
   111 			}
   112 
   113 			return true;
   114 		}
   115 	}
   116 }