Initial actual commit

This commit is contained in:
Paul Fey 2025-07-05 13:20:11 +02:00
parent e555b62c06
commit 22d338eac2
7 changed files with 84 additions and 43 deletions

View file

@ -1,9 +0,0 @@
{
"name": "bpb",
"version": "1.1",
"command": {
"install": "python3 install.py",
"run": "./bpb.py"
},
"bin": "bpb"
}

3
build.sh Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
pip install --prefix $OUT_DIR/usr .

View file

@ -5,8 +5,7 @@ import json
import sys import sys
import shutil import shutil
import tarfile import tarfile
import boundaries from .lowbar import lowbar
from lowbar import lowbar
from urllib.request import urlretrieve from urllib.request import urlretrieve
progress_bar = lowbar(100) progress_bar = lowbar(100)
@ -33,7 +32,7 @@ def report_hook(block_count, block_size, file_size):
progress_bar.update(percentage) progress_bar.update(percentage)
progress_bar.desc = f"{downloaded}MB/{size}MB" progress_bar.desc = f"{downloaded}MB/{size}MB"
def build(path: str, output: str | None, should_install: bool, should_compress: bool, compile_static: bool): def build(path: str, output: str | None, should_compress: bool, compile_static: bool):
global progress_bar global progress_bar
file_path = os.path.realpath(os.path.join(os.getcwd(), path)) file_path = os.path.realpath(os.path.join(os.getcwd(), path))
@ -41,30 +40,42 @@ def build(path: str, output: str | None, should_install: bool, should_compress:
fail(f"Path not existing: {file_path}") fail(f"Path not existing: {file_path}")
if not os.path.isdir(file_path): if not os.path.isdir(file_path):
fail(f"Not a directory: {file_path}") fail(f"Not a directory: {file_path}")
if (not os.path.exists(os.path.join(file_path, "bpb.json"))) or (not os.path.isfile(os.path.join(file_path, "bpb.json"))): if (not os.path.exists(os.path.join(file_path, "rodeo-builder.json"))) or (not os.path.isfile(os.path.join(file_path, "rodeo-builder.json"))):
fail("Could not find the bpb.json file") fail("Could not find the rodeo-builder.json file")
os.chdir(file_path) os.chdir(file_path)
with open(os.path.join(file_path, "bpb.json"), "rb") as f: with open(os.path.join(file_path, "rodeo-builder.json"), "rb") as f:
information = json.load(f) information = json.load(f)
if not "name" in information: if not "name" in information:
fail("The bpb.json file does not contain the 'name' field") fail("The rodeo-builder.json file does not contain the 'name' field")
if not "version" in information: if not "version" in information:
fail("The bpb.json file does not contain the 'version' field") fail("The rodeo-builder.json file does not contain the 'version' field")
if not "build" in information: if not "build" in information:
fail("The bpb.json file does not contain the 'build' field") fail("The rodeo-builder.json file does not contain the 'build' field")
if not "json_file" in information:
fail("The bpb.json file does not contain the 'json_file' field")
if compile_static and "build_static" not in information: if compile_static and "build_static" not in information:
fail("The package does not support static builds") fail("The package does not support static builds")
cache_directory = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
build_directory = os.path.join(cache_directory, "rodeo-builder-build")
src_directory = os.path.join(build_directory, "package-source")
if os.path.exists(build_directory):
shutil.rmtree(build_directory)
os.makedirs(build_directory)
shutil.copytree(file_path, src_directory)
os.chdir(src_directory)
if "dependencies" in information: if "dependencies" in information:
if "build_packages" in information["dependencies"]: if "build_packages" in information["dependencies"]:
for package in information["dependencies"]["build_packages"]: for package in information["dependencies"]["build_packages"]:
if not package in boundaries.get_packages(): if not package in []:
fail(f"The boundaries package {package} could not be found and is a build dependency") fail(f"The boundaries package {package} could not be found and is a build dependency")
if "build_commands" in information["dependencies"]: if "build_commands" in information["dependencies"]:
for command in information["dependencies"]["build_commands"]: for command in information["dependencies"]["build_commands"]:
@ -91,54 +102,49 @@ def build(path: str, output: str | None, should_install: bool, should_compress:
if not os.path.exists(path): if not os.path.exists(path):
fail(f"Cloning of {path} failed") fail(f"Cloning of {path} failed")
if os.path.exists(os.path.join(file_path, "package")):
shutil.rmtree(os.path.join(file_path, "package"))
os.mkdir(os.path.join(file_path, "package"))
print(f"Building {information['name']}") print(f"Building {information['name']}")
if compile_static: if compile_static:
build_command = information['build_static'] build_command = information['build_static']
else: else:
build_command = information['build'] build_command = information['build']
build_result = os.system(f"PKG_NAME={information['name']} PKG_VERSION={information['version']} {build_command}") build_result = os.system(f"PKG_NAME={information['name']} PKG_VERSION={information['version']} OUT_DIR={build_directory} PKG_SRC={src_directory} {build_command}")
if build_result != 0: if build_result != 0:
fail("Build failed") fail("Build failed")
print("Creating boundaries package") print("Creating rodeo package")
os.chdir(os.path.join(file_path, "package")) os.chdir(os.path.join(file_path, build_directory))
json_file = information["json_file"] if "extra_package_info" in information:
json_file = information["extra_package_info"]
else:
json_file = {}
json_file["name"] = information["name"] json_file["name"] = information["name"]
json_file["version"] = information["version"] json_file["version"] = information["version"]
with open("boundaries.json", "wt") as f: with open("rodeo-package.json", "wt") as f:
json.dump(json_file, f) json.dump(json_file, f)
os.chdir(file_path) os.chdir(file_path)
if should_install:
print("Installing package")
boundaries.install("package")
if output and not should_compress: if output and not should_compress:
if os.path.exists(os.path.join(file_path, output)): if os.path.exists(os.path.join(file_path, output)):
shutil.rmtree(os.path.join(file_path, output)) shutil.rmtree(os.path.join(file_path, output))
shutil.move(os.path.join(file_path, "package"), os.path.join(file_path, output)) shutil.move(os.path.join(file_path, build_directory), os.path.join(file_path, output))
elif output and should_compress: elif output and should_compress:
print("Compressing package") print("Compressing package")
with tarfile.open(output, "w:gz") as tar: with tarfile.open(output, "w:gz") as tar:
tar.add("package") tar.add(build_directory)
shutil.rmtree("package") shutil.rmtree(build_directory)
elif should_compress: elif should_compress:
print("Compressing package") print("Compressing package")
with tarfile.open("package.tar.gz", "w:gz") as tar: with tarfile.open("package.tar.gz", "w:gz") as tar:
tar.add("package") tar.add(build_directory)
shutil.rmtree("package") shutil.rmtree(build_directory)
print("\033[92m" + "Done! Package built" + "\033[0m") print("\033[92m" + "Done! Package built" + "\033[0m")
if __name__ == "__main__": def main():
parser = argparse.ArgumentParser(prog="bpb", description="The boundaries package builder") parser = argparse.ArgumentParser(prog="rodeo-builder", description="The rodeo package builder")
parser.add_argument("--install", "-i", help="Install the package directly", action="store_true")
parser.add_argument("--output", "-o", help="The path of the folder/archive to be created", default=None) parser.add_argument("--output", "-o", help="The path of the folder/archive to be created", default=None)
parser.add_argument("--archive", "-a", help="Compress the output into a .tar.gz archive", action="store_true") parser.add_argument("--archive", "-a", help="Compress the output into a .tar.gz archive", action="store_true")
parser.add_argument("--static", "-s", help="Try to build the package statically", action="store_true") parser.add_argument("--static", "-s", help="Try to build the package statically", action="store_true")
@ -146,4 +152,4 @@ if __name__ == "__main__":
args = parser.parse_args() args = parser.parse_args()
build(path=args.path, output=args.output, should_install=args.install, should_compress=args.archive, compile_static=args.static) build(path=args.path, output=args.output, should_compress=args.archive, compile_static=args.static)

4
main.py Normal file
View file

@ -0,0 +1,4 @@
import builder
if __name__ == "__main__":
builder.main()

9
rodeo-builder.json Normal file
View file

@ -0,0 +1,9 @@
{
"name": "rodeo-builder",
"description": "Tool for building rodeo packages",
"version": "0.1",
"build": "bash build.sh",
"dependencies": {
"build_commands": ["pip"]
}
}

28
setup.py Normal file
View file

@ -0,0 +1,28 @@
from setuptools import setup, find_packages
setup(
name="rodeo-builder",
version="0.1",
description="Tool for building rodeo packages",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author="pauljako",
url="https://git.pauljako.de/rodeo/rodeo-builder",
packages=find_packages(),
entry_points={
"console_scripts": [
"rodeo-builder=builder:main",
],
},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
python_requires=">=3.8",
)