Skip to content

Commit

Permalink
manifest: Properly change the app id in the appstream file
Browse files Browse the repository at this point in the history
Also update the `provides` if necessary.

Issue #90

Signed-off-by: Hubert Figuière <[email protected]>
  • Loading branch information
hfiguiere authored and TingPing committed Jan 22, 2024
1 parent 64bc5fb commit 63905e5
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doc/flatpak-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@
</varlistentry>
<varlistentry>
<term><option>rename-desktop-file</option> (string)</term>
<listitem><para>Any desktop file with this name will be renamed to a name based on id during the cleanup phase.</para></listitem>
<listitem><para>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.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>rename-appdata-file</option> (string)</term>
<listitem><para>Any appdata (metainfo) file with this name will be renamed to a name based on id during the cleanup phase.</para></listitem>
<listitem><para>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)</para></listitem>
</varlistentry>
<varlistentry>
<term><option>rename-mime-file</option> (string)</term>
Expand Down
36 changes: 27 additions & 9 deletions src/builder-manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/Hello-desktop.appdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>Hello.desktop</id>
<metadata_license>CC0-1.0</metadata_license>
<project_license>CC0-1.0</project_license>
<content_rating type="oars-1.1" />
<name>Hello</name>
<summary>Hello test app</summary>
<description>
<p>Just a test app</p>
</description>
<launchable type="desktop-id">org.test.Hello2.desktop</launchable>
<releases>
<release version="2024.01.20" date="2024-01-20" />
</releases>
</component>
8 changes: 6 additions & 2 deletions tests/test-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set -euo pipefail

skip_without_fuse

echo "1..6"
echo "1..7"

setup_repo
install_repo
Expand All @@ -37,13 +37,15 @@ 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 .
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 .
Expand All @@ -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

Expand All @@ -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 "<id>org.test.Hello2</id>" 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
Expand Down
117 changes: 117 additions & 0 deletions tests/test-rename-appdata.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}

0 comments on commit 63905e5

Please sign in to comment.