jbaldwin / libcoro

C++20 coroutine library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is setup for what .githooks uses documented?

dok-net opened this issue · comments

I find that my local commits wreck the README.md. I haven't found any information in the intact README.md what needs to be installed (Ubuntu on WSL2).

Yeah thats right, I've got a githook setup so it inserts the examples when you commit so all the examples in the readme are guaranteed to work since they are actually compiled source code. So theres a .githooks/readme-template.md that is what you should actually edit and then on commit it runs the githook to generate the top level README.md file.

Yes, right, but what needs to be installed for that to work? My setup just generates a broken README.md.

Ah... probably because clang-format is failing. It also formats all the files you edited in the git commit via clang format. Otherwise its just simple find and replace via echo's to shove in the examples to the README.md file.

Specifically you would need the program clang-format, here is the bash it executes:

FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .tcc"

# Determins if a file has the right extension to be clang-format'ed.
should_clang_format() {
    local filename=$(basename "$1")
    local extension=".${filename##*.}"
    local ext

    local result=0

    # Ignore the test/catch*.hpp file
    if [[ "$1" != *"catch"* ]]; then
        for ext in $FILE_EXTS; do
            # Otherwise, if the extension is in the array of extensions to reformat, echo 1.
            [[ "$ext" == "$extension" ]] && result=1 && break
        done
    fi

    echo $result
}

# Run the clang-format across the project's changed files.
for file in $(git diff-index --cached --name-only HEAD); do
    if [ -f "${file}" ] && [ "$(should_clang_format "${file}")" != "0" ] ; then
        echo "clang-format ${file}"
        clang-format -i --style=file "${file}"
        git add "${file}"
    fi
done

apt install clang-format wasn't sufficient, still getting a broken README.md like this, snip:

iff --git a/README.md b/README.md
index b591cd0..985c8dc 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ int main()
 
     // Create a task that awaits the doubling of its given value and
     // then returns the result after adding 5.
-    auto double_and_add_5_task = [&](uint64_t input) -> coro::task<uint64_t> {
+    auto double_and_add_5_task = [${EXAMPLE_CORO_TASK_CPP}](uint64_t input) -> coro::task<uint64_t> {
         auto doubled = co_await double_task(input);

Hmm all it's doing after clang format is this on repeat for each example:

template_contents=$(cat 'README.md')
example_contents=$(cat 'examples/coro_task.cpp')
echo "${template_contents/\$\{EXAMPLE_CORO_TASK_CPP\}/$example_contents}" > README.md

What shell are you using?