Skip to content

Commit

Permalink
Merge pull request #135 from pulp-platform/path/no-checkout
Browse files Browse the repository at this point in the history
path: Skip checkout if possible
  • Loading branch information
micprog authored Sep 12, 2023
2 parents 8e67553 + 8c4a1e2 commit 4447df3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 28 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Add `--checkout` flag to `path` command to force checkout if needed.
- Add `--no-checkout` flag to `update` command to prevent checkout after update if not needed.

### Changed
- `path` and local links: Skip checkout if package path already exists (can be overruled by `--checkout` flag)
- `update`: Default to automatically perform checkout after update (can be overruled by `--no-checkout` flag)

### Fixed
- Improve ReadMe and Warning information for `vendor` upstream linking.
- Ensure `workspace.package_links` symlinks are properly updated when executing the `clone` command.
Expand Down
48 changes: 35 additions & 13 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ pub fn main() -> Result<()> {
.help("Disables fetching of remotes (e.g. for air-gapped computers)"),
)
.subcommand(
Command::new("update").about("Update the dependencies").arg(
Arg::new("fetch")
.short('f')
.long("fetch")
.num_args(0)
.action(ArgAction::SetTrue)
.help("forces fetch of git dependencies"),
),
Command::new("update")
.about("Update the dependencies")
.arg(
Arg::new("fetch")
.short('f')
.long("fetch")
.num_args(0)
.action(ArgAction::SetTrue)
.help("forces fetch of git dependencies"),
)
.arg(
Arg::new("no-checkout")
.long("no-checkout")
.num_args(0)
.action(ArgAction::SetTrue)
.help("Disables checkout of dependencies"),
),
)
.subcommand(cmd::path::new())
.subcommand(cmd::parents::new())
Expand Down Expand Up @@ -174,17 +183,24 @@ pub fn main() -> Result<()> {

// Ensure the locally linked packages are up-to-date.
{
let rt = Runtime::new()?;
let io = SessionIo::new(&sess);
for (path, pkg_name) in &sess.manifest.workspace.package_links {
debugln!("main: maintaining link to {} at {:?}", pkg_name, path);

// Determine the checkout path for this package.
let pkg_path = rt.block_on(io.checkout(sess.dependency_with_name(pkg_name)?))?;
let pkg_path = io.get_package_path(sess.dependency_with_name(pkg_name)?);

// Checkout if we are running update or package path does not exist yet
if matches.subcommand_name() == Some("update") || !pkg_path.clone().exists() {
let rt = Runtime::new()?;
rt.block_on(io.checkout(sess.dependency_with_name(pkg_name)?))?;
}

// Convert to relative path
let pkg_path = path
.parent()
.and_then(|path| pathdiff::diff_paths(pkg_path, path))
.unwrap_or_else(|| pkg_path.into());
.and_then(|path| pathdiff::diff_paths(pkg_path.clone(), path))
.unwrap_or(pkg_path);

// Check if there is something at the destination path that needs to be
// removed.
Expand Down Expand Up @@ -256,7 +272,13 @@ pub fn main() -> Result<()> {
Some(("config", matches)) => cmd::config::run(&sess, matches),
Some(("script", matches)) => cmd::script::run(&sess, matches),
Some(("checkout", matches)) => cmd::checkout::run(&sess, matches),
Some(("update", _)) => Ok(()),
Some(("update", _)) => {
if matches.get_flag("no-checkout") {
Ok(())
} else {
cmd::checkout::run(&sess, &matches)
}
}
Some(("vendor", matches)) => cmd::vendor::run(&sess, matches),
Some(("fusesoc", matches)) => cmd::fusesoc::run(&sess, matches),
Some((plugin, matches)) => execute_plugin(&sess, plugin, matches.get_many::<OsString>("")),
Expand Down
50 changes: 35 additions & 15 deletions src/cmd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! The `path` subcommand.
use clap::{Arg, ArgMatches, Command};
use clap::{Arg, ArgAction, ArgMatches, Command};
use futures::future::join_all;
use tokio::runtime::Runtime;

Expand All @@ -20,32 +20,52 @@ pub fn new() -> Command {
.required(true)
.help("Package names to get the path for"),
)
.arg(
Arg::new("checkout")
.long("checkout")
.num_args(0)
.action(ArgAction::SetTrue)
.help("Force check out of dependency."),
)
}

/// Execute the `path` subcommand.
pub fn run(sess: &Session, matches: &ArgMatches) -> Result<()> {
let rt = Runtime::new()?;
let io = SessionIo::new(sess);

let ids = matches
.get_many::<String>("name")
.unwrap()
.map(|n| Ok((n, sess.dependency_with_name(&n.to_lowercase())?)))
.collect::<Result<Vec<_>>>()?;
debugln!("main: obtain checkouts {:?}", ids);
let checkouts = rt
.block_on(join_all(
ids.iter()
.map(|&(_, id)| io.checkout(id))
.collect::<Vec<_>>(),
))
.into_iter()
.collect::<Result<Vec<_>>>()?;
debugln!("main: checkouts {:#?}", checkouts);
for c in checkouts {

let io = SessionIo::new(sess);

// Get paths
let paths = ids
.iter()
.map(|&(_, id)| io.get_package_path(id))
.collect::<Vec<_>>();

// Check out if requested or not done yet
if matches.get_flag("checkout") || !paths.iter().all(|p| p.exists()) {
debugln!("main: obtain checkouts {:?}", ids);
let rt = Runtime::new()?;
let checkouts = rt
.block_on(join_all(
ids.iter()
.map(|&(_, id)| io.checkout(id))
.collect::<Vec<_>>(),
))
.into_iter()
.collect::<Result<Vec<_>>>()?;
debugln!("main: checkouts {:#?}", checkouts);
}

// Print paths
for c in paths {
if let Some(s) = c.to_str() {
println!("{}", s);
}
}

Ok(())
}

0 comments on commit 4447df3

Please sign in to comment.