From 2cb31d576a83861a05f2596d5a5e8d1dee661de6 Mon Sep 17 00:00:00 2001 From: Alexander Flatter Date: Wed, 17 Sep 2014 15:06:37 +0200 Subject: [PATCH] Improve buildRubyGem --- pkgs/development/interpreters/ruby/bundix.nix | 2 +- pkgs/development/interpreters/ruby/fixes.nix | 12 ++-- pkgs/development/interpreters/ruby/gem.nix | 61 +++++++++++++------ 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/pkgs/development/interpreters/ruby/bundix.nix b/pkgs/development/interpreters/ruby/bundix.nix index f86190005bb..4f745cfd62a 100644 --- a/pkgs/development/interpreters/ruby/bundix.nix +++ b/pkgs/development/interpreters/ruby/bundix.nix @@ -9,7 +9,7 @@ gems = rubyLibs.importGems gemset (config.gemOverrides or (gemset: {})); in { inherit ruby; # TODO: Set ruby using expr.rubyVersion if not given. - gemPath = map (drv: "${drv}/${ruby.gemPath}") ( + gemPath = map (drv: "${drv}") ( builtins.filter (value: lib.isDerivation value) (lib.attrValues gems) ); }; diff --git a/pkgs/development/interpreters/ruby/fixes.nix b/pkgs/development/interpreters/ruby/fixes.nix index a8514375c74..ddd673004d3 100644 --- a/pkgs/development/interpreters/ruby/fixes.nix +++ b/pkgs/development/interpreters/ruby/fixes.nix @@ -36,15 +36,11 @@ let then (builtins.getAttr name fixes) attrs else {}; in - buildRubyGem ({ - name = attrs.name; - sha256 = attrs.sha256; + buildRubyGem (attrs // { inherit gemPath; # Disable the checkPhase as there no single way to run tests for a given # gem: https://github.com/rubygems/rubygems/issues/730 checkPhase = ":"; - # Gems downloaded from rubygems.org don't need to be built again. - dontBuild = true; } // fix) ); @@ -70,9 +66,9 @@ let therubyracer = attrs: { dontBuild = false; - preBuild = '' - addToSearchPath RUBYLIB "${gems.libv8}/${ruby.gemPath}/gems/libv8-3.16.14.3/lib" - addToSearchPath RUBYLIB "${gems.libv8}/${ruby.gemPath}/gems/libv8-3.16.14.3/ext" + preInstall = '' + addToSearchPath RUBYLIB "${gems.libv8}/gems/libv8-3.16.14.3/lib" + addToSearchPath RUBYLIB "${gems.libv8}/gems/libv8-3.16.14.3/ext" ln -s ${clang}/bin/clang $TMPDIR/gcc ln -s ${clang}/bin/clang++ $TMPDIR/g++ export PATH=$TMPDIR:$PATH diff --git a/pkgs/development/interpreters/ruby/gem.nix b/pkgs/development/interpreters/ruby/gem.nix index 012c9f5013d..95246797a70 100644 --- a/pkgs/development/interpreters/ruby/gem.nix +++ b/pkgs/development/interpreters/ruby/gem.nix @@ -27,16 +27,24 @@ in ruby.stdenv.mkDerivation (attrs // { inherit (attrs) sha256; }; - unpackPhase = '' - if test -d $src; then - cd $src + # The source is expected to either be a gem package or a directory. + # + # - Gem packages are already built, so they don't even need to be unpacked. + # They will skip the buildPhase. + # - A directory containing the sources will need to go through all of the + # usual phases. + unpackPhase= '' + gemRegex="\.gem" + if [[ $src =~ $gemRegex ]] + then + runHook preUnpack + echo "Source is a gem package, won't unpack." + gempkg=$src + dontBuild=1 + runHook postUnpack else - cp $src ${attrs.name}.gem - gem unpack ${attrs.name}.gem - rm ${attrs.name}.gem - mv ${attrs.name} gem-build - cd gem-build - sourceRoot=`pwd` + # Fall back to the original thing for everything else. + unpackPhase fi ''; @@ -46,6 +54,23 @@ in ruby.stdenv.mkDerivation (attrs // { runHook postCheck ''; + buildPhase = '' + runHook preBuild + + # TODO: Investigate. The complete working tree is touched by fetchgit. + if [ -d .git ]; then + git reset + fi + + gemspec=`find . -name '*.gemspec'` + output=`gem build $gemspec` + gempkg=`echo $output|grep -oP 'File: \K(.*)'` + + echo "Gem package built: $gempkg" + + runHook postBuild + ''; + installPhase = '' runHook preInstall @@ -54,7 +79,7 @@ in ruby.stdenv.mkDerivation (attrs // { # separate buildPhase. # --ignore-dependencies is necessary as rubygems otherwise always # connects to the repository, thus breaking pure builds. - GEM_HOME=$out/${ruby.gemPath} \ + GEM_HOME=$out \ gem install \ --local \ --force \ @@ -63,30 +88,26 @@ in ruby.stdenv.mkDerivation (attrs // { --build-root "/" \ --bindir "$out/bin" \ --backtrace \ - $src $gemFlags -- $buildFlags + $gempkg $gemFlags -- $buildFlags - rm -frv $out/${ruby.gemPath}/cache # don't keep the .gem file here + rm -frv $out/cache # don't keep the .gem file here for prog in $out/bin/*; do wrapProgram "$prog" \ - --prefix GEM_PATH : "$out/${ruby.gemPath}:$GEM_PATH" \ + --prefix GEM_PATH : "$out:$GEM_PATH" \ --prefix RUBYLIB : "${rubygems}/lib" \ --set RUBYOPT rubygems \ $extraWrapperFlags ''${extraWrapperFlagsArray[@]} done - for prog in $out/gems/*/bin/*; do - [[ -e "$out/bin/$(basename $prog)" ]] - done - # looks like useless files which break build repeatability and consume space - rm -fv $out/${ruby.gemPath}/doc/*/*/created.rid || true - rm -fv $out/${ruby.gemPath}/gems/*/ext/*/mkmf.log || true + rm -fv $out/doc/*/*/created.rid || true + rm -fv $out/gems/*/ext/*/mkmf.log || true mkdir -p $out/nix-support cat > $out/nix-support/setup-hook <