xref: /openbmc/qemu/tests/uefi-test-tools/build.sh (revision 65a109ab)
1#!/bin/bash
2
3# Build script that determines the edk2 toolchain to use, invokes the edk2
4# "build" utility, and copies the built UEFI binary to the requested location.
5#
6# Copyright (C) 2019, Red Hat, Inc.
7#
8# This program and the accompanying materials are licensed and made available
9# under the terms and conditions of the BSD License that accompanies this
10# distribution. The full text of the license may be found at
11# <http://opensource.org/licenses/bsd-license.php>.
12#
13# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16set -e -u -C
17
18# Save the command line arguments. We need to reset $# to 0 before sourcing
19# "edksetup.sh", as it will inherit $@.
20program_name=$(basename -- "$0")
21edk2_dir=$1
22dsc_component=$2
23emulation_target=$3
24uefi_binary=$4
25shift 4
26
27# Set up the environment for edk2 building.
28export PACKAGES_PATH=$(realpath -- "$edk2_dir")
29export WORKSPACE=$PWD
30mkdir -p Conf
31
32# Source "edksetup.sh" carefully.
33set +e +u +C
34source "$PACKAGES_PATH/edksetup.sh"
35ret=$?
36set -e -u -C
37if [ $ret -ne 0 ]; then
38  exit $ret
39fi
40
41# Fetch some option arguments, and set the cross-compilation environment (if
42# any), for the edk2 "build" utility.
43source "$edk2_dir/../edk2-funcs.sh"
44edk2_arch=$(qemu_edk2_get_arch "$emulation_target")
45edk2_toolchain=$(qemu_edk2_get_toolchain "$emulation_target")
46qemu_edk2_set_cross_env "$emulation_target"
47
48# Build the UEFI binary
49mkdir -p log
50build \
51  --arch="$edk2_arch" \
52  --buildtarget=DEBUG \
53  --platform=UefiTestToolsPkg/UefiTestToolsPkg.dsc \
54  --tagname="$edk2_toolchain" \
55  --module="UefiTestToolsPkg/$dsc_component/$dsc_component.inf" \
56  --log="log/$dsc_component.$edk2_arch.log" \
57  --report-file="log/$dsc_component.$edk2_arch.report"
58cp -a -- \
59  "Build/UefiTestTools/DEBUG_${edk2_toolchain}/$edk2_arch/$dsc_component.efi" \
60  "$uefi_binary"
61