-
Notifications
You must be signed in to change notification settings - Fork 153
Add a code generator for boilerplate to move data in and out of protobuf messages for grpc #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/26.04
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify that committed codegen output matches what generate_conversions.py produces. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Fails if a developer edited field_registry.yaml without re-running ./build.sh codegen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CODEGEN_DIR="${REPO_DIR}/cpp/codegen" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GENERATED_DIR="${CODEGEN_DIR}/generated" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PROTO_DEST="${REPO_DIR}/cpp/src/grpc/cuopt_remote_data.proto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TMPDIR=$(mktemp -d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trap 'rm -rf ${TMPDIR}' EXIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Running code generator into temp directory..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| python "${CODEGEN_DIR}/generate_conversions.py" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --registry "${CODEGEN_DIR}/field_registry.yaml" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --output-dir "${TMPDIR}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Comparing generated output with committed files..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FAILED=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for f in "${TMPDIR}"/*; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fname=$(basename "$f") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| committed="${GENERATED_DIR}/${fname}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ ! -f "${committed}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "MISSING: ${committed} (new generated file not committed)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FAILED=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! diff -q "$f" "${committed}" > /dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "MISMATCH: cpp/codegen/generated/${fname}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| diff -u "${committed}" "$f" | head -30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FAILED=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the directory comparison exhaustive under
Suggested fix for f in "${TMPDIR}"/*; do
fname=$(basename "$f")
committed="${GENERATED_DIR}/${fname}"
if [ ! -f "${committed}" ]; then
echo "MISSING: ${committed} (new generated file not committed)"
FAILED=1
continue
fi
if ! diff -q "$f" "${committed}" > /dev/null 2>&1; then
echo "MISMATCH: cpp/codegen/generated/${fname}"
- diff -u "${committed}" "$f" | head -30
+ diff -u "${committed}" "$f" | head -30 || true
FAILED=1
fi
done
+
+for committed in "${GENERATED_DIR}"/*; do
+ fname=$(basename "${committed}")
+ if [ ! -f "${TMPDIR}/${fname}" ]; then
+ echo "STALE: ${committed} (committed file is no longer generated)"
+ FAILED=1
+ fi
+done📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -f "${TMPDIR}/cuopt_remote_data.proto" ] && [ -f "${PROTO_DEST}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! diff -q "${TMPDIR}/cuopt_remote_data.proto" "${PROTO_DEST}" > /dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "MISMATCH: cpp/src/grpc/cuopt_remote_data.proto (not copied from codegen)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FAILED=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail when the copied proto is missing.
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ ${FAILED} -ne 0 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "ERROR: Committed generated files are out of sync with field_registry.yaml." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Run './build.sh codegen' and commit the results." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "OK: All generated files match field_registry.yaml." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,8 @@ cache: | |
| - make | ||
| - ninja | ||
| - git | ||
| - python | ||
| - pyyaml | ||
| - tbb-devel | ||
| - zlib | ||
| - bzip2 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codegen is a generic name, you can call it grpc_code_gen or grpc_gen