This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
desc "Remove all build products"
|
||||
task "clobber"
|
||||
@@ -0,0 +1,95 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubygems/package_task"
|
||||
|
||||
namespace :gem do
|
||||
GEM_SPEC = Gem::Specification.new do |s|
|
||||
s.name = PKG_NAME
|
||||
s.version = PKG_VERSION
|
||||
s.summary = PKG_SUMMARY
|
||||
s.description = PKG_DESCRIPTION
|
||||
|
||||
s.files = PKG_FILES.to_a
|
||||
|
||||
s.extra_rdoc_files = %w( README.md )
|
||||
s.rdoc_options.concat ["--main", "README.md"]
|
||||
|
||||
if !s.respond_to?(:add_development_dependency)
|
||||
puts "Cannot build Gem with this version of RubyGems."
|
||||
exit(1)
|
||||
end
|
||||
|
||||
s.required_ruby_version = ">= 2.2"
|
||||
|
||||
s.add_runtime_dependency "public_suffix", ">= 2.0.2", "< 7.0"
|
||||
s.add_development_dependency "bundler", ">= 1.0", "< 3.0"
|
||||
|
||||
s.require_path = "lib"
|
||||
|
||||
s.author = "Bob Aman"
|
||||
s.email = "bob@sporkmonger.com"
|
||||
s.homepage = "https://github.com/sporkmonger/addressable"
|
||||
s.license = "Apache-2.0"
|
||||
s.metadata = {
|
||||
"changelog_uri" => "https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md#v#{PKG_VERSION}"
|
||||
}
|
||||
end
|
||||
|
||||
Gem::PackageTask.new(GEM_SPEC) do |p|
|
||||
p.gem_spec = GEM_SPEC
|
||||
p.need_tar = true
|
||||
p.need_zip = true
|
||||
end
|
||||
|
||||
desc "Generates .gemspec file"
|
||||
task :gemspec do
|
||||
spec_string = GEM_SPEC.to_ruby
|
||||
File.open("#{GEM_SPEC.name}.gemspec", "w") do |file|
|
||||
file.write spec_string
|
||||
end
|
||||
end
|
||||
|
||||
desc "Show information about the gem"
|
||||
task :debug do
|
||||
puts GEM_SPEC.to_ruby
|
||||
end
|
||||
|
||||
desc "Install the gem"
|
||||
task :install => ["clobber", "gem:package"] do
|
||||
sh "gem install --local ./pkg/#{GEM_SPEC.full_name}.gem"
|
||||
end
|
||||
|
||||
desc "Uninstall the gem"
|
||||
task :uninstall do
|
||||
installed_list = Gem.source_index.find_name(PKG_NAME)
|
||||
if installed_list &&
|
||||
(installed_list.collect { |s| s.version.to_s}.include?(PKG_VERSION))
|
||||
sh(
|
||||
"gem uninstall --version '#{PKG_VERSION}' " +
|
||||
"--ignore-dependencies --executables #{PKG_NAME}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Reinstall the gem"
|
||||
task :reinstall => [:uninstall, :install]
|
||||
|
||||
desc "Package for release"
|
||||
task :release => ["gem:package", "gem:gemspec"] do |t|
|
||||
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
||||
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PKG_VERSION
|
||||
pkg = "pkg/#{GEM_SPEC.full_name}"
|
||||
|
||||
changelog = File.open("CHANGELOG.md") { |file| file.read }
|
||||
|
||||
puts "Releasing #{PKG_NAME} v. #{PKG_VERSION}"
|
||||
Rake::Task["git:tag:create"].invoke
|
||||
end
|
||||
end
|
||||
|
||||
desc "Alias to gem:package"
|
||||
task "gem" => "gem:package"
|
||||
|
||||
task "gem:release" => "gem:gemspec"
|
||||
|
||||
task "clobber" => ["gem:clobber_package"]
|
||||
@@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :git do
|
||||
namespace :tag do
|
||||
desc "List tags from the Git repository"
|
||||
task :list do
|
||||
tags = `git tag -l`
|
||||
tags.gsub!("\r", "")
|
||||
tags = tags.split("\n").sort {|a, b| b <=> a }
|
||||
puts tags.join("\n")
|
||||
end
|
||||
|
||||
desc "Create a new tag in the Git repository"
|
||||
task :create do
|
||||
changelog = File.open("CHANGELOG.md", "r") { |file| file.read }
|
||||
puts "-" * 80
|
||||
puts changelog
|
||||
puts "-" * 80
|
||||
puts
|
||||
|
||||
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
||||
abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
|
||||
|
||||
git_status = `git status`
|
||||
if git_status !~ /^nothing to commit/
|
||||
abort "Working directory isn't clean."
|
||||
end
|
||||
|
||||
tag = "#{PKG_NAME}-#{PKG_VERSION}"
|
||||
msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
|
||||
|
||||
existing_tags = `git tag -l #{PKG_NAME}-*`.split('\n')
|
||||
if existing_tags.include?(tag)
|
||||
warn("Tag already exists, deleting...")
|
||||
unless system "git tag -d #{tag}"
|
||||
abort "Tag deletion failed."
|
||||
end
|
||||
end
|
||||
puts "Creating git tag '#{tag}'..."
|
||||
unless system "git tag -a -m \"#{msg}\" #{tag}"
|
||||
abort "Tag creation failed."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task "gem:release" => "git:tag:create"
|
||||
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :metrics do
|
||||
task :lines do
|
||||
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
||||
for file_name in FileList["lib/**/*.rb"]
|
||||
f = File.open(file_name)
|
||||
while line = f.gets
|
||||
lines += 1
|
||||
next if line =~ /^\s*$/
|
||||
next if line =~ /^\s*#/
|
||||
codelines += 1
|
||||
end
|
||||
puts "L: #{sprintf("%4d", lines)}, " +
|
||||
"LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
||||
total_lines += lines
|
||||
total_codelines += codelines
|
||||
|
||||
lines, codelines = 0, 0
|
||||
end
|
||||
|
||||
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,72 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :profile do
|
||||
desc "Profile Template match memory allocations"
|
||||
task :template_match_memory do
|
||||
require "memory_profiler"
|
||||
require "addressable/template"
|
||||
|
||||
start_at = Time.now.to_f
|
||||
template = Addressable::Template.new("http://example.com/{?one,two,three}")
|
||||
report = MemoryProfiler.report do
|
||||
30_000.times do
|
||||
template.match(
|
||||
"http://example.com/?one=one&two=floo&three=me"
|
||||
)
|
||||
end
|
||||
end
|
||||
end_at = Time.now.to_f
|
||||
print_options = { scale_bytes: true, normalize_paths: true }
|
||||
puts "\n\n"
|
||||
|
||||
if ENV["CI"]
|
||||
report.pretty_print(print_options)
|
||||
else
|
||||
t_allocated = report.scale_bytes(report.total_allocated_memsize)
|
||||
t_retained = report.scale_bytes(report.total_retained_memsize)
|
||||
|
||||
puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
|
||||
puts "Total retained: #{t_retained} (#{report.total_retained} objects)"
|
||||
puts "Took #{end_at - start_at} seconds"
|
||||
|
||||
FileUtils.mkdir_p("tmp")
|
||||
report.pretty_print(to_file: "tmp/memprof.txt", **print_options)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Profile URI parse memory allocations"
|
||||
task :memory do
|
||||
require "memory_profiler"
|
||||
require "addressable/uri"
|
||||
if ENV["IDNA_MODE"] == "pure"
|
||||
Addressable.send(:remove_const, :IDNA)
|
||||
load "addressable/idna/pure.rb"
|
||||
end
|
||||
|
||||
start_at = Time.now.to_f
|
||||
report = MemoryProfiler.report do
|
||||
30_000.times do
|
||||
Addressable::URI.parse(
|
||||
"http://google.com/stuff/../?with_lots=of¶ms=asdff#!stuff"
|
||||
).normalize
|
||||
end
|
||||
end
|
||||
end_at = Time.now.to_f
|
||||
print_options = { scale_bytes: true, normalize_paths: true }
|
||||
puts "\n\n"
|
||||
|
||||
if ENV["CI"]
|
||||
report.pretty_print(**print_options)
|
||||
else
|
||||
t_allocated = report.scale_bytes(report.total_allocated_memsize)
|
||||
t_retained = report.scale_bytes(report.total_retained_memsize)
|
||||
|
||||
puts "Total allocated: #{t_allocated} (#{report.total_allocated} objects)"
|
||||
puts "Total retained: #{t_retained} (#{report.total_retained} objects)"
|
||||
puts "Took #{end_at - start_at} seconds"
|
||||
|
||||
FileUtils.mkdir_p("tmp")
|
||||
report.pretty_print(to_file: "tmp/memprof.txt", **print_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
namespace :spec do
|
||||
RSpec::Core::RakeTask.new(:simplecov) do |t|
|
||||
t.pattern = FileList['spec/**/*_spec.rb']
|
||||
t.rspec_opts = %w[--color --format documentation] unless ENV["CI"]
|
||||
end
|
||||
|
||||
namespace :simplecov do
|
||||
desc "Browse the code coverage report."
|
||||
task :browse => "spec:simplecov" do
|
||||
require "launchy"
|
||||
Launchy.open("coverage/index.html")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Alias to spec:simplecov"
|
||||
task "spec" => "spec:simplecov"
|
||||
|
||||
task "clobber" => ["spec:clobber_simplecov"]
|
||||
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rake"
|
||||
|
||||
begin
|
||||
require "yard"
|
||||
require "yard/rake/yardoc_task"
|
||||
|
||||
namespace :doc do
|
||||
desc "Generate Yardoc documentation"
|
||||
YARD::Rake::YardocTask.new do |yardoc|
|
||||
yardoc.name = "yard"
|
||||
yardoc.options = ["--verbose", "--markup", "markdown"]
|
||||
yardoc.files = FileList[
|
||||
"lib/**/*.rb", "ext/**/*.c",
|
||||
"README.md", "CHANGELOG.md", "LICENSE.txt"
|
||||
].exclude(/idna/)
|
||||
end
|
||||
end
|
||||
|
||||
task "clobber" => ["doc:clobber_yard"]
|
||||
|
||||
desc "Alias to doc:yard"
|
||||
task "doc" => "doc:yard"
|
||||
rescue LoadError
|
||||
# If yard isn't available, it's not the end of the world
|
||||
desc "Alias to doc:rdoc"
|
||||
task "doc" => "doc:rdoc"
|
||||
end
|
||||
Reference in New Issue
Block a user