From 3f56fb1bdbcf4c917601b25a19c1ff7a5c000a8a Mon Sep 17 00:00:00 2001 From: miyucy Date: Tue, 23 Sep 2014 12:23:02 +0900 Subject: [PATCH 1/4] add snappy repo --- .gitmodules | 3 +++ vendor/snappy | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 vendor/snappy diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5fc50c4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/snappy"] + path = vendor/snappy + url = git@github.com:google/snappy.git diff --git a/vendor/snappy b/vendor/snappy new file mode 160000 index 0000000..1ff9be9 --- /dev/null +++ b/vendor/snappy @@ -0,0 +1 @@ +Subproject commit 1ff9be9b8fafc8528ca9e055646f5932aa5db9c4 From 03c9d23fcfe5d812e73ad169eb4fc418cb32bc43 Mon Sep 17 00:00:00 2001 From: miyucy Date: Tue, 23 Sep 2014 12:48:53 +0900 Subject: [PATCH 2/4] tweak rake tasks * set default task * combine clean task --- Rakefile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index af93ded..1047c63 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ require "bundler/setup" require "bundler/gem_tasks" require "rake/testtask" require "rbconfig" +DLEXT = RbConfig::CONFIG['DLEXT'] Rake::TestTask.new do |t| t.warning = true @@ -33,12 +34,6 @@ if defined?(JRUBY_VERSION) end end - desc 'Clean up build artifacts' - task :clean do - rm_rf 'ext/java/build' - rm_rf 'lib/snappy_ext.jar' - end - desc 'Package the jar' file 'lib/snappy_ext.jar' => :compile do |t| ant.jar destfile: 'lib/snappy_ext.jar', basedir: '${build.dir}' do @@ -50,19 +45,23 @@ if defined?(JRUBY_VERSION) task :test => 'lib/snappy_ext.jar' task :build => [:clean, 'lib/snappy_ext.jar'] else - DLEXT = RbConfig::CONFIG["DLEXT"] - file "ext/snappy_ext.#{DLEXT}" => Dir.glob("ext/*{.rb,.c}") do Dir.chdir("ext") do - ruby "extconf.rb" - sh "make" + ruby "extconf.rb" + sh "make" end cp "ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}" end - task :clean do - rm_rf(["ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}", "ext/mkmf.log", "ext/config.h", "ext/api.o", "ext/Makefile", "ext/snappy.cc", "ext/snappy.h", "ext/snappy.o"] + Dir["ext/snappy-*"]) - end task :test => "ext/snappy_ext.#{DLEXT}" end + +desc 'Clean up build artifacts' +task :clean do + rm_rf 'ext/java/build' + rm_rf 'lib/snappy_ext.jar' + rm_rf(["ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}", 'ext/mkmf.log', 'ext/config.h', 'ext/api.o', 'ext/Makefile', 'ext/snappy.cc', 'ext/snappy.h', 'ext/snappy.o'] + Dir['ext/snappy-*']) +end + +task :default => :test From d8eff70c35e70f8b53b56d9f3facb04cacfa73a5 Mon Sep 17 00:00:00 2001 From: miyucy Date: Tue, 23 Sep 2014 12:49:21 +0900 Subject: [PATCH 3/4] include vendor sources to gem --- snappy.gemspec | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/snappy.gemspec b/snappy.gemspec index 6c803b7..4789b2a 100644 --- a/snappy.gemspec +++ b/snappy.gemspec @@ -29,4 +29,28 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" spec.add_development_dependency "minitest" + + # get an array of submodule dirs by executing 'pwd' inside each submodule + `git submodule --quiet foreach pwd`.split($\).each do |submodule_path| + # for each submodule, change working directory to that submodule + Dir.chdir(submodule_path) do + + # issue git ls-files in submodule's directory + submodule_files = `git ls-files`.split($\) + + # prepend the submodule path to create absolute file paths + submodule_files_fullpaths = submodule_files.map do |filename| + "#{submodule_path}/#{filename}" + end + + # remove leading path parts to get paths relative to the gem's root dir + # (this assumes, that the gemspec resides in the gem's root dir) + submodule_files_paths = submodule_files_fullpaths.map do |filename| + filename.gsub "#{File.dirname(__FILE__)}/", "" + end + + # add relative paths to gem.files + spec.files += submodule_files_paths + end + end end From ddabe5b38df96b49c5ee94c2edf9e2bedbd96e55 Mon Sep 17 00:00:00 2001 From: miyucy Date: Tue, 23 Sep 2014 12:50:51 +0900 Subject: [PATCH 4/4] use vendor sources to compile --- ext/extconf.rb | 53 +++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/ext/extconf.rb b/ext/extconf.rb index bb84dd4..e878ae8 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -1,39 +1,30 @@ require 'mkmf' require 'fileutils' -unless have_library 'snappy_ext' - dst = File.dirname File.expand_path __FILE__ - - tar = 'tar' - tar = 'gnutar' if find_executable 'gnutar' - - ver = "1.1.1" - src = "snappy-#{ver}" - - FileUtils.rm_rf File.join dst, src - system "curl -s http://snappy.googlecode.com/files/#{src}.tar.gz | #{tar} xz" - - src = File.join dst, src - - Dir.chdir src do - system "./configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags" +unless have_library 'snappy' + # build vendor/snappy + pwd = File.dirname File.expand_path __FILE__ + dir = File.join pwd, '..', 'vendor', 'snappy' + + Dir.chdir dir do + system './autogen.sh' + system './configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags' end - %w( -config.h -snappy-c.cc -snappy-c.h -snappy-internal.h -snappy-sinksource.cc -snappy-sinksource.h -snappy-stubs-internal.cc -snappy-stubs-internal.h -snappy-stubs-public.h -snappy.cc -snappy.h - ).each do |file| - FileUtils.copy File.join(src, file), File.join(dst, file) if FileTest.exist? File.join(src, file) - end + src = %w( + config.h + snappy-c.cc + snappy-c.h + snappy-internal.h + snappy-sinksource.cc + snappy-sinksource.h + snappy-stubs-internal.cc + snappy-stubs-internal.h + snappy-stubs-public.h + snappy.cc + snappy.h + ).map { |e| File.join dir, e } + FileUtils.cp src, pwd, :verbose => true end create_makefile 'snappy_ext'