summaryrefslogtreecommitdiffstats
path: root/BaseTools/Plugin/LinuxGcc5ToolChain/LinuxGcc5ToolChain.py
blob: c31641e9314268a70f8a739a5ad7275c2bfe1bc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# @file LinuxGcc5ToolChain.py
# Plugin to configures paths for GCC5 ARM/AARCH64 Toolchain
##
# This plugin works in conjuncture with the tools_def
#
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
import os
import logging
from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin
from edk2toolext.environment import shell_environment


class LinuxGcc5ToolChain(IUefiBuildPlugin):

    def do_post_build(self, thebuilder):
        return 0

    def do_pre_build(self, thebuilder):
        self.Logger = logging.getLogger("LinuxGcc5ToolChain")

        #
        # GCC5 - The ARM and AARCH64 compilers need their paths set if available
        if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "GCC5":

            # Start with AARACH64 compiler
            ret = self._check_aarch64()
            if ret != 0:
                self.Logger.critical("Failed in check aarch64")
                return ret

            # Check arm compiler
            ret = self._check_arm()
            if ret != 0:
                self.Logger.critical("Failed in check arm")
                return ret

        return 0

    def _check_arm(self):
        # 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.")

        else:
            # now check for install dir.  If set then set the Prefix
            install_path = shell_environment.GetEnvironment().get_shell_var("GCC5_ARM_INSTALL")
            if install_path is None:
                return 0

            # make GCC5_ARM_PREFIX to align with tools_def.txt
            prefix = os.path.join(install_path, "bin", "arm-linux-gnueabihf-")
            shell_environment.GetEnvironment().set_shell_var("GCC5_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")
            return -2

        return 0

    def _check_aarch64(self):
        # 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.")

        else:
            # now check for install dir.  If set then set the Prefix
            install_path = shell_environment.GetEnvironment(
            ).get_shell_var("GCC5_AARCH64_INSTALL")
            if install_path is None:
                return 0

            # make GCC5_AARCH64_PREFIX to align with tools_def.txt
            prefix = os.path.join(install_path, "bin", "aarch64-linux-gnu-")
            shell_environment.GetEnvironment().set_shell_var("GCC5_AARCH64_PREFIX", prefix)

        # now confirm it exists
        if not os.path.exists(shell_environment.GetEnvironment().get_shell_var("GCC5_AARCH64_PREFIX") + "gcc"):
            self.Logger.error(
                "Path for GCC5_AARCH64_PREFIX toolchain is invalid")
            return -2

        return 0