Beispiel #1
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-none-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
 def GetVsInstallPath(vsversion, varname):
     # check if already specified
     path = shell_environment.GetEnvironment().get_shell_var(varname)
     if (path is None):
         # Not specified...find latest
         (rc, path) = FindWithVsWhere(vs_version=vsversion)
         if rc == 0 and path is not None:
             self.Logger.debug("Found VS instance for %s", vsversion)
             shell_environment.GetEnvironment().set_shell_var(
                 varname, path)
         else:
             self.Logger.error(
                 "Failed to find VS instance with VsWhere (%d)" % rc)
     return path
    def __init__(self, descriptor):
        super().__init__(descriptor)

        # Check to see whether this URL should be patched.
        url_creds_var = descriptor.get('url_creds_var', None)
        if url_creds_var is not None:
            env = shell_environment.GetEnvironment()
            url_creds = env.get_shell_var(url_creds_var)
            if url_creds is not None:
                # Break things up.
                source_parts = urlsplit(self.source)
                # Modify the URL host with the creds.
                new_parts = (source_parts.scheme,
                             url_creds + '@' + source_parts.netloc,
                             source_parts.path, source_parts.query,
                             source_parts.fragment)
                # Put things back together.
                self.source = urlunsplit(new_parts)

        self.repo_url = self.source
        self.commit = self.version
        self._local_repo_root_path = os.path.join(
            os.path.abspath(self.contents_dir), self.name)
        self.logger = logging.getLogger("git-dependency")

        # valid_attributes = ["Path", "Url", "Branch", "Commit", "ReferencePath", "Full"]
        self._repo_resolver_dep_obj = {
            "Path": self.name,
            "Url": self.repo_url,
            "Commit": self.commit
        }
Beispiel #4
0
def BootstrapEnvironment(workspace, scopes=()):
    global ENVIRONMENT_BOOTSTRAP_COMPLETE, ENV_STATE

    if not ENVIRONMENT_BOOTSTRAP_COMPLETE:
        #
        # ENVIRONMENT BOOTSTRAP STAGE 1
        # Locate and load all environment description files.
        #
        build_env = self_describing_environment(
            workspace, scopes).load_workspace()

        #
        # ENVIRONMENT BOOTSTRAP STAGE 2
        # Parse all of the PATH-related descriptor files to make sure that
        # any required tools or Python modules are now available.
        #
        shell_env = shell_environment.GetEnvironment()
        build_env.update_simple_paths(shell_env)

        #
        # ENVIRONMENT BOOTSTRAP STAGE 3
        # Now that the preliminary paths have been loaded,
        # we can load the modules that had greater dependencies.
        #
        build_env.update_extdep_paths(shell_env)

        # Debug the environment that was produced.
        shell_env.log_environment()

        ENVIRONMENT_BOOTSTRAP_COMPLETE = True
        ENV_STATE = (build_env, shell_env)

    # Return the environment as it's configured.
    return ENV_STATE
Beispiel #5
0
 def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):
     edk2_path = Edk2pathObj.WorkspacePath
     python_path = os.path.join(edk2_path, "BaseTools", "Source", "Python")
     env = shell_environment.GetEnvironment()
     env.set_shell_var('PYTHONPATH', python_path)
     env.set_shell_var('WORKSPACE', edk2_path)
     self.ECC_PASS = True
     self.ApplyConfig(pkgconfig, edk2_path, packagename)
     modify_dir_list = self.GetModifyDir(packagename)
     patch = self.GetDiff(packagename)
     ecc_diff_range = self.GetDiffRange(patch, packagename, edk2_path)
     self.GenerateEccReport(modify_dir_list, ecc_diff_range, edk2_path)
     ecc_log = os.path.join(edk2_path, "Ecc.log")
     self.RevertCode()
     if self.ECC_PASS:
         tc.SetSuccess()
         self.RemoveFile(ecc_log)
         return 0
     else:
         with open(ecc_log, encoding='utf8') as output:
             ecc_output = output.readlines()
             for line in ecc_output:
                 logging.error(line.strip())
         self.RemoveFile(ecc_log)
         tc.SetFailed("EccCheck failed for {0}".format(packagename), "Ecc detected issues")
         return 1
    def do_pre_build(self, thebuilder):
        '''
        Works with the compiler (either the HostBasedCompilerPlugin or an other Builder) to set
        up the environment that will be needed to build host-based unit tests.

        EXPECTS:
        - Build Var 'CI_BUILD_TYPE' - If not set to 'host_unit_test', will not do anything.

        UPDATES:
        - Shell Var (Several) - Updates the shell with all vars listed in interesting_keys.
        - Shell Path - Updated from QueryVcVariables()
        - Shell Var 'CMOCKA_MESSAGE_OUTPUT'
        '''
        ci_type = thebuilder.env.GetValue('CI_BUILD_TYPE')
        if ci_type != 'host_unit_test':
            return 0

        shell_env = shell_environment.GetEnvironment()
        # Use the tools lib to determine the correct values for the vars that interest us.
        interesting_keys = [
            "ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH",
            "UniversalCRTSdkDir", "UCRTVersion", "WindowsLibPath",
            "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
            "WindowsSDKVersion", "VCToolsInstallDir"
        ]
        vs_vars = locate_tools.QueryVcVariables(interesting_keys, "amd64")
        for (k, v) in vs_vars.items():
            if k.upper() == "PATH":
                shell_env.append_path(v)
            else:
                shell_env.set_shell_var(k, v)

        # Set up the reporting type for Cmocka.
        shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')
        return 0
Beispiel #7
0
 def tearDown(self):
     shell_environment.GetEnvironment().restore_initial_checkpoint()
     TestEdk2CiSetup.restart_logging()
     buildFolder = os.path.join(self.minimalTree, "Build")
     shutil.rmtree(buildFolder, ignore_errors=True)
     self_describing_environment.DestroyEnvironment()
     version_aggregator.ResetVersionAggregator()
     pass
Beispiel #8
0
    def Go(self):
        ret = 0
        env = shell_environment.GetBuildVars()
        env.SetValue("PRODUCT_NAME", self.PlatformSettings.GetName(),
                     "Platform Hardcoded")
        env.SetValue("BLD_*_BUILDID_STRING", "201905", "Current Version")
        env.SetValue("BUILDREPORTING", "TRUE", "Platform Hardcoded")
        env.SetValue("BUILDREPORT_TYPES", 'PCD DEPEX LIBRARY BUILD_FLAGS',
                     "Platform Hardcoded")

        # make sure python_command is set
        python_command = sys.executable
        if " " in python_command:
            python_command = '"' + python_command + '"'
        shell_environment.GetEnvironment().set_shell_var(
            "PYTHON_COMMAND", python_command)

        # Run pre build hook
        ret += self.PlatformSettings.PreFirstBuildHook()
        ws = self.GetWorkspaceRoot()
        pp = self.PlatformSettings.GetModulePkgsPath()
        # run each configuration
        ret = 0
        try:
            for config in self.PlatformSettings.GetConfigurations():
                pre_ret = self.PlatformSettings.PreBuildHook(
                )  # run pre build hook
                if pre_ret != 0:
                    ret = pre_ret
                    raise RuntimeError("We failed in prebuild hook")
                edk2_logging.log_progress(f"--Running next configuration--")
                logging.info(config)
                shell_environment.CheckpointBuildVars(
                )  # checkpoint our config
                env = shell_environment.GetBuildVars()
                # go through the config and apply to environement
                for key in config:
                    env.SetValue(key, config[key], "provided by configuration")
                # make sure to set this after in case the config did
                env.SetValue("TOOL_CHAIN_TAG", "VS2017", "provided by builder")
                platformBuilder = UefiBuilder()  # create our builder
                build_ret = platformBuilder.Go(ws, pp, self.helper,
                                               self.plugin_manager)
                # we always want to run the post build hook
                post_ret = self.PlatformSettings.PostBuildHook(ret)
                if build_ret != 0:
                    ret = build_ret
                    raise RuntimeError("We failed in build")
                if post_ret != 0:
                    ret = post_ret
                    raise RuntimeError("We failed in postbuild hook")
                shell_environment.RevertBuildVars()
        except RuntimeError:
            pass
        finally:
            # make sure to do our final build hook
            self.PlatformSettings.PostFinalBuildHook(ret)
        return ret
Beispiel #9
0
 def tearDown(self):
     shell_environment.GetEnvironment().restore_initial_checkpoint()
     buildFolder = os.path.join(self.minimalTree, "Build")
     shutil.rmtree(buildFolder, ignore_errors=True)
     TestEdk2PlatBuild.restart_logging()
     # we need to make sure to tear down the version aggregator and the SDE
     self_describing_environment.DestroyEnvironment()
     version_aggregator.ResetVersionAggregator()
     pass
 def tearDown(self):
     shell_environment.GetEnvironment().restore_initial_checkpoint()
     for temp_folder in TestEdk2Update.temp_folders:
         logging.info(f"Cleaning up {temp_folder}")
         # shutil.rmtree(os.path.abspath(temp_folder), ignore_errors=True)
     TestEdk2Update.restart_logging()
     # we need to make sure to tear down the version aggregator and the SDE
     self_describing_environment.DestroyEnvironment()
     version_aggregator.ResetVersionAggregator()
        def GetVcVersion(path, varname):
            # check if already specified
            vc_ver = shell_environment.GetEnvironment().get_shell_var(varname)
            if (vc_ver is None):
                # Not specified...find latest
                p2 = os.path.join(path, "VC", "Tools", "MSVC")
                if not os.path.isdir(p2):
                    self.Logger.critical(
                        "Failed to find VC tools.  Might need to check for VS install"
                    )
                    return vc_ver
                vc_ver = os.listdir(p2)[-1].strip()  # get last in list
                self.Logger.debug("Found VC Tool version is %s" % vc_ver)
                shell_environment.GetEnvironment().set_shell_var(
                    varname, vc_ver)

            if (vc_ver):
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)
            return vc_ver
Beispiel #12
0
    def _check_riscv64(self):
        # now check for install dir.  If set then set the Prefix
        install_path = shell_environment.GetEnvironment().get_shell_var(
            "GCC5_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.")

        else:
            # make GCC5_RISCV64_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)

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

        # Check if LD_LIBRARY_PATH is set for the libraries of RISC-V GCC toolchain
        if shell_environment.GetEnvironment().get_shell_var(
                "LD_LIBRARY_PATH") is not None:
            self.Logger.info("LD_LIBRARY_PATH is already set.")

        prefix = os.path.join(install_path, "lib")
        shell_environment.GetEnvironment().set_shell_var(
            "LD_LIBRARY_PATH", prefix)

        return 0
 def do_pre_build(self, thebuilder):
     #get the locate tools module
     path = locate_tools.FindToolInWinSdk("rc.exe")
     if path is None:
         thebuilder.logging.warning("Failed to find rc.exe")
     else:
         p = os.path.abspath(os.path.dirname(path))
         shell_environment.GetEnvironment().set_shell_var(
             "WINSDK_PATH_FOR_RC_EXE", p)
         version_aggregator.GetVersionAggregator().ReportVersion(
             "WINSDK_PATH_FOR_RC_EXE", p,
             version_aggregator.VersionTypes.INFO)
     return 0
    def test_url_should_not_be_modified_without_descriptor_field(self):
        my_test_descriptor = copy.copy(
            TestGitDependencyUrlPatching.TEST_DESCRIPTOR)

        env = shell_environment.GetEnvironment()
        # Add the var to the environment.
        env.set_shell_var('test_creds_var', 'my_stuff')

        # Initialize the GitDependency object.
        git_dep = GitDependency(my_test_descriptor)

        # Assert that the URL is identical.
        self.assertEqual(git_dep.source, my_test_descriptor['source'])
    def do_post_build(self, thebuilder):
        ci_type = thebuilder.env.GetValue('CI_BUILD_TYPE')
        if ci_type != 'host_unit_test':
            return 0

        shell_env = shell_environment.GetEnvironment()
        logging.log(edk2_logging.get_section_level(),
                    "Run Host based Unit Tests")
        path = thebuilder.env.GetValue("BUILD_OUTPUT_BASE")
        for arch in thebuilder.env.GetValue("TARGET_ARCH").split():
            logging.log(edk2_logging.get_subsection_level(),
                        "Testing for architecture: " + arch)
            cp = os.path.join(path, arch)

            # If any old results XML files exist, clean them up.
            for old_result in glob.iglob(os.path.join(cp, "*.result.xml")):
                os.remove(old_result)

            # Determine whether any tests exist.
            testList = glob.glob(os.path.join(cp, "*Test*.exe"))
            for test in testList:
                # Configure output name.
                shell_env.set_shell_var('CMOCKA_XML_FILE',
                                        test + ".%g." + arch + ".result.xml")

                # Run the test.
                ret = RunCmd('"' + test + '"', "", workingdir=cp)
                if (ret != 0):
                    logging.error("UnitTest Execution Error: " +
                                  os.path.basename(test))
                else:
                    logging.info("UnitTest Completed: " +
                                 os.path.basename(test))
                    file_match_pattern = test + ".*." + arch + ".result.xml"
                    xml_results_list = glob.glob(file_match_pattern)
                    for xml_result_file in xml_results_list:
                        root = xml.etree.ElementTree.parse(
                            xml_result_file).getroot()
                        for suite in root:
                            for case in suite:
                                for result in case:
                                    if result.tag == 'failure':
                                        logging.warning("%s Test Failed" %
                                                        os.path.basename(test))
                                        logging.warning(
                                            "  %s - %s" %
                                            (case.attrib['name'], result.text))

        return 0
 def _get_vs_install_path(self, vs_version, varname):
     # check if already specified
     path = None
     if varname is not None:
         path = shell_environment.GetEnvironment().get_shell_var(varname)
     
     if(path is None):
         # Not specified...find latest
         (rc, path) = FindWithVsWhere(vs_version=vs_version)
         if rc == 0 and path is not None and os.path.exists(path):
             self.Logger.debug("Found VS instance for %s", vs_version)
         else:
             self.Logger.error(
                 "Failed to find VS instance with VsWhere (%d)" % rc)
     return path
    def test_url_should_be_modified_if_creds_are_indicated_and_supplied(self):
        my_test_descriptor = copy.copy(
            TestGitDependencyUrlPatching.TEST_DESCRIPTOR)
        # Add the indicator for patching.
        my_test_descriptor['url_creds_var'] = 'test_creds_var'

        env = shell_environment.GetEnvironment()
        # Add the var to the environment.
        env.set_shell_var('test_creds_var', 'my_stuff')

        # Initialize the GitDependency object.
        git_dep = GitDependency(my_test_descriptor)

        # Assert that the URL is identical.
        self.assertEqual(
            git_dep.source,
            "https://[email protected]/octocat/Hello-World.git")
 def _get_vc_version(self, path, varname):
     # check if already specified
     vc_ver = shell_environment.GetEnvironment().get_shell_var(varname)
     if (path is None):
         self.Logger.critical(
             "Failed to find Visual Studio tools.  Might need to check for VS install")
         return vc_ver
     if(vc_ver is None):
         # Not specified...find latest
         p2 = os.path.join(path, "VC", "Tools", "MSVC")
         if not os.path.isdir(p2):
             self.Logger.critical(
                 "Failed to find VC tools.  Might need to check for VS install")
             return vc_ver
         vc_ver = os.listdir(p2)[-1].strip()  # get last in list
         self.Logger.debug("Found VC Tool version is %s" % vc_ver)
     return vc_ver
    def do_pre_build(self, thebuilder):
        ci_type = thebuilder.env.GetValue('CI_BUILD_TYPE')
        if ci_type != 'host_unit_test':
            return 0

        shell_env = shell_environment.GetEnvironment()
        # Use the tools lib to determine the correct values for the vars that interest us.
        interesting_keys = [
            "ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH",
            "UniversalCRTSdkDir", "UCRTVersion", "WindowsLibPath",
            "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
            "WindowsSDKVersion", "VCToolsInstallDir"
        ]
        vs_vars = locate_tools.QueryVcVariables(interesting_keys, "amd64")
        for (k, v) in vs_vars.items():
            if k.upper() == "PATH":
                shell_env.append_path(v)
            else:
                shell_env.set_shell_var(k, v)

        # Set up the reporting type for Cmocka.
        shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')
        return 0
Beispiel #20
0
    def do_pre_build(self, thebuilder):
        self.Logger = logging.getLogger("WindowsVsToolChain")
        interesting_keys = [
            "ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH",
            "UniversalCRTSdkDir", "UCRTVersion", "WindowsLibPath",
            "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
            "WindowsSDKVersion", "VCToolsInstallDir", "Path"
        ]

        #
        # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS150TOOLVER:      version number for the VC compiler tools
        # VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2017_PREFIX") != None:
                self.Logger.info("VS2017_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2017".lower(), "VS150INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS150TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2017")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2017_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2017_PREFIX", prefix)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(interesting_keys,
                                                        "amd64",
                                                        vs_version="vs2017")
                for (k, v) in vs_vars.items():
                    if k.upper() == "PATH":
                        shell_env.insert_path(v)
                    else:
                        shell_env.set_shell_var(k, v)

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

        #
        # VS2019 - Follow VS2019 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS160TOOLVER:      version number for the VC compiler tools
        # VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2019_PREFIX") != None:
                self.Logger.info("VS2019_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2019".lower(), "VS160INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS160TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2019")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2019_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2019_PREFIX", prefix)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(interesting_keys,
                                                        "amd64",
                                                        vs_version="vs2019")
                for (k, v) in vs_vars.items():
                    if k.upper() == "PATH":
                        shell_env.insert_path(v)
                    else:
                        shell_env.set_shell_var(k, v)

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

        return 0
    def do_pre_build(self, thebuilder):
        self.Logger = logging.getLogger("WindowsVsToolChain")

        #
        # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        ## VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        ## VS150TOOLVER:      version number for the VC compiler tools
        ## VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2017_PREFIX") != None:
                self.Logger.info("VS2017_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2017".lower(), "VS150INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS150TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2017")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                #make VS2017_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2017_PREFIX", prefix)

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

        #
        # VS2019 - Follow VS2019 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        ## VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        ## VS160TOOLVER:      version number for the VC compiler tools
        ## VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2019_PREFIX") != None:
                self.Logger.info("VS2019_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2019".lower(), "VS160INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS160TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2019")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                #make VS2019_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2019_PREFIX", prefix)

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

        return 0
    def do_pre_build(self, thebuilder):
        self.Logger = logging.getLogger("WindowsVsToolChain")
        interesting_keys = ["ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH", "UniversalCRTSdkDir",
                            "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
                            "WindowsSDKVersion", "VCToolsInstallDir", "Path"]

        #
        # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS150TOOLVER:      version number for the VC compiler tools
        # VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
        if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":

            # check to see if host is configured
            # HostType for VS2017 should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var("VS2017_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
            else:
                HostInfo = GetHostInfo()
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    raise NotImplementedError()

            # VS2017_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var("VS2017_PREFIX") is not None:
                self.Logger.debug("VS2017_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2017".lower(), "VS150INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS150TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2017")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2017_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC",
                                      "Tools", "MSVC", vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var("VS2017_PREFIX", prefix)
                shell_environment.GetEnvironment().set_shell_var("VS2017_HOST", HostType)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(
                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2017")
                for (k, v) in vs_vars.items():
                    shell_env.set_shell_var(k, v)

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

        #
        # VS2019 - Follow VS2019 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS160TOOLVER:      version number for the VC compiler tools
        # VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        # VS2019_HOST:       set the host architecture to use for host tools, and host libs, etc
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":

            # check to see if host is configured
            # HostType for VS2019 should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var("VS2019_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
            else:
                HostInfo = GetHostInfo()
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    raise NotImplementedError()

            # VS2019_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var("VS2019_PREFIX") is not None:
                self.Logger.debug("VS2019_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2019".lower(), "VS160INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS160TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2019")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2019_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC",
                                      "Tools", "MSVC", vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var("VS2019_PREFIX", prefix)
                shell_environment.GetEnvironment().set_shell_var("VS2019_HOST", HostType)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(
                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="vs2019")
                for (k, v) in vs_vars.items():
                    shell_env.set_shell_var(k, v)

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

        #
        # VS2022 - VS2022 allows a user to install many copies/versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS170INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS170TOOLVER:      version number for the VC compiler tools
        # VS2022_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        # VS2022_HOST:       set the host architecture to use for host tools, and host libs, etc
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2022":

            # check to see if host is configured
            # HostType for VS2022 should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var("VS2022_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"HOST TYPE defined by environment.  Host Type is {HostType}")
            else:
                HostInfo = GetHostInfo()
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    raise NotImplementedError()

            # VS2022_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var("VS2022_PREFIX") is not None:
                self.Logger.debug("VS2022_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2022".lower(), "VS170INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS170TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2022")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2022_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC",
                                      "Tools", "MSVC", vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var("VS2022_PREFIX", prefix)
                shell_environment.GetEnvironment().set_shell_var("VS2022_HOST", HostType)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(
                    interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType], vs_version="VS2022")
                for (k, v) in vs_vars.items():
                    shell_env.set_shell_var(k, v)

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

        #
        # CLANGPDB on Windows uses nmake from
        # the VS compiler toolchain.   Find a version and set
        # as the CLANG_HOST_BIN path if not already set.
        #
        # Also get the platform header files, SDK, etc based on the
        # host type.  This is used for unit test compilation.
        # If CLANG_VS_HOST is not set then find the host type based on Host Info.
        ##
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "CLANGPDB":
            HostInfo = GetHostInfo()

            # check to see if host is configured
            # HostType for VS tools should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var("CLANG_VS_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"CLANG_VS_HOST defined by environment.  Value is {HostType}")
            else:
                #figure it out based on host info
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    # anything other than x86 or x64 is not supported
                    raise NotImplementedError()

            # CLANG_VS_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86", "x64": "AMD64", "arm": "not supported", "arm64": "not supported"}

            # now get the environment variables for the platform
            shell_env = shell_environment.GetEnvironment()
            # Use the tools lib to determine the correct values for the vars that interest us.
            vs_vars = locate_tools.QueryVcVariables(
                interesting_keys, VC_HOST_ARCH_TRANSLATOR[HostType])
            for (k, v) in vs_vars.items():
                shell_env.set_shell_var(k, v)
            
            ## 
            # If environment already has CLANG_HOST_BIN set then user has already
            # set the path to the VS tools like nmake.exe
            ##
            if shell_environment.GetEnvironment().get_shell_var("CLANG_HOST_BIN") is not None:
                self.Logger.debug("CLANG_HOST_BIN is already set.")

            else:
                install_path = self._get_vs_install_path(None, None)
                vc_ver = self._get_vc_version(install_path, None)

                if install_path is None or vc_ver is None:
                    self.Logger.error("Failed to find the VS environment for use by CLANGPDB")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path, version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make path align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC", vc_ver)
                clang_host_bin_prefix = os.path.join(prefix, "bin", "Host%s" % HostType, HostType)

                # now confirm it exists
                if not os.path.exists(clang_host_bin_prefix):
                    self.Logger.error("Path for VS toolchain is invalid")
                    return -2

                # The environment is using nmake (not make) so add "n" to the end of the path.
                # The rest of the command is derived from definitions in tools.def.
                shell_environment.GetEnvironment().set_shell_var("CLANG_HOST_BIN", os.path.join(clang_host_bin_prefix, "n"))

        return 0
Beispiel #23
0
    def RunBuildPlugin(self,
                       packagename,
                       Edk2pathObj,
                       pkgconfig,
                       environment,
                       PLM,
                       PLMHelper,
                       tc,
                       output_stream=None):
        workspace_path = Edk2pathObj.WorkspacePath
        basetools_path = environment.GetValue("EDK_TOOLS_PATH")
        python_path = os.path.join(basetools_path, "Source", "Python")
        env = shell_environment.GetEnvironment()
        env.set_shell_var('PYTHONPATH', python_path)
        env.set_shell_var('WORKSPACE', workspace_path)
        env.set_shell_var('PACKAGES_PATH',
                          os.pathsep.join(Edk2pathObj.PackagePathList))
        self.ECC_PASS = True

        # Create temp directory
        temp_path = os.path.join(workspace_path, 'Build', '.pytool', 'Plugin',
                                 'EccCheck')
        try:
            # Delete temp directory
            if os.path.exists(temp_path):
                shutil.rmtree(temp_path)
            # Copy package being scanned to temp_path
            shutil.copytree(os.path.join(workspace_path, packagename),
                            os.path.join(temp_path, packagename),
                            symlinks=True)
            # Copy exception.xml to temp_path
            shutil.copyfile(
                os.path.join(basetools_path, "Source", "Python", "Ecc",
                             "exception.xml"),
                os.path.join(temp_path, "exception.xml"))
            # Output file to use for git diff operations
            temp_diff_output = os.path.join(temp_path, 'diff.txt')

            self.ApplyConfig(pkgconfig, temp_path, packagename)
            modify_dir_list = self.GetModifyDir(packagename, temp_diff_output)
            patch = self.GetDiff(packagename, temp_diff_output)
            ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)
            #
            # Use temp_path as working directory when running ECC tool
            #
            self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path,
                                   basetools_path)
            ecc_log = os.path.join(temp_path, "Ecc.log")
            if self.ECC_PASS:
                # Delete temp directory
                if os.path.exists(temp_path):
                    shutil.rmtree(temp_path)
                tc.SetSuccess()
                return 0
            else:
                with open(ecc_log, encoding='utf8') as output:
                    ecc_output = output.readlines()
                    for line in ecc_output:
                        logging.error(line.strip())
                # Delete temp directory
                if os.path.exists(temp_path):
                    shutil.rmtree(temp_path)
                tc.SetFailed("EccCheck failed for {0}".format(packagename),
                             "CHECK FAILED")
                return 1
        except KeyboardInterrupt:
            # If EccCheck is interrupted by keybard interrupt, then return failure
            # Delete temp directory
            if os.path.exists(temp_path):
                shutil.rmtree(temp_path)
            tc.SetFailed("EccCheck interrupted for {0}".format(packagename),
                         "CHECK FAILED")
            return 1
        else:
            # If EccCheck fails for any other exception type, raise the exception
            # Delete temp directory
            if os.path.exists(temp_path):
                shutil.rmtree(temp_path)
            tc.SetFailed("EccCheck exception for {0}".format(packagename),
                         "CHECK FAILED")
            raise
            return 1
 def setUpClass(cls):
     env = shell_environment.GetEnvironment()
     cls.env_checkpoint = env.checkpoint()
 def tearDown(self):
     env = shell_environment.GetEnvironment()
     env.restore_checkpoint(TestGitDependencyUrlPatching.env_checkpoint)
    def do_post_build(self, thebuilder):
        '''
        After a build, will automatically locate and run all host-based unit tests. Logs any
        failures with Warning severity and will return a count of the failures as the return code.

        EXPECTS:
        - Build Var 'CI_BUILD_TYPE' - If not set to 'host_unit_test', will not do anything.

        UPDATES:
        - Shell Var 'CMOCKA_XML_FILE'
        '''
        ci_type = thebuilder.env.GetValue('CI_BUILD_TYPE')
        if ci_type != 'host_unit_test':
            return 0

        shell_env = shell_environment.GetEnvironment()
        logging.log(edk2_logging.get_section_level(),
                    "Run Host based Unit Tests")
        path = thebuilder.env.GetValue("BUILD_OUTPUT_BASE")

        failure_count = 0

        # Set up the reporting type for Cmocka.
        shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')

        for arch in thebuilder.env.GetValue("TARGET_ARCH").split():
            logging.log(edk2_logging.get_subsection_level(),
                        "Testing for architecture: " + arch)
            cp = os.path.join(path, arch)

            # If any old results XML files exist, clean them up.
            for old_result in glob.iglob(os.path.join(cp, "*.result.xml")):
                os.remove(old_result)

            # Find and Run any Host Tests
            if GetHostInfo().os.upper() == "LINUX":
                testList = glob.glob(os.path.join(cp, "*Test*"))
                for a in testList[:]:
                    p = os.path.join(cp, a)
                    # It must be a file
                    if not os.path.isfile(p):
                        testList.remove(a)
                        logging.debug(f"Remove directory file: {p}")
                        continue
                    # It must be executable
                    if os.stat(p).st_mode & (stat.S_IEXEC | stat.S_IXGRP
                                             | stat.S_IXOTH) == 0:
                        testList.remove(a)
                        logging.debug(f"Remove non-executable file: {p}")
                        continue

                    logging.info(f"Test file found: {p}")

            elif GetHostInfo().os.upper() == "WINDOWS":
                testList = glob.glob(os.path.join(cp, "*Test*.exe"))
            else:
                raise NotImplementedError("Unsupported Operating System")

            for test in testList:
                # Configure output name.
                shell_env.set_shell_var('CMOCKA_XML_FILE',
                                        test + ".%g." + arch + ".result.xml")

                # Run the test.
                ret = RunCmd('"' + test + '"', "", workingdir=cp)
                if (ret != 0):
                    logging.error("UnitTest Execution Error: " +
                                  os.path.basename(test))
                else:
                    logging.info("UnitTest Completed: " +
                                 os.path.basename(test))
                    file_match_pattern = test + ".*." + arch + ".result.xml"
                    xml_results_list = glob.glob(file_match_pattern)
                    for xml_result_file in xml_results_list:
                        root = xml.etree.ElementTree.parse(
                            xml_result_file).getroot()
                        for suite in root:
                            for case in suite:
                                for result in case:
                                    if result.tag == 'failure':
                                        logging.warning("%s Test Failed" %
                                                        os.path.basename(test))
                                        logging.warning(
                                            "  %s - %s" %
                                            (case.attrib['name'], result.text))
                                        failure_count += 1

        return failure_count
    def SetEnv(self):
        edk2_logging.log_progress("Setting up the Environment")
        shell_environment.GetEnvironment().set_shell_var("WORKSPACE", self.ws)
        shell_environment.GetBuildVars().SetValue("WORKSPACE", self.ws,
                                                  "Set in SetEnv")

        if (self.pp is not None):
            shell_environment.GetEnvironment().set_shell_var(
                "PACKAGES_PATH", self.pp)
            shell_environment.GetBuildVars().SetValue("PACKAGES_PATH", self.pp,
                                                      "Set in SetEnv")

        # process platform parameters defined in platform build file
        ret = self.SetPlatformEnv()
        if (ret != 0):
            logging.critical("Set Platform Env failed")
            return ret

        # set some basic defaults
        self.SetBasicDefaults()

        # Handle all the template files for workspace/conf/ Allow override
        TemplateDirList = [self.env.GetValue("EDK_TOOLS_PATH")
                           ]  # set to edk2 BaseTools
        PlatTemplatesForConf = self.env.GetValue(
            "CONF_TEMPLATE_DIR")  # get platform defined additional path
        if (PlatTemplatesForConf is not None):
            PlatTemplatesForConf = self.mws.join(self.ws, PlatTemplatesForConf)
            TemplateDirList.insert(0, PlatTemplatesForConf)
            logging.debug(
                f"Platform defined override for Template Conf Files: {PlatTemplatesForConf}"
            )

        conf_dir = os.path.join(self.ws, "Conf")
        conf_mgmt.ConfMgmt().populate_conf_dir(conf_dir, self.UpdateConf,
                                               TemplateDirList)

        # parse target file
        ret = self.ParseTargetFile()
        if (ret != 0):
            logging.critical("ParseTargetFile failed")
            return ret

        # parse DSC file
        ret = self.ParseDscFile()
        if (ret != 0):
            logging.critical("ParseDscFile failed")
            return ret

        # parse FDF file
        ret = self.ParseFdfFile()
        if (ret != 0):
            logging.critical("ParseFdfFile failed")
            return ret

        # set build output base envs for all builds
        if self.env.GetValue("OUTPUT_DIRECTORY") is None:
            logging.warn("OUTPUT_DIRECTORY was not found, defaulting to Build")
            self.env.SetValue("OUTPUT_DIRECTORY", "Build",
                              "default from uefi_build", True)
        self.env.SetValue(
            "BUILD_OUT_TEMP",
            os.path.join(self.ws, self.env.GetValue("OUTPUT_DIRECTORY")),
            "Computed in SetEnv")

        target = self.env.GetValue("TARGET")
        self.env.SetValue(
            "BUILD_OUTPUT_BASE",
            os.path.join(self.env.GetValue("BUILD_OUT_TEMP"),
                         target + "_" + self.env.GetValue("TOOL_CHAIN_TAG")),
            "Computed in SetEnv")

        # We have our build target now.  Give platform build one more chance for target specific settings.
        ret = self.SetPlatformEnvAfterTarget()
        if (ret != 0):
            logging.critical("SetPlatformEnvAfterTarget failed")
            return ret

        # set the build report file
        self.env.SetValue(
            "BUILDREPORT_FILE",
            os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"),
                         "BUILD_REPORT.TXT"), True)

        # set environment variables for the build process
        os.environ["EFI_SOURCE"] = self.ws

        return 0
 def tearDown(self):
     shell_environment.GetEnvironment().restore_initial_checkpoint()
     pass
 def tearDown(self):
     shell_environment.GetEnvironment().restore_initial_checkpoint()
     buildFolder = os.path.join(self.minimalTree, "Build")
     shutil.rmtree(buildFolder, ignore_errors=True)
     TestEdk2PlatBuild.restart_logging()
     pass
Beispiel #30
0
    def do_pre_build(self, thebuilder):
        self.Logger = logging.getLogger("WindowsVsToolChain")
        interesting_keys = [
            "ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH",
            "UniversalCRTSdkDir", "UCRTVersion", "WindowsLibPath",
            "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",
            "WindowsSDKVersion", "VCToolsInstallDir", "Path"
        ]

        #
        # VS2017 - Follow VS2017 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS150INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS150TOOLVER:      version number for the VC compiler tools
        # VS2017_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
        if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2017":

            # check to see if host is configured
            # HostType for VS2017 should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var(
                "VS2017_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"HOST TYPE defined by environment.  Host Type is {HostType}"
                )
            else:
                HostInfo = GetHostInfo()
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    raise NotImplementedError()

            # VS2017_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86",
                "x64": "AMD64",
                "arm": "not supported",
                "arm64": "not supported"
            }

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2017_PREFIX") != None:
                self.Logger.info("VS2017_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2017".lower(), "VS150INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS150TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2017")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2017_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2017_PREFIX", prefix)
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2017_HOST", HostType)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(
                    interesting_keys,
                    VC_HOST_ARCH_TRANSLATOR[HostType],
                    vs_version="vs2017")
                for (k, v) in vs_vars.items():
                    shell_env.set_shell_var(k, v)

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

        #
        # VS2019 - Follow VS2019 where there is potential for many versions of the tools.
        # If a specific version is required then the user must set both env variables:
        # VS160INSTALLPATH:  base install path on system to VC install dir.  Here you will find the VC folder, etc
        # VS160TOOLVER:      version number for the VC compiler tools
        # VS2019_PREFIX:     path to MSVC compiler folder with trailing slash (can be used instead of two vars above)
        # VS2017_HOST:       set the host architecture to use for host tools, and host libs, etc
        elif thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "VS2019":

            # check to see if host is configured
            # HostType for VS2019 should be (defined in tools_def):
            # x86   == 32bit Intel
            # x64   == 64bit Intel
            # arm   == 32bit Arm
            # arm64 == 64bit Arm
            #
            HostType = shell_environment.GetEnvironment().get_shell_var(
                "VS2019_HOST")
            if HostType is not None:
                HostType = HostType.lower()
                self.Logger.info(
                    f"HOST TYPE defined by environment.  Host Type is {HostType}"
                )
            else:
                HostInfo = GetHostInfo()
                if HostInfo.arch == "x86":
                    if HostInfo.bit == "32":
                        HostType = "x86"
                    elif HostInfo.bit == "64":
                        HostType = "x64"
                else:
                    raise NotImplementedError()

            # VS2019_HOST options are not exactly the same as QueryVcVariables. This translates.
            VC_HOST_ARCH_TRANSLATOR = {
                "x86": "x86",
                "x64": "AMD64",
                "arm": "not supported",
                "arm64": "not supported"
            }

            # check to see if full path already configured
            if shell_environment.GetEnvironment().get_shell_var(
                    "VS2019_PREFIX") != None:
                self.Logger.info("VS2019_PREFIX is already set.")

            else:
                install_path = self._get_vs_install_path(
                    "VS2019".lower(), "VS160INSTALLPATH")
                vc_ver = self._get_vc_version(install_path, "VS160TOOLVER")

                if install_path is None or vc_ver is None:
                    self.Logger.error(
                        "Failed to configure environment for VS2019")
                    return -1

                version_aggregator.GetVersionAggregator().ReportVersion(
                    "Visual Studio Install Path", install_path,
                    version_aggregator.VersionTypes.INFO)
                version_aggregator.GetVersionAggregator().ReportVersion(
                    "VC Version", vc_ver, version_aggregator.VersionTypes.TOOL)

                # make VS2019_PREFIX to align with tools_def.txt
                prefix = os.path.join(install_path, "VC", "Tools", "MSVC",
                                      vc_ver)
                prefix = prefix + os.path.sep
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2019_PREFIX", prefix)
                shell_environment.GetEnvironment().set_shell_var(
                    "VS2019_HOST", HostType)

                shell_env = shell_environment.GetEnvironment()
                # Use the tools lib to determine the correct values for the vars that interest us.
                vs_vars = locate_tools.QueryVcVariables(
                    interesting_keys,
                    VC_HOST_ARCH_TRANSLATOR[HostType],
                    vs_version="vs2019")
                for (k, v) in vs_vars.items():
                    shell_env.set_shell_var(k, v)

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

        return 0