Skip to content

Commit

Permalink
feat: add use-gitignore to recipe (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw authored Nov 27, 2023
1 parent 4bd2ccf commit f052572
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/ros-humble-turtlebot4-msgs/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 26 additions & 2 deletions src/recipe/parser/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub struct GitSource {
folder: Option<PathBuf>,
/// 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 {
Expand All @@ -120,6 +122,7 @@ impl GitSource {
patches: Vec<PathBuf>,
folder: Option<PathBuf>,
lfs: bool,
use_gitignore: bool,
) -> Self {
Self {
url,
Expand All @@ -128,6 +131,7 @@ impl GitSource {
patches,
folder,
lfs,
use_gitignore,
}
}

Expand Down Expand Up @@ -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<GitSource> for RenderedMappingNode {
Expand All @@ -170,6 +179,7 @@ impl TryConvertNode<GitSource> 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
Expand Down Expand Up @@ -214,11 +224,14 @@ impl TryConvertNode<GitSource> 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`"
))
}
}
Expand All @@ -241,6 +254,7 @@ impl TryConvertNode<GitSource> for RenderedMappingNode {
patches,
folder,
lfs,
use_gitignore,
})
}
}
Expand Down Expand Up @@ -352,7 +366,7 @@ impl TryConvertNode<UrlSource> 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`"
))
}
}
Expand Down Expand Up @@ -404,6 +418,8 @@ pub struct PathSource {
patches: Vec<PathBuf>,
/// Optionally a folder name under the `work` directory to place the source code
folder: Option<PathBuf>,
/// Whether to use the `.gitignore` file in the source directory. Defaults to `true`.
use_gitignore: bool,
}

impl PathSource {
Expand All @@ -421,19 +437,26 @@ 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<PathSource> for RenderedMappingNode {
fn try_convert(&self, _name: &str) -> Result<PathSource, PartialParsingError> {
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(),
Expand All @@ -456,6 +479,7 @@ impl TryConvertNode<PathSource> for RenderedMappingNode {
path,
patches,
folder,
use_gitignore,
})
}
}
4 changes: 4 additions & 0 deletions src/source/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ mod tests {
vec![],
None,
false,
false,
),
"rattler-build",
),
Expand All @@ -270,6 +271,7 @@ mod tests {
vec![],
None,
false,
false,
),
"rattler-build",
),
Expand All @@ -285,6 +287,7 @@ mod tests {
vec![],
None,
false,
false,
),
"rattler-build",
),
Expand All @@ -296,6 +299,7 @@ mod tests {
vec![],
None,
false,
false,
),
"rattler-build",
),
Expand Down
4 changes: 2 additions & 2 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f052572

Please sign in to comment.