Skip to content

Commit 838a961

Browse files
committed
Updates for sharedArtifactDirectory reporting issue
1 parent 75ec75a commit 838a961

File tree

2 files changed

+116
-33
lines changed

2 files changed

+116
-33
lines changed

src/main/resources/scripts/baseJenkinsfile.groovy

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ def transformIntoStep(inputString) {
554554
"""
555555
}
556556

557-
558557
// setup build lot test variable to hold all VC commands results for this job
559558
def buildLogText = ""
560559

@@ -866,6 +865,7 @@ pipeline {
866865

867866
// run script to unstash files and generate results/reports
868867
script {
868+
def buildLogText = ""
869869
def buildFileNames = ""
870870

871871
// Loop over all environnment and unstash each of the files
@@ -882,23 +882,46 @@ pipeline {
882882
catch (Exception ex) {
883883
println ex
884884
}
885+
if (VC_sharedArtifactDirectory.length() > 0) {
886+
def fixedJobName = fixUpName("${env.JOB_NAME}")
887+
buildLogText += runCommands("""_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/copy_build_dir.py ${VC_Manage_Project} --level ${compiler}/${test_suite} --basename ${fixedJobName}_${compiler}_${test_suite}_${environment} --environment ${environment} --notar""")
888+
}
889+
}
890+
891+
if (VC_sharedArtifactDirectory.length() > 0) {
892+
def artifact_dir = ""
893+
try {
894+
artifact_dir = VC_sharedArtifactDirectory.split(" ")[1]
895+
}
896+
catch (Exception ex) {
897+
artifact_dir = VC_sharedArtifactDirectory.split("=")[1]
898+
}
899+
def coverDBpath = formatPath(artifact_dir + "/vcast_data/cover.db")
900+
def coverSfpDBpath = formatPath(artifact_dir + "/vcast_data/vcprj.db")
901+
902+
cmds = """
903+
_RM ${coverDBpath}
904+
_RM ${coverSfpDBpath}
905+
_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/managewait.py --wait_time ${VC_waitTime} --wait_loops ${VC_waitLoops} --command_line "--project "${VC_Manage_Project}" ${VC_UseCILicense} --refresh"
906+
"""
907+
buildLogText += runCommands(cmds)
885908
}
886909

887910
concatenateBuildLogs(buildFileNames, "unstashed_build.log")
888911

889912
// get the manage project's base name for use in rebuild naming
890913
def mpName = getMPname()
891914

892-
def buildLogText = ""
893915

894916
// if we are using SCM and not using a shared artifact directory...
895917
if (VC_usingSCM && !VC_useOneCheckoutDir && VC_sharedArtifactDirectory.length() == 0) {
896918
// run a script to extract stashed files and process data into xml reports
897919
def mpPath = getMPpath()
898920
def coverDBpath = formatPath(mpPath + "/build/vcast_data/cover.db")
899-
921+
def coverSfpDBpath = formatPath(mpPath + "/build/vcast_data/vcprj.db")
900922
cmds = """
901923
_RM ${coverDBpath}
924+
_RM ${coverSfpDBpath}
902925
_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/extract_build_dir.py --leave_files
903926
_VECTORCAST_DIR/vpython "${env.WORKSPACE}"/vc_scripts/managewait.py --wait_time ${VC_waitTime} --wait_loops ${VC_waitLoops} --command_line "--project "${VC_Manage_Project}" ${VC_UseCILicense} --refresh"
904927
"""

src/main/resources/scripts/copy_build_dir.py

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,41 @@
2828
import tarfile
2929
import sqlite3
3030
import shutil
31+
import argparse
3132

33+
try:
34+
## This tests to see if 2018 is present.
35+
from vector.apps.ReportBuilder.custom_report import CustomReport
36+
try:
37+
from vector.apps.DataAPI.unit_test_api import UnitTestApi
38+
except:
39+
from vector.apps.DataAPI.api import Api as UnitTestApi
40+
except:
41+
pass
42+
43+
try:
44+
from vector.apps.DataAPI.vcproject_api import VCProjectApi
45+
except:
46+
pass
3247

33-
def make_relative(path, workspace):
48+
def make_relative(path, workspace, vCastProjectWorkspace, ManageProjectName):
3449

3550
path = path.replace("\\","/")
3651

52+
53+
if path.endswith('.LIS') or '000000' in path:
54+
return path
55+
3756
if not os.path.isabs(path):
3857
return path
3958

4059
# if the paths match
4160
if path.lower().startswith(workspace.lower()):
42-
path = path[len(workspace)+1:]
61+
if "@" in path:
62+
path = path[len(workspace):]
63+
path = path.split("/",1)[1]
64+
else:
65+
path = path[len(workspace)+1:]
4366

4467
# if the paths match except for first character (d:\ changed to j:\)
4568
elif path.lower()[1:].startswith(workspace.lower()[1:]):
@@ -51,17 +74,21 @@ def make_relative(path, workspace):
5174

5275
path = path[workspaceIndex:].split("/",2)[2]
5376

77+
elif vCastProjectWorkspace is not None and vCastProjectWorkspace.lower() in path.lower():
78+
path = path.replace(vCastProjectWorkspace,"")
79+
path = ManageProjectName[:-4].replace("\\", "/") + path
80+
5481
else:
5582
print(" Warning: Unable to convert source file: " + path + " to relative path based on WORKSPACE: " + workspace)
56-
83+
5784
return path
5885

5986

60-
def updateDatabase(conn, nocase, workspace, updateWhat, updateFrom):
87+
def updateDatabase(conn, nocase, workspace, updateWhat, updateFrom, vCastProjectWorkspace, ManageProjectName):
6188
sql = "SELECT id, %s FROM %s" % (updateWhat, updateFrom)
6289
files = conn.execute(sql)
6390
for id_, path in files:
64-
relative = make_relative(path,workspace)
91+
relative = make_relative(path,workspace, vCastProjectWorkspace, ManageProjectName)
6592
sql = "UPDATE %s SET %s = '%s' WHERE id=%s COLLATE NOCASE" % (updateFrom, updateWhat, relative, id_)
6693
conn.execute(sql)
6794

@@ -93,11 +120,12 @@ def addDirectory(tf, build_dir, dir):
93120
for fname in fileList:
94121
tf.add(os.path.join(dirName, fname))
95122

96-
def addConvertCoverFile(tf, file, workspace, build_dir, nocase):
97-
98-
print("Updating cover.db")
123+
def addConvertCoverFile(tf, file, workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar):
124+
99125
fullpath = build_dir + os.path.sep + file
100126
bakpath = fullpath + '.bk'
127+
128+
print("Updating cover.db: ", fullpath)
101129

102130
if os.path.isfile(fullpath):
103131
conn = sqlite3.connect(fullpath)
@@ -106,41 +134,45 @@ def addConvertCoverFile(tf, file, workspace, build_dir, nocase):
106134

107135
# update the database paths to be relative from workspace
108136
try:
109-
updateDatabase(conn, nocase, workspace, "LIS_file", "instrumented_files")
137+
updateDatabase(conn, nocase, workspace, "LIS_file", "instrumented_files", vCastProjectWorkspace, ManageProjectName)
110138
except:
111-
updateDatabase(conn, nocase, workspace, "path", "lis_files")
112-
updateDatabase(conn, nocase, workspace, "display_path", "source_files")
113-
updateDatabase(conn, nocase, workspace, "path", "source_files")
139+
updateDatabase(conn, nocase, workspace, "path", "lis_files" , vCastProjectWorkspace, ManageProjectName)
140+
updateDatabase(conn, nocase, workspace, "display_path", "source_files", vCastProjectWorkspace, ManageProjectName)
141+
updateDatabase(conn, nocase, workspace, "path", "source_files", vCastProjectWorkspace, ManageProjectName)
114142

115143
conn.commit()
116144
conn.close()
117145
addFile(tf, file, build_dir)
118-
os.remove(fullpath)
119-
shutil.move(bakpath, fullpath)
146+
if not noTar:
147+
os.remove(fullpath)
148+
shutil.move(bakpath, fullpath)
120149

121-
def addConvertMasterFile(tf, file, workspace, build_dir, nocase):
150+
def addConvertMasterFile(tf, file, workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar):
122151
print("Updating master.db")
123152
fullpath = build_dir + os.path.sep + file
124153
bakpath = fullpath + '.bk'
125154
if os.path.isfile(fullpath):
126155
conn = sqlite3.connect(fullpath)
127156
if conn:
128157
shutil.copyfile(fullpath, bakpath)
129-
updateDatabase(conn, nocase, workspace, "path", "sourcefiles")
158+
updateDatabase(conn, nocase, workspace, "path", "sourcefiles", vCastProjectWorkspace, ManageProjectName)
130159
conn.commit()
131160
conn.close()
132161
addFile(tf, file, build_dir)
133-
os.remove(fullpath)
134-
shutil.move(bakpath, fullpath)
162+
if not noTar:
163+
os.remove(fullpath)
164+
shutil.move(bakpath, fullpath)
165+
166+
def addConvertFiles(tf, workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar):
167+
addConvertCoverFile (tf, "cover.db", workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar)
168+
addConvertMasterFile(tf, "master.db", workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar)
135169

136-
def addConvertFiles(tf, workspace, build_dir, nocase):
137-
addConvertCoverFile (tf, "cover.db", workspace, build_dir, nocase)
138-
addConvertMasterFile(tf, "master.db", workspace, build_dir, nocase)
139170

140-
def run(ManageProjectName, Level, BaseName, Env, workspace):
171+
def run(ManageProjectName, Level, BaseName, Env, workspace, vCastProjectWorkspace, noTar):
141172

142173
if sys.platform.startswith('win32'):
143174
workspace = workspace.replace("\\", "/")
175+
vCastProjectWorkspace = vCastProjectWorkspace.replace("\\", "/")
144176
nocase = "COLLATE NOCASE"
145177
else:
146178
nocase = ""
@@ -168,9 +200,12 @@ def run(ManageProjectName, Level, BaseName, Env, workspace):
168200

169201
if build_dir != "":
170202
build_dir = build_dir + os.path.sep + Env
171-
tf = tarfile.open(BaseName + "_build.tar", mode='w')
203+
if noTar:
204+
tf = tarfile.open("delete_me_" + BaseName + "_build.tar", mode='w')
205+
else:
206+
tf = tarfile.open(BaseName + "_build.tar", mode='w')
172207
try:
173-
addConvertFiles(tf, workspace, build_dir, nocase)
208+
addConvertFiles(tf, workspace, build_dir, nocase, vCastProjectWorkspace, ManageProjectName, noTar)
174209
addFile(tf, "testcase.db", build_dir)
175210
addFile(tf, "COMMONDB.VCD", build_dir)
176211
addFile(tf, "UNITDATA.VCD", build_dir)
@@ -195,14 +230,39 @@ def run(ManageProjectName, Level, BaseName, Env, workspace):
195230

196231
finally:
197232
tf.close()
233+
234+
if noTar:
235+
os.remove("delete_me_" + BaseName + "_build.tar")
236+
237+
238+
def getVcastProjectWorkspace(args):
198239

240+
with VCProjectApi(args.ManageProject) as vc_api:
241+
# vc_api = VCProjectApi(args.ManageProject)
242+
vCastProjectWorkspace = vc_api.project.workspace
199243

244+
return vCastProjectWorkspace
245+
200246
if __name__ == '__main__':
201-
202-
ManageProjectName = sys.argv[1]
203-
Level = sys.argv[2]
204-
BaseName = sys.argv[3]
205-
Env = sys.argv[4]
247+
248+
249+
parser = argparse.ArgumentParser()
250+
parser.add_argument('ManageProject', help='Manager Project Name')
251+
parser.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of level/env', default="NotProvided/NotProvided")
252+
parser.add_argument('-b', '--basename', help='Enable verbose output', default="")
253+
parser.add_argument('-e', '--environment', help='Enable verbose output', default="")
254+
parser.add_argument('--notar', help='Don\'t Product a tar file', default=False, action="store_true")
255+
parser.add_argument('-v', '--verbose', help='Enable verbose output', action="store_true")
256+
257+
args = parser.parse_args()
258+
259+
ManageProjectName = args.ManageProject
260+
Level = args.level
261+
BaseName = args.basename
262+
Env = args.environment
263+
vCastProjectWorkspace = getVcastProjectWorkspace(args)
264+
noTar = args.notar
265+
206266
workspace = os.getenv("WORKSPACE")
207267

208268
if workspace is None:
@@ -213,5 +273,5 @@ def run(ManageProjectName, Level, BaseName, Env, workspace):
213273

214274
os.environ['VCAST_MANAGE_PROJECT_DIRECTORY'] = os.path.abspath(ManageProjectName).rsplit(".",1)[0]
215275

216-
run(ManageProjectName, Level, BaseName, Env, workspace)
276+
run(ManageProjectName, Level, BaseName, Env, workspace, vCastProjectWorkspace, noTar)
217277

0 commit comments

Comments
 (0)