Skip to content

Commit 9109bc9

Browse files
committed
mruby-cli app can be released with task release
1 parent 0f54c5f commit 9109bc9

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed

Rakefile

+11-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Rake::Task[:mruby].invoke unless Dir.exist?(mruby_root)
1919
Dir.chdir(mruby_root)
2020
load "#{mruby_root}/Rakefile"
2121

22+
load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake")
23+
24+
current_gem = MRuby::Gem.current
25+
app_version = MRuby::Gem.current.version
26+
APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version
27+
2228
desc "compile all the binaries"
2329
task :compile => [:all] do
2430
MRuby.each_target do |target|
@@ -77,12 +83,11 @@ end
7783
desc "generate a release tarball"
7884
task :release => :compile do
7985
require 'tmpdir'
80-
require_relative 'mrblib/mruby-cli/version'
8186

8287
# since we're in the mruby/
83-
release_dir = "releases/v#{MRubyCLI::Version::VERSION}"
88+
release_dir = "releases/v#{APP_VERSION}"
8489
release_path = Dir.pwd + "/../#{release_dir}"
85-
app_name = "mruby-cli-#{MRubyCLI::Version::VERSION}"
90+
app_name = "#{APP_NAME}-#{APP_VERSION}"
8691
FileUtils.mkdir_p(release_path)
8792

8893
Dir.mktmpdir do |tmp_dir|
@@ -109,10 +114,9 @@ task :release => :compile do
109114
end
110115

111116
namespace :local do
112-
desc "show help"
117+
desc "show version"
113118
task :version do
114-
require_relative 'mrblib/mruby-cli/version'
115-
puts "mruby-cli #{MRubyCLI::Version::VERSION}"
119+
puts "#{APP_NAME} #{APP_VERSION}"
116120
end
117121
end
118122

@@ -139,9 +143,8 @@ end
139143
namespace :package do
140144
require 'fileutils'
141145
require 'tmpdir'
142-
require_relative "#{MRUBY_ROOT}/../mrblib/mruby-cli/version"
143146

144-
version = MRubyCLI::Version::VERSION
147+
version = APP_VERSION
145148
release_dir = "releases/v#{version}"
146149
package_dir = "packages/v#{version}"
147150
release_path = Dir.pwd + "/../#{release_dir}"

mrbgem.rake

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
require_relative 'mrblib/mruby-cli/version'
22

3-
MRuby::Gem::Specification.new('mruby-cli') do |spec|
4-
spec.license = 'MIT'
5-
spec.authors = ['Terence Lee', 'Zachary Scott']
6-
spec.summary = 'mruby cli utility'
3+
spec = MRuby::Gem::Specification.new('mruby-cli') do |spec|
74
spec.bins = ['mruby-cli']
8-
spec.version = MRubyCLI::Version
9-
105
spec.add_dependency 'mruby-io', :mgem => 'mruby-io'
116
spec.add_dependency 'mruby-getopts', :mgem => 'mruby-getopts'
127
spec.add_dependency 'mruby-dir', :mgem => 'mruby-dir'
138
spec.add_dependency 'mruby-mtest', :mgem => 'mruby-mtest'
149
end
10+
11+
spec.license = 'MIT'
12+
spec.authors = ['Terence Lee', 'Zachary Scott']
13+
spec.summary = 'mruby cli utility'
14+
spec.version = MRubyCLI::Version::VERSION
15+

mrblib/mruby-cli/setup.rb

+51-9
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ def mrbgem_rake
100100
<<MRBGEM_RAKE
101101
require_relative 'mrblib/#{@name}/version'
102102
103-
MRuby::Gem::Specification.new('#{@name}') do |spec|
104-
spec.license = 'MIT'
105-
spec.author = 'MRuby Developer'
106-
spec.summary = '#{@name}'
103+
spec = MRuby::Gem::Specification.new('#{@name}') do |spec|
107104
spec.bins = ['#{@name}']
108-
spec.version = #{Util.camelize(@name)}::VERSION
109-
110105
spec.add_dependency 'mruby-print', :core => 'mruby-print'
111106
spec.add_dependency 'mruby-mtest', :mgem => 'mruby-mtest'
112107
end
108+
109+
spec.license = 'MIT'
110+
spec.author = 'MRuby Developer'
111+
spec.summary = '#{@name}'
112+
spec.version = #{Util.camelize(@name)}::VERSION
113113
MRBGEM_RAKE
114114
end
115115

@@ -304,6 +304,9 @@ def docker_compose_yml
304304
shell:
305305
<<: *defaults
306306
command: bash
307+
release:
308+
<<: *defaults
309+
command: rake release
307310
DOCKER_COMPOSE_YML
308311
end
309312

@@ -330,6 +333,13 @@ def rakefile
330333
Dir.chdir(mruby_root)
331334
load "\#{mruby_root}/Rakefile"
332335
336+
337+
load File.join(File.expand_path(File.dirname(__FILE__)), "mrbgem.rake")
338+
339+
current_gem = MRuby::Gem.current
340+
app_version = MRuby::Gem.current.version
341+
APP_VERSION = (app_version.nil? || app_version.empty?) ? "unknown" : app_version
342+
333343
desc "compile binary"
334344
task :compile => [:all] do
335345
@@ -386,11 +396,43 @@ def clean_env(envs)
386396
sh "rake deep_clean"
387397
end
388398
399+
desc "generate a release tarball"
400+
task :release => :compile do
401+
require 'tmpdir'
402+
403+
# since we're in the mruby/
404+
release_dir = "releases/v\#{APP_VERSION}"
405+
release_path = Dir.pwd + "/../\#{release_dir}"
406+
app_name = "\#{APP_NAME}-\#{APP_VERSION}"
407+
FileUtils.mkdir_p(release_path)
408+
409+
Dir.mktmpdir do |tmp_dir|
410+
Dir.chdir(tmp_dir) do
411+
MRuby.each_target do |target|
412+
next if name == "host"
413+
414+
arch = name
415+
bin = "\#{build_dir}/bin/\#{exefile(APP_NAME)}"
416+
FileUtils.mkdir_p(name)
417+
FileUtils.cp(bin, name)
418+
419+
Dir.chdir(arch) do
420+
arch_release = "\#{app_name}-\#{arch}"
421+
puts "Writing \#{release_dir}/\#{arch_release}.tgz"
422+
`tar czf \#{release_path}/\#{arch_release}.tgz *`
423+
end
424+
end
425+
426+
puts "Writing \#{release_dir}/\#{app_name}.tgz"
427+
`tar czf \#{release_path}/\#{app_name}.tgz *`
428+
end
429+
end
430+
end
431+
389432
namespace :local do
390-
desc "show help"
433+
desc "show version"
391434
task :version do
392-
require_relative 'mrblib/mruby-cli/version'
393-
puts "mruby-cli \#{MRubyCLI::Version::VERSION}"
435+
puts "\#{APP_NAME} \#{APP_VERSION}"
394436
end
395437
end
396438

0 commit comments

Comments
 (0)