aboutsummaryrefslogtreecommitdiff
path: root/justfile
diff options
context:
space:
mode:
authorRubén Beltrán del Río <jj@r.bdr.sh>2026-04-05 21:25:35 +0200
committerRubén Beltrán del Río <jj@r.bdr.sh>2026-04-06 00:46:50 +0200
commit100fcf7bdf7a5e711475e6173f28ca6d407483bd (patch)
treeaa63de7116b06755a9b531d3d0ac8ddbbea1e349 /justfile
parentd9245d341ed1f258a3dd1073cdfa656115c5b26d (diff)
Move rest of Makefile and scripts to the justfile
Diffstat (limited to 'justfile')
-rw-r--r--justfile222
1 files changed, 211 insertions, 11 deletions
diff --git a/justfile b/justfile
index e87f5c0..fc49f8b 100644
--- a/justfile
+++ b/justfile
@@ -1,42 +1,242 @@
+# Configuration ################################################################
+app_name := "map"
+channel := "unstable"
+builddir := "_build"
+distdir := "_dist"
+clean_images := ""
+
+# Derived Values ---------------------------------------------------------------
+target := `rustc -vV | grep host | awk '{print $2}'`
+arch := replace_regex(target, "-.*$", "")
+filename := f"{{app_name}}-{{arch}}-{{channel}}"
+
+# Packaging --------------------------------------------------------------------
+linuxdeploy_url := "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-" + `uname -m` + ".AppImage"
+linuxdeploy := ".cache/linuxdeploy.AppImage"
+flatpak_cargo_generator := home_directory() / "projects/vendor/flatpak-builder-tools/cargo"
+
+# Build Containers -------------------------------------------------------------
+fedora_versions := "fedora43 fedora44 fedora-rawhide"
+debian_versions := "trixie forky"
+appimage_container := "trixie"
+all_containers := f"arch {{fedora_versions}} {{debian_versions}}"
+container_image_prefix := "map-build"
+
+# Distribution Hosts -----------------------------------------------------------
+distribution_host := "deploy@build.r.bdr.sh"
+distribution_path := f"/srv/http/build.r.bdr.sh/{{app_name}}-linux"
+
# Build ########################################################################
+
+# Setup the meson build directory.
setup:
- meson setup _build
+ meson setup {{builddir}}
+# Compile the project using meson
build: setup
- meson compile -C _build
+ meson compile -C {{builddir}}
+# Create a dist tarball with meson
dist: setup
- meson dist -C _build --no-tests --allow-dirty
+ meson dist -C {{builddir}} --no-tests --allow-dirty
# Code Quality #################################################################
+# Run tests
test:
- cargo test
+ cargo test
+# Run tests with a coverage report
coverage:
- cargo tarpaulin
+ cargo tarpaulin
+# Format the source code and fix fixable code quality issues
format:
- cargo fmt && cargo clippy --fix
+ cargo fmt && cargo clippy --fix
+# Check the source code for lint and code quality issues
lint:
- cargo fmt -- --check && cargo clippy
+ cargo fmt -- --check && cargo clippy
# Internationalization / Localization ##########################################
-# Finds all files that can be translated and adds them to the POTFILES
+# Find translatable strings in the source and create a reference in POTFILES
find_translatable_files:
- find ./src -not -path '*/.*' -type f -name "*.rs" -exec grep -l "tr!(\"\|gettext" {} \; | sed 's|^\./||' | sort > po/POTFILES
- find ./data -not -path '*/.*' -name "*.in.in" -type f | sed 's|^\./||' | sort >> po/POTFILES
+ find ./src -not -path '*/.*' -type f -name "*.rs" -exec grep -l "tr!(\"\|gettext" {} \; | sed 's|^\./||' | sort > po/POTFILES
+ find ./data -not -path '*/.*' -name "*.in.in" -type f | sed 's|^\./||' | sort >> po/POTFILES
+# Extract the strings into the POT file
extract_strings: find_translatable_files
- @xgettext --files-from=po/POTFILES --output=po/systems.tranquil.Map.pot --from-code=UTF-8 --add-comments --keyword='tr!'
+ xgettext --files-from=po/POTFILES --output=po/systems.tranquil.Map.pot --from-code=UTF-8 --add-comments --keyword='tr!'
+
+# Containers ###################################################################
+
+# Builds the container specified by name
+build-container name:
+ {{ if clean_images != "" { "podman system prune -af" } else { "" } }}
+ @echo "=== Building container image: {{container_image_prefix}}:{{name}} ==="
+ podman build -t {{container_image_prefix}}:{{name}} build-containers/{{name}}
+
+# Builds all containers
+build-containers:
+ for container in {{all_containers}}; do just build-container "$container"; done
+
+# Packaging ####################################################################
+
+# Updates the cargo-sources.json
+update_flatpak_dependencies:
+ cd {{flatpak_cargo_generator}} && `poetry env activate` && python3 flatpak-cargo-generator.py {{justfile_directory()}}/Cargo.lock -o {{justfile_directory()}}/build-aux/flatpak/cargo-sources.json && deactivate
+
+# Builds a flatpak and exports the .flatpak file
+package-flatpak: _ensure_distdir update_flatpak_dependencies
+ flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir ./build-aux/flatpak/systems.tranquil.Map.yml
+ flatpak build-bundle repo {{distdir}}/{{filename}}.flatpak systems.tranquil.Map
+
+_fetch-linuxdeploy:
+ @mkdir -p .cache
+ @test -f {{linuxdeploy}} || curl -L -o {{linuxdeploy}} {{linuxdeploy_url}}
+ @chmod +x {{linuxdeploy}}
+
+# Builds an AppImage
+package-appimage: _ensure_distdir (build-container appimage_container) _fetch-linuxdeploy && (_clean_image appimage_container)
+ @echo "=== Building AppImage ==="
+ ./scripts/build_appimage.sh {{container_image_prefix}} trixie {{app_name}} {{arch}} {{channel}} {{linuxdeploy}}
+
+# Builds an arch .pkg.tar.gz
+package-arch: _ensure_distdir (build-container "arch") dist && (_clean_image "arch")
+ @echo "=== Building Arch package ({{arch}}) ==="
+ ./scripts/build_arch.sh {{container_image_prefix}} arch {{app_name}} {{arch}} {{channel}}
+
+# Build .rpm for the given distro
+package-rpm distro: _ensure_distdir (build-container distro) dist && (_clean_image distro)
+ @echo "=== Building RPM for {{distro}} ({{arch}}) ==="
+ ./scripts/build_rpm.sh {{container_image_prefix}} {{distro}} {{app_name}} {{arch}} {{channel}}
+
+# Build .deb for the given distro
+package-deb distro: _ensure_distdir (build-container distro) dist && (_clean_image distro)
+ @echo "=== Building DEB for {{distro}} ({{arch}}) ==="
+ ./scripts/build_deb.sh {{container_image_prefix}} {{distro}} {{app_name}} {{arch}} {{channel}}
+
+# Build .rpm for every supported distro
+package-rpm-all:
+ for distro in {{fedora_versions}}; do just package-rpm "$distro"; done
+
+# Build .deb for every supported distro
+package-deb-all:
+ for distro in {{debian_versions}}; do just package-deb "$distro"; done
+
+# Build all distributable packages
+package: package-flatpak package-appimage package-arch package-rpm-all package-deb-all
+
+# Distribution #################################################################
+
+# Sign and upload flatpak
+distribute-flatpak: (_sign_and_upload f"{{distdir}}/{{filename}}.flatpak")
+
+# Sign and upload AppImage
+distribute-appimage: (_sign_and_upload f"{{distdir}}/{{filename}}.AppImage")
+# Sign and upload arch .pkg.tar.gz
+distribute-arch: (_sign_and_upload f"{{distdir}}/{{filename}}-arch.pkg.tar.gz")
+
+# Sign and upload .rpm files
+distribute-rpm:
+ for distro in {{fedora_versions}}; do just _distribute-rpm "$distro"; done
+
+# Sign and upload .deb files
+distribute-deb:
+ for distro in {{debian_versions}}; do just _distribute-deb "$distro"; done
+
+# Sign and upload all distributable packages
+distribute: distribute-flatpak distribute-appimage distribute-arch distribute-rpm distribute-deb
+
+_distribute-rpm distro: (_sign_and_upload f"{{distdir}}/{{filename}}-{{distro}}.rpm")
+
+_distribute-deb distro: (_sign_and_upload f"{{distdir}}/{{filename}}-{{distro}}.deb")
+
+# Release ######################################################################
+
+# Creates, signs and uploads all distributable packages
+release: package distribute
+
+# CI/CD ########################################################################
+
+# Intended to run in CI. Lints and releases.
+ci: lint
+ #!/usr/bin/env bash
+ if [[ "$GIT_REF" == "refs/heads/main"]]; then
+ just release
+ elif [[ "$GIT_REF" == "refs/tags/*" ]]; then
+ just channel="${GIT_REF#refs/tags/}" release
+ else
+ echo "Not in CI environment."
+ fi
+
+# Local Install ################################################################
+
+# Locally installs
+install: build
+ meson install -C {{builddir}}
+
+uninstall:
+ ninja -C {{builddir}} uninstall
# Utility Tasks ################################################################
+
+# Print the Version
version:
@grep -m1 -o "[^_]version: '[^']*'" meson.build | awk -F"'" '{print $2}'
+# Vendor the rust dependencies
vendor location:
cargo vendor {{location}} >/dev/null
mkdir -p .cargo
+
+# Syncs versions of different files to the meson.build
+sync-versions:
+ #!/usr/bin/env bash
+ version=`just version`
+ echo "Using version from meson.build: ${version}"
+
+ # Rust Cargo.toml
+ echo -ne "\tUpdating: Cargo.toml"
+ sed -i "s/^version = \"[^\"]*\"$/version = \"$version\"/" Cargo.toml
+ echo -e "\r\tUpdated: Cargo.toml "
+
+ # Arch PKGBUILD
+ echo -ne "\tUpdating: PKGBUILD"
+ sed -i "s/^pkgver=.*$/pkgver=$version/" build-aux/arch/PKGBUILD
+ echo -e "\r\tUpdated: PKGBUILD "
+
+ # Fedora RPM Spec
+ echo -ne "\tUpdating: map.spec"
+ sed -i "s/^Version: .*$/Version: $version/" build-aux/rpm/map.spec
+ echo -e "\r\tUpdated: map.spec "
+
+# Internal Tasks ###############################################################
+
+# Cleans images if the flag is set (eg. for low-storage environments)
+_clean_image image:
+ {{ if clean_images != "" { f"podman rmi {{container_image_prefix}}:{{image}}" } else { "" } }}
+
+# Ensures distdir exists
+_ensure_distdir:
+ @mkdir -p {{distdir}}
+
+# Signs a file
+_sign file version platform:
+ #!/usr/bin/env bash
+ comment="Version: {{version}}, File: {{file_name(file)}} Built on: {{datetime('%Y-%m-%d %H:%M')}}, Platform: {{platform}}"
+ if [ -f ~/.minisign/minisign.pass ]; then
+ cat ~/.minisign/minisign.pass | minisign -Sm "{{file}}" -t "${comment}"
+ else
+ minisign -Sm "{{file}}" -t "${comment}"
+ fi
+
+# Uploads a file and its signature.
+_upload file:
+ rsync -avz {{file}}.minisig {{distribution_host}}:{{distribution_path}}
+ rsync -avz {{file}} {{distribution_host}}:{{distribution_path}}
+
+# Sign and upload a file.
+_sign_and_upload file: (_sign file channel arch) (_upload file)