-
Notifications
You must be signed in to change notification settings - Fork 379
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
make env.volumes only change package path when used #665
Conversation
I have not tested this with env.volumes yet |
bors try --target x86 |
tryBuild succeeded: |
1679481
to
b29313c
Compare
This should be feature complete now 🎉 Example docker invocation on windows with env.volumes
without
|
fn wslpath(path: &Path, verbose: bool) -> Result<PathBuf> { | ||
let wslpath = which::which("wsl.exe") | ||
.map_err(|_| eyre::eyre!("could not find wsl.exe")) | ||
.warning("usage of `env.volumes` requires WSL on Windows") | ||
.suggestion("is WSL installed on the host?")?; | ||
|
||
Command::new(wslpath) | ||
.arg("-e") | ||
.arg("wslpath") | ||
.arg("-a") | ||
.arg(path) | ||
.run_and_get_stdout(verbose) | ||
.wrap_err_with(|| { | ||
format!( | ||
"could not get linux compatible path for `{}`", | ||
path.display() | ||
) | ||
}) | ||
.map(|s| s.trim().into()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be possible to fallback to a manual implementation of "normalizing". the logic should be quite simple but I don't feel like it's necessary to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take that back, I tried to do it correctly but handling this is quite annoying :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
fn wslpath2(path: impl AsRef<Path>) -> Result<String> {
fn get_path_prefix_drive(path: &Path) -> Option<&str> {
match path.components().next().unwrap() {
std::path::Component::Prefix(prefix_component) => match prefix_component.kind() {
std::path::Prefix::VerbatimDisk(_) => Some(
prefix_component
.as_os_str()
.to_str()
.expect("windows drive letters should be ascii A-Z")
.strip_prefix(r"\\?\")?
.strip_suffix(":")?,
),
std::path::Prefix::Disk(_) => Some(
prefix_component
.as_os_str()
.to_str()
.expect("windows drive letters should be ascii A-Z")
.strip_suffix(":")?,
),
_ => None,
},
_ => None,
}
}
let path = path.as_ref();
let components = path.components().skip(2);
let mut path_c = String::from("/mnt/");
path_c
.push_str(&get_path_prefix_drive(path).ok_or_else(|| eyre::eyre!("no drive letter found"))?.to_lowercase());
let mut sep = true;
for comp in components {
if sep {
path_c.push('/');
} else {
sep = true;
}
match comp {
std::path::Component::Normal(p) => path_c.push_str(
p.to_str()
.ok_or_else(|| eyre::eyre!("path needs to be utf8"))?,
),
std::path::Component::ParentDir => path_c.push_str(".."),
std::path::Component::CurDir => path_c.push('.'),
_ => sep = false,
}
}
Ok(path_c)
}
has anyone been able to test this and give this a r+ @cross-rs/maintainers <3 |
56c7258
to
f79ce98
Compare
this also tries to fix windows builds by making windows compatible paths for env.volumes
f79ce98
to
daa9ced
Compare
ping @cross-rs/maintainers It would be good to have this included for 0.3.0 |
I'm not using Windows so I cannot test this, but it looks good so far.
Does this have any advantage or is this needed to fix Windows support? |
No advantage, except for not leaking paths in the general case, like what was done before. bors r=reitermarkus |
Build succeeded: |
Removes the dependency on WSL2, and properly handles DOS-style paths, UNC paths, including those on localhost, even if Docker itself does not support them. Closes cross-rs#854. Related to cross-rs#665.
Removes the dependency on WSL2, and properly handles DOS-style paths, UNC paths, including those on localhost, even if Docker itself does not support them. Closes cross-rs#854. Related to cross-rs#665.
Removes the dependency on WSL2, and properly handles DOS-style paths, UNC paths, including those on localhost, even if Docker itself does not support them. Closes cross-rs#854. Related to cross-rs#665. Supersedes cross-rs#852.
856: Remove WSLpath and implement WSL-style path. r=Emilgardis a=Alexhuszagh Removes the dependency on WSL2, and properly handles DOS-style paths, UNC paths, including those on localhost, even if Docker itself does not support them. Closes #854. Related to #665. Supersedes #852. Co-authored-by: Alex Huszagh <[email protected]>
This fixes windows usage.
It also tries to fix windows builds when using
env.volumes
by making windows compatiblepaths for
env.volumes
not using env.volumes will now also mount the project in
/project
again