-
Notifications
You must be signed in to change notification settings - Fork 410
Allow users to ignore config files in the package. #936
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "added", | ||
"description": "allow users to ignore config files in the package.", | ||
"issues": [621] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,12 @@ use crate::cargo::{cargo_metadata_with_args, CargoMetadata}; | |
use crate::config::{bool_from_envvar, Config}; | ||
use crate::errors::*; | ||
use crate::extensions::{CommandExt, SafeCommand}; | ||
use crate::file::{self, write_file, ToUtf8}; | ||
use crate::file::{self, write_file, PathExt, ToUtf8}; | ||
use crate::id; | ||
use crate::rustc::{self, VersionMetaExt}; | ||
use crate::shell::{MessageInfo, Verbosity}; | ||
use crate::Target; | ||
|
||
#[cfg(target_os = "windows")] | ||
use crate::file::PathExt; | ||
|
||
pub use super::custom::CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX; | ||
|
||
pub const CROSS_IMAGE: &str = "ghcr.io/cross-rs"; | ||
|
@@ -37,15 +34,23 @@ pub struct DockerOptions { | |
pub target: Target, | ||
pub config: Config, | ||
pub uses_xargo: bool, | ||
pub ignore_cargo_config: bool, | ||
} | ||
|
||
impl DockerOptions { | ||
pub fn new(engine: Engine, target: Target, config: Config, uses_xargo: bool) -> DockerOptions { | ||
pub fn new( | ||
engine: Engine, | ||
target: Target, | ||
config: Config, | ||
uses_xargo: bool, | ||
ignore_cargo_config: bool, | ||
) -> DockerOptions { | ||
DockerOptions { | ||
engine, | ||
target, | ||
config, | ||
uses_xargo, | ||
ignore_cargo_config, | ||
} | ||
} | ||
|
||
|
@@ -220,10 +225,18 @@ impl DockerPaths { | |
self.workspace_from_cwd().is_ok() | ||
} | ||
|
||
pub fn cargo_home(&self) -> &Path { | ||
&self.directories.cargo | ||
} | ||
|
||
pub fn mount_cwd(&self) -> &str { | ||
&self.directories.mount_cwd | ||
} | ||
|
||
pub fn mount_root(&self) -> &str { | ||
&self.directories.mount_root | ||
} | ||
|
||
pub fn host_root(&self) -> &Path { | ||
&self.directories.host_root | ||
} | ||
|
@@ -499,8 +512,44 @@ pub(crate) fn docker_envvars( | |
Ok(()) | ||
} | ||
|
||
pub(crate) fn docker_cwd(docker: &mut Command, paths: &DockerPaths) -> Result<()> { | ||
fn mount_to_ignore_cargo_config( | ||
docker: &mut Command, | ||
paths: &DockerPaths, | ||
ignore_cargo_config: bool, | ||
) -> Result<()> { | ||
let check_mount = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks if the path exists on the host (canonicalized), and only if it does, mounts it. This avoids any permission issues or creating undesired directories. |
||
|cmd: &mut Command, host: &Path, mount: &Path, relpath: &Path| -> Result<()> { | ||
let cargo_dir = relpath.join(".cargo"); | ||
if host.join(&cargo_dir).exists() { | ||
// this is fine, since it has to be a POSIX path on the mount. | ||
cmd.args(&["-v", &mount.join(&cargo_dir).as_posix()?]); | ||
} | ||
|
||
Ok(()) | ||
}; | ||
if ignore_cargo_config { | ||
let mount_root = Path::new(paths.mount_root()); | ||
let mount_cwd = Path::new(paths.mount_cwd()); | ||
check_mount(docker, &paths.cwd, mount_cwd, Path::new(""))?; | ||
// CWD isn't guaranteed to be a subdirectory of the mount root. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we've removed |
||
if let Ok(mut relpath) = mount_cwd.strip_prefix(mount_root) { | ||
while let Some(parent) = relpath.parent() { | ||
check_mount(docker, paths.host_root(), mount_root, parent)?; | ||
relpath = parent; | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn docker_cwd( | ||
docker: &mut Command, | ||
paths: &DockerPaths, | ||
ignore_cargo_config: bool, | ||
) -> Result<()> { | ||
docker.args(&["-w", paths.mount_cwd()]); | ||
mount_to_ignore_cargo_config(docker, paths, ignore_cargo_config)?; | ||
|
||
Ok(()) | ||
} | ||
|
@@ -788,9 +837,6 @@ mod tests { | |
use super::*; | ||
use crate::id; | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
use crate::file::PathExt; | ||
|
||
#[test] | ||
fn test_docker_user_id() { | ||
let var = "CROSS_ROOTLESS_CONTAINER_ENGINE"; | ||
|
Uh oh!
There was an error while loading. Please reload this page.