ruby: patching gems works
This commit is contained in:
parent
221509b0a6
commit
bd53746646
@ -37,24 +37,33 @@ let
|
|||||||
then attrs // fixes."${attrs.name}" attrs
|
then attrs // fixes."${attrs.name}" attrs
|
||||||
else attrs;
|
else attrs;
|
||||||
|
|
||||||
|
needsPatch = attrs:
|
||||||
|
(attrs ? patches) || (attrs ? prePatch) || (attrs ? postPatch);
|
||||||
|
|
||||||
# patch a gem or source tree.
|
# patch a gem or source tree.
|
||||||
# for gems, the gem is unpacked, patched, and then repacked.
|
# for gems, the gem is unpacked, patched, and then repacked.
|
||||||
# see: https://github.com/fedora-ruby/gem-patch/blob/master/lib/rubygems/patcher.rb
|
# see: https://github.com/fedora-ruby/gem-patch/blob/master/lib/rubygems/patcher.rb
|
||||||
applyPatches = { attrs }:
|
applyPatches = attrs:
|
||||||
if (!(attrs ? patches))
|
if !needsPatch attrs
|
||||||
then attrs
|
then attrs
|
||||||
else attrs // { src =
|
else attrs // { src =
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = gemName attrs;
|
name = gemName attrs;
|
||||||
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
||||||
buildInputs = [ ruby ];
|
buildInputs = [ ruby ] ++ attrs.buildInputs or [];
|
||||||
inherit (attrs) patches;
|
patches = attrs.patches or [ ];
|
||||||
|
prePatch = attrs.prePatch or "true";
|
||||||
|
postPatch = attrs.postPatch or "true";
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
runHook preUnpack
|
runHook preUnpack
|
||||||
|
|
||||||
if [[ -f ${attrs.src} ]]; then
|
if [[ -f ${attrs.src} ]]; then
|
||||||
isGem=1
|
isGem=1
|
||||||
gem unpack ${attrs.src} --target=contents
|
# we won't know the name of the directory that RubyGems creates,
|
||||||
|
# so we'll just use a glob to find it and move it over.
|
||||||
|
gem unpack ${attrs.src} --target=container
|
||||||
|
cp -r container/* contents
|
||||||
|
rm -r container
|
||||||
else
|
else
|
||||||
cp -r ${attrs.src} contents
|
cp -r ${attrs.src} contents
|
||||||
chmod -R +w contents
|
chmod -R +w contents
|
||||||
@ -66,25 +75,33 @@ let
|
|||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
mkdir build
|
|
||||||
if [[ -n "$isGem" ]]; then
|
if [[ -n "$isGem" ]]; then
|
||||||
${writeScript "repack.rb" ''
|
${writeScript "repack.rb" ''
|
||||||
#!${ruby}/bin/ruby
|
#!${ruby}/bin/ruby
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
require 'rubygems/package'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
|
if defined?(Encoding.default_internal)
|
||||||
|
Encoding.default_internal = Encoding::UTF_8
|
||||||
|
Encoding.default_external = Encoding::UTF_8
|
||||||
|
end
|
||||||
|
|
||||||
|
if Gem::VERSION < '2.0'
|
||||||
|
load "${./package-1.8.rb}"
|
||||||
|
end
|
||||||
|
|
||||||
out = ENV['out']
|
out = ENV['out']
|
||||||
files = Dir['**/{.[^\.]*,*}']
|
files = Dir['**/{.[^\.]*,*}']
|
||||||
|
|
||||||
package = Gem::Package.new("${attrs.src}")
|
package = Gem::Package.new("${attrs.src}")
|
||||||
patched_package = Gem::Package.new(package.spec.file_name)
|
patched_package = Gem::Package.new(package.spec.file_name)
|
||||||
patched_package.spec = package.spec.clone
|
patched_package.spec = package.spec.clone
|
||||||
patched_package.spec.files = files
|
patched_package.spec.files = files
|
||||||
|
|
||||||
# Change dir and build the patched gem
|
patched_package.build(false)
|
||||||
Dir.chdir("../build") do
|
|
||||||
patched_package.build false
|
FileUtils.cp(patched_package.spec.file_name, out)
|
||||||
end
|
|
||||||
FileUtils.cp "../build/#{package.file_name}" out
|
|
||||||
''}
|
''}
|
||||||
else
|
else
|
||||||
cp -r . out
|
cp -r . out
|
||||||
@ -96,7 +113,7 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
instantiate = (attrs:
|
instantiate = (attrs:
|
||||||
applyFixes (applySrc attrs)
|
applyPatches (applyFixes (applySrc attrs))
|
||||||
);
|
);
|
||||||
|
|
||||||
instantiated = lib.flip lib.mapAttrs (import gemset) (name: attrs:
|
instantiated = lib.flip lib.mapAttrs (import gemset) (name: attrs:
|
||||||
|
29
pkgs/development/interpreters/ruby/package-1.8.rb
Normal file
29
pkgs/development/interpreters/ruby/package-1.8.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
require 'rubygems/installer'
|
||||||
|
require 'rubygems/builder'
|
||||||
|
|
||||||
|
# Simulate RubyGems 2.0 behavior.
|
||||||
|
|
||||||
|
module Gem::Package
|
||||||
|
def self.new(gem)
|
||||||
|
@gem = gem
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.extract_files(dir)
|
||||||
|
installer = Gem::Installer.new @gem
|
||||||
|
installer.unpack(dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.build(skip_validation=false)
|
||||||
|
builder = Gem::Builder.new(spec)
|
||||||
|
builder.build
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.spec=(spec)
|
||||||
|
@spec = spec
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.spec
|
||||||
|
@spec ||= Gem::Installer.new(@gem).spec
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user