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 unlock_workspace(lock_file_fd): unlock_file(lock_file_fd)
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