def test_Singelton(self): version1 = version_aggregator.GetVersionAggregator() version2 = version_aggregator.GetVersionAggregator() self.assertEqual(version1, version2) self.assertIsNotNone(version1) version3 = version_aggregator.version_aggregator() version4 = version_aggregator.version_aggregator() self.assertNotEqual(version3, version4)
def verify(self, logversion=True): result = True if not os.path.isdir(self._local_repo_root_path): self.logger.error("no dir for Git Dependency") result = False if result and len(os.listdir(self._local_repo_root_path)) == 0: self.logger.error("no files in Git Dependency") result = False if result: # valid repo folder r = Repo(self._local_repo_root_path) if (not r.initalized): self.logger.error("Git Dependency: Not Initialized") result = False elif (r.dirty): self.logger.error("Git Dependency: dirty") result = False if (r.head.commit != self.version): self.logger.error( f"Git Dependency: head is {r.head.commit} and version is {self.version}" ) result = False self.logger.debug("Verify '%s' returning '%s'." % (self.name, result)) if (logversion): version_aggregator.GetVersionAggregator().ReportVersion( self.name, self.version, version_aggregator.VersionTypes.INFO) return result
def _initialize_app_info(self) -> None: """ Initialize Uncrustify application information. This function will determine the application path and version. """ # Verify Uncrustify is specified in the environment. if UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY not in os.environ: raise UncrustifyAppEnvVarNotFoundException( f"Uncrustify environment variable {UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY} is not present.") self._app_path = shutil.which('uncrustify', path=os.environ[UncrustifyCheck.UNCRUSTIFY_PATH_ENV_KEY]) if self._app_path is None: raise FileNotFoundError( errno.ENOENT, os.strerror(errno.ENOENT), self._app_path) self._app_path = os.path.normcase(os.path.normpath(self._app_path)) if not os.path.isfile(self._app_path): raise FileNotFoundError( errno.ENOENT, os.strerror(errno.ENOENT), self._app_path) # Verify Uncrustify is present at the expected path. return_buffer = StringIO() ret = RunCmd(self._app_path, "--version", outstream=return_buffer) if (ret != 0): raise UncrustifyAppVersionErrorException( f"Error occurred executing --version: {ret}.") # Log Uncrustify version information. self._app_version = return_buffer.getvalue().strip() self._tc.LogStdOut(f"Uncrustify version: {self._app_version}") version_aggregator.GetVersionAggregator().ReportVersion( "Uncrustify", self._app_version, version_aggregator.VersionTypes.INFO)
def verify(self): result = True state_data = None # See whether or not the state file exists. if not os.path.isfile(self.state_file_path): result = False # Attempt to load the state file. if result: with open(self.state_file_path, 'r') as file: try: state_data = yaml.safe_load(file) except Exception: pass if state_data is None: result = False # If loaded, check the version. if result and state_data['version'] != self.version: result = False logging.debug("Verify '%s' returning '%s'." % (self.name, result)) version_aggregator.GetVersionAggregator().ReportVersion( self.name, self.version, version_aggregator.VersionTypes.INFO) return result
def populate_conf_dir(self, conf_folder_path: str, override_conf: bool, conf_template_source_list: list) -> None: ''' compare the conf dir files to the template files. copy files if they are not present in the conf dir or the override parameter is set. param: conf_folder_path: folder path to output conf location (absolute path) override_conf: boolean to indicate if templates files should replace conf files regardless of existence or version. conf_template_source_list: priority list of folder path that might contain a "Conf" folder with template files to use When complete the conf_folder_path dir must be setup for edk2 builds ''' # make folder to conf path if needed os.makedirs(conf_folder_path, exist_ok=True) files = ["target.txt", "tools_def.txt", "build_rule.txt"] # add more files here # make output conf files list based on files outfiles = [os.path.join(conf_folder_path, f) for f in files] # make template list based on files templatefiles = [ os.path.join("Conf", os.path.splitext(f)[0] + ".template") for f in files ] # loop thru each Conf file needed for x in range(0, len(outfiles)): template_file_path = None # find template file given multiple root locations for r in conf_template_source_list: p = os.path.join(r, templatefiles[x]) if os.path.isfile(p): template_file_path = p break if (template_file_path is None): self.Logger.critical("Failed to find Template file for %s" % outfiles[x]) raise Exception("Template File Missing", outfiles[x]) else: self.Logger.debug(f"Conf file template: {template_file_path}") # have template now - now copy if needed self._copy_conf_file_if_necessary(outfiles[x], template_file_path, override_conf) # Log Version for reporting version_aggregator.GetVersionAggregator().ReportVersion( outfiles[x], self._get_version(outfiles[x]), version_aggregator.VersionTypes.INFO)
def ToolsDefConfigure(self): Tag = self.env.GetValue("TOOL_CHAIN_TAG") version_aggregator.GetVersionAggregator().ReportVersion( "TOOL_CHAIN_TAG", Tag, version_aggregator.VersionTypes.TOOL) if (Tag is not None) and (Tag.upper().startswith("VS")): if (not self.VisualStudioSpecificVersions(Tag)): self.Logger.warning( "Potential Toolchain issue. VS specific operation failed." ) 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 collect_python_pip_info(cls): # Get the current python version cur_py = "%d.%d.%d" % sys.version_info[:3] ver_agg = version_aggregator.GetVersionAggregator() ver_agg.ReportVersion("Python", cur_py, version_aggregator.VersionTypes.TOOL) # Get a list of all the packages currently installed in pip pip_packages = [p for p in pkg_resources.working_set] # go through all installed pip versions for package in pip_packages: version = pkg_resources.get_distribution(package).version logging.info("{0} version: {1}".format(package.project_name, version)) ver_agg.ReportVersion(package.project_name, version, version_aggregator.VersionTypes.PIP)
def do_report(self, thebuilder): try: from edk2toolext.environment import version_aggregator except ImportError: logging.critical( "Loading BuildToolsReportGenerator failed, please update your Edk2-PyTool-Extensions" ) return 0 OutputReport = os.path.join( thebuilder.env.GetValue("BUILD_OUTPUT_BASE"), "BUILD_TOOLS_REPORT") OutputReport = os.path.normpath(OutputReport) if not os.path.isdir(os.path.dirname(OutputReport)): os.makedirs(os.path.dirname(OutputReport)) Report = BuildToolsReport() Report.MakeReport(version_aggregator.GetVersionAggregator(). GetAggregatedVersionInformation(), OutputReport=OutputReport)
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
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 tearDown(self): # we need to reset the version aggregator each time version_aggregator.GetVersionAggregator().Reset()
def Go(self): required_submodules = self.PlatformSettings.GetRequiredSubmodules() workspace_path = self.GetWorkspaceRoot() # Make sure git is installed return_buffer = StringIO() RunCmd("git", "--version", outstream=return_buffer, raise_exception_on_nonzero=True) git_version = return_buffer.getvalue().strip() return_buffer.close() version_aggregator.GetVersionAggregator().ReportVersion( "Git", git_version, version_aggregator.VersionTypes.TOOL) min_git = "2.11.0" # This code is highly specific to the return value of "git version"... cur_git = ".".join(git_version.split(' ')[2].split(".")[:3]) if version_compare(min_git, cur_git) > 0: raise RuntimeError( "Please upgrade Git! Current version is %s. Minimum is %s." % (cur_git, min_git)) # Pre-setup cleaning if "--force" is specified. if self.force_it: try: # Clean and reset the main repo. edk2_logging.log_progress("## Cleaning the root repo...") RunCmd("git", "reset --hard", workingdir=workspace_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) # Because logging is running right now, we have to skip the files that are open. ignore_files = "-e Build/%s.txt -e Build/%s.md" % ( self.GetLoggingFileName('txt'), self.GetLoggingFileName('md')) RunCmd("git", "clean -xffd %s" % ignore_files, workingdir=workspace_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) edk2_logging.log_progress("Done.\n") # Clean any submodule repos. if required_submodules: for required_submodule in required_submodules: edk2_logging.log_progress( "## Cleaning Git repository: %s..." % required_submodule.path) required_submodule_path = os.path.normpath( os.path.join(workspace_path, required_submodule.path)) RunCmd("git", "reset --hard", workingdir=required_submodule_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) RunCmd("git", "clean -xffd", workingdir=required_submodule_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) edk2_logging.log_progress("Done.\n") except RuntimeError as e: logging.error("FAILED!\n") logging.error("Error while trying to clean the environment!") logging.error(str(e)) return # Grab the remaining Git repos. if required_submodules and len(required_submodules) > 0: # Git Repos: STEP 1 -------------------------------------- # Make sure that the repos are all synced. try: submodule_string = " ".join( [x.path for x in required_submodules]) edk2_logging.log_progress( f"## Syncing Git repositories: {submodule_string}...") RunCmd("git", f'submodule sync -- {submodule_string}', workingdir=workspace_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) edk2_logging.log_progress("Done.\n") except RuntimeError as e: logging.error("FAILED!\n") logging.error( "Error while trying to synchronize the environment!") logging.error(str(e)) return # Git Repos: STEP 2 -------------------------------------- # Iterate through all repos and see whether they should be fetched. for required_submodule in required_submodules: try: edk2_logging.log_progress( f"## Checking Git repository: {required_submodule.path}..." ) # Git Repos: STEP 2a --------------------------------- # Need to determine whether to skip this repo. required_submodule_path = os.path.normpath( os.path.join(workspace_path, required_submodule.path)) skip_repo = False # If the repo exists (and we're not forcing things) make # sure that it's not in a "dirty" state. if os.path.exists( required_submodule_path) and not self.force_it: return_buffer = StringIO() RunCmd("git", 'diff ' + required_submodule.path, outstream=return_buffer, workingdir=workspace_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=True) git_data = return_buffer.getvalue().strip() return_buffer.close() # If anything was returned, we should skip processing the repo. # It is either on a different commit or it has local changes. if git_data != "": logging.info( "-- NOTE: Repo currently exists and appears to have local changes!" ) logging.info("-- Skipping fetch!") skip_repo = True # Git Repos: STEP 2b --------------------------------- # If we're not skipping, grab it. if not skip_repo or self.force_it: logging.info("## Fetching repo.") cmd_string = "submodule update --init" if required_submodule.recursive: cmd_string += " --recursive" cmd_string += " --progress" if self.omnicache_path is not None: cmd_string += " --reference " + self.omnicache_path cmd_string += " " + required_submodule.path ret = RunCmd('git', cmd_string, workingdir=workspace_path, logging_level=logging.DEBUG, raise_exception_on_nonzero=False) if ret != 0: logging.error("We failed to fetch " + required_submodule) raise RuntimeError( "Unable to checkout repo due to error") edk2_logging.log_progress("Done.\n") except RuntimeError as e: logging.error("FAILED!\n") logging.error("Failed to fetch required repository!\n") logging.error(str(e)) 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") != 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
def __PopulateConf(self, OverrideConf, AdditionalTemplateConfDir): ws = self.env.GetValue("WORKSPACE") # Copy Conf template files to conf if not present target = os.path.join(ws, "Conf", "target.txt") buildrules = os.path.join(ws, "Conf", "build_rule.txt") toolsdef = os.path.join(ws, "Conf", "tools_def.txt") # BaseTools Template files target_template = os.path.join("Conf", "target.template") tools_def_template = os.path.join("Conf", "tools_def.template") build_rules_template = os.path.join("Conf", "build_rule.template") outfiles = [target, toolsdef, buildrules] tfiles = [target_template, tools_def_template, build_rules_template] # check if conf exists if (not os.path.isdir(os.path.join(ws, "Conf"))): os.mkdir(os.path.join(ws, "Conf")) x = 0 while (x < len(outfiles)): # check if the conf file already exists # don't overwrite if exists. Popup if version is older in conf TemplateFilePath = "" Tag = self.env.GetValue("TOOL_CHAIN_TAG") if Tag is None: self.Logger.warn( "Can't use ToolChain specific template files since Tag is not defined" ) Tag = "" # # Get the Override template if it exist # if (AdditionalTemplateConfDir is not None): fp = os.path.join(AdditionalTemplateConfDir, tfiles[x] + ".ms") if os.path.isfile(fp): TemplateFilePath = fp # # If not found, try toolchain specific templates # if (TemplateFilePath == "" and Tag.upper().startswith("VS")): fp = os.path.join(self.env.GetValue("EDK2_BASE_TOOLS_DIR"), tfiles[x] + ".vs") if os.path.isfile(fp): TemplateFilePath = fp if (TemplateFilePath == "" and Tag.upper().startswith("GCC")): fp = os.path.join(self.env.GetValue("EDK2_BASE_TOOLS_DIR"), tfiles[x] + ".gcc") if os.path.isfile(fp): TemplateFilePath = fp # # If not found above try MS templates # if (TemplateFilePath == ""): fp = os.path.join(self.env.GetValue("EDK2_BASE_TOOLS_DIR"), tfiles[x] + ".ms") if os.path.isfile(fp): TemplateFilePath = fp # # If not found above try TianoCore Template # if (TemplateFilePath == ""): fp = os.path.join(self.env.GetValue("EDK2_BASE_TOOLS_DIR"), tfiles[x]) if TemplateFilePath == "" and os.path.isfile(fp): TemplateFilePath = fp # # Check to see if found yet -- No more options so now we are broken # if (TemplateFilePath == ""): self.Logger.critical("Failed to find Template file for %s" % outfiles[x]) raise Exception("Template File Missing", outfiles[x]) else: self.Logger.debug("Conf file template: [%s]", TemplateFilePath) # Check to see if we need the template if (not os.path.isfile(outfiles[x])): # file doesn't exist. copy template self.Logger.debug( "%s file not found. Creating from Template file %s" % (outfiles[x], TemplateFilePath)) shutil.copy2(TemplateFilePath, outfiles[x]) elif (OverrideConf): self.Logger.debug("%s file replaced as requested" % outfiles[x]) shutil.copy2(TemplateFilePath, outfiles[x]) else: # Both file exists. Do a quick version check if (self.__OlderVersion(outfiles[x], TemplateFilePath)): # Conf dir is older. Warn user. self.Logger.critical( "Conf file [%s] out-of-date. Please update your conf files! " "Sleeping 30 seconds to encourage update....", outfiles[x]) time.sleep(30) else: self.Logger.debug("Conf file [%s] up-to-date", outfiles[x]) version_aggregator.GetVersionAggregator().ReportVersion( outfiles[x], self.__GetVersion(outfiles[x]), version_aggregator.VersionTypes.INFO) x = x + 1
def do_pre_build(self, thebuilder): self.Logger = logging.getLogger("ClangPdbToolChain") ## # CLANGPBD # - Need to find the clang path. # - Report path and version for logging # # if CLANG_BIN already set the plugin will confirm it exists and get the version of clang # If not set it will look for clang on the path. If found it will configure for that. # if still not found it will try the default install directory. # finally an error will be reported if not found ## if thebuilder.env.GetValue("TOOL_CHAIN_TAG") == "CLANGPDB": HostInfo = GetHostInfo() ClangBin_Default = "UNDEFINED" clang_exe = "clang" if HostInfo.os == "Windows": ClangBin_Default = "C:\\Program Files\\LLVM\\bin\\\\" #need to escape the last slash as it seems to be removed clang_exe += ".exe" elif HostInfo.os == "Linux": ClangBin_Default = "/LLVM/bin/" #this isn't right else: pass # no defaults set ClangBin = shell_environment.GetEnvironment().get_shell_var( "CLANG_BIN") if ClangBin is not None: self.Logger.info("CLANG_BIN is already set.") else: # see if clang is on path. for path_entry in os.getenv("PATH").split(os.pathsep): path_entry = os.path.normpath(path_entry) if os.path.isfile(os.path.join(path_entry, clang_exe)): ClangBin = os.path.abspath(path_entry) + os.sep break if ClangBin is None: # Didn't find it on path - try the install default. ClangBin = ClangBin_Default shell_environment.GetEnvironment().set_shell_var( "CLANG_BIN", ClangBin) version_aggregator.GetVersionAggregator().ReportVersion( "CLANG BIN", ClangBin, version_aggregator.VersionTypes.INFO) # now confirm it exists if not os.path.exists(shell_environment.GetEnvironment(). get_shell_var("CLANG_BIN")): self.Logger.error( f"Path for CLANGPDB toolchain is invalid. {ClangBin}") return -2 version_aggregator.GetVersionAggregator().ReportVersion( "CLANG Version", self._get_clang_version(ClangBin), version_aggregator.VersionTypes.TOOL) return 0
def report_version(self): version_aggregator.GetVersionAggregator().ReportVersion(self.name, self.version, version_aggregator.VersionTypes.INFO, self.descriptor_location)
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 RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): Errors = [] abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSystemFromEdk2RelativePath( packagename) if abs_pkg_path is None: tc.SetSkipped() tc.LogStdError("No package {0}".format(packagename)) return -1 # check for node return_buffer = StringIO() ret = RunCmd("node", "--version", outstream=return_buffer) if (ret != 0): tc.SetSkipped() tc.LogStdError("NodeJs not installed. Test can't run") logging.warning("NodeJs not installed. Test can't run") return -1 node_version = return_buffer.getvalue().strip() # format vXX.XX.XX tc.LogStdOut(f"Node version: {node_version}") # Check for markdownlint-cli return_buffer = StringIO() ret = RunCmd("markdownlint", "--version", outstream=return_buffer) if (ret != 0): tc.SetSkipped() tc.LogStdError("markdownlint not installed. Test can't run") logging.warning("markdownlint not installed. Test can't run") return -1 mdl_version = return_buffer.getvalue().strip() # format XX.XX.XX tc.LogStdOut(f"MarkdownLint version: {mdl_version}") version_aggregator.GetVersionAggregator().ReportVersion( "MarkDownLint", mdl_version, version_aggregator.VersionTypes.INFO) # Get relative path for the root of package to use with ignore and path parameters relpath = os.path.relpath(abs_pkg_path) # # check for any package specific ignore patterns defined by package config # Ignores = [] if("IgnoreFiles" in pkgconfig): for i in pkgconfig["IgnoreFiles"]: Ignores.append(f"{relpath}/{i}") # # Make the path string to check # path_to_check = f'{relpath}/**/*.md' # get path to config file - # Currently there is support for two different config files # If the config file is not found then the test case is skipped # # 1st - At the package root # 2nd - At the workspace root of the build config_file_path = None # 1st check to see if the config file is at package root if os.path.isfile(os.path.join(abs_pkg_path, MarkdownLintCheck.CONFIG_FILE_NAME)): config_file_path = os.path.join(abs_pkg_path, MarkdownLintCheck.CONFIG_FILE_NAME) # 2nd check to see if at workspace root elif os.path.isfile(os.path.join(Edk2pathObj.WorkspacePath, MarkdownLintCheck.CONFIG_FILE_NAME)): config_file_path = os.path.join(Edk2pathObj.WorkspacePath, MarkdownLintCheck.CONFIG_FILE_NAME) # If not found - skip test else: tc.SetSkipped() tc.LogStdError(f"{MarkdownLintCheck.CONFIG_FILE_NAME} not found. Skipping test") logging.warning(f"{MarkdownLintCheck.CONFIG_FILE_NAME} not found. Skipping test") return -1 # Run the linter results = self._check_markdown(path_to_check, config_file_path, Ignores) for r in results: tc.LogStdError(r.strip()) # add result to test case overall_status = len(results) if overall_status != 0: if "AuditOnly" in pkgconfig and pkgconfig["AuditOnly"]: # set as skipped if AuditOnly tc.SetSkipped() return -1 else: tc.SetFailed("Markdown Lint Check {0} Failed. Errors {1}".format( packagename, overall_status), "CHECK_FAILED") else: tc.SetSuccess() return overall_status
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): Errors = [] abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath( packagename) if abs_pkg_path is None: tc.SetSkipped() tc.LogStdError("No package {0}".format(packagename)) return -1 # check for node return_buffer = StringIO() ret = RunCmd("node", "--version", outstream=return_buffer) if (ret != 0): tc.SetSkipped() tc.LogStdError("NodeJs not installed. Test can't run") logging.warning("NodeJs not installed. Test can't run") return -1 node_version = return_buffer.getvalue().strip() # format vXX.XX.XX tc.LogStdOut(f"Node version: {node_version}") version_aggregator.GetVersionAggregator().ReportVersion( "NodeJs", node_version, version_aggregator.VersionTypes.INFO) # Check for cspell return_buffer = StringIO() ret = RunCmd("cspell", "--version", outstream=return_buffer) if (ret != 0): tc.SetSkipped() tc.LogStdError("cspell not installed. Test can't run") logging.warning("cspell not installed. Test can't run") return -1 cspell_version = return_buffer.getvalue().strip() # format XX.XX.XX tc.LogStdOut(f"CSpell version: {cspell_version}") version_aggregator.GetVersionAggregator().ReportVersion( "CSpell", cspell_version, version_aggregator.VersionTypes.INFO) package_relative_paths_to_spell_check = SpellCheck.STANDARD_PLUGIN_DEFINED_PATHS # # Allow the ci.yaml to remove any of the above standard paths # if ("IgnoreStandardPaths" in pkgconfig): for a in pkgconfig["IgnoreStandardPaths"]: if (a in package_relative_paths_to_spell_check): tc.LogStdOut( f"ignoring standard path due to ci.yaml ignore: {a}") package_relative_paths_to_spell_check.remove(a) else: tc.LogStdOut(f"Invalid IgnoreStandardPaths value: {a}") # # check for any additional include paths defined by package config # if ("AdditionalIncludePaths" in pkgconfig): package_relative_paths_to_spell_check.extend( pkgconfig["AdditionalIncludePaths"]) # # Make the path string for cspell to check # relpath = os.path.relpath(abs_pkg_path) cpsell_paths = " ".join([ f"{relpath}/**/{x}" for x in package_relative_paths_to_spell_check ]) # Make the config file config_file_path = os.path.join(Edk2pathObj.WorkspacePath, "Build", packagename, "cspell_actual_config.json") mydir = os.path.dirname(os.path.abspath(__file__)) # load as yaml so it can have comments base = os.path.join(mydir, "cspell.base.yaml") with open(base, "r") as i: config = yaml.safe_load(i) if ("ExtendWords" in pkgconfig): config["words"].extend(pkgconfig["ExtendWords"]) with open(config_file_path, "w") as o: json.dump(config, o) # output as json so compat with cspell All_Ignores = [] # Parse the config for other ignores if "IgnoreFiles" in pkgconfig: All_Ignores.extend(pkgconfig["IgnoreFiles"]) # spell check all the files ignore = parse_gitignore_lines( All_Ignores, os.path.join(abs_pkg_path, "nofile.txt"), abs_pkg_path) # result is a list of strings like this # C:\src\sp-edk2\edk2\FmpDevicePkg\FmpDevicePkg.dec:53:9 - Unknown word (Capule) EasyFix = [] results = self._check_spelling(cpsell_paths, config_file_path) for r in results: path, _, word = r.partition(" - Unknown word ") if len(word) == 0: # didn't find pattern continue pathinfo = path.rsplit(":", 2) # remove the line no info if (ignore(pathinfo[0])): # check against ignore list tc.LogStdOut(f"ignoring error due to ci.yaml ignore: {r}") continue # real error EasyFix.append(word.strip().strip("()")) Errors.append(r) # Log all errors tc StdError for l in Errors: tc.LogStdError(l.strip()) # Helper - Log the syntax needed to add these words to dictionary if len(EasyFix) > 0: EasyFix = sorted(set(a.lower() for a in EasyFix)) tc.LogStdOut("\n Easy fix:") OneString = "If these are not errors add this to your ci.yaml file.\n" OneString += '"SpellCheck": {\n "ExtendWords": [' for a in EasyFix: tc.LogStdOut(f'\n"{a}",') OneString += f'\n "{a}",' logging.info(OneString.rstrip(",") + '\n ]\n}') # add result to test case overall_status = len(Errors) if overall_status != 0: if "AuditOnly" in pkgconfig and pkgconfig["AuditOnly"]: # set as skipped if AuditOnly tc.SetSkipped() return -1 else: tc.SetFailed( "SpellCheck {0} Failed. Errors {1}".format( packagename, overall_status), "CHECK_FAILED") else: tc.SetSuccess() return overall_status
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
def display_pip_package_info(package_list): for package in package_list: version = pkg_resources.get_distribution(package).version logging.info("{0} version: {1}".format(package, version)) version_aggregator.GetVersionAggregator().ReportVersion(package, version, version_aggregator.VersionTypes.TOOL)