Created
March 5, 2024 14:37
-
-
Save santiagocezar/f24cfc15c4fd429de08e35cd2c8ef6c9 to your computer and use it in GitHub Desktop.
Update Flatpak moudles from vcpkg.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from subprocess import run | |
| from sys import stderr, stdout | |
| from typing import Optional | |
| with open("vcpkg.json") as vcpkg_file: | |
| vcpkg = json.load(vcpkg_file) | |
| with open("com.kristianduske.TrenchBroom.json") as manifest_file: | |
| manifest = json.load(manifest_file) | |
| def commit_for_version(repo: str, req_version: str) -> Optional[str]: | |
| out = run(["git", "ls-remote", "--tags", repo], capture_output=True).stdout | |
| for line in out.splitlines(): | |
| commit = line.split(b"\t", 1)[0].decode() | |
| version = line.rsplit(b"/", 1)[1].lstrip(b"v").decode() | |
| if version == req_version: | |
| return commit | |
| return None | |
| git_repos = { | |
| "assimp": "https://github.com/assimp/assimp.git", | |
| "catch2": "https://github.com/catchorg/Catch2.git", | |
| "fmt": "https://github.com/fmtlib/fmt.git", | |
| "freeimage": None, # it's from sourceforge, and it needs a patch | |
| "freetype": None, # uses the one from flathub/shared-modules | |
| "glew": None, # uses the one from flathub/shared-modules | |
| "miniz": "https://github.com/richgel999/miniz.git", | |
| "tinyxml2": "https://github.com/leethomason/tinyxml2.git", | |
| } | |
| modules = {} | |
| for module in manifest["modules"]: | |
| if type(module) is dict: | |
| modules[module["name"]] = module | |
| for dep in vcpkg["dependencies"]: | |
| name = dep["name"] | |
| repo = git_repos[name] | |
| req_version = dep["version>="].rsplit("#", 1)[0] | |
| if repo is None: | |
| print(f"skipping over {name} dependency", file=stderr) | |
| continue | |
| if commit := commit_for_version(repo, req_version): | |
| print(f"commit for {name} v{req_version}: {commit}", file=stderr) | |
| else: | |
| print(f"couldn't find commit for {name} v{req_version}", file=stderr) | |
| continue | |
| module = modules[name] | |
| module["sources"] = [ | |
| { | |
| "type": "git", | |
| "url": repo, | |
| "commit": commit, | |
| } | |
| ] | |
| json.dump(manifest, stdout, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment