Skip to content

Commit

Permalink
Add support to sudo if necessary
Browse files Browse the repository at this point in the history
Instead if executing system-relevant changes directly, use `sudo` on
Ubuntu-based machines.

Simplifies the installation procedure.
  • Loading branch information
MartinNowack authored and ccadar committed Mar 30, 2022
1 parent 71c1c45 commit 818275b
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 60 deletions.
9 changes: 9 additions & 0 deletions scripts/build/common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ function get_git_hash() {
else
echo "${commit_id:0:7}"
fi
}

function with_sudo() {
echo "Checking sudo $@"
if [[ $(whoami) != "root" ]]; then
sudo "$@"
else
"$@"
fi
}
45 changes: 22 additions & 23 deletions scripts/build/p-clang-linux-ubuntu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,36 @@ install_binary_artifact_clang() {
[[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="-${LLVM_VERSION}"
[[ "${LLVM_VERSION_MAJOR}" -ge 7 ]] && version="-${LLVM_VERSION_MAJOR}"

# apt.llvm packages for Trusty clang 5.0 package is broken with atomics. Don't use it.
if [[ "${LLVM_VERSION_MAJOR}" -gt 6 ]]; then
# Add certificate
apt update -y
dependencies=(
ca-certificates
wget
lsb-release
gnupg
)

apt -y --no-install-recommends install "${dependencies[@]}"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add -

# Add repository
codename="$(lsb_release --codename --short)"
apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
echo "${apt_entry}" >> /etc/apt/sources.list
apt update -y
fi
source "${DIR}/common-functions"

# Add certificate
with_sudo apt update -y
dependencies=(
ca-certificates
wget
lsb-release
gnupg
)

with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -

# Add repository
codename="$(lsb_release --codename --short)"
apt_entry="deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}${version} main"
if [[ ! $(grep -rq "${apt_entry}" /etc/apt) ]]; then
echo "${apt_entry}" | with_sudo tee -a /etc/apt/sources.list
with_sudo apt update -y
fi

apt update -y
with_sudo apt update -y
dependencies=(
"llvm${version}"
"clang${version}"
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}" || return 1
with_sudo apt -y --no-install-recommends install "${dependencies[@]}" || return 1
}

get_docker_config_id_clang() {
Expand Down
5 changes: 3 additions & 2 deletions scripts/build/p-gtest-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
install_build_dependencies_gtest() {
apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
ca-certificates
Expand All @@ -8,5 +9,5 @@ install_build_dependencies_gtest() {
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
10 changes: 6 additions & 4 deletions scripts/build/p-klee-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install_build_dependencies_klee() {
apt update -y
source "${DIR}/common-functions"

# Add Kitware's certificate for CMake
dependencies=(
Expand Down Expand Up @@ -42,8 +42,10 @@ install_build_dependencies_klee() {
dependencies+=(doxygen graphviz)
fi

apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"

pip3 install lit
pip3 install tabulate
pip3 install --user lit
pip3 install --user tabulate
base_path="$(python3 -m site --user-base)"
export PATH="$PATH:${base_path}/bin"
}
8 changes: 7 additions & 1 deletion scripts/build/p-klee-osx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
install_build_dependencies_klee() {
brew upgrade python # upgrade to Python 3
brew link --overwrite python

if [[ $(to_bool "${ENABLE_DOXYGEN}") -eq 1 ]]; then
brew install doxygen graphviz
fi
pip3 install lit tabulate

pip3 install --user --upgrade lit tabulate

# Get path of package location
base_path=$(python3 -m site --user-base)
export PATH="${base_path}/bin:$PATH"
}
1 change: 1 addition & 0 deletions scripts/build/p-klee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ validate_build_config_klee() {
}

setup_build_variables_klee() {
source "${DIR}/common-functions"
KLEE_SUFFIX="${LLVM_VERSION_SHORT}${SOLVER_SUFFIX}${SANITIZER_SUFFIX}"
KLEE_BUILD_DIR="${BASE}/klee_build${KLEE_SUFFIX}"
KLEE_SRC="$DIR/../../"
Expand Down
14 changes: 9 additions & 5 deletions scripts/build/p-libcxx-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install_build_dependencies_libcxx() {
apt-get update -y
install_build_dependencies_libcxx() {
source "${DIR}/common-functions"

# Add Kitware's certificate for CMake
dependencies=(
Expand All @@ -19,8 +19,10 @@ install_build_dependencies_libcxx() {
codename="$(lsb_release --codename --short)"
apt-add-repository "deb https://apt.kitware.com/ubuntu/ ${codename} main"

with_sudo apt-get update -y
dependencies=(
build-essential
ca-certificates
git
python3
python3-pip
Expand All @@ -29,7 +31,9 @@ install_build_dependencies_libcxx() {
file # Needed for wllvm
)

apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"

pip3 install wllvm
}
pip3 install --user wllvm
base_path="$(python3 -m site --user-base)"
export PATH="$PATH:${base_path}/bin"
}
4 changes: 3 additions & 1 deletion scripts/build/p-libcxx-osx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ install_build_dependencies_libcxx() {
set +e
brew upgrade python # upgrade to Python 3
set -e
pip3 install wllvm
pip3 install --user wllvm
base_path="$(python3 -m site --user-base)"
export PATH="$PATH:${base_path}/bin"
}
13 changes: 7 additions & 6 deletions scripts/build/p-llvm-linux-ubuntu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install_build_dependencies_llvm() {
fi
#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
install_binary_artifact_llvm() {
Expand All @@ -62,17 +62,18 @@ install_binary_artifact_llvm() {
[[ "${requires_rtti}" -eq 0 ]] && return 1
# Enable/Disable optimized does not matter
source "${DIR}/common-functions"
# Add certificate
apt update -y
with_sudo apt update -y
dependencies=(
ca-certificates
wget
lsb-release
gnupg
)
apt -y --no-install-recommends install "${dependencies[@]}"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add -
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key| with_sudo apt-key add -
local version=""
[[ "${LLVM_VERSION_MAJOR}" -le 6 ]] && version="-${LLVM_VERSION}"
Expand All @@ -94,7 +95,7 @@ install_binary_artifact_llvm() {
)
#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}" || return 1
with_sudo apt -y --no-install-recommends install "${dependencies[@]}" || return 1
}
# Check if the binary artifact is installed
Expand Down
5 changes: 3 additions & 2 deletions scripts/build/p-metasmt-linux-ubuntu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ setup_build_variables_metasmt() {
}

install_build_dependencies_metasmt() {
apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
# libgmp, gperf (required by yices2)
Expand All @@ -27,5 +28,5 @@ install_build_dependencies_metasmt() {
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
10 changes: 6 additions & 4 deletions scripts/build/p-sqlite-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
install_build_dependencies_sqlite() {
apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
build-essential
Expand All @@ -8,16 +9,17 @@ install_build_dependencies_sqlite() {
wget
)

apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
install_binary_artifact_sqlite() {
[[ "${SANITIZER_SUFFIX}x" == "x" ]] || return 1

apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y
dependencies=(
libsqlite3-dev
)
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}

# Check if the binary artifact is installed
Expand Down
8 changes: 4 additions & 4 deletions scripts/build/p-stp-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Build dependencies
install_build_dependencies_stp() {
apt update -y
install_build_dependencies_stp() {
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
build-essential
Expand All @@ -15,5 +15,5 @@ install_build_dependencies_stp() {
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
5 changes: 3 additions & 2 deletions scripts/build/p-tcmalloc-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
install_build_dependencies_tcmalloc() {
apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
build-essential
Expand All @@ -9,5 +10,5 @@ install_build_dependencies_tcmalloc() {
wget
)

apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
6 changes: 3 additions & 3 deletions scripts/build/p-uclibc-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Build dependencies
install_build_dependencies_uclibc() {
apt update -y
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
build-essential
Expand All @@ -13,5 +13,5 @@ install_build_dependencies_uclibc() {
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
7 changes: 4 additions & 3 deletions scripts/build/p-z3-linux-ubuntu.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build dependencies Z3
install_build_dependencies_z3() {
apt update -y
install_build_dependencies_z3() {
source "${DIR}/common-functions"
with_sudo apt update -y

dependencies=(
build-essential
Expand All @@ -11,5 +12,5 @@ install_build_dependencies_z3() {
)

#Install essential dependencies
apt -y --no-install-recommends install "${dependencies[@]}"
with_sudo apt -y --no-install-recommends install "${dependencies[@]}"
}
2 changes: 2 additions & 0 deletions scripts/build/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ run_tests() {

# If metaSMT is the only solver, then rerun lit tests with non-default metaSMT backends
if [ "X${SOLVERS}" == "XmetaSMT" ]; then
base_path="$(python3 -m site --user-base)"
export PATH="$PATH:${base_path}/bin"
available_metasmt_backends="btor stp z3 yices2 cvc4"
for backend in $available_metasmt_backends; do
if [ "X${METASMT_DEFAULT}" != "X$backend" ]; then
Expand Down

0 comments on commit 818275b

Please sign in to comment.