BaseTools: LinuxGcc5ToolChain: Run for GCC Toolchain

The GCC5 TOOL_CHAIN_TAG is being deprecated in favor of
GCC. LinuxGcc5ToolChain.py needs to be updated to find
the correct ARM/AARCH64/RISCV/LOONGARCH64 compilers for
the GCC TOOL_CHAIN_TAG, as well, otherwise it defaults
to the system GCC, which is typically X64 based.

In order to keep this backward and forward compatible,
the plugin now checks for the substring "GCC" in the
TOOL_CHAIN_TAG and will set either the "GCC5" or "GCC"
env variables used by tools_def.template to find the
GCC compiler for the requested architecture.

This plugin is also renamed to drop the old GCC5.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
This commit is contained in:
Oliver Smith-Denny 2024-09-19 11:33:55 -07:00 committed by mergify[bot]
parent 10783187dd
commit 21e1fc5400
3 changed files with 66 additions and 55 deletions

View File

@ -1,12 +0,0 @@
## @file
# Build Plugin used to set the path
# for the GCC5 ARM/AARCH64 downloaded compilers
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
{
"scope": "global-nix",
"name": "Linux GCC5 Tool Chain Support",
"module": "LinuxGcc5ToolChain"
}

View File

@ -1,7 +1,8 @@
# @file LinuxGcc5ToolChain.py
# Plugin to configures paths for GCC5 ARM/AARCH64 Toolchain
# @file LinuxGccToolChain.py
# Plugin to configures paths for GCC/GCC5 ARM/AARCH64/RISCV/LOONGARCH64 Toolchain
##
# This plugin works in conjuncture with the tools_def
# This plugin sets environment variables used in tools_def.template to specify the GCC compiler
# for the requested build architecture.
#
# Copyright (c) Microsoft Corporation
# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
@ -14,110 +15,120 @@ from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlug
from edk2toolext.environment import shell_environment
class LinuxGcc5ToolChain(IUefiBuildPlugin):
class LinuxGccToolChain(IUefiBuildPlugin):
def do_post_build(self, thebuilder):
return 0
def do_pre_build(self, thebuilder):
self.Logger = logging.getLogger("LinuxGcc5ToolChain")
self.Logger = logging.getLogger("LinuxGccToolChain")
#
# GCC5 - The ARM and AARCH64 compilers need their paths set if available
if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "GCC5":
# In order to keep this plugin backwards compatible with the older GCC5 toolchain tag,
# we support setting either the GCC5 or GCC set of env variables required
#
toolchain = "GCC"
#
# GCC - The non-x86 compilers need their paths set if available. To make this more stable, check for
# any substring of GCC in the TOOL_CHAIN_TAG to get the right compiler
#
if "GCC" in thebuilder.env.GetValue("TOOL_CHAIN_TAG"):
if "GCC5" in thebuilder.env.GetValue("TOOL_CHAIN_TAG"):
toolchain = "GCC5"
# Start with AARACH64 compiler
ret = self._check_aarch64()
ret = self._check_aarch64(toolchain)
if ret != 0:
self.Logger.critical("Failed in check aarch64")
return ret
# Check arm compiler
ret = self._check_arm()
ret = self._check_arm(toolchain)
if ret != 0:
self.Logger.critical("Failed in check arm")
return ret
# Check RISCV64 compiler
ret = self._check_riscv64()
ret = self._check_riscv64(toolchain)
if ret != 0:
self.Logger.critical("Failed in check riscv64")
return ret
# Check LoongArch64 compiler
ret = self._check_loongarch64()
ret = self._check_loongarch64(toolchain)
if ret != 0:
self.Logger.critical("Failed in check loongarch64")
return ret
return 0
def _check_arm(self):
def _check_arm(self, toolchain):
# check to see if full path already configured
if shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") is not None:
self.Logger.info("GCC5_ARM_PREFIX is already set.")
if shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_PREFIX") is not None:
self.Logger.info(toolchain + "_ARM_PREFIX is already set.")
else:
# now check for install dir. If set then set the Prefix
install_path = shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_INSTALL")
install_path = shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_INSTALL")
if install_path is None:
return 0
# make GCC5_ARM_PREFIX to align with tools_def.txt
# make the PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "arm-none-linux-gnueabihf-")
shell_environment.GetEnvironment().set_shell_var("GCC5_ARM_PREFIX", prefix)
shell_environment.GetEnvironment().set_shell_var(toolchain + "_ARM_PREFIX", prefix)
# now confirm it exists
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") + "gcc"):
self.Logger.error("Path for GCC5_ARM_PREFIX toolchain is invalid")
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_PREFIX") + "gcc"):
self.Logger.error("Path for " + toolchain + "_ARM_PREFIX toolchain is invalid")
return -2
return 0
def _check_aarch64(self):
def _check_aarch64(self, toolchain):
# check to see if full path already configured
if shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") is not None:
self.Logger.info("GCC5_AARCH64_PREFIX is already set.")
if shell_environment.GetEnvironment().get_shell_var(toolchain + "_AARCH64_PREFIX") is not None:
self.Logger.info(toolchain + "_AARCH64_PREFIX is already set.")
else:
# now check for install dir. If set then set the Prefix
install_path = shell_environment.GetEnvironment(
).get_shell_var("GCC5_AARCH64_INSTALL")
).get_shell_var(toolchain + "_AARCH64_INSTALL")
if install_path is None:
return 0
# make GCC5_AARCH64_PREFIX to align with tools_def.txt
# make PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "aarch64-none-linux-gnu-")
shell_environment.GetEnvironment().set_shell_var("GCC5_AARCH64_PREFIX", prefix)
shell_environment.GetEnvironment().set_shell_var(toolchain + "_AARCH64_PREFIX", prefix)
# now confirm it exists
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") + "gcc"):
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_AARCH64_PREFIX") + "gcc"):
self.Logger.error(
"Path for GCC5_AARCH64_PREFIX toolchain is invalid")
"Path for " + toolchain + "_AARCH64_PREFIX toolchain is invalid")
return -2
return 0
def _check_riscv64(self):
def _check_riscv64(self, toolchain):
# now check for install dir. If set then set the Prefix
install_path = shell_environment.GetEnvironment(
).get_shell_var("GCC5_RISCV64_INSTALL")
).get_shell_var(toolchain + "_RISCV64_INSTALL")
if install_path is None:
return 0
# check to see if full path already configured
if shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") is not None:
self.Logger.info("GCC5_RISCV64_PREFIX is already set.")
if shell_environment.GetEnvironment().get_shell_var(toolchain + "_RISCV64_PREFIX") is not None:
self.Logger.info(toolchain + "_RISCV64_PREFIX is already set.")
else:
# make GCC5_RISCV64_PREFIX to align with tools_def.txt
# make PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "riscv64-unknown-elf-")
shell_environment.GetEnvironment().set_shell_var("GCC5_RISCV64_PREFIX", prefix)
shell_environment.GetEnvironment().set_shell_var(toolchain + "_RISCV64_PREFIX", prefix)
# now confirm it exists
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") + "gcc"):
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_RISCV64_PREFIX") + "gcc"):
self.Logger.error(
"Path for GCC5_RISCV64_PREFIX toolchain is invalid")
"Path for " + toolchain + "_RISCV64_PREFIX toolchain is invalid")
return -2
# Check if LD_LIBRARY_PATH is set for the libraries of RISC-V GCC toolchain
@ -129,26 +140,26 @@ class LinuxGcc5ToolChain(IUefiBuildPlugin):
return 0
def _check_loongarch64(self):
def _check_loongarch64(self, toolchain):
# check to see if full path already configured
if shell_environment.GetEnvironment().get_shell_var("GCC5_LOONGARCH64_PREFIX") is not None:
self.Logger.info("GCC5_LOONGARCH64_PREFIX is already set.")
if shell_environment.GetEnvironment().get_shell_var(toolchain + "_LOONGARCH64_PREFIX") is not None:
self.Logger.info(toolchain + "_LOONGARCH64_PREFIX is already set.")
else:
# now check for install dir. If set then set the Prefix
install_path = shell_environment.GetEnvironment(
).get_shell_var("GCC5_LOONGARCH64_INSTALL")
).get_shell_var(toolchain + "_LOONGARCH64_INSTALL")
if install_path is None:
return 0
# make GCC5_LOONGARCH64_PREFIX to align with tools_def.txt
# make PREFIX to align with tools_def.txt
prefix = os.path.join(install_path, "bin", "loongarch64-unknown-linux-gnu-")
shell_environment.GetEnvironment().set_shell_var("GCC5_LOONGARCH64_PREFIX", prefix)
shell_environment.GetEnvironment().set_shell_var(toolchain + "_LOONGARCH64_PREFIX", prefix)
# now confirm it exists
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_LOONGARCH64_PREFIX") + "gcc"):
if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_LOONGARCH64_PREFIX") + "gcc"):
self.Logger.error(
"Path for GCC5_LOONGARCH64_PREFIX toolchain is invalid")
"Path for " + toolchain + "_LOONGARCH64_PREFIX toolchain is invalid")
return -2
return 0

View File

@ -0,0 +1,12 @@
## @file
# This plugin sets environment variables used in tools_def.template to specify the GCC compiler
# for the requested build architecture.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
{
"scope": "global-nix",
"name": "Linux GCC Tool Chain Support",
"module": "LinuxGccToolChain"
}