File: Rakefile

package info (click to toggle)
ruby-concurrent 1.0.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,200 kB
  • sloc: ruby: 27,502; java: 6,085; ansic: 282; sh: 82; makefile: 4
file content (205 lines) | stat: -rw-r--r-- 5,509 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env rake

$:.push File.join(File.dirname(__FILE__), 'lib')

require 'concurrent/version'
require 'concurrent/utility/native_extension_loader'

## load the gemspec files
CORE_GEMSPEC  = Gem::Specification.load('concurrent-ruby.gemspec')
EXT_GEMSPEC   = Gem::Specification.load('concurrent-ruby-ext.gemspec')
EDGE_GEMSPEC  = Gem::Specification.load('concurrent-ruby-edge.gemspec')

## constants used for compile/build tasks

GEM_NAME      = 'concurrent-ruby'
EXT_NAME      = 'extension'
EDGE_NAME     = 'edge'
JAVA_EXT_NAME = 'concurrent_ruby_ext'

if Concurrent.on_jruby?
  CORE_GEM = "#{GEM_NAME}-#{Concurrent::VERSION}-java.gem"
else
  CORE_GEM   = "#{GEM_NAME}-#{Concurrent::VERSION}.gem"
  EXT_GEM    = "#{GEM_NAME}-ext-#{Concurrent::VERSION}.gem"
  NATIVE_GEM = "#{GEM_NAME}-ext-#{Concurrent::VERSION}-#{Gem::Platform.new(RUBY_PLATFORM)}.gem"
  EDGE_GEM   = "#{GEM_NAME}-edge-#{Concurrent::EDGE_VERSION}.gem"
end

## safely load all the rake tasks in the `tasks` directory

def safe_load(file)
  begin
    load file
  rescue LoadError => ex
    puts "Error loading rake tasks from '#{file}' but will continue..."
    puts ex.message
  end
end

Dir.glob('tasks/**/*.rake').each do |rakefile|
  safe_load rakefile
end

def has_docker?
  if Concurrent.on_linux?
    system("docker version > /dev/null 2>&1")
  elsif Concurrent.on_osx?
    system("docker version > /dev/null 2>&1 || boot2docker version > /dev/null 2>&1")
  else
    false
  end
end

if Concurrent.on_jruby?

  ## create the compile task for the JRuby-specific gem
  require 'rake/javaextensiontask'

  Rake::JavaExtensionTask.new(JAVA_EXT_NAME, CORE_GEMSPEC) do |ext|
    ext.ext_dir = 'ext'
  end

elsif Concurrent.allow_c_extensions?

  ## create the compile tasks for the extension gem
  require 'rake/extensiontask'

  Rake::ExtensionTask.new(EXT_NAME, EXT_GEMSPEC) do |ext|
    ext.ext_dir        = 'ext/concurrent'
    ext.lib_dir        = 'lib/concurrent'
    ext.source_pattern = '*.{c,h}'
    ext.cross_compile  = true
    ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
  end

  ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
    platforms = {
        'x86-mingw32' => 'i686-w64-mingw32',
        'x64-mingw32' => 'x86_64-w64-mingw32'
    }
    platforms.each do |platform, prefix|
      task "copy:#{EXT_NAME}:#{platform}:#{ruby_version}" do |t|
        ["lib", "tmp/#{platform}/stage/lib/concurrent"].each do |dir|
          so_file = "#{dir}/#{ruby_version[/^\d+\.\d+/]}/#{EXT_NAME}.so"
          if File.exists?(so_file)
            sh "#{prefix}-strip -S #{so_file}"
          end
        end
      end
    end
  end
else
  ## create an empty compile task
  task :compile
end

task :clean do
  rm_rf 'pkg/classes'
  rm_rf 'tmp'
  rm_rf Dir.glob('lib/concurrent/1.?')
  rm_rf Dir.glob('lib/concurrent/2.?')
  rm_f Dir.glob('./**/*.so')
  rm_f Dir.glob('./**/*.bundle')
  rm_f Dir.glob('./lib/*.jar')
  mkdir_p 'pkg'
end

## create build tasks tailored to current platform

namespace :build do

  task :mkdir_pkg do
    mkdir_p 'pkg'
  end

  build_deps = [:clean, 'build:mkdir_pkg']
  build_deps << :compile if Concurrent.on_jruby?

  desc "Build #{CORE_GEM} into the pkg directory"
  task :core => build_deps do
    sh "gem build #{CORE_GEMSPEC.name}.gemspec"
    sh 'mv *.gem pkg/'
  end

  unless Concurrent.on_jruby?

    desc "Build #{EDGE_GEM} into the pkg directory"
    task :edge => 'build:mkdir_pkg' do
      sh "gem build #{EDGE_GEMSPEC.name}.gemspec"
      sh 'mv *.gem pkg/'
    end

    desc "Build #{EXT_GEM} into the pkg directory"
    task :ext => build_deps do
      sh "gem build #{EXT_GEMSPEC.name}.gemspec"
      sh 'mv *.gem pkg/'
    end
  end

  if Concurrent.allow_c_extensions?
    desc "Build #{NATIVE_GEM} into the pkg directory"
    task :native => 'build:mkdir_pkg' do
      sh "gem compile pkg/#{EXT_GEM}"
      sh 'mv *.gem pkg/'
    end
  end

  if has_docker?
    desc "Build the windows binary #{Concurrent::VERSION} gems per rake-compiler-dock"
    task :windows do
      require 'rake_compiler_dock'
      RakeCompilerDock.sh <<-EOT
      bundle --without="development testing" &&
      rake cross native gem RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2
      rm -rf .bundle
      EOT
    end
  end
end

if Concurrent.on_jruby?
  desc 'Build JRuby-specific core gem (alias for `build:core`)'
  task :build => ['build:core']
elsif has_docker?
  desc 'Build core, extension, and edge gems, including Windows binaries'
  task :build => ['build:core', 'build:ext', 'build:edge', 'build:windows']
else
  desc 'Build core, extension, and edge gems (excluding Windows binaries)'
  task :build => ['build:core', 'build:ext', 'build:edge']
end

## the RSpec task that compiles extensions when available

begin
  require 'rspec'
  require 'rspec/core/rake_task'

  RSpec::Core::RakeTask.new(:spec)

  options = %w[ --color
                --backtrace
                --seed 1
                --format documentation
                --tag ~unfinished
                --tag ~notravis
                --tag ~buggy ]

  RSpec::Core::RakeTask.new(:travis) do |t|
    t.rspec_opts = ['--color', *options].join(' ')
  end

  RSpec::Core::RakeTask.new(:appveyor) do |t|
    t.rspec_opts = [*options].join(' ')
  end

  if Concurrent.on_windows?
    task :ci => [:clean, :compile, :appveyor]
  else
    task :ci => [:clean, :compile, :travis]
  end

  task :default => [:clean, :compile, :spec]
rescue LoadError
  puts 'Error loading Rspec rake tasks, probably building the gem...'
end