From b3e8ea2a82d132ddcfad8f9e77ab50dbd5ceecea Mon Sep 17 00:00:00 2001 From: makeworld Date: Mon, 27 Dec 2021 00:40:55 -0500 Subject: [PATCH] Initial work on Flatpak for #165 --- .gitignore | 5 ++ Makefile | 2 +- flatpak-go-get-generator.py | 92 +++++++++++++++++++++++++++++++++++++ space.makeworld.amfora.yml | 32 +++++++++++++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 flatpak-go-get-generator.py create mode 100644 space.makeworld.amfora.yml diff --git a/.gitignore b/.gitignore index dceeb46..5cf9a59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# Flatpak +build-dir +.flatpak-builder + + # Binaries amfora amfora.exe diff --git a/Makefile b/Makefile index 4220d7e..b0bd32f 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ VERSION ?= $(GITV) COMMIT ?= $(GITC) BUILDER ?= Makefile -GO := go +GO ?= go INSTALL := install RM := rm diff --git a/flatpak-go-get-generator.py b/flatpak-go-get-generator.py new file mode 100644 index 0000000..7597312 --- /dev/null +++ b/flatpak-go-get-generator.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# Copyright 2018 Çağatay Yiğit Şahin +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +from pathlib import Path +from typing import List, Dict +import subprocess +import argparse +import json + +def is_git_repository(p): + is_git_repo = p.is_dir() and (p / ".git").is_dir() + return is_git_repo + +def repo_paths(build_dir: Path) -> List[Path]: + src_dir = build_dir / 'src' + repo_paths: List[Path] = [] + + domains = src_dir.iterdir() + for domain in domains: + domain_users = domain.iterdir() + for user in domain_users: + if is_git_repository(user): + repo_paths.append(user) + else: + user_repos = user.iterdir() + for ur in user_repos: + if is_git_repository(ur): + repo_paths.append(ur) + return repo_paths + +def repo_source(repo_path: Path) -> Dict[str, str]: + def current_commit(repo_path: Path) -> str: + output = subprocess.check_output(['git', 'rev-parse', 'HEAD'], + cwd=repo_path).decode('ascii').strip() + return output + + def remote_url(repo_path: Path) -> str: + output = subprocess.check_output( + ['git', 'remote', 'get-url', 'origin'], + cwd=repo_path).decode('ascii').strip() + return output + + repo_path_str = str(repo_path) + dest_path = repo_path_str[repo_path_str.rfind('src/'):] + source_object = {'type': 'git', 'url': remote_url(repo_path), 'commit': current_commit(repo_path), 'dest': dest_path} + return source_object + +def sources(build_dir: Path) -> List[Dict[str, str]]: + return list(map(repo_source, repo_paths(build_dir))) + +def main(): + def directory(string: str) -> Path: + path = Path(string) + if not path.is_dir(): + msg = 'build-dir should be a directory.' + raise argparse.ArgumentTypeError(msg) + return path + + parser = argparse.ArgumentParser(description='For a Go module’s dependencies, output array of sources in flatpak-manifest format.') + parser.add_argument('build_dir', help='Build directory of the module in .flatpak-builder/build', type=directory) + parser.add_argument('-o', '--output', dest='output_file', help='The file to write the source list to. Default is -sources.json', type=str) + args = parser.parse_args() + source_list = sources(args.build_dir) + + output_file = args.output_file + if output_file is None: + output_file = args.build_dir.absolute().name + '-sources.json' + + with open(output_file, 'w') as out: + json.dump(source_list, out, indent=2) + +if __name__ == '__main__': + main() diff --git a/space.makeworld.amfora.yml b/space.makeworld.amfora.yml new file mode 100644 index 0000000..e77b8b9 --- /dev/null +++ b/space.makeworld.amfora.yml @@ -0,0 +1,32 @@ +app-id: space.makeworld.amfora +runtime: org.freedesktop.Platform +runtime-version: "21.08" +sdk: org.freedesktop.Sdk +sdk-extensions: + - org.freedesktop.Sdk.Extension.golang +command: amfora + +rename-desktop-file: amfora.desktop + +finish-args: + - --share=network + - --filesystem=xdg-downloads + +build-options: + build-args: + - --share=network +# env: +# - GOBIN=/app/bin +# - GOROOT=/usr/lib/sdk/golang + +modules: + - name: amfora + buildsystem: simple + build-commands: + - . /usr/lib/sdk/golang/enable.sh; make GO=$GOROOT/bin/go + - make install PREFIX=/app + - export GOPATH=$PWD + sources: + - type: git + url: https://github.com/makeworld-the-better-one/amfora + tag: v1.9.0