File build_clean.rb of Package rubygem-libv8
#!/usr/bin/env ruby
require 'rbconfig'
require 'fileutils'
NAME="libv8"
VERSION="8.4.255.0"
BUILDROOT=ENV['RPM_BUILD_ROOT']
LIBDIR=RbConfig::CONFIG['libdir']
MODULE_NAME=NAME + "-" + VERSION
Dir.glob(BUILDROOT + LIBDIR + "/ruby/gems/*") do |gem_base|
module_dir = gem_base + "/gems/" + MODULE_NAME
# clean /usr/lib(64)/ruby/2.[0-3].[0-9]/gems/libv8-*/cache/*.gem,
# which is too big (300+ MB) after v8 source was added.
cached = gem_base + "/cache/" + MODULE_NAME + ".gem"
FileUtils.rm_rf cached
FileUtils.touch cached
# just keep the needed stuff
FileUtils.mv module_dir + "/vendor/v8/include", File.expand_path(module_dir + "/../v8_include")
FileUtils.mv module_dir + "/vendor/v8/out.gn/libv8/obj", File.expand_path(module_dir + "/../v8_out")
Dir.glob(File.expand_path(module_dir + "/../v8_out") + "/**/{*,.*}") do |f|
unless f.end_with?(".a")
FileUtils.rm_rf f
end
end
FileUtils.mv module_dir + "/ext", File.expand_path(module_dir + "/../ext")
FileUtils.mv module_dir + "/lib", File.expand_path(module_dir + "/../lib")
FileUtils.mv module_dir + "/spec", File.expand_path(module_dir + "/../spec")
FileUtils.mv module_dir + "/README.md", File.expand_path(module_dir + "/../README.md")
FileUtils.mv module_dir + "/CHANGELOG.md", File.expand_path(module_dir + "/../CHANGELOG.md")
# move back everything
FileUtils.rm_rf module_dir
FileUtils.mkdir_p module_dir + "/vendor/v8/out.gn/libv8"
FileUtils.mv File.expand_path(module_dir + "/../v8_include"), module_dir + "/vendor/v8/include"
FileUtils.mv File.expand_path(module_dir + "/../v8_out"), module_dir + "/vendor/v8/out.gn/libv8/obj"
FileUtils.mv File.expand_path(module_dir + "/../ext"), module_dir + "/ext"
FileUtils.mv File.expand_path(module_dir + "/../lib"), module_dir + "/lib"
FileUtils.mv File.expand_path(module_dir + "/../spec"), module_dir + "/spec"
FileUtils.mv File.expand_path(module_dir + "/../README.md"), module_dir + "/README.md"
FileUtils.mv File.expand_path(module_dir + "/../CHANGELOG.md"), module_dir + "/CHANGELOG.md"
end