Skip to content

Commit

Permalink
fix: remove associated binaries when deleting a rock
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jan 15, 2025
1 parent 3f32696 commit c213872
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
/*.rockspec
*.snap.new
/.rocks
rocks.lock

.pre-commit-config.yaml
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rocks-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"constraint": "=2.2.3",
"source": "luarocks_rockspec+https://luarocks.org/",
"binaries": [],
"hashes": {
"rockspec": "sha256-kdDMqznWlwP9wIqlzPrZ5qEDp6edhlkaasAcQzWTmmM=",
"source": "sha256-fNO24tL8wApI8j3rk2mdLf5wbbjlUzsvCxki3n0xRw8="
Expand All @@ -21,6 +22,7 @@
"pinned": false,
"dependencies": [],
"constraint": ">=1.8.0",
"binaries": [],
"source": "luarocks_rockspec+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-5iL9++6X/JsKKtpIRaRHcnZpn6DrsAQQRWPubZK9erY=",
Expand Down
3 changes: 3 additions & 0 deletions rocks-lib/resources/test/sample-tree/5.1/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"
],
"constraint": null,
"binaries": [],
"source": "luarocks_rockspec+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
Expand All @@ -21,6 +22,7 @@
"pinned": false,
"dependencies": [],
"constraint": null,
"binaries": [],
"source": "luarocks_rockspec+https://luarocks.org/",
"hashes": {
"rockspec": "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=",
Expand All @@ -34,6 +36,7 @@
"dependencies": [
"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"
],
"binaries": [],
"constraint": null,
"source": "luarocks_rockspec+https://luarocks.org/",
"hashes": {
Expand Down
29 changes: 16 additions & 13 deletions rocks-lib/src/build/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clean_path::Clean as _;
use itertools::Itertools;
use std::{
collections::{HashMap, HashSet},
io,
path::{Path, PathBuf},
str::FromStr,
};
Expand All @@ -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,
};

Expand All @@ -31,7 +30,7 @@ impl Build for BuiltinBuildSpec {
_config: &Config,
build_dir: &Path,
progress: &Progress<ProgressBar>,
) -> Result<(), Self::Err> {
) -> Result<BuildInfo, Self::Err> {
// Detect all Lua modules
let modules = autodetect_modules(build_dir, source_paths(build_dir, &self.modules))
.into_iter()
Expand Down Expand Up @@ -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 })
}
}

Expand Down
6 changes: 3 additions & 3 deletions rocks-lib/src/build/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
config::Config,
lua_installation::LuaInstallation,
progress::{Progress, ProgressBar},
rockspec::{Build, CMakeBuildSpec},
rockspec::{Build, BuildInfo, CMakeBuildSpec},
tree::RockLayout,
};

Expand Down Expand Up @@ -46,7 +46,7 @@ impl Build for CMakeBuildSpec {
config: &Config,
build_dir: &Path,
_progress: &Progress<ProgressBar>,
) -> Result<(), Self::Err> {
) -> Result<BuildInfo, Self::Err> {
let mut args = Vec::new();
if let Some(content) = self.cmake_lists_content {
let cmakelists = build_dir.join("CMakeLists.txt");
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Build for CMakeBuildSpec {
)?;
}

Ok(())
Ok(BuildInfo::default())
}
}

Expand Down
6 changes: 3 additions & 3 deletions rocks-lib/src/build/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
config::Config,
lua_installation::LuaInstallation,
progress::{Progress, ProgressBar},
rockspec::{Build, CommandBuildSpec},
rockspec::{Build, BuildInfo, CommandBuildSpec},
tree::RockLayout,
};

Expand Down Expand Up @@ -44,14 +44,14 @@ impl Build for CommandBuildSpec {
config: &Config,
build_dir: &Path,
progress: &Progress<ProgressBar>,
) -> Result<(), Self::Err> {
) -> Result<BuildInfo, Self::Err> {
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())
}
}

Expand Down
8 changes: 4 additions & 4 deletions rocks-lib/src/build/luarocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -31,7 +31,7 @@ pub(crate) async fn build(
config: &Config,
build_dir: &Path,
progress: &Progress<ProgressBar>,
) -> Result<(), LuarocksBuildError> {
) -> Result<BuildInfo, LuarocksBuildError> {
progress.map(|p| {
p.set_message(format!(
"Building {} {} with luarocks...",
Expand All @@ -55,7 +55,7 @@ fn install(
luarocks_tree: &Path,
output_paths: &RockLayout,
config: &Config,
) -> Result<(), LuarocksBuildError> {
) -> Result<BuildInfo, LuarocksBuildError> {
let lua_version = rockspec
.lua_version_from_config(config)
.expect("could not get lua version!");
Expand All @@ -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())
}
6 changes: 3 additions & 3 deletions rocks-lib/src/build/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
config::Config,
lua_installation::LuaInstallation,
progress::{Progress, ProgressBar},
rockspec::{Build, MakeBuildSpec},
rockspec::{Build, BuildInfo, MakeBuildSpec},
tree::RockLayout,
};

Expand Down Expand Up @@ -41,7 +41,7 @@ impl Build for MakeBuildSpec {
config: &Config,
build_dir: &Path,
_progress: &Progress<ProgressBar>,
) -> Result<(), Self::Err> {
) -> Result<BuildInfo, Self::Err> {
// Build step
if self.build_pass {
let build_args = self
Expand Down Expand Up @@ -109,6 +109,6 @@ impl Build for MakeBuildSpec {
}
};

Ok(())
Ok(BuildInfo::default())
}
}
75 changes: 39 additions & 36 deletions rocks-lib/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,42 +134,42 @@ async fn run_build(
config: &Config,
build_dir: &Path,
progress: &Progress<ProgressBar>,
) -> Result<(), BuildError> {
) -> Result<BuildInfo, BuildError> {
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(
Expand Down Expand Up @@ -271,6 +271,7 @@ async fn do_build(build: Build<'_>) -> Result<LocalPackage, BuildError> {
build.rockspec.version.clone(),
),
build.constraint,
build.rockspec.binaries(),
build.source.unwrap_or_else(|| {
RemotePackageSource::RockspecContent(build.rockspec.raw_content.clone())
}),
Expand All @@ -291,7 +292,7 @@ async fn do_build(build: Build<'_>) -> Result<LocalPackage, BuildError> {
None => temp_dir.path().into(),
};

run_build(
let output = run_build(
build.rockspec,
&output_paths,
&lua,
Expand All @@ -301,6 +302,8 @@ async fn do_build(build: Build<'_>) -> Result<LocalPackage, BuildError> {
)
.await?;

package.spec.binaries.extend(output.binaries);

install(
build.rockspec,
&tree,
Expand Down
5 changes: 3 additions & 2 deletions rocks-lib/src/build/rust_mlua.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -39,7 +40,7 @@ impl Build for RustMluaBuildSpec {
config: &Config,
build_dir: &Path,
progress: &Progress<ProgressBar>,
) -> Result<(), Self::Err> {
) -> Result<BuildInfo, Self::Err> {
let lua_version = LuaVersion::from(config)?;
let lua_feature = match lua_version {
LuaVersion::Lua51 => "lua51",
Expand Down Expand Up @@ -88,7 +89,7 @@ impl Build for RustMluaBuildSpec {
cleanup(output_paths, progress).await?;
return Err(err.into());
}
Ok(())
Ok(BuildInfo::default())
}
}

Expand Down
Loading

0 comments on commit c213872

Please sign in to comment.