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