Skip to content

Commit adf8ebb

Browse files
committed
Address review comments
1 parent 3ecc9ef commit adf8ebb

3 files changed

Lines changed: 50 additions & 46 deletions

File tree

crates/repository/src/cargo.rs

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Cargo {
7979
// let status = command
8080
// .arg("pepsi")
8181
// .arg("sdk")
82-
// .adownload_and_installrg("install")
82+
// .arg("install")
8383
// .arg("--version")
8484
// .arg(version)
8585
// .status()
@@ -127,27 +127,12 @@ impl Cargo {
127127
let pwd = Path::new("/hulk").join(&repository.root_to_current_dir()?);
128128
let root = repository.current_dir_to_root()?;
129129
let tagged_image_name = sdk_image.name_tagged();
130-
let mut command = OsString::from(format!(
131-
"\
132-
mkdir -p {cargo_home}/git && \
133-
mkdir -p {cargo_home}/registry && \
134-
podman run \
135-
--volume={root}:/hulk:z \
136-
--volume={cargo_home}/git:/root/.cargo/git:z \
137-
--volume={cargo_home}/registry:/root/.cargo/registry:z \
138-
--net=host \
139-
--rm \
140-
--interactive \
141-
--pull=never \
142-
--tty \
143-
{tagged_image_name} \
144-
/bin/sh -c '\
145-
cd {pwd} && \
146-
echo $PATH && \
147-
/root/.cargo/bin/cargo \
148-
",
149-
root = root.display(),
150-
pwd = pwd.display(),
130+
let mut command = OsString::from(build_command_string(
131+
"podman",
132+
cargo_home,
133+
root.display().to_string(),
134+
tagged_image_name,
135+
pwd.display().to_string(),
151136
));
152137
command.push(arguments);
153138
command.push(OsStr::new("'"));
@@ -159,26 +144,12 @@ impl Cargo {
159144
let pwd = Path::new("/hulk").join(&repository.root_to_current_dir()?);
160145
let root = repository.current_dir_to_root()?;
161146
let tagged_image_name = sdk_image.name_tagged();
162-
let mut command = OsString::from(format!(
163-
"\
164-
mkdir -p {cargo_home}/git && \
165-
mkdir -p {cargo_home}/registry && \
166-
docker run \
167-
--volume={root}:/hulk:z \
168-
--volume={cargo_home}/git:/root/.cargo/git:z \
169-
--volume={cargo_home}/registry:/root/.cargo/registry:z \
170-
--rm \
171-
--interactive \
172-
--pull=never \
173-
--tty \
174-
{tagged_image_name} \
175-
/bin/sh -c '\
176-
cd {pwd} && \
177-
echo $PATH && \
178-
cargo \
179-
",
180-
root = root.display(),
181-
pwd = pwd.display(),
147+
let mut command = OsString::from(build_command_string(
148+
"docker",
149+
cargo_home,
150+
root.display().to_string(),
151+
tagged_image_name,
152+
pwd.display().to_string(),
182153
));
183154
command.push(arguments);
184155
command.push(OsStr::new("'"));
@@ -208,3 +179,31 @@ impl Cargo {
208179
Ok(command)
209180
}
210181
}
182+
183+
fn build_command_string(
184+
container_runtime: &str,
185+
cargo_home: String,
186+
root: String,
187+
tagged_image_name: String,
188+
pwd: String,
189+
) -> String {
190+
format!(
191+
"\
192+
mkdir -p {cargo_home}/git && \
193+
mkdir -p {cargo_home}/registry && \
194+
{container_runtime} run \
195+
--volume={root}:/hulk:z \
196+
--volume={cargo_home}/git:/root/.cargo/git:z \
197+
--volume={cargo_home}/registry:/root/.cargo/registry:z \
198+
--rm \
199+
--interactive \
200+
--pull=never \
201+
--tty \
202+
{tagged_image_name} \
203+
/bin/sh -c '\
204+
cd {pwd} && \
205+
echo $PATH && \
206+
cargo \
207+
"
208+
)
209+
}

crates/repository/src/sdk.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use color_eyre::{eyre::bail, Result};
1+
use color_eyre::{
2+
eyre::{bail, ContextCompat},
3+
Result,
4+
};
25
use tokio::process::Command;
36

47
use crate::Repository;
@@ -54,7 +57,9 @@ pub async fn pull_sdk_image(sdk_image: &SDKImage) -> Result<()> {
5457

5558
pub async fn build_sdk_container(repository: &Repository, sdk_image: &SDKImage) -> Result<()> {
5659
let containerfile_path = repository.root.join("tools/sdk_container/");
57-
let containerfile_path_str = containerfile_path.to_str().unwrap_or("tools/sdk_container");
60+
let containerfile_path_str = containerfile_path
61+
.to_str()
62+
.wrap_err("failed to convert containerfile path to string")?;
5863

5964
let status = Command::new("podman")
6065
.args([

tools/pepsi/src/cargo/environment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ impl Environment {
5858
Ok(match self {
5959
Environment::Native => RepositoryEnvironment::Native,
6060
Environment::Podman { image: Some(image) } => RepositoryEnvironment::Podman {
61-
sdk_image: { sdk_image.parse_and_update(&image) },
61+
sdk_image: sdk_image.parse_and_update(&image),
6262
},
6363
Environment::Podman { image: None } => RepositoryEnvironment::Podman { sdk_image },
6464
Environment::Docker { image: Some(image) } => RepositoryEnvironment::Docker {
65-
sdk_image: { sdk_image.parse_and_update(&image) },
65+
sdk_image: sdk_image.parse_and_update(&image),
6666
},
6767
Environment::Docker { image: None } => RepositoryEnvironment::Docker { sdk_image },
6868
})

0 commit comments

Comments
 (0)