Skip to content

Commit f79453c

Browse files
committed
use kj/filesystem
1 parent 1f50920 commit f79453c

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

compiler/src/main/cpp/capnpc-java.c++

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <capnp/schema.capnp.h>
2727
#include <capnp/serialize.h>
2828
#include <kj/debug.h>
29+
#include <kj/filesystem.h>
2930
#include <kj/io.h>
3031
#include <kj/string-tree.h>
3132
#include <kj/vector.h>
@@ -46,8 +47,8 @@
4647
#include "config.h"
4748
#endif
4849

49-
#if CAPNP_VERSION < 5000
50-
#error "This version of capnpc-java requires Cap'n Proto version 0.5 or higher."
50+
#if CAPNP_VERSION < 7000
51+
#error "This version of capnpc-java requires Cap'n Proto version 0.7.0 or higher."
5152
#endif
5253

5354
#ifndef VERSION
@@ -1760,9 +1761,7 @@ private:
17601761
KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }, indent);
17611762

17621763
return NodeText {
1763-
kj::strTree(
1764-
kj::mv(top.outerTypeDef),
1765-
KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }),
1764+
kj::mv(top.outerTypeDef),
17661765

17671766
kj::strTree(
17681767
kj::mv(top.readerBuilderDefs),
@@ -1931,42 +1930,19 @@ private:
19311930

19321931
// -----------------------------------------------------------------
19331932

1934-
void makeDirectory(kj::StringPtr path) {
1935-
KJ_IF_MAYBE(slashpos, path.findLast('/')) {
1936-
// Make the parent dir.
1937-
makeDirectory(kj::str(path.slice(0, *slashpos)));
1938-
}
1939-
1940-
if (mkdir(path.cStr(), 0777) < 0) {
1941-
int error = errno;
1942-
if (error != EEXIST) {
1943-
KJ_FAIL_SYSCALL("mkdir(path)", error, path);
1944-
}
1945-
}
1946-
}
1933+
kj::Own<kj::Filesystem> fs = kj::newDiskFilesystem();
19471934

19481935
void writeFile(kj::StringPtr filename, const kj::StringTree& text) {
1949-
if (!filename.startsWith("/")) {
1950-
KJ_IF_MAYBE(slashpos, filename.findLast('/')) {
1951-
// Make the parent dir.
1952-
makeDirectory(kj::str(filename.slice(0, *slashpos)));
1953-
}
1954-
}
1955-
1956-
int fd;
1957-
KJ_SYSCALL(fd = open(filename.cStr(), O_CREAT | O_WRONLY | O_TRUNC, 0666), filename);
1958-
kj::FdOutputStream out((kj::AutoCloseFd(fd)));
1959-
1960-
text.visit(
1961-
[&](kj::ArrayPtr<const char> text) {
1962-
out.write(text.begin(), text.size());
1963-
});
1936+
const auto path = kj::Path::parse(filename);
1937+
auto file = fs->getCurrent().openFile(path,
1938+
kj::WriteMode::CREATE | kj::WriteMode::MODIFY | kj::WriteMode::CREATE_PARENT);
1939+
file->writeAll(text.flatten());
19641940
}
19651941

19661942
kj::MainBuilder::Validity run() {
19671943
ReaderOptions options;
19681944
options.traversalLimitInWords = 1 << 30; // Don't limit.
1969-
StreamFdMessageReader reader(STDIN_FILENO, options);
1945+
StreamFdMessageReader reader(0, options);
19701946
auto request = reader.getRoot<schema::CodeGeneratorRequest>();
19711947

19721948
for (auto node: request.getNodes()) {

0 commit comments

Comments
 (0)