blob: b244f7950b69635df4a6d784720a252d9f7f515b [file] [log] [blame]
Paul Duffin064b70c2020-11-02 17:32:38 +00001#!/bin/bash
2
3set -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.
Paul Duffine17c3162022-12-12 17:37:20 +000020if [ $# -lt 7 ]; then
21 echo "usage: $0 <deapaxer_path> <debugfs_path> <blkid_path> <fsck.erofs_path> <apex file> <output_dir> <required_files>+" >&2
Paul Duffin064b70c2020-11-02 17:32:38 +000022 exit 1
23fi
24
25DEAPEXER_PATH=$1
26DEBUGFS_PATH=$2
Paul Duffine17c3162022-12-12 17:37:20 +000027BLKID_PATH=$3
28FSCK_EROFS_PATH=$4
29APEX_FILE=$5
30OUTPUT_DIR=$6
31shift 6
Paul Duffin064b70c2020-11-02 17:32:38 +000032REQUIRED_PATHS=$@
33
Paul Duffin064b70c2020-11-02 17:32:38 +000034rm -fr $OUTPUT_DIR
35mkdir -p $OUTPUT_DIR
36
37# Unpack the apex file contents.
Paul Duffine17c3162022-12-12 17:37:20 +000038$DEAPEXER_PATH --debugfs_path $DEBUGFS_PATH \
39 --blkid_path $BLKID_PATH \
40 --fsckerofs_path $FSCK_EROFS_PATH \
41 extract $APEX_FILE $OUTPUT_DIR
Paul Duffin064b70c2020-11-02 17:32:38 +000042
43# Verify that the files that the build expects to be in the .apex file actually
44# exist, and make sure they have a fresh mtime to not confuse ninja.
45typeset -i FAILED=0
46for r in $REQUIRED_PATHS; do
47 if [ ! -f $r ]; then
48 echo "Required file $r not present in apex $APEX_FILE" >&2
49 FAILED=$FAILED+1
50 else
51 # TODO(http:/b/177646343) - deapexer extracts the files with a timestamp of 1 Jan 1970.
52 # touch the file so that ninja knows it has changed.
53 touch $r
54 fi
55done
56
57if [ $FAILED -gt 0 ]; then
58 echo "$FAILED required files were missing from $APEX_FILE" >&2
59 echo "Available files are:" >&2
60 find $OUTPUT_DIR -type f | sed "s|^| |" >&2
61 exit 1
62fi