Skip to content

Commit

Permalink
fix: use only unix_path::PathBuf for contract in docker/metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yfo committed May 6, 2024
1 parent 1ba99c0 commit 7bf9423
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tempfile = "3.10.1"
git2 = "0.18"
home = "0.5.9"
pathdiff = { version = "0.2.1", features = ["camino"]}
unix_path = "1.0.1"
url = { version = "2.5.0", features = ["serde"]}

[target.'cfg(unix)'.dependencies]
Expand Down
17 changes: 10 additions & 7 deletions cargo-near/src/commands/build_command/docker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
process::{id, Command, ExitStatus},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};

Expand Down Expand Up @@ -295,10 +294,13 @@ impl ContainerPaths {
&mounted_repo
);
let crate_path = {
let mut repo_path = camino::Utf8PathBuf::from_str(&mounted_repo)?;
repo_path.push(cloned_repo.initial_crate_in_repo.relative_path()?);
// TODO
repo_path.to_string()
let mut repo_path = unix_path::Path::new(NEP330_REPO_MOUNT).to_path_buf();
repo_path.push(cloned_repo.initial_crate_in_repo.unix_relative_path()?);

repo_path
.to_str()
.wrap_err("non UTF-8 unix path computed as crate path")?
.to_string()
};
Ok(Self {
host_volume_arg,
Expand All @@ -323,8 +325,9 @@ impl Nep330BuildInfo {
let build_environment = docker_build_meta.concat_image();
let contract_path = cloned_repo
.initial_crate_in_repo
.relative_path()?
.as_str()
.unix_relative_path()?
.to_str()
.wrap_err("non UTF-8 unix path computed as contract path")?
.to_string();
let contract_path = if contract_path.is_empty() {
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ClonedRepo {
let tmp_crate_metadata = {
let cargo_toml_path: camino::Utf8PathBuf = {
let mut path: camino::Utf8PathBuf = tmp_repo_path.clone().try_into()?;
path.push(crate_in_repo.relative_path()?);
path.push(crate_in_repo.host_relative_path()?);
path.push(MANIFEST_FILE_NAME);
path
};
Expand Down
21 changes: 20 additions & 1 deletion cargo-near/src/commands/build_command/docker/crate_in_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,27 @@ impl Crate {
}
}
}
pub fn relative_path(&self) -> color_eyre::eyre::Result<camino::Utf8PathBuf> {
pub fn host_relative_path(&self) -> color_eyre::eyre::Result<camino::Utf8PathBuf> {
pathdiff::diff_utf8_paths(&self.crate_root, &self.repo_root)
.wrap_err("cannot compute crate's relative path in repo")
}
pub fn unix_relative_path(&self) -> color_eyre::eyre::Result<unix_path::PathBuf> {
let host_relative: camino::Utf8PathBuf = self.host_relative_path()?;

let path_buf = {
let iter = host_relative
.components()
.map(|component| component.as_str());
unix_path::PathBuf::from_iter(iter.map(unix_path::Path::new))
};

if !path_buf.as_path().is_relative() {
return Err(color_eyre::eyre::eyre!(
"crate's path in repo, expressed as a unix path, isn't relative : {:?}",
path_buf.to_str()
));
}

Ok(path_buf)
}
}
12 changes: 11 additions & 1 deletion cargo-near/src/types/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ impl TryFrom<Utf8PathBuf> for CargoManifestPath {
.kind()
{
std::io::ErrorKind::NotFound => {
color_eyre::eyre::eyre!("manifest path `{manifest_path}` does not exist")
match std::env::current_dir() {
Ok(pwd ) => {
let pwd = pwd.to_string_lossy();
color_eyre::eyre::eyre!("manifest path `{manifest_path}` in `{pwd}` does not exist")
},
Err(err) => {
color_eyre::eyre::eyre!("manifest path `{manifest_path}` in `workdir not determined: {:?}` does not exist",
err
)
}
}
}
_ => color_eyre::eyre::eyre!("manifest_path.canonicalize_utf8() error: {err}"),
})?;
Expand Down

0 comments on commit 7bf9423

Please sign in to comment.