Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TBD
* Add ability to set custom fusermount path
* Support setting state-dir for run
* Default to builddir true for cmake and cmake-ninja buildsystems
* Record licence files in licences directory

Changes in 1.4.6
================
Expand Down
46 changes: 46 additions & 0 deletions src/builder-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,14 @@ static const char *default_licence_file_patterns[] = {
NULL
};

static const char *license_dir_names[] = {
"LICENCES",
"LICENSES",
"licences",
"licenses",
NULL
};

static gboolean
find_default_license_files (BuilderModule *self,
GFile *source_dir,
Expand Down Expand Up @@ -1624,6 +1632,43 @@ find_default_license_files (BuilderModule *self,
return FALSE;
}

for (size_t i = 0; license_dir_names[i] != NULL; i++)
{
g_autoptr(GFile) license_dir = g_file_get_child (source_dir, license_dir_names[i]);
g_autoptr(GFileEnumerator) subdir_enum = NULL;
GFileInfo *next;
g_autoptr(GError) subdir_error = NULL;

if (g_file_query_file_type (license_dir,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL) != G_FILE_TYPE_DIRECTORY)
continue;

subdir_enum = g_file_enumerate_children (license_dir, "standard::name,standard::type",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, NULL);
if (subdir_enum == NULL)
continue;

while ((next = g_file_enumerator_next_file (subdir_enum, NULL, &subdir_error)))
{
g_autoptr(GFileInfo) sub_info = next;
g_autoptr(GFile) license_file = NULL;

if (g_file_info_get_file_type (sub_info) != G_FILE_TYPE_REGULAR)
continue;

license_file = g_file_enumerator_get_child (subdir_enum, sub_info);
g_ptr_array_add (files, g_steal_pointer (&license_file));
}

if (subdir_error != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering about the error handling here a bit because this early return means we won't always try to find all the files if an error occurs in one subdir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to skip and warn, i don't find failures in the default case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think the right way to handle errors is to bail out as early as possible. The loop above does it as well. The code here just ignores a bunch of errors and now warns instead of erroring out. Maybe it makes sense to combine both loops (we iterate through all files anyway) which should reduce the error conditions and then early exit as soon as the subdir iter goes wrong?

{
g_warning ("Failed to enumerate license directory: %s", subdir_error->message);
g_clear_error (&subdir_error);
}
}

return TRUE;
}

Expand Down Expand Up @@ -2397,6 +2442,7 @@ builder_module_checksum (BuilderModule *self,
builder_cache_checksum_str (cache, self->buildsystem);
builder_cache_checksum_str (cache, self->install_rule);
builder_cache_checksum_compat_boolean (cache, self->run_tests);
builder_cache_checksum_compat_strv (cache, self->license_files);

if (self->build_options)
builder_options_checksum (self->build_options, cache, context);
Expand Down
3 changes: 3 additions & 0 deletions tests/test-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ cp $(dirname $0)/source2.json include1/include2/
cp $(dirname $0)/data2 include1/include2/
cp $(dirname $0)/data2.patch include1/include2/
echo "MY LICENSE" > ./LICENSE
mkdir LICENSES
echo "MY DIR LICENSE" > ./LICENSES/CC0.txt

for MANIFEST in test.json test.yaml test-rename.json test-rename-appdata.json ; do
echo "building manifest $MANIFEST" >&2
Expand Down Expand Up @@ -105,6 +107,7 @@ for MANIFEST in test.json test.yaml test-rename.json test-rename-appdata.json ;
assert_file_has_content hello_out2 '^Hello world2, from a sandbox$'

assert_file_has_content appdir/files/share/licenses/org.test.Hello2/test/LICENSE '^MY LICENSE$'
assert_file_has_content appdir/files/share/licenses/org.test.Hello2/test/CC0.txt '^MY DIR LICENSE$'

echo "ok build"
done
Expand Down
5 changes: 5 additions & 0 deletions tests/test-rename-appdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
"type": "file",
"path": "LICENSE"
},
{
"type": "file",
"path": "LICENSES/CC0.txt",
"dest": "LICENSES"
},
{
"type": "script",
"dest-filename": "hello2.sh",
Expand Down
5 changes: 5 additions & 0 deletions tests/test-rename.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
"type": "file",
"path": "LICENSE"
},
{
"type": "file",
"path": "LICENSES/CC0.txt",
"dest": "LICENSES"
},
{
"type": "script",
"dest-filename": "hello2.sh",
Expand Down
5 changes: 5 additions & 0 deletions tests/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"type": "file",
"path": "LICENSE"
},
{
"type": "file",
"path": "LICENSES/CC0.txt",
"dest": "LICENSES"
},
{
"type": "shell",
"commands": [
Expand Down
5 changes: 4 additions & 1 deletion tests/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ modules:
make-args: [BAR=2]
make-install-args: [BAR=3]
build-commands: ['echo foo > /app/out']
license-files: ['mytest/LICENSE']
license-files: ['mytest/LICENSE', 'LICENSES/CC0.txt']
sources:
- type: file
path: test-configure
Expand All @@ -56,6 +56,9 @@ modules:
- type: file
path: LICENSE
dest: mytest
- type: file
path: LICENSES/CC0.txt
dest: LICENSES
- type: shell
commands:
- mkdir /app/cleanup/
Expand Down