From: John Stebbins Date: Wed, 6 Jun 2018 23:20:34 +0000 (-0700) Subject: scripts: add script for creating flatpak manifests X-Git-Tag: 1.1.1~3^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f59f31f26ea461e502e6644390a15719982a4e20;p=handbrake scripts: add script for creating flatpak manifests This script can generate manifests that are suitable for submitting to flathub for publishing to their repository. It can also be used for generating manifests suitable for building local flatpak bundles and is used during 'make pkg.create.flatpak' (cherry picked from commit 93a153eee436a5ca71561dd40c4f128e51e4d47a) --- diff --git a/make/include/contrib.defs b/make/include/contrib.defs index 26c2248da..f2138c4af 100644 --- a/make/include/contrib.defs +++ b/make/include/contrib.defs @@ -9,6 +9,11 @@ CONTRIB.spec = $(if $(filter 1,$(BUILD.cross)),$(HOST.spec)) ## $(1) = module name (uppercase) ## define import.CONTRIB.defs + ## + ## keep a list of the enabled contrib packages + ## + CONTRIBS += $(1) + ## ## import gcc/g++ support mainly so we can force contrib choice of ## gcc executable, and debug/optimization flags. diff --git a/pkg/linux/flatpak/fr.handbrake.HandBrakeCLI.json b/pkg/linux/flatpak/fr.handbrake.HandBrakeCLI.json index ae64f64f5..5acef796f 100644 --- a/pkg/linux/flatpak/fr.handbrake.HandBrakeCLI.json +++ b/pkg/linux/flatpak/fr.handbrake.HandBrakeCLI.json @@ -5,9 +5,7 @@ "sdk": "org.gnome.Sdk", "command": "HandBrakeCLI", "finish-args": [ - /* Needs video */ "--filesystem=xdg-videos", - /* Home */ "--filesystem=home" ], "modules": [ diff --git a/pkg/linux/flatpak/fr.handbrake.ghb.json b/pkg/linux/flatpak/fr.handbrake.ghb.json index 0b5aea05f..27947def0 100644 --- a/pkg/linux/flatpak/fr.handbrake.ghb.json +++ b/pkg/linux/flatpak/fr.handbrake.ghb.json @@ -5,16 +5,11 @@ "sdk": "org.gnome.Sdk", "command": "ghb", "finish-args": [ - /* X11 + XShm access */ "--share=ipc", "--socket=x11", - /* Wayland access */ "--socket=wayland", - /* Needed for dconf to work */ "--filesystem=xdg-run/dconf", "--filesystem=~/.config/dconf:ro", "--talk-name=ca.desrt.dconf", "--env=DCONF_USER_CONFIG_DIR=.config/dconf", - /* Needs video */ "--filesystem=xdg-videos", - /* Home */ "--filesystem=home" ], "modules": [ diff --git a/pkg/linux/module.defs b/pkg/linux/module.defs index ad4f559bc..b17aaa377 100644 --- a/pkg/linux/module.defs +++ b/pkg/linux/module.defs @@ -18,6 +18,15 @@ ifneq ($(PGP_ID),) PGPSIGN = --gpg-sign=$(PGP_ID) endif +ifneq ($(FP_RUNTIME),) + FPRUNTIME = -r $(FP_RUNTIME) +endif + +ifneq ($(HB_URL),) +ifneq ($(HB_SHA256),) + FLATHUB_MANIFEST = $(PKG.gui.flathub.manifest) $(PKG.cli.flathub.manifest) +endif +endif ############################################################################### @@ -48,8 +57,8 @@ PKG.rpm.stamp = $(PKG.out/).rpm.stamp PKG.out.flatpak/ = $(PKG.out/)flatpak/ STAGE.out.flatpak/ = $(STAGE.out/)flatpak/ -PKG.src.flatpak = $(STAGE.out.flatpak/)handbrake.tar.bz2 -PKG.contrib.flatpak = $(STAGE.out.flatpak/)download.tgz +PKG.gui.flathub.manifest = $(PKG.out.flatpak/)/fr.handbrake.ghb.json +PKG.cli.flathub.manifest = $(PKG.out.flatpak/)/fr.handbrake.HandBrakeCLI.json PKG.gui.manifest.flatpak = $(PKG.flatpak/)fr.handbrake.ghb.json PKG.cli.manifest.flatpak = $(PKG.flatpak/)fr.handbrake.HandBrakeCLI.json PKG.gui.build.flatpak = $(STAGE.out.flatpak/)$(HB.name)-$(HB.version)-$(BUILD.machine).build diff --git a/pkg/linux/module.rules b/pkg/linux/module.rules index 2fa676087..bca2d8c81 100644 --- a/pkg/linux/module.rules +++ b/pkg/linux/module.rules @@ -1,4 +1,5 @@ -pkg.create.flatpak:: contrib.fetch $(PKG.gui.flatpak) $(PKG.cli.flatpak) +pkg.create.flatpak:: contrib.fetch $(PKG.gui.flatpak) $(PKG.cli.flatpak) $(FLATHUB_MANIFEST) +pkg.create.flathub:: $(FLATHUB_MANIFEST) pkg.create.deb:: $(PKG.gui.deb) $(PKG.cli.deb) pkg.create.rpm:: $(PKG.rpm.stamp) pkg.create.src.deb:: $(PKG.src.deb.stamp) @@ -9,7 +10,6 @@ DEBIAN_CHANGELOG_DATE = $(shell date -R) # # CLI Tar Package # - $(PKG.cli.tar): | $(dir $(PKG.cli.tar)) $(PKG.cli.tar): | $(STAGE.out.cli/) cd $(STAGE.out.cli/) && $(TAR.exe) cjf $(call fn.ABSOLUTE,$(PKG.cli.tar)) . @@ -61,32 +61,23 @@ $(PKG.rpm.stamp): $(PKG.native.rpm.stamp) # # Flatpak binary package rules # -$(PKG.src.flatpak): $(PKG.src.tar.bz2) - $(MKDIR.exe) -p $(STAGE.out.flatpak/) - -$(RM.exe) -rf $(BUILD/).flatpak-builder - $(CP.exe) $(PKG.src.tar.bz2) $(PKG.src.flatpak) +$(PKG.gui.flathub.manifest): + $(SRC/)scripts/create_flatpak_manifest.py -a "$(HB_URL)" -s "$(HB_SHA256)" -t $(PKG.gui.manifest.flatpak) $(foreach m,$(CONTRIBS),-c "$(word 1,$($m.FETCH.url))" -s "$(word 1,$($m.FETCH.sha256))") $(FPRUNTIME) $(PKG.gui.flathub.manifest) -$(PKG.contrib.flatpak): - $(MKDIR.exe) -p $(STAGE.out.flatpak/) - $(TAR.exe) -C $(SRC/) -czf $(PWD)/$(PKG.contrib.flatpak) download +$(PKG.cli.flathub.manifest): + $(SRC/)scripts/create_flatpak_manifest.py -a "$(HB_URL)" -s "$(HB_SHA256)" -t $(PKG.cli.manifest.flatpak) $(foreach m,$(CONTRIBS),-c "$(word 1,$($m.FETCH.url))" -s "$(word 1,$($m.FETCH.sha256))") $(FPRUNTIME) $(PKG.cli.flathub.manifest) -$(PKG.gui.flatpak): GNUmakefile $(PKG.src.flatpak) $(PKG.contrib.flatpak) - make contrib.fetch +$(PKG.gui.flatpak): GNUmakefile $(PKG.src.tar.bz2) + $(MKDIR.exe) -p $(STAGE.out.flatpak/) $(MKDIR.exe) -p $(PKG.out.flatpak/) - # Relative paths in the manifest are relative to the location - # of the manifest. So put it where we have staged the files that - # it needs. - $(CP.exe) $(PKG.gui.manifest.flatpak) $(STAGE.out.flatpak/)fr.handbrake.ghb.json + $(SRC/)scripts/create_flatpak_manifest.py -a "$(abspath $(PKG.src.tar.bz2))" -t $(PKG.gui.manifest.flatpak) $(foreach m,$(CONTRIBS),-c "$(abspath $(CONTRIB.download/)$($m.FETCH.basename))") $(STAGE.out.flatpak/)fr.handbrake.ghb.json flatpak-builder --force-clean $(PGPSIGN) --repo=$(PKG.repo.flatpak) $(PKG.gui.build.flatpak) $(STAGE.out.flatpak/)fr.handbrake.ghb.json flatpak build-bundle $(PKG.repo.flatpak) $(PKG.gui.flatpak) fr.handbrake.ghb -$(PKG.cli.flatpak): GNUmakefile $(PKG.src.flatpak) $(PKG.contrib.flatpak) - make contrib.fetch +$(PKG.cli.flatpak): GNUmakefile $(PKG.src.tar.bz2) + $(MKDIR.exe) -p $(STAGE.out.flatpak/) $(MKDIR.exe) -p $(PKG.out.flatpak/) - # Relative paths in the manifest are relative to the location - # of the manifest. So put it where we have staged the files that - # it needs. - $(CP.exe) $(PKG.cli.manifest.flatpak) $(STAGE.out.flatpak/)fr.handbrake.HandBrakeCLI.json + $(SRC/)scripts/create_flatpak_manifest.py -a "$(abspath $(PKG.src.tar.bz2))" -t $(PKG.cli.manifest.flatpak) $(foreach m,$(CONTRIBS),-c "$(abspath $(CONTRIB.download/)$($m.FETCH.basename))") $(STAGE.out.flatpak/)fr.handbrake.HandBrakeCLI.json flatpak-builder --force-clean $(PGPSIGN) --repo=$(PKG.repo.flatpak) $(PKG.cli.build.flatpak) $(STAGE.out.flatpak/)fr.handbrake.HandBrakeCLI.json flatpak build-bundle $(PKG.repo.flatpak) $(PKG.cli.flatpak) fr.handbrake.HandBrakeCLI diff --git a/scripts/create_flatpak_manifest.py b/scripts/create_flatpak_manifest.py new file mode 100755 index 000000000..537191923 --- /dev/null +++ b/scripts/create_flatpak_manifest.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python + +import types +import os +import sys +import json +import getopt +import posixpath +try: + from urlparse import urlsplit + from urllib import unquote +except ImportError: # Python 3 + from urllib.parse import urlsplit, unquote + + +def url2filename(url): + path = urlsplit(url).path + return posixpath.basename(unquote(path)) + +def islocal(url): + result = urlsplit(url) + return result.scheme == "" and result.netloc == "" + +class SourceType: + contrib = 1 + archive = 2 + +class SourceEntry: + def __init__(self, url, entry_type, sha256=None): + self.url = url + self.entry_type = entry_type + self.sha256 = sha256 + +class FlatpakManifest: + def __init__(self, source_list, runtime, template=None): + if template != None: + with open(template, 'r') as fp: + self.manifest = json.load(fp) + + self.finish_args = self.manifest["finish-args"] + self.modules = self.manifest["modules"] + self.hbmodule = self.modules[0] + self.sources = [None] * 2 + + self.hbmodule["sources"] = self.sources + else: + self.manifest = {} + self.finish_args = [] + self.modules = [] + self.hbmodule = {} + self.sources = [None] * 2 + + self.manifest["finish-args"] = self.finish_args + self.manifest["modules"] = self.modules + self.modules[0] = self.hbmodule + self.hbmodule["sources"] = self.sources + + self.manifest["runtime-version"] = runtime + + # create "shell" source to 'mkdir download' + source = {} + source["type"] = "shell" + source["commands"] = [ "mkdir -p download" ] + self.sources[1] = source + + handbrake_found = False + for key, value in source_list.items(): + source = {} + if islocal(value.url): + source["path"] = value.url + else: + if value.sha256 == "" or value.sha256 == None: + continue + source["url"] = value.url + source["sha256"] = value.sha256 + + if value.entry_type == SourceType.archive: + if handbrake_found: + print "Error: only one archive source permitted" + sys.exit(3) + + source["type"] = "archive" + source["strip-components"] = 1 + self.sources[0] = source + handbrake_found = True + + elif value.entry_type == SourceType.contrib: + source["type"] = "file" + source["dest-filename"] = "download/" + url2filename(value.url) + self.sources.append(source) + + +def usage(): + print "create_flatpak_manifest [-a ] [-c ] [-s ] [-t