Class: MRuby::Command::Compiler
- Inherits:
-
MRuby::Command
- Object
- MRuby::Command
- MRuby::Command::Compiler
- Defined in:
- ext/enterprise_script_service/mruby/lib/mruby/build/command.rb
Constant Summary
Constants inherited from MRuby::Command
Instance Attribute Summary collapse
-
#compile_options ⇒ Object
Returns the value of attribute compile_options.
-
#cxx_compile_flag ⇒ Object
Returns the value of attribute cxx_compile_flag.
-
#cxx_exception_flag ⇒ Object
Returns the value of attribute cxx_exception_flag.
-
#defines ⇒ Object
Returns the value of attribute defines.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#include_paths ⇒ Object
(also: #header_search_paths)
Returns the value of attribute include_paths.
-
#option_define ⇒ Object
Returns the value of attribute option_define.
-
#option_include_path ⇒ Object
Returns the value of attribute option_include_path.
-
#out_ext ⇒ Object
Returns the value of attribute out_ext.
-
#source_exts ⇒ Object
Returns the value of attribute source_exts.
Attributes inherited from MRuby::Command
Instance Method Summary collapse
- #all_flags(_defines = [], _include_paths = [], _flags = []) ⇒ Object
- #define_rules(build_dir, source_dir = '') ⇒ Object
-
#initialize(build, source_exts = []) ⇒ Compiler
constructor
A new instance of Compiler.
- #run(outfile, infile, _defines = [], _include_paths = [], _flags = []) ⇒ Object
- #search_header(name) ⇒ Object
- #search_header_path(name) ⇒ Object
Methods inherited from MRuby::Command
Constructor Details
#initialize(build, source_exts = []) ⇒ Compiler
Returns a new instance of Compiler.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 46 def initialize(build, source_exts=[]) super(build) @command = ENV['CC'] || 'cc' @flags = [ENV['CFLAGS'] || []] @source_exts = source_exts @include_paths = ["#{MRUBY_ROOT}/include"] @defines = %w() @option_include_path = '-I%s' @option_define = '-D%s' @compile_options = '%{flags} -o %{outfile} -c %{infile}' end |
Instance Attribute Details
#compile_options ⇒ Object
Returns the value of attribute compile_options.
43 44 45 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 43 def @compile_options end |
#cxx_compile_flag ⇒ Object
Returns the value of attribute cxx_compile_flag.
44 45 46 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 44 def cxx_compile_flag @cxx_compile_flag end |
#cxx_exception_flag ⇒ Object
Returns the value of attribute cxx_exception_flag.
44 45 46 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 44 def cxx_exception_flag @cxx_exception_flag end |
#defines ⇒ Object
Returns the value of attribute defines.
42 43 44 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 42 def defines @defines end |
#flags ⇒ Object
Returns the value of attribute flags.
42 43 44 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 42 def flags @flags end |
#include_paths ⇒ Object Also known as: header_search_paths
Returns the value of attribute include_paths.
42 43 44 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 42 def include_paths @include_paths end |
#option_define ⇒ Object
Returns the value of attribute option_define.
43 44 45 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 43 def option_define @option_define end |
#option_include_path ⇒ Object
Returns the value of attribute option_include_path.
43 44 45 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 43 def option_include_path @option_include_path end |
#out_ext ⇒ Object
Returns the value of attribute out_ext.
43 44 45 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 43 def out_ext @out_ext end |
#source_exts ⇒ Object
Returns the value of attribute source_exts.
42 43 44 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 42 def source_exts @source_exts end |
Instance Method Details
#all_flags(_defines = [], _include_paths = [], _flags = []) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 70 def all_flags(_defines=[], _include_paths=[], _flags=[]) define_flags = [defines, _defines].flatten.map{ |d| option_define % d } include_path_flags = [include_paths, _include_paths].flatten.map do |f| if MRUBY_BUILD_HOST_IS_CYGWIN option_include_path % cygwin_filename(f) else option_include_path % filename(f) end end [flags, define_flags, include_path_flags, _flags].flatten.join(' ') end |
#define_rules(build_dir, source_dir = '') ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 94 def define_rules(build_dir, source_dir='') @out_ext = build.exts.object gemrake = File.join(source_dir, "mrbgem.rake") rakedep = File.exist?(gemrake) ? [ gemrake ] : [] if build_dir.include? "mrbgems/" generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(.*)#{Regexp.escape out_ext}$") else generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbgems/.+/)(.*)#{Regexp.escape out_ext}$") end source_exts.each do |ext, compile| rule generated_file_matcher => [ proc { |file| file.sub(generated_file_matcher, "#{source_dir}/\\1#{ext}") }, proc { |file| get_dependencies(file) + rakedep } ] do |t| run t.name, t.prerequisites.first end rule generated_file_matcher => [ proc { |file| file.sub(generated_file_matcher, "#{build_dir}/\\1#{ext}") }, proc { |file| get_dependencies(file) + rakedep } ] do |t| run t.name, t.prerequisites.first end end end |
#run(outfile, infile, _defines = [], _include_paths = [], _flags = []) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 82 def run(outfile, infile, _defines=[], _include_paths=[], _flags=[]) FileUtils.mkdir_p File.dirname(outfile) _pp "CC", infile.relative_path, outfile.relative_path if MRUBY_BUILD_HOST_IS_CYGWIN _run , { :flags => all_flags(_defines, _include_paths, _flags), :infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) } else _run , { :flags => all_flags(_defines, _include_paths, _flags), :infile => filename(infile), :outfile => filename(outfile) } end end |
#search_header(name) ⇒ Object
65 66 67 68 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 65 def search_header(name) path = search_header_path name path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1') end |