Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use forward slashes for package configuration #1893

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Bonsai.Configuration/AssemblyLocationCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
namespace Bonsai.Configuration
{
[Serializable]
public class AssemblyLocationCollection : SortedKeyedCollection<Tuple<string, ProcessorArchitecture>, AssemblyLocation>
public class AssemblyLocationCollection : SortedKeyedCollection<(string, ProcessorArchitecture), AssemblyLocation>
{
public void Add(string name, ProcessorArchitecture processorArchitecture, string path)
{
Add(new AssemblyLocation(name, processorArchitecture, path));
}

protected override Tuple<string, ProcessorArchitecture> GetKeyForItem(AssemblyLocation item)
protected override (string, ProcessorArchitecture) GetKeyForItem(AssemblyLocation item)
{
return Tuple.Create(item.AssemblyName, item.ProcessorArchitecture);
return (item.AssemblyName, item.ProcessorArchitecture);
}
}
}
6 changes: 3 additions & 3 deletions Bonsai.Configuration/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public static string GetConfigurationRoot(PackageConfiguration configuration = n

public static string GetAssemblyLocation(this PackageConfiguration configuration, string assemblyName)
{
var msilAssembly = Tuple.Create(assemblyName, ProcessorArchitecture.MSIL);
var msilAssembly = (assemblyName, ProcessorArchitecture.MSIL);
if (configuration.AssemblyLocations.Contains(msilAssembly))
{
return configuration.AssemblyLocations[msilAssembly].Location;
}

var architectureSpecificAssembly = Tuple.Create(assemblyName, Environment.Is64BitProcess ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86);
var architectureSpecificAssembly = (assemblyName, Environment.Is64BitProcess ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86);
if (configuration.AssemblyLocations.Contains(architectureSpecificAssembly))
{
return configuration.AssemblyLocations[architectureSpecificAssembly].Location;
Expand Down Expand Up @@ -209,7 +209,7 @@ public static void RegisterPath(this PackageConfiguration configuration, string
catch (BadImageFormatException) { continue; }
catch (IOException) { continue; }

var locationKey = Tuple.Create(assemblyName.Name, assemblyName.ProcessorArchitecture);
var locationKey = (assemblyName.Name, assemblyName.ProcessorArchitecture);
if (!configuration.AssemblyLocations.Contains(locationKey))
{
configuration.AssemblyReferences.Add(assemblyName.Name);
Expand Down
41 changes: 32 additions & 9 deletions Bonsai.Configuration/PackageConfigurationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public PackageConfigurationUpdater(NuGetFramework projectFramework, PackageConfi
var galleryPath = Path.Combine(bootstrapperDirectory, GalleryDirectory);
var galleryPackageSource = new PackageSource(galleryPath);
galleryRepository = new SourceRepository(galleryPackageSource, Repository.Provider.GetCoreV3());
NormalizePathSeparators(packageConfiguration);
}

string GetRelativePath(string path)
Expand All @@ -69,6 +70,28 @@ string GetRelativePath(string path)
return PathUtility.GetPathWithDirectorySeparator(relativeUri.ToString());
}

static string CombinePath(string path1, string path2)
{
return PathUtility.GetPathWithForwardSlashes(Path.Combine(path1, path2));
}

static void NormalizePathSeparators(PackageConfiguration configuration)
{
foreach (var assemblyLocation in configuration.AssemblyLocations)
{
assemblyLocation.Location = PathUtility.GetPathWithForwardSlashes(assemblyLocation.Location);
}

// cannot normalize in place since path is collection key
var libraryFolders = configuration.LibraryFolders.ToArray();
configuration.LibraryFolders.Clear();
foreach (var folder in libraryFolders)
{
folder.Path = PathUtility.GetPathWithForwardSlashes(folder.Path);
configuration.LibraryFolders.Add(folder);
}
}

static bool IsTaggedPackage(PackageReaderBase package)
{
var tags = package.NuspecReader.GetTags();
Expand Down Expand Up @@ -123,7 +146,7 @@ static IEnumerable<string> GetAssemblyLocations(NuGetFramework projectFramework,
return from file in nearestFramework.Items
where Path.GetExtension(file) == AssemblyExtension &&
!string.IsNullOrEmpty(ResolvePathPlatformName(file))
select PathUtility.GetPathWithDirectorySeparator(file);
select PathUtility.GetPathWithForwardSlashes(file);
}

static IEnumerable<LibraryFolder> GetLibraryFolders(PackageReaderBase package, string installPath)
Expand All @@ -143,7 +166,7 @@ static IEnumerable<LibraryFolder> GetBuildLibraryFolders(PackageReaderBase packa
group file by Path.GetDirectoryName(file) into folder
let platform = ResolvePathPlatformName(folder.Key)
where !string.IsNullOrWhiteSpace(platform)
select new LibraryFolder(Path.Combine(installPath, folder.Key), platform);
select new LibraryFolder(CombinePath(installPath, folder.Key), platform);
}

static IEnumerable<LibraryFolder> GetRuntimeLibraryFolders(PackageReaderBase package, string installPath)
Expand All @@ -154,14 +177,14 @@ where NuGetFramework.FrameworkNameComparer.Equals(frameworkGroup.TargetFramework
where !string.IsNullOrWhiteSpace(platform)
from file in frameworkGroup.Items
group file by new { platform, path = Path.GetDirectoryName(file) } into folder
select new LibraryFolder(Path.Combine(installPath, folder.Key.path), folder.Key.platform);
select new LibraryFolder(CombinePath(installPath, folder.Key.path), folder.Key.platform);
}

static IEnumerable<string> GetCompatibleAssemblyReferences(NuGetFramework projectFramework, PackageReaderBase package)
{
var nearestFramework = package.GetReferenceItems().GetNearest(projectFramework);
if (nearestFramework == null) return Enumerable.Empty<string>();
return nearestFramework.Items.Select(PathUtility.GetPathWithDirectorySeparator);
return nearestFramework.Items.Select(PathUtility.GetPathWithForwardSlashes);
}

void RegisterAssemblyLocations(PackageReaderBase package, string installPath, string relativePath, bool addReferences)
Expand All @@ -174,10 +197,10 @@ void RegisterAssemblyLocations(IEnumerable<string> assemblyLocations, string ins
{
foreach (var path in assemblyLocations)
{
var assemblyFile = Path.Combine(installPath, path);
var assemblyFile = CombinePath(installPath, path);
var assemblyName = AssemblyName.GetAssemblyName(assemblyFile);
var assemblyLocation = Path.Combine(relativePath, path);
var assemblyLocationKey = Tuple.Create(assemblyName.Name, assemblyName.ProcessorArchitecture);
var assemblyLocation = CombinePath(relativePath, path);
var assemblyLocationKey = (assemblyName.Name, assemblyName.ProcessorArchitecture);
if (!packageConfiguration.AssemblyLocations.Contains(assemblyLocationKey))
{
packageConfiguration.AssemblyLocations.Add(assemblyName.Name, assemblyName.ProcessorArchitecture, assemblyLocation);
Expand All @@ -204,11 +227,11 @@ void RemoveAssemblyLocations(IEnumerable<string> assemblyLocations, string insta
{
foreach (var path in assemblyLocations)
{
var assemblyFile = Path.Combine(installPath, path);
var assemblyFile = CombinePath(installPath, path);
var location = packageConfiguration.AssemblyLocations.FirstOrDefault(item => item.Location == assemblyFile);
if (location != null)
{
packageConfiguration.AssemblyLocations.Remove(Tuple.Create(location.AssemblyName, location.ProcessorArchitecture));
packageConfiguration.AssemblyLocations.Remove((location.AssemblyName, location.ProcessorArchitecture));
if (removeReference)
{
packageConfiguration.AssemblyReferences.Remove(location.AssemblyName);
Expand Down