diff --git a/doc/flatpak-manifest.xml b/doc/flatpak-manifest.xml index 0796e4a6..73c3e9d0 100644 --- a/doc/flatpak-manifest.xml +++ b/doc/flatpak-manifest.xml @@ -257,11 +257,11 @@ (string) - Any desktop file with this name will be renamed to a name based on id during the cleanup phase. + Any desktop file with this name will be renamed to a name based on id during the cleanup phase. The appdata file launchable will be updated if needed. (string) - Any appdata (metainfo) file with this name will be renamed to a name based on id during the cleanup phase. + Any appdata (metainfo) file with this name will be renamed to a name based on id during the cleanup phase. The id in the file will be updated as needed and the subsequent provides. (since 1.4.1) (string) diff --git a/src/builder-manifest.c b/src/builder-manifest.c index b43b982d..27312714 100644 --- a/src/builder-manifest.c +++ b/src/builder-manifest.c @@ -2787,22 +2787,29 @@ builder_manifest_cleanup (BuilderManifest *self, } } - if (self->rename_desktop_file != NULL) + if (self->rename_desktop_file != NULL || self->rename_appdata_file != NULL) { - g_autoptr(GFile) applications_dir = g_file_resolve_relative_path (app_root, "share/applications"); - g_autoptr(GFile) src = g_file_get_child (applications_dir, self->rename_desktop_file); g_autofree char *desktop_basename = g_strdup_printf ("%s.desktop", self->id); - g_autoptr(GFile) dest = g_file_get_child (applications_dir, desktop_basename); + if (self->rename_desktop_file != NULL) + { + g_autoptr(GFile) applications_dir = g_file_resolve_relative_path (app_root, "share/applications"); + g_autoptr(GFile) src = g_file_get_child (applications_dir, self->rename_desktop_file); + g_autoptr(GFile) dest = g_file_get_child (applications_dir, desktop_basename); - g_print ("Renaming %s to %s\n", self->rename_desktop_file, desktop_basename); - if (!g_file_move (src, dest, 0, NULL, NULL, NULL, error)) - return FALSE; + g_print ("Renaming %s to %s\n", self->rename_desktop_file, desktop_basename); + if (!g_file_move (src, dest, 0, NULL, NULL, NULL, error)) + return FALSE; + } if (appdata_file != NULL) { FlatpakXml *n_id; FlatpakXml *n_root; FlatpakXml *n_text; + FlatpakXml *n_provides = NULL; + FlatpakXml *n_provides_id = NULL; + FlatpakXml *id_text = NULL; + g_autofree char *old_id = NULL; g_autoptr(FlatpakXml) xml_root = NULL; g_autoptr(GInputStream) in = NULL; g_autoptr(GString) new_contents = NULL; @@ -2827,13 +2834,24 @@ builder_manifest_cleanup (BuilderManifest *self, if (n_id) { n_text = n_id->first_child; - if (n_text && g_strcmp0 (n_text->text, self->rename_desktop_file) == 0) + if (n_text && g_strcmp0 (n_text->text, self->id) != 0) { - g_free (n_text->text); + old_id = g_steal_pointer (&n_text->text); n_text->text = g_strdup (self->id); } } + n_provides = flatpak_xml_find (n_root, "provides", NULL); + if (!n_provides) + { + n_provides = flatpak_xml_new ("provides"); + flatpak_xml_add (n_root, n_provides); + } + n_provides_id = flatpak_xml_new ("id"); + id_text = flatpak_xml_new_text (g_steal_pointer (&old_id)); + flatpak_xml_add (n_provides_id, id_text); + flatpak_xml_add (n_provides, n_provides_id); + /* replace any optional launchable */ n_id = flatpak_xml_find (n_root, "launchable", NULL); if (n_id) diff --git a/tests/Hello-desktop.appdata.xml b/tests/Hello-desktop.appdata.xml new file mode 100644 index 00000000..2e1a5ede --- /dev/null +++ b/tests/Hello-desktop.appdata.xml @@ -0,0 +1,16 @@ + + + Hello.desktop + CC0-1.0 + CC0-1.0 + + Hello + Hello test app + +

Just a test app

+
+ org.test.Hello2.desktop + + + +
diff --git a/tests/test-builder.sh b/tests/test-builder.sh index 33019eee..cd9d8ba0 100755 --- a/tests/test-builder.sh +++ b/tests/test-builder.sh @@ -23,7 +23,7 @@ set -euo pipefail skip_without_fuse -echo "1..6" +echo "1..7" setup_repo install_repo @@ -37,6 +37,7 @@ cd $TEST_DATA_DIR/ cp -a $(dirname $0)/test-configure . echo "version1" > app-data cp $(dirname $0)/test-rename.json . +cp $(dirname $0)/test-rename-appdata.json . cp $(dirname $0)/test.json . cp $(dirname $0)/test.yaml . cp $(dirname $0)/test-runtime.json . @@ -44,6 +45,7 @@ cp $(dirname $0)/0001-Add-test-logo.patch . cp $(dirname $0)/Hello.desktop . cp $(dirname $0)/Hello.xml . cp $(dirname $0)/Hello.appdata.xml . +cp $(dirname $0)/Hello-desktop.appdata.xml . cp $(dirname $0)/org.test.Hello.desktop . cp $(dirname $0)/org.test.Hello.xml . cp $(dirname $0)/org.test.Hello.appdata.xml . @@ -60,7 +62,7 @@ cp $(dirname $0)/source2.json include1/include2/ cp $(dirname $0)/data2 include1/include2/ cp $(dirname $0)/data2.patch include1/include2/ -for MANIFEST in test.json test.yaml test-rename.json ; do +for MANIFEST in test.json test.yaml test-rename.json test-rename-appdata.json ; do echo "building manifest $MANIFEST" >&2 ${FLATPAK_BUILDER} --repo=$REPO $FL_GPGARGS --force-clean appdir $MANIFEST >&2 @@ -79,6 +81,8 @@ for MANIFEST in test.json test.yaml test-rename.json ; do assert_has_file appdir/files/share/icons/hicolor/64x64/mimetypes/org.test.Hello2.application-x-goodbye.png assert_has_file appdir/files/share/applications/org.test.Hello2.desktop assert_has_file appdir/files/share/metainfo/org.test.Hello2.metainfo.xml + xmllint --noout appdir/files/share/metainfo/org.test.Hello2.metainfo.xml >&2 + grep -qs "org.test.Hello2" appdir/files/share/metainfo/org.test.Hello2.metainfo.xml assert_has_file appdir/files/share/mime/packages/org.test.Hello2.xml xmllint --noout appdir/files/share/mime/packages/org.test.Hello2.xml >&2 diff --git a/tests/test-rename-appdata.json b/tests/test-rename-appdata.json new file mode 100644 index 00000000..9169f312 --- /dev/null +++ b/tests/test-rename-appdata.json @@ -0,0 +1,117 @@ +{ + "app-id": "org.test.Hello2", + "runtime": "org.test.Platform", + "sdk": "org.test.Sdk", + "command": "hello2.sh", + "tags": ["test"], + "token-type": 0, + "finish-args": [ + "--share=network" + ], + "rename-icon": "Hello", + "rename-appdata-file": "Hello.appdata.xml", + "rename-mime-file": "Hello.xml", + "rename-mime-icons": [ + "application-x-hello", + "application-x-goodbye" + ], + "build-options" : { + "cflags": "-O2 -g", + "cxxflags": "-O2 -g", + "env": { + "FOO": "bar", + "V": "1" + } + }, + "cleanup": ["/cleanup", "*.cleanup"], + "cleanup-commands": [ "touch /app/cleaned_up" ], + "modules": [ + "include1/module1.json", + { + "name": "root", + "modules": [ + { + "name": "test", + "config-opts": ["--some-arg"], + "post-install": [ + "touch /app/bin/file.cleanup", + "mkdir -p /app/share/icons/hicolor/64x64/apps/", + "mkdir -p /app/share/icons/hicolor/64x64/mimetypes/", + "cp org.test.Hello.png /app/share/icons/hicolor/64x64/apps/Hello.png", + "cp org.test.Hello.png /app/share/icons/hicolor/64x64/mimetypes/application-x-hello.png", + "cp org.test.Hello.png /app/share/icons/hicolor/64x64/mimetypes/application-x-goodbye.png", + "mkdir -p /app/share/applications", + "cp org.test.Hello.desktop /app/share/applications/${FLATPAK_ID}.desktop", + "mkdir -p /app/share/mime/packages", + "cp Hello.xml /app/share/mime/packages/", + "mkdir -p /app/share/appdata", + "cp Hello-desktop.appdata.xml /app/share/appdata/Hello.appdata.xml" + ], + "make-args": ["BAR=2" ], + "make-install-args": ["BAR=3" ], + "build-commands": [ "echo foo > /app/out" ], + "sources": [ + { + "type": "file", + "path": "test-configure", + "dest-filename": "configure", + "sha256": "675a1ac2feec4d4f54e581b4b01bc3cfd2c1cf31aa5963574d31228c8a11b7e7" + }, + { + "type": "file", + "path": "app-data" + }, + { + "type": "file", + "path": "org.test.Hello.desktop" + }, + { + "type": "file", + "path": "Hello-desktop.appdata.xml" + }, + { + "type": "file", + "path": "Hello.xml" + }, + { + "type": "script", + "dest-filename": "hello2.sh", + "commands": [ "echo \"Hello world2, from a sandbox\"" ] + }, + { + "type": "shell", + "commands": [ + "mkdir /app/cleanup/", + "touch /app/cleanup/a_file" + ] + }, + { + "type": "patch", + "path": "0001-Add-test-logo.patch", + "use-git": true + } + ] + }, + { + "name": "test2", + "build-commands": [ + "echo foo2 > /app/out2", + "cp source[12] /app" + ], + "buildsystem": "simple", + "sources": [ + { + "type": "file", + "path": "app-data" + }, + "include1/source1.json", + "include1/include2/source2.json" + ] + }, + { + "name": "empty" + } + ] + } + ] +}