Skip to content

Commit

Permalink
Port to clang-7 (#23)
Browse files Browse the repository at this point in the history
* Port to clang-7
* Move to ubuntu 18.10 for docker image
* Switch to gcc-7 for compilation
* Don't drop support for clang6 yet. Introduce a build matrix for the same
* Explicitly specify language (travis detected Ruby)

Signed-off-by: Vaibhav Yenamandra <vyenamandra@bloomberg.net>
  • Loading branch information
vaibhav-y authored and ruoso committed Oct 10, 2018
1 parent 6044e02 commit d8b60a8
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
File renamed without changes.
63 changes: 63 additions & 0 deletions .travis.clang7.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FROM ubuntu:18.10

# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc-7 \
g++-7 \
clang-format-7 \
clang-tools-7 \
clang-tidy-7 \
cmake \
libclang-7-dev \
libfile-spec-native-perl \
libgtest-dev

# Set up clang compilers
ENV CC=/usr/bin/gcc-7 \
CXX=/usr/bin/g++-7

# Fix issues with gtest installation from ubuntu debian
RUN cd /usr/src/gtest && \
cmake . && \
make && \
mv libg* /usr/lib

# Fix issues with clang installation from ubuntu debian
RUN mkdir -p /usr/lib/cmake && \
ln -s /usr/share/llvm-7/cmake /usr/lib/cmake/clang && \
for hdr in /usr/lib/llvm-7/include/clang/*; do \
ln -s $hdr /usr/include/clang/$(basename $hdr); \
done && \
ln -s /usr/lib/llvm-7/include/clang-c /usr/include/clang-c && \
ln -s /usr/lib/llvm-7/include/llvm /usr/include/llvm && \
ln -s /usr/lib/llvm-7/include/llvm-c /usr/include/llvm-c && \
for lib in /usr/lib/llvm-7/lib/*; do \
ln -s $lib /usr/lib/$(basename $lib); \
done && \
for bin in /usr/bin/*-7; do \
ln -s $bin /usr/bin/$(basename $bin | rev | cut -d '-' -f2- | rev); \
done

COPY . clangmetatool/
WORKDIR clangmetatool

# Build tool, run tests, and do a test install
RUN mkdir build && cd build && \
cmake -DClang_DIR=/usr/share/llvm-7/cmake .. && \
make all test && \
make install && \
cd .. && rm -rf build

# Fix includes for clangmetatool (due to ubuntu debian's clang)
RUN ln -s /usr/lib/llvm-7/include/clangmetatool /usr/include/clangmetatool

# Build skeleton
RUN mkdir skeleton/build && cd skeleton/build && \
cmake -DClang_DIR=/usr/lib/llvm-7/lib/cmake/clang \
-Dclangmetatool_DIR=/usr/lib/llvm-7/lib/cmake/clang .. && \
make all && \
make install && \
cd - && rm -rf skeleton/build

# Run the tool on itself
RUN yourtoolname $(find src skeleton -name '*.cpp') -- -std=gnu++14
16 changes: 14 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@ sudo: required
services:
- docker

script:
- sudo docker build -f .travis.Dockerfile .
matrix:
include:
- os: linux
compiler: gcc
language: cpp
sudo: true
env: MAKEFLAGS="-j 2"
script: docker build -f .travis.clang6.Dockerfile .
- os: linux
compiler: gcc
language: cpp
sudo: true
env: MAKEFLAGS="-j 2"
script: docker build -f .travis.clang7.Dockerfile .
28 changes: 27 additions & 1 deletion src/collectors/include_graph/include_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

#include "include_graph_util.h"


namespace clangmetatool {
namespace collectors {
namespace include_graph {
Expand All @@ -62,6 +61,33 @@ namespace clangmetatool {
llvm::StringRef searchPath,
llvm::StringRef relativePath,
const clang::Module *imported) {
InclusionDirective(hashLoc,
includeToken,
filename,
isAngled,
filenameRange,
file,
searchPath,
relativePath,
imported,
clang::SrcMgr::CharacteristicKind::C_User);
}

void
IncludeFinder::InclusionDirective
(clang::SourceLocation hashLoc,
const clang::Token &includeToken,
llvm::StringRef filename,
bool isAngled,
clang::CharSourceRange filenameRange,
const clang::FileEntry *file,
llvm::StringRef searchPath,
llvm::StringRef relativePath,
const clang::Module *imported,
clang::SrcMgr::CharacteristicKind FileType_)
{
// The filetype characteristic is unused for now, hence marked with
// a trailing '_'. We are recording all filetypes
add_include_statement
( ci,
data,
Expand Down
24 changes: 23 additions & 1 deletion src/collectors/include_graph/include_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <clangmetatool/types/file_uid.h>
#include <clangmetatool/collectors/include_graph_data.h>

// Required to know which version of LLVM/Clang we're building against
#include <llvm/Config/llvm-config.h>

namespace clangmetatool {
namespace collectors {
namespace include_graph {
Expand All @@ -37,7 +40,26 @@ namespace clangmetatool {
llvm::StringRef searchPath,
llvm::StringRef relativePath,
const clang::Module *imported)
override;
#if LLVM_VERSION_MAJOR == 6
override
#endif
;


virtual void InclusionDirective(clang::SourceLocation hashLoc,
const clang::Token &includeToken,
llvm::StringRef filename,
bool isAngled,
clang::CharSourceRange filenameRange,
const clang::FileEntry *file,
llvm::StringRef searchPath,
llvm::StringRef relativePath,
const clang::Module *imported,
clang::SrcMgr::CharacteristicKind FileType_)
#if LLVM_VERSION_MAJOR == 7
override
#endif
;

virtual void MacroExpands(const clang::Token &macroUsage,
const clang::MacroDefinition &macroDef,
Expand Down

0 comments on commit d8b60a8

Please sign in to comment.