tools/builder/ABuilder.cs
changeset 403 fe1c5a3a4ba2
parent 388 4c346c316a49
child 424 f9bcc06b52eb
     1.1 --- a/tools/builder/ABuilder.cs	Sat Jan 27 09:28:48 2007 +0000
     1.2 +++ b/tools/builder/ABuilder.cs	Sun Jan 28 04:19:46 2007 +0000
     1.3 @@ -12,8 +12,48 @@
     1.4  		{
     1.5  		}
     1.6  
     1.7 +		public abstract string CompressPackage(Package pkg);
     1.8 +
     1.9  		public abstract bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath);
    1.10  
    1.11 +		public string GetRevsionOfPath(string path)
    1.12 +		{
    1.13 +			ProcessStartInfo info = new ProcessStartInfo();
    1.14 +
    1.15 +			info.WorkingDirectory = path;
    1.16 +			info.FileName = cfg.SVNVersion;
    1.17 +			info.Arguments = "--committed " + path;
    1.18 +			info.UseShellExecute = false;
    1.19 +			info.RedirectStandardOutput = true;
    1.20 +
    1.21 +			Process p = Process.Start(info);
    1.22 +			string output = p.StandardOutput.ReadToEnd();
    1.23 +			p.WaitForExit();
    1.24 +			p.Close();
    1.25 +
    1.26 +			string [] revs = output.Split(":".ToCharArray(), 2);
    1.27 +			if (revs.Length < 1)
    1.28 +			{
    1.29 +				return null;
    1.30 +			}
    1.31 +
    1.32 +			string rev = null;
    1.33 +			if (revs.Length == 1)
    1.34 +			{
    1.35 +				rev = revs[0];
    1.36 +			} 
    1.37 +			else 
    1.38 +			{
    1.39 +				rev = revs[1];
    1.40 +			}
    1.41 +
    1.42 +			rev = rev.Trim();
    1.43 +			rev = rev.Replace("M", "");
    1.44 +			rev = rev.Replace("S", "");
    1.45 +
    1.46 +			return rev;
    1.47 +		}
    1.48 +
    1.49  		public void UpdateRevisionInfo(Package pkg, Library lib)
    1.50  		{
    1.51  			string path = Config.PathFormat("{0}/{1}", cfg.SourceBase, lib.LocalPath);
    1.52 @@ -25,13 +65,63 @@
    1.53  			}
    1.54  		}
    1.55  
    1.56 +		public void UpdateRevisionInfo(string path, string file)
    1.57 +		{
    1.58 +			string vers = cfg.ProductVersion.Replace(".", ",");
    1.59 +			string rev = GetRevsionOfPath(path);
    1.60 +
    1.61 +			File.Delete(file);
    1.62 +			StreamWriter sw = File.CreateText(file);
    1.63 +
    1.64 +			sw.WriteLine("/** This file is autogenerated by build scripts */");
    1.65 +			sw.WriteLine("");
    1.66 +			sw.WriteLine("#ifndef _INCLUDE_SVN_VERSION_H_");
    1.67 +			sw.WriteLine("#define _INCLUDE_SVN_VERSION_H_");
    1.68 +			sw.WriteLine("");
    1.69 +			sw.WriteLine("#define SVN_REVISION			{0}", rev);
    1.70 +			sw.WriteLine("#define SVN_REVISION_STRING	\"{0}\"", rev);
    1.71 +			sw.WriteLine("#define SVN_FILE_VERSION		{0},{1}", vers, rev);
    1.72 +			sw.WriteLine("");
    1.73 +			sw.WriteLine("#endif //_INCLUDE_SVN_VERSION_H_");
    1.74 +			sw.WriteLine("");
    1.75 +
    1.76 +			sw.Close();
    1.77 +		}
    1.78 +
    1.79 +		public bool CopyFile(Package pkg, string source, string dest)
    1.80 +		{
    1.81 +			string from = Config.PathFormat("{0}/{1}", 
    1.82 +				cfg.SourceBase,
    1.83 +				source);
    1.84 +			string to = Config.PathFormat("{0}/{1}/{2}",
    1.85 +				cfg.OutputBase,
    1.86 +				pkg.GetBaseFolder(),
    1.87 +				dest);
    1.88 +
    1.89 +			File.Copy(from, to, true);
    1.90 +
    1.91 +			return true;
    1.92 +		}
    1.93 +
    1.94 +		/** dest can be null to mean root base folder */
    1.95  		public void CopyFolder(Package pkg, string source, string dest, string [] omits)
    1.96  		{
    1.97  			string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
    1.98 -			string to_base = Config.PathFormat("{0}/{1}/{2}", 
    1.99 -				cfg.OutputBase, 
   1.100 -				pkg.GetBaseFolder(), 
   1.101 -				dest);
   1.102 +			string to_base = null;
   1.103 +			
   1.104 +			if (dest == null)
   1.105 +			{
   1.106 +				to_base = Config.PathFormat("{0}/{1}", 
   1.107 +					cfg.OutputBase, 
   1.108 +					pkg.GetBaseFolder());
   1.109 +			} 
   1.110 +			else 
   1.111 +			{
   1.112 +				to_base = Config.PathFormat("{0}/{1}/{2}", 
   1.113 +					cfg.OutputBase, 
   1.114 +					pkg.GetBaseFolder(), 
   1.115 +					dest);
   1.116 +			}
   1.117  
   1.118  			string [] files = Directory.GetFiles(from_base);
   1.119  			string file;
   1.120 @@ -61,59 +151,15 @@
   1.121  			}
   1.122  		}
   1.123  
   1.124 -		public void UpdateRevisionInfo(string path, string file)
   1.125 +		public string PackageBuildName(Package pkg)
   1.126  		{
   1.127 -			ProcessStartInfo info = new ProcessStartInfo();
   1.128 -
   1.129 -			info.WorkingDirectory = path;
   1.130 -			info.FileName = cfg.SVNVersion;
   1.131 -			info.Arguments = "--committed " + path;
   1.132 -			info.UseShellExecute = false;
   1.133 -			info.RedirectStandardOutput = true;
   1.134 -
   1.135 -			Process p = Process.Start(info);
   1.136 -			string output = p.StandardOutput.ReadToEnd();
   1.137 -			p.WaitForExit();
   1.138 -			p.Close();
   1.139 -
   1.140 -			string [] revs = output.Split(":".ToCharArray(), 2);
   1.141 -			if (revs.Length < 1)
   1.142 -			{
   1.143 -				return;
   1.144 -			}
   1.145 -
   1.146 -			string rev = null;
   1.147 -			if (revs.Length == 1)
   1.148 -			{
   1.149 -				rev = revs[0];
   1.150 -			} 
   1.151 -			else 
   1.152 -			{
   1.153 -				rev = revs[1];
   1.154 -			}
   1.155 -
   1.156 -			rev = rev.Trim();
   1.157 -			rev = rev.Replace("M", "");
   1.158 -			rev = rev.Replace("S", "");
   1.159 -
   1.160 -			string vers = cfg.ProductVersion.Replace(".", ",");
   1.161 -
   1.162 -			File.Delete(file);
   1.163 -			StreamWriter sw = File.CreateText(file);
   1.164 -
   1.165 -			sw.WriteLine("/** This file is autogenerated by build scripts */");
   1.166 -			sw.WriteLine("");
   1.167 -			sw.WriteLine("#ifndef _INCLUDE_SVN_VERSION_H_");
   1.168 -			sw.WriteLine("#define _INCLUDE_SVN_VERSION_H_");
   1.169 -			sw.WriteLine("");
   1.170 -			sw.WriteLine("#define SVN_REVISION			{0}", rev);
   1.171 -			sw.WriteLine("#define SVN_REVISION_STRING	\"{0}\"", rev);
   1.172 -			sw.WriteLine("#define SVN_FILE_VERSION		{0},{1}", vers, rev);
   1.173 -			sw.WriteLine("");
   1.174 -			sw.WriteLine("#endif //_INCLUDE_SVN_VERSION_H_");
   1.175 -			sw.WriteLine("");
   1.176 -
   1.177 -			sw.Close();
   1.178 +			return pkg.GetPackageName() 
   1.179 +				+ "-"
   1.180 +				+ DateTime.Now.Day.ToString("00")
   1.181 +				+ DateTime.Now.Month.ToString("00")
   1.182 +				+ DateTime.Now.Year
   1.183 +				+ "-r"
   1.184 +				+ GetRevsionOfPath(cfg.SourceBase);
   1.185  		}
   1.186  
   1.187  		public void BuildPackage(Package pkg)
   1.188 @@ -138,7 +184,7 @@
   1.189  
   1.190  			/* Do primitive copies */
   1.191  			pkg.OnCopyFolders(this);
   1.192 -			pkg.OnCopyFiles();
   1.193 +			pkg.OnCopyFiles(this);
   1.194  
   1.195  			/* Do libraries */
   1.196  			Library [] libs = pkg.GetLibraries();
   1.197 @@ -160,6 +206,27 @@
   1.198  					throw new System.Exception("Failed to compile library: " + libs[i].Name);
   1.199  				}
   1.200  			}
   1.201 +
   1.202 +			string pkg_file = null;
   1.203 +			if ((pkg_file=CompressPackage(pkg)) == null)
   1.204 +			{
   1.205 +				throw new System.Exception("Failed to compress package: " + pkg.GetPackageName());
   1.206 +			}
   1.207 +
   1.208 +			string lpath = null, ltarget = null;
   1.209 +			pkg.GetCompressBases(ref lpath, ref ltarget);
   1.210 +			lpath = Config.PathFormat("{0}/{1}/{2}",
   1.211 +				cfg.OutputBase,
   1.212 +				lpath,
   1.213 +				pkg_file);
   1.214 +			ltarget = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg_file);
   1.215 +
   1.216 +			if (File.Exists(ltarget))
   1.217 +			{
   1.218 +				File.Delete(ltarget);
   1.219 +			}
   1.220 +
   1.221 +			File.Move(lpath, ltarget);
   1.222  		}
   1.223  	}
   1.224  }