From 7b758f66dbc550fa52ed66fd7f8b81f8ed37a94e Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 20 Apr 2020 12:25:18 +0000 Subject: [PATCH 1/3] Enable cimple tests by default but allow disabling them. Use `bazel test //c-toxcore/... --build_tag_filters=-haskell` to run all tests except the ones that depend on Haskell (i.e. cimple tests). --- .cirrus.yml | 13 +++++++------ toxav/BUILD.bazel | 2 +- toxcore/BUILD.bazel | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index ab863125de..65d6554f70 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,15 +1,16 @@ --- cirrus-ci_task: container: - image: toxchat/toktok-stack:0.0.7 + image: toxchat/toktok-stack:0.0.10 cpu: 2 memory: 2G configure_script: - /src/workspace/tools/inject-repo c-toxcore test_all_script: - bazel test -k - --remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST - --config=ci - --config=docker - --config=release - //c-toxcore/... + --build_tag_filters=-haskell + --test_tag_filters=-haskell + --remote_download_minimal + --config=ci + --config=release + //c-toxcore/... diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel index 036bde3fce..d7e6b6e9c4 100644 --- a/toxav/BUILD.bazel +++ b/toxav/BUILD.bazel @@ -139,5 +139,5 @@ sh_test( srcs = ["//hs-tokstyle/tools:check-cimple"], args = ["$(location %s)" % f for f in CIMPLE_SRCS], data = CIMPLE_SRCS, - tags = ["manual"], + tags = ["haskell"], ) diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index af23a2b2fb..0fdfe0aec0 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -33,6 +33,7 @@ cc_test( name = "crypto_core_test", size = "small", srcs = ["crypto_core_test.cc"], + flaky = True, deps = [ ":crypto_core", "@com_google_googletest//:gtest_main", @@ -296,5 +297,5 @@ sh_test( srcs = ["//hs-tokstyle/tools:check-cimple"], args = ["$(location %s)" % f for f in CIMPLE_SRCS], data = CIMPLE_SRCS, - tags = ["manual"], + tags = ["haskell"], ) From 88b90c82259f86470cf6eba8684e8d9b4cd61bc3 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 3 May 2020 01:09:06 +0100 Subject: [PATCH 2/3] Fix a bug in savedata loading when malloc fails. Also added a bunch of asserts to tests where they don't check allocs. --- .restyled.yaml | 5 +++++ auto_tests/TCP_test.c | 1 + auto_tests/conference_invite_merge_test.c | 2 ++ auto_tests/conference_peer_nick_test.c | 1 + auto_tests/conference_test.c | 2 ++ auto_tests/encryptsave_test.c | 1 + auto_tests/file_saving_test.c | 8 ++++++-- other/astyle/format-source | 8 ++++---- other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- toxav/toxav.c | 8 ++++---- toxcore/DHT.c | 6 ++++++ 11 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 .restyled.yaml diff --git a/.restyled.yaml b/.restyled.yaml new file mode 100644 index 0000000000..722ff51031 --- /dev/null +++ b/.restyled.yaml @@ -0,0 +1,5 @@ +--- +restylers: + - astyle: + arguments: ["--options=other/astyle/astylerc"] + - prettier-yaml diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 9206e265d9..8a109317bb 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -185,6 +185,7 @@ struct sec_TCP_con { static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s, Mono_Time *mono_time) { struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con)); + ck_assert(sec_c != nullptr); Socket sock = net_socket(net_family_ipv6, TOX_SOCK_STREAM, TOX_PROTO_TCP); IP_Port ip_port_loopback; diff --git a/auto_tests/conference_invite_merge_test.c b/auto_tests/conference_invite_merge_test.c index e7ec499c7c..21445525fa 100644 --- a/auto_tests/conference_invite_merge_test.c +++ b/auto_tests/conference_invite_merge_test.c @@ -91,9 +91,11 @@ static void reload(Tox **toxes, State *state, uint32_t n) ck_assert(state[n].save_state != nullptr); struct Tox_Options *const options = tox_options_new(nullptr); + ck_assert(options != nullptr); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, state[n].save_state, state[n].save_size); toxes[n] = tox_new_log(options, nullptr, &state[n].index); + ck_assert(toxes[n] != nullptr); tox_options_free(options); set_mono_time_callback(toxes[n], &state[n]); diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c index 9d10a8a99a..749f909899 100644 --- a/auto_tests/conference_peer_nick_test.c +++ b/auto_tests/conference_peer_nick_test.c @@ -68,6 +68,7 @@ static void rebuild_peer_list(Tox *tox) "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err); uint8_t *const name = (uint8_t *)malloc(size); + ck_assert(name != nullptr); tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err); diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index ec88c82a24..11a7bb0672 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -250,9 +250,11 @@ static void run_conference_tests(Tox **toxes, State *state) for (uint32_t i = 0; i < NUM_GROUP_TOX; ++i) { if (restarting[i]) { struct Tox_Options *const options = tox_options_new(nullptr); + ck_assert(options != nullptr); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, save[i], save_size[i]); toxes[i] = tox_new_log(options, nullptr, &state[i].index); + ck_assert(toxes[i] != nullptr); tox_options_free(options); free(save[i]); diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 19574d16b7..ccb1ee8813 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -76,6 +76,7 @@ static void test_save_friend(void) ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); struct Tox_Options *options = tox_options_new(nullptr); + ck_assert(options != nullptr); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, enc_data, size2); diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 7faa6b2020..cdcce95fa3 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c @@ -64,6 +64,7 @@ static void save_data_encrypted(void) static void load_data_decrypted(void) { FILE *f = fopen(savefile, "r"); + ck_assert(f != nullptr); fseek(f, 0, SEEK_END); int64_t size = ftell(f); fseek(f, 0, SEEK_SET); @@ -71,7 +72,9 @@ static void load_data_decrypted(void) ck_assert_msg(0 <= size && size <= UINT_MAX, "file size out of range"); uint8_t *cipher = (uint8_t *)malloc(size); + ck_assert(cipher != nullptr); uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); + ck_assert(clear != nullptr); size_t read_value = fread(cipher, sizeof(*cipher), size, f); printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size); @@ -81,6 +84,7 @@ static void load_data_decrypted(void) "Could not decrypt, error code %d.", derr); struct Tox_Options *options = tox_options_new(nullptr); + ck_assert(options != nullptr); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); @@ -101,10 +105,10 @@ static void load_data_decrypted(void) ck_assert_msg(strcmp((const char *)readname, name) == 0, "name returned by tox_self_get_name does not match expected result"); - free(cipher); + tox_kill(t); free(clear); + free(cipher); fclose(f); - tox_kill(t); } int main(void) diff --git a/other/astyle/format-source b/other/astyle/format-source index 711823d8db..193e335c44 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source @@ -49,7 +49,7 @@ apidsl_request() { } apidsl_curl() { - echo "apidsl_curl $@" >&2 + echo "apidsl_curl $*" >&2 apidsl_request "c" <( apidsl_request "parse" <( perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON" @@ -68,12 +68,12 @@ set -x wait; wait; wait; wait; wait; wait; wait -if grep '' */*.h; then +if grep '' ./*/*.h; then echo "error: some apidsl references were unresolved" exit 1 fi -CC_SOURCES=`find . '(' -name '*.cc' ')'` +CC_SOURCES=$(find . '(' -name '*.cc' ')') CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c" CC_SOURCES="$CC_SOURCES toxcore/ping_array.c" @@ -91,7 +91,7 @@ FIND="$FIND -and -not -wholename './super_donators/*'" FIND="$FIND -and -not -wholename './third_party/*'" FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'" -C_SOURCES=`eval "$FIND"` +C_SOURCES=$(eval "$FIND") $ASTYLE -n --options=other/astyle/astylerc $C_SOURCES diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 4d02d38faf..82043e0dd5 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -89df21d6a19a1b6652db5b7e6e9f65ad5f8be8abdca9f58645548b9e0c9383e3 /usr/local/bin/tox-bootstrapd +79c4f7416951d024f95d08e7fc48e127181b7465935cc75b9b3e0ab001bd43b4 /usr/local/bin/tox-bootstrapd diff --git a/toxav/toxav.c b/toxav/toxav.c index 3dbe2cffd2..0ecf82590f 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -755,7 +755,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc goto RETURN; } - { /* Encode and send */ + { /* Encode and send */ if (ac_reconfigure_encoder(call->audio, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) { pthread_mutex_unlock(call->mutex_audio); rc = TOXAV_ERR_SEND_FRAME_INVALID; @@ -896,7 +896,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u // we start with I-frames (full frames) and then switch to normal mode later - { /* Encode */ + { /* Encode */ vpx_image_t img; img.w = 0; img.h = 0; @@ -1323,7 +1323,7 @@ static bool call_prepare_transmission(ToxAVCall *call) /* Prepare bwc */ call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time); - { /* Prepare audio */ + { /* Prepare audio */ call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data); if (!call->audio) { @@ -1339,7 +1339,7 @@ static bool call_prepare_transmission(ToxAVCall *call) goto FAILURE; } } - { /* Prepare video */ + { /* Prepare video */ call->video = vc_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data); if (!call->video) { diff --git a/toxcore/DHT.c b/toxcore/DHT.c index b3017259b2..7c9263cd18 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2917,6 +2917,12 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat // Copy to loaded_clients_list dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); + if (dht->loaded_nodes_list == nullptr) { + LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES); + dht->loaded_num_nodes = 0; + break; + } + const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0); if (num > 0) { From 4efe541814ec2ddd073428d6928497b50c48397a Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 3 May 2020 15:36:57 +0100 Subject: [PATCH 3/3] Add a script to run Travis CI locally. This isn't quite Travis, but close enough for local testing. --- .restyled.yaml | 6 +++ .travis.yml | 2 +- .travis/cmake-linux | 22 +++++----- other/analysis/check_recursion | 29 +++++++++---- other/astyle/format-source | 49 +++++++++++++--------- other/docker/Dockerfile.ci | 75 ++++++++++++++++++++++++++++++++++ other/docker/run-ci | 15 +++++++ 7 files changed, 157 insertions(+), 41 deletions(-) create mode 100644 other/docker/Dockerfile.ci create mode 100755 other/docker/run-ci diff --git a/.restyled.yaml b/.restyled.yaml index 722ff51031..f0060d757a 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -2,4 +2,10 @@ restylers: - astyle: arguments: ["--options=other/astyle/astylerc"] + - autopep8 + - black - prettier-yaml + - reorder-python-imports + - shellharden + - shfmt + - yapf diff --git a/.travis.yml b/.travis.yml index 510fb984c5..93192a6fa0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ jobs: - libgtest-dev # For unit tests. - libvpx-dev # For toxav. - ninja-build - - pylint + - pylint3 install: .travis/$JOB install script: .travis/$JOB script after_script: .travis/upload-coverage diff --git a/.travis/cmake-linux b/.travis/cmake-linux index ed06dc26e9..73b335fed6 100755 --- a/.travis/cmake-linux +++ b/.travis/cmake-linux @@ -5,7 +5,7 @@ ACTION="$1" set -eu CACHEDIR="$HOME/cache" -NPROC=`nproc` +NPROC=$(nproc) ASTYLE="$CACHEDIR/astyle/build/gcc/bin/astyle" ASTYLE_VERSION=3.1 TRAVIS_TOOL="https://raw.githubusercontent.com/TokTok/ci-tools/master/bin/travis-haskell" @@ -21,7 +21,7 @@ travis_install() { # Work around https://github.com/eddyxu/cpp-coveralls/issues/108 by manually # installing the pyOpenSSL module and injecting it into urllib3 as per # https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2 - sed -i -e '/^import sys$/a import urllib3.contrib.pyopenssl\nurllib3.contrib.pyopenssl.inject_into_urllib3()' `which coveralls` + sed -i -e '/^import sys$/a import urllib3.contrib.pyopenssl\nurllib3.contrib.pyopenssl.inject_into_urllib3()' "$(which coveralls)" } # Install astyle (version in ubuntu-precise too old). @@ -34,15 +34,15 @@ travis_install() { } run_static_analysis() { - pylint -E other/analysis/check_recursion + pylint3 -E other/analysis/check_recursion export CPPFLAGS="-isystem $CACHEDIR/include" export LDFLAGS="-L$CACHEDIR/lib" - cat toxav/*.c toxcore/*.c toxencryptsave/*.c \ - | clang `pkg-config --cflags libsodium opus vpx` \ - -Itoxav -Itoxcore -Itoxencryptsave -S -emit-llvm -xc - -o- \ - | opt -analyze -print-callgraph 2>&1 \ - | other/analysis/check_recursion + cat toxav/*.c toxcore/*.c toxencryptsave/*.c | + clang "$(pkg-config --cflags libsodium opus vpx)" \ + -Itoxav -Itoxcore -Itoxencryptsave -S -emit-llvm -xc - -o- | + opt -analyze -print-callgraph 2>&1 | + other/analysis/check_recursion other/analysis/run-clang other/analysis/run-clang-analyze } @@ -85,10 +85,10 @@ travis_script() { cmake --build _build --parallel "$NPROC" --target install -- -k 0 - cd _build # pushd - ctest -j50 --output-on-failure || \ + cd _build # pushd + ctest -j50 --output-on-failure || ctest -j50 --output-on-failure --rerun-failed - cd - # popd + cd - # popd } if [ "-z" "$ACTION" ]; then diff --git a/other/analysis/check_recursion b/other/analysis/check_recursion index 210635276c..a8a6e0ef6e 100755 --- a/other/analysis/check_recursion +++ b/other/analysis/check_recursion @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Tool to check for recursive calls in toxcore C code. -Usage: +Usage: cat toxav/*.c toxcore/*.c toxencryptsave/*.c \ | clang `pkg-config --cflags libsodium opus vpx` \ @@ -10,16 +10,17 @@ cat toxav/*.c toxcore/*.c toxencryptsave/*.c \ | opt -analyze -print-callgraph 2>&1 \ | other/analysis/check_recursion """ - -from __future__ import print_function - import collections import fileinput import re import sys import time +from typing import Dict +from typing import List +from typing import Set -def load_callgraph(): + +def load_callgraph() -> Dict: """ Parses the output from opt -print-callgraph from stdin or argv. @@ -39,7 +40,14 @@ def load_callgraph(): return {k: sorted(v) for k, v in graph.items()} -def walk(visited, callgraph, cycles, stack, cur): + +def walk( + visited: Set, + callgraph: Dict, + cycles: Set, + stack: List, + cur: str, +) -> None: """ Detects cycles in the callgraph and adds them to the cycles parameter. """ @@ -54,13 +62,15 @@ def walk(visited, callgraph, cycles, stack, cur): visited.add(callee) stack.pop() -def get_time(): + +def get_time() -> int: """ Return the current time in milliseconds. """ return int(round(time.time() * 1000)) -def find_recursion(expected): + +def find_recursion(expected: Set) -> None: """ Main function: detects cycles and prints them. @@ -98,6 +108,7 @@ def find_recursion(expected): if expected or cycles: sys.exit(1) + find_recursion(expected={ "add_to_closest -> add_to_closest", "add_to_list -> add_to_list", diff --git a/other/astyle/format-source b/other/astyle/format-source index 193e335c44..7de28d06f0 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source @@ -36,10 +36,11 @@ FROM_JSON='s/\\"/"/g;s/^"(.*)"$/$1/;s/\\\\/\\/g;s/\\n/\n/g' apidsl_request() { TMPFILE=$(mktemp /tmp/apidsl.XXXXXX) curl -s -o "$TMPFILE" -X POST --data @<( - echo '["Request",'; - cat $2; - echo ']') https://apidsl.herokuapp.com/$1 - if grep '\[1,"' "$TMPFILE" > /dev/null; then + echo '["Request",' + cat "$2" + echo ']' + ) "https://apidsl.herokuapp.com/$1" + if grep '\[1,"' "$TMPFILE" >/dev/null; then echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2 rm "$TMPFILE" exit 1 @@ -52,34 +53,42 @@ apidsl_curl() { echo "apidsl_curl $*" >&2 apidsl_request "c" <( apidsl_request "parse" <( - perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON" + perl -0777 -pe "$TO_JSON" "$1" + ) + ) | perl -0777 -pe "$FROM_JSON" } # Check if apidsl generated sources are up to date. set +x -$APIDSL toxcore/LAN_discovery.api.h > toxcore/LAN_discovery.h & -$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h & -$APIDSL toxcore/ping.api.h > toxcore/ping.h & -$APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h & -$APIDSL toxcore/tox.api.h > toxcore/tox.h & -$APIDSL toxav/toxav.api.h > toxav/toxav.h & -$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h & +"$APIDSL" toxcore/LAN_discovery.api.h >toxcore/LAN_discovery.h & +"$APIDSL" toxcore/crypto_core.api.h >toxcore/crypto_core.h & +"$APIDSL" toxcore/ping.api.h >toxcore/ping.h & +"$APIDSL" toxcore/ping_array.api.h >toxcore/ping_array.h & +"$APIDSL" toxcore/tox.api.h >toxcore/tox.h & +"$APIDSL" toxav/toxav.api.h >toxav/toxav.h & +"$APIDSL" toxencryptsave/toxencryptsave.api.h >toxencryptsave/toxencryptsave.h & set -x -wait; wait; wait; wait; wait; wait; wait +wait +wait +wait +wait +wait +wait +wait if grep '' ./*/*.h; then echo "error: some apidsl references were unresolved" exit 1 fi -CC_SOURCES=$(find . '(' -name '*.cc' ')') -CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c" -CC_SOURCES="$CC_SOURCES toxcore/ping_array.c" +readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' ')')" +CC_SOURCES+=(toxcore/crypto_core.c) +CC_SOURCES+=(toxcore/ping_array.c) for bin in clang-format-6.0 clang-format-5.0 clang-format; do if which "$bin"; then - "$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' $CC_SOURCES + "$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' "${CC_SOURCES[@]}" break fi done @@ -91,8 +100,8 @@ FIND="$FIND -and -not -wholename './super_donators/*'" FIND="$FIND -and -not -wholename './third_party/*'" FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'" -C_SOURCES=$(eval "$FIND") +readarray -t C_SOURCES <<<"$(eval "$FIND")" -$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES +"$ASTYLE" -n --options=other/astyle/astylerc "${C_SOURCES[@]}" -git diff --exit-code +git diff --color=always --exit-code diff --git a/other/docker/Dockerfile.ci b/other/docker/Dockerfile.ci new file mode 100644 index 0000000000..db7e5e2cee --- /dev/null +++ b/other/docker/Dockerfile.ci @@ -0,0 +1,75 @@ +# This Docker build emulates roughly what Travis CI is doing. It is not exactly +# the same (different tool versions) and success in this image may not +# necessarily mean success on Travis. This image is also not automatically +# tested, so it may get out of date. Send PRs if you use it and it's broken. +# +# For one, we use bionic, not xenial, because xenial's clang is way too old. +FROM ubuntu:16.04 + +# Travis environment. +RUN apt-get update && apt-get install --no-install-recommends -y \ + apt-transport-https \ + build-essential \ + ca-certificates \ + curl \ + git \ + pkg-config \ + python-pip \ + python-setuptools \ + python3 \ + software-properties-common \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ + && apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" \ + && apt-get update && apt-get install --no-install-recommends -y \ + clang-6.0 \ + clang-format-6.0 \ + llvm-6.0 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN ls /usr/bin/clang-6.0 && ln -s /usr/bin/clang-6.0 /usr/bin/clang \ + && ls /usr/bin/clang++-6.0 && ln -s /usr/bin/clang++-6.0 /usr/bin/clang++ \ + && ls /usr/bin/clang-format-6.0 && ln -s /usr/bin/clang-format-6.0 /usr/bin/clang-format \ + && ls /usr/bin/opt-6.0 && ln -s /usr/bin/opt-6.0 /usr/bin/opt + +# Bionic's cmake is too old. +RUN pip install --upgrade pip cmake + +# .travis.yml +RUN apt-get update && apt-get install --no-install-recommends -y \ + libconfig-dev \ + libgtest-dev \ + libopus-dev \ + libsodium-dev \ + libvpx-dev \ + ninja-build \ + pylint3 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Set up travis user. +RUN groupadd -r -g 1000 travis \ + && useradd --no-log-init -r -g travis -u 1000 travis \ + && mkdir -p /src/workspace /home/travis \ + && chown travis:travis /home/travis +USER travis + +# Set up environment. +ENV CC=gcc CXX=g++ \ +PATH=/home/travis/.local/bin:$PATH \ +TRAVIS_REPO_SLUG=TokTok/c-toxcore + +# Copy minimal files to run "cmake-linux install", so we can avoid rebuilding +# astyle and other things when only source files change. +RUN mkdir -p /home/travis/build/c-toxcore /home/travis/cache +WORKDIR /home/travis/build/c-toxcore +COPY --chown=travis:travis c-toxcore/.travis/ /home/travis/build/c-toxcore/.travis/ +RUN .travis/cmake-linux install + +# Now copy the rest of the sources and run the build. +COPY --chown=travis:travis . /home/travis/build/ +RUN .travis/cmake-linux script diff --git a/other/docker/run-ci b/other/docker/run-ci new file mode 100755 index 0000000000..9005cfbd4d --- /dev/null +++ b/other/docker/run-ci @@ -0,0 +1,15 @@ +#!/bin/bash + +set -eu + +readarray -t FILES <<<"$(git ls-files | sed -e 's,^,c-toxcore/,')" + +if [ -f .git ]; then + cd .. + tar -c "${FILES[@]}" "c-toxcore/.git" ".git/modules/c-toxcore" | + docker build -f c-toxcore/other/docker/Dockerfile.ci - +else + cd .. + tar -c "${FILES[@]}" "c-toxcore/.git" | + docker build -f c-toxcore/other/docker/Dockerfile.ci - +fi