PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tasks/compile.rake

https://github.com/YahorSimanau/gherkin
Unknown | 83 lines | 69 code | 14 blank | 0 comment | 0 complexity | 5c81b35361f6ae780d2c3f76d2b6cf19 MD5 | raw file
  1. require File.dirname(__FILE__) + '/ragel_task'
  2. BYPASS_NATIVE_IMPL = true
  3. require 'gherkin/i18n'
  4. CLEAN.include [
  5. 'pkg', 'tmp',
  6. '**/*.{o,bundle,jar,so,obj,pdb,lib,def,exp,log,rbc}', 'ext',
  7. 'java/target',
  8. 'lib/*.dll',
  9. 'ext/**/*.c',
  10. 'doc'
  11. ]
  12. desc "Compile the Java extensions"
  13. task :jar => 'lib/gherkin.jar'
  14. file 'lib/gherkin.jar' => Dir['java/src/main/java/**/*.java'] do
  15. sh("mvn -f java/pom.xml package")
  16. end
  17. desc "Build JavaScript lexers"
  18. task :js
  19. rl_langs = ENV['RL_LANGS'] ? ENV['RL_LANGS'].split(',') : []
  20. langs = Gherkin::I18n.all.select { |lang| rl_langs.empty? || rl_langs.include?(lang.iso_code) }
  21. langs.each do |i18n|
  22. java = RagelTask.new('java', i18n)
  23. rb = RagelTask.new('rb', i18n)
  24. js = RagelTask.new('js', i18n)
  25. file 'lib/gherkin.jar' => [java.target]
  26. begin
  27. if !defined?(JRUBY_VERSION)
  28. require 'rake/extensiontask'
  29. c = RagelTask.new('c', i18n)
  30. extconf = "ext/gherkin_lexer_#{i18n.underscored_iso_code}/extconf.rb"
  31. file extconf do
  32. FileUtils.mkdir(File.dirname(extconf)) unless File.directory?(File.dirname(extconf))
  33. File.open(extconf, "w") do |io|
  34. io.write(<<-EOF)
  35. require 'mkmf'
  36. CONFIG['warnflags'].gsub!(/-Wshorten-64-to-32/, '') if CONFIG['warnflags']
  37. $CFLAGS << ' -O0 -Wall' if CONFIG['CC'] =~ /gcc|clang/
  38. dir_config("gherkin_lexer_#{i18n.underscored_iso_code}")
  39. have_library("c", "main")
  40. create_makefile("gherkin_lexer_#{i18n.underscored_iso_code}")
  41. EOF
  42. end
  43. end
  44. Rake::ExtensionTask.new("gherkin_lexer_#{i18n.underscored_iso_code}") do |ext|
  45. if ENV['RUBY_CC_VERSION']
  46. ext.cross_compile = true
  47. ext.cross_platform = 'x86-mingw32'
  48. end
  49. end
  50. # The way tasks are defined with compile:xxx (but without namespace) in rake-compiler forces us
  51. # to use these hacks for setting up dependencies. Ugly!
  52. Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(extconf)
  53. Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(c.target)
  54. Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(rb.target)
  55. Rake::Task["compile:gherkin_lexer_#{i18n.underscored_iso_code}"].prerequisites.unshift(js.target) if ENV['GHERKIN_JS']
  56. Rake::Task["compile"].prerequisites.unshift(extconf)
  57. Rake::Task["compile"].prerequisites.unshift(c.target)
  58. Rake::Task["compile"].prerequisites.unshift(rb.target)
  59. Rake::Task["compile"].prerequisites.unshift(js.target) if ENV['GHERKIN_JS']
  60. Rake::Task["js"].prerequisites.unshift(js.target) if ENV['GHERKIN_JS']
  61. end
  62. rescue LoadError
  63. unless defined?($c_warned)
  64. warn "WARNING: Rake::ExtensionTask not installed. Skipping C compilation."
  65. $c_warned = true
  66. task :compile # no-op
  67. end
  68. end
  69. end