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 { /// /// Defines common basic rules for standard projects inside UAF. /// [Generate] public abstract class BaseProject : CSharpProject { /// /// Example : x:\jd5\main\ /// public static readonly string BranchRoot = Globals.BranchRoot; /// /// Example : x:\jd5\main\tools\ /// public static readonly string ToolsPath = BranchRoot + @"tools\"; /// /// Example : x:\jd5\main\build\ /// public static readonly string BuildPath = BranchRoot + @"build\"; /// /// Example : x:\jd5\main\output\ /// public static readonly string OutputPath = BranchRoot + @"output\"; /// /// Example : x:\jd5\main\output\bin\Debug\Tools\TeaBox /// public static readonly string ApplicationOutputPath = OutputPath + @"\bin\[conf.Name]\Tools\[project.Name]\"; /// /// Example : x:\jd5\main\output\tmp\ /// public static readonly string TempPath = OutputPath + @"tmp\"; /// /// Example : Drive_Name:\workspace_root_folder\main\output\bin\Release\Tools\scoringtools\ /// public static readonly string ScoringToolsOuptutPath = OutputPath + @"\bin\[conf.Name]\Tools\ScoringTools\[project.Name]\"; /// /// Example : Drive_Name:\workspace_root_folder\main\tools\extern\ScoringUtilities\ /// public static readonly string ScoringUtilitiesOutput = Path.Combine(ToolsPath, "extern", "ScoringUtilities"); /// /// Path that points to the location of scoring pipeline related tools /// public static readonly string ScoringToolsPath = Path.Combine(ToolsPath, "apps", "ScoringTools"); /// /// Drive_Name:\workspace_root_folder\main\tools\ScoringTools\PostRecordingPipelineTools\src\ /// public static readonly string ScoringTools_PostRecordingPipelineTools = Path.Combine(ScoringToolsPath, "PostRecordingPipelineTools", "src"); /// /// Drive_Name:\workspace_root_folder\main\tools\ScoringTools\RecordingPipelineTools\src\ /// public static readonly string ScoringTools_RecordingPipelineTools = Path.Combine(ScoringToolsPath, "RecordingPipelineTools"); /// /// Allows to determine the solution folder and the folder on disk. /// public string ProjectType; /// /// Set to true to set the output path to a subfolder of the bin directory. /// public bool UseOwnFolderInOutput = false; /// /// Set to true to add the target project to the solution and project name. /// Mandatory if you try to generate the solutions for several projects. /// public bool UseMultiProject = Globals.UseMultiProject; public List FileAssociations = new List(); public Configuration.OutputType OutputType { get; set; } private AssemblyInfoGenerator _assemblyInfoGenerator; /// /// True if the project is located in a "Project" folder (in order to have a unit test project later). /// 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)); } /// /// Triggered before the configuration of the project. /// public event Action Configuring; /// /// Global hook to personalize projects. /// public static event Action ConfiguringProject; protected virtual void OnConfiguring(Configuration configuration, Target target) { if (ConfiguringProject != null) { ConfiguringProject(configuration, target); } if (Configuring != null) { Configuring(configuration, target); } } /// /// Triggered before the configuration of the project. /// public event Action 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 Icons(this IEnumerable 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; } } }