Skip to content

Commit

Permalink
Support dynamic export path into scripts
Browse files Browse the repository at this point in the history
When flatpak-builder is running under flatpak, its
path will be /app/bin/flatpak. This path must not
be in export scripts or desktop file. This change
makes it possible for flatpak-builder flatpak to
tell flatpak what it should write to generated
files
  • Loading branch information
nanonyme authored and alexlarsson committed Sep 10, 2021
1 parent 4aa3952 commit a99b748
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions common/flatpak-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7009,6 +7009,7 @@ export_desktop_file (const char *app,
g_autofree char *escaped_branch = maybe_quote (branch);
g_autofree char *escaped_arch = maybe_quote (arch);
int i;
const char *flatpak;

if (!flatpak_openat_noatime (parent_fd, name, &desktop_fd, cancellable, error))
return FALSE;
Expand Down Expand Up @@ -7129,8 +7130,12 @@ export_desktop_file (const char *app,
g_key_file_remove_key (keyfile, groups[i], "X-GNOME-Bugzilla-ExtraInfoScript", NULL);

new_exec = g_string_new ("");
if ((flatpak = g_getenv ("FLATPAK_BINARY")) == NULL)
flatpak = FLATPAK_BINDIR "/flatpak";

g_string_append_printf (new_exec,
FLATPAK_BINDIR "/flatpak run --branch=%s --arch=%s",
"%s run --branch=%s --arch=%s",
flatpak,
escaped_branch,
escaped_arch);

Expand Down Expand Up @@ -8143,6 +8148,7 @@ flatpak_dir_deploy (FlatpakDir *self,
g_autoptr(GFile) metadata_file = NULL;
g_autofree char *metadata_contents = NULL;
gboolean is_oci;
const char *flatpak;

if (!flatpak_dir_ensure_repo (self, cancellable, error))
return FALSE;
Expand Down Expand Up @@ -8452,9 +8458,11 @@ flatpak_dir_deploy (FlatpakDir *self,
cancellable,
error))
return FALSE;
if ((flatpak = g_getenv ("FLATPAK_BINARY")) == NULL)
flatpak = FLATPAK_BINDIR "/flatpak";

bin_data = g_strdup_printf ("#!/bin/sh\nexec %s/flatpak run --branch=%s --arch=%s %s \"$@\"\n",
FLATPAK_BINDIR, escaped_branch, escaped_arch, escaped_app);
bin_data = g_strdup_printf ("#!/bin/sh\nexec %s run --branch=%s --arch=%s %s \"$@\"\n",
flatpak, escaped_branch, escaped_arch, escaped_app);
if (!g_file_replace_contents (wrapper, bin_data, strlen (bin_data), NULL, FALSE,
G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error))
return FALSE;
Expand Down

0 comments on commit a99b748

Please sign in to comment.