Skip to content

Commit 14f2911

Browse files
committed
Integrating changes from gitlab integration (vcast_exec.py) and for missing file detection
1 parent deedeed commit 14f2911

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

src/main/resources/scripts/create_index_html.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,28 @@ def getReportName(filename):
5858
return reportName, reportType
5959

6060
usingGitLabCI = False
61+
baseOutputDir = ""
6162

62-
def create_index_html(mpName, isGitLab = False):
63+
def create_index_html(mpName, isGitLab = False, output_dir = ""):
6364
import pathlib
6465
from vector.apps.DataAPI.vcproject_api import VCProjectApi
6566
from vector.apps.ReportBuilder.custom_report import CustomReport
6667

6768
global usingGitLabCI
6869
usingGitLabCI = isGitLab
6970

71+
global baseOutputDir
72+
baseOutputDir = output_dir
73+
7074
api = VCProjectApi(mpName)
7175
# Set custom report directory to the where this script was
7276
# found. Must contain sections/index_section.py
7377
rep_path = pathlib.Path(__file__).parent.resolve()
7478

7579
if usingGitLabCI:
76-
output_file="index.html"
80+
output_file=os.path.join(baseOutputDir,"index.html")
7781
else:
78-
output_file="index.html"
82+
output_file=os.path.join(baseOutputDir,"index.html")
7983

8084
CustomReport.report_from_api(
8185
api=api,
@@ -90,9 +94,9 @@ def create_index_html(mpName, isGitLab = False):
9094

9195
def create_index_html_body ():
9296

93-
tempHtmlReportList = glob.glob("*.html")
94-
tempHtmlReportList += glob.glob("html_reports/*.html")
95-
tempHtmlReportList += glob.glob("management/*.html")
97+
tempHtmlReportList = glob.glob(os.path.join(baseOutputDir,"*.html"))
98+
tempHtmlReportList += glob.glob(os.path.join(baseOutputDir,"html_reports/*.html"))
99+
tempHtmlReportList += glob.glob(os.path.join(baseOutputDir,"management/*.html"))
96100

97101
htmlReportList = []
98102
try:

src/main/resources/scripts/generate_pclp_reports.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ def generate_source():
303303
return output, listOfContent
304304

305305
def generate_html_report(mpName, input_xml, output_html):
306+
307+
if not os.path.exists(input_xml):
308+
print(f"{input_xml} was not found. Skipping PCLP HTML reporting")
309+
return
310+
306311
import pathlib
307312
from vector.apps.DataAPI.vcproject_api import VCProjectApi
308313
from vector.apps.ReportBuilder.custom_report import CustomReport
@@ -485,6 +490,11 @@ def write_output(output, filename):
485490
file.write(output.decode('utf-8'))
486491

487492
def generate_reports(input_xml, output_text = None, output_html = None, output_json = None, output_gitlab = None, full_mp_name = None):
493+
494+
if not os.path.exists(input_xml):
495+
print(f"{input_xml} was not found. Skipping PCLP reporting")
496+
return
497+
488498
msgs = parse_msgs(input_xml)
489499
msgs.sort(key=lambda msg: (msg.file == "", msg.file, int(msg.line) if msg.line != "" else 0))
490500
if output_text:

src/main/resources/scripts/vcast_exec.py

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ class CITool(Enum):
6464
BAMBOO = "Bamboo"
6565
UNKNOWN = "Unknown CI/CD"
6666

67+
def displayVersion():
68+
versionInfo = "Version Unknown"
69+
70+
# Get absolute path to directory containing the current script
71+
script_dir = os.path.dirname(os.path.abspath(__file__))
72+
73+
# Build path to VERSION.txt
74+
version_path = os.path.join(script_dir, 'VERSION.txt')
75+
76+
if os.path.exists(version_path):
77+
with open(version_path,"r") as fd:
78+
versionInfo = fd.read()
79+
print("vc_scripts_submodule Version: ", versionInfo)
80+
6781
class VectorCASTExecute(object):
6882

6983
def detect_ci_tool(self):
@@ -124,10 +138,12 @@ def __init__(self, args):
124138
self.failed_count = 0
125139

126140
if args.output_dir:
141+
self.output_dir = args.output_dir
127142
self.xml_data_dir = os.path.join(args.output_dir, 'xml_data')
128143
if not os.path.exists(self.xml_data_dir):
129144
os.makedirs(self.xml_data_dir)
130145
else:
146+
self.output_dir = ""
131147
self.xml_data_dir = "xml_data"
132148

133149
if args.build and not args.build_execute:
@@ -230,7 +246,8 @@ def generateIndexHtml(self):
230246
prj_dir = os.getcwd().replace("\\","/") + "/"
231247

232248
tempHtmlReportList = glob.glob("*.html")
233-
tempHtmlReportList += glob.glob(os.path.join(args.html_base_dir, "*.html"))
249+
tempHtmlReportList += glob.glob(os.path.join(self.xml_data_dir, "*.html"))
250+
tempHtmlReportList += glob.glob(os.path.join(self.html_base_dir, "*.html"))
234251
htmlReportList = []
235252

236253
for report in tempHtmlReportList:
@@ -240,7 +257,7 @@ def generateIndexHtml(self):
240257
htmlReportList.append(report)
241258

242259
from create_index_html import create_index_html
243-
create_index_html(self.FullMP, self.ciTool == CITool.GITLAB)
260+
create_index_html(self.FullMP, self.ciTool == CITool.GITLAB, output_dir=self.output_dir)
244261

245262
def runJunitMetrics(self):
246263
print("Creating JUnit Metrics")
@@ -323,29 +340,38 @@ def runPcLintPlusMetrics(self):
323340
print("PC-lint Plus Metrics file: " + report_name)
324341
generate_pclp_reports.generate_reports(self.pclp_input, output_gitlab = report_name)
325342

326-
if args.pclp_output_html:
343+
if self.pclp_output_html:
327344
print("Creating PC-lint Plus Findings")
328345
generate_pclp_reports.generate_html_report(self.FullMP, self.pclp_input, self.pclp_output_html)
329346

330347
def runReports(self):
331348
if self.aggregate:
349+
agg_rpt_name = os.path.join(self.output_dir, self.mpName + "_aggregate_report.html")
332350
print("Creating Aggregate Coverage Report")
333-
self.manageWait.exec_manage_command ("--create-report=aggregate --output=" + self.mpName + "_aggregate_report.html")
351+
if os.path.exists(agg_rpt_name):
352+
os.remove(agg_rpt_name)
353+
self.manageWait.exec_manage_command ("--create-report=aggregate --output=" + agg_rpt_name)
334354
self.needIndexHtml = True
335355
if self.metrics:
356+
met_rpt_name = os.path.join(self.output_dir, self.mpName + "_metrics_report.html")
336357
print("Creating Metrics Report")
337-
self.manageWait.exec_manage_command ("--create-report=metrics --output=" + self.mpName + "_metrics_report.html")
358+
if os.path.exists(met_rpt_name):
359+
os.remove(met_rpt_name)
360+
self.manageWait.exec_manage_command ("--create-report=metrics --output=" + met_rpt_name)
338361
self.needIndexHtml = True
339362
if self.fullstatus:
363+
fs_rpt_name = os.path.join(self.output_dir, self.mpName + "_full_status_report.html")
364+
if os.path.exists(fs_rpt_name):
365+
os.remove(fs_rpt_name)
340366
print("Creating Full Status Report")
341-
self.manageWait.exec_manage_command ("--full-status=" + self.mpName + "_full_status_report.html")
367+
self.manageWait.exec_manage_command ("--full-status=" + fs_rpt_name)
342368
self.needIndexHtml = True
343369

344370
def generateTestCaseMgtRpt(self):
345-
if not os.path.exists("management"):
346-
os.makedirs("management")
371+
if not os.path.exists(os.path.join(self.output_dir, "management")):
372+
os.makedirs(os.path.join(self.output_dir, "management"))
347373
else:
348-
for file in glob.glob("management/*_management_report.html"):
374+
for file in glob.glob(os.path.join(self.output_dir, "management","*_management_report.html")):
349375
os.remove(file)
350376

351377
if checkVectorCASTVersion(21):
@@ -360,7 +386,7 @@ def generateTestCaseMgtRpt(self):
360386
self.needIndexHtml = True
361387

362388
report_name = env.compiler.name + "_" + env.testsuite.name + "_" + env.name + "_management_report.html"
363-
report_name = os.path.join("management",report_name)
389+
report_name = os.path.join(self.output_dir, "management",report_name)
364390
print(f"Creating Test Case Management HTML report for {env.name} in {report_name}")
365391
env.api.report(report_type="MANAGEMENT_REPORT", formats=["HTML"], output_file=report_name)
366392
else:
@@ -424,7 +450,7 @@ def runExec(self):
424450
if __name__ == '__main__':
425451

426452
parser = argparse.ArgumentParser()
427-
parser.add_argument('ManageProject', help='VectorCAST Project Name')
453+
parser.add_argument('ManageProject', nargs='?', help='VectorCAST Project Name')
428454

429455
actionGroup = parser.add_argument_group('Script Actions', 'Options for the main tasks')
430456
actionGroup.add_argument('--build-execute', help='Builds and exeuctes the VectorCAST Project', action="store_true", default = False)
@@ -469,10 +495,24 @@ def runExec(self):
469495
actionGroup.add_argument('--print_exc', help='Prints exceptions', action="store_true", default = False)
470496
actionGroup.add_argument('--timing', help='Prints timing information for metrics generation', action="store_true", default = False)
471497
actionGroup.add_argument('-v', '--verbose', help='Enable verbose output', action="store_true", default = False)
472-
498+
actionGroup.add_argument('--version', help='Displays the version information', action="store_true", default = False)
473499

474500
args = parser.parse_args()
475501

502+
# Conditional requirement check
503+
if not args.version and not args.ManageProject:
504+
parser.error("ManageProject is required unless --version is specified")
505+
sys.exit(0)
506+
507+
if args.ManageProject and not os.path.isfile(args.ManageProject):
508+
print ("Manage project (.vcm file) provided does not exist: " + args.ManageProject)
509+
print ("exiting...")
510+
sys.exit(-1)
511+
512+
if args.version:
513+
displayVersion()
514+
sys.exit(0)
515+
476516
if args.ci:
477517
os.environ['VCAST_USE_CI_LICENSES'] = "1"
478518

0 commit comments

Comments
 (0)