Skip to content

Commit

Permalink
Merge pull request #1893 from glopesdev/issue-1864
Browse files Browse the repository at this point in the history
Use forward slashes for package configuration
  • Loading branch information
glopesdev authored Jul 10, 2024
2 parents 9a6e884 + 9488692 commit 8a63452
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
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

0 comments on commit 8a63452

Please sign in to comment.