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..30f960e5 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; } @@ -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); 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/