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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#!/usr/bin/env -S bash -e
# Setup the repository and local system for development
cd "$(dirname "$0")/.."
HELPER=./contrib/ci/fwupd_setup_helpers.py
HELPER_ARGS="-y"
rename_branch() {
OLD=master
NEW=main
if git log $OLD >/dev/null 2>&1 &&
git remote get-url origin 2>&1 | grep fwupd/fwupd.git >/dev/null 2>&1; then
echo ""
read -p "Rename existing $OLD branch to $NEW? (y/N) " question
if [ "$question" = "y" ]; then
git branch -m $OLD $NEW
git fetch origin
git branch -u origin/$NEW $NEW
git remote set-head origin -a
fi
fi
}
setup_deps() {
if [ -z "$CI" ]; then
read -p "Install build dependencies? (y/N) " question
else
question=y
fi
if [ "$question" = "y" ]; then
python3 $HELPER install-dependencies $HELPER_ARGS -y
fi
}
setup_run_wrappers() {
BASE=../../contrib/
BIN=venv/bin/
TEMPLATE=${BASE}/launch-venv.sh
# launch wrappers
for F in fwupdtool fwupdmgr fwupd; do
rm -f ${BIN}/${F}
ln -s $TEMPLATE ${BIN}/${F}
done
# build wrapper
rm -f ${BIN}/build-fwupd
ln -s ${BASE}/build-venv.sh ${BIN}/build-fwupd
rm -f ${BIN}/test-fwupd
ln -s ${BASE}/test-venv.sh ${BIN}/test-fwupd
}
setup_vscode() {
# Add default vscode settings and debug launcher
SOURCED=./contrib/vscode
TARGETD=./.vscode
SETTINGS_F=settings.json
LAUNCH_F=launch.json
TASK_F=tasks.json
for f in $SETTINGS_F $LAUNCH_F $TASK_F; do
TEMPLATE=${SOURCED}/${f}
TARGETF=${TARGETD}/${f}
mkdir -p ${TARGETD}
echo "Copy ${TEMPLATE} to ${TARGETF}."
cp "${TEMPLATE}" "${TARGETF}"
done
}
setup_git() {
if [ -z "$CI" ]; then
echo "Configuring git environment"
git config include.path ../.gitconfig
fi
}
install_pip() {
package=$1
args=$2
if ! python3 -m pip install $package $args; then
python3 $HELPER install-pip $HELPER_ARGS -y
fi
#try once more
python3 -m pip install $package
}
setup_virtualenv() {
echo "Setting up virtualenv"
if ! which virtualenv >/dev/null 2>&1; then
install_pip virtualenv
fi
virtualenv --system-site-packages venv --prompt fwupd
source venv/bin/activate
cat >>venv/bin/activate <<EOF
echo "To build or rebuild fwupd within development environment run:"
echo ""
echo "# build-fwupd"
echo ""
echo "To run the test suite run:"
echo ""
echo "# test-fwupd"
echo ""
echo "To run any tool under gdbserver add DEBUG=1 to env, for example:"
echo ""
echo "# DEBUG=1 fwupdtool get-devices"
echo ""
echo "To leave fwupd development environment run:"
echo ""
echo "# deactivate"
. data/bash-completion/fwupdtool
. data/bash-completion/fwupdmgr
export MANPATH=./venv/dist/share/man:
EOF
}
setup_precommit() {
if [ -z "$CI" ]; then
echo "Configuring pre-commit hooks"
install_pip pre-commit
pre-commit install
fi
}
setup_prepush() {
if [ -z "$CI" ]; then
echo ""
read -p "Run tests locally before pushing to remote branches? THIS WILL SLOW DOWN EVERY PUSH but reduce the risk of failing CI. (y/N) " question
else
question=y
fi
if [ "$question" = "y" ]; then
pre-commit install -t pre-push
else
pre-commit uninstall -t pre-push
fi
}
check_markdown() {
python3 $HELPER test-markdown
}
check_jinja2() {
python3 $HELPER test-jinja2
}
check_meson() {
python3 $HELPER test-meson
}
detect_os() {
for i in "$@"; do
case $i in
--os=*)
OS="${i#*=}"
shift
;;
--debug)
DEBUG=1
shift
;;
*) ;;
esac
done
if [ -z $OS ]; then
OS=$(python3 $HELPER detect-profile)
if [ -z "$OS" ]; then
install_pip distro
OS=$(python3 $HELPER detect-profile)
fi
echo "Using OS profile $OS to setup"
fi
if [ -n "$OS" ]; then
HELPER_ARGS="$HELPER_ARGS --os $OS"
fi
if [ -n "$DEBUG" ]; then
set -x
HELPER_ARGS="$HELPER_ARGS --debug"
fi
}
howto() {
echo ""
echo "To enter fwupd development environment run:"
echo ""
echo "# source venv/bin/activate"
echo ""
}
#already setup
if [ -f venv/bin/build-fwupd ]; then
echo "$0 has already been run"
howto
exit 0
fi
PYTHON_VERSION=$(python3 --version 2>/dev/null)
if [ -z "$PYTHON_VERSION" ]; then
echo "Install python3 to run this script" >&2
exit 1
fi
#needed for arguments for some commands
detect_os "$@"
#if interactive install build deps and prepare environment
if [ -t 2 ]; then
case $OS in
debian | ubuntu | arch | fedora | darwin | freebsd)
setup_deps
;;
esac
rename_branch
fi
setup_virtualenv
setup_run_wrappers
check_markdown
check_jinja2
setup_vscode
setup_git
check_meson
setup_precommit
#needs to be after pre-commit is sourced
if [ -t 2 ]; then
setup_prepush
fi
howto
|