Skip to content

Commit 2e18193

Browse files
committed
Squashed 'src/crc32c/' content from commit 224988680f7673cd7c769963d4035cb315aa3388
git-subtree-dir: src/crc32c git-subtree-split: 224988680f7673cd7c769963d4035cb315aa3388
0 parents  commit 2e18193

38 files changed

+2730
-0
lines changed

.appveyor.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Build matrix / environment variables are explained on:
2+
# https://www.appveyor.com/docs/appveyor-yml/
3+
# This file can be validated on: https://ci.appveyor.com/tools/validate-yaml
4+
5+
version: "{build}"
6+
7+
environment:
8+
matrix:
9+
# AppVeyor currently has no custom job name feature.
10+
# http://help.appveyor.com/discussions/questions/1623-can-i-provide-a-friendly-name-for-jobs
11+
- JOB: Visual Studio 2017
12+
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
13+
CMAKE_GENERATOR: Visual Studio 15 2017
14+
15+
platform:
16+
- x86
17+
- x64
18+
19+
configuration:
20+
- RelWithDebInfo
21+
- Debug
22+
23+
build_script:
24+
- git submodule update --init --recursive
25+
- mkdir build
26+
- cd build
27+
- if "%platform%"=="x64" set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64
28+
- cmake --version
29+
- cmake .. -G "%CMAKE_GENERATOR%" -DCRC32C_USE_GLOG=0
30+
-DCMAKE_CONFIGURATION_TYPES="%CONFIGURATION%"
31+
- cmake --build . --config "%CONFIGURATION%"
32+
- cd ..
33+
34+
test_script:
35+
- build\%CONFIGURATION%\crc32c_tests.exe
36+
- build\%CONFIGURATION%\crc32c_capi_tests.exe
37+
- build\%CONFIGURATION%\crc32c_bench.exe

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google

.clang_complete

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-Ibuild/include/
2+
-Ibuild/third_party/glog/
3+
-Iinclude/
4+
-Ithird_party/benchmark/include/
5+
-Ithird_party/googletest/googletest/include/
6+
-Ithird_party/googletest/googlemock/include/
7+
-Ithird_party/glog/src/
8+
-std=c++11

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Editors.
2+
*.sw*
3+
.DS_Store
4+
/.vscode
5+
6+
# Build directory.
7+
build/
8+
out/

.gitmodules

Whitespace-only changes.

.travis.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Build matrix / environment variables are explained on:
2+
# http://about.travis-ci.org/docs/user/build-configuration/
3+
# This file can be validated on: http://lint.travis-ci.org/
4+
5+
language: cpp
6+
dist: bionic
7+
osx_image: xcode10.3
8+
9+
compiler:
10+
- gcc
11+
- clang
12+
os:
13+
- linux
14+
- osx
15+
16+
env:
17+
- GLOG=1 SHARED_LIB=0 BUILD_TYPE=Debug
18+
- GLOG=1 SHARED_LIB=0 BUILD_TYPE=RelWithDebInfo
19+
- GLOG=0 SHARED_LIB=0 BUILD_TYPE=Debug
20+
- GLOG=0 SHARED_LIB=0 BUILD_TYPE=RelWithDebInfo
21+
- GLOG=0 SHARED_LIB=1 BUILD_TYPE=Debug
22+
- GLOG=0 SHARED_LIB=1 BUILD_TYPE=RelWithDebInfo
23+
24+
addons:
25+
apt:
26+
sources:
27+
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
28+
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
29+
- sourceline: 'ppa:ubuntu-toolchain-r/test'
30+
packages:
31+
- clang-9
32+
- cmake
33+
- gcc-9
34+
- g++-9
35+
- ninja-build
36+
homebrew:
37+
packages:
38+
- cmake
39+
- gcc@9
40+
- llvm@9
41+
- ninja
42+
update: true
43+
44+
install:
45+
# The following Homebrew packages aren't linked by default, and need to be
46+
# prepended to the path explicitly.
47+
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then
48+
export PATH="$(brew --prefix llvm)/bin:$PATH";
49+
fi
50+
# /usr/bin/gcc points to an older compiler on both Linux and macOS.
51+
- if [ "$CXX" = "g++" ]; then export CXX="g++-9" CC="gcc-9"; fi
52+
# /usr/bin/clang points to an older compiler on both Linux and macOS.
53+
#
54+
# Homebrew's llvm package doesn't ship a versioned clang++ binary, so the values
55+
# below don't work on macOS. Fortunately, the path change above makes the
56+
# default values (clang and clang++) resolve to the correct compiler on macOS.
57+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
58+
if [ "$CXX" = "clang++" ]; then export CXX="clang++-9" CC="clang-9"; fi;
59+
fi
60+
- echo ${CC}
61+
- echo ${CXX}
62+
- ${CXX} --version
63+
- cmake --version
64+
65+
before_script:
66+
- mkdir -p build && cd build
67+
- cmake .. -G Ninja -DCRC32C_USE_GLOG=$GLOG -DCMAKE_BUILD_TYPE=$BUILD_TYPE
68+
-DBUILD_SHARED_LIBS=$SHARED_LIB -DCMAKE_INSTALL_PREFIX=$HOME/.local
69+
- cmake --build .
70+
- cd ..
71+
72+
script:
73+
- build/crc32c_tests
74+
- build/crc32c_capi_tests
75+
- build/crc32c_bench
76+
- cd build && cmake --build . --target install

.ycm_extra_conf.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2017 The CRC32C Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
"""YouCompleteMe configuration that interprets a .clang_complete file.
5+
6+
This module implementes the YouCompleteMe configuration API documented at:
7+
https://github.com/Valloric/ycmd#ycm_extra_confpy-specification
8+
9+
The implementation loads and processes a .clang_complete file, documented at:
10+
https://github.com/Rip-Rip/clang_complete/blob/master/README.md
11+
"""
12+
13+
import os
14+
15+
# Flags added to the list in .clang_complete.
16+
BASE_FLAGS = [
17+
'-Werror', # Unlike clang_complete, YCM can also be used as a linter.
18+
'-DUSE_CLANG_COMPLETER', # YCM needs this.
19+
'-xc++', # YCM needs this to avoid compiling headers as C code.
20+
]
21+
22+
# Clang flags that take in paths.
23+
# See https://clang.llvm.org/docs/ClangCommandLineReference.html
24+
PATH_FLAGS = [
25+
'-isystem',
26+
'-I',
27+
'-iquote',
28+
'--sysroot='
29+
]
30+
31+
32+
def DirectoryOfThisScript():
33+
"""Returns the absolute path to the directory containing this script."""
34+
return os.path.dirname(os.path.abspath(__file__))
35+
36+
37+
def MakeRelativePathsInFlagsAbsolute(flags, build_root):
38+
"""Expands relative paths in a list of Clang command-line flags.
39+
40+
Args:
41+
flags: The list of flags passed to Clang.
42+
build_root: The current directory when running the Clang compiler. Should be
43+
an absolute path.
44+
45+
Returns:
46+
A list of flags with relative paths replaced by absolute paths.
47+
"""
48+
new_flags = []
49+
make_next_absolute = False
50+
for flag in flags:
51+
new_flag = flag
52+
53+
if make_next_absolute:
54+
make_next_absolute = False
55+
if not flag.startswith('/'):
56+
new_flag = os.path.join(build_root, flag)
57+
58+
for path_flag in PATH_FLAGS:
59+
if flag == path_flag:
60+
make_next_absolute = True
61+
break
62+
63+
if flag.startswith(path_flag):
64+
path = flag[len(path_flag):]
65+
new_flag = path_flag + os.path.join(build_root, path)
66+
break
67+
68+
if new_flag:
69+
new_flags.append(new_flag)
70+
return new_flags
71+
72+
73+
def FindNearest(target, path, build_root):
74+
"""Looks for a file with a specific name closest to a project path.
75+
76+
This is similar to the logic used by a version-control system (like git) to
77+
find its configuration directory (.git) based on the current directory when a
78+
command is invoked.
79+
80+
Args:
81+
target: The file name to search for.
82+
path: The directory where the search starts. The search will explore the
83+
given directory's ascendants using the parent relationship. Should be an
84+
absolute path.
85+
build_root: A directory that acts as a fence for the search. If the search
86+
reaches this directory, it will not advance to its parent. Should be an
87+
absolute path.
88+
89+
Returns:
90+
The path to a file with the desired name. None if the search failed.
91+
"""
92+
candidate = os.path.join(path, target)
93+
if os.path.isfile(candidate):
94+
return candidate
95+
96+
if path == build_root:
97+
return None
98+
99+
parent = os.path.dirname(path)
100+
if parent == path:
101+
return None
102+
103+
return FindNearest(target, parent, build_root)
104+
105+
106+
def FlagsForClangComplete(file_path, build_root):
107+
"""Reads the .clang_complete flags for a source file.
108+
109+
Args:
110+
file_path: The path to the source file. Should be inside the project. Used
111+
to locate the relevant .clang_complete file.
112+
build_root: The current directory when running the Clang compiler for this
113+
file. Should be an absolute path.
114+
115+
Returns:
116+
A list of strings, where each element is a Clang command-line flag.
117+
"""
118+
clang_complete_path = FindNearest('.clang_complete', file_path, build_root)
119+
if clang_complete_path is None:
120+
return None
121+
clang_complete_flags = open(clang_complete_path, 'r').read().splitlines()
122+
return clang_complete_flags
123+
124+
125+
def FlagsForFile(filename, **kwargs):
126+
"""Implements the YouCompleteMe API."""
127+
128+
# kwargs can be used to pass 'client_data' to the YCM configuration. This
129+
# configuration script does not need any extra information, so
130+
# pylint: disable=unused-argument
131+
132+
build_root = DirectoryOfThisScript()
133+
file_path = os.path.realpath(filename)
134+
135+
flags = BASE_FLAGS
136+
clang_flags = FlagsForClangComplete(file_path, build_root)
137+
if clang_flags:
138+
flags += clang_flags
139+
140+
final_flags = MakeRelativePathsInFlagsAbsolute(flags, build_root)
141+
142+
return {'flags': final_flags}

AUTHORS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is the list of CRC32C authors for copyright purposes.
2+
#
3+
# This does not necessarily list everyone who has contributed code, since in
4+
# some cases, their employer may be the copyright holder. To see the full list
5+
# of contributors, see the revision history in source control.
6+
Google Inc.
7+
8+
Fangming Fang <[email protected]>
9+
Vadim Skipin <[email protected]>

0 commit comments

Comments
 (0)