Adding iwyu for Linux and fixing includes (#34)

This commit is contained in:
Matt Durak 2021-01-22 10:44:29 -08:00 коммит произвёл GitHub
Родитель 2bc238fbc2
Коммит 78273d89f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 68 добавлений и 18 удалений

Просмотреть файл

@ -319,3 +319,28 @@ jobs:
arguments: '-i $(Build.SourcesDirectory) -buildcheck -e deps'
modifyEnvironment: false
workingFolder: '$(Build.SourcesDirectory)'
- job: includecheck_linux
pool:
name: Azure-MessagingStore
demands:
- linux
steps:
- bash: |
pushd $(Build.Repository.LocalPath)
git submodule update --init
git submodule foreach --recursive "git clean -xdff"
git clean -xdff
popd
workingDirectory: '$(Build.Repository.LocalPath)'
displayName: 'git submodule update and clean'
- task: Bash@3
displayName: 'Build with iwyu'
inputs:
targetType: filePath
filePath: './build/linux/build_linux_iwyu.sh'
arguments: '$(Build.Repository.LocalPath)'
workingDirectory: '$(Build.Repository.LocalPath)'

Просмотреть файл

@ -0,0 +1,26 @@
#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
set -e
build_root=$(cd "$1" && pwd)
cd $build_root
build_folder=$build_root"/cmake_linux_iwyu"
# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
CC="clang" CXX="clang++" cmake $build_root -GNinja -DCMAKE_C_INCLUDE_WHAT_YOU_USE:UNINITIALIZED="include-what-you-use;-Xiwyu;--mapping_file=$build_root/deps/c-build-tools/iwyu/rules.imp;" -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE:UNINITIALIZED="include-what-you-use;-Xiwyu;--mapping_file=$build_root/deps/c-build-tools/iwyu/rules.imp;" -Drun_unittests:bool=ON -Drun_int_tests:bool=ON
cmake --build . > >(tee -a $build_folder"/build.log") 2> >(tee -a $build_folder"/builderror.log" >&2)
if grep 'Warning:' $build_folder"/builderror.log"; then
echo "Failing build due to iwyu warnings"
exit -1
fi
popd

2
deps/c-build-tools поставляемый

@ -1 +1 @@
Subproject commit afd434134683f38ec78fa9ac4ab57de5fd5b6b05
Subproject commit 7f2c839bb3830d68ddb71817b5a0fff759cbb760

2
deps/macro-utils-c поставляемый

@ -1 +1 @@
Subproject commit 88db3e57170663ea25a18ddd872194c625e6ab79
Subproject commit 7517b68d22a57f88d96947753c0739781bb4c341

Просмотреть файл

@ -5,11 +5,19 @@
#define XLOGGING_H
#ifdef __cplusplus
#include <cstdlib>
#include <cstdio>
#else
#include <stdlib.h>
#include <stdio.h>
#endif
#if defined _MSC_VER && defined LOGERROR_CAPTURES_STACK_TRACES
#ifdef __cplusplus
#include <cstring>
#else
#include <string.h> // for memcpy, strlen
#endif
#endif // defined _MSC_VER && defined LOGERROR_CAPTURES_STACK_TRACES
#include "macro_utils/macro_utils.h"
#ifdef LOGERROR_CAPTURES_STACK_TRACES
@ -18,12 +26,6 @@
#define LOG_SIZE_REGULAR 4096 /*in bytes - a message is not expected to exceed this size in bytes, if it does, only LOG_SIZE_REGULAR characters are retained*/
#ifdef __cplusplus
#include <cstdio>
#else
#include <stdio.h>
#endif /* __cplusplus */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@ -68,7 +70,7 @@ typedef void(*LOGGER_LOG_GETLASTERROR)(const char* file, const char* func, int l
// specifications, we call printf with the format and __VA_ARGS__. Since C && operator is shortcircuiting no actual runtime call to printf is performed.
#if defined _MSC_VER
#ifndef LOGERROR_CAPTURES_STACK_TRACES
// ignore warning C4127
// ignore warning C4127
#define LOG(log_category, log_options, format, ...) \
{ \
(void)(0 && printf(format, ##__VA_ARGS__)); \
@ -80,7 +82,7 @@ typedef void(*LOGGER_LOG_GETLASTERROR)(const char* file, const char* func, int l
} \
} \
}
#else /*LOGERROR_CAPTURES_STACK_TRACES is defined*/
#else /*LOGERROR_CAPTURES_STACK_TRACES is defined*/
#define LOG(log_category, log_options, format, ...) MU_C2(LOG_,log_category)(log_category, log_options, format, ##__VA_ARGS__)

Просмотреть файл

@ -4,12 +4,12 @@
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "c_logging/xlogging.h"
#include "c_logging/consolelogger.h"
#if (defined(_MSC_VER))
#include <string.h>
#include "windows.h"
/*this function will use 1x puts (in the happy case) .*/
@ -20,7 +20,7 @@ void consolelogger_log_with_GetLastError(const char* file, const char* func, int
DWORD lastError;
char message[LOG_SIZE_REGULAR];
int size = 0; /*size tracks number of character from "message" that are used so far, not counting the last null character. Uses int as data type because snprintf functions return int*/
int snprintf_result;
@ -78,7 +78,7 @@ void consolelogger_log_with_GetLastError(const char* file, const char* func, int
}
{/*scope for 3) whatever GetLastError can provide*/
/*add the getlastError for good measure anyway*/
snprintf_result = snprintf(message + size, sizeof(message) - size, " GetLastError()=%#lx ", lastError);
if (snprintf_result < 0)

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

Просмотреть файл

@ -3,8 +3,6 @@
#ifndef NO_LOGGING
#include <string.h>
#include "c_logging/xlogging.h"
#include "c_logging/consolelogger.h"