172 lines
6.4 KiB
Groovy
172 lines
6.4 KiB
Groovy
def doDisplayLeftovers() {
|
|
}
|
|
|
|
def doKillLeftovers() {
|
|
}
|
|
|
|
def doCheck(checkpathlist, build_variant = "") {
|
|
def result = 0
|
|
for (checkpath in checkpathlist) {
|
|
echo "Checking file at: ${checkpath}"
|
|
script {
|
|
echo "Build variant is ${build_variant}"
|
|
if (build_variant) {
|
|
def srcFile = "${WORKSPACE}\${checkpath}"
|
|
def srcFileExpanded = srcFile.replace("-BUILDVARIANT-", "${build_variant}")
|
|
// Print out dependencies of the built file
|
|
echo "Showing dependencies of ${srcFileExpanded}"
|
|
if (srcFileExpanded.endsWith(".elf")) {
|
|
result = bat ( script: """
|
|
${CYGWINDIR}/bin/readelf -hS ${srcFileExpanded}
|
|
if errorlevel 1 EXIT /b 1
|
|
""",
|
|
returnStatus: true
|
|
)
|
|
}
|
|
if (result != 0) {
|
|
return result
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
def doExport(exportfolder, exportpathlist, partdest = "", build_variant = "") {
|
|
def result = 0
|
|
def destFolder = ""
|
|
def srcFile = ""
|
|
def srcFileExpanded = ""
|
|
for (exportpath in exportpathlist) {
|
|
echo "Export path at: ${exportpath}"
|
|
script {
|
|
if (build_variant) {
|
|
echo "Build variant is ${build_variant}"
|
|
srcFile = "${WORKSPACE}\\${exportpath}"
|
|
srcFileExpanded = srcFile.replace("-BUILDVARIANT-", "${build_variant}")
|
|
}
|
|
else {
|
|
echo "No build variant"
|
|
srcFileExpanded = "${WORKSPACE}\\${exportpath}"
|
|
}
|
|
destFolder = "${exportfolder}"
|
|
if (partdest) {
|
|
destFolder += "\\" + partdest
|
|
}
|
|
}
|
|
def destFolderExpanded = destFolder.replace("-BUILDVARIANT-", "${build_variant}")
|
|
dir (destFolderExpanded) {
|
|
echo "Copy \"${srcFileExpanded}\" to \"${destFolderExpanded}\""
|
|
result = bat( script: """
|
|
copy "${srcFileExpanded}" "${destFolderExpanded}"
|
|
if errorlevel 1 EXIT /b 1
|
|
""",
|
|
returnStatus: true
|
|
)
|
|
if (result != 0) {
|
|
return result
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
// Import all eclipse projects in a given folder
|
|
def doImportProjects(ds5folder, ds5shellcommand, buildcommand, sourcefolder) {
|
|
bat """
|
|
"${ds5shellcommand}" ${buildcommand} -no-indexer -importAll "${sourcefolder}"
|
|
"""
|
|
}
|
|
|
|
def doBuildAndExportProject(String ds5folder, String ds5shellcommand, String buildcommand, String project, Boolean doexport, variants, String exportfolder, exportpathlist, String destpart) {
|
|
echo "Doing build and export project: ${project} : ${doexport}"
|
|
for (build_variant in variants) {
|
|
retry(maxprojectbuildretries) { // Eclipse occasionally raises exceptions (rather than the builds failing)
|
|
try {
|
|
if (toBuild.contains(build_variant)) {
|
|
doDisplayLeftovers()
|
|
echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer -build ${project}/${build_variant}\'"
|
|
timeout(time: 20, unit: 'MINUTES') {
|
|
bat """
|
|
"${ds5shellcommand}" ${buildcommand} -no-indexer -build ${project}/${build_variant}
|
|
"""
|
|
}
|
|
result = doCheck(exportpathlist, build_variant)
|
|
if (result != 0) {
|
|
error "Failed to check files...."
|
|
}
|
|
echo "Doing export: ${doexport}"
|
|
if (doexport) {
|
|
result = doExport(exportfolder, exportpathlist, destpart, build_variant)
|
|
if (result != 0) {
|
|
error "Failed to copy...."
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
echo "Not building ${build_variant} variant of project: ${project}"
|
|
}
|
|
} catch (Exception e) {
|
|
echo "Exception: ${e.getMessage()}\nBuild failed - Waiting for a while"
|
|
sleep(time: 4, unit: 'SECONDS')
|
|
error "Build failed..."
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def doExportOnlyProject(String project, Boolean doexport, variants, String exportfolder, exportpathlist, String destpart) {
|
|
echo "Doing export only project: ${project} : ${doexport}"
|
|
if (doexport) {
|
|
if (!variants) {
|
|
result = doExport(exportfolder, exportpathlist, destpart)
|
|
if (result != 0) {
|
|
error "Failed to copy...."
|
|
}
|
|
} else {
|
|
for (build_variant in variants) {
|
|
if (toBuild.contains(build_variant)) {
|
|
result = doExport(exportfolder, exportpathlist, destpart, build_variant)
|
|
if (result != 0) {
|
|
error "Failed to copy...."
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Build and export files
|
|
def doBuild(apps, ds5folder, ds5shellcommand, buildcommand, sourcefolder, variantstobuild, exportfolder = "${WORKSPACE}") {
|
|
toBuild = []
|
|
if (variantstobuild) {
|
|
toBuildUntrimmed = variantstobuild.split(',')
|
|
toBuildUntrimmed.each {
|
|
toBuild.add(it.trim())
|
|
}
|
|
}
|
|
// The lock is being used because it was being found that the doKillLeftovers was affecting other builds
|
|
lock(resource: "eclipsebuild_${env.NODE_NAME}") {
|
|
try {
|
|
timeout(time: 5, unit: 'MINUTES') {
|
|
doImportProjects(ds5folder, ds5shellcommand, buildcommand, sourcefolder)
|
|
}
|
|
for (appInfo in apps) {
|
|
def Boolean build
|
|
def Boolean doexport
|
|
(build, doexport, project, variants, exportpathlist, destpart) = appInfo
|
|
if (build) {
|
|
doBuildAndExportProject(ds5folder, ds5shellcommand, buildcommand, project, doexport, variants, exportfolder, exportpathlist, destpart)
|
|
}
|
|
else {
|
|
doExportOnlyProject(project, doexport, variants, exportfolder, exportpathlist, destpart)
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
// doKillLeftovers()
|
|
error "Exception: ${e.getMessage()}\nBuild failed - Killing leftovers"
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|