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

if [ "$(cat  out_adevtool_deps/soong/.intermediates/system/tools/aidl/aidl-test-versioned-interface_interface/has_development )" = "1" ]; then mkdir -p system/tools/aidl/aidl_api/aidl-test-versioned-interface/4 &&  cp -rf out_adevtool_deps/soong/.intermediates/system/tools/aidl/aidl-test-versioned-interface_interface/dump/. system/tools/aidl/aidl_api/aidl-test-versioned-interface/4 ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/system/tools/aidl/aidl-test-versioned-interface_interface/has_development )" = "1" ]; then echo "There is change between ToT version and the latest stable version. Freezing aidl-test-versioned-interface-V4." ; else echo "There is no change from the latest stable version of aidl-test-versioned-interface. Nothing happened." ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/system/tools/aidl/aidl-test-versioned-interface_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m aidl-test-versioned-interface -parameter versions -remove-property system/tools/aidl/Android.bp ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/system/tools/aidl/aidl-test-versioned-interface_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m aidl-test-versioned-interface -parameter versions_with_info -add-literal '{version: "4", imports: []}'  system/tools/aidl/Android.bp && out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m aidl-test-versioned-interface -parameter frozen -set-bool true system/tools/aidl/Android.bp ; fi
