#!/bin/sh
# generate_dbc.sh | Use bazel to generate the Firmware DBC files
# @copyright Highly Confidential and Proprietary Zoox Information. Copyright (c) Zoox
#
# This decouples the build and upload aspects of DBC generation. This script controls building
# and upload is managed by the original upload_dbc.sh script (which no longer performs build)
#
# This is to ensure that DBCs are only uploaded as artifacts by tests that actually need to share
# and distribute those files.
# --trawat

set -xe  # exit on any error and print commands before executing

# Change directory to bazel workspace root
cd $(bazel info workspace)

# Build DBCs, uses kraken config for distributed builds and //firmware/common/can/... means
# build all targets specified by BUILD file within can directory
bazel build --config=kraken //firmware/common/can/...

# Store Githash SHA for this branch
sha=$(git rev-parse HEAD)

# The bus-specific DBCs will be present at this location
dbcs="bazel-bin/firmware/common/can/bus_dbcs"

# Ensure the bus DBC directory exists
test -d $dbcs
