Skip to content

Commit

Permalink
Minor bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Jun 29, 2022
1 parent e594054 commit df1c781
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/bin/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ impl CreateVolume {

#[derive(Args, Debug)]
pub struct RemoveVolume {
/// Triple for the target platform.
#[clap(long)]
pub target: String,
/// FIXME: remove in 0.3.0, remains since it's a breaking change.
#[clap(long, hide = true)]
pub target: Option<String>,
/// If cross is running inside a container.
#[clap(short, long)]
pub docker_in_docker: bool,
Expand Down Expand Up @@ -473,7 +473,6 @@ pub fn create_persistent_volume(

pub fn remove_persistent_volume(
RemoveVolume {
target,
docker_in_docker,
verbose,
quiet,
Expand All @@ -484,8 +483,9 @@ pub fn remove_persistent_volume(
channel: Option<&str>,
) -> cross::Result<()> {
let msg_info = MessageInfo::create(verbose, quiet, color.as_deref())?;
let triple = cross::Host::X86_64UnknownLinuxGnu.triple();
let (_, _, dirs) =
docker::get_package_info(engine, &target, channel, docker_in_docker, msg_info)?;
docker::get_package_info(engine, triple, channel, docker_in_docker, msg_info)?;
let volume = docker::remote::unique_toolchain_identifier(&dirs.sysroot)?;

if !docker::remote::volume_exists(engine, &volume, msg_info)? {
Expand Down
14 changes: 6 additions & 8 deletions xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn gha_output(tag: &str, content: &str) {
println!("::set-output name={tag}::{}", content)
}

pub fn read_dockerfiles(msg_info: MessageInfo) -> cross::Result<Vec<String>> {
pub fn read_dockerfiles(msg_info: MessageInfo) -> cross::Result<Vec<(PathBuf, String)>> {
let root = project_dir(msg_info)?;
let docker = root.join("docker");
let mut dockerfiles = vec![];
Expand All @@ -225,18 +225,18 @@ pub fn read_dockerfiles(msg_info: MessageInfo) -> cross::Result<Vec<String>> {
let file_type = entry.file_type()?;
let file_name = entry.file_name();
if file_type.is_file() && file_name.to_utf8()?.starts_with("Dockerfile") {
dockerfiles.push(fs::read_to_string(entry.path())?);
let contents = fs::read_to_string(entry.path())?;
dockerfiles.push((entry.path().to_path_buf(), contents));
}
}

Ok(dockerfiles)
}

#[cfg(tests)]
#[cfg(test)]
mod tests {
use super::*;

use crate::util::read_dockerfiles;
use cross::shell::Verbosity;
use std::collections::BTreeMap;

Expand All @@ -245,15 +245,13 @@ mod tests {
// count all the entries of FROM for our images
let mut counts = BTreeMap::new();
let dockerfiles = read_dockerfiles(Verbosity::Verbose.into())?;
for dockerfile in dockerfiles {
for (path, dockerfile) in dockerfiles {
let lines: Vec<&str> = dockerfile.lines().collect();
let index = lines
.iter()
.map(|x| x.trim())
.position(|x| x.to_lowercase().starts_with("from"))
.ok_or_else(|| {
eyre::eyre!("unable to find FROM instruction for {:?}", entry.path())
})?;
.ok_or_else(|| eyre::eyre!("unable to find FROM instruction for {:?}", path))?;
let tag = lines[index]
.split_whitespace()
.nth(1)
Expand Down

0 comments on commit df1c781

Please sign in to comment.