Permalink
Browse files

Added sha1 hash of all parser+compiler files and cleaned up kernel.rake.

  • Loading branch information...
1 parent 21cfc13 commit cde6705417b6fc99563a074f609776c3c7b37411 Brian Ford committed Nov 13, 2009
Showing with 105 additions and 55 deletions.
  1. +1 −0 .gitignore
  2. +104 −55 rakelib/kernel.rake
View
@@ -64,6 +64,7 @@ tmtags
/kernel/bootstrap/rubinius_config.rb
/kernel/bootstrap/ruby_config.rb
+/kernel/delta/signature.rb
/lib/compiler/opcodes.rb
View
@@ -1,4 +1,15 @@
-# All the tasks to manage the kernel
+# All the tasks to manage building the Rubinius kernel--which is essentially
+# the Ruby core library plus Rubinius-specific files. The kernel bootstraps
+# a Ruby environment to the point that user code can be loaded and executed.
+#
+# The basic rule is that any generated file should be specified as a file
+# task, not hidden inside some arbitrary task. Generated files are created by
+# rule (e.g. the rule for compiling a .rb file into a .rbc file) or by a block
+# attached to the file task for that particular file.
+#
+# The only tasks should be those names needed by the user to invoke specific
+# parts of the build (including the top-level build task for generating the
+# entire kernel).
# drake does not allow invoke to be called inside tasks
def kernel_clean
@@ -10,87 +21,125 @@ def kernel_clean
:verbose => $verbose
end
-# The default rule for compiling all kernel files use the
-# rbx-kernel compiler flag. Other files are exception cases.
+# The rule for compiling all kernel Ruby files
rule ".rbc" do |t|
- rbc = t.name
- src = t.prerequisites.first
-
- puts "Compiling #{src}"
- Rubinius::CompilerNG.compile src, 1, rbc, :all
+ source = t.prerequisites.first
+ puts "RBC #{source}"
+ Rubinius::CompilerNG.compile source, 1, t.name, :all
end
-# Create file dependencies for all kernel files
-if File.exists? "runtime/index"
- subdirs = IO.readlines("runtime/index").map { |line| line.chomp }
-else
- raise "unable to build kernel, runtime/index is missing"
-end
+# Helper to create file dependencies for all kernel files
+def kernel_dependency(rb, files, sub=true)
+ rbc = rb + "c"
+ rbc.sub!(/^kernel/, "runtime") if sub
-def kernel_dependency(name, files)
- rbc = name.sub(/^kernel/, "runtime") + "c"
- file rbc => [name, File.dirname(rbc)]
+ file rbc => rb
files << rbc
end
-kernel = ["runtime/platform.conf"]
+# Collection of all files in the kernel runtime. Modified by
+# various tasks below.
+runtime = FileList["runtime/platform.conf"]
-subdirs.each do |subdir|
- directory "runtime/#{subdir}"
+# Names of subdirectories of the runtime/ directory.
+dir_names = [
+ "bootstrap",
+ "platform",
+ "common",
+ "delta"
+]
- Dir["kernel/#{subdir}/*.rb"].each do |rb|
- kernel_dependency rb, kernel
- end
-end
+dir_names.each do |dir|
+ directory(runtime_dir = "runtime/#{dir}")
+ runtime << runtime_dir
-opcodes = "lib/compiler/opcodes.rb"
+ load_order = "runtime/#{dir}/load_order.txt"
+ runtime << load_order
-FileList[ "kernel/bootstrap/rubinius_config.rb",
- "kernel/bootstrap/ruby_config.rb",
- "kernel/alpha.rb",
- "kernel/loader.rb"
-].each do |rb|
- kernel_dependency rb, kernel
+ file load_order => "kernel/#{dir}/load_order.txt" do |t|
+ cp t.prerequisites.first, t.name, :verbose => $verbose
+ end
end
-FileList[ "lib/compiler.rb",
- "lib/compiler/**/*.rb",
- opcodes,
- "lib/melbourne.rb",
- "lib/melbourne/**/*.rb"
+# Generate file tasks for all kernel files.
+FileList[
+ "kernel/**/*.rb",
+ "kernel/bootstrap/rubinius_config.rb",
+ "kernel/bootstrap/ruby_config.rb",
].each do |rb|
- rbc = "#{rb}c"
- file rbc => rb
- kernel << rbc
+ kernel_dependency rb, runtime
end
-namespace :compiler do
- task :load => [opcodes, "lib/ext/melbourne/ruby/melbourne.#{$dlext}"] do
- require File.expand_path("../../lib/compiler", __FILE__)
+# Directories to store the core library runtime files (.rbc's)
+runtime_index = "runtime/index"
+
+file runtime_index do |t|
+ File.open t.name, "w" do |file|
+ file.puts dir_names
end
+end
- task :check => :load do
- unless ENV['NOCLEAN']
- existing = kernel.select { |name| name =~ /rbc$/ and File.exists? name }
- kernel_mtime = existing.map { |name| File.stat(name).mtime }.min
+# Compile all compiler files during build stage
+opcodes = "lib/compiler/opcodes.rb"
- compiler = (Dir["lib/compiler/**/*.rb", opcodes])
- compiler_mtime = compiler.map { |name| File.stat(name).mtime }.max
+compiler_files = FileList[
+ "lib/compiler.rb",
+ "lib/compiler/**/*.rb",
+ opcodes,
+ "lib/melbourne.rb",
+ "lib/melbourne/**/*.rb"
+]
- kernel_clean if !kernel_mtime or compiler_mtime > kernel_mtime
+compiler_files.each do |rb|
+ kernel_dependency rb, runtime, false
+end
+
+parser_ext_files = FileList[
+ "lib/ext/melbourne/**/*.{c,h}pp",
+ "lib/ext/melbourne/grammar.y",
+ "lib/ext/melbourne/lex.c.tab"
+]
+
+# Generate a sha1 of all parser and compiler files to use as
+# as signature in the .rbc files.
+compiler_signature = "kernel/delta/signature.rb"
+
+kernel_dependency compiler_signature, runtime
+
+file compiler_signature => compiler_files + parser_ext_files do |t|
+ require 'digest'
+ digest = Digest::SHA1.new
+
+ t.prerequisites.each do |name|
+ File.open name, "r" do |file|
+ file.each_line do |line|
+ digest << line
+ end
end
end
+
+ File.open t.name, "w" do |file|
+ file.puts "# This file is generated by rakelib/kernel.rake. The signature"
+ file.puts "# is used to ensure that only current .rbc files are loaded."
+ file.puts "#"
+ file.puts "Rubinius::Signature = 0x#{digest.to_s[0, 16]}"
+ end
end
-desc "Build all kernel files"
+namespace :compiler do
+ melbourne = "lib/ext/melbourne/ruby/melbourne.#{$dlext}"
+ task :load => [compiler_signature, melbourne] + compiler_files do
+ require File.expand_path("../../lib/compiler", __FILE__)
+ require File.expand_path("../../kernel/delta/signature", __FILE__)
+ end
+end
+
+desc "Build all kernel files (alias for kernel:build)"
task :kernel => 'kernel:build'
namespace :kernel do
- task :build => ['compiler:check'] + kernel do
- subdirs.each do |subdir|
- cp "kernel/#{subdir}/load_order.txt", "runtime/#{subdir}/load_order.txt"
- end
- end
+ desc "Build all kernel files"
+ task :build => ['compiler:load', runtime_index] + runtime
desc "Delete all .rbc files"
task :clean do

0 comments on commit cde6705

Please sign in to comment.