forked from rouge-ruby/rouge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
73 lines (60 loc) · 1.77 KB
/
Rakefile
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
# frozen_string_literal: true
require 'rake/clean'
require 'pathname'
require 'bundler/setup'
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:spec) do |t|
t.libs << "lib"
t.ruby_opts << "-r./spec/spec_helper"
t.warning = !!$VERBOSE
t.pattern = FileList['spec/**/*_spec.rb']
end
task :test => [:spec]
task :doc do
sh 'bundle exec yard'
end
namespace :doc do
task :server do
sh 'bundle exec yard server --reload'
end
task :clean do
sh 'rm -rf ./doc/ ./.yardoc/'
end
end
CLEAN.include('*.gem')
task :build => [:clean, :spec] do
puts
sh "gem build rouge.gemspec"
end
task :default => :spec
Dir.glob(Pathname.new(__FILE__).dirname.join('tasks/*.rake')).each do |f|
load f
end
task :profile_memory do
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'memory_profiler'
source = File.expand_path('lib/rouge/lexer.rb', __dir__)
sample = File.read(source, encoding: 'utf-8')
report = MemoryProfiler.report do
require 'rouge'
formatter = Rouge::Formatters::HTML.new
lexer = Rouge::Lexers::Ruby.new
formatter.format(lexer.lex(sample))
end
print_options = { scale_bytes: true, normalize_paths: true }
if ENV['CI']
report.pretty_print(print_options)
else
results_file = File.expand_path('rouge-memory.tmp')
t_allocated = report.scale_bytes(report.total_allocated_memsize)
t_retained = report.scale_bytes(report.total_retained_memsize)
puts
puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
puts "Total retained: #{t_retained} (#{report.total_retained} objects)"
report.pretty_print(print_options.merge(to_file: results_file))
puts
puts "Detailed report saved to file: #{results_file}"
end
end