diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-10 11:46:24 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-10 11:46:24 +0900 |
| commit | 87038c2c8dd50bf97daf98f94e3d477920b2b716 (patch) | |
| tree | a8b165ef27dff1f5af493f7243b7d1c3e3a9d203 | |
| parent | 2f8047461fa3c3947970bdad3e9e076be0b246ae (diff) | |
| parent | 4e5315ff4110c467e81f273ff0af95c98b0c5bc7 (diff) | |
| download | mruby-87038c2c8dd50bf97daf98f94e3d477920b2b716.tar.gz mruby-87038c2c8dd50bf97daf98f94e3d477920b2b716.zip | |
Merge pull request #2381 from monaka/pr-add-include_paths-in-dependency-gems
Append include paths in dependency gems
| -rw-r--r-- | doc/mrbgems/README.md | 23 | ||||
| -rw-r--r-- | tasks/mrbgem_spec.rake | 23 |
2 files changed, 42 insertions, 4 deletions
diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 7ac225730..571c00450 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -76,6 +76,8 @@ The maximal GEM structure looks like this: +- GEM_NAME <- Name of GEM | + +- include/ <- Header for Ruby extension (will exported) + | +- mrblib/ <- Source for Ruby extension | +- src/ <- Source for C extension @@ -87,10 +89,10 @@ The maximal GEM structure looks like this: +- README.md <- Readme for GEM The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* -contains C files to extend mruby. The folder *test* contains C and pure Ruby files -for testing purposes which will be used by `mrbtest`. *mrbgem.rake* contains -the specification to compile C and Ruby files. *README.md* is a short description -of your GEM. +contains C/C++ files to extend mruby. The folder *include* contains C/C++ header +files. The folder *test* contains C/C++ and pure Ruby files for testing purposes +which will be used by `mrbtest`. *mrbgem.rake* contains the specification +to compile C and Ruby files. *README.md* is a short description of your GEM. ## Build process @@ -173,6 +175,19 @@ the following options additionally inside of your GEM specification: * `spec.test_objs` (Object test files for integration into mrbtest) * `spec.test_preload` (Initialization files for mrbtest) +### include_paths and depencency + +Your GEM can export include paths to another GEMs that depends on your GEM. +By default, `/...absolute path.../{GEM_NAME}/include` will be exported. +So it is recommended not to put GEM's local header files on include/. + +These exports are retroactive. +For example: when B depends to C and A depends to B, A will get include paths exported by C. + +Exported include_paths are automatically appended to GEM local include_paths by Minirake. +You can use `spec.export_include_paths` accessor if you want more complex build. + + ## C Extension mruby can be extended with C. This is possible by using the C API to diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake index 09e000a4a..c8868fe9c 100644 --- a/tasks/mrbgem_spec.rake +++ b/tasks/mrbgem_spec.rake @@ -34,6 +34,8 @@ module MRuby attr_accessor :requirements attr_reader :dependencies + attr_accessor :export_include_paths + attr_block MRuby::Build::COMMANDS def initialize(name, &block) @@ -71,6 +73,8 @@ module MRuby @requirements = [] @dependencies = [] + @export_include_paths = [] + @export_include_paths << "#{dir}/include" if File.directory? "#{dir}/include" instance_eval(&@initializer) @@ -336,6 +340,25 @@ module MRuby rescue TSort::Cyclic => e fail "Circular mrbgem dependency found: #{e.message}" end + + each do |g| + import_include_paths(g) + end + end + + def import_include_paths(g) + gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res } + g.dependencies.each do |dep| + dep_g = gem_table[dep[:gem]] + # We can do recursive call safely + # as circular dependency has already detected in the caller. + import_include_paths(dep_g) + + g.compilers.each do |compiler| + compiler.include_paths += dep_g.export_include_paths + g.export_include_paths += dep_g.export_include_paths + end + end end end # List end # Gem |
