-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,293 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use eyre::{Context, OptionExt}; | ||
use itertools::Itertools; | ||
use std::sync::Arc; | ||
|
||
use clap::Args; | ||
use eyre::Result; | ||
use rocks_lib::{ | ||
build::{self, BuildBehaviour}, | ||
config::Config, | ||
lockfile::PinnedState, | ||
operations::{Install, Sync}, | ||
package::PackageName, | ||
progress::MultiProgress, | ||
project::Project, | ||
rockspec::Rockspec, | ||
}; | ||
|
||
#[derive(Args, Default)] | ||
pub struct Build { | ||
/// Whether to pin the dependencies. | ||
#[arg(long)] | ||
pin: bool, | ||
|
||
/// Ignore the project's existing lockfile. | ||
#[arg(long)] | ||
ignore_lockfile: bool, | ||
} | ||
|
||
pub async fn build(data: Build, config: Config) -> Result<()> { | ||
let project = Project::current()?.ok_or_eyre("Not in a project!")?; | ||
let pin = PinnedState::from(data.pin); | ||
let progress_arc = MultiProgress::new_arc(); | ||
let progress = Arc::clone(&progress_arc); | ||
|
||
let tree = project.tree(&config)?; | ||
let rocks = project.new_local_rockspec()?; | ||
|
||
let lockfile = match project.try_lockfile()? { | ||
None => None, | ||
Some(_) if data.ignore_lockfile => None, | ||
Some(lockfile) => Some(lockfile), | ||
}; | ||
|
||
let dependencies = rocks | ||
.dependencies() | ||
.current_platform() | ||
.iter() | ||
.filter(|package| !package.name().eq(&PackageName::new("lua".into()))) | ||
.cloned() | ||
.collect_vec(); | ||
|
||
match lockfile { | ||
Some(mut project_lockfile) => { | ||
Sync::new(&tree, &mut project_lockfile, &config) | ||
.progress(progress.clone()) | ||
.packages(dependencies) | ||
.sync() | ||
.await | ||
.wrap_err( | ||
" | ||
syncing with the project lockfile failed. | ||
Use --ignore-lockfile to force a new build. | ||
", | ||
)?; | ||
} | ||
None => { | ||
let dependencies_to_install = dependencies | ||
.into_iter() | ||
.filter(|req| { | ||
tree.match_rocks(req) | ||
.is_ok_and(|rock_match| !rock_match.is_found()) | ||
}) | ||
.map(|dep| (BuildBehaviour::NoForce, dep)); | ||
|
||
Install::new(&tree, &config) | ||
.packages(dependencies_to_install) | ||
.project(&project) | ||
.pin(pin) | ||
.progress(progress.clone()) | ||
.install() | ||
.await?; | ||
} | ||
} | ||
|
||
build::Build::new(&rocks, &tree, &config, &progress.map(|p| p.new_bar())) | ||
.pin(pin) | ||
.behaviour(BuildBehaviour::Force) | ||
.build() | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Args; | ||
use eyre::{eyre, Context, Result}; | ||
use rocks_lib::{ | ||
config::{Config, LuaVersion}, | ||
lockfile::Lockfile, | ||
operations, | ||
package::PackageReq, | ||
project::{rocks_toml::RocksToml, ROCKS_TOML}, | ||
rockspec::Rockspec, | ||
}; | ||
|
||
#[derive(Args)] | ||
pub struct Sync { | ||
/// The path to the lockfile to synchronise from. | ||
lockfile: PathBuf, | ||
|
||
/// Path to a rocks.toml. | ||
/// If set, 'rocks sync' will also synchronise the dependencies in the rocks.toml | ||
/// with the lockfile. | ||
/// This is useful if dependencies have been added or removed manually | ||
/// and the lockfile is out of sync. | ||
/// | ||
/// If not set, rocks will check the lockfile's parent directory for a | ||
/// rocks.toml file and use that. | ||
manifest_path: Option<PathBuf>, | ||
|
||
/// Skip the integrity checks for installed rocks. | ||
#[arg(long)] | ||
no_integrity_ckeck: bool, | ||
} | ||
|
||
pub async fn sync(args: Sync, config: Config) -> Result<()> { | ||
let tree = config.tree(LuaVersion::from(&config)?)?; | ||
|
||
let mut lockfile = Lockfile::new(args.lockfile.clone())?; | ||
|
||
let mut sync = operations::Sync::new(&tree, &mut lockfile, &config) | ||
.validate_integrity(!args.no_integrity_ckeck); | ||
|
||
let manifest_path = match args.manifest_path { | ||
Some(path) => { | ||
if !path.is_file() { | ||
return Err(eyre!("File not found: {}", path.display())); | ||
} | ||
Some(path) | ||
} | ||
None => args.lockfile.parent().map(|parent| parent.join(ROCKS_TOML)), | ||
}; | ||
|
||
if let Some(dependencies) = manifest_path | ||
.map(|manifest_path| -> Result<Vec<PackageReq>> { | ||
let content = std::fs::read_to_string(&manifest_path)?; | ||
let rocks = RocksToml::new(&content)?; | ||
Ok(rocks | ||
.into_validated_rocks_toml()? | ||
.dependencies() | ||
.current_platform() | ||
.clone()) | ||
}) | ||
.transpose()? | ||
{ | ||
sync.add_packages(dependencies); | ||
} | ||
|
||
sync.sync().await.wrap_err("sync failed.")?; | ||
|
||
Ok(()) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.