]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Plugin/BuildToolsReport/BuildToolsReportGenerator.py
BaseTools: Add BaseTools plugins to support CI
[mirror_edk2.git] / BaseTools / Plugin / BuildToolsReport / BuildToolsReportGenerator.py
CommitLineData
de4ce46d
SB
1##\r
2# Copyright (c) Microsoft Corporation.\r
3# SPDX-License-Identifier: BSD-2-Clause-Patent\r
4##\r
5import os\r
6import logging\r
7import json\r
8\r
9try:\r
10 from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin\r
11\r
12 class BuildToolsReportGenerator(IUefiBuildPlugin):\r
13 def do_report(self, thebuilder):\r
14 try:\r
15 from edk2toolext.environment import version_aggregator\r
16 except ImportError:\r
17 logging.critical("Loading BuildToolsReportGenerator failed, please update your Edk2-PyTool-Extensions")\r
18 return 0\r
19\r
20 OutputReport = os.path.join(thebuilder.env.GetValue("BUILD_OUTPUT_BASE"), "BUILD_TOOLS_REPORT")\r
21 OutputReport = os.path.normpath(OutputReport)\r
22 if not os.path.isdir(os.path.dirname(OutputReport)):\r
23 os.makedirs(os.path.dirname(OutputReport))\r
24\r
25 Report = BuildToolsReport()\r
26 Report.MakeReport(version_aggregator.GetVersionAggregator().GetAggregatedVersionInformation(), OutputReport=OutputReport)\r
27\r
28 def do_pre_build(self, thebuilder):\r
29 self.do_report(thebuilder)\r
30 return 0\r
31\r
32 def do_post_build(self, thebuilder):\r
33 self.do_report(thebuilder)\r
34 return 0\r
35\r
36except ImportError:\r
37 pass\r
38\r
39\r
40class BuildToolsReport(object):\r
41 MY_FOLDER = os.path.dirname(os.path.realpath(__file__))\r
42 VERSION = "1.00"\r
43\r
44 def __init__(self):\r
45 pass\r
46\r
47 def MakeReport(self, BuildTools, OutputReport="BuildToolsReport"):\r
48 logging.info("Writing BuildToolsReports to {0}".format(OutputReport))\r
49 versions_list = []\r
50 for key, value in BuildTools.items():\r
51 versions_list.append(value)\r
52 versions_list = sorted(versions_list, key=lambda k: k['type'])\r
53 json_dict = {"modules": versions_list,\r
54 "PluginVersion": BuildToolsReport.VERSION}\r
55\r
56 htmlfile = open(OutputReport + ".html", "w")\r
57 jsonfile = open(OutputReport + ".json", "w")\r
58 template = open(os.path.join(BuildToolsReport.MY_FOLDER, "BuildToolsReport_Template.html"), "r")\r
59\r
60 for line in template.readlines():\r
61 if "%TO_BE_FILLED_IN_BY_PYTHON_SCRIPT%" in line:\r
62 line = line.replace("%TO_BE_FILLED_IN_BY_PYTHON_SCRIPT%", json.dumps(json_dict))\r
63 htmlfile.write(line)\r
64\r
65 jsonfile.write(json.dumps(versions_list, indent=4))\r
66\r
67 jsonfile.close()\r
68 template.close()\r
69 htmlfile.close()\r