diff --git a/cmake/chromium.py b/cmake/chromium.py index 8a77e80a..3e8e4291 100755 --- a/cmake/chromium.py +++ b/cmake/chromium.py @@ -24,7 +24,7 @@ build_type = vars['CMAKE_BUILD_TYPE'] python = executable -patcher = Patcher(src,git_binary,build_type) +patcher = Patcher(src, git_binary, build_type) def run(args, fail_ok = False): if isdir(src): diff --git a/cmake/patch.py b/cmake/patch.py index 5f8c8c15..d4bb83e6 100755 --- a/cmake/patch.py +++ b/cmake/patch.py @@ -3,20 +3,20 @@ from os import listdir, remove from os.path import dirname, join, realpath, splitext from subprocess import check_call, check_output -from sys import argv, platform, stderr +from sys import argv, executable, platform, stderr from time import ctime -import requests +try: + import requests +except ModuleNotFoundError: + check_call([executable, '-m', 'pip', 'install', 'requests']) + import requests def osname(): - match platform: - case 'linux': - return 'Linux' - case 'darwn': - return 'Mac' - case _: - return 'Windows' + if platform == 'linux': return 'Linux' + if platform == 'darwin': return 'Mac' + return 'Windows' class Patcher: @@ -160,5 +160,11 @@ def unavailable(self): missing = Patcher('/mnt/big/lbl/code/chromium/src', 'git', 'Debug').unavailable() for m in missing: print(m) + elif argv[1] == 'releases': + p = Patcher('/mnt/big/lbl/code/chromium/src', 'git', 'Debug') + for chan in ['Dev', 'Beta', 'Stable', 'Extended']: + rels = p.release_versions(chan) + for rel in rels: + print(chan, rel) else: Patcher(*argv[1:]).create_patch_file() diff --git a/cmake/release.py b/cmake/release.py new file mode 100755 index 00000000..5924c862 --- /dev/null +++ b/cmake/release.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + + +from version import deduce, on_tag + +from os import chdir, environ, getcwd, listdir +from os.path import join, isdir, isfile, splitext +from subprocess import check_call, check_output +from sys import executable, stderr + +GITHUB_ORG = 'little-bear-labs' +GITHUB_REPO = 'ipfs-chromium' +# GITHUB_ORG = 'John-LittleBearLabs' +# GITHUB_REPO = 'temp' + +try: + from ghapi.all import GhApi +except ModuleNotFoundError: + check_call([executable, '-m', 'pip', 'install', 'ghapi']) + from ghapi.all import GhApi + +build_dir = getcwd() + + +def build_target(target): + argv = ['cmake', '--build', build_dir, '--target', target] + check_call(args=argv) + + +if not isfile('CMakeCache.txt'): + print(__file__, 'must be run from inside the build directory.', file=stderr) + exit(1) + + +def line_to_var(line): + try: + colon = line.index(':') + k = line[0:colon] + v = line[colon:] + equal = v.index('=') + return (k, v[equal+1:]) + except ValueError: + return ('', None) + + +vars = check_output(['cmake', '-L', '-N', '-B', '.'], text=True).splitlines() +vars = dict(map(line_to_var, vars)) +chromium_out = join(vars['CHROMIUM_SOURCE_TREE'], 'out', vars['CHROMIUM_PROFILE']) +tok = environ.get('GITHUB_TOKEN') +if tok: + gh = GhApi() +else: + print('GITHUB_TOKEN not set!', file=stderr) + exit(2) +build_target('package_browser') +if not isdir(chromium_out): + print(chromium_out, 'is not a directory?!', file=stderr) + exit(3) +build_target('package') +version = deduce() +if on_tag(): + print('Will be adding to release', version) + gh_rel = gh.repos.get_release_by_tag(owner=GITHUB_ORG, repo=GITHUB_REPO, tag=version) +else: + print('Creating brand new release!') + gh_rel = gh.repos.create_release(owner=GITHUB_ORG, repo=GITHUB_REPO, tag_name=version) +artifact_extensions = ['.tar.gz', '.rpm', '.deb', '.dmg'] + + +def upload(contains): + for f in listdir('.'): + if contains not in f: + continue + for ext in artifact_extensions: + if f.endswith(ext): + print('Uploading', f, 'to', GITHUB_ORG, GITHUB_REPO, 'release', version) + gh.upload_file(gh_rel, f) + break + + +upload('client') +chdir(chromium_out) +upload('unstable') diff --git a/cmake/version.py b/cmake/version.py index 24414fbe..5c9821f6 100755 --- a/cmake/version.py +++ b/cmake/version.py @@ -28,10 +28,15 @@ def tag_to_version(tag): return 0 +def on_tag(): + git(['fetch', '--all', '--tags']) + return git(['describe', '--tags', '--exact-match', 'HEAD']) + + def deduce(): - on_tag = git(['describe', '--tags', '--exact-match', 'HEAD']) - if on_tag and tag_to_version(on_tag) > 0: - return on_tag + tag = on_tag() + if tag and tag_to_version(tag) > 0: + return tag git(['fetch', '--tags']) tags = git(['tag']).splitlines() versions = map(tag_to_version, tags) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index f4e6314e..55b49588 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -89,8 +89,15 @@ find_program(RPMBUILD rpmbuild) if(RPMBUILD) list(APPEND CPACK_GENERATOR RPM) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND DRAGNDROP) +endif() -set(CPACK_PACKAGE_NAME "ipfs-client-dev-${CMAKE_BUILD_TYPE}") +if (CMAKE_BUILD_TYPE STREQUAL Release) + set(CPACK_PACKAGE_NAME "ipfs-client-devel") +else() + set(CPACK_PACKAGE_NAME "ipfs-client-devel-${CMAKE_BUILD_TYPE}") +endif() set(CPACK_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}") set(CPACK_PACKAGE_VENDOR "LBL") set(CPACK_PACKAGE_CONTACT "john@littlebearlabs.io")