Skip to content

Commit 0d5f1fa

Browse files
committed
iwyu: fix add/remove include errors
1 parent 753d2b1 commit 0d5f1fa

File tree

13 files changed

+119
-51
lines changed

13 files changed

+119
-51
lines changed

example/calculator.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <calculator.h>
6+
#include <init.capnp.h>
7+
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
8+
69
#include <charconv>
10+
#include <cstring>
711
#include <fstream>
8-
#include <init.capnp.h>
9-
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
10-
#include <init.h>
1112
#include <iostream>
13+
#include <kj/async.h>
14+
#include <kj/common.h>
15+
#include <kj/memory.h>
1216
#include <memory>
1317
#include <mp/proxy-io.h>
14-
#include <printer.h>
1518
#include <stdexcept>
1619
#include <string>
20+
#include <system_error>
1721
#include <utility>
1822

1923
class CalculatorImpl : public Calculator

example/example.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <init.capnp.h>
6+
#include <init.capnp.proxy.h>
7+
8+
#include <cstring> // IWYU pragma: keep
59
#include <filesystem>
610
#include <fstream>
711
#include <future>
8-
#include <init.capnp.h>
9-
#include <init.capnp.proxy.h>
1012
#include <iostream>
13+
#include <kj/async.h>
14+
#include <kj/common.h>
15+
#include <memory>
1116
#include <mp/proxy-io.h>
1217
#include <mp/util.h>
1318
#include <stdexcept>

example/init.capnp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ using Printer = import "printer.capnp";
1212
$Proxy.include("calculator.h");
1313
$Proxy.include("init.h");
1414
$Proxy.include("printer.h");
15-
$Proxy.includeTypes("calculator.capnp.proxy-types.h");
16-
$Proxy.includeTypes("printer.capnp.proxy-types.h");
15+
$Proxy.includeTypes("types.h");
1716

1817
interface InitInterface $Proxy.wrap("Init") {
1918
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);

example/printer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <printer.h>
6+
7+
#include <init.capnp.h>
8+
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
9+
510
#include <charconv>
11+
#include <cstring>
612
#include <fstream>
7-
#include <init.capnp.h>
8-
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
9-
#include <init.h>
1013
#include <iostream>
14+
#include <kj/async.h>
15+
#include <kj/common.h>
16+
#include <kj/memory.h>
1117
#include <memory>
1218
#include <mp/proxy-io.h>
13-
#include <printer.h>
1419
#include <stdexcept>
1520
#include <string>
21+
#include <system_error>
1622

1723
class PrinterImpl : public Printer
1824
{

example/types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
#ifndef EXAMPLE_TYPES_H
66
#define EXAMPLE_TYPES_H
77

8+
#include <calculator.capnp.proxy-types.h>
9+
#include <printer.capnp.proxy-types.h>
10+
11+
// IWYU pragma: begin_exports
812
#include <mp/type-context.h>
913
#include <mp/type-decay.h>
1014
#include <mp/type-interface.h>
1115
#include <mp/type-string.h>
1216
#include <mp/type-threadmap.h>
17+
// IWYU pragma: end_exports
18+
19+
struct InitInterface; // IWYU pragma: export
20+
struct CalculatorInterface; // IWYU pragma: export
21+
struct PrinterInterface; // IWYU pragma: export
1322

1423
#endif // EXAMPLE_TYPES_H

include/mp/proxy-io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#include <capnp/rpc-twoparty.h>
1414

1515
#include <assert.h>
16+
#include <condition_variable>
1617
#include <functional>
1718
#include <kj/function.h>
1819
#include <map>
1920
#include <memory>
2021
#include <optional>
2122
#include <sstream>
2223
#include <string>
24+
#include <thread>
2325

2426
namespace mp {
2527
struct ThreadContext;

include/mp/proxy.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,31 @@
77

88
#include <mp/util.h>
99

10-
#include <array>
1110
#include <cassert>
1211
#include <functional>
1312
#include <list>
13+
#include <memory>
1414
#include <stddef.h>
1515
#include <tuple>
1616
#include <type_traits>
1717
#include <utility>
18+
#include <variant> // IWYU pragma: keep
1819

1920
namespace mp {
2021
class Connection;
2122
class EventLoop;
2223
//! Mapping from capnp interface type to proxy client implementation (specializations are generated by
2324
//! proxy-codegen.cpp).
24-
template <typename Interface>
25-
struct ProxyClient;
25+
template <typename Interface> struct ProxyClient; // IWYU pragma: export
2626
//! Mapping from capnp interface type to proxy server implementation (specializations are generated by
2727
//! proxy-codegen.cpp).
28-
template <typename Interface>
29-
struct ProxyServer;
28+
template <typename Interface> struct ProxyServer; // IWYU pragma: export
3029
//! Mapping from capnp method params type to method traits (specializations are generated by proxy-codegen.cpp).
31-
template <typename Params>
32-
struct ProxyMethod;
30+
template <typename Params> struct ProxyMethod; // IWYU pragma: export
3331
//! Mapping from capnp struct type to struct traits (specializations are generated by proxy-codegen.cpp).
34-
template <typename Struct>
35-
struct ProxyStruct;
32+
template <typename Struct> struct ProxyStruct; // IWYU pragma: export
3633
//! Mapping from local c++ type to capnp type and traits (specializations are generated by proxy-codegen.cpp).
37-
template <typename Type>
38-
struct ProxyType;
34+
template <typename Type> struct ProxyType; // IWYU pragma: export
3935

4036
using CleanupList = std::list<std::function<void()>>;
4137
using CleanupIt = typename CleanupList::iterator;

include/mp/util.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
#include <capnp/schema.h>
99
#include <cassert>
1010
#include <cstddef>
11+
#include <cstring>
1112
#include <functional>
12-
#include <future>
13-
#include <kj/common.h>
14-
#include <kj/exception.h>
1513
#include <kj/string-tree.h>
16-
#include <memory>
1714
#include <mutex>
18-
#include <string.h>
1915
#include <string>
2016
#include <tuple>
2117
#include <type_traits>

src/mp/gen.cpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#include <mp/util.h>
77

88
#include <algorithm>
9+
#include <capnp/schema.h>
910
#include <capnp/schema-parser.h>
11+
#include <cerrno>
1012
#include <cstdint>
1113
#include <cstdio>
1214
#include <cstdlib>
13-
#include <errno.h>
1415
#include <fstream>
1516
#include <functional>
17+
#include <initializer_list>
1618
#include <iostream>
1719
#include <kj/array.h>
1820
#include <kj/common.h>
@@ -26,6 +28,7 @@
2628
#include <string>
2729
#include <system_error>
2830
#include <unistd.h>
31+
#include <utility>
2932
#include <vector>
3033

3134
#define PROXY_BIN "mpgen"
@@ -198,19 +201,45 @@ static void Generate(kj::StringPtr src_prefix,
198201

199202
std::ofstream cpp_server(output_path + ".proxy-server.c++");
200203
cpp_server << "// Generated by " PROXY_BIN " from " << src_file << "\n\n";
204+
cpp_server << "// IWYU pragma: no_include <kj/memory.h>\n";
205+
cpp_server << "// IWYU pragma: no_include <memory>\n";
206+
cpp_server << "// IWYU pragma: begin_keep\n";
207+
cpp_server << "#include <" << include_path << ".proxy.h>\n";
201208
cpp_server << "#include <" << include_path << ".proxy-types.h>\n";
202-
cpp_server << "#include <" << PROXY_TYPES << ">\n\n";
209+
cpp_server << "#include <capnp/generated-header-support.h>\n";
210+
cpp_server << "#include <cstring>\n";
211+
cpp_server << "#include <kj/async.h>\n";
212+
cpp_server << "#include <kj/common.h>\n";
213+
cpp_server << "#include <kj/exception.h>\n";
214+
cpp_server << "#include <mp/proxy.h>\n";
215+
cpp_server << "#include <mp/util.h>\n";
216+
cpp_server << "#include <" << PROXY_TYPES << ">\n";
217+
cpp_server << "// IWYU pragma: end_keep\n\n";
203218
cpp_server << "namespace mp {\n";
204219

205220
std::ofstream cpp_client(output_path + ".proxy-client.c++");
206221
cpp_client << "// Generated by " PROXY_BIN " from " << src_file << "\n\n";
222+
cpp_client << "// IWYU pragma: no_include <kj/memory.h>\n";
223+
cpp_client << "// IWYU pragma: no_include <memory>\n";
224+
cpp_client << "// IWYU pragma: begin_keep\n";
225+
cpp_client << "#include <" << include_path << ".h>\n";
226+
cpp_client << "#include <" << include_path << ".proxy.h>\n";
207227
cpp_client << "#include <" << include_path << ".proxy-types.h>\n";
208-
cpp_client << "#include <" << PROXY_TYPES << ">\n\n";
228+
cpp_client << "#include <capnp/generated-header-support.h>\n";
229+
cpp_client << "#include <cstring>\n";
230+
cpp_client << "#include <kj/common.h>\n";
231+
cpp_client << "#include <mp/proxy.h>\n";
232+
cpp_client << "#include <mp/util.h>\n";
233+
cpp_client << "#include <" << PROXY_TYPES << ">\n";
234+
cpp_client << "// IWYU pragma: end_keep\n\n";
209235
cpp_client << "namespace mp {\n";
210236

211237
std::ofstream cpp_types(output_path + ".proxy-types.c++");
212238
cpp_types << "// Generated by " PROXY_BIN " from " << src_file << "\n\n";
213-
cpp_types << "#include <" << include_path << ".proxy-types.h>\n";
239+
cpp_types << "// IWYU pragma: no_include \"mp/proxy.h\"\n";
240+
cpp_types << "// IWYU pragma: no_include \"mp/proxy-io.h\"\n";
241+
cpp_types << "#include <" << include_path << ".proxy.h>\n";
242+
cpp_types << "#include <" << include_path << ".proxy-types.h> // IWYU pragma: keep\n";
214243
cpp_types << "#include <" << PROXY_TYPES << ">\n\n";
215244
cpp_types << "namespace mp {\n";
216245

@@ -226,10 +255,12 @@ static void Generate(kj::StringPtr src_prefix,
226255
inl << "// Generated by " PROXY_BIN " from " << src_file << "\n\n";
227256
inl << "#ifndef " << guard << "_PROXY_TYPES_H\n";
228257
inl << "#define " << guard << "_PROXY_TYPES_H\n\n";
229-
inl << "#include <" << include_path << ".proxy.h>\n";
258+
inl << "// IWYU pragma: no_include \"mp/proxy.h\"\n";
259+
inl << "#include <mp/proxy.h> // IWYU pragma: keep\n";
260+
inl << "#include <" << include_path << ".proxy.h> // IWYU pragma: keep\n";
230261
for (const auto annotation : file_schema.getProto().getAnnotations()) {
231262
if (annotation.getId() == INCLUDE_TYPES_ANNOTATION_ID) {
232-
inl << "#include <" << annotation.getValue().getText() << ">\n";
263+
inl << "#include \"" << annotation.getValue().getText() << "\" // IWYU pragma: export\n";
233264
}
234265
}
235266
inl << "namespace mp {\n";
@@ -238,10 +269,10 @@ static void Generate(kj::StringPtr src_prefix,
238269
h << "// Generated by " PROXY_BIN " from " << src_file << "\n\n";
239270
h << "#ifndef " << guard << "_PROXY_H\n";
240271
h << "#define " << guard << "_PROXY_H\n\n";
241-
h << "#include <" << include_path << ".h>\n";
272+
h << "#include <" << include_path << ".h> // IWYU pragma: keep\n";
242273
for (const auto annotation : file_schema.getProto().getAnnotations()) {
243274
if (annotation.getId() == INCLUDE_ANNOTATION_ID) {
244-
h << "#include <" << annotation.getValue().getText() << ">\n";
275+
h << "#include \"" << annotation.getValue().getText() << "\" // IWYU pragma: export\n";
245276
}
246277
}
247278
h << "#include <" << PROXY_DECL << ">\n\n";

src/mp/proxy.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010
#include <mp/type-threadmap.h>
1111
#include <mp/util.h>
1212

13-
#include <assert.h>
1413
#include <atomic>
15-
#include <capnp/blob.h>
1614
#include <capnp/capability.h>
15+
#include <capnp/rpc.h>
1716
#include <condition_variable>
1817
#include <functional>
1918
#include <future>
20-
#include <kj/async-io.h>
2119
#include <kj/async.h>
20+
#include <kj/async-io.h>
21+
#include <kj/async-prelude.h>
2222
#include <kj/common.h>
2323
#include <kj/debug.h>
24-
#include <kj/exception.h>
2524
#include <kj/function.h>
2625
#include <kj/memory.h>
2726
#include <map>
2827
#include <memory>
2928
#include <mutex>
30-
#include <stddef.h>
29+
#include <optional>
3130
#include <stdexcept>
3231
#include <string>
3332
#include <sys/socket.h>
@@ -38,9 +37,6 @@
3837

3938
namespace mp {
4039

41-
template <typename Interface>
42-
struct ProxyServer;
43-
4440
thread_local ThreadContext g_thread_context;
4541

4642
void LoggingErrorHandler::taskFailed(kj::Exception&& exception)

0 commit comments

Comments
 (0)