From f0525729da7ed700217debe8b0bfea3b229b88dc Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Mon, 27 Nov 2023 09:46:56 +0100 Subject: [PATCH] feat: add use-gitignore to recipe (#358) --- .../ros-humble-turtlebot4-msgs/recipe.yaml | 1 + src/recipe/parser/source.rs | 28 +++++++++++++++++-- src/source/git_source.rs | 4 +++ src/source/mod.rs | 4 +-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/examples/ros-humble-turtlebot4-msgs/recipe.yaml b/examples/ros-humble-turtlebot4-msgs/recipe.yaml index 4223e889..02086b82 100644 --- a/examples/ros-humble-turtlebot4-msgs/recipe.yaml +++ b/examples/ros-humble-turtlebot4-msgs/recipe.yaml @@ -8,6 +8,7 @@ source: git_url: https://github.com/ros2-gbp/turtlebot4-release.git git_rev: release/humble/turtlebot4_msgs/1.0.3-1 folder: ros-humble-turtlebot4-msgs/src/work + use_gitignore: true build: script: diff --git a/src/recipe/parser/source.rs b/src/recipe/parser/source.rs index db06b22e..bce9bf13 100644 --- a/src/recipe/parser/source.rs +++ b/src/recipe/parser/source.rs @@ -109,6 +109,8 @@ pub struct GitSource { folder: Option, /// Optionally request the lfs pull in git source lfs: bool, + /// Whether to use the `.gitignore` file in the source directory, defaults to `false`. + use_gitignore: bool, } impl GitSource { @@ -120,6 +122,7 @@ impl GitSource { patches: Vec, folder: Option, lfs: bool, + use_gitignore: bool, ) -> Self { Self { url, @@ -128,6 +131,7 @@ impl GitSource { patches, folder, lfs, + use_gitignore, } } @@ -160,6 +164,11 @@ impl GitSource { pub const fn lfs(&self) -> bool { self.lfs } + + /// Whether to use the `.gitignore` file in the source directory. Defaults to `false`. + pub const fn use_gitignore(&self) -> bool { + self.use_gitignore + } } impl TryConvertNode for RenderedMappingNode { @@ -170,6 +179,7 @@ impl TryConvertNode for RenderedMappingNode { let mut patches = Vec::new(); let mut folder = None; let mut lfs = false; + let mut use_gitignore = false; // TODO: is there a better place for this error? // raising the error during parsing allows us to suggest fixes in future @@ -214,11 +224,14 @@ impl TryConvertNode for RenderedMappingNode { "lfs" => { lfs = v.try_convert("lfs")?; } + "use_gitignore" => { + use_gitignore = v.try_convert("use_gitignore")?; + } _ => { return Err(_partialerror!( *k.span(), ErrorKind::InvalidField(k.as_str().to_owned().into()), - help = "valid fields for git `source` are `git_url`, `git_rev`, `git_depth`, `patches`, `lfs` and `folder`" + help = "valid fields for git `source` are `git_url`, `git_rev`, `git_depth`, `patches`, `lfs`, `folder` and `use_gitignore`" )) } } @@ -241,6 +254,7 @@ impl TryConvertNode for RenderedMappingNode { patches, folder, lfs, + use_gitignore, }) } } @@ -352,7 +366,7 @@ impl TryConvertNode for RenderedMappingNode { return Err(_partialerror!( *key.span(), ErrorKind::InvalidField(invalid_key.to_owned().into()), - help = "valid fields for URL `source` are `url`, `sha256`, `md5`, `patches`, `file_name` and `folder`" + help = "valid fields for URL `source` are `url`, `sha256`, `md5`, `patches`, `file_name`, `folder` and `use_gitignore`" )) } } @@ -404,6 +418,8 @@ pub struct PathSource { patches: Vec, /// Optionally a folder name under the `work` directory to place the source code folder: Option, + /// Whether to use the `.gitignore` file in the source directory. Defaults to `true`. + use_gitignore: bool, } impl PathSource { @@ -421,6 +437,11 @@ impl PathSource { pub const fn folder(&self) -> Option<&PathBuf> { self.folder.as_ref() } + + /// Whether to use the `.gitignore` file in the source directory. + pub const fn use_gitignore(&self) -> bool { + self.use_gitignore + } } impl TryConvertNode for RenderedMappingNode { @@ -428,12 +449,14 @@ impl TryConvertNode for RenderedMappingNode { let mut path = None; let mut patches = Vec::new(); let mut folder = None; + let mut use_gitignore = true; for (key, value) in self.iter() { match key.as_str() { "path" => path = value.try_convert("path")?, "patches" => patches = value.try_convert("patches")?, "folder" => folder = value.try_convert("folder")?, + "use_gitignore" => use_gitignore = value.try_convert("use_gitignore")?, invalid_key => { return Err(_partialerror!( *key.span(), @@ -456,6 +479,7 @@ impl TryConvertNode for RenderedMappingNode { path, patches, folder, + use_gitignore, }) } } diff --git a/src/source/git_source.rs b/src/source/git_source.rs index 19de85b6..dc41b25a 100644 --- a/src/source/git_source.rs +++ b/src/source/git_source.rs @@ -255,6 +255,7 @@ mod tests { vec![], None, false, + false, ), "rattler-build", ), @@ -270,6 +271,7 @@ mod tests { vec![], None, false, + false, ), "rattler-build", ), @@ -285,6 +287,7 @@ mod tests { vec![], None, false, + false, ), "rattler-build", ), @@ -296,6 +299,7 @@ mod tests { vec![], None, false, + false, ), "rattler-build", ), diff --git a/src/source/mod.rs b/src/source/mod.rs index e00bb019..8701f0dc 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -83,7 +83,7 @@ pub async fn fetch_sources( work_dir.to_path_buf() }; crate::source::copy_dir::CopyDir::new(&result, &dest_dir) - .use_gitignore(false) + .use_gitignore(src.use_gitignore()) .run()?; if !src.patches().is_empty() { patch::apply_patches(src.patches(), work_dir, recipe_dir)?; @@ -139,7 +139,7 @@ pub async fn fetch_sources( work_dir.to_path_buf() }; let _ = copy_dir::CopyDir::new(&src_path, &dest_dir) - .use_gitignore(true) + .use_gitignore(src.use_gitignore()) .run()?; if !src.patches().is_empty() {