OSDN Git Service

Refactor rundiff.sh
authorJooyung Han <jooyung@google.com>
Tue, 31 Mar 2020 06:44:53 +0000 (15:44 +0900)
committerJooyung Han <jooyung@google.com>
Tue, 31 Mar 2020 06:49:49 +0000 (15:49 +0900)
(copied from reverted d283fb913db051ef0653c9ea1af5d2d865dbbbf0)

. Add --update to update golden_output
. Do not rely on ANDROID_BUILD_TOP (required to be run on cloud)

Bug: n/a
Test: ./rundiff.sh # no changes
Change-Id: I098dabd2c5cd06f18a806cf66f593ea930f02945

rundiff.sh

index 3082d4c..baff2a4 100755 (executable)
 # 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