Permalink
Browse files

Refactored rubyspec tasks into re-usable class and added the same tas…

…ks for mspec.

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1345 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent af2279f commit ba40898eec6cdb4ba625ba771fc7fa539d39b458 @alloy alloy committed Apr 4, 2009
Showing with 161 additions and 137 deletions.
  1. +3 −1 .gitignore
  2. +0 −136 rakelib/rubyspec.rake
  3. +18 −0 rakelib/rubyspec_mspec.rake
  4. +140 −0 rakelib/upstream_git_repo_tasks.rb
View
@@ -11,4 +11,6 @@ revision.h
y.tab.c
include/ruby/config.h
spec/ruby
-spec/frozen/upstream_patches
+spec/frozen/upstream_patches
+mspec_upstream
+mspec/upstream_patches
View
@@ -1,136 +0,0 @@
-require 'rakelib/git'
-
-namespace :rubyspec do
- desc "Initialize spec/ruby with a rubyspec clone"
- task :init do
- if File.exists? spec_ruby
- unless is_git_project spec_ruby, "rubyspec.git"
- raise "#{spec_ruby} is not a rubyspec clone. Please remove before running this task."
- end
- else
- sh "git clone git://github.com/rubyspec/rubyspec.git #{spec_ruby}"
- end
- end
-
- desc "Update rubyspec"
- task :update => :init do
- puts "\nUpdating rubyspec repository..."
- Dir.chdir spec_ruby do
- git_update
- end
- end
-
- desc "Report changes to the rubyspec sources"
- task :status do
- Dir.chdir spec_ruby do
- system "git status"
- end
- end
-
- desc "Commit changes to the rubyspec sources"
- task :commit do
- puts "\nCommitting changes to rubyspec sources..."
- Dir.chdir spec_ruby do
- sh "git commit -a"
- end
- end
-
- desc "Push changes to the rubyspec repository"
- task :push => :update do
- puts "\nPushing changes to the rubyspec repository..."
- Dir.chdir spec_ruby do
- git_push
- end
- end
-
- desc "Switch to the `master' branch"
- task :master do
- Dir.chdir spec_ruby do
- git_checkout('master')
- end
- end
-
- namespace :sync do
- def upstream_rev
- @upstream_rev ||= ENV['REV'] || File.read('spec/frozen/upstream')
- end
-
- UPSTREAM_OPTIONS = {
- :branch => "merge_upstream",
- :exclude => %w{ upstream macruby.mspec tags/macruby },
- :revert => %w{ ruby.1.9.mspec }
- }
-
- desc "Synchronize a checkout with spec/frozen (upstream)"
- task :upstream do
- puts "\nSwitching to a `#{UPSTREAM_OPTIONS[:branch]}' branch with current revision of spec/frozen: #{upstream_rev}"
- Dir.chdir(spec_ruby) { git_checkout(upstream_rev, UPSTREAM_OPTIONS[:branch]) }
-
- dir = ENV['DIR'] || spec_ruby
- sh "rm -rf #{dir}/**"
-
- rsync_options = Rsync_options.sub("--exclude 'tags'", '')
- rsync_options += UPSTREAM_OPTIONS[:exclude].map { |f| "--exclude '#{f}'" }.join(' ')
- rsync "spec/frozen/*", dir, rsync_options
-
- Dir.chdir(spec_ruby) do
- sh "git checkout #{UPSTREAM_OPTIONS[:revert].join(' ')}"
- sh "git status"
- end
- end
-
- namespace :upstream do
- desc "Creates all individual patches in spec/frozen/upstream_patches since upstream revision of spec/frozen: #{upstream_rev}"
- task :patches do
- patch_dir = File.expand_path('spec/frozen/upstream_patches')
- create_patches = "git format-patch --numbered --output-directory #{patch_dir} #{upstream_rev}"
-
- Dir.chdir(spec_ruby) do
- git_checkout('master')
- sh create_patches
- end
- end
-
- desc "Remove the `#{UPSTREAM_OPTIONS[:branch]}' branch and switch to the `master' branch (cleans all untracked files!)"
- task :remove do
- puts "\nRemoving the `#{UPSTREAM_OPTIONS[:branch]}' branch and all untracked files!"
- Dir.chdir spec_ruby do
- sh "git clean -f"
- sh "git checkout ."
- git_checkout('master')
- sh "git branch -D #{UPSTREAM_OPTIONS[:branch]}"
- end
- end
- end
-
- desc "Synchronize spec/frozen with a current checkout (downstream)"
- task :downstream => 'rubyspec:update' do
- dir = ENV['DIR'] || spec_ruby
-
- rm_rf "spec/frozen"
- rsync dir + "/*", "spec/frozen"
-
- version = Dir.chdir(dir) { `git log --pretty=oneline -1`[0..7] }
- sh "git add spec/frozen/"
- sh "git commit -m 'Updated CI frozen specs to RubySpec #{version}.' spec/frozen"
- end
- end
-
- namespace :url do
- desc "Switch to the rubyspec commiter URL"
- task :committer do
- Dir.chdir spec_ruby do
- sh "git config remote.origin.url git@github.com:rubyspec/rubyspec.git"
- end
- puts "\nYou're now accessing rubyspec via the committer URL."
- end
-
- desc "Switch to the rubyspec anonymous URL"
- task :anon do
- Dir.chdir spec_ruby do
- sh "git config remote.origin.url git://github.com/rubyspec/rubyspec.git"
- end
- puts "\nYou're now accessing rubyspec via the anonymous URL."
- end
- end
-end
@@ -0,0 +1,18 @@
+require 'rakelib/upstream_git_repo_tasks'
+
+root = File.expand_path("../../", __FILE__)
+
+Rake::UpstreamGitRepoTasks.new :rubyspec do |r|
+ r.local_dir = File.join(root, 'spec/frozen')
+ r.upstream_dir = ENV['DIR'] || File.join(root, 'spec/ruby')
+ r.anon_url = 'git://github.com/rubyspec/rubyspec.git'
+ r.commit_url = 'git@github.com:rubyspec/rubyspec.git'
+ r.upstream_options[:exclude].concat %w{ macruby.mspec tags/macruby ruby.1.9.mspec }
+end
+
+Rake::UpstreamGitRepoTasks.new :mspec do |r|
+ r.local_dir = File.join(root, 'mspec')
+ r.upstream_dir = ENV['DIR'] || File.join(root, 'mspec_upstream')
+ r.anon_url = 'git://github.com/rubyspec/mspec.git'
+ r.commit_url = 'git@github.com:rubyspec/mspec.git'
+end
@@ -0,0 +1,140 @@
+require 'rakelib/git'
+
+class Rake::UpstreamGitRepoTasks
+ attr_accessor :name, :local_dir, :upstream_dir, :anon_url, :commit_url, :upstream_options
+
+ def initialize(name)
+ @name = name
+ @upstream_options = {
+ :branch => 'merge_upstream',
+ :exclude => %w{ upstream }
+ }
+ yield self
+ define
+ end
+
+ def upstream_rev
+ @upstream_rev ||= ENV['REV'] || File.read(File.join(@local_dir, 'upstream'))
+ end
+
+ def define
+ namespace @name do
+ desc "Initialize #{@upstream_dir} with a #{@name} clone"
+ task :init do
+ if File.exists?(@upstream_dir)
+ unless is_git_project(@upstream_dir, "#{@name}.git")
+ raise "#{@upstream_dir} is not a #{@name} clone. Please remove before running this task."
+ end
+ else
+ sh "git clone #{@anon_url} #{@upstream_dir}"
+ end
+ end
+
+ desc "Update #{@name}"
+ task :update => :init do
+ puts "\nUpdating #{@name} repository..."
+ Dir.chdir @upstream_dir do
+ git_update
+ end
+ end
+
+ desc "Report changes to the #{@name} sources"
+ task :status do
+ Dir.chdir @upstream_dir do
+ system "git status"
+ end
+ end
+
+ desc "Commit changes to the #{@name} sources"
+ task :commit do
+ puts "\nCommitting changes to #{@name} sources..."
+ Dir.chdir @upstream_dir do
+ sh "git commit -a"
+ end
+ end
+
+ desc "Push changes to the #{@name} repository"
+ task :push => :update do
+ puts "\nPushing changes to the #{@name} repository..."
+ Dir.chdir @upstream_dir do
+ git_push
+ end
+ end
+
+ desc "Switch to the `master' branch"
+ task :master do
+ Dir.chdir @upstream_dir do
+ git_checkout('master')
+ end
+ end
+
+ namespace :url do
+ desc "Switch to the #{@name} commiter URL"
+ task :committer do
+ Dir.chdir @upstream_dir do
+ sh "git config remote.origin.url #{@commit_url}"
+ end
+ puts "\nYou're now accessing #{@name} via the committer URL."
+ end
+
+ desc "Switch to the #{@name} anonymous URL"
+ task :anon do
+ Dir.chdir @upstream_dir do
+ sh "git config remote.origin.url #{@anon_url}"
+ end
+ puts "\nYou're now accessing #{@name} via the anonymous URL."
+ end
+ end
+
+ namespace :sync do
+ desc "Synchronize a checkout with #{@local_dir} (upstream)"
+ task :upstream do
+ puts "\nSwitching to a `#{@upstream_options[:branch]}' branch with current revision of #{@local_dir}: #{upstream_rev}"
+ Dir.chdir(@upstream_dir) { git_checkout(upstream_rev, @upstream_options[:branch]) }
+ sh "rm -rf #{@upstream_dir}/**"
+
+ rsync_options = Rsync_options.sub("--exclude 'tags'", '')
+ rsync_options += @upstream_options[:exclude].map { |f| "--exclude '#{f}'" }.join(' ')
+ rsync "#{@local_dir}/*", @upstream_dir, rsync_options
+
+ Dir.chdir(@upstream_dir) { system "git status" }
+ end
+
+ namespace :upstream do
+ desc "Creates all individual patches in #{@local_dir}/upstream_patches since upstream revision: #{upstream_rev}"
+ task :patches do
+ create_patches = "git format-patch --numbered --output-directory #{File.join(@local_dir, 'upstream_patches')} #{upstream_rev}"
+ Dir.chdir(@upstream_dir) do
+ git_checkout('master')
+ sh create_patches
+ end
+ end
+
+ desc "Remove the `#{@upstream_options[:branch]}' branch and switch to the `master' branch (cleans all untracked files!)"
+ task :remove do
+ puts "\nRemoving the `#{@upstream_options[:branch]}' branch and all untracked files!"
+ Dir.chdir @upstream_dir do
+ sh "git clean -f"
+ sh "git checkout ."
+ git_checkout('master')
+ sh "git branch -D #{@upstream_options[:branch]}"
+ end
+ end
+ end
+
+ # desc "Synchronize spec/frozen with a current checkout (downstream)"
+ # task :downstream => 'rubyspec:update' do
+ # dir = ENV['DIR'] || spec_ruby
+ #
+ # rm_rf "spec/frozen"
+ # rsync dir + "/*", "spec/frozen"
+ #
+ # version = Dir.chdir(dir) { `git log --pretty=oneline -1`[0..7] }
+ # sh "git add spec/frozen/"
+ # sh "git commit -m 'Updated CI frozen specs to RubySpec #{version}.' spec/frozen"
+ # end
+ end
+
+ end
+ end
+end

0 comments on commit ba40898

Please sign in to comment.