Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c0cfe62a3f55
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 34764219dec3
Choose a head ref
  • 7 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 24, 2015

  1. Copy the full SHA
    775ec0b View commit details
  2. Copy the full SHA
    c1d1bae View commit details
  3. Copy the full SHA
    30ba1cb View commit details
  4. Copy the full SHA
    129b0a7 View commit details
  5. Copy the full SHA
    8244507 View commit details
  6. Copy the full SHA
    47a7e64 View commit details
  7. Copy the full SHA
    3476421 View commit details
Showing with 170 additions and 165 deletions.
  1. +1 −1 .travis.yml
  2. +3 −157 Rakefile
  3. +5 −7 lib/opal/builder.rb
  4. +1 −0 stdlib/buffer.rb
  5. +58 −0 tasks/building.rake
  6. +37 −0 tasks/documenting.rake
  7. +65 −0 tasks/testing.rake
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ matrix:
env: RUN=rspec

- rvm: 2.0.0
env: RUN="rspec mspec"
env: RUN="rspec mspec_phantom"

- rvm: rbx
env: RUN=rspec
160 changes: 3 additions & 157 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -6,162 +6,8 @@ Bundler.require
Bundler::GemHelper.install_tasks

import 'tasks/github.rake'

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = 'spec/lib/**/*_spec.rb'
end

require 'mspec/opal/rake_task'
MSpec::Opal::RakeTask.new(:mspec) do |config|
config.pattern = ENV['MSPEC_PATTERN'] if ENV['MSPEC_PATTERN']
config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
end
import 'tasks/documenting.rake'
import 'tasks/testing.rake'
import 'tasks/building.rake'

task :default => [:rspec, :mspec_node]

desc <<-DESC
Run the MSpec test suite on node
Use PATTERN and env var to manually set the glob for specs:
# Will run all specs matching the specified pattern.
# (Note: the rubyspecs filters will still apply)
rake mspec_node PATTERN=spec/corelib/core/module/class_variable*
DESC
task :mspec_node do
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty?
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
else
specs = add_specs.(:shared, shared)
specs = add_specs.(:rubyspecs, rubyspecs)
end

requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
filename = 'tmp/mspec_node.rb'
mkdir_p File.dirname(filename)
File.write filename, <<-RUBY
require 'spec_helper'
#{requires.join(" \n")}
OSpecRunner.main.did_finish
RUBY

stubs = " -smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian"

sh 'RUBYOPT="-rbundler/setup -rmspec/opal/special_calls" '\
"bin/opal -Ispec -Ilib -gmspec #{stubs} -rnodejs -Dwarning -A #{filename}"
end

require 'opal/version'
desc <<-DESC
Build *corelib* and *stdlib* to "build/"
You can restrict the file list with the FILES env var (comma separated)
and the destination dir with the DIR env var.
Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
Example: rake dist DIR=cdn/opal/#{Opal::VERSION}
Example: rake dist DIR=cdn/opal/master
DESC
task :dist do
require 'opal/util'
require 'opal/sprockets/environment'

Opal::Processor.arity_check_enabled = false
Opal::Processor.const_missing_enabled = false
Opal::Processor.dynamic_require_severity = :warning
env = Opal::Environment.new

build_dir = ENV['DIR'] || 'build'
files = ENV['FILES'] ? ENV['FILES'].split(',') :
Dir['{opal,stdlib}/*.rb'].map { |lib| File.basename(lib, '.rb') }

Dir.mkdir build_dir unless File.directory? build_dir
width = files.map(&:size).max

files.each do |lib|
print "* building #{lib}...".ljust(width+'* building ... '.size)
$stdout.flush

src = env[lib].to_s
min = Opal::Util.uglify src
gzp = Opal::Util.gzip min

File.open("#{build_dir}/#{lib}.js", 'w+') { |f| f << src }
File.open("#{build_dir}/#{lib}.min.js", 'w+') { |f| f << min } if min
File.open("#{build_dir}/#{lib}.min.js.gz", 'w+') { |f| f << gzp } if gzp

print "done. ("
print "development: #{('%.2f' % (src.size/1000.0)).rjust(6)}KB"
print ", minified: #{('%.2f' % (min.size/1000.0)).rjust(6)}KB" if min
print ", gzipped: #{('%.2f' % (gzp.size/1000.0)).rjust(6)}KB" if gzp
puts ")."
end
end

desc 'Rebuild grammar.rb for opal parser'
task :racc do
%x(racc -l lib/opal/parser/grammar.y -o lib/opal/parser/grammar.rb)
end

desc 'Remove any generated file.'
task :clobber do
rm_r './build'
end

namespace :doc do
doc_repo = Pathname(ENV['DOC_REPO'] || 'gh-pages')
doc_base = doc_repo.join('doc')
current_git_release = -> { `git rev-parse --abbrev-ref HEAD`.chomp }
template_option = "--template opal --template-path #{doc_repo.join('yard-templates')}"

directory doc_repo.to_s do
remote = ENV['DOC_REPO_REMOTE'] || '.'
sh 'git', 'clone', '-b', 'gh-pages', '--', remote, doc_repo.to_s
end

task :corelib => doc_repo.to_s do
git = current_git_release.call
name = 'corelib'
glob = 'opal/**/*.rb'

command = "doxx --template #{doc_repo.join('doxx-templates/opal.jade')} "\
"--source opal/corelib --target #{doc_base}/#{git}/#{name} "\
"--title \"Opal runtime.js Documentation\" --readme opal/README.md"
puts command; system command or $stderr.puts "Please install doxx with: npm install"

command = "yard doc #{glob} #{template_option} "\
"--readme opal/README.md -o #{doc_base}/#{git}/#{name}"
puts command; system command
end

task :stdlib => doc_repo do
git = current_git_release.call
name = 'stdlib'
glob = '{stdlib/**/*,opal/compiler,opal/erb,opal/version}.rb'
command = "yard doc #{glob} #{template_option} "\
"--readme stdlib/README.md -o gh-pages/doc/#{git}/#{name}"
puts command; system command
end
end

task :doc => ['doc:corelib', 'doc:stdlib']
12 changes: 5 additions & 7 deletions lib/opal/builder.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ module Opal
class Builder
include BuilderProcessors

class MissingRequire < LoadError
end

def initialize(options = nil)
(options || {}).each_pair do |k,v|
public_send("#{k}=", v)
@@ -39,8 +42,7 @@ def build_str source, filename, options = {}
processed << asset
self
rescue MissingRequire => error
error.message = "A file required by #{filename.inspect} wasn't found.\n#{error.message}"
raise error
raise error, "A file required by #{filename.inspect} wasn't found.\n#{error.message}"
end

def build_require(path, options = {})
@@ -93,9 +95,6 @@ def processor_for(source, filename, path, options)
return processor.new(source, filename, compiler_options.merge(options))
end

class MissingRequire < LoadError
end

def read(path)
path_reader.read(path) or
raise MissingRequire, "can't find file: #{path.inspect} in #{path_reader.paths.inspect}"
@@ -125,8 +124,7 @@ def process_require(filename, options)
def process_requires(source_filename, requires, options)
requires.map { |r| process_require(r, options) }
rescue MissingRequire => error
error.message = "A file required by #{filename.inspect} wasn't found.\n#{error.message}"
raise error
raise error, "A file required by #{filename.inspect} wasn't found.\n#{error.message}"
end

def already_processed
1 change: 1 addition & 0 deletions stdlib/buffer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'native'
require 'buffer/array'
require 'buffer/view'

58 changes: 58 additions & 0 deletions tasks/building.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'opal/version'

desc <<-DESC
Build *corelib* and *stdlib* to "build/"
You can restrict the file list with the FILES env var (comma separated)
and the destination dir with the DIR env var.
Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
Example: rake dist DIR=cdn/opal/#{Opal::VERSION}
Example: rake dist DIR=cdn/opal/master
DESC
task :dist do
require 'opal/util'
require 'opal/sprockets/environment'

Opal::Processor.arity_check_enabled = false
Opal::Processor.const_missing_enabled = false
Opal::Processor.dynamic_require_severity = :warning
env = Opal::Environment.new

build_dir = ENV['DIR'] || 'build'
files = ENV['FILES'] ? ENV['FILES'].split(',') :
Dir['{opal,stdlib}/*.rb'].map { |lib| File.basename(lib, '.rb') }

Dir.mkdir build_dir unless File.directory? build_dir
width = files.map(&:size).max

files.each do |lib|
print "* building #{lib}...".ljust(width+'* building ... '.size)
$stdout.flush

src = env[lib].to_s
min = Opal::Util.uglify src
gzp = Opal::Util.gzip min

File.open("#{build_dir}/#{lib}.js", 'w+') { |f| f << src }
File.open("#{build_dir}/#{lib}.min.js", 'w+') { |f| f << min } if min
File.open("#{build_dir}/#{lib}.min.js.gz", 'w+') { |f| f << gzp } if gzp

print "done. ("
print "development: #{('%.2f' % (src.size/1000.0)).rjust(6)}KB"
print ", minified: #{('%.2f' % (min.size/1000.0)).rjust(6)}KB" if min
print ", gzipped: #{('%.2f' % (gzp.size/1000.0)).rjust(6)}KB" if gzp
puts ")."
end
end

desc 'Rebuild grammar.rb for opal parser'
task :racc do
%x(racc -l lib/opal/parser/grammar.y -o lib/opal/parser/grammar.rb)
end

desc 'Remove any generated file.'
task :clobber do
rm_r './build'
end

37 changes: 37 additions & 0 deletions tasks/documenting.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace :doc do
doc_repo = Pathname(ENV['DOC_REPO'] || 'gh-pages')
doc_base = doc_repo.join('doc')
current_git_release = -> { `git rev-parse --abbrev-ref HEAD`.chomp }
template_option = "--template opal --template-path #{doc_repo.join('yard-templates')}"

directory doc_repo.to_s do
remote = ENV['DOC_REPO_REMOTE'] || '.'
sh 'git', 'clone', '-b', 'gh-pages', '--', remote, doc_repo.to_s
end

task :corelib => doc_repo.to_s do
git = current_git_release.call
name = 'corelib'
glob = 'opal/**/*.rb'

command = "doxx --template #{doc_repo.join('doxx-templates/opal.jade')} "\
"--source opal/corelib --target #{doc_base}/#{git}/#{name} "\
"--title \"Opal runtime.js Documentation\" --readme opal/README.md"
puts command; system command or $stderr.puts "Please install doxx with: npm install"

command = "yard doc #{glob} #{template_option} "\
"--readme opal/README.md -o #{doc_base}/#{git}/#{name}"
puts command; system command
end

task :stdlib => doc_repo do
git = current_git_release.call
name = 'stdlib'
glob = '{stdlib/**/*,opal/compiler,opal/erb,opal/version}.rb'
command = "yard doc #{glob} #{template_option} "\
"--readme stdlib/README.md -o gh-pages/doc/#{git}/#{name}"
puts command; system command
end
end

task :doc => ['doc:corelib', 'doc:stdlib']
65 changes: 65 additions & 0 deletions tasks/testing.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = 'spec/lib/**/*_spec.rb'
end

require 'mspec/opal/rake_task'
MSpec::Opal::RakeTask.new(:mspec_phantom) do |config|
config.pattern = ENV['MSPEC_PATTERN'] if ENV['MSPEC_PATTERN']
config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
end

desc <<-DESC
Run the MSpec test suite on node
Use PATTERN and env var to manually set the glob for specs:
# Will run all specs matching the specified pattern.
# (Note: the rubyspecs filters will still apply)
rake mspec_node PATTERN=spec/corelib/core/module/class_variable*
DESC
task :mspec_node do
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty?
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
else
specs = add_specs.(:shared, shared)
specs = add_specs.(:rubyspecs, rubyspecs)
end

requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
filename = 'tmp/mspec_node.rb'
mkdir_p File.dirname(filename)
File.write filename, <<-RUBY
require 'spec_helper'
#{requires.join(" \n")}
OSpecRunner.main.did_finish
RUBY

stubs = " -smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian"

sh 'RUBYOPT="-rbundler/setup -rmspec/opal/special_calls" '\
"bin/opal -Ispec -Ilib -gmspec #{stubs} -rnodejs -Dwarning -A #{filename}"
end

task :mspec => [:mspec_node, :mspec_phantom]
task :test_all => [:rspec, :mspec]