unpack-prebuilt-apex.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. set -eu
  3. # Copyright 2020 Google Inc. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Tool to unpack an apex file and verify that the required files were extracted.
  17. if [ $# -lt 7 ]; then
  18. echo "usage: $0 <deapaxer_path> <debugfs_path> <fsck.erofs_path> <apex file> <output_dir> <required_files>+" >&2
  19. exit 1
  20. fi
  21. DEAPEXER_PATH=$1
  22. DEBUGFS_PATH=$2
  23. FSCK_EROFS_PATH=$3
  24. APEX_FILE=$4
  25. OUTPUT_DIR=$5
  26. shift 5
  27. REQUIRED_PATHS=$@
  28. rm -fr $OUTPUT_DIR
  29. mkdir -p $OUTPUT_DIR
  30. # Unpack the apex file contents.
  31. $DEAPEXER_PATH --debugfs_path $DEBUGFS_PATH \
  32. --fsckerofs_path $FSCK_EROFS_PATH \
  33. extract $APEX_FILE $OUTPUT_DIR
  34. # Verify that the files that the build expects to be in the .apex file actually
  35. # exist, and make sure they have a fresh mtime to not confuse ninja.
  36. typeset -i FAILED=0
  37. for r in $REQUIRED_PATHS; do
  38. if [ ! -f $r ]; then
  39. echo "Required file $r not present in apex $APEX_FILE" >&2
  40. FAILED=$FAILED+1
  41. else
  42. # TODO(http:/b/177646343) - deapexer extracts the files with a timestamp of 1 Jan 1970.
  43. # touch the file so that ninja knows it has changed.
  44. touch $r
  45. fi
  46. done
  47. if [ $FAILED -gt 0 ]; then
  48. echo "$FAILED required files were missing from $APEX_FILE" >&2
  49. echo "Available files are:" >&2
  50. find $OUTPUT_DIR -type f | sed "s|^| |" >&2
  51. exit 1
  52. fi