Class: U3d::Runner
- Inherits:
-
Object
- Object
- U3d::Runner
- Defined in:
- lib/u3d/unity_runner.rb
Overview
Launches Unity with given arguments
Class Method Summary collapse
- .find_arg_in_args(arg_to_find, args) ⇒ Object
-
.find_logFile_in_args(args) ⇒ Object
rubocop:disable MethodName.
- .find_projectpath_in_args(args) ⇒ Object
Instance Method Summary collapse
- #find_and_prepare_logfile(installation, args) ⇒ Object
- #run(installation, args, raw_logs: false) ⇒ Object
Class Method Details
.find_arg_in_args(arg_to_find, args) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/u3d/unity_runner.rb', line 91 def find_arg_in_args(arg_to_find, args) raise 'Only arguments of type array supported right now' unless args.is_a?(Array) args.each_with_index do |arg, index| return args[index + 1] if arg == arg_to_find && index < args.count - 1 end nil end |
.find_logFile_in_args(args) ⇒ Object
rubocop:disable MethodName
82 83 84 85 |
# File 'lib/u3d/unity_runner.rb', line 82 def find_logFile_in_args(args) # rubocop:enable MethodName find_arg_in_args('-logFile', args) end |
.find_projectpath_in_args(args) ⇒ Object
87 88 89 |
# File 'lib/u3d/unity_runner.rb', line 87 def find_projectpath_in_args(args) find_arg_in_args('-projectPath', args) end |
Instance Method Details
#find_and_prepare_logfile(installation, args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/u3d/unity_runner.rb', line 64 def find_and_prepare_logfile(installation, args) log_file = Runner.find_logFile_in_args(args) return nil if log_file == '/dev/stdout' if log_file # we wouldn't want to do that for the default log file. File.delete(log_file) if File.file?(log_file) # We only delete real files else log_file = installation.default_log_file end Utils.ensure_dir File.dirname(log_file) FileUtils.touch(log_file) unless File.exist? log_file log_file end |
#run(installation, args, raw_logs: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/u3d/unity_runner.rb', line 31 def run(installation, args, raw_logs: false) log_file = find_and_prepare_logfile(installation, args) if raw_logs output_callback = proc do |line| UI.command_output(line.rstrip) end else analyzer = LogAnalyzer.new output_callback = proc do |line| analyzer.parse_line(line) end end if log_file tail_thread = start_tail_thread(log_file, output_callback) return unless tail_thread.status tail_thread.run end begin args.unshift(installation.exe_path) args.map!(&:argescape) U3dCore::CommandExecutor.execute_command(command: args, output_callback: output_callback) ensure if tail_thread sleep 1 Thread.kill(tail_thread) end end end |