summaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2020-05-03 15:36:57 +0100
committeriphydf <iphydf@users.noreply.github.com>2020-05-03 16:59:26 +0100
commit4efe541814ec2ddd073428d6928497b50c48397a (patch)
treeb2d3c877317da1d129900b88097d05ffa879281f /other
parent88b90c82259f86470cf6eba8684e8d9b4cd61bc3 (diff)
Add a script to run Travis CI locally.
This isn't quite Travis, but close enough for local testing.
Diffstat (limited to 'other')
-rwxr-xr-xother/analysis/check_recursion29
-rwxr-xr-xother/astyle/format-source49
-rw-r--r--other/docker/Dockerfile.ci75
-rwxr-xr-xother/docker/run-ci15
4 files changed, 139 insertions, 29 deletions
diff --git a/other/analysis/check_recursion b/other/analysis/check_recursion
index 21063527..a8a6e0ef 100755
--- a/other/analysis/check_recursion
+++ b/other/analysis/check_recursion
@@ -1,8 +1,8 @@
1#!/usr/bin/env python 1#!/usr/bin/env python3
2""" 2"""
3Tool to check for recursive calls in toxcore C code. 3Tool to check for recursive calls in toxcore C code.
4 4
5Usage: 5Usage:
6 6
7cat toxav/*.c toxcore/*.c toxencryptsave/*.c \ 7cat toxav/*.c toxcore/*.c toxencryptsave/*.c \
8 | clang `pkg-config --cflags libsodium opus vpx` \ 8 | clang `pkg-config --cflags libsodium opus vpx` \
@@ -10,16 +10,17 @@ cat toxav/*.c toxcore/*.c toxencryptsave/*.c \
10 | opt -analyze -print-callgraph 2>&1 \ 10 | opt -analyze -print-callgraph 2>&1 \
11 | other/analysis/check_recursion 11 | other/analysis/check_recursion
12""" 12"""
13
14from __future__ import print_function
15
16import collections 13import collections
17import fileinput 14import fileinput
18import re 15import re
19import sys 16import sys
20import time 17import time
18from typing import Dict
19from typing import List
20from typing import Set
21 21
22def load_callgraph(): 22
23def load_callgraph() -> Dict:
23 """ 24 """
24 Parses the output from opt -print-callgraph from stdin or argv. 25 Parses the output from opt -print-callgraph from stdin or argv.
25 26
@@ -39,7 +40,14 @@ def load_callgraph():
39 40
40 return {k: sorted(v) for k, v in graph.items()} 41 return {k: sorted(v) for k, v in graph.items()}
41 42
42def walk(visited, callgraph, cycles, stack, cur): 43
44def walk(
45 visited: Set,
46 callgraph: Dict,
47 cycles: Set,
48 stack: List,
49 cur: str,
50) -> None:
43 """ 51 """
44 Detects cycles in the callgraph and adds them to the cycles parameter. 52 Detects cycles in the callgraph and adds them to the cycles parameter.
45 """ 53 """
@@ -54,13 +62,15 @@ def walk(visited, callgraph, cycles, stack, cur):
54 visited.add(callee) 62 visited.add(callee)
55 stack.pop() 63 stack.pop()
56 64
57def get_time(): 65
66def get_time() -> int:
58 """ 67 """
59 Return the current time in milliseconds. 68 Return the current time in milliseconds.
60 """ 69 """
61 return int(round(time.time() * 1000)) 70 return int(round(time.time() * 1000))
62 71
63def find_recursion(expected): 72
73def find_recursion(expected: Set) -> None:
64 """ 74 """
65 Main function: detects cycles and prints them. 75 Main function: detects cycles and prints them.
66 76
@@ -98,6 +108,7 @@ def find_recursion(expected):
98 if expected or cycles: 108 if expected or cycles:
99 sys.exit(1) 109 sys.exit(1)
100 110
111
101find_recursion(expected={ 112find_recursion(expected={
102 "add_to_closest -> add_to_closest", 113 "add_to_closest -> add_to_closest",
103 "add_to_list -> add_to_list", 114 "add_to_list -> add_to_list",
diff --git a/other/astyle/format-source b/other/astyle/format-source
index 193e335c..7de28d06 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'
36apidsl_request() { 36apidsl_request() {
37 TMPFILE=$(mktemp /tmp/apidsl.XXXXXX) 37 TMPFILE=$(mktemp /tmp/apidsl.XXXXXX)
38 curl -s -o "$TMPFILE" -X POST --data @<( 38 curl -s -o "$TMPFILE" -X POST --data @<(
39 echo '["Request",'; 39 echo '["Request",'
40 cat $2; 40 cat "$2"
41 echo ']') https://apidsl.herokuapp.com/$1 41 echo ']'
42 if grep '\[1,"' "$TMPFILE" > /dev/null; then 42 ) "https://apidsl.herokuapp.com/$1"
43 if grep '\[1,"' "$TMPFILE" >/dev/null; then
43 echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2 44 echo "Error: $(grep -o '".*"' /tmp/apidsl-$$ | perl -0777 -pe "$FROM_JSON")" >&2
44 rm "$TMPFILE" 45 rm "$TMPFILE"
45 exit 1 46 exit 1
@@ -52,34 +53,42 @@ apidsl_curl() {
52 echo "apidsl_curl $*" >&2 53 echo "apidsl_curl $*" >&2
53 apidsl_request "c" <( 54 apidsl_request "c" <(
54 apidsl_request "parse" <( 55 apidsl_request "parse" <(
55 perl -0777 -pe "$TO_JSON" $1)) | perl -0777 -pe "$FROM_JSON" 56 perl -0777 -pe "$TO_JSON" "$1"
57 )
58 ) | perl -0777 -pe "$FROM_JSON"
56} 59}
57 60
58# Check if apidsl generated sources are up to date. 61# Check if apidsl generated sources are up to date.
59set +x 62set +x
60$APIDSL toxcore/LAN_discovery.api.h > toxcore/LAN_discovery.h & 63"$APIDSL" toxcore/LAN_discovery.api.h >toxcore/LAN_discovery.h &
61$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h & 64"$APIDSL" toxcore/crypto_core.api.h >toxcore/crypto_core.h &
62$APIDSL toxcore/ping.api.h > toxcore/ping.h & 65"$APIDSL" toxcore/ping.api.h >toxcore/ping.h &
63$APIDSL toxcore/ping_array.api.h > toxcore/ping_array.h & 66"$APIDSL" toxcore/ping_array.api.h >toxcore/ping_array.h &
64$APIDSL toxcore/tox.api.h > toxcore/tox.h & 67"$APIDSL" toxcore/tox.api.h >toxcore/tox.h &
65$APIDSL toxav/toxav.api.h > toxav/toxav.h & 68"$APIDSL" toxav/toxav.api.h >toxav/toxav.h &
66$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h & 69"$APIDSL" toxencryptsave/toxencryptsave.api.h >toxencryptsave/toxencryptsave.h &
67set -x 70set -x
68 71
69wait; wait; wait; wait; wait; wait; wait 72wait
73wait
74wait
75wait
76wait
77wait
78wait
70 79
71if grep '<unresolved>' ./*/*.h; then 80if grep '<unresolved>' ./*/*.h; then
72 echo "error: some apidsl references were unresolved" 81 echo "error: some apidsl references were unresolved"
73 exit 1 82 exit 1
74fi 83fi
75 84
76CC_SOURCES=$(find . '(' -name '*.cc' ')') 85readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' ')')"
77CC_SOURCES="$CC_SOURCES toxcore/crypto_core.c" 86CC_SOURCES+=(toxcore/crypto_core.c)
78CC_SOURCES="$CC_SOURCES toxcore/ping_array.c" 87CC_SOURCES+=(toxcore/ping_array.c)
79 88
80for bin in clang-format-6.0 clang-format-5.0 clang-format; do 89for bin in clang-format-6.0 clang-format-5.0 clang-format; do
81 if which "$bin"; then 90 if which "$bin"; then
82 "$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' $CC_SOURCES 91 "$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' "${CC_SOURCES[@]}"
83 break 92 break
84 fi 93 fi
85done 94done
@@ -91,8 +100,8 @@ FIND="$FIND -and -not -wholename './super_donators/*'"
91FIND="$FIND -and -not -wholename './third_party/*'" 100FIND="$FIND -and -not -wholename './third_party/*'"
92FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'" 101FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'"
93 102
94C_SOURCES=$(eval "$FIND") 103readarray -t C_SOURCES <<<"$(eval "$FIND")"
95 104
96$ASTYLE -n --options=other/astyle/astylerc $C_SOURCES 105"$ASTYLE" -n --options=other/astyle/astylerc "${C_SOURCES[@]}"
97 106
98git diff --exit-code 107git diff --color=always --exit-code
diff --git a/other/docker/Dockerfile.ci b/other/docker/Dockerfile.ci
new file mode 100644
index 00000000..db7e5e2c
--- /dev/null
+++ b/other/docker/Dockerfile.ci
@@ -0,0 +1,75 @@
1# This Docker build emulates roughly what Travis CI is doing. It is not exactly
2# the same (different tool versions) and success in this image may not
3# necessarily mean success on Travis. This image is also not automatically
4# tested, so it may get out of date. Send PRs if you use it and it's broken.
5#
6# For one, we use bionic, not xenial, because xenial's clang is way too old.
7FROM ubuntu:16.04
8
9# Travis environment.
10RUN apt-get update && apt-get install --no-install-recommends -y \
11 apt-transport-https \
12 build-essential \
13 ca-certificates \
14 curl \
15 git \
16 pkg-config \
17 python-pip \
18 python-setuptools \
19 python3 \
20 software-properties-common \
21 wget \
22 && apt-get clean \
23 && rm -rf /var/lib/apt/lists/*
24
25RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
26 && apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" \
27 && apt-get update && apt-get install --no-install-recommends -y \
28 clang-6.0 \
29 clang-format-6.0 \
30 llvm-6.0 \
31 && apt-get clean \
32 && rm -rf /var/lib/apt/lists/*
33
34RUN ls /usr/bin/clang-6.0 && ln -s /usr/bin/clang-6.0 /usr/bin/clang \
35 && ls /usr/bin/clang++-6.0 && ln -s /usr/bin/clang++-6.0 /usr/bin/clang++ \
36 && ls /usr/bin/clang-format-6.0 && ln -s /usr/bin/clang-format-6.0 /usr/bin/clang-format \
37 && ls /usr/bin/opt-6.0 && ln -s /usr/bin/opt-6.0 /usr/bin/opt
38
39# Bionic's cmake is too old.
40RUN pip install --upgrade pip cmake
41
42# .travis.yml
43RUN apt-get update && apt-get install --no-install-recommends -y \
44 libconfig-dev \
45 libgtest-dev \
46 libopus-dev \
47 libsodium-dev \
48 libvpx-dev \
49 ninja-build \
50 pylint3 \
51 && apt-get clean \
52 && rm -rf /var/lib/apt/lists/*
53
54# Set up travis user.
55RUN groupadd -r -g 1000 travis \
56 && useradd --no-log-init -r -g travis -u 1000 travis \
57 && mkdir -p /src/workspace /home/travis \
58 && chown travis:travis /home/travis
59USER travis
60
61# Set up environment.
62ENV CC=gcc CXX=g++ \
63PATH=/home/travis/.local/bin:$PATH \
64TRAVIS_REPO_SLUG=TokTok/c-toxcore
65
66# Copy minimal files to run "cmake-linux install", so we can avoid rebuilding
67# astyle and other things when only source files change.
68RUN mkdir -p /home/travis/build/c-toxcore /home/travis/cache
69WORKDIR /home/travis/build/c-toxcore
70COPY --chown=travis:travis c-toxcore/.travis/ /home/travis/build/c-toxcore/.travis/
71RUN .travis/cmake-linux install
72
73# Now copy the rest of the sources and run the build.
74COPY --chown=travis:travis . /home/travis/build/
75RUN .travis/cmake-linux script
diff --git a/other/docker/run-ci b/other/docker/run-ci
new file mode 100755
index 00000000..9005cfbd
--- /dev/null
+++ b/other/docker/run-ci
@@ -0,0 +1,15 @@
1#!/bin/bash
2
3set -eu
4
5readarray -t FILES <<<"$(git ls-files | sed -e 's,^,c-toxcore/,')"
6
7if [ -f .git ]; then
8 cd ..
9 tar -c "${FILES[@]}" "c-toxcore/.git" ".git/modules/c-toxcore" |
10 docker build -f c-toxcore/other/docker/Dockerfile.ci -
11else
12 cd ..
13 tar -c "${FILES[@]}" "c-toxcore/.git" |
14 docker build -f c-toxcore/other/docker/Dockerfile.ci -
15fi