refactor(ci): Split into scripts

This commit is contained in:
Michael Carlberg 2016-11-19 08:55:46 +01:00
parent 7dedcf6526
commit 489d429644
11 changed files with 121 additions and 80 deletions

View File

@ -18,100 +18,33 @@ addons:
env:
global:
- BUILD_TESTS="ON"
- BUILD_TYPE="Release"
- LLVM_VERSION="3.8.1"
- LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz"
- LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz"
- LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz"
- CMAKE_URL="https://cmake.org/files/v3.6/cmake-3.6.2-Linux-x86_64.tar.gz"
- PYTHONPATH="/usr/lib/python2.7/dist-packages:${PYTHONPATH}"
cache:
directories:
- ${TRAVIS_BUILD_DIR}/deps/cmake
- ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1/install
before_install:
- sudo apt-add-repository -y "ppa:george-edison55/george-edison"
- sudo apt-get -qq update
# Install packages : core
#--------------------------------------------------------------------------x
- sudo apt-get install -y cmake cmake-data libboost-dev
# Install packages : xcb
#--------------------------------------------------------------------------x
- sudo apt-get install -y libxcb1-dev libxcb-util0-dev libxcb-image0-dev libxcb-randr0-dev libxcb-ewmh-dev libxcb-icccm4-dev xcb-proto python-xcbgen libfreetype6-dev
# Install packages : optional
#--------------------------------------------------------------------------x
- sudo apt-get install -y i3-wm libiw-dev libasound2-dev libmpdclient-dev
install:
# Install dependencies in ${TRAVIS_BUILD_DIR}/deps
#--------------------------------------------------------------------------x
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- LLVM_ROOT="${DEPS_DIR}/llvm-${LLVM_VERSION}"
- mkdir -p "${DEPS_DIR}"
# Update python path to make sure we find the xcbgen module
#--------------------------------------------------------------------------x
- export PYTHONPATH="/usr/lib/python2.7/dist-packages:${PYTHONPATH}"
# Install a later version of cmake
#--------------------------------------------------------------------------x
- |
cd "${DEPS_DIR}"
if [[ -z "$(ls -A ${DEPS_DIR}/cmake/bin 2>/dev/null)" ]]; then
mkdir -p cmake && travis_retry wget --no-check-certificate --quiet -O - "${CMAKE_URL}" | tar --strip-components=1 -xz -C cmake
fi
- export PATH="${DEPS_DIR}/cmake/bin:${PATH}"
# Install LLVM libc++
#--------------------------------------------------------------------------x
- |
if [[ "${CXX}" == "clang++" ]] && [[ -z "$(ls -A ${LLVM_ROOT}/install/include 2>/dev/null)" ]]; then
mkdir -p "${LLVM_ROOT}" "${LLVM_ROOT}/build" "${LLVM_ROOT}/projects/libcxx" "${LLVM_ROOT}/projects/libcxxabi"
travis_retry wget --quiet -O - "${LLVM_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}"
travis_retry wget --quiet -O - "${LIBCXX_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}/projects/libcxx"
travis_retry wget --quiet -O - "${LIBCXXABI_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}/projects/libcxxabi"
(cd "${LLVM_ROOT}/build" && cmake .. -DCMAKE_CXX_COMPILER=clang++ && make cxxabi cxx -j2)
(cd "${LLVM_ROOT}/build/projects/libcxx" && make install)
(cd "${LLVM_ROOT}/build/projects/libcxxabi" && make install)
export CXXFLAGS="${CXXFLAGS} -I${LLVM_ROOT}/install/include"
export CXXFLAGS="${CXXFLAGS} -I${LLVM_ROOT}/install/include/c++/v1"
export CXXFLAGS="${CXXFLAGS} -stdlib=libc++"
export LDFLAGS="${LDFLAGS} -L${LLVM_ROOT}/install/lib"
export LDFLAGS="${LDFLAGS} -lc++"
export LDFLAGS="${LDFLAGS} -lc++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_ROOT}/install/lib"
fi
# Set compiler's
#--------------------------------------------------------------------------x
- if [[ "${CXX}" == "clang++" ]]; then export CXX="clang++-3.8" CC="clang-3.8" CXXFLAGS="${CXXFLAGS} -Qunused-arguments"; fi
- if [[ "${CXX}" == "g++" ]]; then export CXX="g++-5" CC="gcc-5"; fi
- source ${TRAVIS_BUILD_DIR}/common/travis/environment.sh
- source ${TRAVIS_BUILD_DIR}/common/travis/install_deps.sh
- source ${TRAVIS_BUILD_DIR}/common/travis/install_cmake.sh
- source ${TRAVIS_BUILD_DIR}/common/travis/install_libcpp.sh
before_script:
- eval "${CXX} --version"
- eval "${CC} --version"
- cmake --version
- mkdir -p "${TRAVIS_BUILD_DIR}/build"
- cd "${TRAVIS_BUILD_DIR}/build"
- cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" -DBUILD_TESTS:BOOL=ON ..
- source ${TRAVIS_BUILD_DIR}/common/travis/summary.sh
- source ${TRAVIS_BUILD_DIR}/common/travis/configure.sh
script:
- make
- |
for test in tests/unit_test.*; do
if [ -x $test ]; then
echo -n "${test##*/} ";
if $test; then
echo -e "\033[1;32mpassed\033[0m";
else
echo -e "\033[1;31mfailed\033[0m";
fi
fi
done
- source ${TRAVIS_BUILD_DIR}/common/travis/build.sh
- source ${TRAVIS_BUILD_DIR}/common/travis/tests.sh
notifications:
email: false
@ -119,5 +52,8 @@ notifications:
channels:
- "irc.freenode.org#polybar"
template:
- "%{author} pushed #%{commit} \"%{commit_subject}\" -> %{repository_name}/%{branch}"
- "Build #%{build_number}: %{result} // Compare at %{compare_url}"
- "%{author} pushed #%{commit} \"%{commit_subject}\" to %{repository_name}/%{branch}"
- "Build #%{build_number} %{result} / %{build_url} (diff: %{compare_url})"
use_notice: true
on_success: change
on_failure: change

2
common/travis/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
cd "${TRAVIS_BUILD_DIR}/build" && make

9
common/travis/configure.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
mkdir -p "${TRAVIS_BUILD_DIR}/build"
cd "${TRAVIS_BUILD_DIR}/build" || false
cmake \
-DCMAKE_C_COMPILER="${CC}" \
-DCMAKE_CXX_COMPILER="${CXX}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE:-Release}" \
-DBUILD_TESTS:BOOL="${BUILD_TESTS:-OFF}" ..

16
common/travis/environment.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
export DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
export LLVM_ROOT="${DEPS_DIR}/llvm-${LLVM_VERSION}"
mkdir -p "${DEPS_DIR}"
mkdir -p "${LLVM_ROOT}"
# Update compiler flags
if [ "${CXX}" = "clang++" ]; then
export CXX="clang++-3.8"
export CC="clang-3.8"
export CXXFLAGS="${CXXFLAGS} -Qunused-arguments"
elif [ "${CXX}" = "g++" ]; then
export CXX="g++-5"
export CC="gcc-5"
fi

6
common/travis/install_cmake.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
if [ -z "$(ls -A "${DEPS_DIR}/cmake/bin" 2>/dev/null)" ]; then
mkdir -p cmake && travis_retry wget --no-check-certificate --quiet -O - "${CMAKE_URL}" | tar --strip-components=1 -xz -C cmake
fi
export PATH="${DEPS_DIR}/cmake/bin:${PATH}"

6
common/travis/install_deps.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
sudo apt-add-repository -y "ppa:george-edison55/george-edison"
sudo apt-get -qq update
sudo apt-get install -y cmake cmake-data libboost-dev
sudo apt-get install -y libxcb1-dev libxcb-util0-dev libxcb-image0-dev libxcb-randr0-dev libxcb-ewmh-dev libxcb-icccm4-dev xcb-proto python-xcbgen libfreetype6-dev
sudo apt-get install -y i3-wm libiw-dev libasound2-dev libmpdclient-dev

22
common/travis/install_libcpp.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
if [ "${CXX}" = "clang++" ]; then
if [ -z "$(ls -A "${LLVM_ROOT}/install/include" 2>/dev/null)" ]; then
mkdir -p "${LLVM_ROOT}" "${LLVM_ROOT}/build" "${LLVM_ROOT}/projects/libcxx" "${LLVM_ROOT}/projects/libcxxabi"
travis_retry wget --quiet -O - "${LLVM_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}"
travis_retry wget --quiet -O - "${LIBCXX_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}/projects/libcxx"
travis_retry wget --quiet -O - "${LIBCXXABI_URL}" | tar --strip-components=1 -xJ -C "${LLVM_ROOT}/projects/libcxxabi"
(cd "${LLVM_ROOT}/build" && cmake .. -DCMAKE_CXX_COMPILER=clang++ && make cxxabi cxx -j2)
(cd "${LLVM_ROOT}/build/projects/libcxx" && make install)
(cd "${LLVM_ROOT}/build/projects/libcxxabi" && make install)
fi
export CXXFLAGS="${CXXFLAGS} -I${LLVM_ROOT}/install/include"
export CXXFLAGS="${CXXFLAGS} -I${LLVM_ROOT}/install/include/c++/v1"
export CXXFLAGS="${CXXFLAGS} -stdlib=libc++"
export LDFLAGS="${LDFLAGS} -L${LLVM_ROOT}/install/lib"
export LDFLAGS="${LDFLAGS} -lc++"
export LDFLAGS="${LDFLAGS} -lc++abi"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_ROOT}/install/lib"
fi

9
common/travis/summary.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
echo "${CXX} --version"
eval "${CXX} --version"
echo "${CC} --version"
eval "${CC} --version"
echo "cmake --version"
cmake --version

12
common/travis/tests.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
if [ "${BUILD_TESTS:-OFF}" = "ON" ]; then
for test in tests/unit_test.*; do
[ -x "$test" ] || continue
if $test; then
printf "\033[1;32m%s\033[0m\n" "${test##*/} passed"
else
printf "\033[1;31m%s\033[0m\n" "${test##*/} failed"
fi
done
fi

View File

@ -114,13 +114,35 @@ namespace modules {
m_percentage = percentage;
m_state = state;
string time_remaining;
auto rate = strtoul(file_util::get_contents("/sys/class/power_supply/BAT0/current_now").c_str(), nullptr, 10) / 1000;
// int rate{atoi(file_util::get_contents("/sys/class/power_supply/BAT0/current_now").c_str()) / 1000};
// time_remaining = to_string(rate);
auto capacity = strtoul(file_util::get_contents("/sys/class/power_supply/BAT0/charge_now").c_str(), nullptr, 10) / 1000;
auto voltage = strtoul(file_util::get_contents("/sys/class/power_supply/BAT0/voltage_now").c_str(), nullptr, 10) / 1000;
capacity = capacity * 1000 / voltage;
rate = rate * 1000 / voltage;
printf("rate=%lu cap=%lu volt=%lu\n", rate, capacity, voltage);
int seconds = 3600 * capacity / rate;
int hours = seconds / 3600;
seconds -= 3600 * hours;
int minutes = seconds / 60;
seconds -= 60 * minutes;
char buffer[9]{0};
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", hours, minutes, seconds);
time_remaining = buffer;
if (m_label_charging) {
m_label_charging->reset_tokens();
m_label_charging->replace_token("%percentage%", to_string(m_percentage) + "%");
m_label_charging->replace_token("%time%", time_remaining);
}
if (m_label_discharging) {
m_label_discharging->reset_tokens();
m_label_discharging->replace_token("%percentage%", to_string(m_percentage) + "%");
m_label_discharging->replace_token("%time%", time_remaining);
}
if (m_label_full) {
m_label_full->reset_tokens();

View File

@ -75,7 +75,8 @@ int main() {
unsigned long hashB1{string_util::hash("Foo")};
unsigned long hashB2{string_util::hash("Bar")};
expect(hashA1 == hashA2);
expect(hashA1 != hashB1 != hashB2);
expect(hashA1 != hashB1);
expect(hashA1 != hashB2);
expect(hashB1 != hashB2);
};
}