def SetBuildJobs(env): ################################################### # Determine number of Jobs # start by assuming num_jobs was not set NUM_JOBS_SET = False if GetOption("num_jobs") == 1: # if num_jobs is the default we need to check sys.argv # to see if the user happened to set the default for arg in sys.argv: if arg.startswith("-j") or arg.startswith("--jobs"): if arg == "-j" or arg == "--jobs": if int(sys.argv[sys.argv.index(arg) + 1]) == 1: NUM_JOBS_SET = True else: if arg.startswith("-j"): if int(arg[2:]) == 1: NUM_JOBS_SET = True else: # user must have set something if it wasn't default NUM_JOBS_SET = True # num_jobs wasn't specificed so let use the # max number since the user doesn't seem to care if not NUM_JOBS_SET: NUM_CPUS = get_num_cpus() ColorPrinter().InfoPrint(" Building with " + str(NUM_CPUS) + " parallel jobs") env.SetOption("num_jobs", NUM_CPUS) else: # user wants a certain number of jobs so do that ColorPrinter().InfoPrint(" Building with " + str(GetOption('num_jobs')) + " parallel jobs")
def __init__(self, env, paths, required, timeout, conf_dir): self.env = env self.user_paths = paths self.sys_paths = [] self.required = required self.timeout = timeout self.p = ColorPrinter() self.version = "" self.timedout = {'timedout': False} self.addPlatformPaths() if not conf_dir: self.conf_dir = 'confdir' else: self.conf_dir = conf_dir self.packagename = ""
def run_visual_tests(base_dir): """ Callback function to run the test script. """ if ('SIKULI_DIR' not in os.environ and not os.path.isdir(base_dir + '/Testing/VisualTests/SikuliX')): printer = ColorPrinter() printer.InfoPrint( ' Need to download and install sikuli... please be extra patient...' ) proc = subprocess.Popen([sys.executable, 'install_sikuliX.py'], cwd=base_dir + '/Testing/VisualTests', stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False) output, result = proc.communicate() if 'RunSetup: ... SikuliX Setup seems to have ended successfully ;-)' in str( output): printer.InfoPrint(' Silkuli Installed!') else: printer.InfoPrint(' Silkuli Failed to install!:') print(output) test_env = os.environ if 'SIKULI_DIR' not in os.environ: test_env['SIKULI_DIR'] = base_dir + '/Testing/VisualTests/SikuliX' test_env['TEST_BIN_DIR'] = base_dir + '/build/bin' if 'DISPLAY' not in test_env: test_env['DISPLAY'] = ':0' proc = subprocess.Popen(args=['python', 'run_visual_tests.py'], cwd=base_dir + '/Testing', env=test_env) output, err = proc.communicate() if not proc.returncode == 0: exit(proc.returncode)
if "windows" in platform.system().lower(): test_file = os.path.abspath("../build/bin") + "/" + test + '.exe' else: testenv['LD_LIBRARY_PATH'] = '../lib' test_file = "./" + test proc = subprocess.Popen(test_file, cwd=os.path.abspath("../build/bin"), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=testenv) output = proc.communicate()[0] output_lines = output.decode('utf-8').strip().split(os.linesep) printer = None try: from BuildUtils.ColorPrinter import ColorPrinter printer = ColorPrinter() if str(output_lines[-1]).strip().endswith(".OK!"): printer.TestPassPrint(" " + output_lines[0]) else: printer.TestFailPrint(" " + output.decode('utf-8').strip()) except: print(output.decode('utf-8').strip()) pass if proc.returncode == 0: passed_tests.append(test) else: failed_tests.append(test) results_string = "Passed " + str(len(passed_tests)) + " tests." + os.linesep if len(failed_tests) > 0:
# The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. """ Script for running all the tests against the OpenDoorGL library. """ import os import sys import platform import subprocess import time try: from BuildUtils.ColorPrinter import ColorPrinter printer = ColorPrinter() except: printer = None pass def StartGraphicsApp(test, working_dir): my_env = os.environ.copy() command = [] if "windows" in platform.system().lower(): command.append("python") command.append("windows_workaround.py") command.append(working_dir + "/" + test + ".exe") else:
class PackageFinder(object): def __init__(self, env, paths, required, timeout, conf_dir): self.env = env self.user_paths = paths self.sys_paths = [] self.required = required self.timeout = timeout self.p = ColorPrinter() self.version = "" self.timedout = {'timedout': False} self.addPlatformPaths() if not conf_dir: self.conf_dir = 'confdir' else: self.conf_dir = conf_dir self.packagename = "" def startSearch(self): if self.timeout: pool = ThreadPool(processes=1) async_result = pool.apply_async(self.searchThread) try: return async_result.get(timeout) except TimeoutError: self.timedout['timedout'] = True async_result.get() if self.required: self.p.ErrorPrint("Timedout after " + str(timeout) + " seconds searching for " + self.packagename) else: self.p.InfoPrint(" Timedout after " + str(timeout) + " seconds searching for " + self.packagename) return None else: return self.searchThread() def getTestEnv(self): if self.env is None: test_env = Environment() else: test_env = self.env.Clone() return test_env def tryPackageConfig(self): try: if any( os.access(os.path.join(path, 'pkg-config'), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)): test_env = self.getTestEnv() pkgconfig_str = 'pkg-config ' + self.packagename + " --cflags --libs" test_env.ParseConfig(pkgconfig_str) if self.compileTest(test_env): header_dirs = subprocess.check_output( ['pkg-config', self.packagename, "--cflags"]).decode('utf8').strip().split(' ') header_dirs += ['-I/usr/include'] found_version = False for path in header_dirs: if path.startswith('-I'): path = path[2:] for root, dirs, files in os.walk(path, topdown=False): for name in files: if self.timedout['timedout']: return version_file = self.checkVersion( test_env, name, root) if version_file: found_version = version_file break if found_version: break if found_version: break if found_version: self.p.InfoPrint(" Found " + self.packagename + " version " + self.version) else: self.p.InfoPrint(" Found " + self.packagename + " with unknown version.") if self.env: self.env.ParseConfig(pkgconfig_str) return test_env except OSError: pass return self.getTestEnv() def addPlatformPaths(self): test_env = self.getTestEnv() # check parent directory of the current project self.sys_paths.append( os.path.abspath(test_env.Dir('.').abspath + '/..')) if sys.platform == 'win32': if not IsCrossCompile(test_env): if GetTargetArch(test_env) == 'amd64': self.sys_paths.append("C:/Program Files") self.sys_paths.append("C:/cygwin64") self.sys_paths.append("C:/msys64") else: self.sys_paths.append("C:/Program Files (x86)") self.sys_paths.append("C:/cygwin") self.sys_paths.append("C:/msys") self.sys_paths.append("C:/MinGW") # check user directory, and program files self.sys_paths.append(os.environ.get('USERPROFILE')) elif 'linux' in sys.platform: if not IsCrossCompile(test_env): if GetTargetArch(test_env) == 'amd64': self.sys_paths.append(["/usr/include", "/usr/lib64"]) self.sys_paths.append( ["/usr/include", "/usr/lib/x86_64-linux-gnu"]) else: self.sys_paths.append( ["/usr/include", "/usr/lib/i386-linux-gnu"]) self.sys_paths.append(["/usr/local/include", "/usr/local/lib"]) self.sys_paths.append(["/usr/include", "/usr/lib"]) def search(self, paths, required=False): found_headers = None found_libs = None found_version = None test_env = self.getTestEnv() for test_path in paths: self.p.InfoPrint(" Looking in " + str(test_path)) # include and lib paths passed separately if type(test_path) is list: for root, dirs, files in os.walk(test_path[0], topdown=False): for name in files: if self.timedout['timedout']: return header_dir = self.checkHeader(test_env, name, root) if header_dir: found_headers = header_dir break if found_headers: break for root, dirs, files in os.walk(test_path[1], topdown=False): for name in files: if self.timedout['timedout']: return lib_dir = self.checkLib(test_env, name, root) if lib_dir: found_libs = lib_dir break if found_libs: break # look in same dir for lib and include else: for root, dirs, files in os.walk(test_path, topdown=False): for name in files: if self.timedout['timedout']: return header_dir = self.checkHeader(test_env, name, root) if header_dir: found_headers = header_dir break lib_dir = self.checkLib(test_env, name, root) if lib_dir: found_libs = lib_dir break if found_headers and found_libs: break if found_headers and found_libs: for root, dirs, files in os.walk(found_headers, topdown=False): for name in files: if self.timedout['timedout']: return version_file = self.checkVersion(test_env, name, root) if version_file: found_version = version_file break if found_version: break if self.compileTest(test_env): self.p.InfoPrint(" Found " + self.packagename + " version " + self.version + " in " + str(found_headers)) return self.foundPackage(test_env, found_libs, found_headers, found_version) else: self.p.InfoPrint(" Candidate failed in " + found_headers + " and " + found_libs) test_env = self.getTestEnv() found_libs = None found_headers = None found_version = None else: test_env = self.getTestEnv() found_libs = None found_headers = None found_freetype_version = None def searchThread(self): self.p.InfoPrint(" Searching for " + self.packagename + "...") # first search user paths result = self.search(self.user_paths, required=self.required) if result: return result if self.timedout['timedout']: return # next try package config if 'linux' in sys.platform: result = self.tryPackageConfig() if result: return result if self.timedout['timedout']: return # finally try system paths result = self.search(self.sys_paths, required=self.required) if result: return result if self.required: self.p.ErrorPrint("Failed to find working " + self.packagename + " package.") else: self.p.InfoPrint(" Couldn't find " + self.packagename + ".")
import re from BuildUtils.ColorPrinter import ColorPrinter from SCons.Conftest import _lang2suffix, _YesNoResult p = ColorPrinter() def CheckHeader(context, header_name, header=None, language=None, include_quotes=None): """ Configure check for a C or C++ header file "header_name". Optional "header" can be defined to do something before including the header file (unusual, supported for consistency). "language" should be "C" or "C++" and is used to select the compiler. Default is "C". Sets HAVE_header_name in context.havedict according to the result. Note that this uses the current value of compiler and linker flags, make sure $CFLAGS and $CPPFLAGS are set correctly. Returns an empty string for success, an error message for failure. """ # Why compile the program instead of just running the preprocessor? # It is possible that the header file exists, but actually using it may # fail (e.g., because it depends on other header files). Thus this test is # more strict. It may require using the "header" argument. # # Use <> by default, because the check is normally used for system header # files. SCons passes '""' to overrule this. # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
def cppcheck_command(base_dir, jobs): """ Callback function to run the test script. """ printer = ColorPrinter() if "windows" in platform.system().lower(): cppcheck_exec = base_dir + '/build/bin/cppcheck.exe' else: cppcheck_exec = './cppcheck' def execute(): proc = subprocess.Popen([ cppcheck_exec, '--enable=all', '--suppress=*:../include/glm*', '-I../include', '-j', str(jobs), '-DGLM_FORCE_RADIANS', '-DODGL_LIBRARAY_BUILD', '../../Core', '../../AppFrameworks' ], cwd=base_dir + '/build/bin', stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True) for stdout_line in iter(proc.stdout.readline, ""): yield stdout_line proc.stdout.close() return_code = proc.wait() if return_code: raise subprocess.CalledProcessError(return_code, cppcheck_exec) style = ' (style) ' performance = ' (performance) ' portability = ' (portability) ' warning = ' (warning) ' error = ' (error) ' information = ' (information) ' errors = 0 warnings = 0 noncritical = 0 for output in execute(): output = output.strip() if (output.startswith('[') or output.endswith(r'% done')): if (style in output): noncritical += 1 output = printer.highlight_word(output, ' (style) ', printer.OKBLUE) elif (performance in output): noncritical += 1 output = printer.highlight_word(output, ' (performance) ', printer.OKBLUE) elif (portability in output): noncritical += 1 output = printer.highlight_word(output, ' (portability) ', printer.OKBLUE) elif (warning in output): warnings += 1 output = printer.highlight_word(output, ' (warning) ', printer.WARNING) elif (error in output): errors += 1 output = printer.highlight_word(output, ' (error) ', printer.FAIL) elif (information in output): noncritical += 1 printer.CppCheckPrint(' ' + output) printer.InfoPrint(' Cppcheck finished, findings:') printer.InfoPrint(' Non-Critical: ' + str(noncritical)) printer.InfoPrint(' Warnings: ' + str(warnings)) printer.InfoPrint(' Errors: ' + str(errors))
def __init__(self): self.printer = ColorPrinter() self.progress_builders = []
class ProgressCounter(object): """ Utility class used for printing progress during the build. """ class ProgressBuild(): def __init__(self, sources, target, static): self.count = 0.0 self.progress_sources = dict() self.target = None self.target_reported = False self.target_install = '' for source in sources: # print("Making key: " + os.path.splitext(source)[0]) self.progress_sources[os.path.splitext(source)[0]] = False self.target = target if static: self.static_lib = "-static" else: self.static_lib = "" def __init__(self): self.printer = ColorPrinter() self.progress_builders = [] def AddBuild(self, env, sources, target, static=False): env['PROJECT_DIR'] = env.get('PROJECT_DIR', env.Dir('.').abspath) # self.printer.SetSize(self.target_name_size) # pathed_sources = [env.File(source).abspath.replace('\\', '/').replace(env['PROJECT_DIR'] + '/', '') # for source in sources] self.progress_builders.append( self.ProgressBuild(sources, target, static)) def __call__(self, node, *args, **kw): # print(str(node)) slashed_node = str(node).replace("\\", "/") for build in self.progress_builders: # print(build.target + ": "+str(node.get_state())+" - " + slashed_node) if (slashed_node.endswith(build.target)): target_name = os.path.splitext( build.target)[0] + build.static_lib if (build.count == 0): self.printer.InfoPrint(self.printer.OKBLUE + "[ " + target_name + " ]" + self.printer.ENDC + " Building " + build.target) filename = os.path.basename(slashed_node) if (node.get_state() == 2) and not build.target_reported: self.printer.LinkPrint(target_name, "Linking " + filename) build.target_reported = True elif not build.target_reported: self.printer.LinkPrint( target_name, "Skipping, already built " + filename) build.target_reported = True # TODO: make hanlding this file extensions better if (slashed_node.endswith(".obj") or slashed_node.endswith(".o") or slashed_node.endswith(".os")): slashed_node_file = os.path.splitext(slashed_node)[0] # print(" - " + slashed_node_file) for build in self.progress_builders: try: if (not build.progress_sources[slashed_node_file]): build.progress_sources[slashed_node_file] = True target_name = os.path.splitext( build.target)[0] + build.static_lib if (build.count == 0): self.printer.InfoPrint(self.printer.OKBLUE + "[ " + target_name + " ]" + self.printer.ENDC + " Building " + build.target) build.count += 1 percent = build.count / \ len(build.progress_sources.keys()) * 100.00 filename = os.path.basename(slashed_node) if (node.get_state() == 2): self.printer.CompilePrint(percent, target_name, "Compiling " + filename) else: self.printer.CompilePrint( percent, target_name, "Skipping, already built " + filename) break except KeyError: pass
def display_build_status(project_dir, start_time): """Display the build status. Called by atexit. Here you could do all kinds of complicated things.""" status, _unused_failures_message = build_status() ColorPrinter.cleanUpPrinter() printer = ColorPrinter() compile_logs = [] link_logs = [] for root, dirs, files in os.walk(project_dir + '/build'): for name in files: if name.endswith('_compile.txt'): compile_logs.append(os.path.join(root, name)) if name.endswith('_link.txt'): link_logs.append(os.path.join(root, name)) for filename in compile_logs: compileOutput = [] sourcefile = os.path.basename(filename).replace("_compile.txt", "") f = open(filename, "r") tempList = f.read().splitlines() if tempList: if ("windows" in platform.system().lower() and len(tempList) == 1): continue compileOutput += [printer.OKBLUE + sourcefile + ":" + printer.ENDC] compileOutput += tempList pending_output = os.linesep found_info = False for line in compileOutput: if (('error' in line or 'warning' in line or "note" in line) and not line.startswith(sourcefile)): line = printer.highlight_word(line, "error", printer.FAIL) line = printer.highlight_word(line, "warning", printer.WARNING) line = printer.highlight_word(line, "note", printer.OKBLUE) found_info = True pending_output += line + os.linesep if found_info: print(pending_output) for filename in link_logs: linkOutput = [] sourcefile = os.path.basename(filename).replace("_link.txt", "") f = open(filename, "r") tempList = f.read().splitlines() if tempList: linkOutput += [printer.OKBLUE + sourcefile + ":" + printer.ENDC] linkOutput += tempList pending_output = os.linesep found_info = False for line in linkOutput: if (('error' in line or 'warning' in line or "note" in line) and not line.startswith(sourcefile)): line = printer.highlight_word(line, "error", printer.FAIL) line = printer.highlight_word(line, "warning", printer.WARNING) line = printer.highlight_word(line, "note", printer.OKBLUE) found_info = True pending_output += line + os.linesep if found_info: print(pending_output) if status == 'failed': print(printer.FAIL + "Build failed" + printer.ENDC + " in %.3f seconds" % (time.time() - start_time)) elif status == 'ok': print(printer.OKGREEN + "Build succeeded" + printer.ENDC + " in %.3f seconds" % (time.time() - start_time))
from SCons import Action from SCons.Defaults import Copy, mkdir_func, get_paths_str from SCons.Script import Main from SCons.Node import NodeList from SCons.Environment import Environment from SCons.Script.Main import GetOption from SCons.Errors import BuildError from SCons.Platform import TempFileMunge from SCons.Action import ActionFactory from BuildUtils.ColorPrinter import ColorPrinter from BuildUtils import get_num_cpus Mkdir = ActionFactory( mkdir_func, lambda dir: ColorPrinter().InfoPrint(' Mkdir(%s)' % get_paths_str(dir))) def SetBuildJobs(env): ################################################### # Determine number of Jobs # start by assuming num_jobs was not set NUM_JOBS_SET = False if GetOption("num_jobs") == 1: # if num_jobs is the default we need to check sys.argv # to see if the user happened to set the default for arg in sys.argv: if arg.startswith("-j") or arg.startswith("--jobs"): if arg == "-j" or arg == "--jobs": if int(sys.argv[sys.argv.index(arg) + 1]) == 1: NUM_JOBS_SET = True