fx build fix
This commit is contained in:
@@ -6,6 +6,8 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
|
|||||||
API_DIR="${REPO_ROOT}/api"
|
API_DIR="${REPO_ROOT}/api"
|
||||||
PROTO_DIR="./proto"
|
PROTO_DIR="./proto"
|
||||||
PROTOC_BIN="${PROTOC:-protoc}"
|
PROTOC_BIN="${PROTOC:-protoc}"
|
||||||
|
GO_MODULE="github.com/tech/sendico/pkg"
|
||||||
|
GO_OUT_DIR="./pkg"
|
||||||
|
|
||||||
# Ensure required tools exist
|
# Ensure required tools exist
|
||||||
if ! command -v "${PROTOC_BIN}" >/dev/null 2>&1; then
|
if ! command -v "${PROTOC_BIN}" >/dev/null 2>&1; then
|
||||||
@@ -30,33 +32,29 @@ for cand in /usr/include /usr/local/include; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build an include-array only when non-empty
|
PROTOC_ARGS=""
|
||||||
PROTOC_I=()
|
|
||||||
if [ -n "${PROTOC_INCLUDE}" ]; then
|
if [ -n "${PROTOC_INCLUDE}" ]; then
|
||||||
PROTOC_I+=("-I=${PROTOC_INCLUDE}")
|
PROTOC_ARGS="-I=${PROTOC_INCLUDE}"
|
||||||
fi
|
fi
|
||||||
# Always include our proto tree
|
PROTOC_ARGS="${PROTOC_ARGS} -I=${PROTO_DIR}"
|
||||||
PROTOC_I+=("-I=${PROTO_DIR}")
|
|
||||||
|
|
||||||
generate_go() {
|
generate_go() {
|
||||||
local out_dir="$1"; shift
|
# shellcheck disable=SC2086
|
||||||
mkdir -p "${out_dir}"
|
|
||||||
"${PROTOC_BIN}" \
|
"${PROTOC_BIN}" \
|
||||||
"${PROTOC_I[@]}" \
|
${PROTOC_ARGS} \
|
||||||
--go_out="${out_dir}" \
|
--go_out="${GO_OUT_DIR}" \
|
||||||
--go_opt=paths=source_relative \
|
--go_opt=module="${GO_MODULE}" \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_go_with_grpc() {
|
generate_go_with_grpc() {
|
||||||
local out_dir="$1"; shift
|
# shellcheck disable=SC2086
|
||||||
mkdir -p "${out_dir}"
|
|
||||||
"${PROTOC_BIN}" \
|
"${PROTOC_BIN}" \
|
||||||
"${PROTOC_I[@]}" \
|
${PROTOC_ARGS} \
|
||||||
--go_out="${out_dir}" \
|
--go_out="${GO_OUT_DIR}" \
|
||||||
--go_opt=paths=source_relative \
|
--go_opt=module="${GO_MODULE}" \
|
||||||
--go-grpc_out="${out_dir}" \
|
--go-grpc_out="${GO_OUT_DIR}" \
|
||||||
--go-grpc_opt=paths=source_relative \
|
--go-grpc_opt=module="${GO_MODULE}" \
|
||||||
"$@"
|
"$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,57 +65,61 @@ clean_pb_files() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_protos() {
|
||||||
|
local search_dir="$1" maxdepth="${2:-}"
|
||||||
|
if [ -n "$maxdepth" ]; then
|
||||||
|
find "${search_dir}" -maxdepth "${maxdepth}" -type f -name '*.proto' | sort
|
||||||
|
else
|
||||||
|
find "${search_dir}" -type f -name '*.proto' | sort
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cd "${API_DIR}"
|
cd "${API_DIR}"
|
||||||
|
|
||||||
# Messaging (top-level .proto files in ./proto)
|
messaging_files="$(list_protos "${PROTO_DIR}" 1)"
|
||||||
mapfile -t messaging_protos < <(find "${PROTO_DIR}" -maxdepth 1 -type f -name '*.proto' | sort)
|
if [ -n "${messaging_files}" ]; then
|
||||||
if [ "${#messaging_protos[@]}" -gt 0 ]; then
|
|
||||||
info "Compiling messaging protos"
|
info "Compiling messaging protos"
|
||||||
rm -rf ./pkg/messaging/internal/generated
|
rm -rf ./pkg/generated/gmessaging ./pkg/messaging/internal/generated
|
||||||
generate_go "./pkg/messaging/internal/generated" "${messaging_protos[@]}"
|
set -- $messaging_files
|
||||||
|
generate_go "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Common shared
|
common_files="$(list_protos "${PROTO_DIR}/common")"
|
||||||
mapfile -t common_protos < <(find "${PROTO_DIR}/common" -type f -name '*.proto' | sort)
|
if [ -n "${common_files}" ]; then
|
||||||
if [ "${#common_protos[@]}" -gt 0 ]; then
|
|
||||||
info "Compiling common shared protos"
|
info "Compiling common shared protos"
|
||||||
clean_pb_files "./pkg/proto"
|
clean_pb_files "./pkg/proto"
|
||||||
generate_go "./pkg/proto" "${common_protos[@]}"
|
set -- $common_files
|
||||||
|
generate_go "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ledger
|
|
||||||
if [ -f "${PROTO_DIR}/ledger/v1/ledger.proto" ]; then
|
if [ -f "${PROTO_DIR}/ledger/v1/ledger.proto" ]; then
|
||||||
info "Compiling ledger protos"
|
info "Compiling ledger protos"
|
||||||
clean_pb_files "./pkg/proto/ledger"
|
clean_pb_files "./pkg/proto/ledger"
|
||||||
generate_go_with_grpc "./pkg/proto/ledger/v1" "${PROTO_DIR}/ledger/v1/ledger.proto"
|
generate_go_with_grpc "${PROTO_DIR}/ledger/v1/ledger.proto"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Oracle
|
|
||||||
if [ -f "${PROTO_DIR}/oracle/v1/oracle.proto" ]; then
|
if [ -f "${PROTO_DIR}/oracle/v1/oracle.proto" ]; then
|
||||||
info "Compiling oracle protos"
|
info "Compiling oracle protos"
|
||||||
clean_pb_files "./pkg/proto/oracle"
|
clean_pb_files "./pkg/proto/oracle"
|
||||||
generate_go_with_grpc "./pkg/proto/oracle/v1" "${PROTO_DIR}/oracle/v1/oracle.proto"
|
generate_go_with_grpc "${PROTO_DIR}/oracle/v1/oracle.proto"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Chain gateway
|
|
||||||
if [ -f "${PROTO_DIR}/chain/gateway/v1/gateway.proto" ]; then
|
if [ -f "${PROTO_DIR}/chain/gateway/v1/gateway.proto" ]; then
|
||||||
info "Compiling chain gateway protos"
|
info "Compiling chain gateway protos"
|
||||||
clean_pb_files "./pkg/proto/chain/gateway"
|
clean_pb_files "./pkg/proto/chain/gateway"
|
||||||
generate_go_with_grpc "./pkg/proto/chain/gateway/v1" "${PROTO_DIR}/chain/gateway/v1/gateway.proto"
|
generate_go_with_grpc "${PROTO_DIR}/chain/gateway/v1/gateway.proto"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Payments orchestrator
|
|
||||||
if [ -f "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto" ]; then
|
if [ -f "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto" ]; then
|
||||||
info "Compiling payments orchestrator protos"
|
info "Compiling payments orchestrator protos"
|
||||||
clean_pb_files "./pkg/proto/payments/orchestrator"
|
clean_pb_files "./pkg/proto/payments/orchestrator"
|
||||||
generate_go_with_grpc "./pkg/proto/payments/orchestrator/v1" "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto"
|
generate_go_with_grpc "${PROTO_DIR}/payments/orchestrator/v1/orchestrator.proto"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Billing fees
|
|
||||||
if [ -f "${PROTO_DIR}/billing/fees/v1/fees.proto" ]; then
|
if [ -f "${PROTO_DIR}/billing/fees/v1/fees.proto" ]; then
|
||||||
info "Compiling billing fees protos"
|
info "Compiling billing fees protos"
|
||||||
clean_pb_files "./pkg/proto/billing/fees"
|
clean_pb_files "./pkg/proto/billing/fees"
|
||||||
generate_go_with_grpc "./pkg/proto/billing/fees/v1" "${PROTO_DIR}/billing/fees/v1/fees.proto"
|
generate_go_with_grpc "${PROTO_DIR}/billing/fees/v1/fees.proto"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Protobuf generation completed"
|
info "Protobuf generation completed"
|
||||||
|
|||||||
Reference in New Issue
Block a user