Skip to content

Commit

Permalink
[DevScripts] Add universal make.py build/install script
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Sep 30, 2024
1 parent 4128805 commit 769de64
Show file tree
Hide file tree
Showing 30 changed files with 221 additions and 91 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ jobs:
run: poetry install
- name: Change in-app version
run: python3 ./scripts/bump_version.py git
- name: Run build script
run: bash ./scripts/build_debian/build.sh
- name: Build
run: dpkg-buildpackage -b
- name: Move release to dist dir
run: mv ../*.deb ./dist
- name: Upload bundle
uses: actions/upload-artifact@v4
with:
name: Debian package
path: ./scripts/build_debian/openfreebuds*
path: ./dist/*
if-no-files-found: error
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ poetry install
### Just launch without installation

```shell
# Compile Qt Designer & Linguist sources
./scripts/make_qt_parts.sh

# Launch
poetry run python -m openfreebuds_qt -vcs

# use --help for options description
./scripts/make.py build_launch
```

### Windows
Expand All @@ -111,11 +105,10 @@ Output binaries will be located in `scripts\build_win32\dist`
Install all packaging dependencies automated way:
`apt install build-essentials && ./scripts/install_dpkg_dependencies.sh`.

Go to `scripts/build_debian` and run build script:

```shell
cd scripts/build_debian
./build.sh
dpkg-buildpackage -b
```

Output file will be located in parent folder (`../*.deb`).

![Extra dialogs preview](docs/preview_2.png)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/make -f

%:
dh $@

override_dh_auto_build:
python ./scripts/make.py build

override_dh_auto_install:
python ./scripts/make.py install debian/openfreebuds/usr debian/openfreebuds/usr/lib/python3/dist-packages

override_dh_clean:
git clean -Xfd
2 changes: 2 additions & 0 deletions debian/source/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tar-ignore = "*venv"
tar-ignore = ".git"
2 changes: 1 addition & 1 deletion openfreebuds_qt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, ctx: IOfbQtApplication):
self.setupUi(self)

# Win32 staff
self.setWindowIcon(QIcon(str(ASSETS_PATH / "icon.png")))
self.setWindowIcon(QIcon(str(ASSETS_PATH / "pw.mmk.OpenFreebuds.png")))
if sys.platform == "win32":
self.body_content.setStyleSheet(WIN32_BODY_STYLE)

Expand Down
Binary file removed openfreebuds_qt/assets/dual_connect_device.png
Binary file not shown.
Binary file removed openfreebuds_qt/assets/icon.png
Binary file not shown.
Binary file removed openfreebuds_qt/assets/icon_settings.png
Binary file not shown.
Binary file removed openfreebuds_qt/assets/overlay_playing.png
Binary file not shown.
Binary file removed openfreebuds_qt/assets/overlay_primary.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@
<url type="vcs-browser">https://github.com/melianmiko/OpenFreebuds</url>

<screenshots>
<screenshot type="default">
<screenshot type="default" xml:lang="en">
<caption>Tray indicator and context menu with common features</caption>
<image>https://raw.githubusercontent.com/melianmiko/OpenFreebuds/refs/heads/main/docs/preview_0.png</image>
</screenshot>
<screenshot>
<screenshot xml:lang="en">
<caption>Device gesture settings (may vary depending on device model)</caption>
<image>https://raw.githubusercontent.com/melianmiko/OpenFreebuds/refs/heads/main/docs/app_0.png</image>
</screenshot>
<screenshot>
<screenshot xml:lang="en">
<caption>Application user interface settings</caption>
<image>https://raw.githubusercontent.com/melianmiko/OpenFreebuds/refs/heads/main/docs/app_1.png</image>
</screenshot>
Expand Down
2 changes: 0 additions & 2 deletions scripts/build_debian/.gitignore

This file was deleted.

26 changes: 0 additions & 26 deletions scripts/build_debian/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/build_debian/build.sh

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/build_debian/debian/rules

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/build_debian/debian/source/options

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build_debian/pw.mmk.OpenFreebuds.desktop

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build_debian/pw.mmk.OpenFreebuds.metainfo.xml

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build_debian/pw.mmk.OpenFreebuds.png

This file was deleted.

13 changes: 3 additions & 10 deletions scripts/build_flatpak/pw.mmk.OpenFreebuds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,13 @@ modules:

- python3-requirements.json

- name: PyQtApp
- name: OpenFreebuds
buildsystem: simple
build-commands:
- pip3 install --prefix=/app --no-deps *.whl
- touch /app/is_container
- install -Dm644 pw.mmk.OpenFreebuds.png -t /app/share/icons/hicolor/256x256/apps
- install -Dm644 pw.mmk.OpenFreebuds.desktop -t /app/share/applications
- install -Dm644 pw.mmk.OpenFreebuds.metainfo.xml -t /app/share/metainfo
- python ./make.py install /app
sources:
- type: file
path: pw.mmk.OpenFreebuds.desktop
- type: file
path: pw.mmk.OpenFreebuds.metainfo.xml
- type: file
path: pw.mmk.OpenFreebuds.png
path: ../../scripts/make.py
- type: dir
path: ../../dist
2 changes: 1 addition & 1 deletion scripts/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def main():
bump_pyproject(str(PROJECT_ROOT / "pyproject.toml"))
bump_nsis(str(PROJECT_ROOT / "scripts/build_win32/openfreebuds.nsi"))
bump_debian(PROJECT_ROOT / "scripts/build_debian/debian/changelog")
bump_metainfo(str(PROJECT_ROOT / "scripts/build_flatpak/pw.mmk.OpenFreebuds.metainfo.xml"))
bump_metainfo(str(PROJECT_ROOT / "openfreebuds_qt/assets/pw.mmk.OpenFreebuds.metainfo.xml"))
create_version_info(PROJECT_ROOT / "openfreebuds_qt/version_info.py")
create_flatpak_staff()

Expand Down
8 changes: 4 additions & 4 deletions scripts/build_flatpak/build.sh → scripts/flatpak_install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash

cd "$(dirname "$0")"/../..
cd "$(dirname "$0")"/..

rm -rf scripts/build_flatpak/release
./scripts/make_qt_parts.sh
poetry build
# Compile wheel
./scripts/install.py build

# Build & install flatpak
cd scripts/build_flatpak
flatpak-builder \
--force-clean \
Expand Down
185 changes: 185 additions & 0 deletions scripts/make.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/usr/bin/env python3

"""
Unified Linux build/install script for OpenFreebuds
Should work in (mostly) all distributions
"""

import os
import shutil
import subprocess
import sys
from pathlib import Path
from sys import version_info

PROJECT_ROOT = Path(__file__).parent
if PROJECT_ROOT.name == "scripts":
PROJECT_ROOT = PROJECT_ROOT.parent

# Constants
DEFAULT_DESTINATION = "/usr/local"
PYTHON_XX = f"python{version_info.major}.{version_info.minor}"
PYTHON_LIB_PATH_OPTIONS = [
f"lib/{PYTHON_XX}/dist-packages",
f"lib/python3/dist-packages",
f"lib/python/dist-packages",
f"lib/{PYTHON_XX}/site-packages",
f"lib/python3/site-packages",
f"lib/python/site-packages",
]
QT_L_RELEASE_PATH_OPTIONS = [
"/usr/lib/qt6/bin/lrelease",
"/usr/bin/lrelease",
"lrelease",
]
ALLOWED_TASKS = [
"build",
"install",
"build_install",
"launch",
"build_launch"
]

# Base params
if len(sys.argv) < 2 or sys.argv[1] not in ALLOWED_TASKS:
print(f"Usage: ./make.py <{'|'.join(ALLOWED_TASKS)}> [DEST_DIR] [PYTHON_LIBS_DIR]")
raise SystemExit(1)
TASK = sys.argv[1]
DEST_DIR = Path(DEFAULT_DESTINATION if len(sys.argv) < 3 else sys.argv[2])
PYTHON_LIBS_DIR = None if len(sys.argv) < 4 else Path(sys.argv[3])

# Determinate task
DO_INSTALL = "install" in TASK
DO_LAUNCH = "launch" in TASK
DO_BUILD = "build" in TASK

# Ensure environment
if sys.platform == "win32" and TASK != "build":
print("-- Can't install under Windows, use pyinstaller")
raise SystemExit(1)
if os.environ.get("VIRTUAL_ENV", None) is not None:
print("-- Launch this script outside of virtualenv")
raise SystemExit(1)

# Find python dest dir
if PYTHON_LIBS_DIR is None:
for option in PYTHON_LIB_PATH_OPTIONS:
if (DEST_DIR / option).exists():
PYTHON_LIBS_DIR = DEST_DIR / option
PYTHON_LIBS_DIR.mkdir(exist_ok=True, parents=True)
break

if PYTHON_LIBS_DIR is None:
print("-- Error: Can't find python packages location, provide them manually")
raise SystemExit(1)

print(f"Going to {TASK} OpenFreebuds")
if DO_INSTALL:
print(f"root={DEST_DIR}, python_libs={PYTHON_LIBS_DIR}")

# Source compilation tasks
if DO_BUILD:
# Compile Qt Designer layouts
print("Compile Qt Designer files")
DESIGNER_DIR = PROJECT_ROOT / "openfreebuds_qt" / "designer"
result = subprocess.run(["env", "poetry", "run", "pyuic6", DESIGNER_DIR])
if result.returncode != 0:
print("Failed, old pyuic? Will try single file mode...")
for ui_file in DESIGNER_DIR.iterdir():
if not ui_file.name.endswith(".ui"):
continue
print(f"Compile {ui_file}")
result = subprocess.run(["poetry", "run", "pyuic6",
"-o", str(ui_file).replace(".ui", ".py"),
ui_file])
if result.returncode != 0:
print("-- PyUiC failed")
raise SystemExit(1)

# Compile Qt translations
L_RELEASE_EXEC = None
for option in QT_L_RELEASE_PATH_OPTIONS:
if Path(option).exists():
L_RELEASE_EXEC = option
break

if L_RELEASE_EXEC is not None:
print("Compile Qt translations")
files_to_compile = []
for translation in (PROJECT_ROOT / "openfreebuds_qt/assets/i18n").iterdir():
if not translation.name.endswith(".ts"):
continue
files_to_compile.append(str(translation))
result = subprocess.run([L_RELEASE_EXEC, "-silent", *files_to_compile])
if result.returncode != 0:
print("-- lrelease failed")
raise SystemExit(1)
else:
print("Warn: Can't find Qt lrelease executable, skip compiling translations")

# Compile Python bundle
print("Compile Python wheel")
POETRY_DIST = PROJECT_ROOT / "dist"
shutil.rmtree(POETRY_DIST, ignore_errors=True)
result = subprocess.run(["poetry", "build", "-q"])
if result.returncode != 0:
print("-- Poetry build failed")
raise SystemExit(1)

# Launch task
if DO_LAUNCH:
print('----------------------------------------------------------------')
print("Launching OpenFreebuds")
subprocess.run(["poetry", "run", "python", "-m", "openfreebuds_qt", "-vcs"])
raise SystemExit(0)

# Wheel install tasks
if DO_INSTALL:
DISTRIBUTION_PATH = PROJECT_ROOT if not (PROJECT_ROOT / "dist").exists() else PROJECT_ROOT / "dist"
WHEEL_FILE = list(DISTRIBUTION_PATH.glob("*.whl"))
if len(WHEEL_FILE) == 0:
print("-- Error: Can't find wheel file to install")
raise SystemExit(1)
WHEEL_FILE = WHEEL_FILE[0]

# Install python package
print("Install openfreebuds python package")
result = subprocess.run(["pip", "install", "-q",
"--upgrade",
"--no-dependencies",
f"--target={PYTHON_LIBS_DIR}",
WHEEL_FILE])
if result.returncode != 0:
print("-- pip package install failure")
raise SystemExit(1)

# Install binaries
BIN_DIR = PYTHON_LIBS_DIR / "bin"
TARGET_BIN_DIR = DEST_DIR / "bin"
TARGET_BIN_DIR.mkdir(exist_ok=True, parents=True)

if BIN_DIR != TARGET_BIN_DIR:
for filename in ["openfreebuds_qt", "openfreebuds_cmd"]:
print(f"Install {TARGET_BIN_DIR / filename}")
shutil.copy(BIN_DIR / filename, TARGET_BIN_DIR)
os.unlink(BIN_DIR / filename)
print(f"Install {TARGET_BIN_DIR}/openfreebuds (symlink)")
(TARGET_BIN_DIR / "openfreebuds").unlink(missing_ok=True)
os.symlink("./openfreebuds_qt", TARGET_BIN_DIR / "openfreebuds")

# Copy desktop integration files to system environment
ASSETS_DIR = PYTHON_LIBS_DIR / "openfreebuds_qt" / "assets"


def install_asset(asset, dest):
full_dest = DEST_DIR / dest
full_dest.mkdir(exist_ok=True, parents=True)
print(f"Install {full_dest / asset}")
shutil.copy(ASSETS_DIR / asset, full_dest / asset)


install_asset("pw.mmk.OpenFreebuds.desktop", "share/applications")
install_asset("pw.mmk.OpenFreebuds.metainfo.xml", "share/metainfo")
install_asset("pw.mmk.OpenFreebuds.png", "share/icons/hicolor/256x256/apps")

print("Done")
5 changes: 0 additions & 5 deletions scripts/make_qt_parts.sh

This file was deleted.

0 comments on commit 769de64

Please sign in to comment.