-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all code inside ruby.rb crazy fun into its own namespace to make…
… it easier to triage
- Loading branch information
Showing
10 changed files
with
228 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
rake_tasks/crazy_fun/mappings/ruby_mappings/add_test_defaults.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class RubyMappings | ||
class AddTestDefaults | ||
def handle(_fun, dir, args) | ||
args[:include] = Array(args[:include]) | ||
args[:include] << "#{dir}/spec" | ||
|
||
args[:command] = args[:command] || "rspec" | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
rake_tasks/crazy_fun/mappings/ruby_mappings/add_test_dependencies.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class RubyMappings | ||
class AddTestDependencies < Tasks | ||
def handle(_fun, dir, args) | ||
task = Rake::Task[task_name(dir, "#{args[:name]}-test")] | ||
|
||
if args.has_key?(:deps) | ||
add_dependencies task, dir, args[:deps] | ||
end | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
rake_tasks/crazy_fun/mappings/ruby_mappings/check_test_args.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class RubyMappings | ||
class CheckTestArgs | ||
def handle(_fun, dir, args) | ||
raise "no :srcs specified for #{dir}" unless args.has_key? :srcs | ||
raise "no :name specified for #{dir}" unless args.has_key? :name | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
rake_tasks/crazy_fun/mappings/ruby_mappings/expand_source_files.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class RubyMappings | ||
class ExpandSourceFiles | ||
def handle(_fun, dir, args) | ||
args[:srcs] = args[:srcs].map { |str| Dir[File.join(dir, str)] }.flatten | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class RubyMappings | ||
class RubyDocs < Tasks | ||
def handle(_fun, dir, args) | ||
files = args[:files] || raise("no :files specified for rubydocs") | ||
output_dir = args[:output_dir] || raise("no :output_dir specified for rubydocs") | ||
readme = args[:readme] || raise("no :readme specified for rubydocs") | ||
|
||
files = files.map { |pattern| "build/rb/#{pattern}" } | ||
output_dir = "build/#{output_dir}" | ||
readme = "build/rb/#{readme}" | ||
|
||
desc 'Generate Ruby API docs' | ||
task "//#{dir}:docs" => args[:deps] do | ||
yard_args = %w[doc --verbose] | ||
yard_args += ["--output-dir", output_dir] | ||
yard_args += ["--readme", readme] | ||
|
||
ruby :command => "yard", | ||
:args => yard_args, | ||
:files => files | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
class RubyMappings | ||
class RubyGem | ||
def handle(_fun, dir, args) | ||
raise "no :gemspec for rubygem" unless args[:gemspec] | ||
|
||
define_clean_task dir, args | ||
define_build_task dir, args | ||
define_release_task dir, args | ||
|
||
define_gem_install_task dir, args | ||
end | ||
|
||
def define_build_task(dir, args) | ||
gemspec = File.expand_path(args[:gemspec]) | ||
deps = Array(args[:deps]) | ||
spec_dir = File.dirname(gemspec) | ||
|
||
desc "Build #{args[:gemspec]}" | ||
task "//#{dir}:gem:build" => deps do | ||
require 'rubygems/package' | ||
|
||
file = Dir.chdir(spec_dir) do | ||
spec = eval(File.read(gemspec)) | ||
Gem::Package.build(spec) | ||
end | ||
|
||
mv File.join(spec_dir, file), "build/" | ||
end | ||
end | ||
|
||
def define_clean_task(dir, _args) | ||
desc 'Clean rubygem artifacts' | ||
task "//#{dir}:gem:clean" do | ||
Dir['build/*.gem'].each { |gem| rm(gem) } | ||
end | ||
end | ||
|
||
def define_release_task(dir, _args) | ||
desc 'Build and release the ruby gem to Gemcutter' | ||
task "//#{dir}:gem:release" => %W[//#{dir}:gem:clean //#{dir}:gem:build] do | ||
gem = Dir['build/*.gem'].first # safe as long as :clean does its job | ||
sh "gem", "push", gem | ||
end | ||
end | ||
|
||
def define_gem_install_task(dir, _args) | ||
desc 'Install gem dependencies for the current Ruby' | ||
task "//#{dir}:bundle" do | ||
bundler_path = "#{Dir.pwd}/build/third_party/rb/bundler" | ||
mkdir_p bundler_path | ||
|
||
bin_path = [bundler_path, "bin"].join(File::SEPARATOR) | ||
bin_path.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR # Windows | ||
mkdir_p bin_path | ||
|
||
path = ENV["PATH"].split(File::PATH_SEPARATOR) | ||
path = [bin_path, path].flatten.uniq.join(File::PATH_SEPARATOR) | ||
|
||
ENV["BUNDLE_GEMFILE"] = "rb/Gemfile" | ||
ENV["GEM_PATH"] = bundler_path | ||
ENV["PATH"] = path | ||
|
||
gems = `gem list`.split("\n") | ||
if gems.grep(/^bundler\s/).empty? | ||
bundler_gem = Dir["third_party/rb/bundler-*.gem"].first | ||
|
||
sh "gem", "install", "--local", "--no-ri", "--no-rdoc", | ||
"--install-dir", ENV["GEM_PATH"], | ||
"--bindir", ENV["PATH"].split(File::PATH_SEPARATOR).first, | ||
bundler_gem | ||
end | ||
|
||
sh "bundle", "config", "--local", "cache_path", "../third_party/rb/vendor/cache" | ||
sh "bundle", "config", "--local", "path", "#{Dir.pwd}/build/third_party/rb/vendor/bundle" | ||
|
||
sh "bundle", "install", "--local" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.