Added compression support

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40409
This commit is contained in:
David Anderson 2007-01-28 04:19:46 +00:00
parent 0234b51a9f
commit 7a8d164b25
8 changed files with 219 additions and 65 deletions

View File

@ -12,8 +12,48 @@ namespace builder
{
}
public abstract string CompressPackage(Package pkg);
public abstract bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath);
public string GetRevsionOfPath(string path)
{
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = path;
info.FileName = cfg.SVNVersion;
info.Arguments = "--committed " + path;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
Process p = Process.Start(info);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
string [] revs = output.Split(":".ToCharArray(), 2);
if (revs.Length < 1)
{
return null;
}
string rev = null;
if (revs.Length == 1)
{
rev = revs[0];
}
else
{
rev = revs[1];
}
rev = rev.Trim();
rev = rev.Replace("M", "");
rev = rev.Replace("S", "");
return rev;
}
public void UpdateRevisionInfo(Package pkg, Library lib)
{
string path = Config.PathFormat("{0}/{1}", cfg.SourceBase, lib.LocalPath);
@ -25,14 +65,64 @@ namespace builder
}
}
public void CopyFolder(Package pkg, string source, string dest, string [] omits)
public void UpdateRevisionInfo(string path, string file)
{
string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
string to_base = Config.PathFormat("{0}/{1}/{2}",
string vers = cfg.ProductVersion.Replace(".", ",");
string rev = GetRevsionOfPath(path);
File.Delete(file);
StreamWriter sw = File.CreateText(file);
sw.WriteLine("/** This file is autogenerated by build scripts */");
sw.WriteLine("");
sw.WriteLine("#ifndef _INCLUDE_SVN_VERSION_H_");
sw.WriteLine("#define _INCLUDE_SVN_VERSION_H_");
sw.WriteLine("");
sw.WriteLine("#define SVN_REVISION {0}", rev);
sw.WriteLine("#define SVN_REVISION_STRING \"{0}\"", rev);
sw.WriteLine("#define SVN_FILE_VERSION {0},{1}", vers, rev);
sw.WriteLine("");
sw.WriteLine("#endif //_INCLUDE_SVN_VERSION_H_");
sw.WriteLine("");
sw.Close();
}
public bool CopyFile(Package pkg, string source, string dest)
{
string from = Config.PathFormat("{0}/{1}",
cfg.SourceBase,
source);
string to = Config.PathFormat("{0}/{1}/{2}",
cfg.OutputBase,
pkg.GetBaseFolder(),
dest);
File.Copy(from, to, true);
return true;
}
/** dest can be null to mean root base folder */
public void CopyFolder(Package pkg, string source, string dest, string [] omits)
{
string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
string to_base = null;
if (dest == null)
{
to_base = Config.PathFormat("{0}/{1}",
cfg.OutputBase,
pkg.GetBaseFolder());
}
else
{
to_base = Config.PathFormat("{0}/{1}/{2}",
cfg.OutputBase,
pkg.GetBaseFolder(),
dest);
}
string [] files = Directory.GetFiles(from_base);
string file;
@ -61,59 +151,15 @@ namespace builder
}
}
public void UpdateRevisionInfo(string path, string file)
public string PackageBuildName(Package pkg)
{
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = path;
info.FileName = cfg.SVNVersion;
info.Arguments = "--committed " + path;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
Process p = Process.Start(info);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
string [] revs = output.Split(":".ToCharArray(), 2);
if (revs.Length < 1)
{
return;
}
string rev = null;
if (revs.Length == 1)
{
rev = revs[0];
}
else
{
rev = revs[1];
}
rev = rev.Trim();
rev = rev.Replace("M", "");
rev = rev.Replace("S", "");
string vers = cfg.ProductVersion.Replace(".", ",");
File.Delete(file);
StreamWriter sw = File.CreateText(file);
sw.WriteLine("/** This file is autogenerated by build scripts */");
sw.WriteLine("");
sw.WriteLine("#ifndef _INCLUDE_SVN_VERSION_H_");
sw.WriteLine("#define _INCLUDE_SVN_VERSION_H_");
sw.WriteLine("");
sw.WriteLine("#define SVN_REVISION {0}", rev);
sw.WriteLine("#define SVN_REVISION_STRING \"{0}\"", rev);
sw.WriteLine("#define SVN_FILE_VERSION {0},{1}", vers, rev);
sw.WriteLine("");
sw.WriteLine("#endif //_INCLUDE_SVN_VERSION_H_");
sw.WriteLine("");
sw.Close();
return pkg.GetPackageName()
+ "-"
+ DateTime.Now.Day.ToString("00")
+ DateTime.Now.Month.ToString("00")
+ DateTime.Now.Year
+ "-r"
+ GetRevsionOfPath(cfg.SourceBase);
}
public void BuildPackage(Package pkg)
@ -138,7 +184,7 @@ namespace builder
/* Do primitive copies */
pkg.OnCopyFolders(this);
pkg.OnCopyFiles();
pkg.OnCopyFiles(this);
/* Do libraries */
Library [] libs = pkg.GetLibraries();
@ -160,6 +206,27 @@ namespace builder
throw new System.Exception("Failed to compile library: " + libs[i].Name);
}
}
string pkg_file = null;
if ((pkg_file=CompressPackage(pkg)) == null)
{
throw new System.Exception("Failed to compress package: " + pkg.GetPackageName());
}
string lpath = null, ltarget = null;
pkg.GetCompressBases(ref lpath, ref ltarget);
lpath = Config.PathFormat("{0}/{1}/{2}",
cfg.OutputBase,
lpath,
pkg_file);
ltarget = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg_file);
if (File.Exists(ltarget))
{
File.Delete(ltarget);
}
File.Move(lpath, ltarget);
}
}
}

View File

@ -15,10 +15,10 @@ namespace builder
public string SourceBase;
public string OutputBase;
public string BuilderPath;
public string CompressPath;
public string CompressOptions;
public string SVNVersion;
public string ProductVersion;
public string Compressor;
public builder.BasePlatform Platform;
public Config()
@ -84,10 +84,6 @@ namespace builder
{
BuilderPath = val;
}
else if (key.CompareTo("CompressPath") == 0)
{
CompressPath = val;
}
else if (key.CompareTo("CompressOptions") == 0)
{
CompressOptions = val;
@ -100,6 +96,10 @@ namespace builder
{
ProductVersion = val;
}
else if (key.CompareTo("Compressor") == 0)
{
Compressor = val;
}
}
}
}

View File

@ -11,6 +11,38 @@ namespace builder
cfg = _cfg;
}
public override string CompressPackage(Package pkg)
{
string lpath = null, ltarget = null;
pkg.GetCompressBases(ref lpath, ref ltarget);
string local_dir = Config.PathFormat("{0}/{1}",
cfg.OutputBase,
lpath);
string name = PackageBuildName(pkg) + ".tar.gz";
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = cfg.Compressor;
info.WorkingDirectory = local_dir;
info.Arguments = "zcvf \"" + name + "\" \"" + ltarget + "\"";
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
local_dir = Config.PathFormat("{0}/{1}", local_dir, name);
if (!File.Exists(local_dir))
{
return null;
}
return name;
}
public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
{
ProcessStartInfo info = new ProcessStartInfo();

View File

@ -24,7 +24,12 @@ namespace builder
public abstract class Package
{
/**
* Must return the base package folder.
* Must return the root compression point.
*/
public abstract void GetCompressBases(ref string path, ref string folder);
/**
* Must return the base package output folder.
*/
public abstract string GetBaseFolder();
@ -36,7 +41,7 @@ namespace builder
/**
* Called when file to file copies must be performed
*/
public abstract void OnCopyFiles();
public abstract void OnCopyFiles(ABuilder builder);
/**
* Called when dir to dir copies must be performed
@ -47,5 +52,10 @@ namespace builder
* Called to build libraries
*/
public abstract Library [] GetLibraries();
/**
* Called to get package name
*/
public abstract string GetPackageName();
}
}

View File

@ -13,6 +13,17 @@ namespace builder
return "base/addons/sourcemod";
}
public override void GetCompressBases(ref string path, ref string folder)
{
path = "base";
folder = "addons";
}
public override string GetPackageName()
{
return "sourcemod-core";
}
/**
* Must return the list of folders to create.
*/
@ -34,7 +45,7 @@ namespace builder
/**
* Called when file to file copies must be performed
*/
public override void OnCopyFiles()
public override void OnCopyFiles(ABuilder builder)
{
}
@ -51,6 +62,7 @@ namespace builder
builder.CopyFolder(this, "plugins", "scripting", plugin_omits);
builder.CopyFolder(this, "plugins/include", "scripting/include", null);
builder.CopyFolder(this, "translations", "translations", null);
builder.CopyFolder(this, "public/licenses", null, null);
}
/**

View File

@ -11,6 +11,37 @@ namespace builder
cfg = _cfg;
}
public override string CompressPackage(Package pkg)
{
string lpath = null, ltarget = null;
pkg.GetCompressBases(ref lpath, ref ltarget);
string local_dir = Config.PathFormat("{0}/{1}",
cfg.OutputBase,
lpath);
string name = PackageBuildName(pkg) + ".zip";
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = cfg.Compressor;
info.WorkingDirectory = local_dir;
info.Arguments = "-r \"" + name + "\" \"" + ltarget + "\"";
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
local_dir = Config.PathFormat("{0}/{1}", local_dir, name);
if (!File.Exists(local_dir))
{
return null;
}
return name;
}
public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
{
ProcessStartInfo info = new ProcessStartInfo();

View File

@ -3,3 +3,4 @@ SourceBase = /home/users/dvander/sourcemod/trunk
BuilderPath = /usr/bin/make
SVNVersion = /usr/bin/svnversion
ProductVersion = 1.0.0
Compressor = /bin/tar

View File

@ -3,3 +3,4 @@ SourceBase = r:\sourcemod\trunk
BuilderPath = C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.com
SVNVersion = C:\Program Files\Subversion\bin\svnversion.exe
ProductVersion = 1.0.0
Compressor = c:\Windows\zip.exe