Skip to content

Commit

Permalink
flatpak: Allow to specify #!BuildVersion
Browse files Browse the repository at this point in the history
The downloadable files need to have versions, but flatpak
manifests don't have version fields.
  • Loading branch information
perlpunk committed Jan 19, 2021
1 parent 3ae1b18 commit fdc95d3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
32 changes: 30 additions & 2 deletions Build/Flatpak.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,30 @@ sub _load_yaml_file {
sub parse {
my ($cf, $fn) = @_;

my $version = '';
my $data;
my @lines;
if (ref($fn) eq 'SCALAR') {
@lines = split m/(?<=\n)/, $$fn;
}
else {
open my $fh, '<', $fn or return { error => "Failed to open file '$fn'" };
@lines = <$fh>;
close $fh;
}

for my $line (@lines) {
if ($line =~ m/^#!BuildVersion: (\S+)/) {
my $string = $1;
if ($string =~ m/^[0-9.]+$/) {
$version = $string;
}
else {
return { error => "Invalid BuildVersion" };
}
}
}

if ($fn =~ m/\.ya?ml\z/) {
$data = _load_yaml_file($fn);
return { error => "Failed to parse YAML file '$fn'" } unless defined $data;
Expand All @@ -84,8 +107,8 @@ sub parse {
}

my $ret = {};
$ret->{version} = $version if $version;
$ret->{name} = $data->{'app-id'} or die "Flatpak file is missing 'app-id'";
$ret->{version} = $data->{version} || "0";
my $runtime = $data->{runtime};
my $runtime_version = $data->{'runtime-version'};
my $sdk = $data->{sdk};
Expand Down Expand Up @@ -122,7 +145,12 @@ sub show {
my $d = parse($cf, $fn);
die "$d->{error}\n" if $d->{error};
my $value = $d->{ $field };
print "$value\n";
if (ref $value eq 'ARRAY') {
print "$_\n" for @$value;
}
else {
print "$value\n";
}
}

1;
3 changes: 3 additions & 0 deletions build-recipe-flatpak
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ recipe_build_flatpak() {

local FLATPAK_FILE="$TOPDIR/SOURCES/$RECIPEFILE"
local FLATPAK_APP=$(perl -I$BUILD_DIR -MBuild::Flatpak -e 'Build::Flatpak::show' -- "$BUILD_ROOT$FLATPAK_FILE" name)
local FLATPAK_APP_VERSION=$(perl -I$BUILD_DIR -MBuild::Flatpak -e 'Build::Flatpak::show' -- "$BUILD_ROOT$FLATPAK_FILE" version)
FLATPAK_APP_VERSION="${FLATPAK_APP_VERSION:-0}"
local FLATPAK_REPO=/tmp/flatpakrepo
local FLATPAK_REMOTE=https://dl.flathub.org/repo/flathub.flatpakrepo
export FLATPAK_REPO
export FLATPAK_REMOTE
export FLATPAK_APP
export FLATPAK_APP_VERSION
export FLATPAK_FILE
export TOPDIR

Expand Down
4 changes: 2 additions & 2 deletions call-flatpak-builder
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ test -e "$BUILD_ROOT/proc/self" || mount -n -tproc none $BUILD_ROOT/proc
set -x

# Build into repo
chroot "$BUILD_ROOT" bash -c "cd /usr/src/packages/FLATPAK_ROOT && flatpak-builder --force-clean --repo=$FLATPAK_REPO build-dir $FLATPAK_FILE"
chroot "$BUILD_ROOT" bash -c "cd /usr/src/packages/FLATPAK_ROOT && flatpak-builder --default-branch=$FLATPAK_APP_VERSION --force-clean --repo=$FLATPAK_REPO build-dir $FLATPAK_FILE"

# Create bundle from repo
chroot "$BUILD_ROOT" bash -c "flatpak build-bundle --runtime-repo=$FLATPAK_REMOTE $FLATPAK_REPO $TOPDIR/OTHER/$FLATPAK_APP.flatpak $FLATPAK_APP"
chroot "$BUILD_ROOT" bash -c "flatpak build-bundle --runtime-repo=$FLATPAK_REMOTE $FLATPAK_REPO $TOPDIR/OTHER/$FLATPAK_APP-$FLATPAK_APP_VERSION.flatpak $FLATPAK_APP $FLATPAK_APP_VERSION"

1 change: 1 addition & 0 deletions t/data/flatpak.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!BuildVersion: 3.36.2
{
"app-id": "org.gnome.Chess",
"runtime": "org.gnome.Platform",
Expand Down
1 change: 1 addition & 0 deletions t/data/flatpak.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!BuildVersion: 3.36.2
---
app-id: org.gnome.Chess
runtime: org.gnome.Platform
Expand Down
7 changes: 6 additions & 1 deletion t/flatpak.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sub capture_stdout {
subtest parse => sub {
my $expected = {
name => 'org.gnome.Chess',
version => 0,
version => '3.36.2',
sources => [
"phalanx-XXV-source.tgz",
"stockfish-10-src.zip",
Expand All @@ -49,11 +49,16 @@ subtest show => sub {
local @ARGV = ("$path/flatpak.yaml", 'name');
my $data = capture_stdout(sub { Build::Flatpak::show() });
is $data, "org.gnome.Chess\n", 'Build::Flatpak::show name';

@ARGV = ("$path/flatpak.yaml", 'sources');
$data = capture_stdout(sub { Build::Flatpak::show() });
is $data, "phalanx-XXV-source.tgz\nstockfish-10-src.zip\ngnuchess-6.2.5.tar.gz\ngnome-chess-3.36.1.tar.xz\n", 'Build::Flatpak::show sources';
};

done_testing;

__DATA__
#!BuildVersion: 3.36.2
{
"app-id": "org.gnome.Chess",
"runtime": "org.gnome.Platform",
Expand Down

0 comments on commit fdc95d3

Please sign in to comment.