Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor snappy #11

Merged
merged 4 commits into from
Sep 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/snappy"]
path = vendor/snappy
url = git@github.com:google/snappy.git
25 changes: 12 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
53 changes: 22 additions & 31 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 24 additions & 0 deletions snappy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions vendor/snappy
Submodule snappy added at 1ff9be