189 lines
6.1 KiB
Plaintext
Executable File
189 lines
6.1 KiB
Plaintext
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection.Emit;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OozyBuild
|
|
{
|
|
public class SlnProject : Project
|
|
{
|
|
static readonly string Extension = ".sln";
|
|
//static string IncredibuildExe = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Incredibuild\BuildConsole.exe");
|
|
Solution.Sln sln = null;
|
|
CustomSettings defaultSettings;
|
|
bool setInitialSettings = false;
|
|
Dictionary<string, string> realConfigurationNames = new Dictionary<string, string>();
|
|
|
|
public SlnProject()
|
|
{
|
|
// useDefaultScript = false;
|
|
|
|
PropertyChanged += ( s, e ) =>
|
|
{
|
|
if( e.PropertyName == "projectFileName" )
|
|
{
|
|
sln = null;
|
|
Init();
|
|
}
|
|
};
|
|
}
|
|
|
|
string platformsEnum = "Platforms";
|
|
string configsEnum = "Configurations";
|
|
|
|
public override void Init()
|
|
{
|
|
if( sln == null )
|
|
{
|
|
Dictionary<string, bool> platforms = new Dictionary<string, bool>();
|
|
Dictionary<string, bool> configs = new Dictionary<string, bool>();
|
|
int val;
|
|
sln = new Solution.Sln();
|
|
sln.Load( projectFileName, false );
|
|
string guid = Regex.Replace( Util.StringToGUID( projectFileName.ToLower() ).ToString(), @"[-]", "" );
|
|
string nameSpace = Path.GetFileNameWithoutExtension(projectFileName).ToLower() + "_" + guid;
|
|
|
|
VisualStudioInfo ver = VisualStudio.GetAppropriateVersion( sln.visualStudioVersion );
|
|
if(ver != null && string.IsNullOrEmpty( visualStudioVersionName ))
|
|
{
|
|
visualStudioVersion = ver;
|
|
visualStudioVersionName = ver.name;
|
|
}
|
|
|
|
|
|
ClassBuilder classBuilder = new ClassBuilder( nameSpace + "." + Path.GetFileNameWithoutExtension( projectFileName ) + "_BuildSettings", typeof( CustomSettings ) );
|
|
foreach( var config in sln.mConfigurations )
|
|
{
|
|
string[] pc = config.Key.Split( '|' );
|
|
platforms[pc[1]] = true;
|
|
configs[pc[0]] = true;
|
|
}
|
|
|
|
platformsEnum = Path.GetFileNameWithoutExtension( projectFileName ).ToLower() + "_" + guid + "_" + platformsEnum;
|
|
configsEnum = Path.GetFileNameWithoutExtension( projectFileName ).ToLower() + "_" + guid + "_" + configsEnum;
|
|
|
|
// classBuilder.AddProperty( "subsln", typeof( SlnProject ) );
|
|
//Add platforms
|
|
{
|
|
EnumBuilder projectEnum = classBuilder.AddEnum( platformsEnum );
|
|
projectEnum.Add( "None" );
|
|
val = 0;
|
|
foreach( var p in platforms )
|
|
{
|
|
string name = p.Key.Replace( " ", "" );
|
|
projectEnum.Add( name, 1<<val++ );
|
|
}
|
|
// classBuilder.AddProperty( "platforms", projectEnum.eb );
|
|
classBuilder.AddProperty("platforms", projectEnum.Create() );
|
|
}
|
|
|
|
//Add configurations
|
|
{
|
|
EnumBuilder configEnum = classBuilder.AddEnum( configsEnum );
|
|
configEnum.Add( "None" );
|
|
val = 0;
|
|
foreach( var c in configs )
|
|
{
|
|
string name = c.Key.Replace( " ", "" );
|
|
realConfigurationNames[name] = c.Key;
|
|
configEnum.Add( name, 1<<val++ );
|
|
}
|
|
// classBuilder.AddProperty( "configurations", configEnum.eb );
|
|
classBuilder.AddProperty( "configurations", configEnum.Create() );
|
|
}
|
|
|
|
if( File.Exists(IncredibuildExe) )
|
|
{
|
|
classBuilder.AddProperty("Incredibuild", typeof(bool), FieldAttributes.Public);
|
|
}
|
|
|
|
defaultSettings = classBuilder.Create() as CustomSettings;
|
|
#if false
|
|
if( projectFileName != @"Z:\343\MCC\Main\Reach\shared\engine\source\omaha\Reach.sln" )
|
|
{
|
|
SlnProject sub = new SlnProject();
|
|
sub.b.poo = 69;
|
|
sub.b.shit = "69";
|
|
|
|
sub.projectFileName = @"Z:\343\MCC\Main\Reach\shared\engine\source\omaha\Reach.sln";
|
|
// sub.customSettings = sub.defaultSettings;
|
|
// sub.setInitialSettings = true;
|
|
defaultSettings["subsln"] = sub;
|
|
defaultSettings["wank"] = new WankBiscuit();
|
|
(defaultSettings["wank"] as WankBiscuit).poo = 88;
|
|
(defaultSettings["wank"] as WankBiscuit).shit = "88";
|
|
}
|
|
#endif
|
|
customSettings = defaultSettings;
|
|
|
|
assembly = new ProjectAssembly();
|
|
assembly.assembly = classBuilder.GetAssembly();
|
|
// Type[] types= assembly.assembly.GetTypes();
|
|
// foreach( Type t in types )
|
|
// {
|
|
// }
|
|
}
|
|
}
|
|
|
|
public override void OnSelected( /*MainWindow main*/ )
|
|
{
|
|
}
|
|
|
|
public override bool GeneratePackageBuild( Builder builder, BuildParams buildParams)//bool rebuild, bool building, BuildTypeFlags flags, OozyBuild.VisualStudioInfo info )
|
|
{
|
|
if( sln != null )
|
|
{
|
|
bool useIncredibuild = (bool?)customSettings["Incredibuild"] ?? false;
|
|
|
|
Enum pe = customSettings["platforms"] as Enum;
|
|
if( pe != null )
|
|
{
|
|
string devenvOption;
|
|
if( buildParams.rebuild )
|
|
{
|
|
devenvOption = "/ReBuild";
|
|
}
|
|
else
|
|
{
|
|
devenvOption = "/Build";
|
|
}
|
|
foreach( var p in pe.GetFlags() )
|
|
{
|
|
string platform = p.ToString();
|
|
Enum ce = customSettings["configurations"] as Enum;
|
|
foreach( var c in ce.GetFlags() )
|
|
{
|
|
string config = c.ToString();
|
|
if( realConfigurationNames.TryGetValue( config, out config ) )
|
|
{
|
|
//handle sln projects?
|
|
// builder.AddBuild( enginePath, info.devenv, projectFileName + " " + devenvOption + " \"" + config + "|" + platform + "\" /Project " + project.name ).displayName = platform + " " + configuration + " " + model.ToString() + " code";
|
|
|
|
if( useIncredibuild )
|
|
{
|
|
builder.AddBuild(enginePath, IncredibuildExe, projectFileName + " " + devenvOption + " /cfg=\"" + config + "|" + platform + "\"").displayName = platform + " " + config + " code"; ;
|
|
}
|
|
else
|
|
{
|
|
builder.AddBuild(enginePath, buildParams.info.devenv, projectFileName + " " + devenvOption + " \"" + config + "|" + platform + "\" ").displayName = platform + " " + config + " code";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// SlnProject sub = customSettings["subsln"] as SlnProject;
|
|
// if( sub != null )
|
|
// {
|
|
// sub.GeneratePackageBuild( builder, rebuild, building, info );
|
|
// }
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|