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.
-
#cxx_invalid_flags ⇒ Object
Returns the value of attribute cxx_invalid_flags.
-
#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.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 54 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' = '%{flags} -o %{outfile} -c %{infile}' @cxx_invalid_flags = [] end |
Instance Attribute Details
#compile_options ⇒ Object
Returns the value of attribute compile_options.
51 52 53 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 51 def end |
#cxx_compile_flag ⇒ Object
Returns the value of attribute cxx_compile_flag.
52 53 54 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 52 def cxx_compile_flag @cxx_compile_flag end |
#cxx_exception_flag ⇒ Object
Returns the value of attribute cxx_exception_flag.
52 53 54 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 52 def cxx_exception_flag @cxx_exception_flag end |
#cxx_invalid_flags ⇒ Object
Returns the value of attribute cxx_invalid_flags.
52 53 54 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 52 def cxx_invalid_flags @cxx_invalid_flags end |
#defines ⇒ Object
Returns the value of attribute defines.
50 51 52 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 50 def defines @defines end |
#flags ⇒ Object
Returns the value of attribute flags.
50 51 52 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 50 def flags @flags end |
#include_paths ⇒ Object Also known as: header_search_paths
Returns the value of attribute include_paths.
50 51 52 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 50 def include_paths @include_paths end |
#option_define ⇒ Object
Returns the value of attribute option_define.
51 52 53 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 51 def option_define @option_define end |
#option_include_path ⇒ Object
Returns the value of attribute option_include_path.
51 52 53 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 51 def option_include_path @option_include_path end |
#out_ext ⇒ Object
Returns the value of attribute out_ext.
51 52 53 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 51 def out_ext @out_ext end |
#source_exts ⇒ Object
Returns the value of attribute source_exts.
50 51 52 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 50 def source_exts @source_exts end |
Instance Method Details
#all_flags(_defines = [], _include_paths = [], _flags = []) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 79 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
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 128 129 130 131 132 133 134 135 136 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 103 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
91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 91 def run(outfile, infile, _defines=[], _include_paths=[], _flags=[]) 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
74 75 76 77 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 74 def search_header(name) path = search_header_path name path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1') end |
#search_header_path(name) ⇒ Object
68 69 70 71 72 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 68 def search_header_path(name) header_search_paths.find do |v| File.exist? build.filename("#{v}/#{name}").sub(/^"(.*)"$/, '\1') end end |