From 943ba1773e1e768c131da0ad2b4c9b3d29f7232f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 27 Mar 2018 23:20:32 +0200 Subject: [PATCH 1/6] [GitLab] Add .gitlab-ci.yml - add a GitLab CI configuration file to run a pipeline on the major Linux distros - add a build script that builds all build combinations of exiv2 & runs the test suite --- .gitlab-ci.yml | 64 +++++++++++++++++++++++++++++++ ci/debian_build_gtest.sh | 13 +++++++ ci/test_build.py | 81 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100755 ci/debian_build_gtest.sh create mode 100644 ci/test_build.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..466db950 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,64 @@ +# default build for all distros +# only create artifacts of the build directory when something fails (for cmake logs) +# cache the ccache/ directory for each job separately +.build_template: &distro_build + script: + - python3 ci/test_build.py + artifacts: + when: on_failure + paths: + - build/ + cache: + key: "$CI_JOB_NAME" + paths: + - ccache/ + +Fedora: + image: fedora:28 + before_script: + - dnf -y --refresh install gcc-c++ clang cmake make ccache expat-devel zlib-devel libssh-devel libcurl-devel gtest-devel which dos2unix + <<: *distro_build + +Debian: + image: debian:9 + before_script: + - apt-get update + - apt-get install -y cmake g++ clang make ccache python3 libexpat1-dev zlib1g-dev libssh-dev libcurl4-openssl-dev libgtest-dev libxml2-utils + - ./ci/debian_build_gtest.sh + <<: *distro_build + +Archlinux: + image: base/archlinux + before_script: + - pacman --noconfirm -Sy + - pacman --noconfirm -S gcc clang cmake make ccache expat zlib libssh curl gtest python dos2unix + <<: *distro_build + +Ubuntu: + image: ubuntu:18.04 + before_script: + - apt-get update + - apt-get install -y cmake g++ clang make ccache python3 libexpat1-dev zlib1g-dev libssh-dev libcurl4-openssl-dev libgtest-dev google-mock libxml2-utils + - ./ci/debian_build_gtest.sh + <<: *distro_build + +CentOS: + image: centos:7 + before_script: + - yum -y install yum-plugin-copr epel-release + # enable copr for gtest + - yum -y copr enable defolos/devel + - yum clean all + - yum -y install gcc-c++ clang cmake3 make ccache expat-devel zlib-devel libssh-devel libcurl-devel gtest-devel which python36 dos2unix + # symlink up to date versions of python & cmake to 'default' names + - ln -s /usr/bin/python36 /usr/bin/python3 + - mv /bin/cmake /bin/.cmake.old + - ln -s /bin/cmake3 /bin/cmake + <<: *distro_build + +OpenSUSE: + image: opensuse:tumbleweed + before_script: + - zypper --non-interactive refresh + - zypper --non-interactive install gcc-c++ clang cmake make ccache libexpat-devel zlib-devel libssh-devel libcurl-devel gtest which dos2unix libxml2-tools + <<: *distro_build diff --git a/ci/debian_build_gtest.sh b/ci/debian_build_gtest.sh new file mode 100755 index 00000000..a69a6e5b --- /dev/null +++ b/ci/debian_build_gtest.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Debian & derivatives don't provide binary packages of googletest +# => have to build them ourselves +# +# This script builds a shared library of googletest (not googlemock!) and copies +# it to usr/lib/ + +mkdir gtest_build && cd gtest_build +cmake -DBUILD_SHARED_LIBS=1 /usr/src/googletest/googletest +make +cp libgtest* /usr/lib/ +cd .. diff --git a/ci/test_build.py b/ci/test_build.py new file mode 100644 index 00000000..28b67e00 --- /dev/null +++ b/ci/test_build.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import itertools +import multiprocessing +import os +import shlex +import subprocess +import sys + +#: -DEXIV2_BUILD_SHARED_LIBS options +SHARED_LIBS = ["ON", "OFF"] + +#: C & C++ compiler as tuples +CCS = ["gcc", "clang"] + +#: -DCMAKE_BUILD_TYPE options +BUILD_TYPES = ["Debug", "Release"] + +#: Additional parameters for cmake +CMAKE_OPTIONS = os.getenv("CMAKE_OPTIONS") or \ + "-DEXIV2_TEAM_EXTRA_WARNINGS=ON -DEXIV2_ENABLE_VIDEO=ON "\ + "-DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_BUILD_UNIT_TESTS=ON "\ + "-DBUILD_WITH_CCACHE=ON " + +#: cpu count +NCPUS = multiprocessing.cpu_count() + + +def call_wrapper(*args, **kwargs): + """ + Wrapper around subprocess.call which terminates the program on non-zero + return value. + """ + return_code = subprocess.call(*args, **kwargs) + if return_code != 0: + sys.exit(return_code) + + +# create build & ccache directory (ccache could already exist in the CI's cache) +os.mkdir("build") +if not os.path.exists('ccache'): + os.mkdir("ccache") + +root_dir = os.path.abspath(os.getcwd()) + +for params in itertools.product(SHARED_LIBS, CCS, BUILD_TYPES): + + lib_type, cc, build_type = params + + cxx = {"gcc": "g++", "clang": "clang++"}[cc] + + cwd = os.path.abspath(os.path.join("build", "_".join(params))) + os.mkdir(cwd) + + cmake = "cmake {!s} -DCMAKE_BUILD_TYPE={build_type} "\ + "-DBUILD_SHARED_LIBS={lib_type} ../.."\ + .format(CMAKE_OPTIONS, build_type=build_type, lib_type=lib_type) + make = "make -j " + str(NCPUS) + make_tests = "make tests" + unit_tests = os.path.join(cwd, "bin", "unit_tests") + + # set up environment + env_copy = os.environ.copy() + env_copy["CC"] = cc + env_copy["CXX"] = cxx + env_copy["CCACHE_BASEDIR"] = root_dir + env_copy["CCACHE_DIR"] = os.path.join(root_dir, "ccache") + + # location of the binaries for the new test suite: + env_copy["EXIV2_PATH"] = os.path.join(cwd, "bin") + + kwargs = {"env": env_copy, "cwd": cwd} + + def run(cmd): + call_wrapper(shlex.split(cmd), **kwargs) + + run(cmake) + run(make) + run(make_tests) + run(unit_tests) From bf51a76e4ebb728ec56f5d651a4b4e378e49afb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Sat, 7 Apr 2018 00:53:09 +0200 Subject: [PATCH 2/6] [safe_op] Fix ODR violation in compiler builtin specializations The compiler instrinsics are exposed via fully specialized template functions which must not be defined twice (which they accidentally were). Declaring them as inline fixes this issue. --- src/safe_op.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/safe_op.hpp b/src/safe_op.hpp index 760b3267..fefdd6c0 100644 --- a/src/safe_op.hpp +++ b/src/safe_op.hpp @@ -1,6 +1,6 @@ // ********************************************************* -*- C++ -*- /* - * Copyright (C) 2004-2017 Exiv2 maintainers + * Copyright (C) 2004-2018 Exiv2 maintainers * * This program is part of the Exiv2 distribution. * @@ -218,13 +218,13 @@ namespace Safe * The intrinsics are documented here: * https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html#Integer-Overflow-Builtins */ -#define SPECIALIZE_builtin_add_overflow(type, builtin_name) \ - /* Full specialization of builtin_add_overflow for type using the */ \ - /* builtin_name intrinsic */ \ - template <> \ - bool builtin_add_overflow(type summand_1, type summand_2, type & result) \ - { \ - return builtin_name(summand_1, summand_2, &result); \ +#define SPECIALIZE_builtin_add_overflow(type, builtin_name) \ + /* Full specialization of builtin_add_overflow for type using the */ \ + /* builtin_name intrinsic */ \ + template <> \ + inline bool builtin_add_overflow(type summand_1, type summand_2, type & result) \ + { \ + return builtin_name(summand_1, summand_2, &result); \ } SPECIALIZE_builtin_add_overflow(int, __builtin_sadd_overflow); @@ -255,11 +255,11 @@ namespace Safe * The intrinsics are documented here: * https://msdn.microsoft.com/en-us/library/windows/desktop/ff516460(v=vs.85).aspx */ -#define SPECIALIZE_builtin_add_overflow_WIN(type, builtin_name) \ - template <> \ - bool builtin_add_overflow(type summand_1, type summand_2, type& result) \ - { \ - return builtin_name(summand_1, summand_2, &result) != S_OK; \ +#define SPECIALIZE_builtin_add_overflow_WIN(type, builtin_name) \ + template <> \ + inline bool builtin_add_overflow(type summand_1, type summand_2, type& result) \ + { \ + return builtin_name(summand_1, summand_2, &result) != S_OK; \ } SPECIALIZE_builtin_add_overflow_WIN(unsigned int, UIntAdd); From 35bf292d3758d183e47982ed4e1198be0a8c523e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Sun, 6 May 2018 12:07:40 +0200 Subject: [PATCH 3/6] [cmake] Add -Warray-bounds=2 only for gcc > 5.0 --- config/compilerFlags.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/compilerFlags.cmake b/config/compilerFlags.cmake index 3f5517b3..0eaef713 100644 --- a/config/compilerFlags.cmake +++ b/config/compilerFlags.cmake @@ -33,11 +33,16 @@ if ( MINGW OR UNIX ) # MINGW, Linux, APPLE, CYGWIN " -Wuseless-cast" " -Wpointer-arith" # This warning is also enabled by -Wpedantic " -Wformat=2" - " -Warray-bounds=2" #" -Wold-style-cast" ) endif () + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 ) + string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} + " -Warray-bounds=2" + ) + endif () + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 ) string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} " -Wduplicated-cond" From 8c1be86104c07b911d8077b20ac0f413a65b7971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 15 May 2018 00:01:56 +0200 Subject: [PATCH 4/6] [cmake] Add -Wdouble-promotion & -Wcomma only for certain clang versions -Wdouble-promotion is not available in clang 3.4.2 -Wcomma is not available in clang 3.8.1 --- config/compilerFlags.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/config/compilerFlags.cmake b/config/compilerFlags.cmake index 0eaef713..45bc7dfb 100644 --- a/config/compilerFlags.cmake +++ b/config/compilerFlags.cmake @@ -61,11 +61,9 @@ if ( MINGW OR UNIX ) # MINGW, Linux, APPLE, CYGWIN # https://clang.llvm.org/docs/DiagnosticsReference.html # These variables are at least available since clang 3.9.1 string(CONCAT EXTRA_COMPILE_FLAGS "-Wextra" - " -Wdouble-promotion" " -Wshadow" " -Wassign-enum" " -Wmicrosoft" - " -Wcomma" " -Wcomments" " -Wconditional-uninitialized" " -Wdirect-ivar-access" @@ -77,6 +75,18 @@ if ( MINGW OR UNIX ) # MINGW, Linux, APPLE, CYGWIN #" -Wconversion" #" -Wold-style-cast" ) + # -Wdouble-promotion flag is not available in clang 3.4.2 + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4.2 ) + string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} + " -Wdouble-promotion" + ) + endif () + # -Wcomma flag is not available in clang 3.8.1 + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.1 ) + string(CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS} + " -Wcomma" + ) + endif () endif () From b2c243cba34a2f21e80c251ec3e523afc739e53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Wed, 16 May 2018 11:42:11 +0200 Subject: [PATCH 5/6] Add gitlab pipeline status badge to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6f56f5af..9afbd7e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/Exiv2/exiv2.svg?branch=master)](https://travis-ci.org/Exiv2/exiv2) [![Build status](https://ci.appveyor.com/api/projects/status/d6vxf2n0cp3v88al/branch/master?svg=true)](https://ci.appveyor.com/project/piponazo/exiv2-wutfp/branch/master) +[![pipeline status](https://gitlab.com/D4N/exiv2/badges/master/pipeline.svg)](https://gitlab.com/D4N/exiv2/commits/master)


From fe5ca11396a3cadcdd20cfe415f53849c25ccdf3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= 
Date: Wed, 16 May 2018 17:14:13 +0200
Subject: [PATCH 6/6] [travis] Move travis scripts to ci/ folder

---
 .travis.yml                | 4 ++--
 {.travis => ci}/install.sh | 0
 {.travis => ci}/run.sh     | 0
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename {.travis => ci}/install.sh (100%)
 rename {.travis => ci}/run.sh (100%)

diff --git a/.travis.yml b/.travis.yml
index e2c8887d..ff117ca3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,8 +22,8 @@ env:
     #- CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Release -DEXIV2_ENABLE_XMP=OFF -DEXIV2_ENABLE_NLS=OFF -DEXIV2_ENABLE_LENSDATA=OFF" # All disabled
     #- CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=Release -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_ENABLE_CURL=OFF -DEXIV2_ENABLE_SSH=OFF" # WebReady without SSH nor CURL
 
-install: ./.travis/install.sh
-script:  ./.travis/run.sh
+install: ./ci/install.sh
+script:  ./ci/run.sh
 
 cache:
     ccache: true
diff --git a/.travis/install.sh b/ci/install.sh
similarity index 100%
rename from .travis/install.sh
rename to ci/install.sh
diff --git a/.travis/run.sh b/ci/run.sh
similarity index 100%
rename from .travis/run.sh
rename to ci/run.sh