3 require 'rake/gempackagetask'
4 require 'rake/rdoctask'
5 require 'rake/testtask'
12 EXT_DIR = "ext/ohcount_native"
13 EXT_DL = "#{EXT_DIR}/ohcount_native.#{CONFIG['DLEXT']}"
14 ARCH_DIR = "lib/#{::Config::CONFIG['arch']}"
15 ARCH_DL = "#{ARCH_DIR}/ohcount_native.#{CONFIG['DLEXT']}"
17 RAGEL_DIR = File.join(EXT_DIR, 'ragel_parsers')
19 CLEAN.include FileList["#{EXT_DIR}/*.{so,bundle,#{CONFIG['DLEXT']}}"],
20 FileList["#{EXT_DIR}/*.o"],
21 FileList["#{EXT_DIR}/Makefile"],
22 FileList["#{RAGEL_DIR}/*.h"]
23 FileList["#{RAGEL_DIR}/*.tmp"]
25 RDOC_OPTS = ['--quiet', '--title', 'Ohcount Reference', '--main', 'README', '--inline-source']
27 Rake::RDocTask.new do |rdoc|
29 rdoc.options += RDOC_OPTS
30 rdoc.rdoc_files.add ['README' ,'COPYING', 'lib/**/*.rb', 'ext/**/*.rb', 'ext/**/*.c', 'test/test_helper.rb', 'test/unit/detector_test.rb']
33 PKG_FILES = %w(README COPYING Rakefile lib/ohcount.rb) +
34 Dir.glob("#{EXT_DIR}/*.{h,c,rb}") +
35 Dir.glob("#{RAGEL_DIR}/*.h") +
36 Dir.glob("#{RAGEL_DIR}/*.rl") +
37 Dir.glob("lib/**/*.rb") +
41 Gem::Specification.new do |s|
44 s.platform = Gem::Platform::RUBY
46 s.rdoc_options = RDOC_OPTS
47 s.extra_rdoc_files = ['README']
48 s.summary = "The Ohloh source code line counter"
49 s.description = s.summary
50 s.author = "Ohloh Corporation"
51 s.email = "info@ohloh.net"
52 s.homepage = "http://labs.ohloh.net/ohcount"
53 s.files = PKG_FILES.to_a
54 s.require_paths = ['lib']
55 s.extensions << 'ext/ohcount_native/extconf.rb'
57 s.executables = ['ohcount']
58 s.add_dependency 'diff-lcs'
61 Rake::GemPackageTask.new(SPEC) do |p|
66 task :install => :package do
67 `sudo gem install pkg/#{NAME}-#{VERS}`
70 file ARCH_DL => EXT_DL do
75 rule ".h" => ".rl" do |t|
76 if has_embedded_language?(t.source)
77 construct_language(t.source) do |constructed_file|
78 sh "ragel #{constructed_file} -o #{t.name}"
81 sh "ragel #{t.source} -o #{t.name}"
85 def has_embedded_language?(parser_file)
86 return IO.read(parser_file).include?('#EMBED')
89 def construct_language(parser_file)
90 parser_text = IO.read(parser_file).gsub(/#EMBED\([\w_]+\)/) do |elang|
91 lang = elang.scan(/^#EMBED\(([\w_]+)\)/)[0][0]
92 eparser_file = File.join(RAGEL_DIR, lang + '.rl')
93 if File.exists?(eparser_file)
94 eparser = IO.read(eparser_file)
95 ragel = eparser.scan(/%%\{(.+?)\}%%/m)[0][0]
96 # eliminate machine definition, writes, and includes
97 ragel.gsub!(/^\s*machine[^;]+;\s+write[^;]+;\s+include[^;]+;\s+/, '')
103 tmp = parser_file + '.tmp'
104 File.open(tmp, 'w') { |f| f.write parser_text }
109 file EXT_DL => FileList["#{EXT_DIR}/Makefile", "#{EXT_DIR}/*.{c,h,rb}", "#{RAGEL_DIR}/*.h"] do
115 file "#{EXT_DIR}/ragel_parser.c" => FileList["#{RAGEL_DIR}/*.rl"].gsub(/\.rl/,'.h') do
116 # When any ragel parser changes, we need to rebuild ragel_parser.c.
117 # We force this by deleting the existing object file.
118 # We have no better option than this because C dependencies are controlled by mkmf,
119 # outside of the control of this Rakefile.
120 File.delete(File.join(EXT_DIR, 'ragel_parser.o')) if File.exist?(File.join(EXT_DIR, 'ragel_parser.o'))
123 file "#{EXT_DIR}/Makefile" => "#{EXT_DIR}/extconf.rb" do
126 ruby 'extconf.rb', 'debug'
133 Rake::TestTask.new :ohcount_unit_tests => ARCH_DL do |t|
134 # puts File.dirname(__FILE__) + '/test/unit/*_test.rb'
135 t.test_files = FileList[File.dirname(__FILE__) + '/test/unit/**/*_test.rb']
139 task :default => :ohcount_unit_tests