mundler 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48991edd8f68a6db41fc93f84ba8631ffce3e296aecfaeac6bfd8ed1cd8d7a4c
4
- data.tar.gz: 6b09d50fe5fb6a5b79f6fdf92a87a1968a1e028474a606f98312acd18e00a23a
3
+ metadata.gz: e34cffc5ea496c40d16c21f544456bf5fa2db7f921e7c70aa000c5b5fdb5cdc5
4
+ data.tar.gz: 125ad566d2322fa8d931a428c5d8cdfc7df98818dd3e793c1a7a23b66e225758
5
5
  SHA512:
6
- metadata.gz: ab39110a71818d4f1f544e7dd6effe6ff2cb88557db5d2d18cd430f70bff5bd6a4947d3533f8b66f4aea3bca12210910ce42f452e089c72138d0e2ed0becf65e
7
- data.tar.gz: d33d00f82e5be842c712e9b90fba5d101453ce52dcbc3e171d41922c22d4ae0bc7cb14a6fdcc6a4f8f35e9f6cc0b4791368a91589235553b599d62690a292068
6
+ metadata.gz: 326e51648e28ea76872db38f4d8c03168960fad4ed5ee8c53e37b7d6da3d8605f62152a1aa87d22dd04b6e4070bfa60fad265cb52ec5dc8046c323f5f4488219
7
+ data.tar.gz: ba5c5387ddfa27ac31e10f53c128e4b26c319c03dcfde893bea970309025bc44d1cfdb568662e60071a3a255d72312b758d870bb180e9407e8626dfb81a90c99
data/exe/mundle CHANGED
@@ -4,4 +4,6 @@ require "bundler/setup"
4
4
  require "mundler"
5
5
  require "mundler/cli"
6
6
 
7
+ Bundler.require
8
+
7
9
  Mundler::CLI.start(ARGV)
@@ -61,10 +61,90 @@ module Mundler
61
61
  .join("\n")
62
62
  end
63
63
 
64
- def platform(attributes)
65
- type = @config.platform_types[attributes[:name].to_s]
66
- raise "Can't find platform: #{attributes[:name]}" unless type
67
- type.config(attributes, self)
64
+ def platform(platform_attrs)
65
+ platform_name = platform_attrs[:name].to_s
66
+ type = @config.platform_types[platform_name]
67
+ raise "Can't find platform: #{platform_name}" unless type
68
+
69
+ options = {}
70
+ @config.libraries.each do |library_name, library_options|
71
+ library_type = @config.library_types[library_name]
72
+
73
+ raise "Unknown library: #{library_name}" unless library_type
74
+
75
+ library_builder = library_type.new
76
+
77
+ puts "Using #{library_name} library (#{platform_name})"
78
+ library_builder.build(platform_name, library_options)
79
+ library_attrs = library_builder.platform_configuration(platform_name, library_options)
80
+ raise "Library #{library_name} for platform #{platform_name} returned expected result" unless library_attrs.is_a?(Hash)
81
+ merge_platform_attributes!(options, library_attrs)
82
+ end
83
+
84
+ merge_platform_attributes!(options, platform_attrs[:options])
85
+
86
+ type.config(options, self)
87
+ end
88
+
89
+ # Merge with a bit of specific logic to make sure build settings
90
+ #
91
+ # E.g. if lhs was something like
92
+ #
93
+ # ```
94
+ # {
95
+ # cc: { flags: "-I#{sdl_install}/include/SDL2" },
96
+ # linker: { flags: "-L#{sdl_install}/lib -lSDL2 -lSDL2_image -lSDL2_ttf" }
97
+ # }
98
+ # ```
99
+ #
100
+ # and rhs was like
101
+ #
102
+ # ```
103
+ # {
104
+ # cc: { flags: "abc" },
105
+ # linker: { flags: "def" },
106
+ # more_options: true
107
+ # }
108
+ # ```
109
+ #
110
+ # result would be
111
+ # ```
112
+ # {
113
+ # cc: { flags: ["-I#{sdl_install}/include/SDL2", "abc"] },
114
+ # linker: { flags: ["-L#{sdl_install}/lib -lSDL2 -lSDL2_image -lSDL2_ttf", "def"] }
115
+ # more_options: true
116
+ # }
117
+ # ```
118
+ #
119
+ def merge_platform_attributes!(lhs, rhs)
120
+ rhs = rhs.dup
121
+
122
+ [:cc, :linker].each do |cc_or_linker|
123
+ [:command, :flags].each do |command_or_flags|
124
+ lhs_flags = lhs.dig(cc_or_linker, command_or_flags)
125
+ rhs_flags = rhs.dig(cc_or_linker, command_or_flags)
126
+
127
+ if rhs_flags
128
+ lhs[cc_or_linker] ||= {}
129
+ lhs[cc_or_linker][command_or_flags] ||= []
130
+ lhs_flags = lhs.dig(cc_or_linker, command_or_flags)
131
+
132
+ if lhs_flags.is_a?(String)
133
+ lhs[cc_or_linker][command_or_flags] = [lhs_flags]
134
+ end
135
+
136
+ if rhs_flags.is_a?(String)
137
+ rhs[cc_or_linker][command_or_flags] = [rhs_flags]
138
+ end
139
+
140
+ lhs[cc_or_linker][command_or_flags] = lhs[cc_or_linker][command_or_flags] + rhs[cc_or_linker][command_or_flags]
141
+ end
142
+ end
143
+
144
+ rhs.delete(cc_or_linker)
145
+ end
146
+
147
+ lhs.merge!(rhs)
68
148
  end
69
149
 
70
150
  def env_vars
@@ -0,0 +1,11 @@
1
+ module Mundler
2
+ def self.with_clean_env(&blk)
3
+ if defined?(Bundler) && Bundler.respond_to?(:with_unbundled_env)
4
+ Bundler.with_unbundled_env(&blk)
5
+ elsif defined?(Bundler)
6
+ Bundler.with_clean_env(&blk)
7
+ else
8
+ blk.call
9
+ end
10
+ end
11
+ end
data/lib/mundler/cli.rb CHANGED
@@ -11,11 +11,12 @@ module Mundler
11
11
  desc "install", "Download and compile mruby"
12
12
  def install
13
13
  Mundler::Project.new(Dir.pwd).install
14
+ puts("\e[32mMundle complete!\e[0m")
14
15
  rescue Mundler::CompilationError
15
- $stderr.puts("\e[31mFailed to install\e[0m")
16
+ $stderr.puts("\e[31mMundle failed\e[0m")
16
17
  exit 1
17
18
  rescue Interrupt
18
- $stderr.puts("\e[31mUser cancelled\e[0m")
19
+ $stderr.puts("\e[31mMundle failed (user cancelled)\e[0m")
19
20
  exit 1
20
21
  rescue MundlefileNotFound
21
22
  $stderr.puts("\e[31mMundlefile not found in the current directory\e[0m")
@@ -27,6 +28,7 @@ module Mundler
27
28
  project = Mundler::Project.new(Dir.pwd)
28
29
  project.clean
29
30
  project.install
31
+ puts("\e[32mMundle complete!\e[0m")
30
32
  rescue Mundler::CompilationError
31
33
  $stderr.puts("\e[31mFailed to install\e[0m")
32
34
  exit 1
@@ -10,11 +10,15 @@ module Mundler
10
10
  @gemboxes = []
11
11
  @gems = []
12
12
  @platform_types = {}
13
+ @library_types = {}
13
14
  @env = {}
15
+ @libraries = {}
14
16
  end
15
17
 
16
18
  attr_reader :mruby
17
19
  attr_reader :platform_types
20
+ attr_reader :library_types
21
+ attr_reader :libraries
18
22
  attr_reader :env
19
23
 
20
24
  def hex
@@ -38,9 +42,11 @@ module Mundler
38
42
  #{mruby.inspect}
39
43
  #{platforms.inspect}
40
44
  #{platform_types.keys.sort.inspect}
45
+ #{library_types.keys.sort.inspect}
41
46
  #{hashable_string_for_hash(env)}
42
47
  #{gemboxes.inspect}
43
48
  #{gems.inspect}
49
+ #{hashable_string_for_hash(libraries)}
44
50
  HASHABLE
45
51
  end
46
52
 
@@ -50,9 +56,9 @@ module Mundler
50
56
  str = "{"
51
57
  sorted_keys = hash.keys.sort
52
58
 
53
- sorted_keys.each do |key|
59
+ sorted_keys.map do |key|
54
60
  str = str + "#{key}=>#{hash[key]}"
55
- end
61
+ end.join(", ")
56
62
 
57
63
  str + "}"
58
64
  end
data/lib/mundler/dsl.rb CHANGED
@@ -3,13 +3,12 @@ module Mundler
3
3
  def initialize(path)
4
4
  @config = Config.new
5
5
  @path = path
6
+
7
+ load_libraries
8
+ load_platforms
6
9
  end
7
10
 
8
11
  def evaluate!
9
- platforms = Dir.glob(File.join(__dir__, "platforms", "*.rb"))
10
- platforms.each do |platform|
11
- instance_eval(File.read(platform))
12
- end
13
12
  begin
14
13
  instance_eval(File.read(@path), @path)
15
14
  rescue Errno::ENOENT
@@ -19,6 +18,20 @@ module Mundler
19
18
 
20
19
  attr_reader :config
21
20
 
21
+ def load_libraries
22
+ libraries = Dir.glob(File.join(__dir__, "libraries", "*.rb"))
23
+ libraries.each do |library|
24
+ instance_eval(File.read(library))
25
+ end
26
+ end
27
+
28
+ def load_platforms
29
+ platforms = Dir.glob(File.join(__dir__, "platforms", "*.rb"))
30
+ platforms.each do |platform|
31
+ instance_eval(File.read(platform))
32
+ end
33
+ end
34
+
22
35
  private
23
36
 
24
37
  def mruby(url: nil, tag: nil, branch: nil)
@@ -52,5 +65,13 @@ module Mundler
52
65
  def env(name, value)
53
66
  config.env[name] = value
54
67
  end
68
+
69
+ def library(name, options = {})
70
+ config.libraries[name.to_s] = options
71
+ end
72
+
73
+ def define_library(name, library_class)
74
+ config.library_types[name.to_s] = library_class
75
+ end
55
76
  end
56
77
  end
@@ -0,0 +1,13 @@
1
+ # class ExampleLibrary
2
+ # def build(platform, options)
3
+ # end
4
+
5
+ # def platform_configuration(platform, options)
6
+ # {
7
+ # cc: { flags: "X" },
8
+ # linker: { flags: "Y" }
9
+ # }
10
+ # end
11
+ # end
12
+
13
+ # define_library "example", ExampleLibrary
data/lib/mundler/mruby.rb CHANGED
@@ -29,7 +29,8 @@ module Mundler
29
29
  FileUtils.rm_rf(@path)
30
30
  FileUtils.mkdir_p(@path)
31
31
  FileUtils.cd(@path)
32
- git_clone = Proc.new do
32
+
33
+ Mundler.with_clean_env do
33
34
  system(
34
35
  {
35
36
  # The {mundler gem path}/cached_git directory contains a binary called
@@ -38,15 +39,7 @@ module Mundler
38
39
  "PATH" => ([cached_git_dir] + ENV["PATH"].split(":")).join(":")
39
40
  },
40
41
  "git clone #{mruby_url} . >/dev/null 2>&1"
41
- ) || error_out("Failed to clone mruby: #{mruby_url}")
42
- end
43
-
44
- if defined?(Bundler) && Bundler.respond_to?(:with_unbundled_env)
45
- Bundler.with_unbundled_env(&git_clone)
46
- elsif defined?(Bundler)
47
- Bundler.with_clean_env(&git_clone)
48
- else
49
- git_clone.call
42
+ ) || raise(Mundler::CloneError, "Failed to clone #{mruby_url}")
50
43
  end
51
44
 
52
45
  if version
@@ -70,6 +63,22 @@ module Mundler
70
63
  def compile(build_config)
71
64
  logfile = Tempfile.new(['mundler_build', '.log'])
72
65
 
66
+ version = (
67
+ @config.mruby[:tag] ||
68
+ @config.mruby[:branch] ||
69
+ @config.mruby[:version]
70
+ )
71
+
72
+ @config.gemboxes.each do |gembox|
73
+ puts "Using #{gembox} gembox"
74
+ end
75
+ @config.gems.each do |gem|
76
+ puts "Using #{gem[:name]} gem"
77
+ end
78
+
79
+ puts "Using mruby (#{version})"
80
+
81
+
73
82
  success_indicator = File.join(@path, ".mundler_built_successfully")
74
83
  if File.file?(success_indicator)
75
84
  return
@@ -87,14 +96,14 @@ module Mundler
87
96
  directory = pathname.directory? ? pathname.to_s : Pathname.new(file).dirname.to_s
88
97
  next if covered.include?(directory)
89
98
  covered << directory
90
- print "\e[32m.\e[0m"
99
+ print "\e[34m.\e[0m"
91
100
  end
92
101
  end
93
102
  sleep(0.3)
94
103
  end
95
104
  end
96
105
 
97
- clean = Proc.new do
106
+ Mundler.with_clean_env do
98
107
  rake = `which rake`.chomp
99
108
  system(
100
109
  {
@@ -115,9 +124,7 @@ module Mundler
115
124
  end
116
125
 
117
126
  cleaned = true
118
- end
119
127
 
120
- compile = Proc.new do
121
128
  rake = `which rake`.chomp
122
129
  system(
123
130
  {
@@ -138,20 +145,11 @@ module Mundler
138
145
  end
139
146
  end
140
147
 
141
- if defined?(Bundler) && Bundler.respond_to?(:with_unbundled_env)
142
- Bundler.with_unbundled_env(&clean)
143
- Bundler.with_unbundled_env(&compile)
144
- elsif defined?(Bundler)
145
- Bundler.with_clean_env(&clean)
146
- Bundler.with_clean_env(&compile)
147
- else
148
- clean.call
149
- compile.call
150
- end
148
+ puts "\n\n"
151
149
 
152
- output_thread.kill
153
150
  FileUtils.touch(success_indicator)
154
151
  ensure
152
+ output_thread.kill if output_thread
155
153
  logfile.close
156
154
  logfile.delete
157
155
  end
@@ -1,7 +1,6 @@
1
1
  module HostPlatform
2
- def self.config(host_options, build_config)
2
+ def self.config(options, build_config)
3
3
  build = ""
4
- options = host_options[:options]
5
4
 
6
5
  if options[:cc]
7
6
  build += " conf.cc do |cc|\n"
@@ -1,7 +1,8 @@
1
1
  module IOSPlatform
2
2
  def self.config(options, build_config)
3
3
  valid_archs = [:armv7, :arm64]
4
- options[:archs] ||= valid_archs
4
+ default_archs = [:arm64]
5
+ options[:archs] ||= default_archs
5
6
 
6
7
  options[:archs].map do |arch|
7
8
  unless valid_archs.include?(arch)
@@ -19,11 +20,11 @@ module IOSPlatform
19
20
  -isysroot #{ios_sdk}
20
21
  )
21
22
 
22
- cc_command = options.dig(:options, :cc, :command) || clang
23
- linker_command = options.dig(:options, :linker, :command) || clang
23
+ cc_command = options.dig(:cc, :command) || clang
24
+ linker_command = options.dig(:linker, :command) || clang
24
25
 
25
- cc_flags = flags + Array(options.dig(:options, :cc, :flags) || [])
26
- linker_flags = flags + Array(options.dig(:options, :linker, :flags) || [])
26
+ cc_flags = flags + Array(options.dig(:cc, :flags) || [])
27
+ linker_flags = flags + Array(options.dig(:linker, :flags) || [])
27
28
 
28
29
  <<~BUILD
29
30
  MRuby::CrossBuild.new("ios__#{arch}") do |conf|
@@ -1,6 +1,6 @@
1
1
  module IOSSimulatorPlatform
2
2
  def self.config(options, build_config)
3
- valid_archs = [:i386, :x86_64]
3
+ valid_archs = [:i386, :x86_64, :arm64]
4
4
  options[:archs] ||= valid_archs
5
5
 
6
6
  options[:archs].map do |arch|
@@ -19,19 +19,25 @@ module IOSSimulatorPlatform
19
19
  -isysroot #{ios_simulator_sdk}
20
20
  )
21
21
 
22
+ cc_command = options.dig(:cc, :command) || clang
23
+ linker_command = options.dig(:linker, :command) || clang
24
+
25
+ cc_flags = flags + Array(options.dig(:cc, :flags) || [])
26
+ linker_flags = flags + Array(options.dig(:linker, :flags) || [])
27
+
22
28
  <<~BUILD
23
29
  MRuby::CrossBuild.new("ios_simulator__#{arch}") do |conf|
24
30
  #{build_config.gemboxes}
25
31
  #{build_config.gems}
26
32
 
27
33
  conf.cc do |cc|
28
- cc.command = #{clang.inspect}
29
- cc.flags = #{flags.inspect}
34
+ cc.command = #{cc_command.inspect}
35
+ cc.flags = #{cc_flags.inspect}
30
36
  end
31
37
 
32
38
  conf.linker do |l|
33
- l.command = #{clang.inspect}
34
- l.flags = #{flags.inspect}
39
+ l.command = #{linker_command.inspect}
40
+ l.flags = #{linker_flags.inspect}
35
41
  end
36
42
  end
37
43
  BUILD
@@ -1,3 +1,3 @@
1
1
  module Mundler
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/mundler.rb CHANGED
@@ -8,9 +8,11 @@ require "mundler/build_config"
8
8
  require "mundler/dsl"
9
9
  require "mundler/mruby"
10
10
  require "mundler/project"
11
+ require "mundler/clean_environment"
11
12
 
12
13
  module Mundler
13
14
  class CompilationError < StandardError; end
15
+ class CloneError < CompilationError; end
14
16
  class NotInstalledError < StandardError; end
15
17
  class MundlefileNotFound < StandardError; end
16
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Inkpen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-03 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -65,9 +65,11 @@ files:
65
65
  - lib/mundler/build_config.rb
66
66
  - lib/mundler/cached_git/cached_git
67
67
  - lib/mundler/cached_git/git
68
+ - lib/mundler/clean_environment.rb
68
69
  - lib/mundler/cli.rb
69
70
  - lib/mundler/config.rb
70
71
  - lib/mundler/dsl.rb
72
+ - lib/mundler/libraries/example.rb
71
73
  - lib/mundler/mruby.rb
72
74
  - lib/mundler/platforms/android.rb
73
75
  - lib/mundler/platforms/host.rb