def run(self): """Run all the cc_test target programs. """ failed_targets = [] self._get_inctest_run_list() tests_run_list = [] old_pwd = get_cwd() for target in self.targets.values(): if not (target['type'] == 'cc_test' or target['type'] == 'dynamic_cc_test'): continue if (not self.run_all) and target not in self.inctest_run_list: if not target.get('options', {}).get('always_run', False): self.skipped_tests.append((target['path'], target['name'])) continue self._prepare_test_env(target) cmd = "%s --gtest_output=xml" % os.path.abspath(self._test_executable(target)) if self.options.testargs: cmd = "%s %s" % (cmd, self.options.testargs) sys.stdout.flush() # make sure output before scons if redirected test_env = dict(os.environ) test_env['LD_LIBRARY_PATH'] = self._runfiles_dir(target) test_env['GTEST_COLOR'] = 'yes' if blade_util.color_enabled else 'no' test_env['HEAPCHECK'] = target.get('options', {}).get('heap_check', '') tests_run_list.append((target, self._runfiles_dir(target), test_env, cmd)) concurrent_jobs = 0 if hasattr(self.options, 'test_jobs'): concurrent_jobs = self.options.test_jobs scheduler = TestScheduler(tests_run_list, concurrent_jobs, self.tests_run_map) scheduler.schedule_jobs() os.chdir(old_pwd) self._clean_test_env() info("%s Testing Summary %s" % (self.title_str, self.title_str)) info("Run %d test targets" % scheduler.num_of_run_tests) failed_targets = scheduler.failed_targets if failed_targets: info("%d tests failed:" % len(failed_targets)) for i in failed_targets: print "%s/%s, exit code: %s" % ( i["path"], i["name"], i["test_exit_code"]) test_file_name = os.path.abspath(self._test_executable(i)) # Do not skip failed test by default if self.cur_target_dict.has_key(test_file_name): self.cur_target_dict[test_file_name] = (0, 0) info("%d tests passed" % ( scheduler.num_of_run_tests - len(failed_targets))) self._finish_tests() return 1 else: info("All tests passed!") self._finish_tests() return 0
def get_source_dirs(): '''Get workspace dir and working dir relative to workspace dir''' working_dir = get_cwd() blade_root_dir = find_blade_root_dir(working_dir) working_dir = os.path.relpath(working_dir, blade_root_dir) return blade_root_dir, working_dir
def run_target(self, target_key): """Run one single target. """ target = self.targets.get(target_key, {}) if not target: error_exit("target %s:%s is not in the target databases" % ( target_key[0], target_key[1])) if target['type'] not in self.run_list: error_exit("target %s:%s is not a target that could run" % ( target_key[0], target_key[1])) self._prepare_run_env(target) old_pwd = get_cwd() cmd = "%s " % os.path.abspath(self._test_executable(target)) if self.options.runargs: cmd += "%s" % self.options.runargs info("it will run '%s' " % cmd ) sys.stdout.flush() target_dir = os.path.dirname(self._test_executable(target)) os.chdir(target_dir) run_env = dict(os.environ) run_env['LD_LIBRARY_PATH'] = target_dir p = subprocess.Popen(cmd, env=run_env, shell=True) p.wait() os.chdir(old_pwd) return p.returncode
def find_pkg_dir(source_dir): root_dir = load_build_files.find_blade_root_dir(get_cwd()) cc_config = configparse.blade_config.get_config('cc_config') hostname = cc_config.get('hostname', '') if not hostname: console.error_exit("No hostname configured!") pkg_dir = hostname + '/' + source_dir download_dir = os.path.dirname(os.path.join(root_dir, source_dir)) if not os.path.exists(download_dir): os.makedirs(download_dir) return pkg_dir, download_dir
def setup_dirs(options): # Set blade_root_dir to the directory which contains the # file BLADE_ROOT, is upper than and is closest to the current # directory. Set working_dir to current directory. working_dir = get_cwd() blade_root_dir = find_blade_root_dir(working_dir) if blade_root_dir != working_dir: # This message is required by vim quickfix mode if pwd is changed during # the building, DO NOT change the pattern of this message. print "Blade: Entering directory `%s'" % blade_root_dir os.chdir(blade_root_dir) working_dir = os.path.relpath(working_dir, blade_root_dir) load_config(options, blade_root_dir) build_dir = setup_build_dir(options) return blade_root_dir, working_dir, build_dir
def _main(blade_path): """The main entry of blade. """ cmd_options = CmdArguments() command = cmd_options.get_command() targets = cmd_options.get_targets() global query_targets global run_target if command == 'query': query_targets = list(targets) if command == 'run': run_target = targets[0] if not targets: targets = ['.'] options = cmd_options.get_options() # Set blade_root_dir to the directory which contains the # file BLADE_ROOT, is upper than and is closest to the current # directory. Set working_dir to current directory. working_dir = get_cwd() blade_root_dir = find_blade_root_dir(working_dir) os.chdir(blade_root_dir) if blade_root_dir != working_dir: # This message is required by vim quickfix mode if pwd is changed during # the building, DO NOT change the pattern of this message. print >>sys.stderr, "Blade: Entering directory `%s'" % blade_root_dir # Init global configuration manager configparse.blade_config = BladeConfig(blade_root_dir) configparse.blade_config.parse() # Check code style using cpplint.py if command == 'build' or command == 'test': opened_files = _get_opened_files(targets, blade_root_dir, working_dir) os.chdir(blade_root_dir) _check_code_style(opened_files) # Init global blade manager. current_building_path = 'build%s_%s' % (options.m, options.profile) lock_file_fd = None locked_scons = False try: lock_file_fd = open('.Building.lock', 'w') old_fd_flags = fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_SETFD, old_fd_flags | fcntl.FD_CLOEXEC) (locked_scons, ret_code) = lock_file(lock_file_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) if not locked_scons: if ret_code == errno.EAGAIN: console.error_exit( 'There is already an active building in current source ' 'dir tree. Blade will exit...') else: console.error_exit('Lock exception, please try it later.') if command == 'query' and getattr(options, 'depended', None): targets = ['...'] blade.blade = Blade(targets, blade_path, working_dir, current_building_path, blade_root_dir, options, command) # Build the targets blade.blade.generate() # Flush the printing sys.stdout.flush() sys.stderr.flush() # Tune the jobs num if command in ['build', 'run', 'test']: options.jobs = blade.blade.tune_parallel_jobs_num() # Switch case due to different sub command action = { 'build': build, 'run': run, 'test': test, 'clean': clean, 'query': query }[command](options) return action finally: if (not getattr(options, 'scons_only', False) or command == 'clean' or command == 'query'): try: if locked_scons: os.remove(os.path.join(blade_root_dir, 'SConstruct')) unlock_file(lock_file_fd.fileno()) lock_file_fd.close() except OSError: pass return 0
def _main(blade_path): """The main entry of blade. """ cmd_options = CmdArguments() command = cmd_options.get_command() targets = cmd_options.get_targets() global query_targets global run_target if command == 'query': query_targets = list(targets) if command == 'run': run_target = targets[0] if not targets: targets = ['.'] options = cmd_options.get_options() # Set blade_root_dir to the directory which contains the # file BLADE_ROOT, is upper than and is closest to the current # directory. Set working_dir to current directory. working_dir = get_cwd() blade_root_dir = find_blade_root_dir(working_dir) os.chdir(blade_root_dir) if blade_root_dir != working_dir: # This message is required by vim quickfix mode if pwd is changed during # the building, DO NOT change the pattern of this message. print >> sys.stderr, "Blade: Entering directory `%s'" % blade_root_dir # Init global configuration manager configparse.blade_config = BladeConfig(blade_root_dir) configparse.blade_config.parse() # Check code style using cpplint.py if command == 'build' or command == 'test': opened_files = _get_opened_files(targets, blade_root_dir, working_dir) os.chdir(blade_root_dir) _check_code_style(opened_files) # Init global blade manager. build_path_format = configparse.blade_config.configs['global_config'][ 'build_path_template'] s = Template(build_path_format) current_building_path = s.substitute(m=options.m, profile=options.profile) lock_file_fd = None locked_scons = False try: lock_file_fd = open('.Building.lock', 'w') old_fd_flags = fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_SETFD, old_fd_flags | fcntl.FD_CLOEXEC) (locked_scons, ret_code) = lock_file(lock_file_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) if not locked_scons: if ret_code == errno.EAGAIN: console.error_exit( 'There is already an active building in current source ' 'dir tree. Blade will exit...') else: console.error_exit('Lock exception, please try it later.') if command == 'query' and getattr(options, 'depended', None): targets = ['...'] blade.blade = Blade(targets, blade_path, working_dir, current_building_path, blade_root_dir, options, command) # Build the targets blade.blade.generate() # Flush the printing sys.stdout.flush() sys.stderr.flush() # Tune the jobs num if command in ['build', 'run', 'test']: options.jobs = blade.blade.tune_parallel_jobs_num() # Switch case due to different sub command action = { 'build': build, 'run': run, 'test': test, 'clean': clean, 'query': query }[command](options) return action finally: if (not getattr(options, 'scons_only', False) or command == 'clean' or command == 'query'): try: if locked_scons: os.remove(os.path.join(blade_root_dir, 'SConstruct')) unlock_file(lock_file_fd.fileno()) if lock_file_fd: lock_file_fd.close() except OSError: pass return 0
def _main(blade_path): """The main entry of blade. """ cmd_options = CmdArguments() command = cmd_options.get_command() targets = cmd_options.get_targets() global query_targets global run_target if command == "query": if not targets: query_targets = ["."] else: query_targets = list(targets) if command == "run": run_target = targets[0] if not targets: targets = ["."] options = cmd_options.get_options() # Set blade_root_dir to the directory which contains the # file BLADE_ROOT, is upper than and is closest to the current # directory. Set working_dir to current directory. working_dir = get_cwd() blade_root_dir = find_blade_root_dir(working_dir) os.chdir(blade_root_dir) if blade_root_dir != working_dir: # This message is required by vim quickfix mode if pwd is changed during # the building, DO NOT change the pattern of this message. print >>sys.stderr, "Blade: Entering directory `%s'" % blade_root_dir # Init global configuration manager configparse.blade_config = BladeConfig(blade_root_dir) configparse.blade_config.parse() # Check code style using cpplint.py if command == "build" or command == "test": opened_files = _get_opened_files(targets, blade_root_dir, working_dir) os.chdir(blade_root_dir) _check_code_style(opened_files) # Init global blade manager. build_path_format = configparse.blade_config.configs["global_config"]["build_path_template"] s = Template(build_path_format) current_building_path = s.substitute(m=options.m, profile=options.profile) lock_file_fd = None locked_scons = False try: lock_file_fd = open(".Building.lock", "w") old_fd_flags = fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_SETFD, old_fd_flags | fcntl.FD_CLOEXEC) (locked_scons, ret_code) = lock_file(lock_file_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) if not locked_scons: if ret_code == errno.EAGAIN: console.error_exit( "There is already an active building in current source " "dir tree. Blade will exit..." ) else: console.error_exit("Lock exception, please try it later.") if command == "query" and getattr(options, "depended", None): targets = ["..."] blade.blade = Blade(targets, blade_path, working_dir, current_building_path, blade_root_dir, options, command) # Build the targets blade.blade.generate() # Flush the printing sys.stdout.flush() sys.stderr.flush() # Tune the jobs num if command in ["build", "run", "test"]: options.jobs = blade.blade.tune_parallel_jobs_num() # Switch case due to different sub command action = {"build": build, "run": run, "test": test, "clean": clean, "query": query}[command](options) return action finally: if not getattr(options, "scons_only", False) or command == "clean" or command == "query": try: if locked_scons: os.remove(os.path.join(blade_root_dir, "SConstruct")) unlock_file(lock_file_fd.fileno()) if lock_file_fd: lock_file_fd.close() except OSError: pass return 0
def _main(blade_path): """The main entry of blade. """ cmd_options = CmdArguments() command = cmd_options.get_command() targets = cmd_options.get_targets() global query_targets global run_target if command == 'query': query_targets = list(targets) if command == 'run': run_target = targets[0] if not targets: targets = ['.'] options = cmd_options.get_options() # Set current_source_dir to the directory which contains the # file BLADE_ROOT, is upper than and is closest to the current # directory. Set working_dir to current directory. working_dir = get_cwd() current_source_dir = find_blade_root_dir(working_dir) os.chdir(current_source_dir) if current_source_dir != working_dir: # This message is required by vim quickfix mode if pwd is changed during # the building, DO NOT change the pattern of this message. print "Blade: Entering directory `%s'" % current_source_dir # Init global configuration manager configparse.blade_config = BladeConfig(current_source_dir) configparse.blade_config.parse() # Init global blade manager. current_building_path = "build%s_%s" % (options.m, options.profile) lock_file_fd = None locked_scons = False try: lock_file_fd = open('.SConstruct.lock', 'w') old_fd_flags = fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_GETFD) fcntl.fcntl(lock_file_fd.fileno(), fcntl.F_SETFD, old_fd_flags | fcntl.FD_CLOEXEC) (locked_scons, ret_code) = lock_file(lock_file_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) if not locked_scons: if ret_code == errno.EAGAIN: error_exit("There is already an active building in current source " "dir tree,\n" "or make sure there is no SConstruct file existed with " "BLADE_ROOT. Blade will exit...") else: error_exit("Lock exception, please try it later.") if command == 'query' and ( hasattr(options, 'depended') and options.depended): targets = ['...'] blade.blade = Blade(targets, blade_path, working_dir, current_building_path, current_source_dir, options, blade_command=command) # Build the targets blade.blade.generate() # Flush the printing sys.stdout.flush() sys.stderr.flush() # Tune the jobs num if command in ['build', 'run', 'test']: options.jobs = blade.blade.tune_parallel_jobs_num() # Switch case due to different sub command action = { 'build' : build, 'run' : run, 'test' : test, 'clean' : clean, 'query' : query }[command](options) return action finally: if (hasattr(options, 'scons_only') and not options.scons_only) or ( command == 'clean' or command == 'query' ): try: if locked_scons: os.remove(os.path.join(current_source_dir, 'SConstruct')) unlock_file(lock_file_fd.fileno()) lock_file_fd.close() except Exception as inst: pass return 0