Skip to content

Commit

Permalink
+ Rewrite the whole compilation code to make it adhere to "standards"
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Apr 19, 2013
1 parent 2a9b43a commit 1bffcb1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
1 change: 1 addition & 0 deletions server/Rakefile
@@ -1,2 +1,3 @@
load File.expand_path '../tasks/extensions.rake', __FILE__
load File.expand_path '../tasks/specs.rake', __FILE__
load File.expand_path '../tasks/stats.rake', __FILE__
6 changes: 3 additions & 3 deletions server/lib/extconf.rb → server/ext/picky/extconf.rb
@@ -1,5 +1,6 @@
# Information.
#
puts
print "Compiling on Ruby #{RUBY_VERSION}"
if defined?(RbConfig)
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
Expand All @@ -10,7 +11,6 @@
# Compile.
#
require 'mkmf'

abort 'need ruby.h' unless have_header("ruby.h")
create_makefile('performant')
create_makefile 'picky/picky'
puts
2 changes: 1 addition & 1 deletion server/lib/performant.c → server/ext/picky/picky.c
Expand Up @@ -79,7 +79,7 @@ static inline VALUE memory_efficient_intersect(VALUE self, VALUE unsorted_array_

VALUE p_mPerformant, p_cArray;

void Init_performant() {
void Init_picky() {
p_mPerformant = rb_define_module("Performant");
p_cArray = rb_define_class_under(p_mPerformant, "Array", rb_cObject);
rb_define_singleton_method(p_cArray, "memory_efficient_intersect", memory_efficient_intersect, 1);
Expand Down
28 changes: 6 additions & 22 deletions server/lib/maybe_compile.rb
@@ -1,32 +1,16 @@
# Note: This is handled toplevel (in the file
# structure) to not confuse compilers.
#
failed = 0

begin
require ::File.expand_path '../performant', __FILE__
require ::File.expand_path '../picky/picky', __FILE__
rescue LoadError => e
failed += 1

# Have Makefile built.
#
require ::File.expand_path '../extconf', __FILE__

# Run make in the right gem directory.
#
Dir.chdir(::File.expand_path '..', __FILE__) do
puts %x(make)
end

# Try again.
#
retry if failed < 2

# Give up and inform the user.
#
puts <<-NOTE
Picky tried to compile its source on your system but failed.
If you are trying to develop for it, please run the specs first:
bundle exec rake
(You might need to set ulimit -n 3000 for the tests to run)
Please add an issue: https://github.com/floere/picky/issues/
and copy anything into it that you think is helpful. Thanks!
Expand Down
10 changes: 10 additions & 0 deletions server/tasks/extensions.rake
@@ -0,0 +1,10 @@
require 'rake/extensiontask'

Rake::ExtensionTask.new do |ext|
ext.name = 'picky' # indicate the name of the extension.
ext.ext_dir = 'ext/picky' # search for 'picky' inside it.
ext.lib_dir = 'lib/picky' # put binaries into this folder.
ext.tmp_dir = 'tmp' # temporary folder used during compilation.
ext.source_pattern = "*.c" # monitor file changes to allow simple rebuild.
# ext.config_options << '--with-foo' # supply additional options to configure script.
end
2 changes: 1 addition & 1 deletion server/tasks/specs.rake
Expand Up @@ -4,7 +4,7 @@ require 'rspec/core/rake_task'
task :default => :spec

desc "Run specs."
RSpec::Core::RakeTask.new :spec
RSpec::Core::RakeTask.new :spec => :compile

task :simplecov do
ENV['COV'] = 'yes'
Expand Down

0 comments on commit 1bffcb1

Please sign in to comment.