PageRenderTime 32ms CodeModel.GetById 10ms app.highlight 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Rakefile

http://github.com/MagLev/maglev
Rakefile | 234 lines | 196 code | 26 blank | 12 comment | 16 complexity | caa8250d02204ed50d58d6ee8263c4a0 MD5 | raw file
Possible License(s): LGPL-2.1
  1# MagLev Rakefile
  2
  3require 'rake/clean'
  4
  5begin
  6  # Try to support Rake 0.8.7 and 0.9.x (at least for a while)
  7  if defined? Rake::VERSION
  8    # Rake 0.9.x
  9    require 'rubygems'
 10    gem 'rdoc'
 11    require 'rdoc/task'
 12  else
 13    # Rake 0.8.x
 14    require 'rake/rdoctask'
 15  end
 16
 17  Rake::RDocTask.new do |rd|
 18    rd.main = "README.rdoc"
 19    rd.rdoc_files.include 'docs/*', 'LICENSES.txt'
 20    rd.rdoc_files.include 'src/kernel/bootstrap/Maglev.rb'
 21    rd.rdoc_files.include 'examples/**/*README.rdoc', 'examples/**/readme.txt'
 22  end
 23rescue LoadError => e
 24  puts e
 25  puts "Generating RDoc will not work without the rdoc gem"
 26
 27  task :rdoc do
 28    puts "Install the rdoc gem and re-run this"
 29  end
 30  task :rerdoc do
 31    puts "Install the rdoc gem and re-run this"
 32  end
 33end
 34
 35$LOAD_PATH << File.dirname(__FILE__)  # For 1.9, '.' is no longer in the load path
 36
 37require 'rakelib/gemstone_env.rb'
 38require 'rakelib/maglev_stone.rb'
 39
 40verbose false  # turn off rake's chatter about all the sh commands
 41
 42CLEAN.include('*.out', 'log/vmunit*.out', 'log/all*.out', 'html',
 43              'vmunit.log', 'topazerrors.log', 'gem_*_code.log')
 44CLOBBER.include('lib/ruby/site_ruby/1.8/smalltalk', 'version.txt')
 45
 46task :default => :status
 47
 48desc "Show status of all stones"
 49task :status do
 50  sh "$GEMSTONE/bin/gslist -clv" do |ok, status|
 51    case status.exitstatus
 52    when 0, 1
 53      # Ok, or no servers running: do nothing
 54    else
 55      raise "gslist failed: #{status.exitstatus}"
 56    end
 57  end
 58end
 59
 60if ENV["TRAVIS"]
 61  tests = {"rubyspec" => "spec:ci",
 62           "vmunit" => "travis:vmunit",
 63           "vmunit2" => "tests:vmunit2",
 64           "p_tests" => "dev:p-tests",
 65           "fav_gems" => "tests:fav_gems_install",
 66           "sinatra" => "tests:sinatra",
 67           "examples" => "tests:examples"}
 68
 69  task :travis do
 70    Rake::Task["stwrappers"].invoke
 71    ENV["PATH"] = "#{ENV['PATH']}:#{File.dirname(__FILE__)}/bin"
 72    Rake::Task[tests[ENV["CI_TESTS"]]].invoke
 73  end
 74
 75  desc "Run vmunit tests on clean stone and again after update.sh ran"
 76  task :"travis:vmunit" do
 77    unless system("rake tests:vmunit") &&
 78        system("./update.sh") &&
 79        system("rake tests:vmunit")
 80      exit 1
 81    end
 82  end
 83end
 84
 85# This initializes the environment, and then ensures that there is a
 86# gemstone diretory there.  Needed to pull this out, since some of the
 87# initialization tasks need to be performed before there is a gemstone dir
 88# there, but need the ENV var (i.e., need to know where gemstone should
 89# be).
 90task :gemstone do
 91  raise "\nBad GEMSTONE dir: '#{GEMSTONE}'" unless File.directory?(GEMSTONE)
 92  raise "\nNo etc/maglev.demo.key" unless File.exists?("etc/maglev.demo.key")
 93end
 94
 95desc "Run a squeak image"
 96task :squeak => 'netldi:start' do
 97  os = `uname`.chomp
 98  if os == "Darwin"
 99    gem_tools = '/Applications/GemTools-MagLev.app'
100    if File.exists?(gem_tools)
101      sh %{ open #{gem_tools} }
102    else
103      puts "Cannot open #{gem_tools}"
104      puts "as that file does not exist. To fix this, download and unzip"
105      puts "http://seaside.gemstone.com/squeak/GemTools-MagLev.zip"
106      puts "then move GemTools-MagLev.app to /Applications"
107    end
108  else
109    gem_tools = "#{MAGLEV_HOME}/../GemTools-MagLev.app/GemTools.sh"
110    if File.exists?(gem_tools)
111      sh "#{gem_tools}"
112    else
113      puts "Cannot open #{gem_tools}"
114      puts "as that file does not exist. To fix this, download and unzip"
115      puts "http://seaside.gemstone.com/squeak/GemTools-MagLev.zip"
116      puts "then move GemTools-MagLev.app to \$MAGLEV_HOME/../"
117    end
118  end
119end
120
121desc "Create .rb files for each smalltalk class (lib/ruby/site_ruby/1.8/smalltalk/*)"
122task :stwrappers, :force  do |t, args|
123  wrapper_dir = MAGLEV_HOME + '/lib/ruby/site_ruby/1.8/smalltalk'
124  if ! File.exist?(wrapper_dir) || args.force
125    puts "Creating .rb files for smalltalk classes in lib/ruby/site_ruby/1.8/smalltalk/"
126    run_on_stone(["omit resultcheck",
127                  "run",
128                  "RubyContext createSmalltalkFFIWrappers",
129                  "%"])
130  else
131    puts "#{wrapper_dir} already exists"
132  end
133end
134
135namespace :stone do
136  desc "List MagLev servers managed by this Rakefile"
137  task :list do
138    puts GemStoneInstallation.current.stones.join("\n")
139  end
140
141  desc "Create a new MagLev server and repository"
142  task :create, :server_name do |t, args|
143    raise ArgumentError, "Task #{t.name} requires a new server name" unless args.server_name
144    puts "Creating server \"#{args.server_name}\""
145    MagLevStone.create(args.server_name)
146  end
147
148  desc "Destroy an existing MagLev server and repository"
149  task :destroy, :server_name do |t, args|
150    raise ArgumentError, "Task #{t.name} requires an existing server name" unless args.server_name
151    s = MagLevStone.existing(args.server_name)
152    s.stop
153    puts "Destroying server \"#{args.server_name}\""
154    s.destroy!
155  end
156
157  desc "Invoke a task on all MagLev servers"
158  task :all, :task_name do |t,args|
159    GemStoneInstallation.current.stones.each do |server_name|
160      Rake::Task["#{server_name}:#{args.task_name}"].invoke
161    end
162  end
163end
164
165# Run topaz commands on a particular stone
166def run_on_stone(commands_array, stone=(ENV['STONENAME'] || 'maglev'))
167  Stone.new(stone).topaz_commands(commands_array)
168end
169
170namespace :netldi do
171  desc "Stop NetLDI process"
172  task :stop do
173    GemStoneInstallation.current.stopnetldi
174  end
175  desc "Start NetLDI process"
176  task :start do
177    GemStoneInstallation.current.startnetldi
178  end
179end
180
181# Helper function used to define tasks for each named stone
182def task_gemstone(stone, action, desc=nil)
183  desc "#{desc.nil? ? action.to_s : desc}"
184  task action do
185    stone.send(action)
186  end
187end
188
189GemStoneInstallation.current.stones.each do |server_name|
190  next if defined?(Maglev) and Maglev::System.stone_name == server_name
191  namespace server_name do
192    [[:stop,             "Stop the \"#{server_name}\" server"],
193     [:restart,          "Stop then start the \"#{server_name}\" server"],
194     [:status,           "Report status of the \"#{server_name}\" server"],
195     [:reload,           "Destroy the \"#{server_name}\" repository then load a fresh one"],
196     [:take_snapshot,    "Stop the \"#{server_name}\" server then make a backup copy of its repository"],
197     [:restore_snapshot, "Restore the \"#{server_name}\" repository from its previous snapshot"],
198     [:webtools, "Run the GemStone/S Webtools"],
199    ].each do |action,desc|
200      stone = MagLevStone.new(server_name, GemStoneInstallation.current)
201      task_gemstone(stone, action, desc)
202    end
203
204    desc "Start the \"#{server_name}\" server.
205The netldiname parameter determines which netldi to use (default: ENV['gs64ldi'] || 'gs64ldi')."
206    task :start, :netldiname do |t, args|
207      stone = MagLevStone.new(server_name, GemStoneInstallation.current)
208      netldi = args[:netldiname] || ENV['gs64ldi'] || 'gs64ldi'
209      puts "Starting stone with netldi #{netldi}"
210      ['GEMSTONE', 'GEMSTONE_GLOBAL_DIR'].each { |n| puts "#{n} => #{ENV[n]}" }
211      stone.start netldi
212    end
213
214    desc "Read a GemStone Topaz .gs file or .rb file into server.  Does a commit."
215    task :input_file, :file do |t, args|
216      stone = MagLevStone.new(server_name, GemStoneInstallation.current)
217      file = File.expand_path args[:file]
218      raise "Need a file to read." unless file
219      raise "Can't open input file: #{file.inspect}" unless File.exists?(file)
220
221      if file.end_with? ".rb"
222        system "maglev-ruby -Mcommit --stone #{server_name} #{file}"
223      else
224        stone.input_file file, true
225      end
226    end
227  end
228end
229
230if defined? Maglev
231  at_exit do
232    puts "[INFO] Some stone maintenance tasks have been omitted, because they cannot be run through MagLev rake. Use another Ruby for stone maintenance."
233  end
234end