|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +# exit whenever a command called in this script fails |
| 4 | +set -eo pipefail |
| 5 | + |
| 6 | +appdir="" |
| 7 | + |
| 8 | +show_usage() { |
| 9 | + echo "Usage: bash $0 --appdir <AppDir>" |
| 10 | +} |
| 11 | + |
| 12 | +while [ "$1" != "" ]; do |
| 13 | + case "$1" in |
| 14 | + --plugin-api-version) |
| 15 | + echo "0" |
| 16 | + exit 0 |
| 17 | + ;; |
| 18 | + --appdir) |
| 19 | + appdir="$2" |
| 20 | + shift |
| 21 | + shift |
| 22 | + ;; |
| 23 | + *) |
| 24 | + echo "Invalid argument: $1" |
| 25 | + echo |
| 26 | + show_usage |
| 27 | + exit 2 |
| 28 | + esac |
| 29 | +done |
| 30 | + |
| 31 | +if [[ "$appdir" == "" ]]; then |
| 32 | + show_usage |
| 33 | + exit 2 |
| 34 | +fi |
| 35 | + |
| 36 | +# we just need to copy the grantlee plugins properly to the Qt plugins dir which linuxdeploy-plugin-qt defines |
| 37 | +# http://www.grantlee.org/apidox_generictypes/using_and_deploying.html |
| 38 | + |
| 39 | +echo "### NOTE: THIS PLUGIN MUST BE USED IN COMBINATION WITH LINUXDEPLOY'S QT PLUGIN! ###" |
| 40 | + |
| 41 | +# grantlee doesn't provide any _easy_ way to find the plugins' path, therefore we ask CMake |
| 42 | + |
| 43 | +echo "Using CMake to find grantlee5 plugins path (note: you may need to specify your path manually using \$GRANTLEE5_PLUGINS_DIR, e.g., when cross-compiling)" |
| 44 | + |
| 45 | +if [[ "$GRANTLEE5_PLUGINS_DIR" == "" ]]; then |
| 46 | + tempdir="$(mktemp -d /tmp/linuxdeploy-plugin-grantlee-XXXXX)" |
| 47 | + |
| 48 | + _cleanup() { |
| 49 | + cmake_log="$tempdir"/cmake.log |
| 50 | + if [[ -f "$cmake_log" ]]; then |
| 51 | + echo "CMake failed, log:" |
| 52 | + cat "$cmake_log" |
| 53 | + fi |
| 54 | + |
| 55 | + [[ -d "$tempdir" ]] && rm -r "$tempdir" |
| 56 | + } |
| 57 | + trap _cleanup EXIT |
| 58 | + |
| 59 | + pushd "$tempdir" &>/dev/null |
| 60 | + |
| 61 | + cat > CMakeLists.txt <<\EOF |
| 62 | +cmake_minimum_required(VERSION 3.10) |
| 63 | +project(linuxdeploy-plugin-grantlee) |
| 64 | +
|
| 65 | +find_package(Grantlee5 REQUIRED) |
| 66 | +
|
| 67 | +set(imported_target "Grantlee5::defaultfilters") |
| 68 | +
|
| 69 | +message(STATUS "Fetching imported location for target ${imported_target}") |
| 70 | +
|
| 71 | +get_property(imported_location TARGET "${imported_target}" PROPERTY IMPORTED_LOCATION_NONE) |
| 72 | +message(STATUS "Imported location: ${imported_location}") |
| 73 | +
|
| 74 | +file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imported-location" "${imported_location}") |
| 75 | +EOF |
| 76 | + |
| 77 | + cmake . &>cmake.log |
| 78 | + |
| 79 | + # clean up log if everything worked, otherwise it would be printed by the cleanup handler |
| 80 | + rm cmake.log |
| 81 | + |
| 82 | + imported_location="$(cat imported-location)" |
| 83 | + |
| 84 | + if [[ "$imported_location" == "" ]]; then |
| 85 | + echo "Error: could not find plugins location with CMake" |
| 86 | + exit 2 |
| 87 | + fi |
| 88 | + |
| 89 | + GRANTLEE5_PLUGINS_DIR="$(dirname "$imported_location")" |
| 90 | + |
| 91 | + popd &>/dev/null |
| 92 | +fi |
| 93 | + |
| 94 | +if [[ ! -d "$GRANTLEE5_PLUGINS_DIR" ]]; then |
| 95 | + echo "Error: grantlee5 plugins directory does not exist or could not be found" |
| 96 | + exit 2 |
| 97 | +fi |
| 98 | + |
| 99 | +# guess grantlee version from the plugin path |
| 100 | +# this should always be the last component, as the plugins need to be stored in a directory like .../grantlee/<version>/grantlee*.so |
| 101 | +grantlee5_version="$(echo "$GRANTLEE5_PLUGINS_DIR" | rev | cut -d/ -f1 | rev)" |
| 102 | + |
| 103 | +target_dir="$appdir"/usr/plugins/grantlee/"$grantlee5_version" |
| 104 | + |
| 105 | +echo "Copying plugins from $GRANTLEE5_PLUGINS_DIR to $target_dir" |
| 106 | +install -v -D -t "$target_dir" "$GRANTLEE5_PLUGINS_DIR"/* |
| 107 | + |
| 108 | +echo "Using linuxdeploy to deploy dependencies" |
| 109 | + |
| 110 | +if ! test -x "$LINUXDEPLOY"; then |
| 111 | + echo "Error: \$LINUXDEPLOY is not set" |
| 112 | + exit 2 |
| 113 | +fi |
| 114 | + |
| 115 | +"$LINUXDEPLOY" --appdir "$appdir" --plugin qt --deploy-deps-only "$target_dir" |
0 commit comments