Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
WIP: Refactor rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
pbm committed Oct 6, 2011
1 parent 1ea6348 commit 2f8f1f0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 65 deletions.
6 changes: 3 additions & 3 deletions build/load_mcz.topaz.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
set gemstone $STONENAME user DataCurator pass swordfish
login
output append <%= options[:mcz_log] %>
output append <%= MCZ_LOG %>
display resultcheck
run
| fileRepo aBase aName ver |
aName := 'MagLev-<%= options[:mcz_version] %>.mcz'.
aName := 'MagLev-<%= MCZ_VERSION %>.mcz'.
fileRepo := MCDirectoryRepository new directory:
(FileDirectory on: '<%= options[:mcz_dir] %>').
(FileDirectory on: '<%= MCZ_DIR %>').

ver := fileRepo loadVersionFromFileNamed: aName .
ver class == MCVersion ifFalse:[ aName error:'not found in repos' ].
Expand Down
119 changes: 57 additions & 62 deletions rakelib/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,50 @@
# + remove .git*
# + keyfile


namespace :build do
require 'erb'
require 'logger'

IMAGE_RUBY_DIR = File.join(MAGLEV_HOME, 'src', 'smalltalk', 'ruby')
BUILD_DIR = File.join(MAGLEV_HOME, 'build')
FILEIN_DIR = File.join(MAGLEV_HOME, "fileintmp") # TODO: add $$ to name
MCZ_DIR = File.join(MAGLEV_HOME, 'src', 'smalltalk', 'ruby', 'mcz')
GEM_BIN = File.join(GEMSTONE, 'bin')
GEM_CONF = File.join(FILEIN_DIR, 'fileingem.ruby.conf')
IMAGE_RUBY_DIR = File.join(MAGLEV_HOME, 'src', 'smalltalk', 'ruby')
KEYFILE = File.join(MAGLEV_HOME, 'etc', 'maglev.demo.key')
MCZ_DIR = File.join(MAGLEV_HOME, 'src', 'smalltalk', 'ruby', 'mcz')
RUBY_EXTENT = File.join(MAGLEV_HOME, 'bin', 'extent0.ruby.dbf')
STONE_CONF = File.join(FILEIN_DIR, 'filein.ruby.conf')
STONE_LOG = File.join(FILEIN_DIR, 'stone.log')
STONE_NAME = "fileinruby#{$$}stone"
VERBOSE = true

# desc "Create a new extent0.ruby.dbf from virgin Smalltalk extent0.dbf"
# task :ruby_extent => [:check_dev_env, :save_ruby_extent, :image] do
# cp
# end

task :check_dev_env do
[MAGLEV_HOME, GEMSTONE, IMAGE_RUBY_DIR, BUILD_DIR, MCZ_DIR].each do |var|
raise "#{var} is not a directory" unless File.directory? var
end
end

task :save_ruby_extent do
if File.exist? RUBY_EXTENT
puts "Saving copy of #{RUBY_EXTENT}"
mv RUBY_EXTENT, "#{RUBY_EXTENT}.save"
else
puts "No #{RUBY_EXTENT} to save"
end
end

task :temp_dir do
puts "Creating new FILEIN_DIR #{FILEIN_DIR}"
rm_rf FILEIN_DIR
mkdir FILEIN_DIR
end

def setup_env(options)
def setup_env
# upgradeDir is also needed by the filein topaz scripts. When a
# customers does a 'upgrade' it will be set to $GEMSTONE/upgrade. For
# a filein it will be set to the imageDir.
Expand All @@ -56,9 +75,9 @@ namespace :build do
ENV["dbfDir"] = FILEIN_DIR
ENV["imageRubyDir"] = File.join(MAGLEV_HOME, 'src', 'smalltalk', 'ruby')
ENV["GS_DEBUG_COMPILE_TRACE"] = "1"
ENV['STONENAME'] = options[:stone_name]
ENV['GEMSTONE_SYS_CONF'] = options[:stone_conf]
ENV["GEMSTONE_EXE_CONF"] = options[:gem_conf]
ENV['STONENAME'] = STONE_NAME
ENV['GEMSTONE_SYS_CONF'] = STONE_CONF
ENV["GEMSTONE_EXE_CONF"] = GEM_CONF
end

desc "Create a fresh ruby image"
Expand All @@ -70,55 +89,36 @@ namespace :build do
puts "Logging to: #{build_log_name}"
log("build:image", "Begin task")

options = {
:stone_name => "fileinruby#{$$}stone",
:stone_conf => File.join(FILEIN_DIR, 'filein.ruby.conf'),
:stone_log => File.join(FILEIN_DIR, 'stone.log'),
:gem_conf => File.join(FILEIN_DIR, 'fileingem.ruby.conf'),
:gem_bin => File.join(GEMSTONE, 'bin'),
:mcz_version => 'TimFelgentreff.1307', # TODO: Parameterize this: read out of file/ENV?
:mcz_dir => IMAGE_RUBY_DIR,
:mcz_log => File.join(FILEIN_DIR, 'load_mcz.log'),
}
options.each_pair { |k,v| log("build:image", "options[#{k.inspect}] = #{v}") }

setup_env options
create_filein_stone_files options
setup_env
create_filein_stone_files

# Pass one includes a shrink stone, so we only run it
# and logout to ensure image written ok
Dir.chdir FILEIN_DIR do
begin
# Pass one runs the filein of ruby base code,
# then shrinks the image. We stop at that
# point to ensure write of shrunk image
# Pass one runs the filein of ruby base code, then shrinks the
# image. We stop at that point to ensure write of shrunk image
log("build:image", "Begin initial fileinruby")
startstone(options) &&
waitstone(options) &&
fileinruby(options) &&
stopstone(options) &&

startstone && fileinruby && stopstone &&
# loadmcz on shrunk image => restart stone
startstone(options) &&
waitstone(options) &&
load_mcz_dir(options)
startstone && load_mcz_dir && puts("===== SUCCESS =====")
ensure
stopstone(options)
stopstone
end
end
end

def load_mcz_dir(options)
def load_mcz_dir
# No looping in topaz, so generate a script here
files = Dir["#{MCZ_DIR}/*.gs"].sort_by {|a| a.split('_').last }
inputs = files.map{ |fn| "input #{fn}\n" }

outfile = "#{FILEIN_DIR}/loadmczdir.out"
log_run("load_mcz_dir", outfile) do
run_topaz("load_mcz_dir", <<-EOS, options)
run_topaz("load_mcz_dir", <<-EOS)
output push #{outfile} only
iferr 1 exit 3
set gemstone #{options[:stone_name]} user DataCurator pass swordfish
set gemstone #{STONE_NAME} user DataCurator pass swordfish
login
#{inputs}
expectvalue true
Expand Down Expand Up @@ -149,75 +149,70 @@ namespace :build do
# We will use $GEMSTONE/bin/extent0.dbf as the base smalltalk image upon
# which we build the ruby image.
#
def fileinruby(options)
def fileinruby
outfile = "#{FILEIN_DIR}/fileinruby.out"
log_run("fileinruby", outfile) do
run_topaz("fileinruby", <<-EOS, options)
run_topaz("fileinruby", <<-EOS)
output push #{outfile} only
set gemstone #{options[:stone_name]}
set gemstone #{STONE_NAME}
input $imageDir/fileinruby.topaz
output pop
exit
EOS
end
end

# Assume stone is running and we PWD is correct
def loadmcz(options) # todo: parameterize
def loadmcz
log_run("loadmcz") do
tpz_cmds = "load_mcz.topaz"
cp_template("#{BUILD_DIR}/load_mcz.topaz.erb", tpz_cmds, options)
run_topaz_file(tpz_cmds, options)
cp_template("#{BUILD_DIR}/load_mcz.topaz.erb", tpz_cmds)
run_topaz_file(tpz_cmds)
end
end

# Run a block wrapped in logging and error checking
def log_run(step_name, logfile="<no logfile>")
puts
log(step_name, "Begin: LOG: #{logfile}")
res = yield
if res
log(step_name, "Success: $?: #{$?.exitstatus} LOG: #{logfile}")
log(step_name, "SUCCESS: $?: #{$?.exitstatus} LOG: #{logfile}")
else
log(step_name, "FAILURE: $?: #{$?.exitstatus} LOG: #{logfile}", Logger::ERROR)
end
log(step_name, "End: #{step_name}")
res
end

def startstone(opts)
def startstone
logfile = "#{Dir.pwd}/startstone.log"
cmd = "#{opts[:gem_bin]}/startstone #{opts[:stone_name]} -l #{opts[:stone_log]} -e #{opts[:stone_conf]} -z #{opts[:stone_conf]} > #{logfile} 2>&1"

cmd = "#{GEM_BIN}/startstone #{STONE_NAME} -l #{STONE_LOG} -e #{STONE_CONF} -z #{STONE_CONF} > #{logfile} 2>&1"
log_run("startstone", logfile) { system cmd }
end

def waitstone(opts)
logfile = "#{Dir.pwd}/waitstone.log"
cmd = "#{opts[:gem_bin]}/waitstone #{opts[:stone_name]} > #{logfile} 2>&1"
cmd = "#{GEM_BIN}/waitstone #{STONE_NAME} >> #{logfile} 2>&1"
log_run("waitstone", logfile) { system cmd }
end

def stopstone(opts)
def stopstone
logfile = "#{Dir.pwd}/stopstone.log"
cmd = "#{opts[:gem_bin]}/stopstone #{opts[:stone_name]} DataCurator swordfish > #{logfile} 2>&1"
cmd = "#{GEM_BIN}/stopstone #{STONE_NAME} DataCurator swordfish > #{logfile} 2>&1"
log_run("stopstone", logfile) { system cmd }
end

def run_topaz(step_name, topaz_commands, opts)
def run_topaz(step_name, topaz_commands)
log("run_topaz: #{step_name}", "Begin")
cmd_file = File.join(Dir.pwd, 'tpz_commands')
File.open(cmd_file, 'w') { |f| f.write(topaz_commands) }
run_topaz_file(cmd_file, opts)
run_topaz_file(cmd_file)
end

def run_topaz_file(file, opts)
topaz_cmd = "#{opts[:gem_bin]}/topaz -l -i -e #{opts[:gem_conf]} -z #{opts[:gem_conf]}"
def run_topaz_file(file)
topaz_cmd = "#{GEM_BIN}/topaz -l -i -e #{GEM_CONF} -z #{GEM_CONF}"
system "#{topaz_cmd} < #{file} > #{file}.out 2>&1"
end

# Given the name of a ERB template, copy it to the destination dir,
# running it through erb.
def cp_template(erb_file, dest_file, options)
def cp_template(erb_file, dest_file)
raise "Can't find erb_file #{erb_file}" unless File.exist? erb_file

File.open(dest_file, "w") do | dest |
Expand All @@ -228,14 +223,14 @@ namespace :build do
end
end

def create_filein_stone_files(options)
def create_filein_stone_files
log("create_filein_stone_files", "Begin")
Dir.chdir(FILEIN_DIR) do

cp File.join(GEMSTONE, 'bin', 'extent0.dbf'), 'extent0.ruby.dbf'
chmod 0770,'extent0.ruby.dbf'
cp_template("#{BUILD_DIR}/filein.ruby.conf.erb", options[:stone_conf], options)
cp "#{BUILD_DIR}/fileingem.ruby.conf", options[:gem_conf]
cp_template("#{BUILD_DIR}/filein.ruby.conf.erb", STONE_CONF)
cp "#{BUILD_DIR}/fileingem.ruby.conf", GEM_CONF

# TODO: Remove this when smalltalk bug resovled.
# Workaround for bug in Smalltalk build. patchMaster30.gs should be shipped
Expand Down
3 changes: 3 additions & 0 deletions rakelib/maglev_stone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"#{ML}/log", # base log directory
"#{ML}/backups", # backup directory
'extent0.ruby.dbf') # initial extent name
def (GemStoneInstallation.current).initial_extent
File.join(ML, "bin", @initial_extent_name)
end

class MagLevStone < Stone
def config_file_template
Expand Down

0 comments on commit 2f8f1f0

Please sign in to comment.