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

cargo-bitbake: Add an option to trust lockfiles #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 24 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ impl<'cfg> PackageInfo<'cfg> {
Ok(registry)
}

/// Loads the set of packages from a lockfile.
fn load_from_lockfile(&self) -> CargoResult<Option<Resolve>> {
cargo::ops::load_pkg_lockfile(&self.ws)
}

/// Resolve the packages necessary for the workspace
fn resolve(&self) -> CargoResult<(PackageSet<'cfg>, Resolve)> {
// build up our registry
Expand Down Expand Up @@ -140,6 +145,13 @@ struct Args {
/// Legacy Overrides: Use legacy override syntax
#[structopt(short = "l", long = "--legacy-overrides")]
legacy_overrides: bool,

/// Require that a lockfile exists, and use it exclusively when
/// resolving what crates to put into the generated .bb recipe.
/// This command will fail if you don't already have a `Cargo.lock`
/// file for the project.
#[structopt(long)]
require_lockfile: bool,
}

#[derive(StructOpt, Debug)]
Expand Down Expand Up @@ -199,13 +211,22 @@ fn real_main(options: Args, config: &mut Config) -> CliResult {
println!("Package name contains an underscore");
}

// Resolve all dependencies (generate or use Cargo.lock as necessary)
let resolve = md.resolve()?;
// If require lockfile was passed, pull dependencies from the
// existing lockfile and skip the resolution step.
let resolve = if options.require_lockfile {
md.load_from_lockfile()?.ok_or(anyhow::format_err!(
"--use-lockfile was passed, but no lockfile was found"
))?
} else {
// Otherwise, resolve all dependencies. If a Cargo.lock file
// already exists, use it as a guide while performing resolution
// and generate or use Cargo.lock as necessary.
md.resolve()?.1
};

// build the crate URIs
let mut src_uri_extras = vec![];
let mut src_uris = resolve
.1
.iter()
.filter_map(|pkg| {
// get the source info for this package
Expand Down