#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# This scripts runs the source code generation and commit the generated source code files.
# We use source code generation scripts to avoid tedious, repetitive code such as op definitions
# and FFI bindings. These generated source code files are required in development and deployment,
# but we DO NOT commit them to the upstream, so all source code files generated by this scripts
# are specified in .gitignore.

# However, it is hard for developers to track the changes of generated source code files,
# so this script forces committing the generated source code files so that you could
# use git diff to see the changes. On the other hand, please remember to remove the generated
# source code files before filing a pull request by running git_reset_generated_files.sh.
# Development steps:
#   1. Run this script: python3 scripts/src_codegen/git_add_generated_files.sh
#   2. Commit the generated source code files: git commit -a -m "Update generated source code files"
#   3. Work on your features.
#   4. Run this script again.
#   5. git diff to see the changes, build and run unit tests, etc.
#   6. If everything looks good, run git_reset_generated_files.sh.
#   7. Commit the changes and file a pull request.

SCRIPT_DIR=$(dirname "$0")
bash $SCRIPT_DIR/run_all.sh
(< $SCRIPT_DIR/generated_file_list.txt xargs -i find {} -type f) | xargs git add -f