Skip to content

Commit

Permalink
Cleanup includes (#120)
Browse files Browse the repository at this point in the history
* add support for iwyu on nix

* cleanup headers based on iwyu tool

* fix a couple of compiler warnings

* tidy
  • Loading branch information
krupkat committed Feb 10, 2024
1 parent 8f96a54 commit 0048d1d
Show file tree
Hide file tree
Showing 39 changed files with 156 additions and 46 deletions.
53 changes: 53 additions & 0 deletions misc/build/nix/iwyu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ pkgs ? import <nixpkgs> { }
}:
let
# Workaround taken from https://github.com/NixOS/nixpkgs/issues/189753
#
# To use the tool extend your cmake settings:
# "cmake.configureSettings": {
# "CMAKE_CXX_INCLUDE_WHAT_YOU_USE": [
# "include-what-you-use",
# "-Xiwyu",
# "--mapping_file=${workspaceFolder}/misc/mappings/iwyu_nix.imp",
# "-Xiwyu",
# "--no_fwd_decls",
# ]
# },
#
include-what-you-use-wrapped =
let
llvm = pkgs.llvmPackages_15;
in
pkgs.wrapCCWith rec {
cc = pkgs.include-what-you-use.override {
llvmPackages = llvm;
};
extraBuildCommands = ''
wrap include-what-you-use $wrapper $ccPath/include-what-you-use
substituteInPlace "$out/bin/include-what-you-use" --replace 'dontLink=0' 'dontLink=1'
substituteInPlace "$out/bin/include-what-you-use" --replace ' && isCxx=1 || isCxx=0' '&& true; isCxx=1'
rsrc="$out/resource-root"
mkdir "$rsrc"
ln -s "${llvm.clang}/resource-root/include" "$rsrc"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'';
libcxx = llvm.libcxx;
};
in
pkgs.mkShell {
buildInputs = with pkgs; [
cmake
ninja
pkg-config
opencv
SDL2
catch2_3
spdlog
exiv2
dbus
(python3.withPackages (pkgs: with pkgs; [ pyyaml ]))
clang-tools_15
include-what-you-use-wrapped
];
}
29 changes: 29 additions & 0 deletions misc/mappings/iwyu_nix.imp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{ include: ["@<__algorithm/.*>", "private", "<algorithm>", "public"] },
{ include: ["@<__functional/.*>", "private", "<functional>", "public"] },
{ include: ["@<__type_traits/.*>", "private", "<type_traits>", "public"] },
{ include: ["@<__memory/.*>", "private", "<memory>", "public"] },
{ include: ["@<__iterator/.*>", "private", "<iterator>", "public"] },
{ include: ["@<__filesystem/.*>", "private", "<filesystem>", "public"] },
{ include: ["@<__numeric/.*>", "private", "<numeric>", "public"] },
{ include: ["@<__utility/.*>", "private", "<utility>", "public"] },
{ include: ["@<__chrono/.*>", "private", "<chrono>", "public"] },
{ include: ["@<__concepts/.*>", "private", "<concepts>", "public"] },
{ include: ["@<opencv2/core/.*>", "private", "<opencv2/core.hpp>", "public"] },
{ include: ["@<opencv2/stitching/.*>", "private", "<opencv2/stitching.hpp>", "public"] },
{ symbol: [ "std::string", private, "<string>", public ] },
{ symbol: [ "std::abs", private, "<cmath>", public ] },
{ symbol: [ "std::ssize", private, "<vector>", public ] },
{ include: ["@<fmt/.*>", "private", "<spdlog/fmt/fmt.h>", "public"] },
{ include: ["<__errc>", "private", "<system_error>", "public"] },
{ include: ["<__mutex_base>", "private", "<mutex>", "public"] },
{ include: ["@<alpaca/detail/.*>", "private", "<alpaca/alpaca.h>", "public"] },
{ include: ["<exiv2/exif.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
{ include: ["<exiv2/image.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
{ include: ["<exiv2/tags.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
{ include: ["<exiv2/types.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
{ include: ["<exiv2/error.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
{ include: ["<__fwd/string_view.h>", "private", "<string_view>", "public"] },
{ include: ["@<SDL_.*>", "private", "<SDL.h>", "public"] },
{ include: ["<spdlog/common.h>", "private", "<spdlog/spdlog.h>", "public"] },
]
2 changes: 1 addition & 1 deletion misc/scripts/format.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
clang-format-15 -i `find xpano -name *.cc -or -name *.h`
clang-format-15 -i `find tests -name *.cc -or -name *.h`
clang-format-15 -i `find tests -name *.cc -or -name *.h`
1 change: 1 addition & 0 deletions tests/serialize_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <catch2/catch_test_macros.hpp>

#include "tests/utils.h"
#include "xpano/algorithm/options.h"
#include "xpano/pipeline/options.h"

struct Bar {
Expand Down
6 changes: 5 additions & 1 deletion tests/stitcher_pipeline_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

#include "xpano/pipeline/stitcher_pipeline.h"

#include <chrono>
#include <filesystem>
#include <iterator>
#include <string>
#include <utility>
#include <vector>

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
Expand All @@ -20,6 +22,8 @@
#include <opencv2/imgproc.hpp>

#include "tests/utils.h"
#include "xpano/algorithm/options.h"
#include "xpano/constants.h"

using Catch::Matchers::Equals;
using Catch::Matchers::WithinAbs;
Expand Down
3 changes: 0 additions & 3 deletions xpano/algorithm/algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include <opencv2/features2d.hpp>
#include <opencv2/photo.hpp>
#include <opencv2/stitching.hpp>
#include <opencv2/stitching/detail/matchers.hpp>
#include <opencv2/stitching/detail/warpers.hpp>
#include <opencv2/stitching/warpers.hpp>

#include "xpano/algorithm/auto_crop.h"
#include "xpano/algorithm/blenders.h"
Expand Down
3 changes: 0 additions & 3 deletions xpano/algorithm/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <array>
#include <atomic>
#include <optional>
#include <string>
#include <vector>
Expand All @@ -17,7 +15,6 @@
#include "xpano/algorithm/options.h"
#include "xpano/algorithm/progress.h"
#include "xpano/algorithm/stitcher.h"
#include "xpano/constants.h"
#include "xpano/utils/rect.h"
#include "xpano/utils/threadpool.h"

Expand Down
5 changes: 2 additions & 3 deletions xpano/algorithm/blenders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

#include "xpano/algorithm/blenders.h"

#include <array>
#include <cstdint>
#include <cstring>
#include <stdexcept>

#ifdef XPANO_WITH_MULTIBLEND
#include <mb/flex.h>
#include <mb/multiblend.h>
#include <mb/threadpool.h>
#endif
#include <spdlog/fmt/fmt.h>

namespace xpano::algorithm::blenders {

Expand Down
4 changes: 3 additions & 1 deletion xpano/algorithm/blenders.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#ifdef XPANO_WITH_MULTIBLEND
#include <mb/image.h>
#endif
#include <opencv2/stitching/detail/blenders.hpp>

#include <opencv2/core.hpp>
#include <opencv2/stitching.hpp>

#include "xpano/utils/threadpool.h"

Expand Down
7 changes: 6 additions & 1 deletion xpano/algorithm/stitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@
#include "xpano/algorithm/stitcher.h"

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <numeric>
#include <string_view>
#include <utility>

#include <spdlog/spdlog.h>

#include "xpano/utils/opencv.h"

namespace xpano::algorithm::stitcher {

namespace {
Expand Down Expand Up @@ -91,7 +96,7 @@ class Timer {
return kTickFrequency;
}

int64 start_count_;
int64 start_count_ = 0;
};

double ComputeWarpScale(const std::vector<cv::detail::CameraParams> &cameras) {
Expand Down
4 changes: 2 additions & 2 deletions xpano/algorithm/stitcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@

#pragma once

#include <atomic>
#include <vector>

#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/stitching.hpp>

#include "xpano/algorithm/progress.h"
#include "xpano/utils/opencv.h"

namespace xpano::algorithm::stitcher {

Expand Down
2 changes: 2 additions & 0 deletions xpano/cli/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "xpano/cli/args.h"

#include <exception>
#include <filesystem>
#include <string>
#include <vector>

#include <spdlog/fmt/fmt.h>
Expand Down
2 changes: 2 additions & 0 deletions xpano/cli/pano_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "xpano/cli/pano_cli.h"

#include <atomic>
#include <exception>
#include <filesystem>

#include <spdlog/spdlog.h>
Expand All @@ -13,6 +14,7 @@
#include "xpano/cli/signal.h"
#include "xpano/constants.h"
#include "xpano/log/logger.h"
#include "xpano/pipeline/options.h"
#include "xpano/pipeline/stitcher_pipeline.h"
#include "xpano/utils/future.h"
#include "xpano/version_fmt.h"
Expand Down
4 changes: 2 additions & 2 deletions xpano/cli/signal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "xpano/cli/signal.h"

#include <spdlog/spdlog.h>

#ifdef _WIN32
#include <windows.h>

#include <spdlog/spdlog.h>
#else
#include <signal.h> // NOLINT(modernize-deprecated-headers)
#endif
Expand Down
3 changes: 3 additions & 0 deletions xpano/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ constexpr int kExifDefaultOrientation = 1;

constexpr int kCancelAnimationFrameDuration = 128;

const std::string kGithubIssuesLink = "https://github.com/krupkat/xpano/issues";
const std::string kAuthorEmail = "tomas@krupkat.cz";

} // namespace xpano
2 changes: 1 addition & 1 deletion xpano/gui/file_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <filesystem>
#include <iterator>
#include <string>
#include <utility>
#include <vector>

#include <nfd.h>
#include <nfd.hpp>
#include <spdlog/fmt/fmt.h>
#include <spdlog/spdlog.h>
Expand Down
1 change: 0 additions & 1 deletion xpano/gui/file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include <filesystem>
#include <optional>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions xpano/gui/panels/about.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <future>
#include <optional>
#include <string>

#include "xpano/utils/text.h"

Expand Down
9 changes: 0 additions & 9 deletions xpano/gui/panels/bugreport_pane.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@

namespace xpano::gui {

namespace {

const std::string kGithubIssuesLink =
R"(https://github.com/krupkat/xpano/issues)";

const std::string kAuthorEmail = R"(tomas@krupkat.cz)";

} // namespace

BugReportPane::BugReportPane(logger::Logger *logger) : logger_(logger) {}

void BugReportPane::Show() { show_ = true; }
Expand Down
2 changes: 0 additions & 2 deletions xpano/gui/panels/preview_pane.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
#include <imgui.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/stitching/detail/camera.hpp>
#include <spdlog/spdlog.h>

#include "xpano/constants.h"
#include "xpano/gui/action.h"
#include "xpano/gui/backends/base.h"
#include "xpano/gui/widgets/widgets.h"
#include "xpano/utils/opencv.h"
#include "xpano/utils/rect.h"
#include "xpano/utils/vec.h"
#include "xpano/utils/vec_converters.h"
Expand Down
1 change: 1 addition & 0 deletions xpano/gui/panels/sidebar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "xpano/algorithm/algorithm.h"
#include "xpano/algorithm/blenders.h"
#include "xpano/algorithm/image.h"
#include "xpano/algorithm/progress.h"
#include "xpano/constants.h"
#include "xpano/gui/action.h"
#include "xpano/gui/panels/preview_pane.h"
Expand Down
1 change: 1 addition & 0 deletions xpano/gui/panels/sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "xpano/algorithm/algorithm.h"
#include "xpano/algorithm/image.h"
#include "xpano/algorithm/options.h"
#include "xpano/gui/action.h"
#include "xpano/gui/panels/preview_pane.h"
#include "xpano/gui/panels/thumbnail_pane.h"
Expand Down
2 changes: 2 additions & 0 deletions xpano/gui/panels/warning_pane.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "xpano/gui/panels/warning_pane.h"

#include <utility>

#include <imgui.h>
#include <spdlog/fmt/fmt.h>
#include <spdlog/spdlog.h>
Expand Down
7 changes: 5 additions & 2 deletions xpano/gui/pano_gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "xpano/gui/pano_gui.h"

#include <algorithm>
#include <exception>
#include <filesystem>
#include <future>
#include <optional>
#include <string>
Expand All @@ -19,6 +21,7 @@

#include "xpano/algorithm/algorithm.h"
#include "xpano/algorithm/image.h"
#include "xpano/algorithm/options.h"
#include "xpano/cli/args.h"
#include "xpano/constants.h"
#include "xpano/gui/action.h"
Expand Down Expand Up @@ -198,7 +201,7 @@ auto ResolveStitchingResultFuture(
spdlog::info(*status_message);
}

return std::move(result);
return result;
}

auto ResolveExportFuture(std::future<pipeline::ExportResult> export_future,
Expand Down Expand Up @@ -625,7 +628,7 @@ MultiAction PanoGui::ResolveFutures() {
};

auto handle_pano =
[this, &actions](std::future<pipeline::StitchingResult> pano_future) {
[this](std::future<pipeline::StitchingResult> pano_future) {
auto result = ResolveStitchingResultFuture(
std::move(pano_future), &plot_pane_, &status_message_);
auto& pano = stitcher_data_->panos[result.pano_id];
Expand Down
Loading

0 comments on commit 0048d1d

Please sign in to comment.