# Update .zrn files for all modified .zrn.pbtxt files
# $ bazel run //experimental/lgarg:update_zrns
#
# Update .zrn files for specified files
# (paths must be specified relative to driving root)
# $ bazel run //experimental/lgarg:update_zrns -- <list of pbtxts>
#
# If the file list contains any non .zrn.pbtxt files, they
# are automatically ignored. If no files are specified, we
# use git to check which zrn pbtxts have been modified and
# update the corresponing zrn files

all_files="$@"
if [[ -z "$all_files" ]]; then
  all_files=$(git -C "$BUILD_WORKING_DIRECTORY" status --short | sed 's/^...//')
fi

for pbtxt in `echo "$all_files" | grep "\.zrn\.pbtxt$"`; do
  echo "Converting ZRN: $pbtxt"
  mapping/zrn/tools/zrn_to_pb              \
    --in="$BUILD_WORKING_DIRECTORY/$pbtxt" \
    --out="$BUILD_WORKING_DIRECTORY/${pbtxt::-6}"
done
