From 027ae42e9c334a0294682a6a1c9ba4f3d2203177 Mon Sep 17 00:00:00 2001 From: Kyle Scheuing Date: Tue, 14 May 2024 01:02:13 -0400 Subject: [PATCH] build: replace cargo-make with Just cargo-make was originally chosen so that bash would not be a requirement for building, but now that msys2 is required on windows, bash will always be present. Just is a better choice here since rust is not the only language used. The install scripts are also now independent bash scripts that are not dependent on Just, so they can be used when building the flatpak. --- .github/workflows/build.yml | 22 ++-- .github/workflows/lint.yml | 28 ++--- .github/workflows/test.yml | 16 ++- Makefile.toml | 100 ---------------- README.md | 8 +- android/Makefile.toml | 7 -- android/justfile | 30 +++++ cli/Makefile.toml | 66 ----------- cli/justfile | 22 ++++ cli/scripts/install.sh | 24 ++++ cli/scripts/uninstall.sh | 17 +++ docs/build-linux.md | 6 +- docs/build-macos.md | 8 +- docs/build-windows.md | 2 +- gui/Makefile.toml | 151 ------------------------- gui/justfile | 31 +++++ gui/scripts/build-locale.sh | 5 +- gui/scripts/install.sh | 20 ++++ gui/scripts/uninstall.sh | 25 ++++ gui/scripts/update-po-files.sh | 5 +- justfile | 67 +++++++++++ lib/Makefile.toml | 21 ---- lib/justfile | 11 ++ lib_protobuf/Makefile.toml | 7 -- lib_protobuf/justfile | 11 ++ packaging/appimage/AppImageBuilder.yml | 5 +- packaging/windows/build.ps1 | 46 -------- packaging/windows/build.sh | 18 ++- web/justfile | 21 ++++ web/wasm/Makefile.toml | 13 --- web/wasm/justfile | 11 ++ 31 files changed, 336 insertions(+), 488 deletions(-) delete mode 100644 Makefile.toml delete mode 100644 android/Makefile.toml create mode 100644 android/justfile delete mode 100644 cli/Makefile.toml create mode 100644 cli/justfile create mode 100755 cli/scripts/install.sh create mode 100755 cli/scripts/uninstall.sh delete mode 100644 gui/Makefile.toml create mode 100644 gui/justfile create mode 100755 gui/scripts/install.sh create mode 100755 gui/scripts/uninstall.sh create mode 100644 justfile delete mode 100644 lib/Makefile.toml create mode 100644 lib/justfile delete mode 100644 lib_protobuf/Makefile.toml create mode 100644 lib_protobuf/justfile delete mode 100644 packaging/windows/build.ps1 create mode 100644 web/justfile delete mode 100644 web/wasm/Makefile.toml create mode 100644 web/wasm/justfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0630159..fc9e8383 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: run: | apt-get update apt-get upgrade -y - apt-get install -y git curl unzip clang gpg + apt-get install -y git curl unzip clang gpg just - uses: actions/checkout@v4 with: @@ -25,8 +25,6 @@ jobs: - name: Install dependencies run: | apt-get install -y libdbus-1-dev pkg-config libgtk-4-dev libadwaita-1-dev gettext libfuse2 - - name: Install cargo-make - run: cargo install cargo-make - name: Install appimage-builder run: | curl --location -o appimage-builder https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage @@ -34,6 +32,7 @@ jobs: mv appimage-builder /usr/bin/ - name: Build cli run: cargo build --release --package openscq30_cli + - name: Build AppImage working-directory: ./packaging/appimage run: appimage-builder --skip-tests @@ -91,23 +90,16 @@ jobs: libadwaita:p rust:p pkg-config:p - - # cargo-make does not use the current shell to run "cargo build". It spawns a new shell, and on Windows, that's cmd. - # Rather than trying to get cargo-make to conditionally use the msys2 shell, we can just get anything that would - # interfere out of the path. - # We want to use the msys2 cargo and linker, so that means cargo and visual studio need to be removed from the path. - - name: Remove Visual Studio and cargo from path - run: | - Move-Item -Path "C:\Program Files\Microsoft Visual Studio" -Destination "C:\Program Files\_Microsoft Visual Studio" - Move-Item -Path "~\.cargo" -Destination "~\._cargo" - - - name: Install cargo-make + - name: Install just shell: msys2 {0} run: | - cargo install cargo-make + mkdir ~/.cargo + CARGO_PROFILE_RELEASE_LTO=false cargo install --root "$HOME/.cargo" just + - name: Build gui shell: msys2 {0} run: | + export PATH="$HOME/.cargo/bin:$PATH" ./packaging/windows/build.sh - name: Build installer diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 89cdd89d..4f70390f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,32 +4,24 @@ on: - push jobs: - rustfmt: + format-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: true + - name: Install just + # todo switch to apt once ubuntu-24.04 is available + # run: sudo apt-get install -y just + run: sudo snap install --edge --classic just + - uses: actions/setup-java@v4 + with: + distribution: temurin # See 'Supported distributions' for available options + java-version: 17 - name: Install rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt - - name: Install cargo-make - uses: davidB/rust-cargo-make@v1 - name: Check formatting - run: cargo make fmt-check + run: just format-check - ktlint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - uses: actions/setup-java@v4 - with: - distribution: temurin # See 'Supported distributions' for available options - java-version: 17 - - name: Run ktlint - run: | - cd android - ./gradlew ktlintCheck diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c0a8aef..ca6a582f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: - name: Install basic requirements run: | apt-get update - apt-get install -y git curl unzip clang + apt-get install -y git curl unzip clang just - uses: actions/checkout@v4 with: @@ -27,14 +27,12 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - - name: Install cargo-make - uses: davidB/rust-cargo-make@v1 - name: Cache cargo dependencies uses: Swatinem/rust-cache@v2 - name: Run rust tests - run: xvfb-run --auto-servernum cargo make test-cov + run: xvfb-run --auto-servernum just test-cov - name: Generate HTML test coverage report - run: cargo make test-cov-report-html + run: just test-cov-report html - name: Upload coverage report uses: actions/upload-artifact@v4 with: @@ -48,14 +46,14 @@ jobs: - uses: actions/checkout@v4 with: submodules: true + - name: Install just + run: choco install just - name: Install rust uses: dtolnay/rust-toolchain@stable - name: Cache cargo dependencies uses: Swatinem/rust-cache@v2 - - name: Install cargo-make - uses: davidB/rust-cargo-make@v1 - - name: Run rust tests - run: cargo make integration-test + - name: Run lib tests + run: just lib/ test android_test: runs-on: ubuntu-latest diff --git a/Makefile.toml b/Makefile.toml deleted file mode 100644 index ace8de0d..00000000 --- a/Makefile.toml +++ /dev/null @@ -1,100 +0,0 @@ -[env] -CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true -CARGO_MAKE_CARGO_BUILD_TEST_FLAGS = "" -OPENSCQ30_BUILD_DEMO_MODE = false -CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["uniffi-bindgen"] - -[env.demo] -OPENSCQ30_BUILD_DEMO_MODE = true - -[tasks.build] -clear = true -env = { "CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS" = ["gui", "cli"] } -script_runner = "@duckscript" -script.pre = ''' -cargo_build_flags = set "" -if eq ${CARGO_MAKE_PROFILE} "release" - cargo_build_flags = set --release - set_env OPENSCQ30_BUILD_DIR ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release -else - set_env OPENSCQ30_BUILD_DIR ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/debug -end - -if eq ${OPENSCQ30_BUILD_DEMO_MODE} "true" - cargo_build_flags = concat ${cargo_build_flags} " --no-default-features --features demo" -end - -set_env OPENSCQ30_BUILD_FLAGS ${cargo_build_flags} -''' - -[tasks.test] -clear = true -dependencies = ["unit-test", "integration-test"] - -[tasks.integration-test] -env = { "CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS" = ["cli"] } - -[tasks.test-cov] -clear = true -workspace = false -dependencies = [ - "llvm-cov-clean", - "member-unit-test-cov", - "member-integration-test-cov", -] - -[tasks.llvm-cov-clean] -private = true -command = "cargo" -args = ["llvm-cov", "clean", "--workspace"] - -[tasks.member-unit-test-cov] -private = true -run_task = { name = "unit-test-cov", fork = true } - -[tasks.member-integration-test-cov] -private = true -env = { "CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS" = ["cli"] } -run_task = { name = "integration-test-cov", fork = true } - -[tasks.test-cov-report-html] -workspace = false -command = "cargo" -args = ["llvm-cov", "report", "--html"] - -[tasks.test-cov-report-lcov] -workspace = false -command = "cargo" -args = ["llvm-cov", "report", "--lcov", "--output-path", "lcov.info"] - -[tasks.install] -clear = true -env = { "CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS" = ["gui", "cli"] } -script_runner = "@duckscript" -script.pre = ''' -if is_empty ${INSTALL_PREFIX} - echo Please specify INSTALL_PREFIX environment variable. Recommended: /usr - exit 1 -end - -install_prefix = canonicalize ${INSTALL_PREFIX} -echo Install prefix is ${install_prefix} -''' - -[tasks.uninstall] -clear = true -env = { "CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS" = ["gui", "cli"] } -script_runner = "@duckscript" -script.pre = ''' -if is_empty ${INSTALL_PREFIX} - echo Please specify INSTALL_PREFIX environment variable. Recommended: /usr - exit 1 -end - -install_prefix = canonicalize ${INSTALL_PREFIX} -echo Install prefix is ${install_prefix} -''' - -[tasks.fmt-check] -command = "cargo" -args = ["fmt", "--check"] diff --git a/README.md b/README.md index 5354d562..73049b6d 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,4 @@ See [GitHub Releases](https://github.com/Oppzippy/OpenSCQ30/releases). All files ## Running Tests -### Rust - -`cargo make test` will run all unit and integration tests for the Rust code. - -### Web - -`npm run test` will run unit tests, and `npm run e2etest` will run end to end tests. +`just test` will run all unit and integration tests. To run tests for a specific package, use `just gui/ test` for example. diff --git a/android/Makefile.toml b/android/Makefile.toml deleted file mode 100644 index 95dca73c..00000000 --- a/android/Makefile.toml +++ /dev/null @@ -1,7 +0,0 @@ -[tasks.unit-test] -command = "cargo" -args = ["test", "--lib"] - -[tasks.unit-test-cov] -command = "cargo" -args = ["llvm-cov", "--no-report", "--lib"] diff --git a/android/justfile b/android/justfile new file mode 100644 index 00000000..fd3d7eab --- /dev/null +++ b/android/justfile @@ -0,0 +1,30 @@ +build profile='dev': + #!/usr/bin/env bash + set -euo pipefail + + case "{{profile}}" in + dev) + ./gradlew assembleBluetoothDebug + ;; + release) + ./gradlew assembleBluetoothRelease + ;; + *) + echo Invalid profile + exit 1 + esac + +test: + cargo test + ./gradlew testBluetoothDebugUnitTest + +test-cov: + cargo llvm-cov --no-report + +format: + cargo fmt + ./gradlew ktlintFormat + +format-check: + cargo fmt --check + ./gradlew ktlintCheck diff --git a/cli/Makefile.toml b/cli/Makefile.toml deleted file mode 100644 index 3cda2140..00000000 --- a/cli/Makefile.toml +++ /dev/null @@ -1,66 +0,0 @@ -extend = "../Makefile.toml" - -[tasks.build] -script.main = ''' -cm_run_task build-bin -''' - -[tasks.build-bin] -private = true -command = "cargo" -args = ["build", "@@split(OPENSCQ30_BUILD_FLAGS, )"] - -[tasks.unit-test] -command = "cargo" -args = ["test", "--bins"] - -[tasks.integration-test] -command = "cargo" -args = ["test", "--no-default-features", "--features", "demo", "--test", "*"] - -[tasks.unit-test-cov] -command = "cargo" -args = ["llvm-cov", "--no-report", "--bins"] - -[tasks.integration-test-cov] -command = "cargo" -args = [ - "llvm-cov", - "--no-report", - "--no-default-features", - "--features", - "demo", - "--test", - "*", -] - -[tasks.install] -condition.platforms = ["linux"] -script.main = ''' -bin_path = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release/openscq30_cli -is_bin_built = is_file ${bin_path} -if not ${is_bin_built} - echo Run `cargo make --profile release build` before installing. - exit 1 -end - -echo Installing binary -cp ${bin_path} ${INSTALL_PREFIX}/bin/openscq30_cli -chmod 755 ${INSTALL_PREFIX}/bin/openscq30_cli - -if is_path_exists ${INSTALL_PREFIX}/share/bash-completions/completions - echo Installing bash completions - output = exec ${bin_path} completions bash - bash_completions = set ${output.stdout} - writefile ${INSTALL_PREFIX}/share/bash-completions/completions/openscq30_cli ${bash_completions} -end -''' - -[tasks.uninstall] -condition.platforms = ["linux"] -script.main = ''' -echo Removing binary -rm ${INSTALL_PREFIX}/bin/openscq30_cli -echo Removing bash completions -rm ${INSTALL_PREFIX}/share/bash-completions/completions/openscq30_cli -''' diff --git a/cli/justfile b/cli/justfile new file mode 100644 index 00000000..07dafff6 --- /dev/null +++ b/cli/justfile @@ -0,0 +1,22 @@ +build profile='dev': + cargo build --profile {{profile}} + +test: + cargo test --bins + cargo test --no-default-features --features demo --test '*' + +test-cov: + cargo llvm-cov --no-report --bins + cargo llvm-cov --no-report --no-default-features --features demo --test '*' + +install prefix: + ./scripts/install.sh "{{prefix}}" + +uninstall prefix: + ./scripts/uninstall.sh "{{prefix}}" + +format: + cargo fmt + +format-check: + cargo fmt --check diff --git a/cli/scripts/install.sh b/cli/scripts/install.sh new file mode 100755 index 00000000..3d510448 --- /dev/null +++ b/cli/scripts/install.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_path="$(readlink -f -- "$0")" +script_dir="$(dirname -- "$script_path")" +cd "$script_dir/.." + +install_prefix="$1" +case "$OSTYPE" in + msys | cygwin) bin_ext=".exe" ;; + *) bin_ext="" ;; +esac + +echo Installing binary +install -Dm755 "../target/release/openscq30_cli$bin_ext" -t "$install_prefix/bin/" + +if [[ -z "$OPENSCQ30_SKIP_SHELL_COMPLETIONS" ]]; then + if [[ -d "$install_prefix/share/bash-completions/completions" ]]; then + echo Installing bash completions + "../target/release/openscq30_cli$bin_ext" completions bash > "$install_prefix/share/bash-completions/completions/openscq30_cli" + else + echo Skipping bash completions + fi +fi diff --git a/cli/scripts/uninstall.sh b/cli/scripts/uninstall.sh new file mode 100755 index 00000000..1f7d830c --- /dev/null +++ b/cli/scripts/uninstall.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_path="$(readlink -f -- "$0")" +script_dir="$(dirname -- "$script_path")" +cd "$script_dir/.." + +install_prefix="$1" +case "$OSTYPE" in + msys | cygwin) bin_ext=".exe" ;; + *) bin_ext="" ;; +esac + +echo Removing binary +rm "$install_prefix/bin/openscq30_cli$bin_ext" || true +echo Removing bash completions +rm "$install_prefix/share/bash-completions/completions/openscq30_cli" || true diff --git a/docs/build-linux.md b/docs/build-linux.md index ad21fe3d..2713567f 100644 --- a/docs/build-linux.md +++ b/docs/build-linux.md @@ -3,7 +3,7 @@ Instructions use Ubuntu package names. Package names may differ on other distros. 1. Install rust -2. Install [cargo-make](https://github.com/sagiegurari/cargo-make#installation) +2. Install [Just](https://just.systems/man/en/chapter_4.html) 3. Install libdbus-1-dev pkg-config libgtk-4-dev libadwaita-1-dev -4. `cd` to the `gui` directory and run `cargo make --profile release build`. Note that `--profile release` must come before `build`. -5. The compiled binary can be found at `target/release/openscq30_gui`. Locale files are in `target/release/share`. +4. Run `just gui/ build release` +5. The compiled binary can be found at `target/release/openscq30_gui`. Locale files are in `gui/share`. diff --git a/docs/build-macos.md b/docs/build-macos.md index 01f8dc1d..b369dc7a 100644 --- a/docs/build-macos.md +++ b/docs/build-macos.md @@ -1,7 +1,7 @@ ## Building OpenSCQ30 on MacOS 1. Install rust -2. Install [cargo-make](https://github.com/sagiegurari/cargo-make#installation) -3. Install gtk4 and libadwaita (`brew install gtk4 libadwaita`) -4. `cd` to the `gui` directory and run `cargo make --profile release build`. Note that `--profile release` must come before `build`. -5. The compiled binary can be found at `target/release/openscq30_gui`. Locale files are in `target/release/share`. +2. Install [Just](https://just.systems/man/en/chapter_4.html): `brew install just` +3. Install gtk4 and libadwaita: `brew install gtk4 libadwaita` +4. Run `just gui/ build release` +5. The compiled binary can be found at `target/release/openscq30_gui`. Locale files are in `gui/share`. diff --git a/docs/build-windows.md b/docs/build-windows.md index e9360e7c..5e207c3b 100644 --- a/docs/build-windows.md +++ b/docs/build-windows.md @@ -2,6 +2,6 @@ 1. Install MSYS2 and run the UCRT64 environment. 2. Install dependencies using `pacman -Syu base-devel mingw-w64-ucrt-x86_64-libadwaita mingw-w64-ucrt-x86_64-rust mingw-w64-ucrt-x86_64-pkg-config`. -3. Install cargo-make: `cargo install cargo-make`. +3. Install [Just](https://just.systems/man/en/chapter_4.html): `cargo install just` 4. Run `./packaging/windows/build.sh` 5. The compiled binary along with all dependencies can be found at `packaging/windows/root`. This can then be moved and run from outside of the MSYS2 environment. diff --git a/gui/Makefile.toml b/gui/Makefile.toml deleted file mode 100644 index 7067433e..00000000 --- a/gui/Makefile.toml +++ /dev/null @@ -1,151 +0,0 @@ -extend = "../Makefile.toml" - -[tasks.build] -script_runner = "@duckscript" -script.main = ''' -cm_run_task build-bin -cm_run_task build-locale -''' - -[tasks.build-bin] -private = true -command = "cargo" -args = ["build", "@@split(OPENSCQ30_BUILD_FLAGS, )"] - -[tasks.build-locale] -private = true -script_runner = "@duckscript" -condition = { files_modified = { input = [ - "./po/**/*", - "Makefile.toml", -], output = [ - "${OPENSCQ30_BUILD_DIR}/share/**/*", -] } } -script = ''' -project_name = set com.oppzippy.OpenSCQ30 -out_dir = set ${OPENSCQ30_BUILD_DIR} - -echo "Building en" -mkdir ${OPENSCQ30_BUILD_DIR}/share/locale/en/LC_MESSAGES -exec msgfmt --output-file ${OPENSCQ30_BUILD_DIR}/share/locale/en/LC_MESSAGES/${project_name}.mo ${CARGO_MAKE_WORKING_DIRECTORY}/po/${project_name}.pot - -paths = glob_array ${CARGO_MAKE_WORKING_DIRECTORY}/po/* -for path in ${paths} - if is_dir ${path} - locale = basename ${path} - echo Building ${locale} - mkdir ${OPENSCQ30_BUILD_DIR}/share/locale/${locale}/LC_MESSAGES - exec msgfmt --output-file ${OPENSCQ30_BUILD_DIR}/share/locale/${locale}/LC_MESSAGES/${project_name}.mo ${CARGO_MAKE_WORKING_DIRECTORY}/po/${locale}/${project_name}.po - end -end -''' - -[tasks.unit-test] -command = "cargo" -env.LC_ALL = "C" -env.LANG = "C" -args = ["test", "--bins"] - -[tasks.unit-test-cov] -command = "cargo" -args = ["llvm-cov", "--no-report", "--bins"] - -[tasks.install] -script_runner = "@duckscript" -script.main = ''' -os = os_family -is_windows = eq ${os} windows -if ${is_windows} - bin_name = set openscq30_gui.exe -else - bin_name = set openscq30_gui -end -bin_path = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release/${bin_name} - -is_bin_built = is_file ${bin_path} -is_locale_built = is_dir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release/share - -if not ${is_bin_built} and ${is_locale_built} - echo Run `cargo make --profile release build` before installing. - exit 1 -end - -echo Installing to ${INSTALL_PREFIX} - -echo Installing bin -cp ${bin_path} ${INSTALL_PREFIX}/bin/${bin_name} -if not ${is_windows} - chmod 755 ${INSTALL_PREFIX}/bin/${bin_name} -end - -echo Installing locales -cp_glob ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/release/share/**/* ${INSTALL_PREFIX}/share/ - -echo Installing icon -cp ${CARGO_MAKE_WORKING_DIRECTORY}/resources/com.oppzippy.OpenSCQ30.svg ${INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/com.oppzippy.OpenSCQ30.svg - -echo Installing desktop file -cp ${CARGO_MAKE_WORKING_DIRECTORY}/resources/com.oppzippy.OpenSCQ30.desktop ${INSTALL_PREFIX}/share/applications/com.oppzippy.OpenSCQ30.desktop - -echo Installing AppStream Catalog XML -cp ${CARGO_MAKE_WORKING_DIRECTORY}/resources/com.oppzippy.OpenSCQ30.metainfo.xml ${INSTALL_PREFIX}/share/metainfo/com.oppzippy.OpenSCQ30.metainfo.xml -''' - -[tasks.uninstall] -script.main = ''' -os = os_family -is_windows = eq ${os} windows -if ${is_windows} - bin_name = set "openscq30_gui.exe" -else - bin_name = set "openscq30_gui" -end - -echo Removing binary -rm ${INSTALL_PREFIX}/bin/${bin_name} - -echo Removing locales -mo_files = glob_array ${INSTALL_PREFIX}/share/locale/*/LC_MESSAGES/com.oppzippy.OpenSCQ30.mo -for path in ${mo_files} - rm ${path} -end - -echo Removing icon -rm ${INSTALL_PREFIX}/share/icons/hicolor/scalable/apps/com.oppzippy.OpenSCQ30.svg - -echo Removing desktop file -rm ${INSTALL_PREFIX}/share/applications/com.oppzippy.OpenSCQ30.desktop - -echo Removing AppStream Catalog XML -rm ${INSTALL_PREFIX}/share/metainfo/com.oppzippy.OpenSCQ30.metainfo.xml -''' - -[tasks.update-po-files] -script_runner = "@duckscript" -script = ''' - -project_name = set com.oppzippy.OpenSCQ30 - -echo Generating template -if is_file ./po/${project_name}.pot - exec xgettext --files-from ./po/POTFILES.in --join-existing --add-comments --sort-output --output ./po/${project_name}.pot -else - exec xgettext --files-from ./po/POTFILES.in --add-comments --sort-output --output ./po/${project_name}.pot -end - -content = readfile ./po/LINGUAS -locales = split ${content} \n - -for locale in ${locales} - is_locale_empty = is_empty ${locale} - if not ${is_locale_empty} - echo "Updating ${locale}" - mkdir ./po/${locale} - if is_file ./po/${locale}/${project_name}.po - exec msgmerge --update ./po/${locale}/${project_name}.po ./po/${project_name}.pot - else - exec msginit --input ./po/${project_name}.pot --locale ${locale} --output ./po/${locale}/${project_name}.po - end - end -end -''' diff --git a/gui/justfile b/gui/justfile new file mode 100644 index 00000000..8d93a728 --- /dev/null +++ b/gui/justfile @@ -0,0 +1,31 @@ +build profile='dev': + #!/usr/bin/env bash + set -euo pipefail + if [[ "{{profile}}" != "dev" && "{{profile}}" != "release" ]]; then + echo "Invalid profile: {{profile}}" + exit 1 + fi + + cargo build --profile {{profile}} + ./scripts/build-locale.sh ./share + +test: + cargo test + +test-cov: + cargo llvm-cov --no-report + +install install_prefix: (build 'release') + ./scripts/install.sh "{{install_prefix}}" + +uninstall install_prefix: + ./scripts/uninstall.sh "{{install_prefix}}" + +update-po-files: + ./scripts/update-po-files.sh + +format: + cargo fmt + +format-check: + cargo fmt --check diff --git a/gui/scripts/build-locale.sh b/gui/scripts/build-locale.sh index 9382335c..0b7d47b3 100755 --- a/gui/scripts/build-locale.sh +++ b/gui/scripts/build-locale.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -set -e -set -o pipefail +set -euo pipefail PROJECT_NAME="com.oppzippy.OpenSCQ30" script_path="$(readlink -f -- "$0")" -script_dir="$(dirname -- $script_path)" +script_dir="$(dirname -- "$script_path")" gui_dir="$script_dir/.." out_dir=$1 diff --git a/gui/scripts/install.sh b/gui/scripts/install.sh new file mode 100755 index 00000000..b6905a0f --- /dev/null +++ b/gui/scripts/install.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_path="$(readlink -f -- "$0")" +script_dir="$(dirname -- "$script_path")" +cd "$script_dir/.." + +install_prefix="$1" + +case "$OSTYPE" in + msys | cygwin) bin_ext=".exe" ;; + *) bin_ext="" ;; +esac + +echo "Installing to $1" +install -Dm755 "../target/release/openscq30_gui$bin_ext" -t "$install_prefix/bin/" +install -Dm644 ./resources/com.oppzippy.OpenSCQ30.desktop -t "$install_prefix/share/applications" +install -Dm644 ./resources/com.oppzippy.OpenSCQ30.metainfo.xml -t "$install_prefix/share/metainfo" +install -Dm644 ./resources/com.oppzippy.OpenSCQ30.svg -t "$install_prefix/share/icons/hicolor/scalable/apps" +cp -r ./share/* "$install_prefix/" diff --git a/gui/scripts/uninstall.sh b/gui/scripts/uninstall.sh new file mode 100755 index 00000000..5bd88010 --- /dev/null +++ b/gui/scripts/uninstall.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_path="$(readlink -f -- "$0")" +script_dir="$(dirname -- "$script_path")" +cd "$script_dir/.." + +install_prefix="$1" + +case "$OSTYPE" in + msys | cygwin) bin_ext=".exe" ;; + *) bin_ext="" ;; +esac + +echo "Uninstalling from $install_prefix" +echo Removing binary +rm "$install_prefix/bin/openscq30_gui$bin_ext" || true +echo Removing desktop file +rm "$install_prefix/share/applications/com.oppzippy.OpenSCQ30.desktop" || true +echo Removing appstream metainfo +rm "$install_prefix/share/metainfo/com.oppzippy.OpenSCQ30.metainfo.xml" || true +echo Removing icon +rm "$install_prefix/share/icons/hicolor/scalable/apps/com.oppzippy.OpenSCQ30.svg" || true +echo Removing locales +rm "$install_prefix"/share/locale/*/LC_MESSAGES/com.oppzippy.OpenSCQ30.mo || true diff --git a/gui/scripts/update-po-files.sh b/gui/scripts/update-po-files.sh index 3ae3c9b4..1158c74f 100755 --- a/gui/scripts/update-po-files.sh +++ b/gui/scripts/update-po-files.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -set -e -set -o pipefail +set -euo pipefail PROJECT_NAME="com.oppzippy.OpenSCQ30" script_path="$(readlink -f -- "$0")" -script_dir="$(dirname -- $script_path)" +script_dir="$(dirname -- "$script_path")" cd "$script_dir/.." echo "Updating POTFILES.in" diff --git a/justfile b/justfile new file mode 100644 index 00000000..3e0cebce --- /dev/null +++ b/justfile @@ -0,0 +1,67 @@ +default: + @just --choose + +build profile='dev': + just gui/ build '{{profile}}' + just cli/ build '{{profile}}' + just android/ build '{{profile}}' + just web/ build '{{profile}}' + +test: + just gui/ test + just cli/ test + just android/ test + just web/ test + +test-cov: + just gui/ test-cov + just cli/ test-cov + just android/ test-cov + just web/ test-cov + +llvm-cov-clean: + cargo llvm-cov clean --workspace + +test-cov-report format='lcov': + #!/usr/bin/env bash + set -eou pipefail + + case '{{format}}' in + lcov) + format_args="--lcov --output-path lcov.info" + ;; + html) + format_args="--html" + ;; + *) + echo Invalid format + exit 1 + ;; + esac + + cargo llvm-cov report $format_args + +install prefix: + just gui/ install '{{prefix}}' + just cli/ install '{{prefix}}' + +uninstall prefix: + just gui/ uninstall '{{prefix}}' + just cli/ uninstall '{{prefix}}' + +format: + just android/ format + just cli/ format + just gui/ format + just lib/ format + just lib_protobuf/ format + just web/ format + +format-check: + just android/ format-check + just cli/ format-check + just gui/ format-check + just lib/ format-check + just lib_protobuf/ format-check + just web/ format-check + diff --git a/lib/Makefile.toml b/lib/Makefile.toml deleted file mode 100644 index 5b06b0f0..00000000 --- a/lib/Makefile.toml +++ /dev/null @@ -1,21 +0,0 @@ -[tasks.unit-test] -dependencies = ["unit-test-bluetooth", "unit-test-demo"] - -[tasks.unit-test-bluetooth] -command = "cargo" -args = ["test", "--lib", "--features", "bluetooth"] - -[tasks.unit-test-demo] -command = "cargo" -args = ["test", "--lib", "--features", "demo"] - -[tasks.unit-test-cov] -dependencies = ["unit-test-cov-bluetooth", "unit-test-cov-demo"] - -[tasks.unit-test-cov-bluetooth] -command = "cargo" -args = ["llvm-cov", "--no-report", "--lib", "--features", "bluetooth"] - -[tasks.unit-test-cov-demo] -command = "cargo" -args = ["llvm-cov", "--no-report", "--lib", "--features", "demo"] diff --git a/lib/justfile b/lib/justfile new file mode 100644 index 00000000..35bbd765 --- /dev/null +++ b/lib/justfile @@ -0,0 +1,11 @@ +test: + cargo test + +test-cov: + cargo llvm-cov --no-report + +format: + cargo fmt + +format-check: + cargo fmt --check diff --git a/lib_protobuf/Makefile.toml b/lib_protobuf/Makefile.toml deleted file mode 100644 index 95dca73c..00000000 --- a/lib_protobuf/Makefile.toml +++ /dev/null @@ -1,7 +0,0 @@ -[tasks.unit-test] -command = "cargo" -args = ["test", "--lib"] - -[tasks.unit-test-cov] -command = "cargo" -args = ["llvm-cov", "--no-report", "--lib"] diff --git a/lib_protobuf/justfile b/lib_protobuf/justfile new file mode 100644 index 00000000..35bbd765 --- /dev/null +++ b/lib_protobuf/justfile @@ -0,0 +1,11 @@ +test: + cargo test + +test-cov: + cargo llvm-cov --no-report + +format: + cargo fmt + +format-check: + cargo fmt --check diff --git a/packaging/appimage/AppImageBuilder.yml b/packaging/appimage/AppImageBuilder.yml index 8a4db04a..10917900 100644 --- a/packaging/appimage/AppImageBuilder.yml +++ b/packaging/appimage/AppImageBuilder.yml @@ -1,10 +1,7 @@ version: 1 script: - - export CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS="gui" - - export INSTALL_PREFIX="$(pwd)/AppDir/usr" - - cargo make --profile release --cwd ../.. build - rm -rf ./AppDir || true - - cargo make --profile release --cwd ../.. install + - just ../../gui/ install "$PWD/AppDir/usr" AppDir: app_info: diff --git a/packaging/windows/build.ps1 b/packaging/windows/build.ps1 deleted file mode 100644 index aa301ad1..00000000 --- a/packaging/windows/build.ps1 +++ /dev/null @@ -1,46 +0,0 @@ -$ErrorActionPreference = "Stop" -$root = "$PSScriptRoot\..\.." - -cargo make --profile release --env CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS=gui --cwd $root build - -function Write-Filtered-Errors { - param ( - $errors - ) - $errors | ForEach-Object { - if ($_ -notmatch "already exists") { - Write-Error $_ - } - } -} - -$directoriesToCreate = @( - "$root\packaging\windows\root\bin" - "$root\packaging\windows\root\share\locale" - "$root\packaging\windows\root\share\glib-2.0\schemas" -) -$filesToCopyNoOverwrite = @{ - "$root\LICENSE.txt" = "$root\packaging\windows\root"; - "C:\gtk-build\gtk\x64\release\bin\*.dll" = "$root\packaging\windows\root\bin"; - "C:\gtk-build\gtk\x64\release\bin\gdbus.exe" = "$root\packaging\windows\root\bin"; - "C:\gtk-build\gtk\x64\release\share\glib-2.0\schemas\*" = "$root\packaging\windows\root\share\glib-2.0\schemas"; - "C:\gtk-build\gtk\x64\release\share\locale\*" = "$root\packaging\windows\root\share\locale"; -} -$filesToCopy = @{ - "$root\target\release\openscq30_gui.exe" = "$root\packaging\windows\root\bin"; - "$root\target\release\share\*" = "$root\packaging\windows\root\share"; -} - -foreach ($directory in $directoriesToCreate) { - New-Item -Type Directory -Path $directory -ErrorVariable errors -ErrorAction SilentlyContinue - Write-Filtered-Errors $errors -} -foreach ($source in $filesToCopy.Keys) { - Copy-Item -Recurse -Force -Path $source -Destination $filesToCopy[$source] -} -foreach ($source in $filesToCopyNoOverwrite.Keys) { - Copy-Item -Recurse -Path $source -Destination $filesToCopyNoOverwrite[$source] -ErrorVariable errors -ErrorAction SilentlyContinue - Write-Filtered-Errors $errors -} - -& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "$root\packaging\windows\setup.iss" diff --git a/packaging/windows/build.sh b/packaging/windows/build.sh index dd2d7bff..0fe50f35 100644 --- a/packaging/windows/build.sh +++ b/packaging/windows/build.sh @@ -1,9 +1,8 @@ #!/usr/bin/env bash -set -e -set -o pipefail +set -euo pipefail script_path="$(readlink -f -- "$0")" -script_dir="$(dirname -- $script_path)" +script_dir="$(dirname -- "$script_path")" project_root="$script_dir/../.." input_exe="$project_root/target/release/openscq30_gui.exe" @@ -11,29 +10,28 @@ package_type="ucrt64" output_dir="$script_dir/root" # Install OpenSCQ30 -export CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS=gui -export INSTALL_PREFIX="$output_dir" -cargo make --profile release --cwd "$project_root" build -cargo make --profile release --cwd "$project_root" install +just "$project_root/gui/" install "$output_dir" # Determine what dlls are required, and which packages those dlls belong to +dependencies="" list=$(ldd "$input_exe" | grep "/$package_type" | sed "s/.dll.*/.dll/") for dll in $list; do package=$(pacman -Qo "$dll" | awk '{ print $5 }') - dependencies="$dependencies\n$package" + dependencies="$dependencies"$'\n'"$package" done -dependencies=$(printf "$dependencies" | sort | uniq) +dependencies=$(printf "%s" "$dependencies" | sort | uniq) echo "packages: $dependencies" # Find all dll files belonging to packages that own required dll files +# shellcheck disable=SC2086 files=$(pacman -Ql $dependencies | sed -E "s/^[^ ]+ //" | grep -E "^\/$package_type\/bin/.*\.dll" | sort | uniq) echo "files: $files" # Install the files, stripping the /ucrt64 prefix for file in $files; do if [[ -f "$file" ]]; then - file_without_prefix=$(echo $file | sed -E "s/^\/$package_type//") + file_without_prefix=$(echo "$file" | sed -E "s/^\/$package_type//") output_file="$output_dir/$file_without_prefix" output_file_dir=$(dirname "$output_file") mkdir -p "$output_file_dir" diff --git a/web/justfile b/web/justfile new file mode 100644 index 00000000..740c3fee --- /dev/null +++ b/web/justfile @@ -0,0 +1,21 @@ +export RUSTFLAGS := "--cfg=web_sys_unstable_apis" + +build: + npm run build + +_build-wasm: + npm run build:wasm + +test: (_build-wasm) + cd wasm && cargo test + npm run test + npm run e2etest + +test-cov: + cd wasm && cargo llvm-cov --no-report + +format: + cd wasm && cargo fmt + +format-check: + cd wasm && cargo fmt --check diff --git a/web/wasm/Makefile.toml b/web/wasm/Makefile.toml deleted file mode 100644 index c8a79296..00000000 --- a/web/wasm/Makefile.toml +++ /dev/null @@ -1,13 +0,0 @@ -[tasks.test] -clear = true -dependencies = ["unit-test"] - -[tasks.unit-test] -command = "cargo" -env = { "RUSTFLAGS" = "--cfg=web_sys_unstable_apis" } -args = ["test", "--lib"] - -[tasks.unit-test-cov] -command = "cargo" -env = { "RUSTFLAGS" = "--cfg=web_sys_unstable_apis" } -args = ["llvm-cov", "--no-report", "--lib"] diff --git a/web/wasm/justfile b/web/wasm/justfile new file mode 100644 index 00000000..c0853072 --- /dev/null +++ b/web/wasm/justfile @@ -0,0 +1,11 @@ +export RUSTFLAGS='--cfg=web_sys_unstable_apis' + +build: + wasm-pack build --no-pack + wasm-pack build --no-pack --dev + +test: + cargo test + +test-cov: + cargo llvm-cov --no-report