From b5e215ac68c253b90b08742f0fa32b80130b500d Mon Sep 17 00:00:00 2001 From: bbhtt Date: Sat, 7 Mar 2026 12:14:33 +0530 Subject: [PATCH 1/2] builder-module: Record licence files in licences directory as well The licences directory is a common convention across Qt and KDE projects. See examples [1], [2], [3]. The files inside that directory usually use the licence id as their filename. Listing them individually inside licence-files key is annoying but without anything no licence information is recorded for these projects. So when collecting the default license files, also collect files inside the licences directory. [1]: https://github.com/qt/qtbase/tree/2d790125429123aec4fb3dbee8335732f2d122eb/LICENSES [2]: https://github.com/qt/qtwebengine/tree/cf5db2b9242facf4797a7779ae50916326f75d0b/LICENSES [3]: https://invent.kde.org/system/dolphin/-/tree/02165defeeeb529a566c8cc00f30e7a5c8c11185/LICENSES --- NEWS | 1 + src/builder-module.c | 45 ++++++++++++++++++++++++++++++++++ tests/test-builder.sh | 3 +++ tests/test-rename-appdata.json | 5 ++++ tests/test-rename.json | 5 ++++ tests/test.json | 5 ++++ tests/test.yaml | 5 +++- 7 files changed, 68 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 279715ee..b567c246 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ TBD * Prevent writing duplicate groups to metadata file * Disable all filesystem access in flatpak-builder --run sandbox * Add ability to set custom fusermount path +* Record licence files in licences directory Changes in 1.4.6 ================ diff --git a/src/builder-module.c b/src/builder-module.c index ea10095a..bb07d013 100644 --- a/src/builder-module.c +++ b/src/builder-module.c @@ -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, @@ -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) + { + g_propagate_error (error, g_steal_pointer (&subdir_error)); + return FALSE; + } + } + return TRUE; } diff --git a/tests/test-builder.sh b/tests/test-builder.sh index 16407856..61867c70 100755 --- a/tests/test-builder.sh +++ b/tests/test-builder.sh @@ -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 @@ -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 diff --git a/tests/test-rename-appdata.json b/tests/test-rename-appdata.json index 83650d8a..296440b0 100644 --- a/tests/test-rename-appdata.json +++ b/tests/test-rename-appdata.json @@ -77,6 +77,11 @@ "type": "file", "path": "LICENSE" }, + { + "type": "file", + "path": "LICENSES/CC0.txt", + "dest": "LICENSES" + }, { "type": "script", "dest-filename": "hello2.sh", diff --git a/tests/test-rename.json b/tests/test-rename.json index 6b171982..7e08970c 100644 --- a/tests/test-rename.json +++ b/tests/test-rename.json @@ -78,6 +78,11 @@ "type": "file", "path": "LICENSE" }, + { + "type": "file", + "path": "LICENSES/CC0.txt", + "dest": "LICENSES" + }, { "type": "script", "dest-filename": "hello2.sh", diff --git a/tests/test.json b/tests/test.json index 532a13d8..077f8c57 100644 --- a/tests/test.json +++ b/tests/test.json @@ -75,6 +75,11 @@ "type": "file", "path": "LICENSE" }, + { + "type": "file", + "path": "LICENSES/CC0.txt", + "dest": "LICENSES" + }, { "type": "shell", "commands": [ diff --git a/tests/test.yaml b/tests/test.yaml index 734523c8..3b06a83f 100644 --- a/tests/test.yaml +++ b/tests/test.yaml @@ -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 @@ -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/ From f5dcbae375f748275ede43059b42b473b1d491b0 Mon Sep 17 00:00:00 2001 From: bbhtt Date: Sat, 7 Mar 2026 12:21:47 +0530 Subject: [PATCH 2/2] builder-module: Include license-files in cache checksum Otherwise modifications to license-files would not invalidate the module cache. --- src/builder-module.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/builder-module.c b/src/builder-module.c index bb07d013..30f960e5 100644 --- a/src/builder-module.c +++ b/src/builder-module.c @@ -2442,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);