File: Rakefile

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (332 lines) | stat: -rw-r--r-- 10,701 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
require_relative 'lib/concurrent-ruby/concurrent/version'
require_relative 'lib/concurrent-ruby-edge/concurrent/edge/version'
require_relative 'lib/concurrent-ruby/concurrent/utility/engine'

if Concurrent.ruby_version :<, 2, 0, 0
  # @!visibility private
  module Kernel
    def __dir__
      File.dirname __FILE__
    end
  end
end

core_gemspec = Gem::Specification.load File.join(__dir__, 'concurrent-ruby.gemspec')
ext_gemspec  = Gem::Specification.load File.join(__dir__, 'concurrent-ruby-ext.gemspec')
edge_gemspec = Gem::Specification.load File.join(__dir__, 'concurrent-ruby-edge.gemspec')

require 'rake/javaextensiontask'

ENV['JRUBY_HOME'] = ENV['CONCURRENT_JRUBY_HOME'] if ENV['CONCURRENT_JRUBY_HOME'] && !Concurrent.on_jruby?

Rake::JavaExtensionTask.new('concurrent_ruby', core_gemspec) do |ext|
  ext.ext_dir = 'ext/concurrent-ruby'
  ext.lib_dir = 'lib/concurrent-ruby/concurrent'
end

unless Concurrent.on_jruby?
  require 'rake/extensiontask'

  Rake::ExtensionTask.new('concurrent_ruby_ext', ext_gemspec) do |ext|
    ext.ext_dir        = 'ext/concurrent-ruby-ext'
    ext.lib_dir        = 'lib/concurrent-ruby/concurrent'
    ext.source_pattern = '*.{c,h}'

    ext.cross_compile  = true
    ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
  end
end

require 'rake_compiler_dock'
namespace :repackage do
  desc '* with Windows fat distributions'
  task :all do
    Dir.chdir(__dir__) do
      # store gems in vendor cache for docker
      sh 'bundle package'

      # build only the jar file not the whole gem for java platform, the jar is part the concurrent-ruby-x.y.z.gem
      Rake::Task['lib/concurrent-ruby/concurrent/concurrent_ruby.jar'].invoke

      # build all gem files
      RakeCompilerDock.sh 'bundle install --local && bundle exec rake cross native package --trace'
    end
  end
end

require 'rubygems'
require 'rubygems/package_task'

Gem::PackageTask.new(core_gemspec) {} if core_gemspec
Gem::PackageTask.new(ext_gemspec) {} if ext_gemspec && !Concurrent.on_jruby?
Gem::PackageTask.new(edge_gemspec) {} if edge_gemspec

CLEAN.include('lib/concurrent-ruby/concurrent/2.*', 'lib/concurrent-ruby/concurrent/*.jar')

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

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

  namespace :spec do
    desc '* Configured for ci'
    RSpec::Core::RakeTask.new(:ci) do |t|
      options      = %w[ --color
                    --backtrace
                    --order defined
                    --format documentation
                    --tag ~notravis ]
      t.rspec_opts = [*options].join(' ')
    end

    desc '* test packaged and installed gems instead of local files'
    task :installed do
      Dir.chdir(__dir__) do
        sh "gem install pkg/concurrent-ruby-#{Concurrent::VERSION}.gem"
        sh "gem install pkg/concurrent-ruby-ext-#{Concurrent::VERSION}.gem" if Concurrent.on_cruby?
        sh "gem install pkg/concurrent-ruby-edge-#{Concurrent::EDGE_VERSION}.gem"
        ENV['NO_PATH'] = 'true'
        sh 'bundle update'
        sh 'bundle exec rake spec:ci'
      end
    end
  end

  desc 'executed in CI'
  task :ci => [:compile, 'spec:ci']

  task :default => [:clobber, :compile, :spec]
rescue LoadError => e
  puts 'RSpec is not installed, skipping test task definitions: ' + e.message
end

current_yard_version_name = Concurrent::VERSION

begin
  require 'yard'
  require 'md_ruby_eval'
  require_relative 'support/yard_full_types'

  common_yard_options = ['--no-yardopts',
                         '--no-document',
                         '--no-private',
                         '--embed-mixins',
                         '--markup', 'markdown',
                         '--title', 'Concurrent Ruby',
                         '--template', 'default',
                         '--template-path', 'yard-template',
                         '--default-return', 'undocumented']

  desc 'Generate YARD Documentation (signpost, master)'
  task :yard => ['yard:signpost', 'yard:master']

  namespace :yard do

    desc '* eval markdown files'
    task :eval_md do
      Dir.chdir File.join(__dir__, 'docs-source') do
        sh 'bundle exec md-ruby-eval --auto'
      end
    end

    task :update_readme do
      Dir.chdir __dir__ do
        content = File.read(File.join('README.md')).
            gsub(/\[([\w ]+)\]\(http:\/\/ruby-concurrency\.github\.io\/concurrent-ruby\/master\/.*\)/) do |_|
          case $1
          when 'LockFreeLinkedSet'
            "{Concurrent::Edge::#{$1} #{$1}}"
          when '.dataflow'
            '{Concurrent.dataflow Concurrent.dataflow}'
          when 'thread pool'
            '{file:thread_pools.md thread pool}'
          else
            "{Concurrent::#{$1} #{$1}}"
          end
        end
        FileUtils.mkpath 'tmp'
        File.write 'tmp/README.md', content
      end
    end

    define_yard_task = -> name do
      output_dir = "docs/#{name}"

      removal_name = "remove.#{name}"
      task removal_name do
        Dir.chdir __dir__ do
          FileUtils.rm_rf output_dir
        end
      end

      desc "* of #{name} into subdir #{name}"
      YARD::Rake::YardocTask.new(name) do |yard|
        yard.options.push(
            '--output-dir', output_dir,
            '--main', 'tmp/README.md',
            *common_yard_options)
        yard.files = ['./lib/concurrent-ruby/**/*.rb',
                      './lib/concurrent-ruby-edge/**/*.rb',
                      './ext/concurrent_ruby_ext/**/*.c',
                      '-',
                      'docs-source/thread_pools.md',
                      'docs-source/promises.out.md',
                      'docs-source/medium-example.out.rb',
                      'LICENSE.md',
                      'CHANGELOG.md']
      end
      Rake::Task[name].prerequisites.push removal_name,
                                          # 'yard:eval_md',
                                          'yard:update_readme'
    end

    define_yard_task.call current_yard_version_name
    define_yard_task.call 'master'

    desc "* signpost for versions"
    YARD::Rake::YardocTask.new(:signpost) do |yard|
      yard.options.push(
          '--output-dir', 'docs',
          '--main', 'docs-source/signpost.md',
          *common_yard_options)
      yard.files = ['no-lib']
    end

    define_uptodate_task = -> name do
      namespace name do
        desc "** ensure that #{name} generated documentation is matching the source code"
        task :uptodate do
          Dir.chdir(__dir__) do
            begin
              FileUtils.cp_r 'docs', 'docs-copy', verbose: true
              Rake::Task["yard:#{name}"].invoke
              sh 'diff -r docs/ docs-copy/' do |ok, res|
                unless ok
                  begin
                    STDOUT.puts 'Command failed. Continue? (y/n)'
                    input = STDIN.gets.strip.downcase
                  end until %w(y n).include?(input)
                  exit 1 if input == 'n'
                end
              end
            ensure
              FileUtils.rm_rf 'docs-copy', verbose: true
            end
          end
        end
      end
    end

    define_uptodate_task.call current_yard_version_name
    define_uptodate_task.call 'master'
  end

rescue LoadError => e
  puts 'YARD is not installed, skipping documentation task definitions: ' + e.message
end

desc 'build, test, and publish the gem'
task :release => ['release:checks', 'release:build', 'release:test', 'release:publish']

namespace :release do
  # Depends on environment of @pitr-ch

  mri_version   = '2.6.5'
  jruby_version = 'jruby-9.2.9.0'

  task :checks => "yard:#{current_yard_version_name}:uptodate" do
    Dir.chdir(__dir__) do
      sh 'test -z "$(git status --porcelain)"' do |ok, res|
        unless ok
          begin
            STDOUT.puts 'Command failed. Continue? (y/n)'
            input = STDIN.gets.strip.downcase
          end until %w(y n).include?(input)
          exit 1 if input == 'n'
        end
      end
      sh 'git fetch'
      sh 'test $(git show-ref --verify --hash refs/heads/master) = ' +
             '$(git show-ref --verify --hash refs/remotes/origin/master)' do |ok, res|
        unless ok
          begin
            STDOUT.puts 'Command failed. Continue? (y/n)'
            input = STDIN.gets.strip.downcase
          end until %w(y n).include?(input)
          exit 1 if input == 'n'
        end
      end
    end
  end

  desc '* build all *.gem files necessary for release'
  task :build => [:clobber, 'repackage:all']

  desc '* test actual installed gems instead of cloned repository on MRI and JRuby'
  task :test do
    Dir.chdir(__dir__) do
      old = ENV['RBENV_VERSION']

      ENV['RBENV_VERSION'] = mri_version
      sh 'rbenv version'
      sh 'bundle exec rake spec:installed'

      ENV['RBENV_VERSION'] = jruby_version
      sh 'rbenv version'
      sh 'bundle exec rake spec:installed'

      puts 'Windows build is untested'

      ENV['RBENV_VERSION'] = old
    end
  end

  desc '* do all nested steps'
  task :publish => ['publish:ask', 'publish:tag', 'publish:rubygems', 'publish:post_steps']

  namespace :publish do
    publish_edge = false

    task :ask do
      begin
        STDOUT.puts 'Do you want to publish anything? (y/n)'
        input = STDIN.gets.strip.downcase
      end until %w(y n).include?(input)
      exit 1 if input == 'n'
      begin
        STDOUT.puts 'Do you want to publish edge? (y/n)'
        input = STDIN.gets.strip.downcase
      end until %w(y n).include?(input)
      publish_edge = input == 'y'
    end

    desc '** tag HEAD with current version and push to github'
    task :tag do
      Dir.chdir(__dir__) do
        sh "git tag v#{Concurrent::VERSION}"
        sh "git push origin v#{Concurrent::VERSION}"
        sh "git tag edge-v#{Concurrent::EDGE_VERSION}" if publish_edge
        sh "git push origin edge-v#{Concurrent::EDGE_VERSION}" if publish_edge
      end
    end

    desc '** push all *.gem files to rubygems'
    task :rubygems do
      Dir.chdir(__dir__) do
        sh "gem push pkg/concurrent-ruby-#{Concurrent::VERSION}.gem"
        sh "gem push pkg/concurrent-ruby-edge-#{Concurrent::EDGE_VERSION}.gem" if publish_edge
        sh "gem push pkg/concurrent-ruby-ext-#{Concurrent::VERSION}.gem"
        sh "gem push pkg/concurrent-ruby-ext-#{Concurrent::VERSION}-x64-mingw32.gem"
        sh "gem push pkg/concurrent-ruby-ext-#{Concurrent::VERSION}-x86-mingw32.gem"
      end
    end

    desc '** print post release steps'
    task :post_steps do
      puts 'Manually: create a release on GitHub with relevant changelog part'
      puts 'Manually: send email same as release with relevant changelog part'
      puts 'Manually: tweet'
    end
  end
end