Skip to content

Commit 156ac79

Browse files
committed
Add grantlee5 plugin
1 parent e1514af commit 156ac79

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

grantlee5/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# linuxdeploy-plugin-grantlee5
2+
3+
This linuxdeploy plugin copies grantlee5's plugins into the AppDir and uses linuxdeploy and the Qt plugin to deploy the dependencies.
4+
5+
The plugin uses CMake to auto-detect the plugins path. Should this fail (e.g., because they cannot be found by CMake, or during cross compilation), users can specify the directory manually in `$GRANTLEE5_PLUGINS_DIR`
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

Comments
 (0)