Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GitHub Actions config. #30

Merged
merged 7 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Checks: 'cppcoreguidelines-*,clang-diagnostic-*,clang-analyzer-*'
WarningsAsErrors: '*'
AnalyzeTemporaryDtors: false
101 changes: 101 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# For documentation please refer to:
# https://docs.github.com/en/free-pro-team@latest/actions
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
black-check:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Cache Pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
- name: Cache Tox environments
uses: actions/cache@v2
with:
path: .tox
key: ${{ runner.os }}-tox-${{ hashFiles('tox.ini') }}
- run: pip install tox>=3
- run: tox -e black-check
clang-tidy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8-dev'
- name: Cache C++ third-party dependencies
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/thirdparty
key: ${{ runner.os }}-thirdparty-${{ hashFiles('FetchDependencies.cmake') }}
- name: Install CMake 3.19
run: sudo snap install cmake --channel=3.19/stable --classic
- run: |
sudo apt-get purge -y clang*
sudo sh -c "echo '$CLANG_APT' >> /etc/apt/sources.list"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y clang-tidy-11 clang-11
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-11 0
clang-tidy --version
env:
CLANG_APT: |
# i386 not available
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
# 10
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main
# 11
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main
- run: cmake .
- run: make clang-tidy
clang-format-check:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Cache C++ third-party dependencies
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/thirdparty
key: ${{ runner.os }}-thirdparty-${{ hashFiles('FetchDependencies.cmake') }}
- name: Install CMake 3.19
run: sudo snap install cmake --channel=3.19/stable --classic
- run: |
sudo apt-get purge -y clang*
sudo sh -c "echo '$CLANG_APT' >> /etc/apt/sources.list"
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y clang-format-11 clang-11
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 0
clang-format --version
env:
CLANG_APT: |
# i386 not available
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
# 10
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main
# 11
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main
- run: cmake .
- run: make clang-format-check
23 changes: 6 additions & 17 deletions FetchDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
set(THIRD_PARTY ${CMAKE_SOURCE_DIR}/thirdparty)
file(MAKE_DIRECTORY ${THIRD_PARTY})

if(NOT FETCH_DEPENDENCIES)
set(FETCH_DEPENDENCIES FALSE)
endif()

FILE(GLOB deps "${THIRD_PARTY}/*")
if(NOT deps)
set(FETCH_DEPENDENCIES TRUE)
endif()

# Fetch Boost.
# TODO: Can it be made partial?
if(FETCH_DEPENDENCIES)
if(NOT EXISTS "${THIRD_PARTY}/boost/")
message(NOTICE "Fetching Boost...")
FetchContent_Declare(
boost
Expand Down Expand Up @@ -58,23 +49,23 @@ if(FETCH_DEPENDENCIES)
endif()

# Fetch Pybind11.
if(FETCH_DEPENDENCIES)
if(NOT EXISTS "${THIRD_PARTY}/pybind11/")
message(NOTICE "Fetching Pybind11...")
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.5.0
GIT_TAG v2.6.1
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
SOURCE_DIR ${THIRD_PARTY}/pybind11
)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
endif()
endif(FETCH_DEPENDENCIES)
endif()

# Fetch Fmt library.
if(FETCH_DEPENDENCIES)
if(NOT EXISTS "${THIRD_PARTY}/fmt/")
message(NOTICE "Fetching Fmt...")
FetchContent_Declare(
fmt
Expand All @@ -90,7 +81,7 @@ if(FETCH_DEPENDENCIES)
endif()

# Fetch Spdlog.
if(FETCH_DEPENDENCIES)
if(NOT EXISTS "${THIRD_PARTY}/spdlog/")
message(NOTICE "Fetching Spdlog...")
FetchContent_Declare(
spdlog
Expand All @@ -104,5 +95,3 @@ if(FETCH_DEPENDENCIES)
FetchContent_Populate(spdlog)
endif()
endif()

unset(FETCH_DEPENDENCIES CACHE)
54 changes: 25 additions & 29 deletions scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,32 @@

DIRECTORIES = [
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir,
"include"
os.path.dirname(os.path.abspath(__file__)), os.pardir, "include"
),
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir,
"src",
"cpp"
)
os.path.dirname(os.path.abspath(__file__)), os.pardir, "src", "cpp"
),
]


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser(
'format',
"format",
description="""
Format C++ sources using Clang-Format.
"""
""",
)
parser.add_argument(
'--check',
'-C',
"--check",
"-C",
help="Do not format files but check if formatting is needed and exit "
"with non-zero code if it is.",
action='store_true',
default=False
"with non-zero code if it is.",
action="store_true",
default=False,
)
parser.add_argument(
'files',
nargs='*',
"files",
nargs="*",
)
arguments = parser.parse_args()
filepaths = []
Expand All @@ -62,22 +57,23 @@
sys.exit(result.returncode)
with open(filepath) as file_handle:
actual_source = file_handle.read()
diff = '\n'.join(difflib.unified_diff(
result.stdout.decode().split('\n'),
actual_source.split('\n'),
'Formatted source',
f'Actual source ({filepath})',
lineterm=''
))
diff = "\n".join(
difflib.unified_diff(
result.stdout.decode().split("\n"),
actual_source.split("\n"),
"Formatted source",
f"Actual source ({filepath})",
lineterm="",
)
)
if diff:
print('Fail')
print("Fail")
print(diff, file=sys.stderr, flush=True)
sys.exit(1)
print('Ok')
print("Ok")
sys.exit(0)
else:
result = subprocess.run(
["clang-format", "-i", "-style=file"] + filepaths,
env=os.environ
["clang-format", "-i", "-style=file"] + filepaths, env=os.environ
)
sys.exit(result.returncode)
2 changes: 1 addition & 1 deletion src/cpp/gauge/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PYBIND11_MAKE_OPAQUE(std::vector<std::shared_ptr<Span>>);
// TODO: 1. Make __repr__(), __hash__(), __eq__(), __ne__()
// for Frame and Trace classes.
// clang-format off
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-vararg)
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-vararg, cppcoreguidelines-avoid-non-const-global-variables)
PYBIND11_MODULE(_gauge, m) {
// clang-format on
py::bind_vector<
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/gauge/utils/benchmark.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GAUGE_BENCHMARK_HPP
#define GAUGE_BENCHMARK_HPP
#include <chrono>
#include <string>
#include <unordered_map>

class Timer {
Expand All @@ -9,9 +10,9 @@ class Timer {
long long observations_count = 0;
long double average = 0;
};
std::unordered_map<std::string, Average> averages;
std::unordered_map<std::string, Average> averages{};
std::unordered_map<std::string, std::chrono::steady_clock::time_point>
pending;
pending{};

public:
Timer() = default;
Expand Down