diff --git a/.changes/1325.json b/.changes/1325.json new file mode 100644 index 000000000..5c00fa8ad --- /dev/null +++ b/.changes/1325.json @@ -0,0 +1,5 @@ +{ + "description": "create CACHEDIR.TAG during custom docker build", + "type": "fixed", + "issues": [1324] +} diff --git a/src/docker/custom.rs b/src/docker/custom.rs index d71825710..a58b2370c 100644 --- a/src/docker/custom.rs +++ b/src/docker/custom.rs @@ -7,7 +7,10 @@ use crate::shell::MessageInfo; use crate::{errors::*, file, CommandExt, ToUtf8}; use crate::{CargoMetadata, TargetTriple}; -use super::{get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine, ImagePlatform}; +use super::{ + create_target_dir, get_image_name, path_hash, BuildCommandExt, BuildResultExt, Engine, + ImagePlatform, +}; pub const CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX: &str = "localhost/cross-rs/cross-custom-"; @@ -119,11 +122,12 @@ impl<'a> Dockerfile<'a> { let path = match self { Dockerfile::File { path, .. } => PathBuf::from(path), Dockerfile::Custom { content, .. } => { - let path = paths + let target_dir = paths .metadata .target_directory - .join(options.target.to_string()) - .join(format!("Dockerfile.{}-custom", &options.target)); + .join(options.target.to_string()); + create_target_dir(&target_dir)?; + let path = target_dir.join(format!("Dockerfile.{}-custom", &options.target)); { let mut file = file::write_file(&path, true)?; file.write_all(content.as_bytes())?; diff --git a/src/docker/shared.rs b/src/docker/shared.rs index 83ec3bfc9..efe1e332e 100644 --- a/src/docker/shared.rs +++ b/src/docker/shared.rs @@ -819,7 +819,7 @@ const CACHEDIR_TAG: &str = "Signature: 8a477f597d28d172789f06886806bc55 # This file is a cache directory tag created by cross. # For information about cache directory tags see https://bford.info/cachedir/"; -fn create_target_dir(path: &Path) -> Result<()> { +pub fn create_target_dir(path: &Path) -> Result<()> { // cargo creates all paths to the target directory, and writes // a cache dir tag only if the path doesn't previously exist. if !path.exists() {