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