diff --git a/.gitignore b/.gitignore index 6765ad1a..e782a7ad 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ /*.rockspec *.snap.new /.rocks +rocks.lock .pre-commit-config.yaml diff --git a/Cargo.lock b/Cargo.lock index adda1353..d655fd8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,6 +526,12 @@ dependencies = [ "roff", ] +[[package]] +name = "clean-path" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaa6b4b263a5d737e9bf6b7c09b72c41a5480aec4d7219af827f6564e950b6a5" + [[package]] name = "colorchoice" version = "1.0.3" @@ -3030,6 +3036,7 @@ dependencies = [ "bytes", "cc", "clap 4.5.23", + "clean-path", "dir-diff", "directories", "flate2", diff --git a/rocks-lib/Cargo.toml b/rocks-lib/Cargo.toml index 3d148f07..db59b96f 100644 --- a/rocks-lib/Cargo.toml +++ b/rocks-lib/Cargo.toml @@ -54,6 +54,7 @@ shlex = "1.3.0" pkg-config = "0.3.31" url = "2.5.4" bon = { version = "3.3.2", features = ["implied-bounds"] } +clean-path = "0.2.1" [dev-dependencies] httptest = { version = "0.16.1" } diff --git a/rocks-lib/resources/test/sample-project-lockfile-missing-deps/rocks.lock b/rocks-lib/resources/test/sample-project-lockfile-missing-deps/rocks.lock index b50882c3..576faa80 100644 --- a/rocks-lib/resources/test/sample-project-lockfile-missing-deps/rocks.lock +++ b/rocks-lib/resources/test/sample-project-lockfile-missing-deps/rocks.lock @@ -10,6 +10,7 @@ ], "constraint": "=2.2.3", "source": "luarocks_rockspec+https://luarocks.org/", + "binaries": [], "hashes": { "rockspec": "sha256-kdDMqznWlwP9wIqlzPrZ5qEDp6edhlkaasAcQzWTmmM=", "source": "sha256-fNO24tL8wApI8j3rk2mdLf5wbbjlUzsvCxki3n0xRw8=" @@ -21,6 +22,7 @@ "pinned": false, "dependencies": [], "constraint": ">=1.8.0", + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-5iL9++6X/JsKKtpIRaRHcnZpn6DrsAQQRWPubZK9erY=", diff --git a/rocks-lib/resources/test/sample-tree/5.1/lock.json b/rocks-lib/resources/test/sample-tree/5.1/lock.json index c1b12794..22438903 100644 --- a/rocks-lib/resources/test/sample-tree/5.1/lock.json +++ b/rocks-lib/resources/test/sample-tree/5.1/lock.json @@ -9,6 +9,7 @@ "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -21,6 +22,7 @@ "pinned": false, "dependencies": [], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -34,6 +36,7 @@ "dependencies": [ "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], + "binaries": [], "constraint": null, "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { diff --git a/rocks-lib/src/build/builtin.rs b/rocks-lib/src/build/builtin.rs index 8dca1433..95a89859 100644 --- a/rocks-lib/src/build/builtin.rs +++ b/rocks-lib/src/build/builtin.rs @@ -1,6 +1,8 @@ +use clean_path::Clean as _; use itertools::Itertools; use std::{ collections::{HashMap, HashSet}, + io, path::{Path, PathBuf}, str::FromStr, }; @@ -10,11 +12,8 @@ use crate::{ build::utils, config::Config, lua_installation::LuaInstallation, - progress::{ - Progress::{self}, - ProgressBar, - }, - rockspec::{Build, BuiltinBuildSpec, LuaModule, ModuleSpec}, + progress::{Progress, ProgressBar}, + rockspec::{Build, BuildInfo, BuiltinBuildSpec, LuaModule, ModuleSpec}, tree::RockLayout, }; @@ -31,7 +30,7 @@ impl Build for BuiltinBuildSpec { _config: &Config, build_dir: &Path, progress: &Progress, - ) -> Result<(), Self::Err> { + ) -> Result { // Detect all Lua modules let modules = autodetect_modules(build_dir, source_paths(build_dir, &self.modules)) .into_iter() @@ -98,14 +97,18 @@ impl Build for BuiltinBuildSpec { } } - for relative_path in autodetect_bin_scripts(build_dir).iter() { - let source = build_dir.join("src").join("bin").join(relative_path); - let target = output_paths.bin.join(relative_path); - std::fs::create_dir_all(target.parent().unwrap())?; - std::fs::copy(source, target)?; - } + let binaries = autodetect_bin_scripts(build_dir) + .iter() + .map(|relative_path| { + let source = build_dir.join("src").join("bin").join(relative_path); + let target = output_paths.bin.join(relative_path); + std::fs::create_dir_all(target.parent().unwrap())?; + std::fs::copy(source, target)?; + Ok(relative_path.clean()) + }) + .try_collect::<_, Vec<_>, io::Error>()?; - Ok(()) + Ok(BuildInfo { binaries }) } } diff --git a/rocks-lib/src/build/cmake.rs b/rocks-lib/src/build/cmake.rs index 90989984..6d9f3a66 100644 --- a/rocks-lib/src/build/cmake.rs +++ b/rocks-lib/src/build/cmake.rs @@ -10,7 +10,7 @@ use crate::{ config::Config, lua_installation::LuaInstallation, progress::{Progress, ProgressBar}, - rockspec::{Build, CMakeBuildSpec}, + rockspec::{Build, BuildInfo, CMakeBuildSpec}, tree::RockLayout, }; @@ -46,7 +46,7 @@ impl Build for CMakeBuildSpec { config: &Config, build_dir: &Path, _progress: &Progress, - ) -> Result<(), Self::Err> { + ) -> Result { let mut args = Vec::new(); if let Some(content) = self.cmake_lists_content { let cmakelists = build_dir.join("CMakeLists.txt"); @@ -101,7 +101,7 @@ impl Build for CMakeBuildSpec { )?; } - Ok(()) + Ok(BuildInfo::default()) } } diff --git a/rocks-lib/src/build/command.rs b/rocks-lib/src/build/command.rs index b3156c4d..a2ae9fec 100644 --- a/rocks-lib/src/build/command.rs +++ b/rocks-lib/src/build/command.rs @@ -10,7 +10,7 @@ use crate::{ config::Config, lua_installation::LuaInstallation, progress::{Progress, ProgressBar}, - rockspec::{Build, CommandBuildSpec}, + rockspec::{Build, BuildInfo, CommandBuildSpec}, tree::RockLayout, }; @@ -44,14 +44,14 @@ impl Build for CommandBuildSpec { config: &Config, build_dir: &Path, progress: &Progress, - ) -> Result<(), Self::Err> { + ) -> Result { progress.map(|bar| bar.set_message("Running build_command...")); run_command(&self.build_command, output_paths, lua, config, build_dir)?; if !no_install { progress.map(|bar| bar.set_message("Running install_command...")); run_command(&self.install_command, output_paths, lua, config, build_dir)?; } - Ok(()) + Ok(BuildInfo::default()) } } diff --git a/rocks-lib/src/build/luarocks.rs b/rocks-lib/src/build/luarocks.rs index c962cc10..acc6616c 100644 --- a/rocks-lib/src/build/luarocks.rs +++ b/rocks-lib/src/build/luarocks.rs @@ -5,7 +5,7 @@ use crate::{ lua_installation::LuaInstallation, luarocks::luarocks_installation::{ExecLuaRocksError, LuaRocksError, LuaRocksInstallation}, progress::{Progress, ProgressBar}, - rockspec::Rockspec, + rockspec::{BuildInfo, Rockspec}, tree::RockLayout, }; @@ -31,7 +31,7 @@ pub(crate) async fn build( config: &Config, build_dir: &Path, progress: &Progress, -) -> Result<(), LuarocksBuildError> { +) -> Result { progress.map(|p| { p.set_message(format!( "Building {} {} with luarocks...", @@ -55,7 +55,7 @@ fn install( luarocks_tree: &Path, output_paths: &RockLayout, config: &Config, -) -> Result<(), LuarocksBuildError> { +) -> Result { let lua_version = rockspec .lua_version_from_config(config) .expect("could not get lua version!"); @@ -82,5 +82,5 @@ fn install( .join("lua") .join(lua_version.version_compatibility_str()); recursive_copy_dir(&lib_dir, &output_paths.lib)?; - Ok(()) + Ok(BuildInfo::default()) } diff --git a/rocks-lib/src/build/make.rs b/rocks-lib/src/build/make.rs index a9de63df..a6dfc765 100644 --- a/rocks-lib/src/build/make.rs +++ b/rocks-lib/src/build/make.rs @@ -11,7 +11,7 @@ use crate::{ config::Config, lua_installation::LuaInstallation, progress::{Progress, ProgressBar}, - rockspec::{Build, MakeBuildSpec}, + rockspec::{Build, BuildInfo, MakeBuildSpec}, tree::RockLayout, }; @@ -41,7 +41,7 @@ impl Build for MakeBuildSpec { config: &Config, build_dir: &Path, _progress: &Progress, - ) -> Result<(), Self::Err> { + ) -> Result { // Build step if self.build_pass { let build_args = self @@ -109,6 +109,6 @@ impl Build for MakeBuildSpec { } }; - Ok(()) + Ok(BuildInfo::default()) } } diff --git a/rocks-lib/src/build/mod.rs b/rocks-lib/src/build/mod.rs index 830d4f49..7fbaa061 100644 --- a/rocks-lib/src/build/mod.rs +++ b/rocks-lib/src/build/mod.rs @@ -9,7 +9,7 @@ use crate::{ package::PackageSpec, progress::{Progress, ProgressBar}, remote_package_source::RemotePackageSource, - rockspec::{Build as _, BuildBackendSpec, LuaVersionError, Rockspec}, + rockspec::{Build as _, BuildBackendSpec, BuildInfo, LuaVersionError, Rockspec}, tree::{RockLayout, Tree}, }; pub(crate) mod utils; @@ -134,42 +134,42 @@ async fn run_build( config: &Config, build_dir: &Path, progress: &Progress, -) -> Result<(), BuildError> { +) -> Result { progress.map(|p| p.set_message("🛠️ Building...")); - match rockspec.build.current_platform().build_backend.to_owned() { - Some(BuildBackendSpec::Builtin(build_spec)) => { - build_spec - .run(output_paths, false, lua, config, build_dir, progress) - .await? - } - Some(BuildBackendSpec::Make(make_spec)) => { - make_spec - .run(output_paths, false, lua, config, build_dir, progress) - .await? - } - Some(BuildBackendSpec::CMake(cmake_spec)) => { - cmake_spec - .run(output_paths, false, lua, config, build_dir, progress) - .await? - } - Some(BuildBackendSpec::Command(command_spec)) => { - command_spec - .run(output_paths, false, lua, config, build_dir, progress) - .await? - } - Some(BuildBackendSpec::RustMlua(rust_mlua_spec)) => { - rust_mlua_spec - .run(output_paths, false, lua, config, build_dir, progress) - .await? - } - Some(BuildBackendSpec::LuaRock(_)) => { - luarocks::build(rockspec, output_paths, lua, config, build_dir, progress).await?; - } - None => (), - } - - Ok(()) + Ok( + match rockspec.build.current_platform().build_backend.to_owned() { + Some(BuildBackendSpec::Builtin(build_spec)) => { + build_spec + .run(output_paths, false, lua, config, build_dir, progress) + .await? + } + Some(BuildBackendSpec::Make(make_spec)) => { + make_spec + .run(output_paths, false, lua, config, build_dir, progress) + .await? + } + Some(BuildBackendSpec::CMake(cmake_spec)) => { + cmake_spec + .run(output_paths, false, lua, config, build_dir, progress) + .await? + } + Some(BuildBackendSpec::Command(command_spec)) => { + command_spec + .run(output_paths, false, lua, config, build_dir, progress) + .await? + } + Some(BuildBackendSpec::RustMlua(rust_mlua_spec)) => { + rust_mlua_spec + .run(output_paths, false, lua, config, build_dir, progress) + .await? + } + Some(BuildBackendSpec::LuaRock(_)) => { + luarocks::build(rockspec, output_paths, lua, config, build_dir, progress).await? + } + None => BuildInfo::default(), + }, + ) } async fn install( @@ -271,6 +271,7 @@ async fn do_build(build: Build<'_>) -> Result { build.rockspec.version.clone(), ), build.constraint, + build.rockspec.binaries(), build.source.unwrap_or_else(|| { RemotePackageSource::RockspecContent(build.rockspec.raw_content.clone()) }), @@ -291,7 +292,7 @@ async fn do_build(build: Build<'_>) -> Result { None => temp_dir.path().into(), }; - run_build( + let output = run_build( build.rockspec, &output_paths, &lua, @@ -301,6 +302,8 @@ async fn do_build(build: Build<'_>) -> Result { ) .await?; + package.spec.binaries.extend(output.binaries); + install( build.rockspec, &tree, diff --git a/rocks-lib/src/build/rust_mlua.rs b/rocks-lib/src/build/rust_mlua.rs index 23a0e3d3..57c786c4 100644 --- a/rocks-lib/src/build/rust_mlua.rs +++ b/rocks-lib/src/build/rust_mlua.rs @@ -1,6 +1,7 @@ use super::utils::lua_lib_extension; use crate::config::LuaVersionUnset; use crate::progress::{Progress, ProgressBar}; +use crate::rockspec::BuildInfo; use crate::{ config::{Config, LuaVersion}, lua_installation::LuaInstallation, @@ -39,7 +40,7 @@ impl Build for RustMluaBuildSpec { config: &Config, build_dir: &Path, progress: &Progress, - ) -> Result<(), Self::Err> { + ) -> Result { let lua_version = LuaVersion::from(config)?; let lua_feature = match lua_version { LuaVersion::Lua51 => "lua51", @@ -88,7 +89,7 @@ impl Build for RustMluaBuildSpec { cleanup(output_paths, progress).await?; return Err(err.into()); } - Ok(()) + Ok(BuildInfo::default()) } } diff --git a/rocks-lib/src/lockfile/mod.rs b/rocks-lib/src/lockfile/mod.rs index 4372c0f7..cef02c39 100644 --- a/rocks-lib/src/lockfile/mod.rs +++ b/rocks-lib/src/lockfile/mod.rs @@ -16,6 +16,7 @@ use crate::package::{ PackageVersionReqError, RemotePackageTypeFilterSpec, }; use crate::remote_package_source::RemotePackageSource; +use crate::rockspec::RockBinaries; #[cfg(feature = "lua")] use mlua::{ExternalResult as _, FromLua}; @@ -89,6 +90,7 @@ pub(crate) struct LocalPackageSpec { pub dependencies: Vec, // TODO: Deserialize this directly into a `LuaPackageReq` pub constraint: Option, + pub binaries: RockBinaries, } #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, Clone)] @@ -138,6 +140,7 @@ impl LocalPackageSpec { constraint: LockConstraint, dependencies: Vec, pinned: &PinnedState, + binaries: RockBinaries, ) -> Self { Self { name: name.clone(), @@ -148,6 +151,7 @@ impl LocalPackageSpec { LockConstraint::Unconstrained => None, LockConstraint::Constrained(version_req) => Some(version_req.to_string()), }, + binaries, } } @@ -184,6 +188,10 @@ impl LocalPackageSpec { self.dependencies.iter().collect() } + pub fn binaries(&self) -> Vec<&PathBuf> { + self.binaries.iter().collect() + } + pub fn to_package(&self) -> PackageSpec { PackageSpec::new(self.name.clone(), self.version.clone()) } @@ -215,6 +223,7 @@ struct LocalPackageIntermediate { pinned: PinnedState, dependencies: Vec, constraint: Option, + binaries: RockBinaries, source: RemotePackageSource, hashes: LocalPackageHashes, } @@ -231,6 +240,7 @@ impl TryFrom for LocalPackage { constraint, value.dependencies, &value.pinned, + value.binaries, ), source: value.source, hashes: value.hashes, @@ -246,6 +256,7 @@ impl From<&LocalPackage> for LocalPackageIntermediate { pinned: value.spec.pinned, dependencies: value.spec.dependencies.clone(), constraint: value.spec.constraint.clone(), + binaries: value.spec.binaries.clone(), source: value.source.clone(), hashes: value.hashes.clone(), } @@ -283,6 +294,7 @@ impl LocalPackage { pub(crate) fn from( package: &PackageSpec, constraint: LockConstraint, + binaries: RockBinaries, source: RemotePackageSource, hashes: LocalPackageHashes, ) -> Self { @@ -293,6 +305,7 @@ impl LocalPackage { constraint, Vec::default(), &PinnedState::Unpinned, + binaries, ), source, hashes, @@ -816,6 +829,7 @@ mod tests { let test_local_package = LocalPackage::from( &test_package, crate::lockfile::LockConstraint::Unconstrained, + RockBinaries::default(), RemotePackageSource::Test, mock_hashes.clone(), ); @@ -826,6 +840,7 @@ mod tests { let mut test_local_dep_package = LocalPackage::from( &test_dep_package, crate::lockfile::LockConstraint::Constrained(">= 1.0.0".parse().unwrap()), + RockBinaries::default(), RemotePackageSource::Test, mock_hashes.clone(), ); @@ -849,6 +864,6 @@ mod tests { let tree = Tree::new(temp.to_path_buf(), Lua51).unwrap(); - tree.lockfile().unwrap(); // Try to create the lockfile but don't actually do anything with it. + let _ = tree.lockfile().unwrap().write_guard(); // Try to create the lockfile but don't actually do anything with it. } } diff --git a/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__add_rocks.snap b/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__add_rocks.snap index 8c1739f3..7e2dd6d1 100644 --- a/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__add_rocks.snap +++ b/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__add_rocks.snap @@ -1,6 +1,5 @@ --- source: rocks-lib/src/lockfile/mod.rs -assertion_line: 649 expression: lockfile --- { @@ -12,6 +11,7 @@ expression: lockfile "pinned": false, "dependencies": [], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -26,6 +26,7 @@ expression: lockfile "a9f137d1dad1af603e33935a3f8722dfbb2aebeac03bec5ed0b6e9cc5828c7f3" ], "constraint": null, + "binaries": [], "source": "test+foo_bar", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -38,6 +39,7 @@ expression: lockfile "pinned": true, "dependencies": [], "constraint": ">=1.0.0", + "binaries": [], "source": "test+foo_bar", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -52,6 +54,7 @@ expression: lockfile "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -66,6 +69,7 @@ expression: lockfile "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", diff --git a/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__parse_lockfile.snap b/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__parse_lockfile.snap index adbac26b..6676a69f 100644 --- a/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__parse_lockfile.snap +++ b/rocks-lib/src/lockfile/snapshots/rocks_lib__lockfile__tests__parse_lockfile.snap @@ -1,8 +1,6 @@ --- source: rocks-lib/src/lockfile/mod.rs -assertion_line: 603 expression: lockfile -snapshot_kind: text --- { "version": "1.0.0", @@ -13,6 +11,7 @@ snapshot_kind: text "pinned": false, "dependencies": [], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -27,6 +26,7 @@ snapshot_kind: text "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", @@ -41,6 +41,7 @@ snapshot_kind: text "48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0" ], "constraint": null, + "binaries": [], "source": "luarocks_rockspec+https://luarocks.org/", "hashes": { "rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=", diff --git a/rocks-lib/src/luarocks/install_binary_rock.rs b/rocks-lib/src/luarocks/install_binary_rock.rs index 91e6feb0..f795476b 100644 --- a/rocks-lib/src/luarocks/install_binary_rock.rs +++ b/rocks-lib/src/luarocks/install_binary_rock.rs @@ -108,6 +108,7 @@ impl<'a> BinaryRockInstall<'a> { let mut package = LocalPackage::from( &PackageSpec::new(rockspec.package.clone(), rockspec.version.clone()), self.constraint, + rockspec.binaries(), self.source, hashes, ); diff --git a/rocks-lib/src/operations/lockfile_update.rs b/rocks-lib/src/operations/lockfile_update.rs index 174da868..aedf1b70 100644 --- a/rocks-lib/src/operations/lockfile_update.rs +++ b/rocks-lib/src/operations/lockfile_update.rs @@ -123,6 +123,7 @@ async fn do_add_missing_packages(update: LockfileUpdate<'_>) -> Result<(), Lockf let pkg = LocalPackage::from( &PackageSpec::new(rockspec.package.clone(), rockspec.version.clone()), install_spec.spec.constraint(), + rockspec.binaries(), downloaded_rock.rockspec_download().source.clone(), hashes, ); diff --git a/rocks-lib/src/operations/remove.rs b/rocks-lib/src/operations/remove.rs index 0179fbb5..97891aa5 100644 --- a/rocks-lib/src/operations/remove.rs +++ b/rocks-lib/src/operations/remove.rs @@ -5,6 +5,7 @@ use crate::config::{LuaVersion, LuaVersionUnset}; use crate::lockfile::{LocalPackage, LocalPackageId}; use crate::progress::{MultiProgress, Progress, ProgressBar}; use crate::{config::Config, tree::Tree}; +use clean_path::Clean as _; use futures::future::join_all; use itertools::Itertools; use thiserror::Error; @@ -118,6 +119,20 @@ async fn remove_package( tokio::fs::remove_dir_all(tree.root_for(&package)).await?; + // Delete the corresponding binaries attached to the current package (located under `{ROCKS_TREE}/bin/`) + for relative_binary_path in package.spec.binaries() { + let binary_path = tree.bin().join( + relative_binary_path + .clean() + .file_name() + .expect("malformed lockfile"), + ); + + if binary_path.is_file() { + tokio::fs::remove_file(binary_path).await?; + } + } + bar.map(|p| p.finish_and_clear()); Ok(()) } diff --git a/rocks-lib/src/operations/resolve.rs b/rocks-lib/src/operations/resolve.rs index 32da9858..42c25595 100644 --- a/rocks-lib/src/operations/resolve.rs +++ b/rocks-lib/src/operations/resolve.rs @@ -97,6 +97,7 @@ where constraint, dependencies, &pin, + rockspec.binaries(), ); let install_spec = PackageInstallSpec { diff --git a/rocks-lib/src/rockspec/build/mod.rs b/rocks-lib/src/rockspec/build/mod.rs index 9af3002d..1ff9f768 100644 --- a/rocks-lib/src/rockspec/build/mod.rs +++ b/rocks-lib/src/rockspec/build/mod.rs @@ -528,6 +528,11 @@ impl Default for BuildType { } } +#[derive(Default)] +pub struct BuildInfo { + pub binaries: Vec, +} + // TODO(vhyrro): Move this to the dedicated build.rs module pub trait Build { type Err: std::error::Error; @@ -540,7 +545,7 @@ pub trait Build { config: &Config, build_dir: &Path, progress: &Progress, - ) -> impl Future> + Send; + ) -> impl Future> + Send; } #[cfg(test)] diff --git a/rocks-lib/src/rockspec/mod.rs b/rocks-lib/src/rockspec/mod.rs index 90fbf9d6..61118e53 100644 --- a/rocks-lib/src/rockspec/mod.rs +++ b/rocks-lib/src/rockspec/mod.rs @@ -5,7 +5,13 @@ mod rock_source; mod serde_util; mod test_spec; -use std::{collections::HashMap, io, path::PathBuf, str::FromStr}; +use std::{ + collections::HashMap, + io, + ops::{Deref, DerefMut}, + path::PathBuf, + str::FromStr, +}; use itertools::Itertools; use mlua::{FromLua, Lua, LuaSerdeExt, Value}; @@ -106,6 +112,20 @@ impl Rockspec { Ok(rockspec) } + /// Shorthand to extract the binaries that are part of the rockspec. + // TODO(vhyrro): Move this to the `Rocks` trait during the `rocks.toml` rewrite. + pub(crate) fn binaries(&self) -> RockBinaries { + RockBinaries( + self.build + .current_platform() + .install + .bin + .keys() + .map_into() + .collect(), + ) + } + pub fn validate_lua_version(&self, config: &Config) -> Result<(), LuaVersionError> { let _ = self.lua_version_from_config(config)?; Ok(()) @@ -168,6 +188,23 @@ fn latest_lua_version(dependencies: &PerPlatform>) -> Option); + +impl Deref for RockBinaries { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for RockBinaries { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + #[derive(Error, Debug)] pub enum LuaVersionError { #[error("The lua version {0} is not supported by {1} version {1}!")] diff --git a/rocks-lib/src/tree/mod.rs b/rocks-lib/src/tree/mod.rs index c2d34444..d3098019 100644 --- a/rocks-lib/src/tree/mod.rs +++ b/rocks-lib/src/tree/mod.rs @@ -340,6 +340,7 @@ mod tests { lockfile::{LocalPackage, LocalPackageHashes, LockConstraint}, package::{PackageName, PackageSpec, PackageVersion}, remote_package_source::RemotePackageSource, + rockspec::RockBinaries, tree::RockLayout, }; @@ -368,6 +369,7 @@ mod tests { let package = LocalPackage::from( &PackageSpec::parse("neorg".into(), "8.0.0-1".into()).unwrap(), LockConstraint::Unconstrained, + RockBinaries::default(), RemotePackageSource::Test, mock_hashes.clone(), ); @@ -392,6 +394,7 @@ mod tests { let package = LocalPackage::from( &PackageSpec::parse("lua-cjson".into(), "2.1.0-1".into()).unwrap(), LockConstraint::Unconstrained, + RockBinaries::default(), RemotePackageSource::Test, mock_hashes.clone(), ); @@ -468,6 +471,7 @@ mod tests { .rock(&LocalPackage::from( &PackageSpec::parse("neorg".into(), "8.0.0-1-1".into()).unwrap(), LockConstraint::Unconstrained, + RockBinaries::default(), RemotePackageSource::Test, mock_hashes.clone(), ))