tools/builder/LinuxBuilder.cs
author David Anderson <dvander@alliedmods.net>
Sun Jan 28 04:19:46 2007 +0000 (2007-01-28)
changeset 403 fe1c5a3a4ba2
parent 392 12aa3258d020
child 467 8192f64d8f57
permissions -rw-r--r--
Added compression support
     1 using System;
     2 using System.IO;
     3 using System.Diagnostics;
     4 
     5 namespace builder
     6 {
     7 	public class LinuxBuilder : ABuilder
     8 	{
     9 		public LinuxBuilder(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) + ".tar.gz";
    25 
    26 			ProcessStartInfo info = new ProcessStartInfo();
    27 			info.FileName = cfg.Compressor;
    28 			info.WorkingDirectory = local_dir;
    29 			info.Arguments = "zcvf \"" + 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 
    46 		public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
    47 		{
    48 			ProcessStartInfo info = new ProcessStartInfo();
    49 
    50 			string path = Config.PathFormat("{0}/{1}", 
    51 				cfg.SourceBase,
    52 				lib.LocalPath);
    53 
    54 			/* PlatformExt ignored for us */
    55 			string binName = lib.Name;
    56 			
    57 			if (!lib.IsExecutable)
    58 			{
    59 				if (lib.PlatformExt)
    60 				{
    61 					binName += "_i486.so";
    62 				} 
    63 				else 
    64 				{
    65 					binName += ".so";
    66 				}
    67 			}
    68 
    69 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    70 				path,
    71 				lib.ReleaseBuild,
    72 				binName);
    73 			
    74 			if (File.Exists(binpath))
    75 			{
    76 				File.Delete(binpath);
    77 			}
    78 
    79 			/* Clean the project first */
    80 			info.WorkingDirectory = path;
    81 			info.FileName = cfg.BuilderPath;
    82 			info.Arguments = "clean";
    83 			info.UseShellExecute = false;
    84 
    85 			Process p = Process.Start(info);
    86 			p.WaitForExit();
    87 			p.Close();
    88 
    89 			/* Now build it */
    90 			info.WorkingDirectory = path;
    91 			info.FileName = cfg.BuilderPath;
    92 			info.Arguments = "";
    93 			info.UseShellExecute = false;
    94 			p = Process.Start(info);
    95 			p.WaitForExit();
    96 			p.Close();
    97 
    98 			if (!File.Exists(binpath))
    99 			{
   100 				return false;
   101 			}
   102 			
   103 			_binName = binName;
   104 			_binPath = binpath;
   105 
   106 			return true;
   107 		}
   108 	}
   109 }