285 lines
13 KiB
C#
285 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using JustDance.Engine;
|
|
using JustDance.Tools;
|
|
using Sharpmake;
|
|
using Optimization = Sharpmake.Optimization;
|
|
|
|
namespace JustDance
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
|
public sealed class PackageTagsAttribute : Attribute
|
|
{
|
|
public string[] Tags;
|
|
|
|
public PackageTagsAttribute(params string[] tags)
|
|
{
|
|
Tags = tags;
|
|
}
|
|
}
|
|
|
|
public static class VillagerInfoGenerator
|
|
{
|
|
private static string AsString(this Platform platform)
|
|
{
|
|
switch (platform)
|
|
{
|
|
case Platform.anycpu:
|
|
return "AnyCpu";
|
|
|
|
case Platform.win64:
|
|
return "x64";
|
|
|
|
default:
|
|
return platform.ToString();
|
|
}
|
|
}
|
|
|
|
private static string AsEngineString(this Platform platform)
|
|
{
|
|
switch (platform)
|
|
{
|
|
case Platform._reserved8:
|
|
return "prospero";
|
|
|
|
case Platform._reserved7:
|
|
return "scarlett";
|
|
|
|
default:
|
|
return platform.ToString();
|
|
}
|
|
}
|
|
|
|
private static string AsString(this Optimization optimization)
|
|
{
|
|
switch (optimization)
|
|
{
|
|
case Optimization.Retail:
|
|
return "Final";
|
|
|
|
default:
|
|
return optimization.ToString();
|
|
}
|
|
}
|
|
|
|
private static string AsString(this Engine.Optimization optimization)
|
|
{
|
|
switch (optimization)
|
|
{
|
|
case Engine.Optimization.Retail:
|
|
return "Final";
|
|
|
|
default:
|
|
return optimization.ToString();
|
|
}
|
|
}
|
|
|
|
private static void WriteFile(string filePath, string content)
|
|
{
|
|
FileInfo file = new FileInfo(filePath);
|
|
file.Directory.Create();
|
|
|
|
if (file.Exists)
|
|
{
|
|
file.Attributes &= ~FileAttributes.ReadOnly;
|
|
}
|
|
|
|
File.WriteAllText(file.FullName, content);
|
|
}
|
|
|
|
private static void WriteInfo<TConfiguration>(
|
|
this object item,
|
|
string name,
|
|
string projectFilePath,
|
|
IEnumerable<TConfiguration> configurations,
|
|
string[] targets = null,
|
|
string[] prerequisites = null,
|
|
string[] unavailableOperations = null,
|
|
string msBuildVersion = null)
|
|
{
|
|
DescriptionAttribute descriptionAttribute = item.GetType().GetCustomAttribute<DescriptionAttribute>(true);
|
|
PackageTagsAttribute packageTagsAttribute = item.GetType().GetCustomAttribute<PackageTagsAttribute>(true);
|
|
|
|
IEnumerable<string> tags = packageTagsAttribute != null ? packageTagsAttribute.Tags : Array.Empty<string>();
|
|
|
|
if (!tags.Any(t => t.StartsWith("project-")))
|
|
{
|
|
tags = tags.Concat(Enumerable.Repeat("project-JustDance2022", 1));
|
|
}
|
|
|
|
WriteFile(
|
|
Path.Combine(Globals.ApplicationInfosOutput.FullName, name + ".json"),
|
|
Ubisoft.Json.JsonUtils.SerializeToString(
|
|
new
|
|
{
|
|
ApplicationName = name,
|
|
ProjectFilePath = projectFilePath,
|
|
Configurations = configurations.Distinct().ToArray(),
|
|
Targets = targets ?? Array.Empty<string>(),
|
|
Description = descriptionAttribute == null ? string.Empty : descriptionAttribute.Description,
|
|
PackageTags = string.Join(" ", tags),
|
|
Prerequisites = prerequisites ?? Array.Empty<string>(),
|
|
UnavailableOperations = unavailableOperations ?? Array.Empty<string>(),
|
|
MsBuildVersion = msBuildVersion
|
|
},
|
|
Ubisoft.Json.JsonUtils.JsonFormatting.Indented));
|
|
}
|
|
|
|
public static void GenerateInfos(List<Project> projects, List<Solution> solutions)
|
|
{
|
|
if (Globals.ApplicationInfosOutput == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (Project project in projects)
|
|
{
|
|
// c# tools
|
|
if (project is BaseProject)
|
|
{
|
|
BaseProject baseProject = (BaseProject)project;
|
|
if (baseProject.OutputType == Project.Configuration.OutputType.Exe
|
|
|| baseProject.OutputType == Project.Configuration.OutputType.DotNetConsoleApp
|
|
|| baseProject.OutputType == Project.Configuration.OutputType.DotNetWindowsApp)
|
|
{
|
|
Project.Configuration configuration = project.Configurations.First();
|
|
string projectFilePath = Path.Combine(project.ResolveString(project.SourceRootPath).Replace(@"\\", @"\").TrimEnd('\\'), project.ResolveString(configuration.ProjectFileName, configuration, configuration.Target) + ".csproj");
|
|
|
|
project.WriteInfo(
|
|
project.Name,
|
|
projectFilePath,
|
|
project.Configurations.Where(c => c.Target.GetPlatform() == Platform.win64).Select(c => new
|
|
{
|
|
Platform = c.Target.GetPlatform().AsString(),
|
|
Configuration = c.Target.GetOptimization().AsString(),
|
|
OutputPath = project.ResolveString(c.TargetPath, c, c.Target).Replace(@"\\", @"\").TrimEnd('\\')
|
|
}),
|
|
null,
|
|
// check if JD.Serialization is referenced somewhere, not clean but we don't have a better solution for now
|
|
File.ReadAllText(projectFilePath).Contains("JD.Serialization") ? new[] { "Engine_Solution_win64" } : null,
|
|
null,
|
|
"VS2017");
|
|
}
|
|
}
|
|
// specific scoring utilities tools
|
|
if (project is GenerateExamples || project is GenerateLabeledExamples || project is TrainGesture)
|
|
{
|
|
string solutionFilePath = Path.Combine(ScoringToolAplication.ToolsPath, "apps", "ScoringTools", string.Format("ScoringUtilities.{0}.2017.sln", Globals.CurrentBranchName.ToLower()));
|
|
|
|
foreach (string console in new[] { "_PS4", "_XOne" })
|
|
{
|
|
project.WriteInfo(
|
|
project.ResolveString(project.Name) + console,
|
|
solutionFilePath,
|
|
project.Configurations.Where(c => c.Compiler == DevEnv.vs2017 && c.Target.ProjectConfigurationName.EndsWith(console)).Select(c => new
|
|
{
|
|
Platform = "pc64",
|
|
Configuration = c.Target.ProjectConfigurationName,
|
|
OutputPath = project.ResolveString(c.TargetPath, c, c.Target).Replace(@"\\", @"\").TrimEnd('\\')
|
|
}),
|
|
new[] { project.ResolveString(project.Name) });
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (Solution solution in solutions.Where(s =>
|
|
!(s is SingleProjectSolution)
|
|
&& !(s is LegacyToolsSingleProjectSolution)
|
|
&& !(s is PlumeSolution)))
|
|
{
|
|
// cpp solution
|
|
if (solution is BaseCppSolution)
|
|
{
|
|
Solution.Configuration configuration = solution.Configurations.First(c => c.Compiler == DevEnv.vs2017);
|
|
|
|
solution.WriteInfo(
|
|
solution.Name + "_Solution",
|
|
solution.ResolveString(Path.Combine(configuration.SolutionPath, configuration.SolutionFileName + ".sln"), configuration),
|
|
solution.Configurations.Where(c => c.Compiler == DevEnv.vs2017).Select(c => c.Target).OfType<BaseCppTarget>().Select(t => new
|
|
{
|
|
Platform = t.Platform.AsEngineString(),
|
|
Configuration = t.Optimization.AsString(),
|
|
}),
|
|
null,
|
|
solution is EngineSolution ? new[] { "CheckSDK" } : null);
|
|
|
|
if (solution is EngineSolution)
|
|
{
|
|
// check installed sdk
|
|
WriteFile(
|
|
Path.Combine(Globals.ApplicationInfosOutput.FullName, "CheckSDK.json"),
|
|
Ubisoft.Json.JsonUtils.SerializeToString(
|
|
new
|
|
{
|
|
ApplicationName = "CheckSDK",
|
|
ProjectFilePath = Path.Combine(Globals.BranchRoot, @"build\sharpmake\sdks.proj"),
|
|
Configurations = solution.Configurations.Where(c => c.Compiler == DevEnv.vs2017).Select(c => c.Target).OfType<BaseCppTarget>().Select(t => new
|
|
{
|
|
Platform = t.Platform.AsEngineString(),
|
|
Configuration = t.Optimization.AsString(),
|
|
}).Distinct().ToArray()
|
|
},
|
|
Ubisoft.Json.JsonUtils.JsonFormatting.Indented));
|
|
}
|
|
}
|
|
// c# solution
|
|
else if (solution is BaseSolution)
|
|
{
|
|
Solution.Configuration configuration = solution.Configurations.First();
|
|
|
|
solution.WriteInfo(
|
|
solution.Name + "_Solution",
|
|
Path.Combine(configuration.SolutionPath, configuration.SolutionFileName + ".sln"),
|
|
solution.Configurations.Where(c => c.Target.GetPlatform() == Platform.win64).Select(c => new
|
|
{
|
|
Platform = c.Target.GetPlatform().AsString(),
|
|
Configuration = c.Target.GetOptimization().AsString(),
|
|
}),
|
|
null,
|
|
new[] { "Engine_Solution_win64" });
|
|
}
|
|
// specific scoring utilities solution
|
|
else if (solution is ScoringUtilitiesSolution)
|
|
{
|
|
Solution.Configuration configuration = solution.Configurations.First(c => c.Compiler == DevEnv.vs2017);
|
|
string solutionFilePath = Path.Combine(ScoringToolAplication.ToolsPath, "apps", "ScoringTools", string.Format("ScoringUtilities.{0}.2017.sln", Globals.CurrentBranchName.ToLower()));
|
|
|
|
foreach (string platform in new[] { string.Empty, "_PS4", "_XOne" })
|
|
{
|
|
solution.WriteInfo(
|
|
solution.Name + platform,
|
|
solution.ResolveString(Path.Combine(configuration.SolutionFilePath, configuration.SolutionFileName + ".sln"), configuration),
|
|
solution.Configurations.Where(c => c.Compiler == DevEnv.vs2017 && c.Target.ProjectConfigurationName.EndsWith(platform) && (!string.IsNullOrEmpty(platform) || !c.Target.ProjectConfigurationName.Contains("_"))).Select(c => new
|
|
{
|
|
Platform = "pc64",
|
|
Configuration = c.Target.ProjectConfigurationName
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
// sharpmake debug solution
|
|
WriteFile(
|
|
Path.Combine(Globals.ApplicationInfosOutput.FullName, "Sharpmake.json"),
|
|
Ubisoft.Json.JsonUtils.SerializeToString(
|
|
new
|
|
{
|
|
ApplicationName = "Sharpmake",
|
|
ProjectFilePath = Path.Combine(Globals.BranchRoot, @"build\sharpmake\sharpmake_debugsolution.vs2017.sln"),
|
|
Configurations = new[]
|
|
{
|
|
new
|
|
{
|
|
Platform = "Any Cpu",
|
|
Configuration = "Debug"
|
|
}
|
|
}
|
|
},
|
|
Ubisoft.Json.JsonUtils.JsonFormatting.Indented));
|
|
}
|
|
}
|
|
}
|