Skip to content

Commit 0048d1d

Browse files
authored
Cleanup includes (#120)
* add support for iwyu on nix * cleanup headers based on iwyu tool * fix a couple of compiler warnings * tidy
1 parent 8f96a54 commit 0048d1d

39 files changed

+156
-46
lines changed

misc/build/nix/iwyu.nix

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{ pkgs ? import <nixpkgs> { }
2+
}:
3+
let
4+
# Workaround taken from https://github.com/NixOS/nixpkgs/issues/189753
5+
#
6+
# To use the tool extend your cmake settings:
7+
# "cmake.configureSettings": {
8+
# "CMAKE_CXX_INCLUDE_WHAT_YOU_USE": [
9+
# "include-what-you-use",
10+
# "-Xiwyu",
11+
# "--mapping_file=${workspaceFolder}/misc/mappings/iwyu_nix.imp",
12+
# "-Xiwyu",
13+
# "--no_fwd_decls",
14+
# ]
15+
# },
16+
#
17+
include-what-you-use-wrapped =
18+
let
19+
llvm = pkgs.llvmPackages_15;
20+
in
21+
pkgs.wrapCCWith rec {
22+
cc = pkgs.include-what-you-use.override {
23+
llvmPackages = llvm;
24+
};
25+
extraBuildCommands = ''
26+
wrap include-what-you-use $wrapper $ccPath/include-what-you-use
27+
substituteInPlace "$out/bin/include-what-you-use" --replace 'dontLink=0' 'dontLink=1'
28+
substituteInPlace "$out/bin/include-what-you-use" --replace ' && isCxx=1 || isCxx=0' '&& true; isCxx=1'
29+
30+
rsrc="$out/resource-root"
31+
mkdir "$rsrc"
32+
ln -s "${llvm.clang}/resource-root/include" "$rsrc"
33+
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
34+
'';
35+
libcxx = llvm.libcxx;
36+
};
37+
in
38+
pkgs.mkShell {
39+
buildInputs = with pkgs; [
40+
cmake
41+
ninja
42+
pkg-config
43+
opencv
44+
SDL2
45+
catch2_3
46+
spdlog
47+
exiv2
48+
dbus
49+
(python3.withPackages (pkgs: with pkgs; [ pyyaml ]))
50+
clang-tools_15
51+
include-what-you-use-wrapped
52+
];
53+
}

misc/mappings/iwyu_nix.imp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[
2+
{ include: ["@<__algorithm/.*>", "private", "<algorithm>", "public"] },
3+
{ include: ["@<__functional/.*>", "private", "<functional>", "public"] },
4+
{ include: ["@<__type_traits/.*>", "private", "<type_traits>", "public"] },
5+
{ include: ["@<__memory/.*>", "private", "<memory>", "public"] },
6+
{ include: ["@<__iterator/.*>", "private", "<iterator>", "public"] },
7+
{ include: ["@<__filesystem/.*>", "private", "<filesystem>", "public"] },
8+
{ include: ["@<__numeric/.*>", "private", "<numeric>", "public"] },
9+
{ include: ["@<__utility/.*>", "private", "<utility>", "public"] },
10+
{ include: ["@<__chrono/.*>", "private", "<chrono>", "public"] },
11+
{ include: ["@<__concepts/.*>", "private", "<concepts>", "public"] },
12+
{ include: ["@<opencv2/core/.*>", "private", "<opencv2/core.hpp>", "public"] },
13+
{ include: ["@<opencv2/stitching/.*>", "private", "<opencv2/stitching.hpp>", "public"] },
14+
{ symbol: [ "std::string", private, "<string>", public ] },
15+
{ symbol: [ "std::abs", private, "<cmath>", public ] },
16+
{ symbol: [ "std::ssize", private, "<vector>", public ] },
17+
{ include: ["@<fmt/.*>", "private", "<spdlog/fmt/fmt.h>", "public"] },
18+
{ include: ["<__errc>", "private", "<system_error>", "public"] },
19+
{ include: ["<__mutex_base>", "private", "<mutex>", "public"] },
20+
{ include: ["@<alpaca/detail/.*>", "private", "<alpaca/alpaca.h>", "public"] },
21+
{ include: ["<exiv2/exif.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
22+
{ include: ["<exiv2/image.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
23+
{ include: ["<exiv2/tags.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
24+
{ include: ["<exiv2/types.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
25+
{ include: ["<exiv2/error.hpp>", "private", "<exiv2/exiv2.hpp>", "public"] },
26+
{ include: ["<__fwd/string_view.h>", "private", "<string_view>", "public"] },
27+
{ include: ["@<SDL_.*>", "private", "<SDL.h>", "public"] },
28+
{ include: ["<spdlog/common.h>", "private", "<spdlog/spdlog.h>", "public"] },
29+
]

misc/scripts/format.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
clang-format-15 -i `find xpano -name *.cc -or -name *.h`
2-
clang-format-15 -i `find tests -name *.cc -or -name *.h`
2+
clang-format-15 -i `find tests -name *.cc -or -name *.h`

tests/serialize_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <catch2/catch_test_macros.hpp>
99

1010
#include "tests/utils.h"
11+
#include "xpano/algorithm/options.h"
1112
#include "xpano/pipeline/options.h"
1213

1314
struct Bar {

tests/stitcher_pipeline_test.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include "xpano/pipeline/stitcher_pipeline.h"
55

6+
#include <chrono>
67
#include <filesystem>
8+
#include <iterator>
79
#include <string>
10+
#include <utility>
811
#include <vector>
912

1013
#include <catch2/catch_test_macros.hpp>
11-
#include <catch2/generators/catch_generators.hpp>
1214
#include <catch2/matchers/catch_matchers_floating_point.hpp>
1315
#include <catch2/matchers/catch_matchers_string.hpp>
1416
#include <catch2/matchers/catch_matchers_vector.hpp>
@@ -20,6 +22,8 @@
2022
#include <opencv2/imgproc.hpp>
2123

2224
#include "tests/utils.h"
25+
#include "xpano/algorithm/options.h"
26+
#include "xpano/constants.h"
2327

2428
using Catch::Matchers::Equals;
2529
using Catch::Matchers::WithinAbs;

xpano/algorithm/algorithm.cc

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include <opencv2/features2d.hpp>
2121
#include <opencv2/photo.hpp>
2222
#include <opencv2/stitching.hpp>
23-
#include <opencv2/stitching/detail/matchers.hpp>
24-
#include <opencv2/stitching/detail/warpers.hpp>
25-
#include <opencv2/stitching/warpers.hpp>
2623

2724
#include "xpano/algorithm/auto_crop.h"
2825
#include "xpano/algorithm/blenders.h"

xpano/algorithm/algorithm.h

-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#pragma once
66

7-
#include <array>
8-
#include <atomic>
97
#include <optional>
108
#include <string>
119
#include <vector>
@@ -17,7 +15,6 @@
1715
#include "xpano/algorithm/options.h"
1816
#include "xpano/algorithm/progress.h"
1917
#include "xpano/algorithm/stitcher.h"
20-
#include "xpano/constants.h"
2118
#include "xpano/utils/rect.h"
2219
#include "xpano/utils/threadpool.h"
2320

xpano/algorithm/blenders.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
#include "xpano/algorithm/blenders.h"
55

6+
#include <array>
7+
#include <cstdint>
68
#include <cstring>
79
#include <stdexcept>
810

911
#ifdef XPANO_WITH_MULTIBLEND
10-
#include <mb/flex.h>
1112
#include <mb/multiblend.h>
12-
#include <mb/threadpool.h>
1313
#endif
14-
#include <spdlog/fmt/fmt.h>
1514

1615
namespace xpano::algorithm::blenders {
1716

xpano/algorithm/blenders.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#ifdef XPANO_WITH_MULTIBLEND
77
#include <mb/image.h>
88
#endif
9-
#include <opencv2/stitching/detail/blenders.hpp>
9+
10+
#include <opencv2/core.hpp>
11+
#include <opencv2/stitching.hpp>
1012

1113
#include "xpano/utils/threadpool.h"
1214

xpano/algorithm/stitcher.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@
4949
#include "xpano/algorithm/stitcher.h"
5050

5151
#include <algorithm>
52+
#include <cmath>
53+
#include <cstddef>
5254
#include <numeric>
5355
#include <string_view>
56+
#include <utility>
5457

5558
#include <spdlog/spdlog.h>
5659

60+
#include "xpano/utils/opencv.h"
61+
5762
namespace xpano::algorithm::stitcher {
5863

5964
namespace {
@@ -91,7 +96,7 @@ class Timer {
9196
return kTickFrequency;
9297
}
9398

94-
int64 start_count_;
99+
int64 start_count_ = 0;
95100
};
96101

97102
double ComputeWarpScale(const std::vector<cv::detail::CameraParams> &cameras) {

xpano/algorithm/stitcher.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848

4949
#pragma once
5050

51-
#include <atomic>
51+
#include <vector>
5252

5353
#include <opencv2/core.hpp>
5454
#include <opencv2/features2d.hpp>
55+
#include <opencv2/imgproc.hpp>
5556
#include <opencv2/stitching.hpp>
5657

5758
#include "xpano/algorithm/progress.h"
58-
#include "xpano/utils/opencv.h"
5959

6060
namespace xpano::algorithm::stitcher {
6161

xpano/cli/args.cc

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include "xpano/cli/args.h"
55

6+
#include <exception>
67
#include <filesystem>
8+
#include <string>
79
#include <vector>
810

911
#include <spdlog/fmt/fmt.h>

xpano/cli/pano_cli.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "xpano/cli/pano_cli.h"
55

66
#include <atomic>
7+
#include <exception>
78
#include <filesystem>
89

910
#include <spdlog/spdlog.h>
@@ -13,6 +14,7 @@
1314
#include "xpano/cli/signal.h"
1415
#include "xpano/constants.h"
1516
#include "xpano/log/logger.h"
17+
#include "xpano/pipeline/options.h"
1618
#include "xpano/pipeline/stitcher_pipeline.h"
1719
#include "xpano/utils/future.h"
1820
#include "xpano/version_fmt.h"

xpano/cli/signal.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#include "xpano/cli/signal.h"
55

6-
#include <spdlog/spdlog.h>
7-
86
#ifdef _WIN32
97
#include <windows.h>
8+
9+
#include <spdlog/spdlog.h>
1010
#else
1111
#include <signal.h> // NOLINT(modernize-deprecated-headers)
1212
#endif

xpano/constants.h

+3
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,7 @@ constexpr int kExifDefaultOrientation = 1;
100100

101101
constexpr int kCancelAnimationFrameDuration = 128;
102102

103+
const std::string kGithubIssuesLink = "https://github.com/krupkat/xpano/issues";
104+
const std::string kAuthorEmail = "[email protected]";
105+
103106
} // namespace xpano

xpano/gui/file_dialog.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <filesystem>
1010
#include <iterator>
1111
#include <string>
12+
#include <utility>
1213
#include <vector>
1314

14-
#include <nfd.h>
1515
#include <nfd.hpp>
1616
#include <spdlog/fmt/fmt.h>
1717
#include <spdlog/spdlog.h>

xpano/gui/file_dialog.h

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#pragma once
55

66
#include <filesystem>
7-
#include <optional>
87
#include <string>
98
#include <vector>
109

xpano/gui/panels/about.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <future>
88
#include <optional>
9+
#include <string>
910

1011
#include "xpano/utils/text.h"
1112

xpano/gui/panels/bugreport_pane.cc

-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212

1313
namespace xpano::gui {
1414

15-
namespace {
16-
17-
const std::string kGithubIssuesLink =
18-
R"(https://github.com/krupkat/xpano/issues)";
19-
20-
const std::string kAuthorEmail = R"([email protected])";
21-
22-
} // namespace
23-
2415
BugReportPane::BugReportPane(logger::Logger *logger) : logger_(logger) {}
2516

2617
void BugReportPane::Show() { show_ = true; }

xpano/gui/panels/preview_pane.cc

-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
#include <imgui.h>
1313
#include <opencv2/core.hpp>
1414
#include <opencv2/imgproc.hpp>
15-
#include <opencv2/stitching/detail/camera.hpp>
1615
#include <spdlog/spdlog.h>
1716

1817
#include "xpano/constants.h"
1918
#include "xpano/gui/action.h"
2019
#include "xpano/gui/backends/base.h"
2120
#include "xpano/gui/widgets/widgets.h"
22-
#include "xpano/utils/opencv.h"
2321
#include "xpano/utils/rect.h"
2422
#include "xpano/utils/vec.h"
2523
#include "xpano/utils/vec_converters.h"

xpano/gui/panels/sidebar.cc

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "xpano/algorithm/algorithm.h"
1717
#include "xpano/algorithm/blenders.h"
1818
#include "xpano/algorithm/image.h"
19+
#include "xpano/algorithm/progress.h"
1920
#include "xpano/constants.h"
2021
#include "xpano/gui/action.h"
2122
#include "xpano/gui/panels/preview_pane.h"

xpano/gui/panels/sidebar.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "xpano/algorithm/algorithm.h"
1111
#include "xpano/algorithm/image.h"
12+
#include "xpano/algorithm/options.h"
1213
#include "xpano/gui/action.h"
1314
#include "xpano/gui/panels/preview_pane.h"
1415
#include "xpano/gui/panels/thumbnail_pane.h"

xpano/gui/panels/warning_pane.cc

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

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

6+
#include <utility>
7+
68
#include <imgui.h>
79
#include <spdlog/fmt/fmt.h>
810
#include <spdlog/spdlog.h>

xpano/gui/pano_gui.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "xpano/gui/pano_gui.h"
77

88
#include <algorithm>
9+
#include <exception>
10+
#include <filesystem>
911
#include <future>
1012
#include <optional>
1113
#include <string>
@@ -19,6 +21,7 @@
1921

2022
#include "xpano/algorithm/algorithm.h"
2123
#include "xpano/algorithm/image.h"
24+
#include "xpano/algorithm/options.h"
2225
#include "xpano/cli/args.h"
2326
#include "xpano/constants.h"
2427
#include "xpano/gui/action.h"
@@ -198,7 +201,7 @@ auto ResolveStitchingResultFuture(
198201
spdlog::info(*status_message);
199202
}
200203

201-
return std::move(result);
204+
return result;
202205
}
203206

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

627630
auto handle_pano =
628-
[this, &actions](std::future<pipeline::StitchingResult> pano_future) {
631+
[this](std::future<pipeline::StitchingResult> pano_future) {
629632
auto result = ResolveStitchingResultFuture(
630633
std::move(pano_future), &plot_pane_, &status_message_);
631634
auto& pano = stitcher_data_->panos[result.pano_id];

0 commit comments

Comments
 (0)