# See the License for the specific language governing permissions and
# limitations under the License.
-if [ -z $ANDROID_BUILD_TOP ]; then
- echo "You need to source and lunch before you can use this script"
- exit 1
-fi
-
set -e
-$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode linkerconfig conv_apex_manifest
+# to use relative paths
+cd $(dirname $0)
+
+# when executed directly from commandline, build dependencies
+if [[ $(basename $0) == "rundiff.sh" ]]; then
+ if [ -z $ANDROID_BUILD_TOP ]; then
+ echo "You need to source and lunch before you can use this script"
+ exit 1
+ fi
+ $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode linkerconfig conv_apex_manifest
+fi
-LINKERCONFIG_DIR=$ANDROID_BUILD_TOP/system/linkerconfig
-LINKERCONFIG_BIN=$ANDROID_HOST_OUT/bin/linkerconfig
-CONV_APEX_BIN=$ANDROID_HOST_OUT/bin/conv_apex_manifest
-GOLDEN_OUT=$LINKERCONFIG_DIR/testdata/golden_output
-TEST_OUT=$LINKERCONFIG_DIR/testdata/output
+# $1: target output directory
+function run_linkerconfig_to {
+ # prepare testdata root
+ TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
+ cp -R ./testdata/root/* $TMP_ROOT
+ find $TMP_ROOT -name apex_manifest.json -exec sh -c '$2 proto $1 -o ${1%.json}.pb' sh {} conv_apex_manifest \;
+ find $TMP_ROOT -name apex_manifest.json -exec sh -c 'mkdir `dirname $1`/lib' sh {} \;
-echo "Running linkerconfig "
+ # run linkerconfig
+ rm -rf $1
-TMP_ROOT=$(mktemp -d -t linkerconfig-XXXXXXXX)
+ mkdir -p $1
+ linkerconfig -v R -r $TMP_ROOT -t $1
-cp -R $LINKERCONFIG_DIR/testdata/root/* $TMP_ROOT
+ # clean up testdata root
+ rm -rf $TMP_ROOT
+}
-find $TMP_ROOT -name apex_manifest.json -exec sh -c '$2 proto $1 -o ${1%.json}.pb' sh {} $CONV_APEX_BIN \;
-find $TMP_ROOT -name apex_manifest.json -exec sh -c 'mkdir `dirname $1`/lib' sh {} \;
+# update golden_output
+if [[ $1 == "--update" ]]; then
+ run_linkerconfig_to ./testdata/golden_output
+ echo "Updated"
+ exit 0
+fi
-rm -rf $TEST_OUT
-mkdir -p $TEST_OUT
-$LINKERCONFIG_BIN -v R -r $TMP_ROOT -t $TEST_OUT
-rm -rf $TMP_ROOT
+echo "Running linkerconfig diff test..."
-if diff -ruN $GOLDEN_OUT $TEST_OUT ; then
- echo "no changes"
+run_linkerconfig_to ./testdata/output
+if diff -ruN ./testdata/golden_output ./testdata/output ; then
+ echo "No changes."
else
echo
echo "------------------------------------------------------------------------------------------"
echo "if change looks fine, run following:"
- echo " rm -iRf $GOLDEN_OUT && cp -R $TEST_OUT $GOLDEN_OUT"
+ echo " \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
echo "------------------------------------------------------------------------------------------"
-fi
+ # fail
+ exit 1
+fi
\ No newline at end of file