forked from pia-foss/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtcbuild.sh
executable file
·148 lines (135 loc) · 4.21 KB
/
qtcbuild.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env bash
# Copyright (c) 2024 Private Internet Access, Inc.
#
# This file is part of the Private Internet Access Desktop Client.
#
# The Private Internet Access Desktop Client is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# The Private Internet Access Desktop Client is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the Private Internet Access Desktop Client. If not, see
# <https://www.gnu.org/licenses/>.
function print_usage() {
echo "usage:"
echo "$0 [--] <command> <args>"
echo "$0 --path"
echo "$0 --help"
echo ""
echo "Finds the active Qt Creator build configuration of pia_desktop and runs"
echo "<command> in that build. Qt Creator should be running in order to"
echo "detect the build configuration that is currently in use."
echo ""
echo "Simplifies running commands from the console while developing with Qt"
echo "Creator. For example, instead of:"
echo " ../build-pia_desktop-Desktop_Qt_5_12_3_clang_64bit5-Debug/Debug/install-root/Private\ Internet\ Access.app/Contents/MacOS/pia-cli -v"
echo "use:"
echo " ./qtcbuild.sh pia-cli -v"
echo ""
echo "With --path, instead locates the build and prints the bin path, for"
echo "example:"
echo " nano $(./qtcbuild.sh --path)/data/settings.json"
echo "(note: the data dir location is platform-specific)"
echo ""
}
if [ $# -lt 1 ]; then
print_usage
exit 1
fi
print_path_only=""
args_done=""
while [ "$#" -gt 0 ] && [ -z "$args_done" ]; do
case "$1" in
"--help")
print_usage
exit 0
;;
"--path")
print_path_only=1
shift
;;
"--")
args_done=1
shift
;;
"--*")
echo "Unknown option $1"
exit 1
;;
*)
# Not an option, start of command (don't shift this arg)
args_done=1
;;
esac
done
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Find the newest .bg.lock file in any build directory to determine which build
# configuration is active.
NEWEST_BG_LOCK=""
for bglock in "$ROOT"/../build-pia_desktop-*/*/*.bg.lock; do
if [ ! -f "$bglock" ]; then
break
fi
if [ -z "$NEWEST_BG_LOCK" ] || [ "$bglock" -nt "$NEWEST_BG_LOCK" ]; then
NEWEST_BG_LOCK="$bglock"
fi
done
if [ ! -f "$NEWEST_BG_LOCK" ]; then
echo "Could not find Qt Creator's active build configuration."
echo "Is pia_desktop.qbs open in Qt Creator, and has a build finished?"
exit 1
fi
BUILD_ROOT=$(cd "$(dirname "$NEWEST_BG_LOCK")" && pwd)
BUILD_BIN_PATH=""
case $OSTYPE in
darwin*)
BUILD_BIN_PATH="install-root/*.app/Contents/MacOS/"
BUILD_LIB_PATH="install-root/*.app/Contents/MacOS/"
;;
msys*)
BUILD_BIN_PATH="install-root/"
BUILD_LIB_PATH="install-root/"
;;
linux*)
BUILD_BIN_PATH="install-root/bin/"
BUILD_LIB_PATH="install-root/lib/"
;;
*)
echo "OS type not known: $OSTYPE"
exit 1
;;
esac
# Add matching directories to PATH
for dir in $BUILD_ROOT/$BUILD_BIN_PATH; do
if [ ! -d "$dir" ]; then
echo "Unable to find binary directory matching $dir" >&2
exit 1
fi
# With --path, instead just print paths
if [ ! -z "$print_path_only" ]; then
# Canonicalize the path
(cd "$dir" && pwd)
else
# Add to PATH
PATH=$dir:$PATH
fi
done
# Run the command with the new PATH (if not just printing paths)
if [ -z "$print_path_only" ]; then
for dir in $BUILD_ROOT/$BUILD_LIB_PATH; do
case "$OSTYPE" in
linux*)
export LD_LIBRARY_PATH=$dir:$LD_LIBRARY_PATH
;;
*)
;;
esac
done
"$@"
fi