use kj/filesystem
This commit is contained in:
parent
ad1fa2cc22
commit
57c0215bef
1 changed files with 10 additions and 34 deletions
|
@ -26,6 +26,7 @@
|
||||||
#include <capnp/schema.capnp.h>
|
#include <capnp/schema.capnp.h>
|
||||||
#include <capnp/serialize.h>
|
#include <capnp/serialize.h>
|
||||||
#include <kj/debug.h>
|
#include <kj/debug.h>
|
||||||
|
#include <kj/filesystem.h>
|
||||||
#include <kj/io.h>
|
#include <kj/io.h>
|
||||||
#include <kj/string-tree.h>
|
#include <kj/string-tree.h>
|
||||||
#include <kj/vector.h>
|
#include <kj/vector.h>
|
||||||
|
@ -47,8 +48,8 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CAPNP_VERSION < 5000
|
#if CAPNP_VERSION < 7000
|
||||||
#error "This version of capnpc-java requires Cap'n Proto version 0.5 or higher."
|
#error "This version of capnpc-java requires Cap'n Proto version 0.7.0 or higher."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
|
@ -2318,9 +2319,7 @@ private:
|
||||||
KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }, indent);
|
KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }, indent);
|
||||||
|
|
||||||
return NodeText {
|
return NodeText {
|
||||||
kj::strTree(
|
|
||||||
kj::mv(top.outerTypeDef),
|
kj::mv(top.outerTypeDef),
|
||||||
KJ_MAP(n, nestedTexts) { return kj::mv(n.outerTypeDef); }),
|
|
||||||
|
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(top.readerBuilderDefs),
|
kj::mv(top.readerBuilderDefs),
|
||||||
|
@ -2498,36 +2497,13 @@ private:
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
void makeDirectory(kj::StringPtr path) {
|
kj::Own<kj::Filesystem> fs = kj::newDiskFilesystem();
|
||||||
KJ_IF_MAYBE(slashpos, path.findLast('/')) {
|
|
||||||
// Make the parent dir.
|
|
||||||
makeDirectory(kj::str(path.slice(0, *slashpos)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mkdir(path.cStr(), 0777) < 0) {
|
|
||||||
int error = errno;
|
|
||||||
if (error != EEXIST) {
|
|
||||||
KJ_FAIL_SYSCALL("mkdir(path)", error, path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeFile(kj::StringPtr filename, const kj::StringTree& text) {
|
void writeFile(kj::StringPtr filename, const kj::StringTree& text) {
|
||||||
if (!filename.startsWith("/")) {
|
const auto path = kj::Path::parse(filename);
|
||||||
KJ_IF_MAYBE(slashpos, filename.findLast('/')) {
|
auto file = fs->getCurrent().openFile(path,
|
||||||
// Make the parent dir.
|
kj::WriteMode::CREATE | kj::WriteMode::MODIFY | kj::WriteMode::CREATE_PARENT);
|
||||||
makeDirectory(kj::str(filename.slice(0, *slashpos)));
|
file->writeAll(text.flatten());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd;
|
|
||||||
KJ_SYSCALL(fd = open(filename.cStr(), O_CREAT | O_WRONLY | O_TRUNC, 0666), filename);
|
|
||||||
kj::FdOutputStream out((kj::AutoCloseFd(fd)));
|
|
||||||
|
|
||||||
text.visit(
|
|
||||||
[&](kj::ArrayPtr<const char> text) {
|
|
||||||
out.write(text.begin(), text.size());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::MainBuilder::Validity run() {
|
kj::MainBuilder::Validity run() {
|
||||||
|
@ -2538,7 +2514,7 @@ private:
|
||||||
|
|
||||||
ReaderOptions options;
|
ReaderOptions options;
|
||||||
options.traversalLimitInWords = 1 << 30; // Don't limit.
|
options.traversalLimitInWords = 1 << 30; // Don't limit.
|
||||||
StreamFdMessageReader reader(STDIN_FILENO, options);
|
StreamFdMessageReader reader(0, options);
|
||||||
auto request = reader.getRoot<schema::CodeGeneratorRequest>();
|
auto request = reader.getRoot<schema::CodeGeneratorRequest>();
|
||||||
|
|
||||||
for (auto node: request.getNodes()) {
|
for (auto node: request.getNodes()) {
|
||||||
|
|
Loading…
Reference in a new issue