Sha256: 7f27af6237a8b6004331649bde54188c4f80cf73337e32bf161f1e6dc08807b7
Contents?: true
Size: 1.93 KB
Versions: 9
Compression:
Stored size: 1.93 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require 'optparse' require 'English' require 'open3' def detect_main # check predefined files main_file_cands = ['Rakefile.raka', 'rakefile.raka', 'main.raka'] main_file_cands.each do |cand| return cand if File.exist?(cand) end # if only one .raka file, use it as main rakas = Dir.glob('*.raka') return rakas[0] if rakas.length == 1 end options = { rake: {}, raka_finished: false } def set_option(opts, key, value) if opts[:raka_finished] opts[:rake][key] = value else opts[key] = value end end parser = OptionParser.new do |opts| opts.banner = 'Usage: raka [options] <output> -- [rake options]' opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| set_option(options, :verbose, v) end opts.on('-f', '--file FILE', String, 'Run even when up to date') do |s| set_option(options, :file, s) end opts.on('-j', '--jobs JOBS', Integer, 'Run in parallel') do |n| set_option(options, :jobs, n) end end if ARGV.empty? puts parser.help exit(1) end both_args = ARGV.join(' ').split(' -- ') self_args = both_args[0].split(/\s+/) parser.parse!(self_args) extra_args = (both_args[1] || ' ').lstrip entry = options[:file] || detect_main env = if options[:verbose] 'LOG_LEVEL=0 ' else '' end targets = self_args.join(' ') cmd = '' opt_str = "-f #{entry}" opt_str += " -m -j #{options[:jobs]}" if options.key?(:jobs) cmd += "#{env}rake #{opt_str} #{extra_args} #{targets}" dry_cmd = 'RUBYOPT="-W0" ' + cmd + ' --dry-run' dry_out, dry_msg, status = Open3.capture3(dry_cmd) if status != 0 puts dry_out puts dry_msg exit(status.exitstatus) end unless (dry_msg.lines.first.chomp =~ /^.*\(.*not_needed.*\)$/).nil? puts 'All targets are up to date' exit(0) end puts cmd pid = fork do status = system(cmd) puts 'Error: rake returns the following information:' unless status exit($CHILD_STATUS.exitstatus) end Process.wait(pid)
Version data entries
9 entries across 9 versions & 1 rubygems