#!/usr/bin/env python import sys, json, yaml import os import subprocess from shutil import copy2 from shutil import copyfile from os.path import expanduser from util_functions import util_functions from util_functions import ct_functions from util_functions import step_functions # doyCTbuild arguments: # 1. subfolder of file in HOST:DIRN # 2. local folder for file # 3. configuration file name # 4. ctconfig # 5. ctparams # 6. build system # 7. theplatform # 8. os size of slave # 9. installocation # 10... datastore def main(argv): print ('{}={}:{}:{}:{}:{}:{}:{}:{}:{}:{}'.format(sys.argv[0],sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7],sys.argv[8],sys.argv[9],sys.argv[10])) HOST = sys.argv[1] DIRN = sys.argv[2] configfile = sys.argv[3] buildconfig = sys.argv[4] ctparams = sys.argv[5] buildsys = sys.argv[6] theplatform = sys.argv[7] theossize = sys.argv[8] installocation = sys.argv[9] datastore = {} datastore = eval(argv[10]) toolsets = datastore['toolsets'] compilers = datastore['compilers'] modules = datastore['modules'] generator = datastore['generator'] schedule = datastore['scheduler'] compilername = util_functions.VS_full_to_short(generator) buildtype = 'Release' script_path, script_name = os.path.split(sys.argv[0]) userhome = expanduser("~") bbuserhome = os.path.join(userhome, '.buildbot') util_functions.getPlatforms(buildsys) script_res = {ctparams+'-'+script_name: 'SKIPPED'} thereturncode = 0 if os.path.exists('{}'.format(bbuserhome)): worker_params_file = os.path.join(bbuserhome, 'bbworker.json') try: with open(worker_params_file, 'r') as json_worker_params_file: json_worker_params_data = json.load(json_worker_params_file) toolsets = json_worker_params_data['worker']['toolsets'] compilers = json_worker_params_data['worker']['compilers'] compilervers = json_worker_params_data['worker']['compilervers'] modules = json_worker_params_data['worker']['modules'] #print('compilervers={}'.format(compilervers)) except: toolsets = {'default': ['default']} compilers = ['C'] compilervers = [{'compiler':'C', 'module':'default', 'name':'default', 'command':'default', 'version':'default'}] modules = {'use': ''} else: toolsets = datastore['toolsets'] compilers = datastore['compilers'] compilervers = [{'compiler':'default', 'module':'default', 'name':'default', 'command':'default', 'version':'default'}] modules = datastore['modules'] scriptdir = os.getcwd() #### print('scriptdir={}'.format(scriptdir)) source_dir = '{}/../hdfsrc'.format(scriptdir) jsparams_file = 'bb_params.json' if scriptdir.split(os.sep)[-1] == buildsys: jsparams_file = '../bb_params.json' with open(jsparams_file, 'r') as json_bbparams_file: json_bbparams_data = json.load(json_bbparams_file) if 'Fortran' in compilers: HAVE_FORTRAN = 'ON' else: HAVE_FORTRAN = 'OFF' if 'CXX' in compilers: HAVE_CXX = 'ON' else: HAVE_CXX = 'OFF' if 'Java' in compilers: HAVE_JAVA = 'ON' else: HAVE_JAVA = 'OFF' # Load configuration file with open(configfile, 'r') as yaml_file: yaml_data = yaml.safe_load(yaml_file) #print(yaml_data) if buildsys in yaml_data['configfile'][buildconfig][ctparams]['buildsys']: if 'nightly' in schedule.lower() and not 'ec2' in schedule.lower(): cdashmodel = 'Nightly' else: cdashmodel = 'BuildBot' # configure script_tc_res = {ctparams+'-'+script_name+'-config': 'SKIPPED'} thescriptreturncode = 0 target_binaries = [] #target_binaries = util_functions.format_binary_name_list(theplatform, yaml_data['configfile'], buildconfig, ctparams, buildsys, compilername, theossize, True, False) print ('target_binaries {}'.format(target_binaries)) for testparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']: if 'usetoolsets' in testparam: toolsets = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']['usetoolsets'] configToolset = 'default' if 'MPI' in buildconfig: configToolset = 'MPI' for toolset in toolsets[configToolset]: thereturncode = 0 print('toolset={}'.format(toolset)) os.chdir(scriptdir) currdir=os.getcwd() #### print ('current={}'.format(currdir)) ts_path = 'hdfbld' ts_mod = 'default' if toolset != 'default': if theplatform.lower() in util_functions.WinPlatforms: ts_path = (toolset.split(None, 1))[0] else: if 'mingw' in toolset: ts_path = (toolset.split(None, 1))[0] else: ts_mod = (toolset.split('/', 1))[0] ts_path = (toolset.split('/', 1))[1] for mod in modules: k = mod v = modules[k] util_functions.module(k, v) util_functions.module('load', '{}'.format(toolset)) installdir = installocation if not os.path.exists('{}'.format(installocation)): os.mkdir(installocation) if not os.path.exists('{}'.format(ts_path)): os.mkdir(ts_path) installdir += '/' + ts_path if not os.path.exists('{}'.format(installdir)): os.mkdir(installdir) for btparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]: if 'envparams' in btparam: envparams = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['envparams'] #print ('tconf env == {}'.format(envparams)) if 'ftpbinary' in envparams: if envparams['ftpbinary']: if ctparams == 'bbparams': for envparam in envparams: if 'binaryfolder' in envparam: installdir += '/' + envparams['binaryfolder'] else: installdir += '/' + ctparams script_tc_res.update({ctparams+'-installfolder':installdir}) json_bbparams_data.append(script_tc_res) currdir=os.getcwd() #### print ('current={} install={}'.format(currdir, installdir)) installfolder = os.path.join(currdir, installdir) print ('install directory = {}'.format(installfolder)) thereturncode = step_functions.ftp_uncompress(json_bbparams_data, HOST, DIRN, theplatform, toolset, ts_path, installdir, target_binaries) if thereturncode == 0 and len(target_binaries) > 0: thereturncode = step_functions.install_binary(json_bbparams_data, buildsys, theplatform, installdir, 'install') os.chdir(currdir) #### if thereturncode == 255: json_bbparams_data.append(script_res) with open(jsparams_file, 'w') as json_bbparams_file: json.dump(json_bbparams_data, json_bbparams_file) raise Exception('Unable to get and uncompress file') os.chdir(ts_path) print ('ctparams is {}'.format(ctparams)) if not 'bbparams' in ctparams: if not os.path.exists('{}'.format(ctparams)): os.mkdir(ctparams) os.chdir(ctparams) builddir = os.getcwd() print('builddir={}'.format(builddir)) confilename = 'HDFoptions.cmake' confiledir = '.' for ctparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]: if 'envparams' in ctparam: envparams = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['envparams'] #print ('tconf env == {}'.format(envparams)) for envparam in envparams: if 'cdash_model' in envparam: if 'ec2' in schedule.lower(): cdashmodel = 'BuildBot' else: cdashmodel = envparams['cdash_model'] if 'ctest_optname' in envparam: confilename = envparams['ctest_optname'] if 'ctest_optdir' in envparam: confiledir = envparams['ctest_optdir'] if not os.path.exists('{}'.format(confiledir)): os.mkdir(confiledir) os.chdir(confiledir) print('currdir={}'.format(os.getcwd())) conffile = open(confilename,'w') conffile.write('###################################################################\n') conffile.write('######### Following is for submission to CDash ############\n') conffile.write('###################################################################\n') conffile.write('set(MODEL "{}")\n'.format(cdashmodel)) conffile.write('##### Following controls CDash submission #####\n') conffile.write('set(LOCAL_SUBMIT "TRUE")\n') conffile.write('###################################################################\n') for testparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']: if 'ctest_opts' in testparam: ct_functions.ctest_sets(conffile, yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']['ctest_opts']) elif 'ctest_conf' in testparam: ct_functions.ctest_options(conffile, yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']['ctest_conf'], HAVE_FORTRAN, HAVE_CXX, HAVE_JAVA) if theplatform.startswith("10vs"): conffile.write('set(SITE_OS_VERSION "10")\n') elif theplatform.startswith("vs"): conffile.write('set(SITE_OS_VERSION "7")\n') if toolset != 'default': if theplatform.lower() in util_functions.WinPlatforms: conffile.write('set(CMAKE_GENERATOR_TOOLSET "{}")\n'.format(toolset)) else: if os.path.exists('{}/config/toolchain/{}.cmake'.format(source_dir, ts_path)): conffile.write('set(ADD_BUILD_OPTIONS "${{ADD_BUILD_OPTIONS}} -DCMAKE_TOOLCHAIN_FILE:STRING=config/toolchain/{}.cmake")\n'.format(ts_path)) conffile.write('if(SITE_BUILDNAME_SUFFIX)\n') conffile.write(' set(SITE_BUILDNAME_SUFFIX "-${SITE_BUILDNAME_SUFFIX}")\n') conffile.write('endif()\n') conffile.write('set(SITE_BUILDNAME_SUFFIX "{}-{}${{SITE_BUILDNAME_SUFFIX}}")\n'.format(schedule, ts_path)) conffile.close() if not os.path.exists('{}'.format(confilename)): script_tc_res = {ctparams+'-'+script_name+'-config': 'FAILURE'} json_bbparams_data.append(script_tc_res) with open(jsparams_file, 'w') as json_bbparams_file: json.dump(json_bbparams_data, json_bbparams_file) raise Exception('ctest config failure: file not found') else: script_tc_res = {ctparams+'-'+script_name+'-config': 'SUCCESS'} json_bbparams_data.append(script_tc_res) os.chdir(scriptdir) print('currdir={}'.format(os.getcwd())) # do the run script_tc_res = {ctparams+'-'+script_name+'-run': 'SKIPPED'} thereturncode = 0 currdir=os.getcwd() #### print ('current={}'.format(currdir)) # get config buildtype for testparam in yaml_data['configfile'][buildconfig]['bbparams']['testparams']: if 'buildtype' in testparam: buildtype = yaml_data['configfile'][buildconfig]['bbparams']['testparams']['buildtype'] print ('bb buildtype={}'.format(buildtype)) # check if config buildtype is overridden by buildsys buildtype for testparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']: if 'buildtype' in testparam: buildtype = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']['buildtype'] if 'copyfiles' in testparam: copyfiles = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['testparams']['copyfiles'] for copyfile in copyfiles: x = '{}/{}/{}'.format(builddir, ctparams, copyfile) y = '../hdfsrc/{}/{}'.format(ctparams, copyfiles[copyfile]) #y = '{}/{}/{}'.format(source_dir, ctparams, copyfiles[copyfile]) copyfile(y, x) print ('bb2 buildtype={}'.format(buildtype)) shellState = False winver = '' if theplatform.lower() in util_functions.WinPlatforms: if 'bbparams' == ctparams: winver = '{};.'.format(util_functions.VS_full_to_VScompile(generator)) else: winver = '{};{}'.format(util_functions.VS_full_to_VScompile(generator), ctparams) shellState = True else: if 'bbparams' == ctparams: winver = 'unix;.' else: winver = 'unix;{}'.format(ctparams) if toolset != 'default': winver = '{};BLDDIR={}'.format(winver, ts_path) my_env = os.environ.copy() for aparam in yaml_data['configfile'][buildconfig]['bbparams']: print ('bbparams aparam={}'.format(aparam)) if 'testparams' in aparam: testparams = yaml_data['configfile'][buildconfig]['bbparams']['testparams'] for testparam in testparams: if 'env' == testparam.lower(): envitems = testparams['env'] for envitem in envitems: k = envitem v = envitems[k] my_env[str(k)] = str(v) my_env["CMAKE_CONFIG_TYPE"] = str('{}'.format(buildtype)) if toolset != 'default': if not theplatform.lower() in util_functions.WinPlatforms: # now set any env vars for the compilers for compiler in compilers: k = compiler if not 'MPI' in compiler: if 'MPI' in buildconfig: k = 'MPI{}'.format(compiler) for compver in compilervers: v = compver['compiler'] m = compver['module'] if k == v and m == ts_mod: if 'env' in compver: x = compver['env'] y = compver['command'] my_env[str(x)] = str(y) output = '' try: test = subprocess.Popen(['ctest', '-version'], shell=shellState, env=my_env) (textout, texterr) = test.communicate() if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) except Exception as e: print('Popen Exception: {}'.format(e)) try: test = subprocess.Popen(['ctest', '-S', 'HDF.cmake,'+ winver, '-C', buildtype, '-VV'], shell=shellState, env=my_env) (textout, texterr) = test.communicate() if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) thereturncode = test.returncode print('ctest returncode = {}'.format(thereturncode)) except Exception as e: print('subprocess failure {}'.format(e)) if os.path.exists('{}/FailedCTest.txt'.format(currdir)): thereturncode = 255 with open('{}/FailedCTest.txt'.format(currdir)) as f: print ('ctest failure: {}'.format(f.read())) try: os.rename('{}/FailedCTest.txt'.format(currdir), '{}/{}-FailedCTest.txt'.format(currdir, ts_path)) except Exception as e: print('FailedCTest rename failure {}'.format(e)) os.chdir(scriptdir) script_tc_res = {} for btparam in yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]: if 'envparams' in btparam: envparams = yaml_data['configfile'][buildconfig][ctparams]['buildsys'][buildsys]['envparams'] #print ('tconf env == {}'.format(envparams)) if 'ftpbinary' in envparams: if envparams['ftpbinary']: script_tc_res.update({btparam+'-uninstallfolder':installdir}) json_bbparams_data.append(script_tc_res) currdir=os.getcwd() #### print ('current uninstall={}'.format(currdir)) step_functions.install_binary(json_bbparams_data, buildsys, theplatform, installdir, 'uninstall') os.chdir(currdir) #### if thereturncode != 0: thescriptreturncode = 255 script_tc_res = {ctparams+'-'+script_name+'-'+toolset+'-run': 'FAILURE'} json_bbparams_data.append(script_tc_res) script_res = {ctparams+'-'+script_name+'-'+toolset: 'FAILURE'} json_bbparams_data.append(script_res) with open(jsparams_file, 'w') as json_bbparams_file: json.dump(json_bbparams_data, json_bbparams_file) else: script_tc_res = {ctparams+'-'+script_name+'-'+toolset+'-run': 'SUCCESS'} json_bbparams_data.append(script_tc_res) if toolset != 'default' and not 'mingw' in toolset: if theplatform.lower() not in util_functions.WinPlatforms: util_functions.module('purge') if thescriptreturncode != 0: script_tc_res = {ctparams+'-'+script_name+'-run': 'FAILURE'} json_bbparams_data.append(script_tc_res) script_res = {ctparams+'-'+script_name: 'FAILURE'} json_bbparams_data.append(script_res) with open(jsparams_file, 'w') as json_bbparams_file: json.dump(json_bbparams_data, json_bbparams_file) raise Exception('ctest failure: {}'.format(thescriptreturncode)) else: script_tc_res = {ctparams+'-'+script_name+'-run': 'SUCCESS'} json_bbparams_data.append(script_tc_res) ############################################## # write final script status ############################################## script_res = {ctparams+'-'+script_name: 'SUCCESS'} json_bbparams_data.append(script_res) with open(jsparams_file, 'w') as json_bbparams_file: json.dump(json_bbparams_data, json_bbparams_file) return thereturncode if __name__ == '__main__': main(sys.argv)