]> granicus.if.org Git - handbrake/commitdiff
scripts: add script for creating flatpak manifests
authorJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 6 Jun 2018 23:20:34 +0000 (16:20 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 14 Jun 2018 20:51:08 +0000 (13:51 -0700)
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)

make/include/contrib.defs
pkg/linux/flatpak/fr.handbrake.HandBrakeCLI.json
pkg/linux/flatpak/fr.handbrake.ghb.json
pkg/linux/module.defs
pkg/linux/module.rules
scripts/create_flatpak_manifest.py [new file with mode: 0755]

index 26c2248da9c896d1b531599dedf66b0940db7aca..f2138c4afb173147b5f1ead6985857c895273b8b 100644 (file)
@@ -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.
index ae64f64f5d9e1ff83d8693ce2effd8c62b8f94c7..5acef796f9df902361e5eb2add6bc57fe9290f06 100644 (file)
@@ -5,9 +5,7 @@
     "sdk": "org.gnome.Sdk",
     "command": "HandBrakeCLI",
     "finish-args": [
-        /* Needs video */
         "--filesystem=xdg-videos",
-        /* Home */
         "--filesystem=home"
     ],
     "modules": [
index 0b5aea05f11bd3535c7608801d6a889dc417ee99..27947def07efee6dd18e6e6aae81774f713f0156 100644 (file)
@@ -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": [
index ad4f559bc8f9a03badf441766ece1b459001b18b..b17aaa3772975ca509893e61fe203de34a3999e4 100644 (file)
@@ -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
index 2fa676087c5b5daef8e22c18c487672b80c957ec..bca2d8c81e351e83cec2341cd0b5b3371fd962cd 100644 (file)
@@ -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 (executable)
index 0000000..5371919
--- /dev/null
@@ -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 <archive>] [-c <contrib>] [-s <sha265>] [-t <template>] [-r <sdk-runtime-version] [-h] [<dst>]"
+    print "     -a --archive    - Main archive (a.k.a. HB sources)"
+    print "     -c --contrib    - Contrib download URL (can be repeated)"
+    print "     -s --sha256     - sha256 of previous file on command line"
+    print "     -t --template   - Flatpak manifest template"
+    print "     -r --runtime    - Flatpak SDK runtime version"
+    print "     -h --help       - Show this message"
+
+if __name__ == "__main__":
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "a:c:s:t:r:h",
+            ["archive=", "contrib=", "sha265=",
+             "template=", "runtime=", "help"])
+    except getopt.GetoptError:
+        print "Error: Invalid option"
+        usage()
+        sys.exit(2)
+
+    if len(args) > 1:
+        usage()
+        exit(2)
+
+    source_list = {}
+    current_source = None
+    runtime = "3.28"
+    for opt, arg in opts:
+        if opt in ("-h", "--help"):
+            usage()
+            sys.exit()
+        elif opt in ("-a", "--archive"):
+            if arg != None and arg != "":
+                current_source = arg
+                source_list[arg] = SourceEntry(arg, SourceType.archive)
+            else:
+                current_source = None
+        elif opt in ("-c", "--contrib"):
+            if arg != None and arg != "":
+                current_source = arg
+                source_list[arg] = SourceEntry(arg, SourceType.contrib)
+            else:
+                current_source = None
+        elif opt in ("-s", "--sha256"):
+            if current_source != None:
+                source_list[current_source].sha256 = arg
+        elif opt in ("-t", "--template"):
+            template = arg
+        elif opt in ("-r", "--runtime"):
+            runtime = arg
+
+    if len(args) > 0:
+        dst = args[0]
+    else:
+        dst = None
+
+    manifest = FlatpakManifest(source_list, runtime, template)
+    if dst != None:
+        with open(dst, 'w') as fp:
+            json.dump(manifest.manifest, fp, ensure_ascii=False, indent=4)
+    else:
+        print json.dumps(manifest.manifest, ensure_ascii=False, indent=4)
+