From 6757073b014f1912b48798375d76dcb3820afd25 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 13 Aug 2016 20:47:43 +0800 Subject: [PATCH] add CI build array for kindle, kobo and android --- .ci/android_install.sh | 22 ++++++++++++ .ci/before_install.sh | 13 +++++++ .ci/build_script.sh | 7 ++++ .ci/common.sh | 59 +++++++++++++++++++++++++++++++ .ci/emulator_install.sh | 17 +++++++++ .ci/kindle_install.sh | 7 ++++ .ci/kobo_install.sh | 7 ++++ .ci/test_script.sh | 18 ++++++++++ .travis.yml | 59 ++++++++----------------------- Makefile.third | 1 + ffi/SDL2_0.lua | 4 +-- thirdparty/gettext/CMakeLists.txt | 3 +- 12 files changed, 169 insertions(+), 48 deletions(-) create mode 100755 .ci/android_install.sh create mode 100755 .ci/before_install.sh create mode 100755 .ci/build_script.sh create mode 100644 .ci/common.sh create mode 100755 .ci/emulator_install.sh create mode 100755 .ci/kindle_install.sh create mode 100755 .ci/kobo_install.sh create mode 100755 .ci/test_script.sh diff --git a/.ci/android_install.sh b/.ci/android_install.sh new file mode 100755 index 000000000..b936ef8ee --- /dev/null +++ b/.ci/android_install.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# install 32 bit libz package for NDK build +sudo dpkg --add-architecture i386 +sudo apt-get update +sudo apt-get install zlib1g:i386 libc6-dev-i386 linux-libc-dev:i386 + +if [ "$NDKREV" = "r9c" ]; then + curl -L http://dl.google.com/android/ndk/android-ndk-${NDKREV}-linux-x86_64.tar.bz2 -O + echo "extracting android ndk" + bzip2 -dc android-ndk-${NDKREV}-linux-x86_64.tar.bz2 | tar xf - +fi + +if [ "$NDKREV" = "r11c" ]; then + curl -L http://dl.google.com/android/repository/android-ndk-${NDKREV}-linux-x86_64.zip -O + echo "extracting android ndk" + unzip -q android-ndk-${NDKREV}-linux-x86_64.zip +fi + +export NDK=`pwd`/android-ndk-${NDKREV} +export PATH=$PATH:${NDK} +make android-toolchain diff --git a/.ci/before_install.sh b/.ci/before_install.sh new file mode 100755 index 000000000..38fd9e929 --- /dev/null +++ b/.ci/before_install.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# don't do this for clang +if [ "$CXX" = "g++" ]; + then export CXX="g++-4.8" CC="gcc-4.8"; +fi +# in case anything ignores the environment variables, override through PATH +mkdir bin +ln -s $(which gcc-4.8) bin/cc +ln -s $(which gcc-4.8) bin/gcc +ln -s $(which c++-4.8) bin/c++ +ln -s $(which g++-4.8) bin/g++ +export PATH=$PWD/bin:$PATH diff --git a/.ci/build_script.sh b/.ci/build_script.sh new file mode 100755 index 000000000..18a0d0568 --- /dev/null +++ b/.ci/build_script.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CI_DIR}/common.sh" + +travis_retry make fetchthirdparty +make all diff --git a/.ci/common.sh b/.ci/common.sh new file mode 100644 index 000000000..cc33b7357 --- /dev/null +++ b/.ci/common.sh @@ -0,0 +1,59 @@ +set -e +set -o pipefail + +ANSI_RED="\033[31;1m" +ANSI_GREEN="\033[32;1m" +ANSI_RESET="\033[0m" +ANSI_CLEAR="\033[0K" + +travis_retry() { + local result=0 + local count=1 + set +e + + while [ $count -le 3 ]; do + [ $result -ne 0 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2 + } + "$@" + result=$? + [ $result -eq 0 ] && break + count=$(($count + 1)) + sleep 1 + done + + [ $count -gt 3 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2 + } + + set -e + return $result +} + +retry_cmd() { + local result=0 + local count=1 + set +e + + retry_cnt=$1 + shift 1 + + while [ $count -le ${retry_cnt} ]; do + [ $result -ne 0 ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of ${retry_cnt}${ANSI_RESET}\n" >&2 + } + "$@" + result=$? + [ $result -eq 0 ] && break + count=$(($count + 1)) + sleep 1 + done + + [ $count -gt ${retry_cnt} ] && { + echo -e "\n${ANSI_RED}The command \"$@\" failed ${retry_cnt} times.${ANSI_RESET}\n" >&2 + } + + set -e + return $result +} + diff --git a/.ci/emulator_install.sh b/.ci/emulator_install.sh new file mode 100755 index 000000000..fe76b0c20 --- /dev/null +++ b/.ci/emulator_install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CI_DIR}/common.sh" + +mkdir $HOME/.luarocks +cp /etc/luarocks/config.lua $HOME/.luarocks/config.lua +echo "wrap_bin_scripts = false" >> $HOME/.luarocks/config.lua +# recent versions of busted may cause some weird segmentation faults +# - git clone https://github.com/Olivine-Labs/busted/ +# - cd busted && git checkout v1.10.0 && luarocks --local make busted-1.10.0-0.rockspec && cd .. +travis_retry luarocks --local install busted 2.0.rc12-1 +# for verbose_print module +travis_retry luarocks --local install ansicolors +eval $(luarocks path --bin) +export PATH=$PATH:$HOME/.luarocks/bin + diff --git a/.ci/kindle_install.sh b/.ci/kindle_install.sh new file mode 100755 index 000000000..9c86ce86e --- /dev/null +++ b/.ci/kindle_install.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +sudo dpkg --add-architecture i386 +sudo apt-get update +sudo apt-get install libc6-dev-i386 linux-libc-dev:i386 + +sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi diff --git a/.ci/kobo_install.sh b/.ci/kobo_install.sh new file mode 100755 index 000000000..e495274e2 --- /dev/null +++ b/.ci/kobo_install.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +sudo dpkg --add-architecture i386 +sudo apt-get update +sudo apt-get install libc6-dev-i386 linux-libc-dev:i386 + +sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf diff --git a/.ci/test_script.sh b/.ci/test_script.sh new file mode 100755 index 000000000..556dc5fd2 --- /dev/null +++ b/.ci/test_script.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CI_DIR}/common.sh" + +cp build/*/luajit $HOME/.luarocks/bin +# install tesseract trained language data for testing OCR functionality +travis_retry wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.eng.tar.gz +tar zxf tesseract-ocr-3.02.eng.tar.gz +cd build/* && export TESSDATA_PREFIX=`pwd`/data && mkdir -p data/tessdata +mv ../../tesseract-ocr/tessdata/* data/tessdata/ && cd ../../ +# fetch font for base test +travis_retry wget https://github.com/koreader/koreader/raw/master/resources/fonts/droid/DroidSansMono.ttf +export OUTPUT_DIR=`ls -d ./build/x86_64-*linux-gnu` +mkdir -p ${OUTPUT_DIR}/fonts/droid/ +cp DroidSansMono.ttf ${OUTPUT_DIR}/fonts/droid/DroidSansMono.ttf +# finally make test +travis_retry make test diff --git a/.travis.yml b/.travis.yml index ebedee8b6..19af56029 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ # Travis-CI Build for koreader-base # see travis-ci.org for details -language: c - dist: trusty sudo: required # sudo: false @@ -12,17 +10,16 @@ cache: directories: - $HOME/.ccache -compiler: - - gcc - - clang - env: - - EMULATE_READER=1 + - EMULATE_READER=1 CC=gcc + - EMULATE_READER=1 CC=clang + - TARGET=kindle + - TARGET=kobo + - TARGET=android NDKREV=r9c + - TARGET=android NDKREV=r11c addons: apt: - sources: - - ubuntu-toolchain-r-test packages: - g++-4.8 - libsdl1.2-dev @@ -33,43 +30,15 @@ addons: # OpenSSL likes this (package contains makedepend) - xutils-dev -before_install: - # don't do this for clang - - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - # in case anything ignores the environment variables, override through PATH - - mkdir bin - - ln -s $(which gcc-4.8) bin/cc - - ln -s $(which gcc-4.8) bin/gcc - - ln -s $(which c++-4.8) bin/c++ - - ln -s $(which g++-4.8) bin/g++ - - export PATH=$PWD/bin:$PATH +before_install: source .ci/before_install.sh install: - - mkdir $HOME/.luarocks - - cp /etc/luarocks/config.lua $HOME/.luarocks/config.lua - - echo "wrap_bin_scripts = false" >> $HOME/.luarocks/config.lua - # recent versions of busted may cause some weird segmentation faults - # - git clone https://github.com/Olivine-Labs/busted/ - # - cd busted && git checkout v1.10.0 && luarocks --local make busted-1.10.0-0.rockspec && cd .. - - travis_retry luarocks --local install busted 2.0.rc12-1 - # for verbose_print module - - travis_retry luarocks --local install ansicolors - - eval $(luarocks path --bin) - - export PATH=$PATH:$HOME/.luarocks/bin + - if [ "$EMULATE_READER" = 1 ]; then source .ci/emulator_install.sh; fi + - if [ "$TARGET" = kindle ]; then .ci/kindle_install.sh; fi + - if [ "$TARGET" = kobo ]; then .ci/kobo_install.sh; fi + - if [ "$TARGET" = android ]; then source .ci/android_install.sh; fi script: - - travis_retry make fetchthirdparty - - make all - - cp build/*/luajit $HOME/.luarocks/bin - # install tesseract trained language data for testing OCR functionality - - travis_retry wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.eng.tar.gz - - tar zxf tesseract-ocr-3.02.eng.tar.gz - - cd build/* && export TESSDATA_PREFIX=`pwd`/data && mkdir -p data/tessdata - - mv ../../tesseract-ocr/tessdata/* data/tessdata/ && cd ../../ - # fetch font for base test - - travis_retry wget https://github.com/koreader/koreader/raw/master/resources/fonts/droid/DroidSansMono.ttf - - export OUTPUT_DIR=`ls -d ./build/x86_64-*linux-gnu` - - mkdir -p ${OUTPUT_DIR}/fonts/droid/ - - cp DroidSansMono.ttf ${OUTPUT_DIR}/fonts/droid/DroidSansMono.ttf - # finally make test - - travis_retry make test + - .ci/build_script.sh + - if [ "$EMULATE_READER" = 1 ]; then source .ci/test_script.sh; fi + diff --git a/Makefile.third b/Makefile.third index 95369b1a6..44533a1fe 100644 --- a/Makefile.third +++ b/Makefile.third @@ -220,6 +220,7 @@ $(LIBGETTEXT): $(LIBICONV) $(THIRDPARTY_DIR)/gettext/CMakeLists.txt $(CMAKE) -DCC="$(CC) -std=gnu89" -DLIBICONV_PREFIX=$(LIBICONV_DIR) \ -DCHOST_OPTS="$(if $(EMULATE_READER),,--host=$(if $(ANDROID),arm-linux,$(CHOST)))" \ $(if $(ANDROID),-DIS_ANDROID:BOOL=on,) \ + $(if $(ANDROID),-DNDK=$(NDK),) \ $(CURDIR)/thirdparty/gettext && \ $(MAKE) diff --git a/ffi/SDL2_0.lua b/ffi/SDL2_0.lua index 56b8a9c41..bfbf6c8cd 100644 --- a/ffi/SDL2_0.lua +++ b/ffi/SDL2_0.lua @@ -52,8 +52,8 @@ function S.open() -- set up screen (window) S.screen = SDL.SDL_CreateWindow("KOReader", - SDL.SDL_WINDOWPOS_UNDEFINED, - SDL.SDL_WINDOWPOS_UNDEFINED, + tonumber(os.getenv("KOREADER_WINDOW_POS_X")) or SDL.SDL_WINDOWPOS_UNDEFINED, + tonumber(os.getenv("KOREADER_WINDOW_POS_Y")) or SDL.SDL_WINDOWPOS_UNDEFINED, S.w, S.h, full_screen and 1 or 0) S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0) diff --git a/thirdparty/gettext/CMakeLists.txt b/thirdparty/gettext/CMakeLists.txt index 821e44cdc..4004cf4e9 100644 --- a/thirdparty/gettext/CMakeLists.txt +++ b/thirdparty/gettext/CMakeLists.txt @@ -14,7 +14,8 @@ ep_get_binary_dir(BINARY_DIR) set(CFG_ENV_VAR "CC=\"${CC}\"") if(${IS_ANDROID}) - set(CFG_ENV_VAR "${CFG_ENV_VAR} LDFLAGS=-lc") + # workaround of 'undefined reference to getdtablesize' for NDK-r11c + set(CFG_ENV_VAR "${CFG_ENV_VAR} LDFLAGS=-lc LIBS=${NDK}/platforms/android-9/arch-arm/usr/lib/libc.a") endif() set(CFG_OPTS "--with-threads=none --prefix=${BINARY_DIR} --with-libiconv-prefix=${LIBICONV_PREFIX} --enable-shared=false --enable-static=true ${CHOST_OPTS}") set(CFG_CMD sh -c "${CFG_ENV_VAR} ${SOURCE_DIR}/configure ${CFG_OPTS}")