added build tool

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40394
This commit is contained in:
David Anderson 2007-01-27 03:10:31 +00:00
parent 17389981a0
commit 7f44c014ae
13 changed files with 846 additions and 6 deletions

View File

@ -3,9 +3,9 @@
#ifndef _INCLUDE_SVN_VERSION_H_
#define _INCLUDE_SVN_VERSION_H_
#define SVN_REVISION 390
#define SVN_REVISION_STRING "390"
#define SVN_FILE_VERSION 1,0,0,390
#define SVN_REVISION 392
#define SVN_REVISION_STRING "392"
#define SVN_FILE_VERSION 1,0,0,392
#endif //_INCLUDE_SVN_VERSION_H_

View File

@ -3,9 +3,9 @@
#ifndef _INCLUDE_SVN_VERSION_H_
#define _INCLUDE_SVN_VERSION_H_
#define SVN_REVISION 390
#define SVN_REVISION_STRING "390"
#define SVN_FILE_VERSION 1,0,0,390
#define SVN_REVISION 392
#define SVN_REVISION_STRING "392"
#define SVN_FILE_VERSION 1,0,0,392
#endif //_INCLUDE_SVN_VERSION_H_

165
tools/builder/ABuilder.cs Normal file
View File

@ -0,0 +1,165 @@
using System;
using System.IO;
using System.Diagnostics;
namespace builder
{
public abstract class ABuilder
{
public Config cfg;
public ABuilder()
{
}
public abstract bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath);
public void UpdateRevisionInfo(Package pkg, Library lib)
{
string path = Config.PathFormat("{0}/{1}", cfg.SourceBase, lib.LocalPath);
string file = Config.PathFormat("{0}/svn_version.h", path);
if (File.Exists(file))
{
UpdateRevisionInfo(path, file);
}
}
public void CopyFolder(Package pkg, string source, string dest, string [] omits)
{
string from_base = Config.PathFormat("{0}/{1}", cfg.SourceBase, source);
string to_base = Config.PathFormat("{0}/{1}/{2}",
cfg.OutputBase,
pkg.GetBaseFolder(),
dest);
string [] files = Directory.GetFiles(from_base);
string file;
for (int i=0; i<files.Length; i++)
{
file = Path.GetFileName(files[i]);
if (omits != null)
{
bool skip = false;
for (int j=0; j<omits.Length; j++)
{
if (file.CompareTo(omits[j]) == 0)
{
skip = true;
break;
}
}
if (skip)
{
continue;
}
}
dest = Config.PathFormat("{0}/{1}", to_base, file);
File.Copy(files[i], dest, true);
}
}
public void UpdateRevisionInfo(string path, string file)
{
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();
}
public void BuildPackage(Package pkg)
{
string path = Config.PathFormat("{0}/{1}", cfg.OutputBase, pkg.GetBaseFolder());
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
/* Create all dirs */
string [] paths = pkg.GetFolders();
for (int i=0; i<paths.GetLength(0); i++)
{
path = Config.PathFormat("{0}/{1}/{2}", cfg.OutputBase, pkg.GetBaseFolder(), paths[i]);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
/* Do primitive copies */
pkg.OnCopyFolders(this);
pkg.OnCopyFiles();
/* Do libraries */
Library [] libs = pkg.GetLibraries();
string bin = null, binpath = null;
for (int i=0; i<libs.Length; i++)
{
UpdateRevisionInfo(pkg, libs[i]);
if (BuildLibrary(pkg, libs[i], ref bin, ref binpath))
{
path = Config.PathFormat("{0}/{1}/{2}/{3}",
cfg.OutputBase,
pkg.GetBaseFolder(),
libs[i].Destination,
bin);
File.Copy(binpath, path, true);
}
else
{
throw new System.Exception("Failed to compile library: " + libs[i].Name);
}
}
}
}
}

View File

@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

120
tools/builder/Config.cs Normal file
View File

@ -0,0 +1,120 @@
using System;
using System.IO;
using System.Text;
namespace builder
{
public enum BasePlatform
{
Platform_Windows,
Platform_Linux
};
public class Config
{
public string SourceBase;
public string OutputBase;
public string BuilderPath;
public string CompressPath;
public string CompressOptions;
public string SVNVersion;
public string ProductVersion;
public builder.BasePlatform Platform;
public Config()
{
if ((int)System.Environment.OSVersion.Platform == 128)
{
Platform = BasePlatform.Platform_Linux;
}
else
{
Platform = BasePlatform.Platform_Windows;
}
}
public static string PathFormat(string format, params string [] args)
{
string temp = string.Format(format, args);
return temp.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
public bool ReadFromFile(string file)
{
bool read = true;
StreamReader sr = null;
try
{
sr = new StreamReader(file);
string line;
string delim = "\t \n\r\v";
string split = "=";
while ( (line = sr.ReadLine()) != null )
{
line = line.Trim(delim.ToCharArray());
if (line.Length < 1 || line[0] == ';')
{
continue;
}
string [] s = line.Split(split.ToCharArray());
string key, val = "";
if (s.GetLength(0) >= 1)
{
key = s[0];
if (s.GetLength(0) >= 2)
{
for (int i=1; i<s.GetLength(0); i++)
{
val += s[i];
}
}
key = key.Trim(delim.ToCharArray());
val = val.Trim(delim.ToCharArray());
if (key.CompareTo("SourceBase") == 0)
{
SourceBase = val;
}
else if (key.CompareTo("OutputBase") == 0)
{
OutputBase = val;
}
else if (key.CompareTo("BuilderPath") == 0)
{
BuilderPath = val;
}
else if (key.CompareTo("CompressPath") == 0)
{
CompressPath = val;
}
else if (key.CompareTo("CompressOptions") == 0)
{
CompressOptions = val;
}
else if (key.CompareTo("SVNVersion") == 0)
{
SVNVersion = val;
}
else if (key.CompareTo("ProductVersion") == 0)
{
ProductVersion = val;
}
}
}
}
catch (System.Exception e)
{
Console.WriteLine("Unable to read {0:s}: {1:s}", file, e.Message);
read = false;
}
if (sr != null)
{
sr.Close();
}
return read;
}
}
}

View File

@ -0,0 +1,93 @@
using System;
using System.IO;
using System.Diagnostics;
namespace builder
{
public class LinuxBuilder : ABuilder
{
public LinuxBuilder(Config _cfg)
{
cfg = _cfg;
}
public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
{
ProcessStartInfo info = new ProcessStartInfo();
string path = Config.PathFormat("{0}/{1}",
cfg.SourceBase,
lib.LocalPath);
/* PlatformExt ignored for us */
string binName = lib.Name;
if (!lib.IsExecutable)
{
if (lib.PlatformExt)
{
binName += "_i486.so";
}
else
{
binName += ".so";
}
}
string binpath = Config.PathFormat("{0}/{1}/{2}",
path,
lib.ReleaseBuild,
binName);
if (File.Exists(binpath))
{
File.Delete(binpath);
}
/* Clean the project first */
info.WorkingDirectory = path;
info.FileName = cfg.BuilderPath;
info.Arguments = "clean";
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
p.Close();
/* Now build it */
info.WorkingDirectory = path;
info.FileName = cfg.BuilderPath;
info.Arguments = "Release";
info.UseShellExecute = false;
p = Process.Start(info);
p.WaitForExit();
p.Close();
if (!File.Exists(binpath))
{
return false;
}
/* Now verify the binary */
info.WorkingDirectory = "/bin"; /* :TODO: Fix this */
info.FileName = "dlsym";
info.Arguments = binpath;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
p = Process.Start(info);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
if (output.IndexOf("Handle:") == -1)
{
return false;
}
_binName = binName;
_binPath = binpath;
return true;
}
}
}

39
tools/builder/Main.cs Normal file
View File

@ -0,0 +1,39 @@
using System;
using System.IO;
using System.Diagnostics;
namespace builder
{
class Program
{
static void Main(string[] args)
{
if (args.GetLength(0) < 1)
{
System.Console.WriteLine("Usage: <config file>");
return;
}
Config cfg = new Config();
if (!cfg.ReadFromFile(args[0]))
{
return;
}
/* :TODO: Add path validation */
ABuilder bld = null;
if (cfg.Platform == BasePlatform.Platform_Linux)
{
bld = new LinuxBuilder(cfg);
}
else if (cfg.Platform == BasePlatform.Platform_Windows)
{
bld = new Win32Builder(cfg);
}
bld.BuildPackage(new PkgCore());
}
}
}

51
tools/builder/Package.cs Normal file
View File

@ -0,0 +1,51 @@
using System;
namespace builder
{
public class Library
{
public Library()
{
PlatformExt = false;
ProjectFile = null;
IsExecutable = false;
ReleaseBuild = "Release";
}
public string Name; /* Name of binary */
public string LocalPath; /* Local path to library build scripts */
public string ReleaseBuild; /* Release build name */
public string Destination; /* Final relative path */
public bool PlatformExt; /* Extra platform extension */
public string ProjectFile; /* Project file, NULL for standard */
public bool IsExecutable; /* If this is an EXE instead of a DLL */
//string DebugBuild; /* Debug build name */
};
public abstract class Package
{
/**
* Must return the base package folder.
*/
public abstract string GetBaseFolder();
/**
* Must return the list of folders to create.
*/
public abstract string [] GetFolders();
/**
* Called when file to file copies must be performed
*/
public abstract void OnCopyFiles();
/**
* Called when dir to dir copies must be performed
*/
public abstract void OnCopyFolders(ABuilder builder);
/**
* Called to build libraries
*/
public abstract Library [] GetLibraries();
}
}

96
tools/builder/PkgCore.cs Normal file
View File

@ -0,0 +1,96 @@
using System;
namespace builder
{
public class PkgCore : Package
{
public PkgCore()
{
}
public override string GetBaseFolder()
{
return "base/addons/sourcemod";
}
/**
* Must return the list of folders to create.
*/
public override string [] GetFolders()
{
string [] folders = new string[7];
folders[0] = "bin";
folders[1] = "plugins/disabled";
folders[2] = "configs";
folders[3] = "translations";
folders[4] = "logs";
folders[5] = "extensions";
folders[6] = "scripting/include";
return folders;
}
/**
* Called when file to file copies must be performed
*/
public override void OnCopyFiles()
{
}
/**
* Called when dir to dir copies must be performed
*/
public override void OnCopyFolders(ABuilder builder)
{
builder.CopyFolder(this, "configs", "configs", null);
string [] plugin_omits = new string[1];
plugin_omits[0] = "spcomp.exe";
builder.CopyFolder(this, "plugins", "scripting", plugin_omits);
builder.CopyFolder(this, "plugins/include", "scripting/include", null);
builder.CopyFolder(this, "translations", "translations", null);
}
/**
* Called to build libraries
*/
public override Library [] GetLibraries()
{
Library [] libs = new Library[5];
for (int i=0; i<libs.Length; i++)
{
libs[i] = new Library();
}
libs[0].Destination = "bin";
libs[0].LocalPath = "core";
libs[0].Name = "sourcemod_mm";
libs[0].PlatformExt = true;
libs[1].Destination = "bin";
libs[1].LocalPath = "sourcepawn/jit/x86";
libs[1].Name = "sourcepawn.jit.x86";
libs[1].ProjectFile = "jit-x86";
libs[2].Destination = "scripting";
libs[2].LocalPath = "sourcepawn/compiler";
libs[2].Name = "spcomp";
libs[2].IsExecutable = true;
libs[3].Destination = "extensions";
libs[3].LocalPath = "extensions/geoip";
libs[3].Name = "geoip.ext";
libs[3].ProjectFile = "geoip";
libs[4].Destination = "extensions";
libs[4].LocalPath = "extensions/threader";
libs[4].Name = "threader.ext";
libs[4].ProjectFile = "threader";
return libs;
}
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.IO;
using System.Diagnostics;
namespace builder
{
public class Win32Builder : ABuilder
{
public Win32Builder(Config _cfg)
{
cfg = _cfg;
}
public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
{
ProcessStartInfo info = new ProcessStartInfo();
string path = Config.PathFormat("{0}/{1}/msvc8",
cfg.SourceBase,
lib.LocalPath);
/* PlatformExt ignored for us */
string binName = lib.Name + (lib.IsExecutable ? ".exe" : ".dll");
string binpath = Config.PathFormat("{0}/{1}/{2}",
path,
lib.ReleaseBuild,
binName);
if (File.Exists(binpath))
{
File.Delete(binpath);
}
string projectFile = null;
if (lib.ProjectFile != null)
{
projectFile = lib.ProjectFile + ".vcproj";
}
else
{
projectFile = lib.Name + ".vcproj";
}
info.WorkingDirectory = path;
info.FileName = cfg.BuilderPath;
info.Arguments = "/rebuild " + lib.ReleaseBuild + " " + projectFile;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
p.Close();
if (!File.Exists(binpath))
{
return false;
}
_binName = binName;
_binPath = binpath;
return true;
}
}
}

View File

View File

@ -0,0 +1,130 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.6030"
SchemaVersion = "2.0"
ProjectGuid = "{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "builder"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Exe"
PreBuildEvent = ""
PostBuildEvent = ""
RootNamespace = "builder"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.XML"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "ABuilder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Config.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "LinuxBuilder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Main.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Package.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "PkgCore.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Win32Builder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

23
tools/builder/builder.sln Normal file
View File

@ -0,0 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "builder", "builder.csproj", "{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}.Debug.ActiveCfg = Debug|.NET
{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}.Debug.Build.0 = Debug|.NET
{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}.Release.ActiveCfg = Release|.NET
{BFC4EB78-4C3E-4C81-8EAD-5A1A2F126512}.Release.Build.0 = Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal