Skip to content

Commit

Permalink
Static analysers in CI (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored May 11, 2023
1 parent 1d963be commit ebbeb81
Showing 53 changed files with 277 additions and 184 deletions.
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Checks: '-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-modernize-use-nodiscard,-modernize-avoid-c-arrays,-modernize-use-auto'
WarningsAsErrors: '*'
UseColor: true
FormatStyle: none
16 changes: 16 additions & 0 deletions .cppcheck.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// remove some checks
missingInclude
unusedFunction

// external libraries
*:external/json.hpp
*:external/cxxopts.hpp

// opencascade
*:*opencascade/*.hxx

// specific checks
preprocessorErrorDirective:plugins/draco/module/vtkF3DDracoReader.cxx
preprocessorErrorDirective:library/src/engine.cxx
unknownMacro:library/VTKExtensions/Applicative/vtkF3DObjectFactory.cxx
knownConditionTrueFalse:library/testing/TestSDKImage.cxx
92 changes: 91 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -466,7 +466,7 @@ jobs:
- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --parallel 2 --config Release
run: cmake --build . --parallel 2

- name: Run Xvfb
run: Xvfb $DISPLAY -screen 0 1280x1024x24 &
@@ -484,3 +484,93 @@ jobs:
with:
path: ./build/Testing/Temporary
name: f3d-tests-artifact-sanitizer-${{matrix.santype}}

#----------------------------------------------------------------------------
# static-analysis: Run static analysis on linux
#----------------------------------------------------------------------------
static-analysis:
if: github.event.pull_request.draft == false

strategy:
fail-fast: false

runs-on: ubuntu-latest
container: ghcr.io/f3d-app/f3d-ci

env:
CC: clang
CXX: clang++

steps:

- name: Checkout
uses: actions/checkout@v3
with:
path: 'source'
fetch-depth: 0
lfs: false

- name: Set LFS env var
working-directory: ${{github.workspace}}/source
shell: bash
run: echo "LFS_SHA=$(git log -n 1 --pretty=format:%H -- testing/data/ testing/baselines/)" >> $GITHUB_ENV

- name: Copy LFS Data
uses: ./source/.github/actions/lfs-copy
with:
lfs_sha: ${{env.LFS_SHA}}

- name: Dependencies Dir
working-directory: ${{github.workspace}}
run: |
mkdir dependencies
cd dependencies
mkdir install
- name: Install VTK dependency
uses: ./source/.github/actions/vtk-install-dep
with:
vtk_sha_file: ./source/.github/actions/vtk_commit_sha

- name: Install F3D dependencies
uses: ./source/.github/actions/f3d-dependencies

- name: Setup Build Directory
working-directory: ${{github.workspace}}
run: mkdir build

- name: Configure
working-directory: ${{github.workspace}}/build
run: >
cmake ../source
-Werror=dev
-Werror=deprecated
--warn-uninitialized
-DBUILD_TESTING=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_PREFIX_PATH:PATH=$(pwd)/../dependencies/install/
-DF3D_MODULE_EXTERNAL_RENDERING=ON
-DF3D_PLUGIN_BUILD_ALEMBIC=ON
-DF3D_PLUGIN_BUILD_ASSIMP=ON
-DF3D_PLUGIN_BUILD_DRACO=ON
-DF3D_PLUGIN_BUILD_OCCT=ON
-DF3D_STRICT_BUILD=ON
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# It's necessary to run the build step to generate F3DIcon.h
- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --parallel 2

- name: Clang-tidy
working-directory: ${{github.workspace}}/source
run: run-clang-tidy -quiet -p ../build

- name: Cppcheck
working-directory: ${{github.workspace}}/source
run: >
cppcheck -q
--project=../build/compile_commands.json
--enable=all
--suppressions-list=.cppcheck.supp
--error-exitcode=1
4 changes: 2 additions & 2 deletions .github/workflows/style-checks.yml
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DoozyX/clang-format-lint-action@v0.13
- uses: DoozyX/clang-format-lint-action@v0.16.1
with:
source: 'library application python'
extensions: 'h,cxx'
clangFormatVersion: 13
clangFormatVersion: 14 # Last Ubuntu LTS version (22.04)

codespell-check:
name: Codespell Check
12 changes: 6 additions & 6 deletions application/F3DConfigFileTools.cxx
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ fs::path F3DConfigFileTools::GetUserConfigFileDirectory()
const char* appData = std::getenv("APPDATA");
if (!appData)
{
return fs::path();
return {};
}
dirPath = fs::path(appData);
#else
@@ -35,7 +35,7 @@ fs::path F3DConfigFileTools::GetUserConfigFileDirectory()
const char* home = std::getenv("HOME");
if (!home || strlen(home) == 0)
{
return fs::path();
return {};
}
dirPath = fs::path(home);
dirPath /= ".config";
@@ -67,7 +67,7 @@ fs::path F3DConfigFileTools::GetBinaryConfigFileDirectory()
catch (const fs::filesystem_error&)
{
f3d::log::debug("Cannot recover binary configuration file directory: ", dirPath.string());
return fs::path();
return {};
}

return dirPath;
@@ -77,9 +77,9 @@ fs::path F3DConfigFileTools::GetBinaryConfigFileDirectory()
fs::path F3DConfigFileTools::GetConfigPath(const std::string& configSearch)
{
fs::path configPath;
std::vector<fs::path> dirsToCheck;
try
{
std::vector<fs::path> dirsToCheck;
dirsToCheck.emplace_back(F3DConfigFileTools::GetUserConfigFileDirectory());
#ifdef __APPLE__
dirsToCheck.emplace_back("/usr/local/etc/f3d");
@@ -120,11 +120,11 @@ fs::path F3DConfigFileTools::GetConfigPath(const std::string& configSearch)
}
}
f3d::log::debug("No configuration file for \"", configSearch, "\" found");
return fs::path();
return {};
}
catch (const fs::filesystem_error&)
{
f3d::log::error("Error recovering configuration file path: ", configPath.string());
return fs::path();
return {};
}
}
2 changes: 1 addition & 1 deletion application/F3DException.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
class F3DExNoProcess : public std::runtime_error
{
public:
F3DExNoProcess(const std::string& what = "")
explicit F3DExNoProcess(const std::string& what = "")
: std::runtime_error(what)
{
}
8 changes: 4 additions & 4 deletions application/F3DOptionsParser.cxx
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ class ConfigurationOptions

void PrintHelpPair(
const std::string& key, const std::string& help, int keyWidth = 10, int helpWidth = 70);
void PrintHelp(cxxopts::Options& cxxOptions);
void PrintHelp(const cxxopts::Options& cxxOptions);
void PrintVersion();
void PrintReadersList();
void PrintPluginsScan();
@@ -254,7 +254,7 @@ void ConfigurationOptions::GetOptions(F3DAppOptions& appOptions, f3d::options& o
std::vector<std::string>& inputs, std::string filePathForConfigBlock, bool allOptionsInitialized,
bool parseCommandLine)
{
this->FilePathForConfigBlock = filePathForConfigBlock;
this->FilePathForConfigBlock = std::move(filePathForConfigBlock);

// When parsing multiple times, hasDefault should be forced to yes after the first pass as all
// options are expected to be already initialized, which means they have a "default" in the
@@ -420,7 +420,7 @@ void ConfigurationOptions::PrintHelpPair(
}

//----------------------------------------------------------------------------
void ConfigurationOptions::PrintHelp(cxxopts::Options& cxxOptions)
void ConfigurationOptions::PrintHelp(const cxxopts::Options& cxxOptions)
{
const std::vector<std::pair<std::string, std::string> > examples = {
{ this->ExecutableName + " file.vtu -xtgans",
@@ -684,7 +684,7 @@ F3DOptionsParser::~F3DOptionsParser() = default;
//----------------------------------------------------------------------------
void F3DOptionsParser::Initialize(int argc, char** argv)
{
this->ConfigOptions = std::unique_ptr<ConfigurationOptions>(new ConfigurationOptions(argc, argv));
this->ConfigOptions = std::make_unique<ConfigurationOptions>(argc, argv);
}

//----------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion application/F3DOptionsParser.h
Original file line number Diff line number Diff line change
@@ -88,10 +88,10 @@ class F3DOptionsParser
F3DOptionsParser();
~F3DOptionsParser();

private:
F3DOptionsParser(F3DOptionsParser const&) = delete;
void operator=(F3DOptionsParser const&) = delete;

private:
std::unique_ptr<ConfigurationOptions> ConfigOptions;
};

10 changes: 5 additions & 5 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ int F3DStarter::Start(int argc, char** argv)
f3d::interactor& interactor = this->Internals->Engine->getInteractor();

interactor.setKeyPressCallBack(
[this](int, std::string keySym) -> bool
[this](int, const std::string& keySym) -> bool
{
if (keySym == "Left")
{
@@ -177,11 +177,11 @@ int F3DStarter::Start(int argc, char** argv)
});

interactor.setDropFilesCallBack(
[this](std::vector<std::string> filesVec) -> bool
[this](const std::vector<std::string>& filesVec) -> bool
{
this->Internals->Engine->getInteractor().stopAnimation();
int index = -1;
for (std::string file : filesVec)
for (const std::string& file : filesVec)
{
index = this->AddFile(fs::path(file));
}
@@ -341,7 +341,7 @@ void F3DStarter::LoadFile(int index, bool relativeIndex)
// Detect changed options and apply the change to the dynamic options
// options names are shared between options instance
std::vector<std::string> optionNames = this->Internals->DynamicOptions.getNames();
for (auto name : optionNames)
for (const auto& name : optionNames)
{
if (!previousOptions.isSame(this->Internals->FileOptions, name))
{
@@ -517,7 +517,7 @@ int F3DStarter::AddFile(const fs::path& path, bool quiet)
{
sortedPaths.insert(entry.path());
}
for (auto& entryPath : sortedPaths)
for (const auto& entryPath : sortedPaths)
{
// Recursively add all files
this->AddFile(entryPath, quiet);
6 changes: 3 additions & 3 deletions application/F3DStarter.h
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@ class F3DStarter
F3DStarter();
~F3DStarter();

F3DStarter(F3DStarter const&) = delete;
void operator=(F3DStarter const&) = delete;

private:
class F3DInternals;
std::unique_ptr<F3DInternals> Internals;

F3DStarter(F3DStarter const&) = delete;
void operator=(F3DStarter const&) = delete;
};

#endif
6 changes: 3 additions & 3 deletions application/F3DSystemTools.cxx
Original file line number Diff line number Diff line change
@@ -28,15 +28,15 @@ fs::path GetApplicationPath()
return fs::path(wc.data());
}
f3d::log::error("Cannot retrieve application path");
return fs::path();
return {};
#else
#ifdef __APPLE__
uint32_t size = 1024;
std::array<char, 1024> buffer;
if (_NSGetExecutablePath(buffer.data(), &size) != 0)
{
f3d::log::error("Executable is too long to recover application path");
return fs::path();
return {};
}
return fs::path(buffer.data());
#else
@@ -47,7 +47,7 @@ fs::path GetApplicationPath()
catch (const std::exception& ex)
{
f3d::log::error("Cannot retrieve application path: ", ex.what());
return fs::path();
return {};
}
#endif
#endif
2 changes: 1 addition & 1 deletion examples/libf3d/render-interact/main.cxx
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ int main(int argc, char** argv)
f3d::engine eng(f3d::window::Type::NATIVE);

// Load a model
f3d::loader& load = eng.getLoader().loadGeometry(std::string(argv[1]));
const f3d::loader& load = eng.getLoader().loadGeometry(std::string(argv[1]));

// Render
f3d::window& win = eng.getWindow();
7 changes: 3 additions & 4 deletions library/VTKExtensions/Applicative/vtkF3DObjectFactory.h
Original file line number Diff line number Diff line change
@@ -18,13 +18,12 @@ class vtkF3DObjectFactory : public vtkObjectFactory

const char* GetVTKSourceVersion() override;

vtkF3DObjectFactory(const vtkF3DObjectFactory&) = delete;
void operator=(const vtkF3DObjectFactory&) = delete;

protected:
vtkF3DObjectFactory();
~vtkF3DObjectFactory() override = default;

private:
vtkF3DObjectFactory(const vtkF3DObjectFactory&) = delete;
void operator=(const vtkF3DObjectFactory&) = delete;
};

#endif // vtkF3DObjectFactory_h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

vtkStandardNewMacro(vtkF3DAndroidLogOutputWindow);

vtkF3DAndroidLogOutputWindow::vtkF3DAndroidLogOutputWindow() {}
vtkF3DAndroidLogOutputWindow::vtkF3DAndroidLogOutputWindow() = default;

void vtkF3DAndroidLogOutputWindow::DisplayText(const char* txt)
{
6 changes: 4 additions & 2 deletions library/VTKExtensions/Core/vtkF3DConsoleOutputWindow.cxx
Original file line number Diff line number Diff line change
@@ -6,16 +6,18 @@
vtkStandardNewMacro(vtkF3DConsoleOutputWindow);

//----------------------------------------------------------------------------
#ifdef WIN32
vtkF3DConsoleOutputWindow::vtkF3DConsoleOutputWindow()
{
#ifdef WIN32
// enable formatting on windows terminal
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode;
GetConsoleMode(hOut, &dwMode);
SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
#endif
}
#else
vtkF3DConsoleOutputWindow::vtkF3DConsoleOutputWindow() = default;
#endif

//----------------------------------------------------------------------------
void vtkF3DConsoleOutputWindow::DisplayText(const char* txt)
Loading

0 comments on commit ebbeb81

Please sign in to comment.