#!/usr/bin/env bash
set -euo pipefail

if [ "$(cat  out_adevtool_deps/soong/.intermediates/packages/services/Car/cpp/computepipe/aidl/android.automotive.computepipe.runner_interface/has_development )" = "1" ]; then mkdir -p packages/services/Car/cpp/computepipe/aidl/aidl_api/android.automotive.computepipe.runner/2 &&  cp -rf out_adevtool_deps/soong/.intermediates/packages/services/Car/cpp/computepipe/aidl/android.automotive.computepipe.runner_interface/dump/. packages/services/Car/cpp/computepipe/aidl/aidl_api/android.automotive.computepipe.runner/2 ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/packages/services/Car/cpp/computepipe/aidl/android.automotive.computepipe.runner_interface/has_development )" = "1" ]; then echo "There is change between ToT version and the latest stable version. Freezing android.automotive.computepipe.runner-V2." ; else echo "There is no change from the latest stable version of android.automotive.computepipe.runner. Nothing happened." ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/packages/services/Car/cpp/computepipe/aidl/android.automotive.computepipe.runner_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.automotive.computepipe.runner -parameter versions -remove-property packages/services/Car/cpp/computepipe/aidl/Android.bp ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/packages/services/Car/cpp/computepipe/aidl/android.automotive.computepipe.runner_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.automotive.computepipe.runner -parameter versions_with_info -add-literal '{version: "2", imports: ["android.hardware.graphics.common-V7"]}'  packages/services/Car/cpp/computepipe/aidl/Android.bp && out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.automotive.computepipe.runner -parameter frozen -set-bool true packages/services/Car/cpp/computepipe/aidl/Android.bp ; fi
