Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 92274a2
Author: salman ameeri <29689492+recore67@users.noreply.github.com>
Date:   Sun Dec 31 02:20:28 2023 +0300

    openxr files removed

commit 4822e84
Author: salman ameeri <29689492+recore67@users.noreply.github.com>
Date:   Sun Dec 31 01:44:35 2023 +0300

    initial start of vr stripping

commit 16a5fb1
Author: salman ameeri <29689492+recore67@users.noreply.github.com>
Date:   Sat Dec 30 18:10:42 2023 +0300

    more platform stripping

commit 71e55c3
Author: salman ameeri <29689492+recore67@users.noreply.github.com>
Date:   Fri Dec 29 23:12:01 2023 +0300

    fbx import error

commit 1feb124
Author: Virgile Bello <virgile@stride3d.net>
Date:   Sun Dec 31 10:22:17 2023 +0900

    [NuGet] Ignore case when comparing assembly file names

commit ef52eba
Author: Virgile Bello <virgile@stride3d.net>
Date:   Sun Dec 31 10:09:15 2023 +0900

    [Build] Skip localization assembly build during dev build

commit 1fe15d2
Merge: c4965c3 78cf1ca
Author: xen2 <virgile@stride3d.net>
Date:   Sun Dec 31 00:04:23 2023 +0900

    Merge pull request stride3d#2055 from Kryptos-FR/feature/central-package-management

    [Build] Move Directory.Packages.props

commit 78cf1ca
Author: Nicolas Musset <musset.nicolas@gmail.com>
Date:   Fri Dec 8 14:55:10 2023 +0100

    Add nuget.config to Stride.sln

commit 6f2df39
Author: Nicolas Musset <musset.nicolas@gmail.com>
Date:   Fri Dec 8 14:49:51 2023 +0100

    [Build] Don't use central package management for Stride.Samples.Tests

    It is confused by nuget configurations.

commit c5bff0d
Author: Nicolas Musset <musset.nicolas@gmail.com>
Date:   Fri Dec 8 14:48:54 2023 +0100

    Add nuget.config

commit 1f0be73
Author: Nicolas Musset <musset.nicolas@gmail.com>
Date:   Mon Nov 20 17:55:21 2023 +0100

    [Build] Move Directory.Packages.props
  • Loading branch information
recore67 committed Jan 1, 2024
1 parent e514c1d commit 4b0ec02
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
3 changes: 2 additions & 1 deletion build/Stride.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "20-StrideRuntime", "20-Stri
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00-Targets.Private", "00-Targets.Private", "{97978864-95DD-43A6-9159-AA1C881BE99F}"
ProjectSection(SolutionItems) = preProject
..\Directory.Packages.props = ..\Directory.Packages.props
..\sources\Directory.Packages.props = ..\sources\Directory.Packages.props
..\nuget.config = ..\nuget.config
..\sources\targets\Stride.Core.CompilerServices.props = ..\sources\targets\Stride.Core.CompilerServices.props
..\sources\targets\Stride.Core.PostSettings.Dependencies.targets = ..\sources\targets\Stride.Core.PostSettings.Dependencies.targets
..\sources\targets\Stride.Core.props = ..\sources\targets\Stride.Core.props
Expand Down
11 changes: 11 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
5 changes: 3 additions & 2 deletions samples/Tests/Stride.Samples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!-- NuGet resolved needed for StrideDefaultAssetsPlugin.LoadDefaultTemplates() -->
<Import Project="..\..\sources\targets\Stride.UnitTests.props" />
<PropertyGroup>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<TargetFramework>$(StrideEditorTargetFramework)</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
Expand All @@ -10,8 +11,8 @@
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\sources\shared\SharedAssemblyInfo.cs">
Expand Down
File renamed without changes.
63 changes: 49 additions & 14 deletions sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class NuGetAssemblyResolver

static bool assembliesResolved;
static readonly object assembliesLock = new object();
static List<string> assemblies;
static Dictionary<string, string> assemblyNameToPath;

public static void DisableAssemblyResolve()
{
Expand Down Expand Up @@ -59,12 +59,6 @@ public static void SetupNuGet(string targetFramework, string packageName, string
// Note: we perform nuget restore inside the assembly resolver rather than top level module ctor (otherwise it freezes)
AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) =>
{
// Check if already loaded.
// Somehow it happens for Microsoft.NET.Build.Tasks -> NuGet.ProjectModel, probably due to the specific way it's loaded.
var matchingAssembly = Array.Find(AppDomain.CurrentDomain.GetAssemblies(), x => x.FullName == eventArgs.Name);
if (matchingAssembly != null)
return matchingAssembly;
if (!assembliesResolved)
{
lock (assembliesLock)
Expand Down Expand Up @@ -132,11 +126,31 @@ public static void SetupNuGet(string targetFramework, string packageName, string
throw new InvalidOperationException($"Could not restore NuGet packages");
}
assemblies = RestoreHelper.ListAssemblies(result.LockFile);
// Build list of assemblies
var assemblies = RestoreHelper.ListAssemblies(result.LockFile);
// Create a dictionary by assembly name
// note: we ignore case as filename might not be properly matching assembly name casing
assemblyNameToPath = new(StringComparer.OrdinalIgnoreCase);
foreach (var assembly in assemblies)
{
var extension = Path.GetExtension(assembly).ToLowerInvariant();
if (extension != ".dll")
continue;
var assemblyName = Path.GetFileNameWithoutExtension(assembly);
// Ignore duplicates (however, make sure it's the same version otherwise display a warning)
if (assemblyNameToPath.TryGetValue(assemblyName, out var otherAssembly))
{
if (!FileContentIsSame(new FileInfo(otherAssembly), new FileInfo(assembly)))
logger.LogWarning($"Assembly {assemblyName} found in two locations with different content: {assembly} and {otherAssembly}");
continue;
}
assemblyNameToPath.Add(assemblyName, assembly);
}
// Register the native libraries
var nativeLibs = RestoreHelper.ListNativeLibs(result.LockFile);
RegisterNativeDependencies(assemblies, nativeLibs);
RegisterNativeDependencies(assemblyNameToPath, nativeLibs);
}
catch (Exception e)
{
Expand Down Expand Up @@ -169,13 +183,12 @@ public static void SetupNuGet(string targetFramework, string packageName, string
}
}
if (assemblies != null)
if (assemblyNameToPath != null)
{
var aname = new AssemblyName(eventArgs.Name);
if (aname.Name.StartsWith("Microsoft.Build", StringComparison.Ordinal) && aname.Name != "Microsoft.Build.Locator")
return null;
var assemblyPath = assemblies.Find(x => Path.GetFileNameWithoutExtension(x) == aname.Name);
if (assemblyPath != null)
if (assemblyNameToPath.TryGetValue(aname.Name, out var assemblyPath))
{
return Assembly.LoadFrom(assemblyPath);
}
Expand All @@ -184,6 +197,28 @@ public static void SetupNuGet(string targetFramework, string packageName, string
};
}

static bool FileContentIsSame(FileInfo file1, FileInfo file2)
{
if (file1.Length != file2.Length)
return false;

// Assume same size and same modified time means it's the same file
if (file1.LastWriteTimeUtc == file2.LastWriteTimeUtc)
return true;

// Otherwise, full file compare
using (var fs1 = file1.OpenRead())
using (var fs2 = file2.OpenRead())
{
for (int i = 0; i < file1.Length; i++)
{
if (fs1.ReadByte() != fs2.ReadByte())
return false;
}
}
return true;
}

private static void RemoveSources(ISettings settings, string prefixName)
{
var packageSources = settings.GetSection("packageSources");
Expand All @@ -208,9 +243,9 @@ private static void CheckPackageSource(ISettings settings, string name, string u
/// <summary>
/// Registers the listed native libs in Stride.Core.NativeLibraryHelper using reflection to avoid a compile time dependency on Stride.Core
/// </summary>
private static void RegisterNativeDependencies(List<string> assemblies, List<string> nativeLibs)
private static void RegisterNativeDependencies(Dictionary<string, string> assemblyNameToPath, List<string> nativeLibs)
{
var strideCoreAssembly = Assembly.LoadFrom(assemblies.Find(a => Path.GetFileNameWithoutExtension(a) == "Stride.Core"));
var strideCoreAssembly = Assembly.LoadFrom(assemblyNameToPath["Stride.Core"]);
if (strideCoreAssembly is null)
throw new InvalidOperationException($"Couldn't find assembly 'Stride.Core' in restored packages");

Expand Down
6 changes: 5 additions & 1 deletion sources/targets/Stride.Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,15 @@
<Import Project="$(MSBuildThisFileDirectory)Stride.AutoPack.targets"/>

<!-- Generate localization satellite assemblies -->
<PropertyGroup>
<!-- Unless explicitly requested, only build them for packages to save dev time -->
<StrideBuildLocalization Condition="'$(StrideBuildLocalization)' == '' And '$(StridePackageBuild)' == 'true'">true</StrideBuildLocalization>
</PropertyGroup>
<Target Name="StrideGenerateLocalizationSatelliteDlls"
BeforeTargets="SatelliteDllsProjectOutputGroup"
AfterTargets="Build"
Returns="@(SatelliteDllsProjectOutputGroupOutput)"
Condition="'$(StrideLocalized)' == 'true'">
Condition="'$(StrideLocalized)' == 'true' And '$(StrideBuildLocalization)' == 'true'">

<ItemGroup>
<!-- Current list of languages to try to generate -->
Expand Down

0 comments on commit 4b0ec02

Please sign in to comment.