Merge branch 'master' into Improve-HighlightedPopUpColor

This commit is contained in:
Phantom
2026-01-24 15:29:34 +01:00
6 changed files with 174 additions and 78 deletions

View File

@@ -107,6 +107,7 @@ void LightWithShadow::Serialize(SerializeStream& stream, const void* otherObj)
SERIALIZE(ContactShadowsLength);
SERIALIZE(ShadowsUpdateRate);
SERIALIZE(ShadowsUpdateRateAtDistance);
SERIALIZE(ShadowsResolution);
}
void LightWithShadow::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
@@ -125,4 +126,5 @@ void LightWithShadow::Deserialize(DeserializeStream& stream, ISerializeModifier*
DESERIALIZE(ContactShadowsLength);
DESERIALIZE(ShadowsUpdateRate);
DESERIALIZE(ShadowsUpdateRateAtDistance);
DESERIALIZE(ShadowsResolution);
}

View File

@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Flax.Build.Graph;
using Flax.Build.NativeCpp;
@@ -424,5 +425,120 @@ namespace Flax.Build
return failed;
}
private static void DeployFiles(TaskGraph graph, Target target, BuildOptions targetBuildOptions, string outputPath)
{
using (new ProfileEventScope("DeployFiles"))
{
foreach (var srcFile in targetBuildOptions.OptionalDependencyFiles.Where(File.Exists).Union(targetBuildOptions.DependencyFiles))
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
graph.AddCopyFile(dstFile, srcFile);
}
if (targetBuildOptions.NugetPackageReferences.Any())
{
// Find all packages to deploy (incl. dependencies) and restore if needed
var nugetPath = Utilities.GetNugetPackagesPath();
Log.Verbose($"Deploying NuGet packages from {nugetPath}");
var restoreOnce = true;
var nugetFiles = new HashSet<string>();
foreach (var reference in targetBuildOptions.NugetPackageReferences)
{
var folder = reference.GetLibFolder(nugetPath);
if (!Directory.Exists(folder) && restoreOnce)
{
// Package binaries folder is missing so restore packages (incl. dependency packages)
RestoreNugetPackages(graph, target, targetBuildOptions);
restoreOnce = false;
}
DeployNuGetPackage(nugetPath, targetBuildOptions, nugetFiles, reference, folder);
}
// Copy libraries from all referenced packages to the output folder
foreach (var file in nugetFiles)
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(file));
graph.AddCopyFile(dstFile, file);
}
}
}
}
private static void RestoreNugetPackages(TaskGraph graph, Target target, BuildOptions targetBuildOptions)
{
// Generate a dummy csproj file to restore package from it
var csprojPath = Path.Combine(targetBuildOptions.IntermediateFolder, "nuget.restore.csproj");
var dotnetSdk = DotNetSdk.Instance;
var csProjectFileContent = new StringBuilder();
csProjectFileContent.AppendLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
csProjectFileContent.AppendLine(" <PropertyGroup>");
csProjectFileContent.AppendLine($" <TargetFramework>net{dotnetSdk.Version.Major}.{dotnetSdk.Version.Minor}</TargetFramework>");
csProjectFileContent.AppendLine(" <IsPackable>false</IsPackable>");
csProjectFileContent.AppendLine(" <EnableDefaultItems>false</EnableDefaultItems>");
csProjectFileContent.AppendLine(" <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>");
csProjectFileContent.AppendLine(" <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>");
csProjectFileContent.AppendLine(" <EnableBaseIntermediateOutputPathMismatchWarning>false</EnableBaseIntermediateOutputPathMismatchWarning>");
csProjectFileContent.AppendLine(" <GenerateAssemblyInfo>false</GenerateAssemblyInfo>");
csProjectFileContent.AppendLine($" <LangVersion>{dotnetSdk.CSharpLanguageVersion}</LangVersion>");
csProjectFileContent.AppendLine(" <FileAlignment>512</FileAlignment>");
csProjectFileContent.AppendLine(" <RestorePackages>true</RestorePackages>");
csProjectFileContent.AppendLine(" </PropertyGroup>");
csProjectFileContent.AppendLine(" <ItemGroup>");
foreach (var reference in targetBuildOptions.NugetPackageReferences)
csProjectFileContent.AppendLine($" <PackageReference Include=\"{reference.Name}\" Version=\"{reference.Version}\" />");
csProjectFileContent.AppendLine(" </ItemGroup>");
csProjectFileContent.AppendLine("</Project>");
Utilities.WriteFileIfChanged(csprojPath, csProjectFileContent.ToString());
// Restore packages using dotnet CLI (synchronous to prevent task ordering issues on C# library building)
Log.Info($"Restoring NuGet packages for target {target.Name}");
Utilities.Run(Utilities.GetDotNetPath(), $"restore \"{csprojPath}\"", null, null, Utilities.RunOptions.DefaultTool);
}
private static void DeployNuGetPackage(string nugetPath, BuildOptions targetBuildOptions, HashSet<string> nugetFiles, NugetPackage package, string folder = null)
{
// Deploy library
var path = package.GetLibPath(nugetPath, folder);
if (!File.Exists(path))
return;
Log.Verbose($"Deploying NuGet package {package.Name}, {package.Version}, {package.Framework}");
nugetFiles.Add(path);
// Copy additional files (if included)
path = Path.ChangeExtension(path, "xml");
if (File.Exists(path))
nugetFiles.Add(path);
path = Path.ChangeExtension(path, "pdb");
if (targetBuildOptions.Configuration != TargetConfiguration.Release && File.Exists(path))
nugetFiles.Add(path);
// Read package dependencies
var nuspecFile = package.GetNuspecPath(nugetPath);
if (File.Exists(nuspecFile))
{
var doc = System.Xml.Linq.XDocument.Load(nuspecFile);
var root = (System.Xml.Linq.XElement)doc.FirstNode;
var metadataNode = root.Descendants().First(x => x.Name.LocalName== "metadata");
var dependenciesNode = metadataNode.Descendants().First(x => x.Name.LocalName == "dependencies");
var groupNode = dependenciesNode.Descendants().FirstOrDefault(x => x.Attribute("targetFramework")?.Value == package.Framework);
if (groupNode == null)
{
Log.Warning($"Cannot find framework {package.Framework} inside NuGet package {package.Name}, {package.Version}");
return;
}
foreach (var dependency in groupNode.Descendants())
{
if (dependency.Name.LocalName != "dependency")
continue;
// Deploy dependency package
var dependencyId = dependency.Attribute("id").Value;
var dependencyVersion = dependency.Attribute("version").Value;
DeployNuGetPackage(nugetPath, targetBuildOptions, nugetFiles, new NugetPackage { Name = dependencyId, Version = dependencyVersion, Framework = package.Framework } );
}
}
}
}
}

View File

@@ -135,27 +135,7 @@ namespace Flax.Build
// Deploy files
if (!target.IsPreBuilt)
{
using (new ProfileEventScope("DeployFiles"))
{
foreach (var srcFile in targetBuildOptions.OptionalDependencyFiles.Where(File.Exists).Union(targetBuildOptions.DependencyFiles))
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
graph.AddCopyFile(dstFile, srcFile);
}
if (targetBuildOptions.NugetPackageReferences.Any())
{
var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
foreach (var reference in targetBuildOptions.NugetPackageReferences)
{
var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll");
if (!File.Exists(path))
Utilities.RestoreNugetPackages(graph, target);
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
graph.AddCopyFile(dstFile, path);
}
}
}
DeployFiles(graph, target, targetBuildOptions, outputPath);
}
using (new ProfileEventScope("PostBuild"))
@@ -301,10 +281,10 @@ namespace Flax.Build
// Reference Nuget package
if (buildData.TargetOptions.NugetPackageReferences.Any())
{
var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
var nugetPath = Utilities.GetNugetPackagesPath();
foreach (var reference in buildOptions.NugetPackageReferences)
{
var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll");
var path = reference.GetLibPath(nugetPath);
args.Add(string.Format("/reference:\"{0}\"", path));
}
}

View File

@@ -102,6 +102,51 @@ namespace Flax.Build.NativeCpp
Version = version;
Framework = framework;
}
internal string GetLibFolder(string nugetPath)
{
var libFolder = Path.Combine(nugetPath, Name, Version, "lib", Framework);
if (Directory.Exists(libFolder))
return libFolder;
// Try to find nearest framework folder
if (Framework.StartsWith("net"))
{
var baseVersion = int.Parse(Framework.Substring(3, Framework.IndexOf('.') - 3));
for (int version = baseVersion - 1; version >= 5; version--)
{
var framework = $"net{version}.0";
libFolder = Path.Combine(nugetPath, Name, Version, "lib", framework);
if (Directory.Exists(libFolder))
{
Framework = framework;
return libFolder;
}
}
}
Log.Error($"Missing NuGet package \"{Name}, {Version}, {Framework}\" (nuget: {nugetPath})");
return string.Empty;
}
internal string GetNuspecPath(string nugetPath)
{
var files = Directory.GetFiles(Path.Combine(nugetPath, Name, Version), "*.nuspec", SearchOption.TopDirectoryOnly);
return files[0];
}
internal string GetLibPath(string nugetPath, string libFolder = null)
{
if (libFolder == null)
libFolder = GetLibFolder(nugetPath);
var dlls = Directory.GetFiles(libFolder, "*.dll", SearchOption.TopDirectoryOnly);
if (dlls.Length == 0)
{
Log.Error($"Missing NuGet package \"{Name}, {Version}, {Framework}\" binaries (folder: {libFolder})");
return string.Empty;
}
return dlls[0];
}
}
/// <summary>
@@ -167,7 +212,7 @@ namespace Flax.Build.NativeCpp
/// <summary>
/// The nuget package references.
/// </summary>
public List<NugetPackage> NugetPackageReferences = new List<NugetPackage>();
public HashSet<NugetPackage> NugetPackageReferences = new HashSet<NugetPackage>();
/// <summary>
/// The collection of defines with preprocessing symbol for a source files of this module. Inherited by the modules that include it.

View File

@@ -1057,27 +1057,7 @@ namespace Flax.Build
// Deploy files
if (!buildData.Target.IsPreBuilt)
{
using (new ProfileEventScope("DeployFiles"))
{
foreach (var srcFile in targetBuildOptions.OptionalDependencyFiles.Where(File.Exists).Union(targetBuildOptions.DependencyFiles))
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
graph.AddCopyFile(dstFile, srcFile);
}
if (targetBuildOptions.NugetPackageReferences.Any())
{
var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
foreach (var reference in targetBuildOptions.NugetPackageReferences)
{
var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll");
if (!File.Exists(path))
Utilities.RestoreNugetPackages(graph, target);
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
graph.AddCopyFile(dstFile, path);
}
}
}
DeployFiles(graph, target, targetBuildOptions, outputPath);
}
using (new ProfileEventScope("PostBuild"))
@@ -1270,27 +1250,7 @@ namespace Flax.Build
// Deploy files
if (!buildData.Target.IsPreBuilt)
{
using (new ProfileEventScope("DeployFiles"))
{
foreach (var srcFile in targetBuildOptions.OptionalDependencyFiles.Where(File.Exists).Union(targetBuildOptions.DependencyFiles))
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
graph.AddCopyFile(dstFile, srcFile);
}
if (targetBuildOptions.NugetPackageReferences.Any())
{
var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
foreach (var reference in targetBuildOptions.NugetPackageReferences)
{
var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll");
if (!File.Exists(path))
Utilities.RestoreNugetPackages(graph, target);
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
graph.AddCopyFile(dstFile, path);
}
}
}
DeployFiles(graph, target, targetBuildOptions, outputPath);
}
using (new ProfileEventScope("PostBuild"))

View File

@@ -42,21 +42,14 @@ namespace Flax.Build
}
/// <summary>
/// Restores a targets nuget packages.
/// Gets the NuGet packages cache folder path.
/// </summary>
/// <param name="graph">The task graph.</param>
/// <param name="target">The target.</param>
/// <param name="dotNetPath">The dotnet path.</param>
public static void RestoreNugetPackages(Graph.TaskGraph graph, Target target)
/// <returns>The path.</returns>
public static string GetNugetPackagesPath()
{
var dotNetPath = GetDotNetPath();
var task = graph.Add<Graph.Task>();
task.WorkingDirectory = target.FolderPath;
task.InfoMessage = $"Restoring Nuget Packages for {target.Name}";
task.CommandPath = dotNetPath;
task.CommandArguments = $"restore";
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
}
/// <summary>
/// Gets the hash code for the string (the same for all platforms). Matches Engine algorithm for string hashing.
/// </summary>