summaryrefslogtreecommitdiffhomepage
path: root/tasks/mruby_build_gem.rake
blob: 69dd4cafc58fd48e8444eea4947a8136c6b23d46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module MRuby
  module LoadGems
    def gem(gemdir, &block)
      gemdir = load_external_gem(gemdir) if gemdir.is_a?(Hash)
      gemrake = File.join(gemdir, "mrbgem.rake")

      fail "Can't find #{gemrake}" unless File.exists?(gemrake)
      Gem.current = nil
      load gemrake
      return nil unless Gem.current

      Gem.current.dir = gemdir
      Gem.current.build = MRuby::Build.current
      Gem.current.build_config_initializer = block
      gems << Gem.current
      Gem.current
    end

    def load_external_gem(params)
      if params[:github]
        params[:git] = "https://github.com/#{params[:github]}.git"
      end

      if params[:git]
        url = params[:git]
        gemdir = "build/mrbgems/#{url.match(/([-_\w]+)(\.[-_\w]+|)$/).to_a[1]}"
        return gemdir if File.exists?(gemdir)

        options = [params[:options]] || []
        options << "--branch \"#{params[:branch]}\"" if params[:tag]

        FileUtils.mkdir_p "build/mrbgems"
        git.run_clone gemdir, url, options
        
        gemdir
      else
        fail "unknown gem option #{params}"
      end
    end

    def enable_gems?
      [email protected]?
    end
  end # LoadGems
end # MRuby