Commit 1396abd0 authored by Kenton Varda's avatar Kenton Varda

Add test to check that bootstrapped sources are up-to-date and a script for updating them.

parent d0f630fe
#! /bin/bash
set -euo pipefail
export PATH=$PWD/bin:$PWD:$PATH
capnp compile -Isrc --no-standard-import --src-prefix=src -oc++:src \
src/capnp/c++.capnp src/capnp/schema.capnp \
src/capnp/compiler/lexer.capnp src/capnp/compiler/grammar.capnp
#! /bin/sh
# Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This is a one-off test rule.
set -eu
echo findProvider special:ekam-interceptor
read INTERCEPTOR
if test "$INTERCEPTOR" = ""; then
echo "error: couldn't find intercept.so." >&2
exit 1
fi
echo findProvider file:capnp
read CAPNP
if test "$CAPNP" = ""; then
echo "error: couldn't find capnp." >&2
exit 1
fi
echo findProvider file:capnpc-c++
read CAPNPC_CXX
if test "$CAPNPC_CXX" = ""; then
echo "error: couldn't find capnpc-c++." >&2
exit 1
fi
mkdir -p tmp/capnp/bootstrap-test-tmp
INPUTS="src/capnp/c++.capnp src/capnp/schema.capnp src/capnp/compiler/lexer.capnp src/capnp/compiler/grammar.capnp"
$CAPNP compile --src-prefix=src -Isrc --no-standard-import \
-o$CAPNPC_CXX:tmp/capnp/bootstrap-test-tmp $INPUTS
for file in $INPUTS; do
for ext in h c++; do
diff -u $file.$ext tmp/capnp/bootstrap-test-tmp/${file#src/}.$ext >&2
done
done
...@@ -65,6 +65,5 @@ if test "$CAPNPC_CXX" = ""; then ...@@ -65,6 +65,5 @@ if test "$CAPNPC_CXX" = ""; then
exit 1 exit 1
fi fi
# When exception stack traces are needed, add: +RTS -xc -RTS
LD_PRELOAD=$INTERCEPTOR DYLD_FORCE_FLAT_NAMESPACE= DYLD_INSERT_LIBRARIES=$INTERCEPTOR \ LD_PRELOAD=$INTERCEPTOR DYLD_FORCE_FLAT_NAMESPACE= DYLD_INSERT_LIBRARIES=$INTERCEPTOR \
$CAPNP compile -I. -o$CAPNPC_CXX "$INPUT" 3>&1 4<&0 >&2 $CAPNP compile -I. -o$CAPNPC_CXX "$INPUT" 3>&1 4<&0 >&2
capnp bin
capnpc-capnp bin
capnpc-c++ bin
...@@ -163,11 +163,10 @@ void makeMemberInfoTable(uint parent, MemberList&& members, ...@@ -163,11 +163,10 @@ void makeMemberInfoTable(uint parent, MemberList&& members,
} }
kj::StringPtr baseName(kj::StringPtr path) { kj::StringPtr baseName(kj::StringPtr path) {
const char* slashPos = strrchr(path.cStr(), '/'); KJ_IF_MAYBE(slashPos, path.findLast('/')) {
if (slashPos == nullptr) { return path.slice(*slashPos + 1);
return path;
} else { } else {
return slashPos + 1; return path;
} }
} }
...@@ -1298,7 +1297,26 @@ private: ...@@ -1298,7 +1297,26 @@ private:
// ----------------------------------------------------------------- // -----------------------------------------------------------------
void makeDirectory(kj::StringPtr path) {
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) {
KJ_IF_MAYBE(slashpos, filename.findLast('/')) {
// Make the parent dir.
makeDirectory(kj::str(filename.slice(0, *slashpos)));
}
int fd; int fd;
KJ_SYSCALL(fd = open(filename.cStr(), O_CREAT | O_WRONLY | O_TRUNC, 0666), filename); KJ_SYSCALL(fd = open(filename.cStr(), O_CREAT | O_WRONLY | O_TRUNC, 0666), filename);
kj::FdOutputStream out((kj::AutoCloseFd(fd))); kj::FdOutputStream out((kj::AutoCloseFd(fd)));
......
...@@ -87,6 +87,7 @@ public: ...@@ -87,6 +87,7 @@ public:
inline bool endsWith(const StringPtr& other) const; inline bool endsWith(const StringPtr& other) const;
inline Maybe<size_t> findFirst(char c) const; inline Maybe<size_t> findFirst(char c) const;
inline Maybe<size_t> findLast(char c) const;
private: private:
inline StringPtr(ArrayPtr<const char> content): content(content) {} inline StringPtr(ArrayPtr<const char> content): content(content) {}
...@@ -150,6 +151,7 @@ public: ...@@ -150,6 +151,7 @@ public:
} }
inline Maybe<size_t> findFirst(char c) const { return StringPtr(*this).findFirst(c); } inline Maybe<size_t> findFirst(char c) const { return StringPtr(*this).findFirst(c); }
inline Maybe<size_t> findLast(char c) const { return StringPtr(*this).findLast(c); }
private: private:
Array<char> content; Array<char> content;
...@@ -399,6 +401,15 @@ inline Maybe<size_t> StringPtr::findFirst(char c) const { ...@@ -399,6 +401,15 @@ inline Maybe<size_t> StringPtr::findFirst(char c) const {
} }
} }
inline Maybe<size_t> StringPtr::findLast(char c) const {
const char* pos = reinterpret_cast<const char*>(memrchr(content.begin(), c, size()));
if (pos == nullptr) {
return nullptr;
} else {
return pos - content.begin();
}
}
inline String::operator ArrayPtr<char>() { inline String::operator ArrayPtr<char>() {
return content == nullptr ? ArrayPtr<char>(nullptr) : content.slice(0, content.size() - 1); return content == nullptr ? ArrayPtr<char>(nullptr) : content.slice(0, content.size() - 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment