1- begin
2- require 'rubygems/package_task'
3- rescue LoadError
4- end
1+ require "bundler/gem_tasks"
52
63require 'rbconfig'
74include RbConfig
85
9- require 'rake/clean'
10- CLOBBER . include 'doc' , 'Gemfile.lock'
11- CLEAN . include FileList [ 'diagrams/*.*' ] , 'doc' , 'coverage' , 'tmp' ,
12- FileList [ "ext/**/{Makefile,mkmf.log}" ] , 'build' , 'dist' , FileList [ '**/*.rbc' ] ,
13- FileList [ "{ext,lib}/**/*.{so,bundle,#{ CONFIG [ 'DLEXT' ] } ,o,obj,pdb,lib,manifest,exp,def,jar,class,dSYM}" ] ,
14- FileList [ 'java/src/**/*.class' ]
15-
166require 'rake/testtask'
177class UndocumentedTestTask < Rake ::TestTask
188 def desc ( *) end
199end
2010
21- which = lambda { |c |
22- w = `which #{ c } `
23- break w . chomp unless w . empty?
24- }
25-
26- MAKE = ENV [ 'MAKE' ] || %w[ gmake make ] . find ( &which )
27- BUNDLE = ENV [ 'BUNDLE' ] || %w[ bundle ] . find ( &which )
28-
2911PKG_VERSION = File . foreach ( File . join ( __dir__ , "lib/json/version.rb" ) ) do |line |
3012 /^\s *VERSION\s *=\s *'(.*)'/ =~ line and break $1
3113end rescue nil
3214
33- EXT_ROOT_DIR = 'ext/json/ext'
34- EXT_PARSER_DIR = "#{ EXT_ROOT_DIR } /parser"
35- EXT_PARSER_DL = "#{ EXT_PARSER_DIR } /parser.#{ CONFIG [ 'DLEXT' ] } "
36- EXT_PARSER_SRC = "#{ EXT_PARSER_DIR } /parser.c"
37- EXT_GENERATOR_DIR = "#{ EXT_ROOT_DIR } /generator"
38- EXT_GENERATOR_DL = "#{ EXT_GENERATOR_DIR } /generator.#{ CONFIG [ 'DLEXT' ] } "
39- EXT_GENERATOR_SRC = "#{ EXT_GENERATOR_DIR } /generator.c"
40-
4115JAVA_DIR = "java/src/json/ext"
4216JAVA_RAGEL_PATH = "#{ JAVA_DIR } /ParserConfig.rl"
4317JAVA_PARSER_SRC = "#{ JAVA_DIR } /ParserConfig.java"
@@ -46,6 +20,11 @@ JAVA_CLASSES = []
4620JRUBY_PARSER_JAR = File . expand_path ( "lib/json/ext/parser.jar" )
4721JRUBY_GENERATOR_JAR = File . expand_path ( "lib/json/ext/generator.jar" )
4822
23+ which = lambda { |c |
24+ w = `which #{ c } `
25+ break w . chomp unless w . empty?
26+ }
27+
4928if RUBY_PLATFORM =~ /mingw|mswin/
5029 # cleans up Windows CI output
5130 RAGEL_CODEGEN = %w[ ragel ] . find ( &which )
5534 RAGEL_DOTGEN = %w[ rlgen-dot rlgen-cd ragel ] . find ( &which )
5635end
5736
58- desc "Installing library (extension)"
59- task :install => [ :compile ] do
60- sitearchdir = CONFIG [ "sitearchdir" ]
61- cd 'ext' do
62- for file in Dir [ "json/ext/*.#{ CONFIG [ 'DLEXT' ] } " ]
63- d = File . join ( sitearchdir , file )
64- mkdir_p File . dirname ( d )
65- install ( file , d )
66- end
67- warn " *** Installed EXT ruby library."
68- end
69- end
70-
71- namespace :gems do
72- desc 'Install all development gems'
73- task :install do
74- sh "#{ BUNDLE } "
75- end
76- end
77-
78- file EXT_PARSER_DL => EXT_PARSER_SRC do
79- cd EXT_PARSER_DIR do
80- ruby 'extconf.rb'
81- sh MAKE
82- end
83- cp "#{ EXT_PARSER_DIR } /parser.#{ CONFIG [ 'DLEXT' ] } " , EXT_ROOT_DIR
84- end
85-
86- file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
87- cd EXT_GENERATOR_DIR do
88- ruby 'extconf.rb'
89- sh MAKE
90- end
91- cp "#{ EXT_GENERATOR_DIR } /generator.#{ CONFIG [ 'DLEXT' ] } " , EXT_ROOT_DIR
92- end
93-
9437file JAVA_PARSER_SRC => JAVA_RAGEL_PATH do
9538 cd JAVA_DIR do
9639 if RAGEL_CODEGEN == 'ragel'
@@ -102,13 +45,7 @@ file JAVA_PARSER_SRC => JAVA_RAGEL_PATH do
10245end
10346
10447desc "Generate parser with ragel"
105- task :ragel => [ EXT_PARSER_SRC , JAVA_PARSER_SRC ]
106-
107- desc "Delete the ragel generated C source"
108- task :ragel_clean do
109- rm_rf EXT_PARSER_SRC
110- rm_rf JAVA_PARSER_SRC
111- end
48+ task :ragel => [ JAVA_PARSER_SRC ]
11249
11350if defined? ( RUBY_ENGINE ) and RUBY_ENGINE == 'jruby'
11451 ENV [ 'JAVA_HOME' ] ||= [
@@ -201,13 +138,14 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
201138
202139 task :release => :build
203140else
204- desc "Compiling extension"
205- if RUBY_ENGINE == 'truffleruby'
206- task :compile => [ EXT_PARSER_DL ]
207- else
208- task :compile => [ EXT_PARSER_DL , EXT_GENERATOR_DL ]
141+ require 'rake/extensiontask'
142+
143+ unless RUBY_ENGINE == 'truffleruby'
144+ Rake ::ExtensionTask . new ( "json/ext/generator" )
209145 end
210146
147+ Rake ::ExtensionTask . new ( "json/ext/parser" )
148+
211149 UndocumentedTestTask . new do |t |
212150 t . name = :test
213151 t . test_files = FileList [ 'test/json/*_test.rb' ]
0 commit comments