Skip to content

Commit

Permalink
Add Rust tool version reporting
Browse files Browse the repository at this point in the history
Adds support to report Rust tool versions in the version aggregator
so the versions are available in the Build Tools Report.

Also prints the version to the logger at info level similar to other
versions so it is part of the build output.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Oct 20, 2023
1 parent 4f2b186 commit fbfab9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion edk2toolext/edk2_invocable.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from typing import Iterable, Tuple

import pkg_resources
from edk2toollib.utility_functions import GetHostInfo, import_module_by_file_name, locate_class_in_module
from edk2toollib.utility_functions import GetHostInfo, RunCmd, import_module_by_file_name, locate_class_in_module

from edk2toolext.base_abstract_invocable import BaseAbstractInvocable
from edk2toolext.environment import shell_environment, version_aggregator
Expand Down Expand Up @@ -196,6 +196,39 @@ def collect_python_pip_info(cls):
logging.info("{0} version: {1}".format(package.project_name, version))
ver_agg.ReportVersion(package.project_name, version, version_aggregator.VersionTypes.PIP)

@classmethod
def collect_rust_info(cls):
"""Class method to collect Rust tool versions.
Reports them to the global version_aggregator as well as print them to the screen.
"""
import re
from io import StringIO

def get_rust_tool_version(tool_name: str, tool_params: str = "--version"):
cmd_output = StringIO()
ret = RunCmd(tool_name, tool_params, outstream=cmd_output, logging_level=logging.DEBUG)
if ret == 0:
return cmd_output.getvalue().strip()
else:
return "N/A"

tools = {
"cargo": ("cargo",),
"cargo make": ("cargo", "make --version"),
"rustc": ("rustc",)
}

for tool_name, tool_cmd in tools.items():
ver = get_rust_tool_version(*tool_cmd)
match = re.search(r'(\d+\.\d+\.\d+)', ver)
if match:
ver = match.group(1)

logging.info(f"{tool_name} version: {ver}")
ver_agg = version_aggregator.GetVersionAggregator()
ver_agg.ReportVersion(tool_name, ver, version_aggregator.VersionTypes.TOOL)

def GetWorkspaceRoot(self) -> os.PathLike:
"""Returns the absolute path to the workspace root.
Expand Down
1 change: 1 addition & 0 deletions edk2toolext/invocables/edk2_ci_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def Go(self):
log_directory = os.path.join(self.GetWorkspaceRoot(), self.GetLoggingFolderRelativeToRoot())

Edk2CiBuild.collect_python_pip_info()
Edk2CiBuild.collect_rust_info()

# make Edk2Path object to handle all path operations
try:
Expand Down
1 change: 1 addition & 0 deletions edk2toolext/invocables/edk2_platform_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def Go(self):
logging.info("Running Python version: " + str(sys.version_info))

Edk2PlatformBuild.collect_python_pip_info()
Edk2PlatformBuild.collect_rust_info()

(build_env, shell_env) = self_describing_environment.BootstrapEnvironment(
self.GetWorkspaceRoot(), self.GetActiveScopes(), self.GetSkippedDirectories())
Expand Down

0 comments on commit fbfab9f

Please sign in to comment.