]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Plugin/LinuxGcc5ToolChain/LinuxGcc5ToolChain.py
BaseTools: Enable RISC-V architecture for RISC-V EDK2 CI.
[mirror_edk2.git] / BaseTools / Plugin / LinuxGcc5ToolChain / LinuxGcc5ToolChain.py
1 # @file LinuxGcc5ToolChain.py
2 # Plugin to configures paths for GCC5 ARM/AARCH64 Toolchain
3 ##
4 # This plugin works in conjuncture with the tools_def
5 #
6 # Copyright (c) Microsoft Corporation
7 # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
8 # SPDX-License-Identifier: BSD-2-Clause-Patent
9 ##
10 import os
11 import logging
12 from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin
13 from edk2toolext.environment import shell_environment
14
15
16 class LinuxGcc5ToolChain(IUefiBuildPlugin):
17
18 def do_post_build(self, thebuilder):
19 return 0
20
21 def do_pre_build(self, thebuilder):
22 self.Logger = logging.getLogger("LinuxGcc5ToolChain")
23
24 #
25 # GCC5 - The ARM and AARCH64 compilers need their paths set if available
26 if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "GCC5":
27
28 # Start with AARACH64 compiler
29 ret = self._check_aarch64()
30 if ret != 0:
31 self.Logger.critical("Failed in check aarch64")
32 return ret
33
34 # Check arm compiler
35 ret = self._check_arm()
36 if ret != 0:
37 self.Logger.critical("Failed in check arm")
38 return ret
39
40 # Check RISCV64 compiler
41 ret = self._check_riscv64()
42 if ret != 0:
43 self.Logger.critical("Failed in check riscv64")
44 return ret
45
46 return 0
47
48 def _check_arm(self):
49 # check to see if full path already configured
50 if shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") is not None:
51 self.Logger.info("GCC5_ARM_PREFIX is already set.")
52
53 else:
54 # now check for install dir. If set then set the Prefix
55 install_path = shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_INSTALL")
56 if install_path is None:
57 return 0
58
59 # make GCC5_ARM_PREFIX to align with tools_def.txt
60 prefix = os.path.join(install_path, "bin", "arm-linux-gnueabihf-")
61 shell_environment.GetEnvironment().set_shell_var("GCC5_ARM_PREFIX", prefix)
62
63 # now confirm it exists
64 if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_PREFIX") + "gcc"):
65 self.Logger.error("Path for GCC5_ARM_PREFIX toolchain is invalid")
66 return -2
67
68 return 0
69
70 def _check_aarch64(self):
71 # check to see if full path already configured
72 if shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") is not None:
73 self.Logger.info("GCC5_AARCH64_PREFIX is already set.")
74
75 else:
76 # now check for install dir. If set then set the Prefix
77 install_path = shell_environment.GetEnvironment(
78 ).get_shell_var("GCC5_AARCH64_INSTALL")
79 if install_path is None:
80 return 0
81
82 # make GCC5_AARCH64_PREFIX to align with tools_def.txt
83 prefix = os.path.join(install_path, "bin", "aarch64-linux-gnu-")
84 shell_environment.GetEnvironment().set_shell_var("GCC5_AARCH64_PREFIX", prefix)
85
86 # now confirm it exists
87 if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") + "gcc"):
88 self.Logger.error(
89 "Path for GCC5_AARCH64_PREFIX toolchain is invalid")
90 return -2
91
92 return 0
93
94 def _check_riscv64(self):
95 # now check for install dir.  If set then set the Prefix
96 install_path = shell_environment.GetEnvironment(
97 ).get_shell_var("GCC5_RISCV64_INSTALL")
98 if install_path is None:
99 return 0
100
101 # check to see if full path already configured
102 if shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") is not None:
103 self.Logger.info("GCC5_RISCV64_PREFIX is already set.")
104
105 else:
106 # make GCC5_RISCV64_PREFIX to align with tools_def.txt
107 prefix = os.path.join(install_path, "bin", "riscv64-unknown-elf-")
108 shell_environment.GetEnvironment().set_shell_var("GCC5_RISCV64_PREFIX", prefix)
109
110 # now confirm it exists
111 if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_RISCV64_PREFIX") + "gcc"):
112 self.Logger.error(
113 "Path for GCC5_RISCV64_PREFIX toolchain is invalid")
114 return -2
115
116 # Check if LD_LIBRARY_PATH is set for the libraries of RISC-V GCC toolchain
117 if shell_environment.GetEnvironment().get_shell_var("LD_LIBRARY_PATH") is not None:
118 self.Logger.info("LD_LIBRARY_PATH is already set.")
119
120 prefix = os.path.join(install_path, "lib")
121 shell_environment.GetEnvironment().set_shell_var("LD_LIBRARY_PATH", prefix)
122
123 return 0