Extract outdate-bundled-gems.rb
This commit is contained in:
parent
8e3ac264df
commit
ed4b5c4f21
30
common.mk
30
common.mk
@ -1406,35 +1406,7 @@ extract-gems$(gnumake:yes=-sequential): PHONY
|
||||
gems/bundled_gems
|
||||
|
||||
outdate-bundled-gems: PHONY
|
||||
$(Q) $(BASERUBY) \
|
||||
-rfileutils \
|
||||
-e "srcdir = ARGV.shift" \
|
||||
-e "FU = /\A-\w*n/ =~ ENV['MFLAGS'] ? FileUtils::DryRun : FileUtils::Verbose" \
|
||||
-e "Dir.glob(%[#{srcdir}/.bundle/gems/*/]) {|dir|" \
|
||||
-e "gem = %[#{srcdir}/gems/#{File.basename(dir)}.gem]" \
|
||||
-e "FU.rm_rf(dir) unless File.exist?(gem)" \
|
||||
-e "}" \
|
||||
-e "Dir.glob(%[#{srcdir}/.bundle/specifications/*.gemspec]) {|spec|" \
|
||||
-e "gem = %[#{srcdir}/gems/#{File.basename(spec, '.gemspec')}.gem]" \
|
||||
-e "FU.rm_f(spec) unless File.exist?(gem)" \
|
||||
-e "}" \
|
||||
-e "Dir.glob('.bundle/specifications/*.gemspec') {|spec|" \
|
||||
-e "dir = %[#{srcdir}/.bundle/gems/#{File.basename(spec, '.gemspec')}]" \
|
||||
-e "FU.rm_f(spec) unless File.directory?(dir)" \
|
||||
-e "}" \
|
||||
-e "Dir.glob('.bundle/gems/*/') {|dir|" \
|
||||
-e "spec = %[.bundle/specifications/#{File.basename(dir)}.gemspec]" \
|
||||
-e "FU.rm_rf(dir) unless File.exist?(spec)" \
|
||||
-e "}" \
|
||||
-e "Dir.glob('.bundle/extensions/*/*/*/') {|dir|" \
|
||||
-e "spec = %[.bundle/specifications/#{File.basename(dir)}.gemspec]" \
|
||||
-e "unless File.exist?(spec)" \
|
||||
-e "FU.rm_rf(dir)" \
|
||||
-e "FU.rmdir(File.dirname(dir), parents: true) rescue nil" \
|
||||
-e "end" \
|
||||
-e "}" \
|
||||
-e "# $(MAKE)" \
|
||||
"$(srcdir)"
|
||||
$(Q) $(BASERUBY) $(tooldir)/$@.rb --make="$(MAKE)" --mflags="$(MFLAGS)" "$(srcdir)"
|
||||
|
||||
update-bundled_gems: PHONY
|
||||
$(Q) $(RUNRUBY) -rrubygems \
|
||||
|
134
tool/outdate-bundled-gems.rb
Executable file
134
tool/outdate-bundled-gems.rb
Executable file
@ -0,0 +1,134 @@
|
||||
#!/usr/bin/ruby
|
||||
require 'fileutils'
|
||||
require 'rubygems'
|
||||
|
||||
fu = FileUtils::Verbose
|
||||
until ARGV.empty?
|
||||
case ARGV.first
|
||||
when '--'
|
||||
ARGV.shift
|
||||
break
|
||||
when '-n', '--dryrun'
|
||||
fu = FileUtils::DryRun
|
||||
when /\A--make=/
|
||||
# just to run when `make -n`
|
||||
when /\A--mflags=(.*)/
|
||||
fu = FileUtils::DryRun if /\A-\S*n/ =~ $1
|
||||
when /\A--basedir=(.*)/m
|
||||
dir = $1
|
||||
when /\A-/
|
||||
raise "#{$0}: unknown option: #{ARGV.first}"
|
||||
else
|
||||
break
|
||||
end
|
||||
ARGV.shift
|
||||
end
|
||||
|
||||
class Removal
|
||||
def initialize(base = nil)
|
||||
@base = (File.join(base, "/") if base)
|
||||
@remove = {}
|
||||
end
|
||||
|
||||
def prefixed(name)
|
||||
@base ? File.join(@base, name) : name
|
||||
end
|
||||
|
||||
def stripped(name)
|
||||
if @base && name.start_with?(@base)
|
||||
name[@base.size..-1]
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def slash(name)
|
||||
name.sub(%r[[^/]\K\z], '/')
|
||||
end
|
||||
|
||||
def exist?(name)
|
||||
!@remove.fetch(name) {|k| @remove[k] = !File.exist?(prefixed(name))}
|
||||
end
|
||||
def directory?(name)
|
||||
!@remove.fetch(slash(name)) {|k| @remove[k] = !File.directory?(prefixed(name))}
|
||||
end
|
||||
|
||||
def unlink(name)
|
||||
@remove[stripped(name)] = :rm_f
|
||||
end
|
||||
def rmdir(name)
|
||||
@remove[slash(stripped(name))] = :rm_rf
|
||||
end
|
||||
|
||||
def glob(pattern, *rest)
|
||||
Dir.glob(prefixed(pattern), *rest) {|n|
|
||||
yield stripped(n)
|
||||
}
|
||||
end
|
||||
|
||||
def each_file
|
||||
@remove.each {|k, v| yield prefixed(k) if v == :rm_f}
|
||||
end
|
||||
|
||||
def each_directory
|
||||
@remove.each {|k, v| yield prefixed(k) if v == :rm_rf}
|
||||
end
|
||||
end
|
||||
|
||||
srcdir = Removal.new(ARGV.shift)
|
||||
curdir = Removal.new
|
||||
|
||||
srcdir.glob(".bundle/gems/*/") do |dir|
|
||||
unless srcdir.exist?("gems/#{File.basename(dir)}.gem")
|
||||
srcdir.rmdir(dir)
|
||||
end
|
||||
end
|
||||
|
||||
srcdir.glob(".bundle/specifications/*.gemspec") do |spec|
|
||||
unless srcdir.directory?(".bundle/gems/#{File.basename(spec, '.gemspec')}/")
|
||||
srcdir.unlink(spec)
|
||||
end
|
||||
end
|
||||
|
||||
curdir.glob(".bundle/specifications/*.gemspec") do |spec|
|
||||
unless srcdir.directory?(".bundle/gems/#{File.basename(spec, '.gemspec')}")
|
||||
curdir.unlink(spec)
|
||||
end
|
||||
end
|
||||
|
||||
curdir.glob(".bundle/gems/*/") do |dir|
|
||||
unless curdir.exist?(".bundle/specifications/#{File.basename(dir)}.gemspec")
|
||||
curdir.rmdir(dir)
|
||||
end
|
||||
end
|
||||
|
||||
platform = Gem::Platform.local.to_s
|
||||
curdir.glob(".bundle/{extensions,.timestamp}/*/") do |dir|
|
||||
unless File.basename(dir) == platform
|
||||
curdir.rmdir(dir)
|
||||
end
|
||||
end
|
||||
|
||||
version = RbConfig::CONFIG['ruby_version']
|
||||
curdir.glob(".bundle/{extensions,.timestamp}/#{platform}/*/") do |dir|
|
||||
unless File.basename(dir) == version
|
||||
curdir.rmdir(dir)
|
||||
end
|
||||
end
|
||||
|
||||
curdir.glob(".bundle/extensions/#{platform}/#{version}/*/") do |dir|
|
||||
unless curdir.exist?(".bundle/specifications/#{File.basename(dir)}.gemspec")
|
||||
curdir.rmdir(dir)
|
||||
end
|
||||
end
|
||||
|
||||
curdir.glob(".bundle/.timestamp/#{platform}/#{version}/.*.time") do |stamp|
|
||||
unless curdir.directory?(File.join(".bundle", stamp[%r[/\.([^/]+)\.time\z], 1].gsub('.-.', '/')))
|
||||
curdir.unlink(stamp)
|
||||
end
|
||||
end
|
||||
|
||||
srcdir.each_file {|f| fu.rm_f(f)}
|
||||
srcdir.each_directory {|d| fu.rm_rf(d)}
|
||||
curdir.each_file {|f| fu.rm_f(f)}
|
||||
curdir.each_directory {|d| fu.rm_rf(d)}
|
Loading…
x
Reference in New Issue
Block a user