From 1bffcb11ab57e07ccbc7f0976287e5ee607c93ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ren=C3=A9=20Hanke?= Date: Fri, 19 Apr 2013 12:09:22 +1000 Subject: [PATCH] + Rewrite the whole compilation code to make it adhere to "standards" --- server/Rakefile | 1 + server/{lib => ext/picky}/extconf.rb | 6 ++-- .../{lib/performant.c => ext/picky/picky.c} | 2 +- server/lib/maybe_compile.rb | 28 ++++--------------- server/tasks/extensions.rake | 10 +++++++ server/tasks/specs.rake | 2 +- 6 files changed, 22 insertions(+), 27 deletions(-) rename server/{lib => ext/picky}/extconf.rb (88%) rename server/{lib/performant.c => ext/picky/picky.c} (98%) create mode 100644 server/tasks/extensions.rake diff --git a/server/Rakefile b/server/Rakefile index 44a3a8f7..28a91f3d 100644 --- a/server/Rakefile +++ b/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__ diff --git a/server/lib/extconf.rb b/server/ext/picky/extconf.rb similarity index 88% rename from server/lib/extconf.rb rename to server/ext/picky/extconf.rb index 4a8bc370..012b48e2 100644 --- a/server/lib/extconf.rb +++ b/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'] @@ -10,7 +11,6 @@ # Compile. # require 'mkmf' - abort 'need ruby.h' unless have_header("ruby.h") - -create_makefile('performant') \ No newline at end of file +create_makefile 'picky/picky' +puts \ No newline at end of file diff --git a/server/lib/performant.c b/server/ext/picky/picky.c similarity index 98% rename from server/lib/performant.c rename to server/ext/picky/picky.c index ace4587f..e6f43c8c 100644 --- a/server/lib/performant.c +++ b/server/ext/picky/picky.c @@ -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); diff --git a/server/lib/maybe_compile.rb b/server/lib/maybe_compile.rb index 3a678ef8..782d02dc 100644 --- a/server/lib/maybe_compile.rb +++ b/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! diff --git a/server/tasks/extensions.rake b/server/tasks/extensions.rake new file mode 100644 index 00000000..29e2eee7 --- /dev/null +++ b/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 diff --git a/server/tasks/specs.rake b/server/tasks/specs.rake index ff2b164a..c7e2e5da 100644 --- a/server/tasks/specs.rake +++ b/server/tasks/specs.rake @@ -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'