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
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.
-
#label ⇒ Object
Returns the value of attribute label.
-
#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.
- #preprocess_options ⇒ Object
-
#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 = '', out_ext = build.exts.object) ⇒ Object
-
#initialize(build, source_exts = [], label: "CC") ⇒ 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 = [], label: "CC") ⇒ Compiler
Returns a new instance of Compiler.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 47 def initialize(build, source_exts=[], label: "CC") super(build) @command = ENV['CC'] || 'cc' @label = label @flags = [ENV['CFLAGS'] || []] @source_exts = source_exts @include_paths = ["#{MRUBY_ROOT}/include"] @defines = %w() @option_include_path = %q[-I"%s"] @option_define = %q[-D"%s"] @compile_options = %q[%{flags} -o "%{outfile}" -c "%{infile}"] @cxx_invalid_flags = [] @out_ext = build.exts.object 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 |
#cxx_invalid_flags ⇒ Object
Returns the value of attribute cxx_invalid_flags.
44 45 46 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 44 def cxx_invalid_flags @cxx_invalid_flags 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 |
#label ⇒ Object
Returns the value of attribute label.
42 43 44 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 42 def label @label 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 |
#preprocess_options ⇒ Object
64 65 66 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 64 def @preprocess_options ||= @compile_options.sub(/(?:\A|\s)\K-c(?=\s)/, "-E -P") 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
79 80 81 82 83 84 85 |
# 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| option_include_path % filename(f) end [flags, define_flags, include_path_flags, _flags].flatten.join(' ') end |
#define_rules(build_dir, source_dir = '', out_ext = build.exts.object) ⇒ Object
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 128 129 130 131 132 133 134 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 102 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
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 87 def run(outfile, infile, _defines=[], _include_paths=[], _flags=[]) mkdir_p File.dirname(outfile) flags = all_flags(_defines, _include_paths, _flags) if object_ext?(outfile) label = @label opts = else label = "CPP" opts = flags << " -DMRB_PRESYM_SCANNING" end _pp label, infile.relative_path, outfile.relative_path _run opts, flags: flags, infile: filename(infile), outfile: filename(outfile) 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 |