Cleanup SBOM test script for later adding tests of generating SBOM of
unbundled APKs/APEXs. Bug: 266726655 Test: build/soong/tests/sbom_test.sh (cherry picked from https://android-review.googlesource.com/q/commit:cd9948f66e9686e83cbe86d2b8ee998564caff0f) Merged-In: I2bb3e8405dad716837d3004d4c6fd54ae80527c1 Change-Id: I2bb3e8405dad716837d3004d4c6fd54ae80527c1
This commit is contained in:
committed by
Cherrypicker Worker
parent
92275ff913
commit
1b2badc435
@@ -23,49 +23,71 @@ if [ ! -e "build/make/core/Makefile" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function setup {
|
||||||
tmp_dir="$(mktemp -d tmp.XXXXXX)"
|
tmp_dir="$(mktemp -d tmp.XXXXXX)"
|
||||||
|
trap 'cleanup "${tmp_dir}"' EXIT
|
||||||
|
echo "${tmp_dir}"
|
||||||
|
}
|
||||||
|
|
||||||
function cleanup {
|
function cleanup {
|
||||||
|
tmp_dir="$1"; shift
|
||||||
rm -rf "${tmp_dir}"
|
rm -rf "${tmp_dir}"
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
out_dir=$tmp_dir
|
|
||||||
droid_target=droid
|
|
||||||
|
|
||||||
debug=false
|
|
||||||
if [ $debug = "true" ]; then
|
|
||||||
out_dir=out
|
|
||||||
droid_target=
|
|
||||||
fi
|
|
||||||
|
|
||||||
function run_soong {
|
function run_soong {
|
||||||
TARGET_PRODUCT="aosp_cf_x86_64_phone" TARGET_BUILD_VARIANT=userdebug OUT_DIR=$out_dir \
|
target_product="$1";shift
|
||||||
build/soong/soong_ui.bash --make-mode "$@"
|
out_dir="$1"; shift
|
||||||
|
targets="$1"; shift
|
||||||
|
if [ "$#" -ge 1 ]; then
|
||||||
|
apps=$1; shift
|
||||||
|
TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" TARGET_BUILD_UNBUNDLED=true TARGET_BUILD_APPS=$apps build/soong/soong_ui.bash --make-mode ${targets}
|
||||||
|
else
|
||||||
|
TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" build/soong/soong_ui.bash --make-mode ${targets}
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function diff_files {
|
||||||
|
file_list_file="$1"; shift
|
||||||
|
files_in_spdx_file="$1"; shift
|
||||||
|
partition_name="$1"; shift
|
||||||
|
exclude=
|
||||||
|
if [ -v 'diff_excludes[$partition_name]' ]; then
|
||||||
|
exclude=${diff_excludes[$partition_name]}
|
||||||
|
fi
|
||||||
|
|
||||||
|
diff "$file_list_file" "$files_in_spdx_file" $exclude
|
||||||
|
if [ $? != "0" ]; then
|
||||||
|
echo Found diffs in $f and SBOM.
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo No diffs.
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_sbom_aosp_cf_x86_64_phone {
|
||||||
|
# Setup
|
||||||
|
out_dir="$(setup)"
|
||||||
|
|
||||||
|
# Test
|
||||||
# m droid, build sbom later in case additional dependencies might be built and included in partition images.
|
# m droid, build sbom later in case additional dependencies might be built and included in partition images.
|
||||||
run_soong $droid_target dump.erofs lz4
|
run_soong "aosp_cf_x86_64_phone" "${out_dir}" "droid dump.erofs lz4"
|
||||||
|
|
||||||
product_out=$out_dir/target/product/vsoc_x86_64
|
product_out=$out_dir/target/product/vsoc_x86_64
|
||||||
sbom_test=$product_out/sbom_test
|
sbom_test=$product_out/sbom_test
|
||||||
mkdir $sbom_test
|
mkdir -p $sbom_test
|
||||||
cp $product_out/*.img $sbom_test
|
cp $product_out/*.img $sbom_test
|
||||||
|
|
||||||
# m sbom
|
# m sbom
|
||||||
run_soong sbom
|
run_soong "aosp_cf_x86_64_phone" "${out_dir}" sbom
|
||||||
|
|
||||||
# Generate installed file list from .img files in PRODUCT_OUT
|
# Generate installed file list from .img files in PRODUCT_OUT
|
||||||
dump_erofs=$out_dir/host/linux-x86/bin/dump.erofs
|
dump_erofs=$out_dir/host/linux-x86/bin/dump.erofs
|
||||||
lz4=$out_dir/host/linux-x86/bin/lz4
|
lz4=$out_dir/host/linux-x86/bin/lz4
|
||||||
|
|
||||||
declare -A diff_excludes
|
declare -A diff_excludes
|
||||||
diff_excludes[odm]="-I /odm/lib/modules"
|
diff_excludes[vendor]="-I /vendor/lib64/libkeystore2_crypto.so"
|
||||||
diff_excludes[vendor]=\
|
diff_excludes[system]="\
|
||||||
"-I /vendor/lib64/libkeystore2_crypto.so \
|
-I /bin \
|
||||||
-I /vendor/lib/modules \
|
|
||||||
-I /vendor/odm"
|
|
||||||
diff_excludes[system]=\
|
|
||||||
"-I /bin \
|
|
||||||
-I /bugreports \
|
-I /bugreports \
|
||||||
-I /cache \
|
-I /cache \
|
||||||
-I /d \
|
-I /d \
|
||||||
@@ -105,24 +127,6 @@ diff_excludes[system]=\
|
|||||||
-I /system/usr/icu \
|
-I /system/usr/icu \
|
||||||
-I /vendor_dlkm/etc"
|
-I /vendor_dlkm/etc"
|
||||||
|
|
||||||
function diff_files {
|
|
||||||
file_list_file="$1"; shift
|
|
||||||
files_in_spdx_file="$1"; shift
|
|
||||||
partition_name="$1"; shift
|
|
||||||
exclude=
|
|
||||||
if [ -v 'diff_excludes[$partition_name]' ]; then
|
|
||||||
exclude=${diff_excludes[$partition_name]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
diff "$file_list_file" "$files_in_spdx_file" $exclude
|
|
||||||
if [ $? != "0" ]; then
|
|
||||||
echo Found diffs in $f and SBOM.
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo No diffs.
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Example output of dump.erofs is as below, and the data used in the test start
|
# Example output of dump.erofs is as below, and the data used in the test start
|
||||||
# at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name.
|
# at line 11. Column 1 is inode id, column 2 is inode type and column 3 is name.
|
||||||
# Each line is captured in variable "entry", awk is used to get type and name.
|
# Each line is captured in variable "entry", awk is used to get type and name.
|
||||||
@@ -159,7 +163,7 @@ for f in $EROFS_IMAGES; do
|
|||||||
partition_name=$(basename $f | cut -d. -f1)
|
partition_name=$(basename $f | cut -d. -f1)
|
||||||
file_list_file="${sbom_test}/sbom-${partition_name}-files.txt"
|
file_list_file="${sbom_test}/sbom-${partition_name}-files.txt"
|
||||||
files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt"
|
files_in_spdx_file="${sbom_test}/sbom-${partition_name}-files-in-spdx.txt"
|
||||||
rm "$file_list_file" > /dev/null 2>&1
|
rm "$file_list_file" > /dev/null 2>&1 || true
|
||||||
all_dirs="/"
|
all_dirs="/"
|
||||||
while [ ! -z "$all_dirs" ]; do
|
while [ ! -z "$all_dirs" ]; do
|
||||||
dir=$(echo "$all_dirs" | cut -d ' ' -f1)
|
dir=$(echo "$all_dirs" | cut -d ' ' -f1)
|
||||||
@@ -214,3 +218,9 @@ for f in $RAMDISK_IMAGES; do
|
|||||||
echo ============ Diffing files in $f and SBOM
|
echo ============ Diffing files in $f and SBOM
|
||||||
diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name"
|
diff_files "$file_list_file" "$files_in_spdx_file" "$partition_name"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Teardown
|
||||||
|
cleanup "${out_dir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_sbom_aosp_cf_x86_64_phone
|
Reference in New Issue
Block a user