xref: /openbmc/qemu/tests/uefi-test-tools/build.sh (revision 49d755d0)
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# Work around <https://bugzilla.tianocore.org/show_bug.cgi?id=1607>.
33export PYTHON_COMMAND=python2
34
35# Source "edksetup.sh" carefully.
36set +e +u +C
37source "$PACKAGES_PATH/edksetup.sh"
38ret=$?
39set -e -u -C
40if [ $ret -ne 0 ]; then
41  exit $ret
42fi
43
44# Fetch some option arguments, and set the cross-compilation environment (if
45# any), for the edk2 "build" utility.
46source "$edk2_dir/../edk2-funcs.sh"
47edk2_arch=$(qemu_edk2_get_arch "$emulation_target")
48edk2_toolchain=$(qemu_edk2_get_toolchain "$emulation_target")
49qemu_edk2_set_cross_env "$emulation_target"
50
51# Build the UEFI binary
52mkdir -p log
53build \
54  --arch="$edk2_arch" \
55  --buildtarget=DEBUG \
56  --platform=UefiTestToolsPkg/UefiTestToolsPkg.dsc \
57  --tagname="$edk2_toolchain" \
58  --module="UefiTestToolsPkg/$dsc_component/$dsc_component.inf" \
59  --log="log/$dsc_component.$edk2_arch.log" \
60  --report-file="log/$dsc_component.$edk2_arch.report"
61cp -a -- \
62  "Build/UefiTestTools/DEBUG_${edk2_toolchain}/$edk2_arch/$dsc_component.efi" \
63  "$uefi_binary"
64