Skip to content

Commit

Permalink
fix: use license from recipe folder instead of erroring if both are f…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
wolfv committed Dec 9, 2024
1 parent b3f6bd2 commit 75402b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/reference/recipe_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ to directories with license information. Directory entries must end with a `/`
suffix (this is to lessen unintentional inclusion of non-license files; all the
directory's contents will be unconditionally and recursively added).

If a license file is found in both the source and recipe directories, the file from
the recipe directory is used (you should see a warning about this in the build log).

```yaml
about:
license_file:
Expand Down
21 changes: 17 additions & 4 deletions src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pub enum PackagingError {
}

/// This function copies the license files to the info/licenses folder.
/// License files are selected from the recipe directory and the source (work) folder.
/// If the same file is found in both locations, the file from the recipe directory is used.
fn copy_license_files(
output: &Output,
tmp_dir_path: &Path,
Expand All @@ -98,27 +100,38 @@ fn copy_license_files(
fs::create_dir_all(&licenses_folder)?;

let copy_dir = copy_dir::CopyDir::new(
&output.build_configuration.directories.recipe_dir,
&output.build_configuration.directories.work_dir,
&licenses_folder,
)
.with_globvec(&output.recipe.about().license_file)
.use_gitignore(false)
.run()?;

let copied_files_recipe_dir = copy_dir.copied_paths();
let copied_files_work_dir = copy_dir.copied_paths();
let any_include_matched_recipe_dir = copy_dir.any_include_glob_matched();

let copy_dir = copy_dir::CopyDir::new(
&output.build_configuration.directories.work_dir,
&output.build_configuration.directories.recipe_dir,
&licenses_folder,
)
.with_globvec(&output.recipe.about().license_file)
.use_gitignore(false)
.overwrite(true)
.run()?;

let copied_files_work_dir = copy_dir.copied_paths();
let copied_files_recipe_dir = copy_dir.copied_paths();
let any_include_matched_work_dir = copy_dir.any_include_glob_matched();

// if a file was copied from the recipe dir, and the work dir, we should
// issue a warning
for file in copied_files_recipe_dir {
if copied_files_work_dir.contains(&file) {

Check failure on line 128 in src/packaging.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

[clippy] reported by reviewdog 🐶 error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` Raw Output: src/packaging.rs:128:47:e:error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` __END__

Check failure on line 128 in src/packaging.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

[clippy] reported by reviewdog 🐶 error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` Raw Output: src/packaging.rs:128:47:e:error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` __END__

Check failure on line 128 in src/packaging.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

[clippy] reported by reviewdog 🐶 error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` Raw Output: src/packaging.rs:128:47:e:error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` __END__

Check failure on line 128 in src/packaging.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

[clippy] reported by reviewdog 🐶 error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` Raw Output: src/packaging.rs:128:47:e:error: this expression creates a reference which is immediately dereferenced by the compiler --> src/packaging.rs:128:47 | 128 | if copied_files_work_dir.contains(&file) { | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` __END__
let warn_str = format!("License file from source directory was overwritten by license file from recipe folder ({})", file.display());
tracing::warn!(warn_str);
output.record_warning(&warn_str);
}
}

let copied_files = copied_files_recipe_dir
.iter()
.chain(copied_files_work_dir)
Expand Down

0 comments on commit 75402b6

Please sign in to comment.