Skip to content

Commit

Permalink
Merge branch 'main' into ArthurBandaryk.copts
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurBandaryk authored Oct 18, 2021
2 parents c167dae + 4a61461 commit d32669e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 32 deletions.
16 changes: 12 additions & 4 deletions stout/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct _Range {
step_(step) {}

void Start() {
previous_ = Scheduler::Context::Get();

k_.Start(*this);
}

Expand Down Expand Up @@ -47,20 +49,26 @@ struct _Range {
|| (from_ < to_ && step_ < 0)) {
k_.Ended();
} else {
int temp = from_;
from_ += step_;
k_.Body(temp);
previous_->Continue([this]() {
int temp = from_;
from_ += step_;
k_.Body(temp);
});
}
}

void Done() override {
k_.Ended();
previous_->Continue([this]() {
k_.Ended();
});
}

K_ k_;
int from_;
const int to_;
const int step_;

Scheduler::Context* previous_ = nullptr;
};

struct Composable {
Expand Down
30 changes: 19 additions & 11 deletions stout/stream-for-each.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct _StreamForEach {

void Start(detail::TypeErasedStream& stream) {
outer_ = &stream;
previous_ = Scheduler::Context::Get();

k_.Start(*this);
}

Expand Down Expand Up @@ -101,20 +103,24 @@ struct _StreamForEach {
}

void Next() override {
if (adaptor_.has_value()) {
CHECK_NOTNULL(inner_)->Next();
} else {
outer_->Next();
}
previous_->Continue([this]() {
if (adaptor_.has_value()) {
CHECK_NOTNULL(inner_)->Next();
} else {
outer_->Next();
}
});
}

void Done() override {
done_ = true;
if (adaptor_.has_value()) {
CHECK_NOTNULL(inner_)->Done();
} else {
outer_->Done();
}
previous_->Continue([this]() {
done_ = true;
if (adaptor_.has_value()) {
CHECK_NOTNULL(inner_)->Done();
} else {
outer_->Done();
}
});
}

K_ k_;
Expand All @@ -133,6 +139,8 @@ struct _StreamForEach {
Interrupt* interrupt_ = nullptr;

bool done_ = false;

Scheduler::Context* previous_ = nullptr;
};

template <typename F_>
Expand Down
33 changes: 20 additions & 13 deletions stout/take.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct _TakeLastN {

void Start(TypeErasedStream& stream) {
stream_ = &stream;
previous_ = Scheduler::Context::Get();

k_.Start(*this);
}

Expand Down Expand Up @@ -64,22 +66,26 @@ struct _TakeLastN {
// If the stream_ has not produced its values yet,
// make it do so by calling stream_.Next().
// When it has produced all its values we'll receive an Ended() call.
if (!ended_) {
stream_->Next();
return;
}
if (data_.empty()) {
// There are no more stored values, our stream has ended.
k_.Ended();
return;
}
auto value = std::move(data_.front());
data_.pop_front();
k_.Body(std::move(value));
previous_->Continue([this]() {
if (!ended_) {
stream_->Next();
return;
}
if (data_.empty()) {
// There are no more stored values, our stream has ended.
k_.Ended();
return;
}
auto value = std::move(data_.front());
data_.pop_front();
k_.Body(std::move(value));
});
}

void Done() override {
k_.Ended();
previous_->Continue([this]() {
k_.Ended();
});
}

K_ k_;
Expand All @@ -88,6 +94,7 @@ struct _TakeLastN {
bool ended_ = false;

TypeErasedStream* stream_ = nullptr;
Scheduler::Context* previous_ = nullptr;
};

struct Composable {
Expand Down
40 changes: 36 additions & 4 deletions tools/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ if [[ $? != 0 ]]; then
exit 1
fi

# Check for existence of buildifier
which buildifier >/dev/null
if [[ $? != 0 ]]; then
printf "Failed to find 'buildifier' (please install or update your path)\n"
exit 1
fi

# Returns 0 if the version in the first argument is greater than or
# equal to the version in the second argument, otherwise returns 1.
check_version() {
Expand All @@ -40,6 +47,19 @@ if [[ $? != 0 ]]; then
exit 1
fi

# Check version of buildifier.
buildifier_version_found="$(buildifier --version | head -n1 | cut -d" " -f3)"
buildifier_version_required="4.2.0"

check_version ${buildifier_version_found} ${buildifier_version_required}

if [[ $? != 0 ]]; then
printf "buildifier version '%s' is required but found '%s'\n" \
"${buildifier_version_required}" \
"${buildifier_version_found}"
exit 1
fi

# Get top-level directory so we can look for .clang-format file.
directory=$(git rev-parse --show-toplevel)

Expand All @@ -51,9 +71,11 @@ fi

run_checks() {
local -i status=0
files=`git diff --cached --name-only --diff-filter=ACM HEAD | grep -iE '\.(cc|h)$'`
for file in ${files}; do
# Check file is formatted correctly.

# C++ checks
cpp_files=`git diff --cached --name-only --diff-filter=ACM HEAD | grep -iE '\.(cc|h)$'`
for file in ${cpp_files}; do
# Check if file is formatted correctly.
clang-format --dry-run -Werror --ferror-limit=0 ${file}
if [[ $? != 0 ]]; then
status=1
Expand Down Expand Up @@ -81,9 +103,19 @@ run_checks() {
fi
(( number++ ))
done < "${file}"
done

# TODO: add more pre-commit checks here ...
# Starlark checks
bzl_files=`git diff --cached --name-only --diff-filter=ACM HEAD | grep -iE '\.(bzl|bazel)$'`
for file in ${bzl_files}; do
# Check if file is formatted correctly or if there are any warnings.
buildifier -v -lint=warn -warnings=all -mode=check ${file}
if [[ $? != 0 ]]; then
status=1
fi
done

# TODO: add more pre-commit checks here ...
exit ${status}
}

Expand Down

0 comments on commit d32669e

Please sign in to comment.