302 lines
11 KiB
C#
302 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JustDance.Tools.Helpers;
|
|
using Sharpmake;
|
|
using sharpmake_sharpmake.Tools.Helpers;
|
|
|
|
namespace JustDance.Tools
|
|
{
|
|
/// <summary>
|
|
/// Defines common basic rules for standard projects inside UAF.
|
|
/// </summary>
|
|
[Generate]
|
|
public abstract class BaseProject : CSharpProject
|
|
{
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\
|
|
/// </summary>
|
|
public static readonly string BranchRoot = Globals.BranchRoot;
|
|
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\tools\
|
|
/// </summary>
|
|
public static readonly string ToolsPath = BranchRoot + @"tools\";
|
|
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\build\
|
|
/// </summary>
|
|
public static readonly string BuildPath = BranchRoot + @"build\";
|
|
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\output\
|
|
/// </summary>
|
|
public static readonly string OutputPath = BranchRoot + @"output\";
|
|
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\output\bin\Debug\Tools\TeaBox
|
|
/// </summary>
|
|
public static readonly string ApplicationOutputPath = OutputPath + @"\bin\[conf.Name]\Tools\[project.Name]\";
|
|
|
|
/// <summary>
|
|
/// Example : x:\jd5\main\output\tmp\
|
|
/// </summary>
|
|
public static readonly string TempPath = OutputPath + @"tmp\";
|
|
|
|
/// <summary>
|
|
/// Example : Drive_Name:\workspace_root_folder\main\output\bin\Release\Tools\scoringtools\
|
|
/// </summary>
|
|
public static readonly string ScoringToolsOuptutPath = OutputPath + @"\bin\[conf.Name]\Tools\ScoringTools\[project.Name]\";
|
|
|
|
/// <summary>
|
|
/// Example : Drive_Name:\workspace_root_folder\main\tools\extern\ScoringUtilities\
|
|
/// </summary>
|
|
public static readonly string ScoringUtilitiesOutput = Path.Combine(ToolsPath, "extern", "ScoringUtilities");
|
|
|
|
/// <summary>
|
|
/// Path that points to the location of scoring pipeline related tools
|
|
/// </summary>
|
|
public static readonly string ScoringToolsPath = Path.Combine(ToolsPath, "apps", "ScoringTools");
|
|
|
|
/// <summary>
|
|
/// Drive_Name:\workspace_root_folder\main\tools\ScoringTools\PostRecordingPipelineTools\src\
|
|
/// </summary>
|
|
public static readonly string ScoringTools_PostRecordingPipelineTools = Path.Combine(ScoringToolsPath, "PostRecordingPipelineTools", "src");
|
|
|
|
/// <summary>
|
|
/// Drive_Name:\workspace_root_folder\main\tools\ScoringTools\RecordingPipelineTools\src\
|
|
/// </summary>
|
|
public static readonly string ScoringTools_RecordingPipelineTools = Path.Combine(ScoringToolsPath, "RecordingPipelineTools");
|
|
|
|
/// <summary>
|
|
/// Allows to determine the solution folder and the folder on disk.
|
|
/// </summary>
|
|
public string ProjectType;
|
|
|
|
/// <summary>
|
|
/// Set to true to set the output path to a subfolder of the bin directory.
|
|
/// </summary>
|
|
public bool UseOwnFolderInOutput = false;
|
|
|
|
/// <summary>
|
|
/// Set to true to add the target project to the solution and project name.
|
|
/// <remarks>Mandatory if you try to generate the solutions for several projects. </remarks>
|
|
/// </summary>
|
|
public bool UseMultiProject = Globals.UseMultiProject;
|
|
|
|
public List<FileAssociation> FileAssociations = new List<FileAssociation>();
|
|
|
|
public Configuration.OutputType OutputType { get; set; }
|
|
|
|
private AssemblyInfoGenerator _assemblyInfoGenerator;
|
|
|
|
/// <summary>
|
|
/// True if the project is located in a "Project" folder (in order to have a unit test project later).
|
|
/// </summary>
|
|
public virtual bool UnitTestCompliant
|
|
{
|
|
get { return UnitTestedProjects.Contains(GetType()); }
|
|
}
|
|
|
|
protected BaseProject(string projectType, bool sourcesInSubFolder = false)
|
|
: base(typeof(Target))
|
|
{
|
|
AddTargets(Utilities.GetDefaultTargets());
|
|
|
|
Name = GetType().Name.Replace('_', '.');
|
|
ProjectType = projectType;
|
|
RootPath = ToolsPath;
|
|
SourceRootPath = sourcesInSubFolder ? @"[project.RootPath]\[project.ProjectType]\[project.Name]\[project.Name]" : @"[project.RootPath]\[project.ProjectType]\[project.Name]";
|
|
if (UnitTestCompliant)
|
|
{
|
|
SourceRootPath += @"\Project";
|
|
}
|
|
|
|
OutputType = Configuration.OutputType.DotNetClassLibrary;
|
|
|
|
ResourcesPath = @"[project.SourceRootPath]\Resources";
|
|
|
|
ResourceFilesExtensions.Add(".png");
|
|
ResourceFilesExtensions.Add(".bmp");
|
|
ResourceFilesExtensions.Add(".gif");
|
|
ResourceFilesExtensions.Add(".jpg");
|
|
ResourceFilesExtensions.Add(".ico");
|
|
ResourceFilesExtensions.Add(".rtf");
|
|
|
|
// We use P4vs plugin so we dont store any reference to perforce in the project files.
|
|
// PerforceRootPath = null;
|
|
IsFileNameToLower = false;
|
|
_assemblyInfoGenerator = new AssemblyInfoGenerator(this);
|
|
|
|
// Used by villager to override version and information version
|
|
ImportProjects.Add(new ImportProject { Project = Path.Combine(SharpmakeCsPath, "OverrideVersion.targets") });
|
|
}
|
|
|
|
[Configure]
|
|
[ConfigurePriority(-1)]
|
|
public virtual void BeforeConfigureAll(Configuration conf, Target target)
|
|
{
|
|
OnConfiguring(conf, target);
|
|
}
|
|
|
|
[Configure]
|
|
[ConfigurePriority(0)]
|
|
public virtual void ConfigureAll(Configuration conf, Target target)
|
|
{
|
|
if (conf.Project != null) //this check is to crash in ProjectMerger.cs when a configuration is created from scratch
|
|
{
|
|
conf.Output = OutputType;
|
|
}
|
|
conf.SolutionFolder = ProjectType;
|
|
if (UnitTestedProjects.Contains(GetType()))
|
|
{
|
|
conf.SolutionFolder = ProjectType + @"\" + Name;
|
|
}
|
|
|
|
conf.ProjectFileName = "[project.Name]";
|
|
conf.IntermediatePath = OutputPath + @"tmp\Tools\[project.Name]\[target.Platform]_[target.DevEnv]_[conf.Name]";
|
|
if (conf.Output == Configuration.OutputType.DotNetWindowsApp ||
|
|
conf.Output == Configuration.OutputType.DotNetConsoleApp)
|
|
{
|
|
conf.TargetPath = ApplicationOutputPath;
|
|
}
|
|
else
|
|
{
|
|
conf.TargetPath = OutputPath + @"\lib\Tools\";
|
|
}
|
|
|
|
if (UseMultiProject)
|
|
{
|
|
conf.ProjectFileName += "." + Globals.CurrentProjectName;
|
|
conf.IntermediatePath = OutputPath + @"tmp\[project.Name]\" + Globals.CurrentProjectName + @"\[target.Platform]_[target.DevEnv]_[conf.Name]";
|
|
}
|
|
conf.ProjectPath = SourceRootPath;
|
|
|
|
|
|
conf.ReferencesByName.Add("System");
|
|
conf.ReferencesByName.Add("System.Core");
|
|
conf.ReferencesByName.Add("System.Xml.Linq");
|
|
conf.ReferencesByName.Add("System.Data.DataSetExtensions");
|
|
conf.ReferencesByName.Add("System.Data");
|
|
conf.ReferencesByName.Add("System.Xml");
|
|
|
|
conf.Defines.Add(string.Format("ITF_PROJECT_{0}", Globals.CurrentProjectName.ToUpper()));
|
|
|
|
conf.Options.Add(Options.CSharp.TreatWarningsAsErrors.Enabled);
|
|
if (target.DevEnv != DevEnv.vs2012)
|
|
{
|
|
conf.Options.Add(Options.CSharp.AutoGenerateBindingRedirects.Enabled);
|
|
}
|
|
}
|
|
|
|
[Configure]
|
|
[ConfigurePriority(1)]
|
|
public virtual void AfterConfigureAll(Configuration conf, Target target)
|
|
{
|
|
OnConfigured(conf, target);
|
|
_assemblyInfoGenerator.AfterConfigureAll(conf);
|
|
}
|
|
|
|
public void AddFileAssociation(string fileExtension, string iconPath, string applicationName = null)
|
|
{
|
|
var fileAssociation = FileAssociations.FirstOrDefault(x => x.Extension == fileExtension);
|
|
if (fileAssociation == null)
|
|
{
|
|
fileAssociation = new FileAssociation();
|
|
FileAssociations.Add(fileAssociation);
|
|
}
|
|
fileAssociation.ApplicationName = applicationName ?? ResolveString(AssemblyName);
|
|
fileAssociation.Extension = fileExtension;
|
|
fileAssociation.IconPath = Path.GetFullPath(Path.Combine(ResolveString(SourceRootPath), iconPath));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Triggered before the configuration of the project.
|
|
/// </summary>
|
|
public event Action<Configuration, Target> Configuring;
|
|
|
|
/// <summary>
|
|
/// Global hook to personalize projects.
|
|
/// </summary>
|
|
public static event Action<Configuration, Target> ConfiguringProject;
|
|
|
|
protected virtual void OnConfiguring(Configuration configuration, Target target)
|
|
{
|
|
if (ConfiguringProject != null)
|
|
{
|
|
ConfiguringProject(configuration, target);
|
|
}
|
|
|
|
if (Configuring != null)
|
|
{
|
|
Configuring(configuration, target);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Triggered before the configuration of the project.
|
|
/// </summary>
|
|
public event Action<Configuration, Target> Configured;
|
|
|
|
protected virtual void OnConfigured(Configuration configuration, Target target)
|
|
{
|
|
if (Configured != null)
|
|
{
|
|
Configured(configuration, target);
|
|
}
|
|
}
|
|
|
|
protected override void ExcludeOutputFiles()
|
|
{
|
|
// Do nothing, our output files are under source path.
|
|
// Adding those regex slows the generation for nothing.
|
|
}
|
|
|
|
public override void PostLink()
|
|
{
|
|
if (Globals.ToolsContent.HasFlag(Globals.ToolsSolutionOptions.NoCopyLocal))
|
|
{
|
|
// Do not copy local the project, they are copied in a post build step.
|
|
DependenciesCopyLocal &= ~DependenciesCopyLocalTypes.ProjectReferences;
|
|
DependenciesCopyLocal &= ~DependenciesCopyLocalTypes.DotNetReferences;
|
|
DependenciesCopyLocal &= ~DependenciesCopyLocalTypes.ExternalReferences;
|
|
|
|
if (OutputType != Configuration.OutputType.DotNetClassLibrary)
|
|
{
|
|
this.ConvertCopiesIntoHardlinks();
|
|
}
|
|
}
|
|
|
|
base.PostLink();
|
|
}
|
|
}
|
|
|
|
public class FileAssociation
|
|
{
|
|
public string Extension;
|
|
public string IconPath;
|
|
public string ApplicationName;
|
|
}
|
|
|
|
public static class FileAssociationExtensions
|
|
{
|
|
public static IEnumerable<string> Icons(this IEnumerable<FileAssociation> fileAssociations)
|
|
{
|
|
return fileAssociations.Select(x => x.IconPath).Distinct().OrderBy(x => x);
|
|
}
|
|
}
|
|
|
|
public class NuGetDependency
|
|
{
|
|
public NuGetDependency(string name, string version)
|
|
{
|
|
Name = name;
|
|
Version = version;
|
|
}
|
|
|
|
public string Name { get; set; }
|
|
|
|
public string Version { get; set; }
|
|
}
|
|
}
|