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

feat: rocks install --pin #153

Open
wants to merge 1 commit into
base: push-sxryxmlkxnlp
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion rocks-bin/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ pub async fn build(data: Build, config: Config) -> Result<()> {
.filter(|req| tree.has_rock(req).is_none())
.enumerate()
{
rocks_lib::operations::install(&progress, dependency_req.clone(), &config).await?;
rocks_lib::operations::install(&progress, dependency_req.clone(), data.pin, &config)
.await?;
bar.set_position(index as u64);
}

Expand Down
12 changes: 10 additions & 2 deletions rocks-bin/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ use rocks_lib::{config::Config, package::PackageReq};
#[derive(clap::Args)]
pub struct Install {
package_req: PackageReq,

#[arg(long)]
pin: bool,
}

pub async fn install(install_data: Install, config: Config) -> Result<()> {
// TODO(vhyrro): If the tree doesn't exist then error out.
rocks_lib::operations::install(&MultiProgress::new(), install_data.package_req, &config)
.await?;
rocks_lib::operations::install(
&MultiProgress::new(),
install_data.package_req,
install_data.pin,
&config,
)
.await?;

Ok(())
}
2 changes: 1 addition & 1 deletion rocks-lib/resources/test/sample-tree/5.1/lock.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.0.0","rocks":{"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0":{"name":"lua-cjson","version":"2.1.0-1","pinned":false,"dependencies":[],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}},"aa0a5bcd396f3b8e59fa9dd8059a06c3bf4952f48473214d96fc46895edb59f0":{"name":"neorg","version":"8.8.1-1","pinned":false,"dependencies":["48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}},"d7164c4921869877c7f29fce3f14b8ea78e0aec0d0c36123a3a920a894785ea5":{"name":"neorg","version":"8.0.0-1","pinned":false,"dependencies":["48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}}},"entrypoints":["aa0a5bcd396f3b8e59fa9dd8059a06c3bf4952f48473214d96fc46895edb59f0","d7164c4921869877c7f29fce3f14b8ea78e0aec0d0c36123a3a920a894785ea5"]}
{"version":"1.0.0","rocks":{"aa0a5bcd396f3b8e59fa9dd8059a06c3bf4952f48473214d96fc46895edb59f0":{"name":"neorg","version":"8.8.1-1","pinned":false,"dependencies":["48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}},"d7164c4921869877c7f29fce3f14b8ea78e0aec0d0c36123a3a920a894785ea5":{"name":"neorg","version":"8.0.0-1","pinned":false,"dependencies":["48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0"],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}},"48ec344951668eca0e0a4ff284d804a11e4e709194df3191a72ed8fac89cf2e0":{"name":"lua-cjson","version":"2.1.0-1","pinned":false,"dependencies":[],"constraint":null,"hashes":{"rockspec":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","source":"sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="}}},"entrypoints":["aa0a5bcd396f3b8e59fa9dd8059a06c3bf4952f48473214d96fc46895edb59f0","d7164c4921869877c7f29fce3f14b8ea78e0aec0d0c36123a3a920a894785ea5"]}
9 changes: 5 additions & 4 deletions rocks-lib/src/operations/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ use itertools::Itertools;
pub async fn install(
progress: &MultiProgress,
package_req: PackageReq,
pin: bool,
config: &Config,
) -> Result<LocalPackage> {
with_spinner(
progress,
format!("💻 Installing {}", package_req),
|| async { install_impl(progress, package_req, config).await },
|| async { install_impl(progress, package_req, pin, config).await },
)
.await
}

async fn install_impl(
progress: &MultiProgress,
package_req: PackageReq,
pin: bool,
config: &Config,
) -> Result<LocalPackage> {
let rockspec = super::download_rockspec(progress, &package_req, config).await?;
Expand All @@ -38,7 +40,6 @@ async fn install_impl(
let mut lockfile = tree.lockfile()?;

let constraint = LockConstraint::Constrained(package_req.version_req().clone());
let pinned = false;

// Recursively build all dependencies.
let dependencies = rockspec
Expand All @@ -57,13 +58,13 @@ async fn install_impl(
.enumerate()
{
let dependency =
crate::operations::install(progress, dependency_req.clone(), config).await?;
crate::operations::install(progress, dependency_req.clone(), pin, config).await?;

installed_dependencies.push(dependency);
bar.set_position(index as u64);
}

let package = crate::build::build(progress, rockspec, pinned, constraint, config).await?;
let package = crate::build::build(progress, rockspec, pin, constraint, config).await?;

lockfile.add(&package);
for dependency in installed_dependencies {
Expand Down
4 changes: 2 additions & 2 deletions rocks-lib/src/operations/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub async fn update(
.to_package()
.has_update_with(&constraint, manifest)?;

if latest_version.is_some() {
if latest_version.is_some() && !package.pinned() {
// Install the newest package.
install(progress, constraint, config).await?;
install(progress, constraint, false, config).await?;

// Remove the old package
remove(progress, package, config).await?;
Expand Down