Skip to content

Commit

Permalink
fix: license from recipe folder instead of erroring if both are found (
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Dec 9, 2024
1 parent 2c7f0e9 commit 1d28667
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 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) {
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
10 changes: 3 additions & 7 deletions test/end-to-end/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,9 @@ def test_filter_files(

def test_double_license(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path):
path_to_recipe = recipes / "double_license"
args = rattler_build.build_args(
path_to_recipe,
tmp_path,
)
# make sure that two license files in $SRC_DIR and $RECIPE_DIR raise an exception
with pytest.raises(CalledProcessError):
rattler_build(*args)
args = rattler_build.build_args(path_to_recipe, tmp_path)
output = rattler_build(*args, stderr=STDOUT)
assert "warning License file from source directory was overwritten" in output


@pytest.mark.skipif(
Expand Down

0 comments on commit 1d28667

Please sign in to comment.