Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- The `source.filter` field is now also supported for `url` and `git` sources (it was previously only available for `path` sources). The filter is applied to the files copied into the work directory: the contents of the extracted archive for `url` sources (and `path` sources pointing to an archive) and the checked-out tree for `git` sources. This allows large sources to be trimmed down to the parts needed for the build.

### Changed

- Improve CRAN (R) recipe generation: pass `${R_ARGS}` to `R CMD INSTALL`, add `cross-r-base` for cross-compilation, set `rpaths` for compiled packages, mark pure-R packages as `noarch: generic`, reference `r-base`'s bundled license files, and fix the `r-base` version constraint so it is applied to both `host` and `run` without duplication.
Expand Down
16 changes: 14 additions & 2 deletions crates/rattler_build_core/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};

use fs_err as fs;
use rattler_build_recipe::stage1::{Source, source::GitRev};
use rattler_build_recipe::stage1::{GlobVec, Source, source::GitRev};
use rattler_build_source_cache::{Checksum, cache::is_tarball};
use rattler_build_source_cache::{
GitSource as CacheGitSource, Source as CacheSource, UrlSource as CacheUrlSource,
Expand Down Expand Up @@ -90,6 +90,7 @@ fn copy_from_cache(
cache_path: &Path,
dest_dir: &Path,
file_name: Option<&str>,
filter: &GlobVec,
tool_config: &tool_configuration::Configuration,
) -> Result<(), SourceError> {
if cache_path.is_dir() {
Expand All @@ -103,6 +104,7 @@ fn copy_from_cache(
|| {
copy_dir::CopyDir::new(cache_path, dest_dir)
.use_gitignore(false)
.with_globvec(filter)
.run()
},
)?;
Expand Down Expand Up @@ -272,6 +274,7 @@ async fn fetch_source(
|| {
copy_dir::CopyDir::new(&result.path, &dest_dir)
.use_gitignore(false)
.with_globvec(&git_src.filter)
.run()
},
)?;
Expand Down Expand Up @@ -316,7 +319,13 @@ async fn fetch_source(
fs::create_dir_all(&dest_dir)?;

let extracted_path = if result.path.is_dir() {
copy_from_cache(&result.path, &dest_dir, None, tool_configuration)?;
copy_from_cache(
&result.path,
&dest_dir,
None,
&url_src.filter,
tool_configuration,
)?;

// Track the extracted path for create-patch functionality
result
Expand All @@ -335,6 +344,7 @@ async fn fetch_source(
&result.path,
&dest_dir,
Some(&file_name),
&url_src.filter,
tool_configuration,
)?;
None
Expand Down Expand Up @@ -409,6 +419,7 @@ async fn fetch_source(
file_name: None,
target_directory: path_src.target_directory.clone(),
attestation: None,
filter: path_src.filter.clone(),
};

let cache_url_source = convert_url_source(&temp_url_source)?;
Expand All @@ -421,6 +432,7 @@ async fn fetch_source(
&result.path,
&dest_dir,
Some(&file_name_string),
&temp_url_source.filter,
tool_configuration,
)?;
} else {
Expand Down
2 changes: 2 additions & 0 deletions crates/rattler_build_recipe/src/stage0/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@ impl Evaluate for Stage0GitSource {
.as_ref()
.map(|v| evaluate_string_value(v, context))
.transpose()?,
filter: evaluate_glob_vec(&self.filter, context)?,
})
}
}
Expand Down Expand Up @@ -2295,6 +2296,7 @@ impl Evaluate for Stage0UrlSource {
.map(|v| v.evaluate(context))
.transpose()?,
attestation,
filter: evaluate_glob_vec(&self.filter, context)?,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_build_recipe/src/stage0/parser/snapshot_tests.rs
assertion_line: 112
expression: "serde_yaml::to_string(&recipe).unwrap()"
---
schema_version: 1
Expand All @@ -14,6 +13,7 @@ source:
- url:
- https://github.com/example/project/archive/v${{ version }}.tar.gz
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
filter: []
build:
number: ${{ build_number }}
script: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_build_recipe/src/stage0/parser/snapshot_tests.rs
assertion_line: 104
expression: "serde_yaml::to_string(&recipe).unwrap()"
---
schema_version: 1
Expand All @@ -11,6 +10,7 @@ source:
- url:
- https://example.com/source.tar.gz
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
filter: []
build:
script: {}
python:
Expand Down Expand Up @@ -46,6 +46,7 @@ outputs:
- url:
- https://example.com/build-source.tar.gz
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
filter: []
requirements:
build:
- gcc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rattler_build_recipe/src/stage0/parser/snapshot_tests.rs
assertion_line: 136
expression: "serde_yaml::to_string(&recipe).unwrap()"
---
schema_version: 1
Expand All @@ -10,6 +9,7 @@ source:
- url:
- https://example.com/top-level-source.tar.gz
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
filter: []
build:
number: 0
script:
Expand Down
14 changes: 12 additions & 2 deletions crates/rattler_build_recipe/src/stage0/parser/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ fn parse_git_source(
let mut lfs = None;
let mut submodules = None;
let mut expected_commit = None;
let mut filter = IncludeExclude::default();

for (key_node, value_node) in mapping.iter() {
let key = key_node.as_str();
Expand Down Expand Up @@ -320,14 +321,17 @@ fn parse_git_source(
"expected_commit" => {
expected_commit = Some(parse_value(value_node)?);
}
"filter" => {
filter = parse_source_filter(value_node)?;
}
_ => {
return Err(ParseError::invalid_value(
"git source",
format!("unknown field '{}'", key),
*key_node.span(),
)
.with_suggestion(
"Valid fields are: git, rev, tag, branch, depth, patches, target_directory, lfs, submodules, expected_commit",
"Valid fields are: git, rev, tag, branch, depth, patches, target_directory, lfs, submodules, expected_commit, filter",
));
}
}
Expand Down Expand Up @@ -361,6 +365,7 @@ fn parse_git_source(
lfs,
submodules,
expected_commit,
filter,
})
}

Expand Down Expand Up @@ -417,6 +422,7 @@ fn parse_url_source(
let mut patches = ConditionalList::default();
let mut target_directory = None;
let mut attestation = None;
let mut filter = IncludeExclude::default();

for (key_node, value_node) in mapping.iter() {
let key = key_node.as_str();
Expand Down Expand Up @@ -458,14 +464,17 @@ fn parse_url_source(
));
}
}
"filter" => {
filter = parse_source_filter(value_node)?;
}
_ => {
return Err(ParseError::invalid_value(
"url source",
format!("unknown field '{}'", key),
*key_node.span(),
)
.with_suggestion(
"Valid fields are: url, sha256, md5, file_name, patches, target_directory, attestation",
"Valid fields are: url, sha256, md5, file_name, patches, target_directory, attestation, filter",
));
}
}
Expand All @@ -486,6 +495,7 @@ fn parse_url_source(
patches,
target_directory,
attestation,
filter,
})
}

Expand Down
12 changes: 12 additions & 0 deletions crates/rattler_build_recipe/src/stage0/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pub struct GitSource {
/// Optionally an expected commit hash to verify after checkout
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expected_commit: Option<Value<String>>,

/// Filter for files to include/exclude from the checked-out tree
#[serde(default)]
pub filter: IncludeExclude,
}

/// Attestation verification configuration
Expand Down Expand Up @@ -156,6 +160,10 @@ pub struct UrlSource {
/// Optional attestation verification configuration
#[serde(default, skip_serializing_if = "Option::is_none")]
pub attestation: Option<AttestationConfig>,

/// Filter for files to include/exclude from the extracted source
#[serde(default)]
pub filter: IncludeExclude,
}

/// A local path source
Expand Down Expand Up @@ -314,6 +322,7 @@ impl GitSource {
lfs,
submodules,
expected_commit,
filter,
} = self;

let mut vars = Vec::new();
Expand Down Expand Up @@ -344,6 +353,7 @@ impl GitSource {
if let Some(ec) = expected_commit {
vars.extend(ec.used_variables());
}
vars.extend(filter.used_variables());
vars.sort();
vars.dedup();
vars
Expand All @@ -361,6 +371,7 @@ impl UrlSource {
patches,
target_directory,
attestation,
filter,
} = self;

let mut vars = Vec::new();
Expand All @@ -386,6 +397,7 @@ impl UrlSource {
if let Some(attestation) = attestation {
vars.extend(attestation.used_variables());
}
vars.extend(filter.used_variables());
vars.sort();
vars.dedup();
vars
Expand Down
8 changes: 8 additions & 0 deletions crates/rattler_build_recipe/src/stage1/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub struct GitSource {
/// Optionally an expected commit hash to verify after checkout
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expected_commit: Option<String>,

/// Only take certain files from the checked-out tree (validated glob patterns)
#[serde(default, skip_serializing_if = "GlobVec::is_empty")]
pub filter: GlobVec,
}

fn is_false(value: &bool) -> bool {
Expand Down Expand Up @@ -323,6 +327,10 @@ pub struct UrlSource {
/// Optional attestation verification configuration
#[serde(default, skip_serializing_if = "attestation_is_none_or_empty")]
pub attestation: Option<AttestationConfig>,

/// Only take certain files from the extracted source (validated glob patterns)
#[serde(default, skip_serializing_if = "GlobVec::is_empty")]
pub filter: GlobVec,
}

/// A local path source (evaluated)
Expand Down
Loading
Loading