From 39b488a103838c5ad43c69cb0f18160f27f61ed3 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 3 Feb 2018 23:01:15 -0500 Subject: [PATCH 01/10] Download/install DF --- .travis.yml | 18 +++++++++++------- travis/download-df.sh | 28 ++++++++++++++++++++++++++++ travis/get-df-version.sh | 4 ++++ 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100755 travis/download-df.sh create mode 100755 travis/get-df-version.sh diff --git a/.travis.yml b/.travis.yml index ad17693a9..ab18066f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: cpp cache: pip: true directories: + - $HOME/DF-travis - $HOME/lua53 addons: apt: @@ -22,8 +23,11 @@ matrix: - gcc-4.8-multilib - g++-4.8-multilib before_install: +- export DF_VERSION=$(sh travis/get-df-version.sh) +- export DF_FOLDER="$HOME/DF-travis/$DF_VERSION" - pip install --user "sphinx==1.4" "requests[security]" - sh travis/build-lua.sh +- sh travis/download-df.sh script: - export PATH="$PATH:$HOME/lua53/bin" - git tag tmp-travis-build @@ -37,12 +41,12 @@ script: - python travis/script-syntax.py --ext=rb --cmd="ruby -c" - mkdir build-travis - cd build-travis -- cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DBUILD_DOCS:BOOL=ON -- make -j3 +- cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" +- make -j3 install notifications: email: false - irc: - channels: - - "chat.freenode.net#dfhack" - on_success: change - on_failure: always + # irc: + # channels: + # - "chat.freenode.net#dfhack" + # on_success: change + # on_failure: always diff --git a/travis/download-df.sh b/travis/download-df.sh new file mode 100755 index 000000000..56a2a539d --- /dev/null +++ b/travis/download-df.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +tardest="df.tar.bz2" + +cd "$(dirname "$0")" +echo "DF_VERSION: $DF_VERSION" +echo "DF_FOLDER: $DF_FOLDER" +mkdir -p "$DF_FOLDER" +cd "$DF_FOLDER" + +if [ -f receipt ]; then + echo "Already downloaded $DF_VERSION" + exit 0 +fi + +rm -rif "$tardest" df_linux + +minor=$(echo "$DF_VERSION" | cut -d. -f2) +patch=$(echo "$DF_VERSION" | cut -d. -f3) +url="http://www.bay12games.com/dwarves/df_${minor}_${patch}_linux.tar.bz2" + +echo Downloading +wget "$url" -O "$tardest" +echo Extracting +tar xf "$tardest" --strip-components=1 +echo Done + +touch receipt diff --git a/travis/get-df-version.sh b/travis/get-df-version.sh new file mode 100755 index 000000000..13d317d2e --- /dev/null +++ b/travis/get-df-version.sh @@ -0,0 +1,4 @@ +#!/bin/sh +cd "$(dirname "$0")" +cd .. +grep DF_VERSION CMakeLists.txt | perl -ne 'print "$&\n" if /[\d\.]+/' From b54a35ce5dc36c2b375b99555072b2b7322a450f Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 3 Feb 2018 23:26:43 -0500 Subject: [PATCH 02/10] Build 64-bit DFHack, install SDL --- .travis.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab18066f3..8499aa761 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,12 @@ cache: addons: apt: packages: &default_packages + - libsdl-image1.2-dev + - libsdl-ttf2.0-dev + - libsdl1.2-dev - libxml-libxml-perl - libxml-libxslt-perl - - zlib1g-dev:i386 + - zlib1g-dev matrix: include: - env: GCC_VERSION=4.8 @@ -20,8 +23,8 @@ matrix: - ubuntu-toolchain-r-test packages: - *default_packages - - gcc-4.8-multilib - - g++-4.8-multilib + - gcc-4.8 + - g++-4.8 before_install: - export DF_VERSION=$(sh travis/get-df-version.sh) - export DF_FOLDER="$HOME/DF-travis/$DF_VERSION" @@ -41,8 +44,9 @@ script: - python travis/script-syntax.py --ext=rb --cmd="ruby -c" - mkdir build-travis - cd build-travis -- cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" +- cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DDFHACK_BUILD_ARCH=64 -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" - make -j3 install +- "$DF_FOLDER/dfhack +devel/check-release +die" notifications: email: false # irc: From 78c60e249edff9196262e2b5183b22b715565de4 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 3 Feb 2018 23:56:44 -0500 Subject: [PATCH 03/10] Set PRINT_MODE:TEXT --- travis/download-df.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/travis/download-df.sh b/travis/download-df.sh index 56a2a539d..4430f7630 100755 --- a/travis/download-df.sh +++ b/travis/download-df.sh @@ -2,15 +2,23 @@ tardest="df.tar.bz2" +which md5sum && alias md5=md5sum +selfmd5=$(openssl md5 < "$0") +echo $selfmd5 + cd "$(dirname "$0")" echo "DF_VERSION: $DF_VERSION" echo "DF_FOLDER: $DF_FOLDER" mkdir -p "$DF_FOLDER" cd "$DF_FOLDER" -if [ -f receipt ]; then - echo "Already downloaded $DF_VERSION" - exit 0 +if [[ -f receipt ]]; then + if [[ "$selfmd5" != "$(cat receipt)" ]]; then + echo "download-df.sh changed; removing DF" + else + echo "Already downloaded $DF_VERSION" + exit 0 + fi fi rm -rif "$tardest" df_linux @@ -23,6 +31,9 @@ echo Downloading wget "$url" -O "$tardest" echo Extracting tar xf "$tardest" --strip-components=1 +echo Changing settings +echo '' >> "$DF_FOLDER/data/init/init.txt" +echo '[PRINT_MODE:TEXT]' >> "$DF_FOLDER/data/init/init.txt" echo Done -touch receipt +echo "$selfmd5" > receipt From 638f0ab35aecf18c02c0a3ef5430b8bb3bb0cc09 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 3 Feb 2018 23:59:01 -0500 Subject: [PATCH 04/10] Add "headless" mode, use in travis --- .travis.yml | 1 + library/Core.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8499aa761..d2516b967 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ before_install: - pip install --user "sphinx==1.4" "requests[security]" - sh travis/build-lua.sh - sh travis/download-df.sh +- echo "export DFHACK_HEADLESS=1" >> "$HOME/.dfhackrc" script: - export PATH="$PATH:$HOME/lua53/bin" - git tag tmp-travis-build diff --git a/library/Core.cpp b/library/Core.cpp index 5173a3ad9..58b3f85f5 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -81,6 +81,10 @@ using namespace DFHack; #include "SDL_events.h" +#ifdef LINUX_BUILD +#include +#endif + using namespace tthread; using namespace df::enums; using df::global::init; @@ -1638,7 +1642,24 @@ bool Core::Init() cerr << "Initializing Console.\n"; // init the console. bool is_text_mode = (init && init->display.flag.is_set(init_display_flags::TEXT)); - if (is_text_mode || getenv("DFHACK_DISABLE_CONSOLE")) + bool is_headless = bool(getenv("DFHACK_HEADLESS")); + if (is_headless) + { +#ifdef LINUX_BUILD + auto endwin = (int(*)(void))dlsym(RTLD_DEFAULT, "endwin"); + if (endwin) + { + endwin(); + } + else + { + cerr << "endwin(): bind failed" << endl; + } +#else + cerr << "Headless mode not supported on Windows" << endl; +#endif + } + if ((is_text_mode && !is_headless) || getenv("DFHACK_DISABLE_CONSOLE")) { con.init(true); cerr << "Console is not available. Use dfhack-run to send commands.\n"; @@ -1718,7 +1739,7 @@ bool Core::Init() HotkeyMutex = new mutex(); HotkeyCond = new condition_variable(); - if (!is_text_mode) + if (!is_text_mode || is_headless) { cerr << "Starting IO thread.\n"; // create IO thread From a5cca757154813c5d3acb7050aed148538c2859b Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 00:17:46 -0500 Subject: [PATCH 05/10] headless: Disable sound, wgetch --- library/Hooks-linux.cpp | 4 ++++ travis/download-df.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/library/Hooks-linux.cpp b/library/Hooks-linux.cpp index b0bf5a781..8291bf899 100644 --- a/library/Hooks-linux.cpp +++ b/library/Hooks-linux.cpp @@ -88,6 +88,10 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event) struct WINDOW; DFhackCExport int wgetch(WINDOW *win) { + if (getenv("DFHACK_HEADLESS")) + { + return 0; + } static int (*_wgetch)(WINDOW * win) = (int (*)( WINDOW * )) dlsym(RTLD_NEXT, "wgetch"); if(!_wgetch) { diff --git a/travis/download-df.sh b/travis/download-df.sh index 4430f7630..db5009069 100755 --- a/travis/download-df.sh +++ b/travis/download-df.sh @@ -34,6 +34,7 @@ tar xf "$tardest" --strip-components=1 echo Changing settings echo '' >> "$DF_FOLDER/data/init/init.txt" echo '[PRINT_MODE:TEXT]' >> "$DF_FOLDER/data/init/init.txt" +echo '[SOUND:NO]' >> "$DF_FOLDER/data/init/init.txt" echo Done echo "$selfmd5" > receipt From f8a9557562574d1b0dffc080df40e8f7dcf372bd Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 00:36:19 -0500 Subject: [PATCH 06/10] Exit with pop-screen --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2516b967..187e9bce2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ script: - cd build-travis - cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DDFHACK_BUILD_ARCH=64 -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" - make -j3 install -- "$DF_FOLDER/dfhack +devel/check-release +die" +- "$DF_FOLDER/dfhack +devel/check-release +devel/pop-screen" notifications: email: false # irc: From 4aa0990dc764ad5ab328a8d6da867e772486352a Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 01:48:09 -0500 Subject: [PATCH 07/10] Fix issue with DF not quitting --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 187e9bce2..a706d8f79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,8 @@ script: - cd build-travis - cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DDFHACK_BUILD_ARCH=64 -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" - make -j3 install -- "$DF_FOLDER/dfhack +devel/check-release +devel/pop-screen" +- mv "$DF_FOLDER"/dfhack.init-example "$DF_FOLDER"/dfhack.init +- "$DF_FOLDER/dfhack" "+devel/check-release" "+lua" "scr.breakdown_level=1" notifications: email: false # irc: From 2de28d43576707820d2e2a3e4a76c4e4f2d6b561 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 02:13:20 -0500 Subject: [PATCH 08/10] Fix bash compat issues --- travis/download-df.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/travis/download-df.sh b/travis/download-df.sh index db5009069..20dc3dbd4 100755 --- a/travis/download-df.sh +++ b/travis/download-df.sh @@ -12,8 +12,8 @@ echo "DF_FOLDER: $DF_FOLDER" mkdir -p "$DF_FOLDER" cd "$DF_FOLDER" -if [[ -f receipt ]]; then - if [[ "$selfmd5" != "$(cat receipt)" ]]; then +if [ -f receipt ]; then + if [ "$selfmd5" != "$(cat receipt)" ]; then echo "download-df.sh changed; removing DF" else echo "Already downloaded $DF_VERSION" From 23efb1cbf11e8debbebeb4cbad5f355538ff46c1 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 02:13:23 -0500 Subject: [PATCH 09/10] Run startup commands in dfhack_travis.init --- .travis.yml | 3 ++- travis/dfhack_travis.init | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 travis/dfhack_travis.init diff --git a/.travis.yml b/.travis.yml index a706d8f79..04bfcae9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,8 @@ script: - cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DDFHACK_BUILD_ARCH=64 -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" - make -j3 install - mv "$DF_FOLDER"/dfhack.init-example "$DF_FOLDER"/dfhack.init -- "$DF_FOLDER/dfhack" "+devel/check-release" "+lua" "scr.breakdown_level=1" +- cp ../travis/dfhack_travis.init "$DF_FOLDER"/ +- "$DF_FOLDER/dfhack" notifications: email: false # irc: diff --git a/travis/dfhack_travis.init b/travis/dfhack_travis.init new file mode 100644 index 000000000..5b28cefef --- /dev/null +++ b/travis/dfhack_travis.init @@ -0,0 +1,2 @@ +devel/check-release +:lua scr.breakdown_level=df.interface_breakdown_types.QUIT From 2af5f7ab870901edc5237e62f01e1be15a1d074f Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 4 Feb 2018 16:00:53 -0500 Subject: [PATCH 10/10] Add test runner --- .travis.yml | 5 +++-- test/main.lua | 10 ++++++++++ travis/dfhack_travis.init | 4 ++-- travis/run-tests.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test/main.lua create mode 100644 travis/run-tests.py diff --git a/.travis.yml b/.travis.yml index 04bfcae9b..147cd13fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,8 +48,9 @@ script: - cmake .. -DCMAKE_C_COMPILER=gcc-$GCC_VERSION -DCMAKE_CXX_COMPILER=g++-$GCC_VERSION -DDFHACK_BUILD_ARCH=64 -DBUILD_DOCS:BOOL=ON -DCMAKE_INSTALL_PREFIX="$DF_FOLDER" - make -j3 install - mv "$DF_FOLDER"/dfhack.init-example "$DF_FOLDER"/dfhack.init -- cp ../travis/dfhack_travis.init "$DF_FOLDER"/ -- "$DF_FOLDER/dfhack" +- cd .. +- cp travis/dfhack_travis.init "$DF_FOLDER"/ +- python travis/run-tests.py "$DF_FOLDER" notifications: email: false # irc: diff --git a/test/main.lua b/test/main.lua new file mode 100644 index 000000000..0085a9711 --- /dev/null +++ b/test/main.lua @@ -0,0 +1,10 @@ +function set_test_stage(stage) + local f = io.open('test_stage.txt', 'w') + f:write(stage) + f:close() +end + +print('running tests') + +set_test_stage('done') +dfhack.run_command('die') diff --git a/travis/dfhack_travis.init b/travis/dfhack_travis.init index 5b28cefef..d9bc3e5ba 100644 --- a/travis/dfhack_travis.init +++ b/travis/dfhack_travis.init @@ -1,2 +1,2 @@ -devel/check-release -:lua scr.breakdown_level=df.interface_breakdown_types.QUIT +:lua dfhack.internal.addScriptPath(os.getenv('TRAVIS_BUILD_DIR')) +test/main diff --git a/travis/run-tests.py b/travis/run-tests.py new file mode 100644 index 000000000..a8265088c --- /dev/null +++ b/travis/run-tests.py @@ -0,0 +1,30 @@ +import os, subprocess, sys + +MAX_TRIES = 5 + +dfhack = 'Dwarf Fortress.exe' if sys.platform == 'win32' else './dfhack' +test_stage = 'test_stage.txt' + +def get_test_stage(): + if os.path.isfile(test_stage): + return open(test_stage).read().strip() + return '0' + +os.chdir(sys.argv[1]) +if os.path.exists(test_stage): + os.remove(test_stage) + +tries = 0 +while True: + tries += 1 + stage = get_test_stage() + print('Run #%i: stage=%s' % (tries, get_test_stage())) + if stage == 'done': + print('Done!') + os.remove(test_stage) + sys.exit(0) + if tries > MAX_TRIES: + print('Too many tries - aborting') + sys.exit(1) + + os.system(dfhack)