From be46042b51fd3a5e0083cace27cd1e1e3ae15e59 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sat, 16 Nov 2024 10:40:37 +0100 Subject: [PATCH] fix: correctly link Wally server packages --- CHANGELOG.md | 4 ++++ src/cli/commands/run.rs | 3 +-- src/download.rs | 2 +- src/linking/mod.rs | 28 ++++++++++------------------ src/lockfile.rs | 4 ++-- src/patches.rs | 12 ++---------- src/resolver.rs | 2 +- src/source/git/mod.rs | 18 +++++++++++------- src/source/git/pkg_ref.rs | 8 +------- src/source/pesde/pkg_ref.rs | 9 +-------- src/source/refs.rs | 12 +----------- src/source/traits.rs | 2 -- src/source/wally/mod.rs | 14 ++++++++++++-- src/source/wally/pkg_ref.rs | 6 +----- src/source/workspace/pkg_ref.rs | 9 +-------- 15 files changed, 49 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f2663..fc1b478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Fixed +- Correctly link Wally server packages by @daimond113 + ## [0.5.0-rc.8] - 2024-11-12 ### Added - Add `--index` flag to `publish` command to publish to a specific index by @daimond113 diff --git a/src/cli/commands/run.rs b/src/cli/commands/run.rs index 87da831..b891ec0 100644 --- a/src/cli/commands/run.rs +++ b/src/cli/commands/run.rs @@ -4,7 +4,6 @@ use clap::Args; use pesde::{ linking::generator::generate_bin_linking_module, names::{PackageName, PackageNames}, - source::traits::PackageRef, Project, PACKAGES_CONTAINER_NAME, }; use relative_path::RelativePathBuf; @@ -87,7 +86,7 @@ impl RunCommand { .await? .target .kind() - .packages_folder(&node.node.pkg_ref.target_kind()); + .packages_folder(version_id.target()); let container_folder = node.node.container_folder( &project .package_dir() diff --git a/src/download.rs b/src/download.rs index 21c5f57..377f044 100644 --- a/src/download.rs +++ b/src/download.rs @@ -72,7 +72,7 @@ impl Project { let container_folder = node.container_folder( &package_dir - .join(manifest_target_kind.packages_folder(&node.pkg_ref.target_kind())) + .join(manifest_target_kind.packages_folder(version_id.target())) .join(PACKAGES_CONTAINER_NAME), &name, version_id.version(), diff --git a/src/linking/mod.rs b/src/linking/mod.rs index 10cbfff..f3cb11c 100644 --- a/src/linking/mod.rs +++ b/src/linking/mod.rs @@ -51,12 +51,7 @@ impl Project { let container_folder = node.node.container_folder( &self .package_dir() - .join( - manifest - .target - .kind() - .packages_folder(&node.node.pkg_ref.target_kind()), - ) + .join(manifest.target.kind().packages_folder(version_id.target())) .join(PACKAGES_CONTAINER_NAME), name, version_id.version(), @@ -130,12 +125,8 @@ impl Project { for (version_id, node) in versions { let (node_container_folder, node_packages_folder) = { let base_folder = create_and_canonicalize( - self.package_dir().join( - manifest - .target - .kind() - .packages_folder(&node.node.pkg_ref.target_kind()), - ), + self.package_dir() + .join(manifest.target.kind().packages_folder(version_id.target())), ) .await?; let packages_container_folder = base_folder.join(PACKAGES_CONTAINER_NAME); @@ -214,10 +205,9 @@ impl Project { let base_folder = create_and_canonicalize( self.package_dir().join( - node.node - .pkg_ref - .target_kind() - .packages_folder(&dependency_node.node.pkg_ref.target_kind()), + version_id + .target() + .packages_folder(dependency_version_id.target()), ), ) .await?; @@ -230,8 +220,10 @@ impl Project { ); let linker_folder = create_and_canonicalize( - node_container_folder - .join(node.node.base_folder(dependency_node.target.kind())), + node_container_folder.join( + node.node + .base_folder(version_id, dependency_node.target.kind()), + ), ) .await?; diff --git a/src/lockfile.rs b/src/lockfile.rs index 02e1fec..2df59cf 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -37,9 +37,9 @@ pub struct DependencyGraphNode { } impl DependencyGraphNode { - pub(crate) fn base_folder(&self, project_target: TargetKind) -> String { + pub(crate) fn base_folder(&self, version_id: &VersionId, project_target: TargetKind) -> String { if self.pkg_ref.use_new_structure() { - self.pkg_ref.target_kind().packages_folder(&project_target) + version_id.target().packages_folder(&project_target) } else { "..".to_string() } diff --git a/src/patches.rs b/src/patches.rs index d8fe6f4..166e37f 100644 --- a/src/patches.rs +++ b/src/patches.rs @@ -1,7 +1,4 @@ -use crate::{ - lockfile::DownloadedGraph, source::traits::PackageRef, Project, MANIFEST_FILE_NAME, - PACKAGES_CONTAINER_NAME, -}; +use crate::{lockfile::DownloadedGraph, Project, MANIFEST_FILE_NAME, PACKAGES_CONTAINER_NAME}; use fs_err::tokio as fs; use git2::{ApplyLocation, Diff, DiffFormat, DiffLineType, Repository, Signature}; use relative_path::RelativePathBuf; @@ -110,12 +107,7 @@ impl Project { let container_folder = node.node.container_folder( &self .package_dir() - .join( - manifest - .target - .kind() - .packages_folder(&node.node.pkg_ref.target_kind()), - ) + .join(manifest.target.kind().packages_folder(version_id.target())) .join(PACKAGES_CONTAINER_NAME), &name, version_id.version(), diff --git a/src/resolver.rs b/src/resolver.rs index 5545190..c799bc5 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -328,7 +328,7 @@ impl Project { .chain(std::iter::once(alias.to_string())) .collect(), overridden.is_some(), - pkg_ref.target_kind(), + *target_version_id.target(), )); } } diff --git a/src/source/git/mod.rs b/src/source/git/mod.rs index 3b8a15b..413bdba 100644 --- a/src/source/git/mod.rs +++ b/src/source/git/mod.rs @@ -272,8 +272,15 @@ impl PackageSource for GitPackageSource { ) })?; let name = PackageNames::Wally(manifest.package.name); - let version_id = - VersionId(manifest.package.version, TargetKind::Roblox); + let version_id = VersionId( + manifest.package.version, + match manifest.package.realm { + crate::source::wally::manifest::Realm::Server => { + TargetKind::RobloxServer + } + _ => TargetKind::Roblox, + }, + ); (name, version_id, dependencies) } @@ -300,7 +307,6 @@ impl PackageSource for GitPackageSource { } }; - let target = *version_id.target(); let new_structure = matches!(name, PackageNames::Pesde(_)); Ok(( @@ -310,7 +316,6 @@ impl PackageSource for GitPackageSource { GitPackageRef { repo: self.repo_url.clone(), tree_id: tree.id.to_string(), - target, new_structure, dependencies, }, @@ -333,10 +338,9 @@ impl PackageSource for GitPackageSource { match fs::read_to_string(&index_file).await { Ok(s) => { log::debug!( - "using cached index file for package {}#{} {}", + "using cached index file for package {}#{}", pkg_ref.repo, - pkg_ref.tree_id, - pkg_ref.target + pkg_ref.tree_id ); let fs = toml::from_str::(&s).map_err(|e| { diff --git a/src/source/git/pkg_ref.rs b/src/source/git/pkg_ref.rs index 7ced83d..a9e9d6f 100644 --- a/src/source/git/pkg_ref.rs +++ b/src/source/git/pkg_ref.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use crate::{ - manifest::{target::TargetKind, DependencyType}, + manifest::DependencyType, source::{git::GitPackageSource, DependencySpecifiers, PackageRef, PackageSources}, }; @@ -22,8 +22,6 @@ pub struct GitPackageRef { pub dependencies: BTreeMap, /// Whether this package uses the new structure pub new_structure: bool, - /// The target of the package - pub target: TargetKind, } impl PackageRef for GitPackageRef { fn dependencies(&self) -> &BTreeMap { @@ -34,10 +32,6 @@ impl PackageRef for GitPackageRef { self.new_structure } - fn target_kind(&self) -> TargetKind { - self.target - } - fn source(&self) -> PackageSources { PackageSources::Git(GitPackageSource::new(self.repo.clone())) } diff --git a/src/source/pesde/pkg_ref.rs b/src/source/pesde/pkg_ref.rs index 8701c44..14179ce 100644 --- a/src/source/pesde/pkg_ref.rs +++ b/src/source/pesde/pkg_ref.rs @@ -4,10 +4,7 @@ use semver::Version; use serde::{Deserialize, Serialize}; use crate::{ - manifest::{ - target::{Target, TargetKind}, - DependencyType, - }, + manifest::{target::Target, DependencyType}, names::PackageName, source::{pesde::PesdePackageSource, DependencySpecifiers, PackageRef, PackageSources}, }; @@ -40,10 +37,6 @@ impl PackageRef for PesdePackageRef { true } - fn target_kind(&self) -> TargetKind { - self.target.kind() - } - fn source(&self) -> PackageSources { PackageSources::Pesde(PesdePackageSource::new(self.index_url.clone())) } diff --git a/src/source/refs.rs b/src/source/refs.rs index 9cfc7f7..474ab11 100644 --- a/src/source/refs.rs +++ b/src/source/refs.rs @@ -1,5 +1,5 @@ use crate::{ - manifest::{target::TargetKind, DependencyType}, + manifest::DependencyType, source::{pesde, specifiers::DependencySpecifiers, traits::PackageRef, PackageSources}, }; use serde::{Deserialize, Serialize}; @@ -53,16 +53,6 @@ impl PackageRef for PackageRefs { } } - fn target_kind(&self) -> TargetKind { - match self { - PackageRefs::Pesde(pkg_ref) => pkg_ref.target_kind(), - #[cfg(feature = "wally-compat")] - PackageRefs::Wally(pkg_ref) => pkg_ref.target_kind(), - PackageRefs::Git(pkg_ref) => pkg_ref.target_kind(), - PackageRefs::Workspace(pkg_ref) => pkg_ref.target_kind(), - } - } - fn source(&self) -> PackageSources { match self { PackageRefs::Pesde(pkg_ref) => pkg_ref.source(), diff --git a/src/source/traits.rs b/src/source/traits.rs index bcd487a..4dc9bd9 100644 --- a/src/source/traits.rs +++ b/src/source/traits.rs @@ -22,8 +22,6 @@ pub trait PackageRef: Debug { fn dependencies(&self) -> &BTreeMap; /// Whether to use the new structure (`packages` folders inside the package's content folder) or the old structure (Wally-style, with linker files in the parent of the folder containing the package's contents) fn use_new_structure(&self) -> bool; - /// The target of this package - fn target_kind(&self) -> TargetKind; /// The source of this package fn source(&self) -> PackageSources; } diff --git a/src/source/wally/mod.rs b/src/source/wally/mod.rs index 88ba96c..f366985 100644 --- a/src/source/wally/mod.rs +++ b/src/source/wally/mod.rs @@ -6,7 +6,11 @@ use crate::{ git_index::{read_file, root_tree, GitBasedSource}, traits::PackageSource, version_id::VersionId, - wally::{compat_util::get_target, manifest::WallyManifest, pkg_ref::WallyPackageRef}, + wally::{ + compat_util::get_target, + manifest::{Realm, WallyManifest}, + pkg_ref::WallyPackageRef, + }, IGNORED_DIRS, IGNORED_FILES, }, util::hash, @@ -125,7 +129,13 @@ impl PackageSource for WallyPackageSource { .filter(|manifest| specifier.version.matches(&manifest.package.version)) .map(|manifest| { Ok(( - VersionId(manifest.package.version.clone(), TargetKind::Roblox), + VersionId( + manifest.package.version.clone(), + match manifest.package.realm { + Realm::Server => TargetKind::RobloxServer, + _ => TargetKind::Roblox, + }, + ), WallyPackageRef { name: specifier.name.clone(), index_url: self.repo_url.clone(), diff --git a/src/source/wally/pkg_ref.rs b/src/source/wally/pkg_ref.rs index 363c0fc..08bdce9 100644 --- a/src/source/wally/pkg_ref.rs +++ b/src/source/wally/pkg_ref.rs @@ -4,7 +4,7 @@ use semver::Version; use serde::{Deserialize, Serialize}; use crate::{ - manifest::{target::TargetKind, DependencyType}, + manifest::DependencyType, names::wally::WallyPackageName, source::{wally::WallyPackageSource, DependencySpecifiers, PackageRef, PackageSources}, }; @@ -36,10 +36,6 @@ impl PackageRef for WallyPackageRef { false } - fn target_kind(&self) -> TargetKind { - TargetKind::Roblox - } - fn source(&self) -> PackageSources { PackageSources::Wally(WallyPackageSource::new(self.index_url.clone())) } diff --git a/src/source/workspace/pkg_ref.rs b/src/source/workspace/pkg_ref.rs index 06c3dd7..fd38ca5 100644 --- a/src/source/workspace/pkg_ref.rs +++ b/src/source/workspace/pkg_ref.rs @@ -3,10 +3,7 @@ use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use crate::{ - manifest::{ - target::{Target, TargetKind}, - DependencyType, - }, + manifest::{target::Target, DependencyType}, source::{workspace::WorkspacePackageSource, DependencySpecifiers, PackageRef, PackageSources}, }; @@ -30,10 +27,6 @@ impl PackageRef for WorkspacePackageRef { true } - fn target_kind(&self) -> TargetKind { - self.target.kind() - } - fn source(&self) -> PackageSources { PackageSources::Workspace(WorkspacePackageSource) }