rubyswig 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +82 -0
- data/Rakefile +2 -0
- data/bin/ccache-swig +5 -0
- data/bin/swig +5 -0
- data/ext/Rakefile +174 -0
- data/ext/bsdtar-pcre-build.sh +8 -0
- data/ext/build_swig +41 -0
- data/ext/download.rb +204 -0
- data/ext/findpcre.c +1 -0
- data/lib/rubyswig.rb +5 -0
- data/lib/rubyswig/version.rb +3 -0
- data/rubyswig.gemspec +25 -0
- metadata +83 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brian Wong
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Rubyswig
|
2
|
+
|
3
|
+
Builds [SWIG](http://www.swig.org) (Simplified Wrapper Interface Generator) from source with minimal dependencies,
|
4
|
+
then installs it as a rubygem executable, allowing it to be versioned with rvm gemsets.
|
5
|
+
|
6
|
+
More importantly, makes installing SWIG dead-easy, and allows you to use Gemfiles and
|
7
|
+
Bundler to specify dependencies against it.
|
8
|
+
|
9
|
+
Tested with Ruby 1.9.3 on Ubuntu 12.04, OSX Snow Leopard (10.6), and Windows 7 (x86-64) with [Devkit](http://rubyinstaller.org/add-ons/devkit/).
|
10
|
+
|
11
|
+
## Prerequisites
|
12
|
+
|
13
|
+
### All
|
14
|
+
|
15
|
+
Ruby and an environment that can build native gems.
|
16
|
+
|
17
|
+
### Windows
|
18
|
+
|
19
|
+
If you're starting your Ruby environment from scratch, I recommend the [RailsInstaller](http://railsinstaller.org/), which includes Devkit. You can also install Devkit [manually](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit), but there are more steps involved.
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
gem 'rubyswig'
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install rubyswig
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
Once SWIG is installed, use it as normal. See <http://www.swig.org>. Remember that if you use rvm gemsets that the executable is tied to the gemset in which you installed it.
|
38
|
+
|
39
|
+
If you have gems that need to create SWIG wrappers, you can add rubyswig as a dependency of your gem.
|
40
|
+
|
41
|
+
## Makefiles and extconf.rb
|
42
|
+
|
43
|
+
You can include swig in your extconf.rb to automatically generate and compile wrappers from the .i interface file. Example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'mkmf'
|
47
|
+
|
48
|
+
dir_config('ois', '/usr/include/OIS', '/usr/lib')
|
49
|
+
|
50
|
+
# Identify SWIG interface files as source files
|
51
|
+
SRC_EXT.concat %w[i]
|
52
|
+
|
53
|
+
# make dependency file for SWIG wrappers
|
54
|
+
open("depend", "w") do |f|
|
55
|
+
f.puts("SWIG = #{find_executable('swig')}")
|
56
|
+
f.puts("SWIGFLAGS = -D__GNUC__=4 -D__GNUC_MINOR__=6 -D__GNUC_PATCHLEVEL__=3 -ruby -Wall -c++ -minherit")
|
57
|
+
f.puts(".i.cxx:")
|
58
|
+
f.puts("\t$(ECHO) wrapping $(<)")
|
59
|
+
f.puts("\t$(SWIG) $(SWIGFLAGS) $(INCFLAGS) $(CPPFLAGS) -o $@ $(<)")
|
60
|
+
|
61
|
+
have_library('OIS')
|
62
|
+
|
63
|
+
create_makefile('ois')
|
64
|
+
```
|
65
|
+
|
66
|
+
Note that SWIG does not define the same symbols as, say, GCC, so you need to define them yourself for platform-specific compilation.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
75
|
+
|
76
|
+
## Additional Credits
|
77
|
+
|
78
|
+
Jon Maken for download.rb (https://gist.github.com/2202048)
|
79
|
+
|
80
|
+
## Alternatives
|
81
|
+
|
82
|
+
[Rice](http://rice.rubyforge.org/) is a C++ wrapper interface to the Ruby API. It's easier to use but is specific to Ruby.
|
data/Rakefile
ADDED
data/bin/ccache-swig
ADDED
data/bin/swig
ADDED
data/ext/Rakefile
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'parallel'
|
3
|
+
require 'rbconfig'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'download'))
|
5
|
+
|
6
|
+
module RubySwig
|
7
|
+
SWIG_VERSION='2.0.7'
|
8
|
+
PCRE_VERSION='8.30'
|
9
|
+
IS_WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
|
10
|
+
if (IS_WINDOWS)
|
11
|
+
begin
|
12
|
+
# Setup devkit path so we have access to bash and tar.
|
13
|
+
require 'devkit'
|
14
|
+
rescue LoadError
|
15
|
+
puts "Devkit is required on Windows to build SWIG from source."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
PROJECT_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
20
|
+
EXT_ROOT=File.expand_path(File.dirname(__FILE__))
|
21
|
+
SOURCE_DIR=File.join(EXT_ROOT, "swig-#{SWIG_VERSION}")
|
22
|
+
INSTALL_DIR=File.join(PROJECT_ROOT, "swig")
|
23
|
+
PWD=FileUtils.pwd
|
24
|
+
GEMDIR=`gem env gemdir`.chomp
|
25
|
+
GEM_CACHE_DIR=File.join(GEMDIR, 'cache')
|
26
|
+
# Windows VC++: download http://prdownloads.sourceforge.net/swig/swigwin-2.0.7.zip
|
27
|
+
|
28
|
+
class SwigBuilder
|
29
|
+
def initialize
|
30
|
+
if `bash -c "which bsdtar"`.empty?
|
31
|
+
@tar_cmd='tar'
|
32
|
+
else
|
33
|
+
@tar_cmd='bsdtar'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def bsd_tar?
|
38
|
+
@tar_cmd=='bsdtar'
|
39
|
+
end
|
40
|
+
|
41
|
+
def system!(*args)
|
42
|
+
system(*args)
|
43
|
+
return_code=$?
|
44
|
+
if return_code != 0 then
|
45
|
+
raise RuntimeError.new("Failed to run #{args}. Return code: #{return_code}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def link(src, dest, options={})
|
50
|
+
if IS_WINDOWS
|
51
|
+
begin
|
52
|
+
FileUtils.cp(src, dest)
|
53
|
+
rescue Errno::EEXIST
|
54
|
+
puts "File #{src} already exists, skipping file copy"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
begin
|
58
|
+
FileUtils.ln_s(src, dest, options)
|
59
|
+
rescue Errno::EEXIST
|
60
|
+
puts "File #{src} already exists, skipping symlink"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def run_script!(command)
|
66
|
+
if IS_WINDOWS
|
67
|
+
system "bash -c '#{command}'"
|
68
|
+
else
|
69
|
+
system! command
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Detect existing pcre library.
|
74
|
+
def pcre_installed?
|
75
|
+
system "gcc -c #{EXT_ROOT}/findpcre.c -o /dev/null"
|
76
|
+
$? == 0
|
77
|
+
end
|
78
|
+
|
79
|
+
# Download and build local version of pcre.
|
80
|
+
def install_pcre
|
81
|
+
pcre_filename = "pcre-#{PCRE_VERSION}.tar.gz"
|
82
|
+
pcre_download_path = File.join(GEM_CACHE_DIR, pcre_filename)
|
83
|
+
pcre_url = "http://sourceforge.net/projects/pcre/files/pcre/#{PCRE_VERSION}/#{pcre_filename}"
|
84
|
+
|
85
|
+
FileUtils.chdir(SOURCE_DIR)
|
86
|
+
if not File.exists?(pcre_download_path) then
|
87
|
+
Downloader.download_file(pcre_url, pcre_download_path)
|
88
|
+
# system! "curl -L -o #{pcre_download_path} #{pcre_url}"
|
89
|
+
# system! "wget -P #{GEM_CACHE_DIR} #{pcre_url}"
|
90
|
+
end
|
91
|
+
link(pcre_download_path, pcre_filename)
|
92
|
+
if bsd_tar?
|
93
|
+
FileUtils.cp(File.join(EXT_ROOT, 'bsdtar-pcre-build.sh'), '.')
|
94
|
+
run_script! './bsdtar-pcre-build.sh'
|
95
|
+
else
|
96
|
+
run_script! 'Tools/pcre-build.sh'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def install_manpages(dest)
|
101
|
+
begin
|
102
|
+
FileUtils.chdir(INSTALL_DIR)
|
103
|
+
Dir.glob(File.join('share', 'man', '**', '*')).each do |file|
|
104
|
+
dest_file = File.join(dest, file)
|
105
|
+
FileUtils.mkdir_p(File.dirname(file))
|
106
|
+
link(File.expand_path(file), dest_file, :force => true)
|
107
|
+
end
|
108
|
+
rescue Errno::EACCES
|
109
|
+
puts "Warning: man pages are not installed. To install locally:"
|
110
|
+
puts "cd #{PROJECT_ROOT}; sudo rake install_manpages"
|
111
|
+
rescue Errno::EEXIST
|
112
|
+
puts "Man pages already installed."
|
113
|
+
rescue => e
|
114
|
+
puts "Rescuing #{e.class}"
|
115
|
+
puts e.inspect
|
116
|
+
raise
|
117
|
+
ensure
|
118
|
+
FileUtils.chdir(PWD)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def build_swig
|
123
|
+
swig_filename = "swig-#{SWIG_VERSION}.tar.gz"
|
124
|
+
swig_download_path = File.join(GEM_CACHE_DIR, swig_filename)
|
125
|
+
swig_url = "http://downloads.sourceforge.net/project/swig/swig/swig-#{SWIG_VERSION}/#{swig_filename}"
|
126
|
+
|
127
|
+
FileUtils.chdir(EXT_ROOT)
|
128
|
+
if not File.exists?(swig_download_path) then
|
129
|
+
Downloader.download_file(swig_url, swig_download_path)
|
130
|
+
# system! "curl -L -o #{swig_download_path} #{swig_url}"
|
131
|
+
# system! "wget -P #{GEM_CACHE_DIR} #{swig_url}"
|
132
|
+
end
|
133
|
+
link(swig_download_path, swig_filename)
|
134
|
+
system! "#{@tar_cmd} -xf swig-#{SWIG_VERSION}.tar.gz"
|
135
|
+
FileUtils.chdir(SOURCE_DIR)
|
136
|
+
|
137
|
+
# Requirement: pcre.
|
138
|
+
if not pcre_installed? then
|
139
|
+
install_pcre
|
140
|
+
end
|
141
|
+
|
142
|
+
system! "make distclean" if File.exists?('Makefile')
|
143
|
+
run_script! "./configure --prefix=#{INSTALL_DIR}"
|
144
|
+
|
145
|
+
processors = Parallel.processor_count
|
146
|
+
if processors > 1
|
147
|
+
system! "make -j#{processors}"
|
148
|
+
else
|
149
|
+
system! 'make'
|
150
|
+
end
|
151
|
+
FileUtils.chdir(PWD)
|
152
|
+
end
|
153
|
+
|
154
|
+
def install_swig
|
155
|
+
FileUtils.chdir(SOURCE_DIR)
|
156
|
+
system! 'make install'
|
157
|
+
FileUtils.chdir(PWD)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
task :default => [:build_swig]
|
163
|
+
|
164
|
+
task :build_swig do
|
165
|
+
builder = RubySwig::SwigBuilder.new
|
166
|
+
builder.build_swig
|
167
|
+
builder.install_swig
|
168
|
+
builder.install_manpages('/usr/local')
|
169
|
+
end
|
170
|
+
|
171
|
+
task :install_manpages do
|
172
|
+
RubySwig::SwigBuilder.new.install_manpages('/usr/local')
|
173
|
+
end
|
174
|
+
|
data/ext/build_swig
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
pushd `dirname $0/..`
|
3
|
+
PROJECT_ROOT=$PWD
|
4
|
+
|
5
|
+
wget http://downloads.sourceforge.net/project/swig/swig/swig-2.0.7/swig-2.0.7.tar.gz
|
6
|
+
tar -zxsf swig-2.0.7.tar.gz
|
7
|
+
cd swig-2.0.7
|
8
|
+
|
9
|
+
# Requirement: pcre.
|
10
|
+
# Detect existing pcre library.
|
11
|
+
gcc -c findpcre.c -o /dev/null
|
12
|
+
if ! $?; then
|
13
|
+
# Download and build local version of pcre.
|
14
|
+
wget http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz
|
15
|
+
Tools/pcre-build.sh
|
16
|
+
fi
|
17
|
+
|
18
|
+
# This works for both rvm and non-rvm installations (as opposed to $GEM_PATH)
|
19
|
+
GEMDIR=`gem env gemdir`
|
20
|
+
# When running from extconf.rb, use $PROJECT_ROOT. Then swig will be in the bin folder.
|
21
|
+
./configure --prefix=$GEMDIR
|
22
|
+
processor_count=`ruby -r 'parallel' -e 'puts Parallel.processor_count'`
|
23
|
+
make -j${processor_count:-1}
|
24
|
+
make install
|
25
|
+
|
26
|
+
# This is optional.
|
27
|
+
# Add share/man page for ccache-swig
|
28
|
+
sudo mkdir -p /usr/local/share/man/man1
|
29
|
+
# ln -s $GEMDIR/share/man/man1/ccache-swig.1 /usr/local/share/man/man1/
|
30
|
+
for manpage in $GEMDIR/share/man/man1/*; do
|
31
|
+
page=`basename $manpage`
|
32
|
+
if ! [ -f /usr/local/share/man/man1/$page ]; then
|
33
|
+
if [ -h /usr/local/share/man/man1/$page ]; then
|
34
|
+
# Remove stale link
|
35
|
+
sudo rm /usr/local/share/man/man1/$page
|
36
|
+
fi
|
37
|
+
sudo ln -s $manpage /usr/local/share/man/man1/$page
|
38
|
+
fi
|
39
|
+
done
|
40
|
+
|
41
|
+
popd
|
data/ext/download.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile's
|
3
|
+
# HTTP implementation.
|
4
|
+
#
|
5
|
+
# Author: Jon Maken
|
6
|
+
# License: 3-clause BSD
|
7
|
+
# Revision: 2012-03-25 23:01:19 -0600
|
8
|
+
|
9
|
+
require 'net/http'
|
10
|
+
require 'net/https' if RUBY_VERSION < '1.9'
|
11
|
+
require 'net/ftp'
|
12
|
+
require 'fileutils'
|
13
|
+
require 'tempfile'
|
14
|
+
|
15
|
+
class Downloader
|
16
|
+
|
17
|
+
VERSION = '0.1.0'
|
18
|
+
|
19
|
+
# class attributes
|
20
|
+
class << self
|
21
|
+
attr_accessor :logger, :max_ca_verify_depth, :ftp_data_chunk_size
|
22
|
+
end
|
23
|
+
|
24
|
+
@logger = STDOUT.binmode
|
25
|
+
@max_ca_verify_depth = 5
|
26
|
+
@ftp_data_chunk_size = 8192
|
27
|
+
|
28
|
+
|
29
|
+
def self.download_file(url, full_path, count = 3)
|
30
|
+
return if File.exist?(full_path)
|
31
|
+
|
32
|
+
uri = URI.parse(url)
|
33
|
+
case uri.scheme.downcase
|
34
|
+
when /ftp/
|
35
|
+
ftp_download(uri, full_path)
|
36
|
+
when /http|https/
|
37
|
+
http_download(url, full_path, count)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
def self.message(text)
|
44
|
+
@logger.print text
|
45
|
+
@logger.flush
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.output(text = '')
|
49
|
+
@logger.puts text
|
50
|
+
@logger.flush
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.http_download(url, full_path, count)
|
54
|
+
|
55
|
+
begin
|
56
|
+
uri = URI.parse(url)
|
57
|
+
filename = File.basename(uri.path)
|
58
|
+
|
59
|
+
if ENV['HTTP_PROXY']
|
60
|
+
protocol, userinfo, proxy_host, proxy_port = URI::split(ENV['HTTP_PROXY'])
|
61
|
+
proxy_user, proxy_pass = userinfo.split(/:/) if userinfo
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
|
63
|
+
else
|
64
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
65
|
+
end
|
66
|
+
|
67
|
+
if uri.scheme.downcase == 'https'
|
68
|
+
http.use_ssl = true
|
69
|
+
if ENV['CA_CERT_FILE']
|
70
|
+
cert_file = ENV['CA_CERT_FILE'].dup
|
71
|
+
cert_file.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
72
|
+
end
|
73
|
+
if cert_file && File.exists?(cert_file)
|
74
|
+
http.ca_file = cert_file
|
75
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
76
|
+
http.verify_depth = @max_ca_verify_depth
|
77
|
+
else
|
78
|
+
raise <<-EOT
|
79
|
+
To download using HTTPS you must first set the CA_CERT_FILE
|
80
|
+
environment variable to the path of a valid CA certificate file.
|
81
|
+
A file of bundled public CA certs may be downloaded from:
|
82
|
+
|
83
|
+
http://curl.haxx.se/ca/cacert.pem
|
84
|
+
|
85
|
+
EOT
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
http.request_get(uri.path) do |response|
|
90
|
+
case response
|
91
|
+
when Net::HTTPNotFound
|
92
|
+
output "404 - Not Found"
|
93
|
+
return false
|
94
|
+
|
95
|
+
when Net::HTTPClientError
|
96
|
+
output "Error: Client Error: #{response.inspect}"
|
97
|
+
return false
|
98
|
+
|
99
|
+
when Net::HTTPRedirection
|
100
|
+
raise "Too many redirections for the original URL, halting." if count <= 0
|
101
|
+
url = response["location"]
|
102
|
+
return http_download(url, full_path, count - 1)
|
103
|
+
|
104
|
+
when Net::HTTPOK
|
105
|
+
temp_file = Tempfile.new("download-#{filename}")
|
106
|
+
temp_file.binmode
|
107
|
+
|
108
|
+
size = 0
|
109
|
+
progress = 0
|
110
|
+
total = response.header["Content-Length"].to_i
|
111
|
+
|
112
|
+
response.read_body do |chunk|
|
113
|
+
temp_file << chunk
|
114
|
+
size += chunk.size
|
115
|
+
new_progress = (size * 100) / total
|
116
|
+
unless new_progress == progress
|
117
|
+
message "\rDownloading %s (%3d%%) " % [filename, new_progress]
|
118
|
+
end
|
119
|
+
progress = new_progress
|
120
|
+
end
|
121
|
+
|
122
|
+
output
|
123
|
+
|
124
|
+
temp_file.close
|
125
|
+
File.unlink full_path if File.exists?(full_path)
|
126
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
127
|
+
FileUtils.mv temp_file.path, full_path, :force => true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
rescue Exception => e
|
132
|
+
File.unlink full_path if File.exists?(full_path)
|
133
|
+
output "ERROR: #{e.message}"
|
134
|
+
raise "Failed to download file"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.ftp_download(parsed_uri, full_path)
|
139
|
+
filename = File.basename(parsed_uri.path)
|
140
|
+
|
141
|
+
begin
|
142
|
+
temp_file = Tempfile.new("download-#{filename}")
|
143
|
+
temp_file.binmode
|
144
|
+
|
145
|
+
size = 0
|
146
|
+
progress = 0
|
147
|
+
|
148
|
+
# TODO add user/pw support
|
149
|
+
Net::FTP.open(parsed_uri.host) do |ftp|
|
150
|
+
ftp.passive = true
|
151
|
+
ftp.login
|
152
|
+
remote_dir = File.dirname(parsed_uri.path)
|
153
|
+
ftp.chdir(remote_dir) unless remote_dir == '.'
|
154
|
+
|
155
|
+
total = ftp.size(filename)
|
156
|
+
|
157
|
+
ftp.getbinaryfile(filename, nil, @ftp_data_chunk_size) do |chunk|
|
158
|
+
temp_file << chunk
|
159
|
+
size += chunk.size
|
160
|
+
new_progress = (size * 100) / total
|
161
|
+
unless new_progress == progress
|
162
|
+
message "\rDownloading %s (%3d%%) " % [filename, new_progress]
|
163
|
+
end
|
164
|
+
progress = new_progress
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
output
|
169
|
+
|
170
|
+
temp_file.close
|
171
|
+
File.unlink full_path if File.exists?(full_path)
|
172
|
+
FileUtils.mkdir_p File.dirname(full_path)
|
173
|
+
FileUtils.mv temp_file.path, full_path, :force => true
|
174
|
+
|
175
|
+
rescue Exception => e
|
176
|
+
File.unlink full_path if File.exists?(full_path)
|
177
|
+
output "ERROR: #{e.message}"
|
178
|
+
raise "Failed to download file"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end # Downloader
|
183
|
+
|
184
|
+
|
185
|
+
if __FILE__ == $0
|
186
|
+
usage = <<-EOU
|
187
|
+
|
188
|
+
HTTP/HTTPS/FTP File Downloader, v#{Downloader::VERSION}
|
189
|
+
Usage: ruby download.rb URL FILE
|
190
|
+
|
191
|
+
URL http/https/ftp location of the file to download
|
192
|
+
FILE full local path at which to save downloaded file
|
193
|
+
|
194
|
+
|
195
|
+
influential environment variables:
|
196
|
+
|
197
|
+
HTTP_PROXY url to http proxy
|
198
|
+
CA_CERT_FILE full path to CA certificate file
|
199
|
+
EOU
|
200
|
+
|
201
|
+
abort usage if ARGV.length != 2
|
202
|
+
|
203
|
+
Downloader.download_file(ARGV[0], ARGV[1])
|
204
|
+
end
|
data/ext/findpcre.c
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#include "pcre.h"
|
data/lib/rubyswig.rb
ADDED
data/rubyswig.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rubyswig/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Wong"]
|
6
|
+
gem.email = ["bdwong.net@gmail.com"]
|
7
|
+
gem.description = %q{Builds SWIG (Simplified Wrapper Interface Generator) from source with minimal dependencies,
|
8
|
+
then installs it as a rubygem executable, allowing it to be versioned with rvm gemsets.
|
9
|
+
More importantly, makes installing SWIG dead-easy, and allows you to use Gemfiles and
|
10
|
+
Bundler to specify dependencies against it.
|
11
|
+
}
|
12
|
+
gem.summary = %q{Build and install SWIG from source for Ruby}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.extensions << "ext/Rakefile"
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
#gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.executables = ['swig', 'ccache-swig']
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.name = "rubyswig"
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
gem.version = Rubyswig::VERSION
|
23
|
+
gem.bindir = "bin"
|
24
|
+
gem.add_dependency "parallel"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyswig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Wong
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: parallel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ! "Builds SWIG (Simplified Wrapper Interface Generator) from source with
|
31
|
+
minimal dependencies,\n then installs it as a rubygem executable,
|
32
|
+
allowing it to be versioned with rvm gemsets.\n More importantly,
|
33
|
+
makes installing SWIG dead-easy, and allows you to use Gemfiles and\n Bundler
|
34
|
+
to specify dependencies against it.\n "
|
35
|
+
email:
|
36
|
+
- bdwong.net@gmail.com
|
37
|
+
executables:
|
38
|
+
- swig
|
39
|
+
- ccache-swig
|
40
|
+
extensions:
|
41
|
+
- ext/Rakefile
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- bin/ccache-swig
|
50
|
+
- bin/swig
|
51
|
+
- ext/Rakefile
|
52
|
+
- ext/bsdtar-pcre-build.sh
|
53
|
+
- ext/build_swig
|
54
|
+
- ext/download.rb
|
55
|
+
- ext/findpcre.c
|
56
|
+
- lib/rubyswig.rb
|
57
|
+
- lib/rubyswig/version.rb
|
58
|
+
- rubyswig.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.21
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Build and install SWIG from source for Ruby
|
83
|
+
test_files: []
|