1 | # @file LinuxGccToolChain.py
|
---|
2 | # Plugin to configures paths for GCC/GCC5 ARM/AARCH64/RISCV/LOONGARCH64 Toolchain
|
---|
3 | ##
|
---|
4 | # This plugin sets environment variables used in tools_def.template to specify the GCC compiler
|
---|
5 | # for the requested build architecture.
|
---|
6 | #
|
---|
7 | # Copyright (c) Microsoft Corporation
|
---|
8 | # Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
|
---|
9 | # Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>
|
---|
10 | # SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 | ##
|
---|
12 | import os
|
---|
13 | import logging
|
---|
14 | from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin
|
---|
15 | from edk2toolext.environment import shell_environment
|
---|
16 |
|
---|
17 |
|
---|
18 | class LinuxGccToolChain(IUefiBuildPlugin):
|
---|
19 |
|
---|
20 | def do_post_build(self, thebuilder):
|
---|
21 | return 0
|
---|
22 |
|
---|
23 | def do_pre_build(self, thebuilder):
|
---|
24 | self.Logger = logging.getLogger("LinuxGccToolChain")
|
---|
25 |
|
---|
26 | #
|
---|
27 | # In order to keep this plugin backwards compatible with the older GCC5 toolchain tag,
|
---|
28 | # we support setting either the GCC5 or GCC set of env variables required
|
---|
29 | #
|
---|
30 | toolchain = "GCC"
|
---|
31 |
|
---|
32 | #
|
---|
33 | # GCC - The non-x86 compilers need their paths set if available. To make this more stable, check for
|
---|
34 | # any substring of GCC in the TOOL_CHAIN_TAG to get the right compiler
|
---|
35 | #
|
---|
36 | if "GCC" in thebuilder.env.GetValue("TOOL_CHAIN_TAG"):
|
---|
37 | if "GCC5" in thebuilder.env.GetValue("TOOL_CHAIN_TAG"):
|
---|
38 | toolchain = "GCC5"
|
---|
39 |
|
---|
40 | # Start with AARACH64 compiler
|
---|
41 | ret = self._check_aarch64(toolchain)
|
---|
42 | if ret != 0:
|
---|
43 | self.Logger.critical("Failed in check aarch64")
|
---|
44 | return ret
|
---|
45 |
|
---|
46 | # Check arm compiler
|
---|
47 | ret = self._check_arm(toolchain)
|
---|
48 | if ret != 0:
|
---|
49 | self.Logger.critical("Failed in check arm")
|
---|
50 | return ret
|
---|
51 |
|
---|
52 | # Check RISCV64 compiler
|
---|
53 | ret = self._check_riscv64(toolchain)
|
---|
54 | if ret != 0:
|
---|
55 | self.Logger.critical("Failed in check riscv64")
|
---|
56 | return ret
|
---|
57 |
|
---|
58 | # Check LoongArch64 compiler
|
---|
59 | ret = self._check_loongarch64(toolchain)
|
---|
60 | if ret != 0:
|
---|
61 | self.Logger.critical("Failed in check loongarch64")
|
---|
62 | return ret
|
---|
63 |
|
---|
64 | return 0
|
---|
65 |
|
---|
66 | def _check_arm(self, toolchain):
|
---|
67 | # check to see if full path already configured
|
---|
68 | if shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_PREFIX") is not None:
|
---|
69 | self.Logger.info(toolchain + "_ARM_PREFIX is already set.")
|
---|
70 |
|
---|
71 | else:
|
---|
72 | # now check for install dir. If set then set the Prefix
|
---|
73 | install_path = shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_INSTALL")
|
---|
74 | if install_path is None:
|
---|
75 | return 0
|
---|
76 |
|
---|
77 | # make the PREFIX to align with tools_def.txt
|
---|
78 | prefix = os.path.join(install_path, "bin", "arm-none-linux-gnueabihf-")
|
---|
79 | shell_environment.GetEnvironment().set_shell_var(toolchain + "_ARM_PREFIX", prefix)
|
---|
80 |
|
---|
81 | # now confirm it exists
|
---|
82 | if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_ARM_PREFIX") + "gcc"):
|
---|
83 | self.Logger.error("Path for " + toolchain + "_ARM_PREFIX toolchain is invalid")
|
---|
84 | return -2
|
---|
85 |
|
---|
86 | return 0
|
---|
87 |
|
---|
88 | def _check_aarch64(self, toolchain):
|
---|
89 | # check to see if full path already configured
|
---|
90 | if shell_environment.GetEnvironment().get_shell_var(toolchain + "_AARCH64_PREFIX") is not None:
|
---|
91 | self.Logger.info(toolchain + "_AARCH64_PREFIX is already set.")
|
---|
92 |
|
---|
93 | else:
|
---|
94 | # now check for install dir. If set then set the Prefix
|
---|
95 | install_path = shell_environment.GetEnvironment(
|
---|
96 | ).get_shell_var(toolchain + "_AARCH64_INSTALL")
|
---|
97 | if install_path is None:
|
---|
98 | return 0
|
---|
99 |
|
---|
100 | # make PREFIX to align with tools_def.txt
|
---|
101 | prefix = os.path.join(install_path, "bin", "aarch64-none-linux-gnu-")
|
---|
102 | shell_environment.GetEnvironment().set_shell_var(toolchain + "_AARCH64_PREFIX", prefix)
|
---|
103 |
|
---|
104 | # now confirm it exists
|
---|
105 | if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_AARCH64_PREFIX") + "gcc"):
|
---|
106 | self.Logger.error(
|
---|
107 | "Path for " + toolchain + "_AARCH64_PREFIX toolchain is invalid")
|
---|
108 | return -2
|
---|
109 |
|
---|
110 | return 0
|
---|
111 |
|
---|
112 | def _check_riscv64(self, toolchain):
|
---|
113 | # now check for install dir. If set then set the Prefix
|
---|
114 | install_path = shell_environment.GetEnvironment(
|
---|
115 | ).get_shell_var(toolchain + "_RISCV64_INSTALL")
|
---|
116 | if install_path is None:
|
---|
117 | return 0
|
---|
118 |
|
---|
119 | # check to see if full path already configured
|
---|
120 | if shell_environment.GetEnvironment().get_shell_var(toolchain + "_RISCV64_PREFIX") is not None:
|
---|
121 | self.Logger.info(toolchain + "_RISCV64_PREFIX is already set.")
|
---|
122 |
|
---|
123 | else:
|
---|
124 | # make PREFIX to align with tools_def.txt
|
---|
125 | prefix = os.path.join(install_path, "bin", "riscv64-unknown-elf-")
|
---|
126 | shell_environment.GetEnvironment().set_shell_var(toolchain + "_RISCV64_PREFIX", prefix)
|
---|
127 |
|
---|
128 | # now confirm it exists
|
---|
129 | if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_RISCV64_PREFIX") + "gcc"):
|
---|
130 | self.Logger.error(
|
---|
131 | "Path for " + toolchain + "_RISCV64_PREFIX toolchain is invalid")
|
---|
132 | return -2
|
---|
133 |
|
---|
134 | # Check if LD_LIBRARY_PATH is set for the libraries of RISC-V GCC toolchain
|
---|
135 | if shell_environment.GetEnvironment().get_shell_var("LD_LIBRARY_PATH") is not None:
|
---|
136 | self.Logger.info("LD_LIBRARY_PATH is already set.")
|
---|
137 |
|
---|
138 | prefix = os.path.join(install_path, "lib")
|
---|
139 | shell_environment.GetEnvironment().set_shell_var("LD_LIBRARY_PATH", prefix)
|
---|
140 |
|
---|
141 | return 0
|
---|
142 |
|
---|
143 | def _check_loongarch64(self, toolchain):
|
---|
144 | # check to see if full path already configured
|
---|
145 | if shell_environment.GetEnvironment().get_shell_var(toolchain + "_LOONGARCH64_PREFIX") is not None:
|
---|
146 | self.Logger.info(toolchain + "_LOONGARCH64_PREFIX is already set.")
|
---|
147 |
|
---|
148 | else:
|
---|
149 | # now check for install dir. If set then set the Prefix
|
---|
150 | install_path = shell_environment.GetEnvironment(
|
---|
151 | ).get_shell_var(toolchain + "_LOONGARCH64_INSTALL")
|
---|
152 | if install_path is None:
|
---|
153 | return 0
|
---|
154 |
|
---|
155 | # make PREFIX to align with tools_def.txt
|
---|
156 | prefix = os.path.join(install_path, "bin", "loongarch64-unknown-linux-gnu-")
|
---|
157 | shell_environment.GetEnvironment().set_shell_var(toolchain + "_LOONGARCH64_PREFIX", prefix)
|
---|
158 |
|
---|
159 | # now confirm it exists
|
---|
160 | if not os.path.exists(shell_environment.GetEnvironment().get_shell_var(toolchain + "_LOONGARCH64_PREFIX") + "gcc"):
|
---|
161 | self.Logger.error(
|
---|
162 | "Path for " + toolchain + "_LOONGARCH64_PREFIX toolchain is invalid")
|
---|
163 | return -2
|
---|
164 |
|
---|
165 | return 0
|
---|